
// Make newform 1350.4.c.o 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_o();".
// 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_o();".
// 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, 13], [30, 0], [0, -61], [0, 12], [49, 0], [0, -18], [-186, 0], [-160, 0], [0, 91], [-378, 0], [0, -268], [0, 144], [0, -570], [204, 0], [-877, 0], [0, 187], [606, 0], [0, 431], [-1151, 0], [0, -102], [984, 0], [0, 265], [1248, 0], [0, -1225], [0, -78], [-2198, 0], [0, -1986], [0, -2792], [708, 0], [0, -1686], [307, 0], [-1812, 0], [203, 0], [0, 214], [0, -673], [0, -3696], [0, -3132], [510, 0], [-1087, 0], [4056, 0], [0, 473], [0, 2556], [2923, 0], [-3175, 0], [0, -2176], [0, -3834], [3202, 0], [0, -4152], [-5466, 0], [-943, 0], [7290, 0], [0, 312], [0, 8004], [-324, 0], [-7849, 0], [0, 5758], [2688, 0], [0, 3260], [0, -5922], [0, -3728], [732, 0], [0, 5357], [0, -4572], [845, 0], [0, -8723], [0, 9018], [-5759, 0], [0, 5772], [-2046, 0], [0, 1069], [0, 7133], [8557, 0], [0, -14328], [13500, 0], [0, -1334], [-3474, 0], [-569, 0], [-9132, 0], [-2971, 0], [-12042, 0], [0, -8566], [-7400, 0], [0, 2580], [13200, 0], [0, -18038], [-5544, 0], [0, -17137], [0, -15888], [3942, 0], [0, -1379], [-14214, 0], [-9992, 0], [0, 21258], [-16614, 0], [-11838, 0], [0, 2201], [-10795, 0], [0, 14185], [0, -3576], [0, 9132], [25020, 0], [-15997, 0], [0, 5971], [0, 19242], [0, -8118], [1902, 0], [-14074, 0], [0, 13825], [0, 15569], [0, 11922], [-6899, 0], [11711, 0], [-9240, 0], [0, -17908], [0, 7530], [0, 22788], [16440, 0], [-12421, 0], [0, 6461], [0, -912], [0, 14442], [1892, 0], [7914, 0], [1291, 0], [-30210, 0], [0, -15680], [0, 13898], [-35300, 0], [0, -28188], [25163, 0], [0, -7979], [-26622, 0], [35413, 0], [0, 33834], [0, -13469], [0, -21168], [408, 0], [-36916, 0], [24636, 0], [0, -18187], [0, 1464], [12295, 0], [46884, 0], [0, 12197], [0, -28182], [-25433, 0], [0, 16968], [0, 22423], [-8442, 0], [0, 41207], [0, 8472], [0, 21799], [-23544, 0], [-11072, 0], [-21654, 0], [0, 42835], [48534, 0], [0, 14676], [0, -27372], [0, -3581], [1824, 0], [0, -29778], [0, -9402], [-24907, 0], [0, -27830], [25771, 0], [0, -45948], [35862, 0], [52778, 0], [-31668, 0], [0, -44113], [45799, 0], [22122, 0], [48692, 0], [4374, 0], [0, -60019], [39382, 0], [0, 15343], [-31356, 0], [0, -9646], [0, 23784], [0, -21012], [-32814, 0], [0, 49237], [0, 23807], [-68441, 0], [62772, 0], [0, 67847], [0, -60720], [-39703, 0], [40560, 0], [0, -14460], [0, 34410], [65591, 0], [0, 8063], [0, 76854], [0, -55902], [-38232, 0], [-53677, 0], [0, -69731], [14887, 0], [-57126, 0], [0, -36582], [-44915, 0], [0, -23298], [35766, 0], [11423, 0], [0, -2405], [57636, 0], [0, -37591], [0, -4986], [55854, 0], [72179, 0], [0, 14092], [-26250, 0], [0, 26586], [0, 55698], [7709, 0], [-24716, 0], [41628, 0], [0, 56000], [0, -38454], [-19667, 0], [0, -6312], [8082, 0], [0, -15887], [24408, 0], [0, -23197], [-9236, 0], [27920, 0], [23766, 0], [0, -92485], [0, -61656], [-15245, 0], [0, 70680], [84426, 0], [-44124, 0], [0, -3750], [17903, 0], [0, -89095], [3121, 0], [0, -2592], [-68514, 0], [0, 40279], [10968, 0], [26332, 0], [0, 58386], [0, 3166], [4716, 0], [0, 56976], [35215, 0], [0, -12942], [-89880, 0], [-74443, 0], [0, 105928], [0, 32946], [0, -30674], [0, -22513], [0, -55878], [106219, 0], [0, 14405], [0, 19296], [-23708, 0], [-30378, 0], [-97302, 0], [0, -98908], [0, 54948], [-57505, 0], [0, -86363], [0, 99578], [-12719, 0], [0, 48490], [0, -39469], [0, -127122], [146590, 0], [-15802, 0], [-113430, 0], [0, 128802], [104204, 0], [0, -16206], [55091, 0], [0, -90767], [-54540, 0], [0, 112727], [0, 118728], [-82457, 0], [29622, 0], [-21822, 0], [0, 24198], [0, 142134], [-54204, 0], [0, 100622], [83928, 0], [-61843, 0], [0, 22140], [44742, 0], [0, 130699], [0, 80261], [0, 72810], [43540, 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_o();".
// 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_o(: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_o();".
// 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_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![169, 0, 1]>,<11,R![-30, 1]>],Snew);
    return Vf;
end function;