
// Make newform 1350.4.c.e in Magma, downloaded from the LMFDB on 19 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_e();".
// 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_e();".
// 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, 23], [-30, 0], [0, 34], [0, 42], [139, 0], [0, 192], [234, 0], [-55, 0], [0, 191], [-138, 0], [0, -53], [0, -366], [0, -330], [-396, 0], [23, 0], [0, 452], [-204, 0], [0, 691], [709, 0], [0, 1098], [-816, 0], [0, 905], [1278, 0], [0, -605], [0, -1488], [-593, 0], [0, 324], [0, 1928], [-2742, 0], [0, -1326], [-893, 0], [-2502, 0], [-2767, 0], [0, -2701], [0, -1748], [0, 534], [0, -192], [1140, 0], [398, 0], [-3474, 0], [0, 2713], [0, -4734], [-5132, 0], [5240, 0], [0, 4519], [0, -5064], [-2573, 0], [0, 4098], [-306, 0], [6482, 0], [5850, 0], [0, -5598], [0, -8286], [-504, 0], [-4489, 0], [0, 2213], [2718, 0], [0, -5615], [0, 1488], [0, 7487], [-8118, 0], [0, 5002], [0, -5082], [7625, 0], [0, -3778], [0, 8268], [-1379, 0], [0, 3072], [-7446, 0], [0, -6496], [0, 1633], [-6788, 0], [0, 6582], [2850, 0], [0, 7451], [-14124, 0], [-6374, 0], [3948, 0], [12629, 0], [-4842, 0], [0, -3851], [7435, 0], [0, -5760], [-2190, 0], [0, 7202], [13476, 0], [0, 10843], [0, -6108], [9852, 0], [0, 7796], [-2454, 0], [2953, 0], [0, -11322], [9696, 0], [12192, 0], [0, 8491], [-9355, 0], [0, -295], [0, 16914], [0, -12108], [-6960, 0], [-10687, 0], [0, -8329], [0, 25302], [0, -22248], [24252, 0], [-9829, 0], [0, -14155], [0, -23051], [0, 8352], [24331, 0], [2216, 0], [28500, 0], [0, 25252], [0, 28920], [0, 32268], [-10050, 0], [-4561, 0], [0, -21359], [0, -15042], [0, 27462], [6212, 0], [13224, 0], [-34709, 0], [32070, 0], [0, 125], [0, -32222], [19240, 0], [0, 30252], [-12517, 0], [0, 2201], [-8742, 0], [28618, 0], [0, 6594], [0, 15881], [0, 26052], [12648, 0], [27179, 0], [-11874, 0], [0, 18448], [0, 3234], [32155, 0], [-21996, 0], [0, -3278], [0, 21228], [5767, 0], [0, -5322], [0, -42097], [17658, 0], [0, 22297], [0, 10542], [0, 47639], [10326, 0], [-5147, 0], [-47064, 0], [0, -15385], [34914, 0], [0, -37434], [0, 8778], [0, -54061], [3084, 0], [0, -12048], [0, 33618], [25043, 0], [0, -17710], [60691, 0], [0, 13902], [-20508, 0], [46403, 0], [-26208, 0], [0, -55733], [-34976, 0], [19812, 0], [-60733, 0], [-57906, 0], [0, -36164], [10477, 0], [0, -62152], [-60846, 0], [0, 3979], [0, 39324], [0, 15948], [-28434, 0], [0, 16382], [0, 35692], [-37841, 0], [-27408, 0], [0, -19733], [0, 52050], [-49153, 0], [-6660, 0], [0, 3120], [0, 9270], [-1789, 0], [0, 43063], [0, -47196], [0, 12558], [-77172, 0], [-58417, 0], [0, -53431], [32947, 0], [-32106, 0], [0, -6582], [21955, 0], [0, 16002], [48966, 0], [-86092, 0], [0, -13570], [62106, 0], [0, -3116], [0, -4686], [-43206, 0], [21179, 0], [0, 49157], [-86610, 0], [0, -6804], [0, -67152], [72509, 0], [12169, 0], [-17022, 0], [0, 9880], [0, -46644], [43918, 0], [0, -40212], [-42678, 0], [0, 1208], [77448, 0], [0, 59143], [-17876, 0], [-91225, 0], [-12534, 0], [0, 74275], [0, 63144], [43855, 0], [0, 51360], [61596, 0], [-14964, 0], [0, 27750], [40448, 0], [0, 3775], [97486, 0], [0, -38382], [-105714, 0], [0, 72149], [55848, 0], [11647, 0], [0, -8364], [0, -113434], [101196, 0], [0, -11394], [6190, 0], [0, 1428], [35850, 0], [-26203, 0], [0, 16148], [0, 9336], [0, -101194], [0, 95737], [0, 107802], [-124661, 0], [0, -64895], [0, -23574], [-91748, 0], [23352, 0], [-93042, 0], [0, 45592], [0, 288], [64715, 0], [0, -88603], [0, 49498], [-88184, 0], [0, -53695], [0, 64201], [0, -62232], [21025, 0], [105443, 0], [-92430, 0], [0, -63648], [8984, 0], [0, 48654], [52706, 0], [0, 7508], [105750, 0], [0, -141698], [0, 125088], [101383, 0], [79482, 0], [146688, 0], [0, -38292], [0, -25896], [131796, 0], [0, -95003], [-38172, 0], [-14233, 0], [0, 70890], [4332, 0], [0, 23159], [0, 100861], [0, -38520], [29395, 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_e();".
// 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_e(: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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![529, 0, 1]>,<11,R![30, 1]>],Snew);
    return Vf;
end function;