
// Make newform 650.3.k.g in Magma, downloaded from the LMFDB on 04 November 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_650_k();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_650_k_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_3_k_g();".
// 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_3_k_g();".
// 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 := [9, 0, 0, 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, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 3, 3];
    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_k();"
function MakeCharacter_650_k()
    N := 650;
    order := 4;
    char_gens := [27, 301];
    v := [4, 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_k_Hecke();"
function MakeCharacter_650_k_Hecke( : Kf := false)
    N := 650;
    order := 4;
    char_gens := [27, 301];
    char_values := [[1, 0, 0, 0], [0, 0, 1, 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 := 3;
    raw_aps := [[1, 0, 1, 0], [-2, -1, 0, 1], [0, 0, 0, 0], [3, 0, -3, 3], [1, 0, -1, -9], [0, 0, 13, 0], [0, -6, -3, -6], [6, 0, 6, 0], [0, -3, 26, -3], [19, -12, 0, 12], [15, 3, 15, 0], [-17, 0, 17, -12], [16, -24, 16, 0], [0, 9, 38, 9], [-3, 0, 3, 51], [-65, 6, 0, -6], [13, 0, -13, 33], [-25, 18, 0, -18], [-11, 39, -11, 0], [14, 48, 14, 0], [-9, 0, 9, -48], [-16, 24, 0, -24], [-35, -33, -35, 0], [21, 0, -21, 12], [32, -24, 32, 0], [0, 30, -23, 30], [0, 48, 68, 48], [122, 15, 0, -15], [-19, 72, -19, 0], [16, -12, 0, 12], [0, -24, 112, -24], [-2, -39, 0, 39], [101, 0, -101, -12], [-118, -57, 0, 57], [100, 36, 100, 0], [77, 0, -77, -3], [147, 12, 0, -12], [-160, 0, 160, 30], [74, 0, -74, -96], [0, -54, -185, -54], [0, 0, 140, 0], [0, 72, -69, 72], [-16, -24, 0, 24], [156, 0, -156, -84], [-112, 48, -112, 0], [0, -24, 208, -24], [162, 39, 0, -39], [160, -42, 160, 0], [-69, -9, -69, 0], [24, 0, -24, 192], [0, 0, -94, 0], [129, -123, 129, 0], [68, 0, -68, 156], [0, 96, 168, 96], [0, 24, 377, 24], [162, 99, 0, -99], [-251, -84, 0, 84], [237, 0, -237, -3], [0, 96, -62, 96], [-120, 0, 120, -72], [0, -87, 18, -87], [-88, 0, 88, 48], [-86, 0, 86, -48], [0, 45, 422, 45], [-125, -186, 0, 186], [-116, -108, -116, 0], [-210, -192, -210, 0], [0, -90, 125, -90], [-98, 57, 0, -57], [-84, 0, 84, 84], [123, -60, 123, 0], [297, 0, -297, 51], [-190, 123, 0, -123], [-235, 120, 0, -120], [199, -39, 199, 0], [-48, -378, -48, 0], [0, 120, -304, 120], [-441, 0, 441, 36], [48, 0, -48, -144], [-111, -288, -111, 0], [598, -33, 0, 33], [-60, 12, -60, 0], [288, 6, 288, 0], [0, 12, -104, 12], [0, 192, -312, 192], [318, -15, 0, 15], [81, 0, -81, -264], [201, 96, 201, 0], [4, -180, 4, 0], [-169, 0, 169, -291], [0, 111, -350, 111], [-31, 0, 31, -267], [-219, -99, -219, 0], [0, 249, -58, 249], [105, 9, 105, 0], [284, 144, 0, -144], [224, -216, 224, 0], [-320, -180, 0, 180], [160, 0, 0, 0], [-140, 0, 140, 36], [42, -327, 0, 327], [-4, 0, 4, 132], [0, -168, -512, -168], [0, -24, -751, -24], [0, -72, -420, -72], [-56, 576, -56, 0], [-415, -39, -415, 0], [501, 0, -501, -132], [410, -213, 0, 213], [-283, 6, 0, -6], [258, 195, 0, -195], [216, -144, 216, 0], [19, 372, 19, 0], [-106, 0, 106, -144], [96, 0, -96, -186], [0, 318, -133, 318], [378, -144, 378, 0], [0, -27, -38, -27], [285, -180, 0, 180], [-356, 360, 0, -360], [665, 0, -665, -84], [0, 54, -579, 54], [-190, 96, 0, -96], [81, 0, -81, -9], [485, 153, 485, 0], [0, -216, -659, -216], [-456, 0, 456, -120], [0, -315, -22, -315], [0, 216, -356, 216], [99, 288, 99, 0], [-183, 0, 183, -519], [367, 117, 367, 0], [0, -99, -982, -99], [-279, -474, 0, 474], [-124, 0, 124, -420], [-120, 432, -120, 0], [-312, 240, -312, 0], [399, 0, -399, 447], [0, 240, -245, 240], [1194, 0, 0, 0], [247, 159, 247, 0], [-324, -60, -324, 0], [0, 120, -772, 120], [-431, 0, 431, 255], [0, 78, -1231, 78], [-286, 0, 286, 240], [315, 0, -315, 48], [0, -60, -328, -60], [-1146, -39, 0, 39], [327, -387, 327, 0], [297, -324, 297, 0], [0, 144, -671, 144], [0, -504, -224, -504], [-456, -48, 0, 48], [0, -408, 256, -408], [1652, -24, 0, 24], [-288, -336, 0, 336], [465, 168, 465, 0], [721, 264, 0, -264], [431, -492, 431, 0], [29, 0, -29, 87], [0, -84, 111, -84], [1139, -165, 1139, 0], [-1158, 9, 0, -9], [-85, -324, -85, 0], [-511, 0, 511, 357], [598, -195, 0, 195], [-1, 270, 0, -270]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_650_k_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_650_3_k_g();".
// 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_3_k_g(:prec:=4)
    chi := MakeCharacter_650_k();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_k_g();".
// 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_3_k_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_650_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![-2, 4, 1]>],Snew);
    return Vf;
end function;