
// Make newform 1350.4.c.n in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1350_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1350_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_1350_4_c_n();".
// 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_1350_4_c_n();".
// 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 := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1350_c();"
function MakeCharacter_1350_c()
    N := 1350;
    order := 2;
    char_gens := [1001, 1027];
    v := [2, 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_1350_c_Hecke();"
function MakeCharacter_1350_c_Hecke(Kf)
    N := 1350;
    order := 2;
    char_gens := [1001, 1027];
    char_values := [[1, 0], [-1, 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+1)]];
    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, 0], [0, 8], [18, 0], [0, -8], [0, 15], [-23, 0], [0, -63], [-156, 0], [-85, 0], [0, 74], [246, 0], [0, 190], [0, 288], [0, 177], [-792, 0], [-907, 0], [0, -322], [-270, 0], [0, -254], [1123, 0], [0, 771], [198, 0], [0, -1192], [-1692, 0], [0, -1748], [0, -948], [-593, 0], [0, 1062], [0, 326], [-990, 0], [0, -147], [-1604, 0], [-1218, 0], [-2248, 0], [0, -2998], [0, -3470], [0, 387], [0, 855], [264, 0], [-2551, 0], [-2238, 0], [0, -2180], [0, 2577], [-1412, 0], [-307, 0], [0, -5234], [0, 1509], [-1211, 0], [0, -6246], [-4650, 0], [-3145, 0], [1020, 0], [0, 6741], [0, -2340], [6198, 0], [875, 0], [0, 5486], [-3204, 0], [0, -7322], [0, -1353], [0, 1658], [-1044, 0], [0, -2588], [0, -1449], [4880, 0], [0, -7744], [0, 804], [2815, 0], [0, 3738], [11022, 0], [0, 7544], [0, 5404], [2335, 0], [0, 6633], [7566, 0], [0, -7420], [-8502, 0], [1903, 0], [-13482, 0], [-1537, 0], [-10368, 0], [0, 13168], [-7319, 0], [0, 4119], [5388, 0], [0, -2752], [-4314, 0], [0, 5794], [0, 6309], [-14826, 0], [0, 6758], [-14574, 0], [-12611, 0], [0, -15639], [-15420, 0], [10494, 0], [0, 10708], [23030, 0], [0, -3814], [0, 22266], [0, 23844], [-7488, 0], [5111, 0], [0, 6986], [0, 20571], [0, -23241], [-20208, 0], [-9055, 0], [0, 15554], [0, 5632], [0, -9141], [13372, 0], [11165, 0], [-912, 0], [0, 27952], [0, -6285], [0, 16497], [-14844, 0], [31934, 0], [0, 24352], [0, -10374], [0, 7347], [-5371, 0], [7086, 0], [-17186, 0], [23814, 0], [0, -22732], [0, -4664], [-5501, 0], [0, 27096], [-5659, 0], [0, 37694], [-6588, 0], [19, 0], [0, -33639], [0, 23474], [0, 7917], [41202, 0], [35492, 0], [-7146, 0], [0, -8882], [0, -21705], [-29018, 0], [-31164, 0], [0, -49160], [0, -2349], [28195, 0], [0, 23997], [0, 46286], [39636, 0], [0, 16744], [0, 1251], [0, -36988], [16404, 0], [664, 0], [39642, 0], [0, -36028], [23058, 0], [0, 19953], [0, -25638], [0, -27034], [14802, 0], [0, -9186], [0, -31647], [-48823, 0], [0, -13066], [24361, 0], [0, -23013], [-31260, 0], [-8953, 0], [2760, 0], [0, -55628], [-11321, 0], [-17064, 0], [-59629, 0], [55644, 0], [0, 44794], [-38114, 0], [0, 2030], [47892, 0], [0, -29162], [0, 32118], [0, -22689], [42180, 0], [0, -17044], [0, -70844], [57379, 0], [-18636, 0], [0, 13954], [0, 62709], [-28783, 0], [-29208, 0], [0, -14643], [0, -31929], [-50407, 0], [0, -53876], [0, -32046], [0, 71448], [50706, 0], [-12400, 0], [0, 11774], [-22979, 0], [-65556, 0], [0, -9174], [48280, 0], [0, 70743], [86340, 0], [-11020, 0], [0, 7016], [44142, 0], [0, -33680], [0, -34788], [-64356, 0], [-72655, 0], [0, -29746], [52968, 0], [0, -62661], [0, -43923], [30434, 0], [-9299, 0], [46164, 0], [0, -19370], [0, 34041], [68293, 0], [0, 60087], [-74466, 0], [0, -20074], [9012, 0], [0, 1918], [-32339, 0], [48320, 0], [94338, 0], [0, 36340], [0, -36015], [-9461, 0], [0, 58239], [29886, 0], [-28146, 0], [0, -56700], [22871, 0], [0, -37478], [-84161, 0], [0, -106422], [-33198, 0], [0, 115484], [79008, 0], [-96476, 0], [0, 74823], [0, 7958], [-13902, 0], [0, 94245], [85147, 0], [0, -1875], [-85632, 0], [110693, 0], [0, 49376], [0, 93147], [0, -46960], [0, -44402], [0, -56973], [-88823, 0], [0, -1772], [0, 78021], [-19028, 0], [-3192, 0], [76434, 0], [0, 84022], [0, -64938], [-11773, 0], [0, 84998], [0, 134206], [-52571, 0], [0, -29002], [0, 89152], [0, -44253], [40783, 0], [-34663, 0], [-129258, 0], [0, -62640], [95807, 0], [0, 113535], [6311, 0], [0, -94084], [-59988, 0], [0, 60418], [0, -85566], [93751, 0], [-22440, 0], [32568, 0], [0, 100995], [0, -11850], [-122166, 0], [0, 31930], [139104, 0], [-25213, 0], [0, -165102], [-73872, 0], [0, 80012], [0, 112246], [0, 13251], [2800, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_4_c_n();".
// 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_1350_4_c_n(:prec:=2)
    chi := MakeCharacter_1350_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(1999) - 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_1350_4_c_n();".
// 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_1350_4_c_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![64, 0, 1]>,<11,R![-18, 1]>],Snew);
    return Vf;
end function;