
// Make newform 1350.4.c.l in Magma, downloaded from the LMFDB on 25 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_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_1350_4_c_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 := [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, 22], [12, 0], [0, 38], [0, -105], [157, 0], [0, 117], [66, 0], [-25, 0], [0, -314], [504, 0], [0, 380], [0, -252], [0, -3], [-318, 0], [293, 0], [0, 322], [120, 0], [0, 44], [-917, 0], [0, -309], [1272, 0], [0, -1328], [492, 0], [0, 548], [0, 732], [907, 0], [0, 1542], [0, 2554], [150, 0], [0, 1653], [-1124, 0], [1608, 0], [-2488, 0], [0, 2968], [0, 3170], [0, 327], [0, -1305], [-4044, 0], [-1051, 0], [2598, 0], [0, 4370], [0, -2943], [4768, 0], [-1267, 0], [0, -2986], [0, 5409], [-4331, 0], [0, -2586], [510, 0], [-205, 0], [4680, 0], [0, -6159], [0, 6240], [-7758, 0], [-7345, 0], [0, 3004], [-2046, 0], [0, -5488], [0, -333], [0, -2918], [5754, 0], [0, 3368], [0, 2871], [-10540, 0], [0, -5006], [0, -36], [6715, 0], [0, -12822], [5478, 0], [0, 2446], [0, 11696], [2095, 0], [0, 11313], [2124, 0], [0, -6410], [9882, 0], [-5897, 0], [6852, 0], [323, 0], [-10242, 0], [0, -14398], [-4079, 0], [0, -5781], [-15078, 0], [0, -4268], [5634, 0], [0, 4526], [0, 969], [9756, 0], [0, -8768], [2274, 0], [1969, 0], [0, 10701], [12420, 0], [18816, 0], [0, -16798], [-5890, 0], [0, -5516], [0, 4146], [0, 21444], [14778, 0], [9131, 0], [0, 2344], [0, -26829], [0, -8181], [24078, 0], [22565, 0], [0, 14716], [0, -7552], [0, -3981], [-13928, 0], [18605, 0], [-14928, 0], [0, -6082], [0, 4875], [0, 5157], [-1506, 0], [-2386, 0], [0, 21158], [0, 26826], [0, -32493], [-7531, 0], [-24306, 0], [27454, 0], [-5334, 0], [0, -26048], [0, -33136], [11599, 0], [0, -26424], [13661, 0], [0, 22846], [-20862, 0], [22219, 0], [0, -17619], [0, -15584], [0, -13023], [-25872, 0], [22052, 0], [-1914, 0], [0, -11068], [0, -21405], [40042, 0], [17904, 0], [0, -21580], [0, 17151], [-33425, 0], [0, -6603], [0, 43384], [-12726, 0], [0, 2786], [0, -4389], [0, 24868], [126, 0], [16144, 0], [-42192, 0], [0, -3272], [-20838, 0], [0, 13353], [0, -13098], [0, -19826], [-23322, 0], [0, -47346], [0, 33033], [6017, 0], [0, 34216], [-32099, 0], [0, -22773], [-45660, 0], [-1033, 0], [-48570, 0], [0, 54428], [-281, 0], [-60606, 0], [-19969, 0], [49626, 0], [0, 37496], [10006, 0], [0, 49300], [-4752, 0], [0, 2882], [0, -8922], [0, 64011], [36540, 0], [0, 27394], [0, 39584], [26599, 0], [-36174, 0], [0, 66686], [0, 42069], [24197, 0], [-66792, 0], [0, -17763], [0, -8889], [-51067, 0], [0, -38584], [0, -19806], [0, -19632], [11304, 0], [-56260, 0], [0, -12014], [58501, 0], [52746, 0], [0, -87594], [-11300, 0], [0, -6477], [58140, 0], [59060, 0], [0, -12566], [54828, 0], [0, -520], [0, -40068], [-71244, 0], [-1675, 0], [0, 53296], [-75768, 0], [0, 50499], [0, -33843], [-51286, 0], [-92999, 0], [-53394, 0], [0, -16360], [0, -67479], [-45767, 0], [0, -77313], [102816, 0], [0, 12994], [20628, 0], [0, -19588], [89341, 0], [43040, 0], [27042, 0], [0, 38330], [0, 345], [-7721, 0], [0, 53679], [5514, 0], [94836, 0], [0, -30300], [33671, 0], [0, -34762], [15379, 0], [0, -84942], [21378, 0], [0, 2776], [-28038, 0], [84004, 0], [0, 34203], [0, 73582], [-74178, 0], [0, -36075], [41047, 0], [0, 62865], [44112, 0], [-967, 0], [0, 38914], [0, -31593], [0, 44710], [0, 70232], [0, 13287], [-7523, 0], [0, -66388], [0, -10719], [22732, 0], [124872, 0], [76506, 0], [0, -5002], [0, 16302], [86207, 0], [0, 40402], [0, 59024], [5209, 0], [0, -96068], [0, -45562], [0, 12567], [-30557, 0], [5177, 0], [-67152, 0], [0, -61440], [-41893, 0], [0, 27975], [47531, 0], [0, -60716], [-44982, 0], [0, -16558], [0, 153774], [10351, 0], [-90600, 0], [-64968, 0], [0, -79905], [0, -116670], [-78054, 0], [0, 66440], [-137004, 0], [-3793, 0], [0, -70002], [-40488, 0], [0, 7678], [0, -100576], [0, 148491], [-31520, 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_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_1350_4_c_l(: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_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_1350_4_c_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![484, 0, 1]>,<11,R![-12, 1]>],Snew);
    return Vf;
end function;