
// Make newform 1350.4.c.h 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_h();".
// 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_h();".
// 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, 19], [-12, 0], [0, 50], [0, -126], [-29, 0], [0, -18], [102, 0], [-265, 0], [0, -65], [-240, 0], [0, -367], [0, -72], [0, 636], [102, 0], [-103, 0], [0, 52], [582, 0], [0, 65], [-173, 0], [0, -498], [-822, 0], [0, -821], [1200, 0], [0, -2041], [0, -1278], [205, 0], [0, 1500], [0, -416], [1902, 0], [0, -2712], [367, 0], [3006, 0], [2651, 0], [0, -2801], [0, 1412], [0, -2154], [0, -234], [2472, 0], [-190, 0], [-1524, 0], [0, 3335], [0, -4440], [-2192, 0], [-1732, 0], [0, -5989], [0, -3300], [-4379, 0], [0, -2958], [-2676, 0], [3626, 0], [2046, 0], [0, 5700], [0, 7674], [4326, 0], [6473, 0], [0, 7825], [-2760, 0], [0, -4801], [0, 8166], [0, 577], [7656, 0], [0, 2726], [0, -9450], [3089, 0], [0, 7894], [0, -3450], [-2261, 0], [0, -11544], [-198, 0], [0, -10388], [0, -4867], [-656, 0], [0, -3078], [1644, 0], [0, -5729], [1776, 0], [-12842, 0], [-11298, 0], [3431, 0], [-10530, 0], [0, 3179], [-6047, 0], [0, -16554], [-4446, 0], [0, -146], [-9822, 0], [0, 7931], [0, 18714], [12786, 0], [0, -10400], [19548, 0], [-14939, 0], [0, -4098], [-12216, 0], [-18492, 0], [0, -5467], [6983, 0], [0, -9281], [0, -1986], [0, 12672], [-8370, 0], [-19675, 0], [0, -26951], [0, -10986], [0, 11226], [-11400, 0], [-6469, 0], [0, -6383], [0, -10843], [0, 25236], [-24809, 0], [-11476, 0], [-25350, 0], [0, -14164], [0, -7536], [0, 432], [-10782, 0], [26057, 0], [0, 19091], [0, 1044], [0, -26046], [-28060, 0], [-16794, 0], [-2495, 0], [1950, 0], [0, -16127], [0, -12634], [10420, 0], [0, 21936], [-21715, 0], [0, 19849], [29952, 0], [-17582, 0], [0, -19194], [0, 9823], [0, 22188], [9654, 0], [-32377, 0], [-23952, 0], [0, 5072], [0, -3024], [3049, 0], [-40374, 0], [0, 40322], [0, -19932], [-34553, 0], [0, -6918], [0, -6497], [44082, 0], [0, 10127], [0, -12936], [0, 45853], [34530, 0], [31015, 0], [36186, 0], [0, 1441], [33168, 0], [0, -42054], [0, -26460], [0, 29239], [54288, 0], [0, -38634], [0, 19548], [28445, 0], [0, 48706], [32719, 0], [0, -4830], [37350, 0], [-37135, 0], [-672, 0], [0, 50525], [51880, 0], [18450, 0], [-16213, 0], [-11478, 0], [0, -8608], [-20981, 0], [0, -67544], [-18240, 0], [0, -6121], [0, -66810], [0, -23574], [-4872, 0], [0, -17894], [0, 16136], [16675, 0], [-26058, 0], [0, 34013], [0, -67482], [-4969, 0], [31608, 0], [0, -44004], [0, 19938], [34751, 0], [0, 81047], [0, -40812], [0, 12264], [-36900, 0], [8993, 0], [0, 54061], [-32321, 0], [-3804, 0], [0, -16830], [62989, 0], [0, -3318], [4962, 0], [-85672, 0], [0, 64558], [-70590, 0], [0, -89116], [0, 8796], [-18114, 0], [-7297, 0], [0, -42311], [56538, 0], [0, -16296], [0, 3912], [-36061, 0], [-28529, 0], [81450, 0], [0, -53980], [0, -58236], [-13874, 0], [0, 57564], [62838, 0], [0, 17776], [46200, 0], [0, 7595], [97792, 0], [-86479, 0], [-24720, 0], [0, -101743], [0, 51636], [22939, 0], [0, -23484], [-53532, 0], [-44214, 0], [0, 73572], [-37420, 0], [0, 72203], [-75134, 0], [0, -50394], [-59598, 0], [0, -44219], [-59040, 0], [-76217, 0], [0, -78714], [0, 40102], [-50334, 0], [0, -73848], [40714, 0], [0, -66948], [-22536, 0], [55571, 0], [0, 88180], [0, 48354], [0, -76214], [0, 28541], [0, 15192], [43045, 0], [0, 107945], [0, 37872], [78100, 0], [77406, 0], [-26406, 0], [0, -73564], [0, -61830], [30149, 0], [0, -125849], [0, 22322], [69316, 0], [0, 88555], [0, 42269], [0, 51378], [-115601, 0], [-31981, 0], [-84642, 0], [0, -88680], [-97612, 0], [0, 129210], [147458, 0], [0, -148628], [81402, 0], [0, -48478], [0, -41946], [124945, 0], [-98718, 0], [91578, 0], [0, 33738], [0, -38412], [-27678, 0], [0, 74969], [98736, 0], [42761, 0], [0, 18978], [50478, 0], [0, -98003], [0, 102503], [0, 37500], [-32807, 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_h();".
// 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_h(: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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![361, 0, 1]>,<11,R![12, 1]>],Snew);
    return Vf;
end function;