
// Make newform 650.4.b.j in Magma, downloaded from the LMFDB on 06 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_650_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_650_b_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_650_4_b_j();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_650_4_b_j();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [1296, 0, 73, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 37, 0, 1], [37, 0, 1, 0]];
    Rf_basisdens := [1, 1, 36, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_650_b();"
function MakeCharacter_650_b()
    N := 650;
    order := 2;
    char_gens := [27, 301];
    v := [1, 2];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_650_b_Hecke();"
function MakeCharacter_650_b_Hecke(Kf)
    N := 650;
    order := 2;
    char_gens := [27, 301];
    char_values := [[-1, 0, 0, 0], [1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..prec]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 4;
    raw_aps := [[0, 0, -2, 0], [0, 1, -1, 0], [0, 0, 0, 0], [0, -1, 20, 0], [13, 0, 0, -10], [0, 0, -13, 0], [0, 6, 9, 0], [-64, 0, 0, 5], [0, 2, -36, 0], [207, 0, 0, -15], [-179, 0, 0, 1], [0, -6, -124, 0], [-12, 0, 0, -21], [0, 14, -308, 0], [0, -15, -456, 0], [0, 53, -210, 0], [101, 0, 0, -77], [-65, 0, 0, 49], [0, 8, 293, 0], [232, 0, 0, -64], [0, -111, -353, 0], [-104, 0, 0, -180], [0, -120, 15, 0], [-70, 0, 0, -203], [0, -10, 182, 0], [-923, 0, 0, 59], [0, -2, -1010, 0], [0, -93, -51, 0], [-626, 0, 0, 210], [0, 175, -1119, 0], [0, -6, -730, 0], [-222, 0, 0, 42], [0, -31, 1923, 0], [-1770, 0, 0, -191], [1848, 0, 0, -192], [-687, 0, 0, -259], [0, 79, 632, 0], [0, -385, -1037, 0], [0, 454, -498, 0], [0, 123, -2826, 0], [-1500, 0, 0, -213], [603, 0, 0, 329], [-108, 0, 0, 126], [0, 581, -275, 0], [0, 432, 1848, 0], [-952, 0, 0, 554], [1842, 0, 0, 77], [0, -330, -1958, 0], [0, 269, 840, 0], [160, 0, 0, -480], [0, 496, 3930, 0], [2351, 0, 0, 121], [2196, 0, 0, -121], [-220, 0, 0, -5], [0, 717, -2334, 0], [0, 258, -120, 0], [2255, 0, 0, -203], [-939, 0, 0, 59], [0, -732, 230, 0], [-1460, 0, 0, 158], [0, -1173, 673, 0], [0, -542, 810, 0], [0, 347, 1523, 0], [2454, 0, 0, 918], [0, 399, 3934, 0], [0, -1150, -3294, 0], [-3752, 0, 0, 1291], [0, -384, 3707, 0], [0, -317, -483, 0], [-132, 0, 0, 1798], [0, -264, 7110, 0], [1565, 0, 0, -1877], [0, 218, 8744, 0], [0, 233, -7028, 0], [-4637, 0, 0, -744], [0, 422, 1122, 0], [-2114, 0, 0, -322], [0, 632, -2350, 0], [1120, 0, 0, -2077], [10858, 0, 0, -573], [9022, 0, 0, -1387], [-10588, 0, 0, 396], [-4884, 0, 0, -1236], [0, 761, -6581, 0], [820, 0, 0, -2454], [0, 495, 8853, 0], [-10170, 0, 0, 663], [0, 1621, 7883, 0], [-11544, 0, 0, -714], [0, -495, -662, 0], [0, 678, 8604, 0], [-3889, 0, 0, 1267], [0, -1605, 2252, 0], [2974, 0, 0, -2458], [-6251, 0, 0, 843], [0, 1040, 6768, 0], [-5148, 0, 0, 684], [-11298, 0, 0, 759], [0, -1229, 9055, 0], [8128, 0, 0, -1682], [0, -413, 12737, 0], [0, 1746, -8418, 0], [0, -456, -8040, 0], [-12109, 0, 0, -1400], [8116, 0, 0, 724], [0, -775, -991, 0], [0, 798, 14925, 0], [0, -4211, -5049, 0], [-12390, 0, 0, -2004], [15021, 0, 0, -142], [0, 112, 15914, 0], [0, -1530, -7202, 0], [0, 168, -8358, 0], [10444, 0, 0, 1440], [-7732, 0, 0, 2124], [-10281, 0, 0, -2337], [0, -3616, -1316, 0], [0, 36, 9294, 0], [0, -2041, -14106, 0], [9164, 0, 0, 1753], [-16846, 0, 0, -1908], [0, 413, -14990, 0], [0, 2006, -6420, 0], [0, 1150, 9693, 0], [22143, 0, 0, -952], [-21257, 0, 0, 1325], [21920, 0, 0, -94], [22614, 0, 0, 648], [0, -930, 14378, 0], [0, 2504, -7862, 0], [-7079, 0, 0, 1227], [0, 3027, 20340, 0], [770, 0, 0, -3972], [0, 4361, -1288, 0], [-29400, 0, 0, 1047], [-412, 0, 0, 1229], [0, -3694, 3606, 0], [0, -6323, -808, 0], [0, 2609, 2796, 0], [-35094, 0, 0, -1380], [35919, 0, 0, -1639], [24900, 0, 0, -3480], [0, -3568, -4052, 0], [0, -3516, -10683, 0], [-2941, 0, 0, 3971], [-26928, 0, 0, -2622], [0, -70, 23812, 0], [0, -4197, -10623, 0], [-20206, 0, 0, -3523], [0, 645, 21762, 0], [0, 3210, -11392, 0], [22349, 0, 0, 2269], [0, -1853, 22795, 0], [0, 1516, -23916, 0], [0, -3256, 24860, 0], [9432, 0, 0, 918], [14408, 0, 0, 632], [-20722, 0, 0, 652], [0, -7608, -13885, 0], [-8730, 0, 0, -3900], [0, -1453, -7188, 0], [0, -836, -47169, 0], [0, 2239, 40376, 0], [22938, 0, 0, 3159], [0, 945, 2595, 0], [0, 2393, 21156, 0], [12854, 0, 0, 4092], [0, -1971, -24028, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_650_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_650_4_b_j();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_650_4_b_j(:prec:=4)
    chi := MakeCharacter_650_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_650_4_b_j();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_650_4_b_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_650_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![1156, 0, 77, 0, 1]>,<7,R![147456, 0, 913, 0, 1]>],Snew);
    return Vf;
end function;