
// Make newform 650.4.b.l in Magma, downloaded from the LMFDB on 29 September 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_l();".
// 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_l();".
// 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 := [25, 0, -9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -4, 0, 1], [0, 14, 0, -1], [-9, 0, 2, 0]];
    Rf_basisdens := [1, 5, 5, 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 := false)
    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 := ISA(Type(Kf), Fld), 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, -2, 0, 0], [0, -1, 0, 1], [0, 0, 0, 0], [0, 0, 0, 6], [-25, 0, 7, 0], [0, -13, 0, 0], [0, -44, 0, -14], [47, 0, 15, 0], [0, 61, 0, 3], [130, 0, 22, 0], [-201, 0, -1, 0], [0, 160, 0, 32], [-268, 0, -34, 0], [0, 31, 0, 89], [0, 376, 0, 10], [0, -124, 0, -122], [165, 0, 13, 0], [310, 0, 66, 0], [0, 230, 0, -124], [-367, 0, 13, 0], [0, -228, 0, 164], [462, 0, -118, 0], [0, 1152, 0, -6], [374, 0, -60, 0], [0, 962, 0, -184], [182, 0, 52, 0], [0, -109, 0, 377], [0, -1095, 0, 243], [294, 0, -232, 0], [0, 248, 0, 150], [0, -333, 0, 481], [956, 0, -124, 0], [0, 1394, 0, -188], [-1082, 0, -242, 0], [-510, 0, 168, 0], [-589, 0, 407, 0], [0, 2414, 0, 88], [0, 414, 0, -452], [0, -2892, 0, 34], [0, 72, 0, -834], [-2120, 0, 376, 0], [386, 0, 998, 0], [-444, 0, 492, 0], [0, 898, 0, 128], [0, -3286, 0, -76], [-512, 0, 908, 0], [-4156, 0, -4, 0], [0, 1608, 0, -622], [0, 1518, 0, 224], [-512, 0, 678, 0], [0, -3554, 0, -640], [-825, 0, -485, 0], [-692, 0, -866, 0], [-4726, 0, -90, 0], [0, -2042, 0, 640], [0, 1721, 0, 95], [118, 0, 152, 0], [-5705, 0, 67, 0], [0, -2148, 0, 94], [-1944, 0, 1346, 0], [0, -2157, 0, 413], [0, 2560, 0, 1004], [0, -6700, 0, 638], [5034, 0, -738, 0], [0, -880, 0, -134], [0, 4924, 0, -72], [1681, 0, 129, 0], [0, 316, 0, -1450], [0, 3131, 0, -315], [-2080, 0, 1802, 0], [0, -6720, 0, 1476], [-1645, 0, 1755, 0], [0, -8619, 0, 1107], [0, -3518, 0, -1240], [4121, 0, 1573, 0], [0, -7772, 0, -642], [-2470, 0, 448, 0], [0, 3684, 0, 756], [-1078, 0, 1108, 0], [640, 0, 1014, 0], [-1750, 0, -2, 0], [1950, 0, 244, 0], [10095, 0, -201, 0], [0, 5546, 0, 2148], [4160, 0, 2392, 0], [0, -873, 0, -135], [-492, 0, 246, 0], [0, -4154, 0, 948], [-4340, 0, -2342, 0], [0, -26, 0, -1368], [0, -467, 0, -1337], [6699, 0, -2765, 0], [0, -13422, 0, -440], [11886, 0, 1010, 0], [-221, 0, -1293, 0], [0, 8119, 0, -843], [4656, 0, 3402, 0], [8446, 0, 1030, 0], [0, 1411, 0, -2747], [-9860, 0, -738, 0], [0, -15, 0, -2917], [0, 13192, 0, 328], [0, -18153, 0, 1617], [16238, 0, 2274, 0], [-8550, 0, 410, 0], [0, 6724, 0, -1556], [0, 8090, 0, 716], [0, 7098, 0, -2804], [11162, 0, -442, 0], [-13094, 0, -3080, 0], [0, -6877, 0, -335], [0, -12602, 0, 1176], [0, 13918, 0, 1648], [-16387, 0, -707, 0], [7225, 0, -3127, 0], [-15354, 0, 2652, 0], [0, 21356, 0, 294], [0, -18773, 0, -1823], [0, -22194, 0, -1072], [3382, 0, 2474, 0], [-186, 0, -3212, 0], [0, -18256, 0, -1134], [0, 12916, 0, 3570], [0, 7106, 0, 5124], [13669, 0, -707, 0], [-6534, 0, 848, 0], [-8640, 0, -2738, 0], [19648, 0, 796, 0], [0, -21883, 0, -2829], [0, 5562, 0, 808], [-2557, 0, 3679, 0], [0, -15608, 0, -2750], [9518, 0, -1866, 0], [0, -3508, 0, -2938], [15330, 0, -3072, 0], [8330, 0, 804, 0], [0, 18564, 0, 3476], [0, -1992, 0, -5446], [0, 21330, 0, -388], [-6394, 0, -118, 0], [-14283, 0, 6021, 0], [20322, 0, 5580, 0], [0, -18177, 0, -6395], [0, 1056, 0, -5970], [4566, 0, -1406, 0], [25537, 0, -2819, 0], [0, -33796, 0, -1296], [0, -14274, 0, 6600], [-4818, 0, -4022, 0], [0, 13252, 0, -194], [0, -7414, 0, -4944], [-1870, 0, 8082, 0], [0, -11081, 0, 6553], [0, -34867, 0, -1101], [0, -35147, 0, 4351], [26880, 0, -900, 0], [-9858, 0, 3874, 0], [-5308, 0, -162, 0], [0, -29842, 0, -1212], [9900, 0, -7362, 0], [0, -7788, 0, -8230], [0, -9210, 0, 4660], [0, 746, 0, 8224], [16240, 0, 4144, 0], [0, 516, 0, 3132], [0, 38246, 0, 2584], [15368, 0, 6888, 0], [0, 27864, 0, 2878]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_650_b_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_650_4_b_l();".
// 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_l(: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_l();".
// 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_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_650_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![324, 0, 40, 0, 1]>,<7,R![684, 0, 1]>],Snew);
    return Vf;
end function;