
// Make newform 1350.4.c.r 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_r();".
// 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_r();".
// 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, 34], [48, 0], [0, -70], [0, -27], [-119, 0], [0, 51], [-30, 0], [-133, 0], [0, -218], [-156, 0], [0, -88], [0, -516], [0, 639], [-654, 0], [461, 0], [0, -182], [-900, 0], [0, 704], [1375, 0], [0, -915], [-1116, 0], [0, 16], [-348, 0], [0, -412], [0, -900], [115, 0], [0, -966], [0, -1406], [-246, 0], [0, 519], [-1316, 0], [372, 0], [-1456, 0], [0, -956], [0, -2446], [0, -3111], [0, 2397], [-540, 0], [2333, 0], [2730, 0], [0, -4570], [0, 675], [3112, 0], [2441, 0], [0, -3418], [0, -4377], [-4187, 0], [0, 1098], [6474, 0], [3251, 0], [-1728, 0], [0, -5469], [0, 3216], [-8010, 0], [-3805, 0], [0, -3224], [4530, 0], [0, -3292], [0, 7953], [0, 5290], [-5358, 0], [0, 5600], [0, 7341], [380, 0], [0, -434], [0, 8004], [-1109, 0], [0, 7662], [-8478, 0], [0, -13286], [0, 3080], [-10109, 0], [0, 8727], [-2712, 0], [0, 8818], [-3306, 0], [-6401, 0], [-2256, 0], [1811, 0], [5454, 0], [0, 2990], [-9371, 0], [0, -6171], [4122, 0], [0, -7076], [-762, 0], [0, 8822], [0, -4977], [10104, 0], [0, -14924], [-1146, 0], [14965, 0], [0, -15525], [-8196, 0], [-4932, 0], [0, -5938], [-6730, 0], [0, 17656], [0, 7974], [0, 25332], [-1038, 0], [15671, 0], [0, 916], [0, 9141], [0, -5247], [-24162, 0], [14357, 0], [0, -3152], [0, 4592], [0, -7359], [15712, 0], [-3175, 0], [-96, 0], [0, -18070], [0, 1341], [0, 24495], [-12378, 0], [-24442, 0], [0, 2378], [0, 5478], [0, -8595], [-31615, 0], [-29790, 0], [-3818, 0], [-28314, 0], [0, -56], [0, -34432], [1051, 0], [0, -39144], [-1735, 0], [0, -6698], [-38766, 0], [-23501, 0], [0, 3591], [0, 20716], [0, -42981], [-2268, 0], [11756, 0], [-8646, 0], [0, 10784], [0, 42597], [26458, 0], [-11496, 0], [0, 21548], [0, 6261], [3355, 0], [0, -19701], [0, -16292], [-9270, 0], [0, 38486], [0, 1893], [0, -44876], [-23802, 0], [24784, 0], [9060, 0], [0, -6176], [4182, 0], [0, 44079], [0, -12726], [0, -45218], [3978, 0], [0, 23466], [0, -47913], [31997, 0], [0, 45628], [-27299, 0], [0, -8679], [31596, 0], [-45313, 0], [39894, 0], [0, 53804], [11275, 0], [-21462, 0], [25715, 0], [63306, 0], [0, -43612], [-56882, 0], [0, 2608], [-9384, 0], [0, -35134], [0, 58698], [0, -29595], [-10236, 0], [0, 47734], [0, 5384], [-53273, 0], [-7254, 0], [0, -57202], [0, -43845], [-6271, 0], [-3336, 0], [0, 1323], [0, 46725], [72677, 0], [0, -48544], [0, -40746], [0, -10584], [-62196, 0], [-21868, 0], [0, 5650], [37285, 0], [18882, 0], [0, 15642], [-1820, 0], [0, -42987], [37140, 0], [-13228, 0], [0, -21098], [-18264, 0], [0, 33320], [0, 2076], [54588, 0], [57917, 0], [0, -26444], [-14568, 0], [0, 53973], [0, -29793], [-42982, 0], [-28451, 0], [-86226, 0], [0, -47140], [0, 11487], [70369, 0], [0, 52293], [-67860, 0], [0, -26822], [-42612, 0], [0, -49480], [-22223, 0], [-4768, 0], [76974, 0], [0, 8102], [0, 53727], [-19865, 0], [0, 45045], [-65994, 0], [108576, 0], [0, 53940], [-107485, 0], [0, 88958], [6667, 0], [0, 38310], [-97914, 0], [0, 448], [3066, 0], [-26732, 0], [0, 22149], [0, -5690], [-93798, 0], [0, -63285], [56671, 0], [0, 99651], [57744, 0], [-27511, 0], [0, 33046], [0, -90099], [0, -2918], [0, -37924], [0, 52017], [81493, 0], [0, 95276], [0, -60045], [87532, 0], [85896, 0], [69510, 0], [0, 57206], [0, -56406], [128639, 0], [0, -41366], [0, 10964], [-42491, 0], [0, 85048], [0, -24622], [0, -130119], [-90461, 0], [6977, 0], [33708, 0], [0, 33576], [-96505, 0], [0, -28911], [-144421, 0], [0, 33028], [-88110, 0], [0, 72218], [0, -73086], [63691, 0], [62136, 0], [-44952, 0], [0, 127521], [0, -75810], [126942, 0], [0, 51140], [-10860, 0], [148619, 0], [0, 138882], [-8568, 0], [0, 29266], [0, 134804], [0, -142119], [156688, 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_r();".
// 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_r(: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_r();".
// 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_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![1156, 0, 1]>,<11,R![-48, 1]>],Snew);
    return Vf;
end function;