
// Make newform 650.4.c.f in Magma, downloaded from the LMFDB on 03 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_650_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_650_c_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_c_f();".
// 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_c_f();".
// 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 := [2916, 0, 109, 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, 55, 0, 1], [55, 0, 1, 0]];
    Rf_basisdens := [1, 1, 54, 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_c();"
function MakeCharacter_650_c()
    N := 650;
    order := 2;
    char_gens := [27, 301];
    v := [1, 1];
    // 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_c_Hecke();"
function MakeCharacter_650_c_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 := [[2, 0, 0, 0], [0, 1, -1, 0], [0, 0, 0, 0], [-4, 0, 0, 1], [0, -6, -12, 0], [-8, -1, -28, 5], [0, -5, -9, 0], [0, -12, -66, 0], [0, -10, -54, 0], [-194, 0, 0, 14], [0, -2, 204, 0], [-2, 0, 0, 17], [0, -32, -168, 0], [0, 25, -97, 0], [228, 0, 0, 9], [0, 12, 18, 0], [0, 20, 342, 0], [-118, 0, 0, -46], [-22, 0, 0, -50], [0, 45, -15, 0], [500, 0, 0, -50], [324, 0, 0, 74], [-670, 0, 0, 88], [0, 138, -282, 0], [216, 0, 0, 132], [74, 0, 0, 214], [0, -102, 614, 0], [0, -112, -1332, 0], [0, 53, 1803, 0], [0, -128, 522, 0], [0, 166, -142, 0], [-446, 0, 0, -157], [1028, 0, 0, 70], [-442, 0, 0, -163], [0, 166, 1590, 0], [0, 151, -1521, 0], [0, -76, 286, 0], [-2462, 0, 0, 128], [-210, 0, 0, 234], [0, -132, -54, 0], [-1038, 0, 0, 399], [334, 0, 0, 388], [-4200, 0, 0, 60], [1708, 0, 0, 110], [190, 0, 0, -271], [-2448, 0, 0, 20], [-390, 0, 0, 199], [-3116, 0, 0, -157], [-806, 0, 0, 566], [0, -259, -1461, 0], [0, -99, -1503, 0], [0, 217, -1431, 0], [0, -106, 930, 0], [932, 0, 0, -104], [0, 723, -729, 0], [0, 264, -1584, 0], [2446, 0, 0, -466], [0, 53, -6255, 0], [0, 614, 1924, 0], [0, -418, 4722, 0], [0, 240, -1820, 0], [3562, 0, 0, 275], [-826, 0, 0, -164], [-1348, 0, 0, -326], [0, 333, 1465, 0], [5304, 0, 0, 378], [0, -616, 3342, 0], [0, 1041, -583, 0], [0, 297, 6615, 0], [0, 271, 8313, 0], [2492, 0, 0, -434], [0, -574, 1884, 0], [0, 504, -5672, 0], [0, 118, 9736, 0], [0, -1420, -2490, 0], [4820, 0, 0, 307], [-5646, 0, 0, -780], [-2072, 0, 0, 1754], [0, -654, 6198, 0], [0, -334, -7314, 0], [-5086, 0, 0, 991], [0, -421, -8067, 0], [0, 943, 3039, 0], [0, 1551, -3377, 0], [-11676, 0, 0, 262], [0, -323, -2565, 0], [0, 1392, -2688, 0], [11060, 0, 0, -338], [0, -621, -11667, 0], [-462, 0, 0, 1530], [0, -696, -6084, 0], [0, -429, 5031, 0], [14142, 0, 0, -294], [-4690, 0, 0, 253], [0, -830, 8712, 0], [0, -1650, -2574, 0], [0, -882, 7686, 0], [-6612, 0, 0, 1941], [0, 52, 4736, 0], [0, 163, 3885, 0], [0, 1499, 565, 0], [6354, 0, 0, 2127], [0, 937, 9063, 0], [12872, 0, 0, 673], [16226, 0, 0, -1009], [-1388, 0, 0, -502], [3662, 0, 0, -1340], [5768, 0, 0, -1796], [15132, 0, 0, -30], [15472, 0, 0, -993], [0, -1054, -15482, 0], [-6056, 0, 0, -766], [-1328, 0, 0, 2852], [0, 14, 12420, 0], [0, -1385, -561, 0], [1218, 0, 0, 276], [-25530, 0, 0, 114], [0, 118, 1098, 0], [0, 278, -12240, 0], [4588, 0, 0, -3004], [0, -394, -25938, 0], [0, 113, 17597, 0], [0, -204, 14238, 0], [14490, 0, 0, -288], [0, 602, -11796, 0], [12982, 0, 0, 284], [0, -378, 18006, 0], [-8912, 0, 0, 1280], [0, -1076, 25436, 0], [-19646, 0, 0, 1499], [0, 1106, -7896, 0], [10648, 0, 0, 833], [-352, 0, 0, -1608], [0, 1552, -16702, 0], [0, 102, 26202, 0], [0, 1752, -9960, 0], [-3930, 0, 0, -567], [-6278, 0, 0, -1930], [0, -1340, 3150, 0], [19340, 0, 0, 1783], [0, 1522, -12660, 0], [0, -1569, -14631, 0], [0, 5330, 5438, 0], [-10818, 0, 0, -2148], [-1698, 0, 0, -2782], [0, -2126, 23244, 0], [-14914, 0, 0, -1043], [0, 2552, -14274, 0], [-1420, 0, 0, -3564], [2704, 0, 0, 1625], [-4586, 0, 0, -1159], [-13164, 0, 0, -471], [0, 1579, -26003, 0], [0, -876, 19188, 0], [0, 1575, 21377, 0], [21480, 0, 0, -996], [-9408, 0, 0, -3244], [0, -420, -1404, 0], [0, -1428, 23978, 0], [0, -4615, 20367, 0], [-4286, 0, 0, -4606], [0, 2379, 33147, 0], [-10292, 0, 0, -4639], [9678, 0, 0, 1869], [8664, 0, 0, 1980], [7068, 0, 0, 3291], [1852, 0, 0, -4082], [0, 502, 1348, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_650_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_650_4_c_f();".
// 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_c_f(:prec:=4)
    chi := MakeCharacter_650_c();
    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_c_f();".
// 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_c_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_650_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![2704, 0, 113, 0, 1]>,<7,R![-42, 7, 1]>],Snew);
    return Vf;
end function;