
// Make newform 1350.4.c.q in Magma, downloaded from the LMFDB on 08 May 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_q();".
// 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_q();".
// 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, 4], [42, 0], [0, 20], [0, -93], [-59, 0], [0, 9], [-120, 0], [47, 0], [0, 262], [126, 0], [0, -178], [0, -144], [0, 741], [444, 0], [221, 0], [0, 538], [690, 0], [0, -1126], [-665, 0], [0, 75], [1086, 0], [0, -1544], [-132, 0], [0, -892], [0, 1140], [1735, 0], [0, -1434], [0, -686], [-114, 0], [0, -159], [-2276, 0], [1398, 0], [2624, 0], [0, 394], [0, -3346], [0, 1491], [0, 2403], [2640, 0], [1073, 0], [1470, 0], [0, -4720], [0, 765], [-668, 0], [4601, 0], [0, -2158], [0, -3123], [-2027, 0], [0, -438], [-6414, 0], [3431, 0], [7308, 0], [0, 3729], [0, -1956], [-990, 0], [8495, 0], [0, 1366], [5520, 0], [0, 5438], [0, -8253], [0, -9290], [-8112, 0], [0, -7900], [0, 4419], [-8200, 0], [0, 9556], [0, 10116], [6751, 0], [0, -4062], [8778, 0], [0, -956], [0, 2300], [-29, 0], [0, -8127], [-7938, 0], [0, -272], [-4554, 0], [-1001, 0], [-1794, 0], [-16129, 0], [13356, 0], [0, -11500], [11149, 0], [0, -3849], [18048, 0], [0, 4264], [10242, 0], [0, 3302], [0, -1923], [15246, 0], [0, 8206], [16806, 0], [5425, 0], [0, 19665], [-14724, 0], [-2058, 0], [0, 11912], [-5170, 0], [0, 4186], [0, 13026], [0, 10668], [-15372, 0], [-14989, 0], [0, 1066], [0, -621], [0, 20187], [-18228, 0], [-11743, 0], [0, 24418], [0, 2672], [0, -8601], [-21308, 0], [-19015, 0], [4416, 0], [0, 7580], [0, -14901], [0, -12915], [28128, 0], [-8362, 0], [0, 29708], [0, 6762], [0, 19155], [-22975, 0], [6450, 0], [-34538, 0], [27114, 0], [0, -236], [0, 27128], [-5249, 0], [0, -13896], [27665, 0], [0, 8122], [-10584, 0], [18619, 0], [0, -22251], [0, -24854], [0, 3681], [-5142, 0], [-18484, 0], [-25014, 0], [0, -32146], [0, -10977], [-36602, 0], [11076, 0], [0, 36848], [0, -26961], [415, 0], [0, 45501], [0, -35042], [-1080, 0], [0, -20164], [0, 20067], [0, 26524], [-35568, 0], [23704, 0], [-40590, 0], [0, 12964], [-29922, 0], [0, 5241], [0, -26214], [0, -18278], [24942, 0], [0, -11226], [0, 23073], [22037, 0], [0, -19082], [-2759, 0], [0, 14439], [-28356, 0], [38927, 0], [-1884, 0], [0, -29956], [11995, 0], [-61668, 0], [-6505, 0], [5904, 0], [0, -54862], [-6122, 0], [0, 55438], [1764, 0], [0, -62134], [0, 14502], [0, 12255], [-68004, 0], [0, -73856], [0, -7756], [-51053, 0], [-8376, 0], [0, -12802], [0, 20805], [73949, 0], [-12264, 0], [0, 4677], [0, -9525], [3977, 0], [0, 6956], [0, -64614], [0, 2784], [-4374, 0], [-48088, 0], [0, -74510], [40285, 0], [-4992, 0], [0, -14502], [-33440, 0], [0, 68127], [35100, 0], [51572, 0], [0, 16252], [-2466, 0], [0, -31840], [0, 70884], [82692, 0], [-55063, 0], [0, 40246], [46248, 0], [0, -21213], [0, -87567], [47858, 0], [11329, 0], [47616, 0], [0, 47630], [0, -53967], [-87491, 0], [0, -12093], [-71730, 0], [0, -40862], [31932, 0], [0, -12010], [16657, 0], [-9088, 0], [-49794, 0], [0, 82952], [0, -46407], [80875, 0], [0, -72885], [88194, 0], [85254, 0], [0, 39660], [13475, 0], [0, 67118], [-11513, 0], [0, 91890], [49974, 0], [0, -77252], [57684, 0], [-75692, 0], [0, 74391], [0, 5650], [-45882, 0], [0, -64635], [25171, 0], [0, 70569], [29616, 0], [-23611, 0], [0, -53804], [0, -76281], [0, 68092], [0, 92966], [0, -16437], [-83087, 0], [0, 86396], [0, 106785], [-7508, 0], [-102696, 0], [28110, 0], [0, -18934], [0, 37086], [-70861, 0], [0, -85166], [0, 48494], [-121151, 0], [0, 48958], [0, -116212], [0, -16221], [91519, 0], [-70783, 0], [-12138, 0], [0, 3624], [-61765, 0], [0, 33351], [-114361, 0], [0, 145348], [50400, 0], [0, 18038], [0, -38574], [-8189, 0], [-105816, 0], [-5448, 0], [0, 102099], [0, -4650], [127518, 0], [0, 100730], [71880, 0], [-22801, 0], [0, -25182], [76848, 0], [0, 44056], [0, -79066], [0, 159759], [-87392, 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_q();".
// 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_q(: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_q();".
// 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_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![16, 0, 1]>,<11,R![-42, 1]>],Snew);
    return Vf;
end function;