
// Make newform 1815.4.a.l in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1815_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1815_4_a_l();".
// 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_1815_4_a_l();".
// 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 := [-3, 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_1815_a();"
function MakeCharacter_1815_a()
    N := 1815;
    order := 1;
    char_gens := [1211, 727, 1696];
    v := [1, 1, 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;

function MakeCharacter_1815_a_Hecke(Kf)
    return MakeCharacter_1815_a();
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], [3, 0], [5, 0], [0, 18], [0, 0], [0, -44], [0, 27], [0, -18], [195, 0], [0, 20], [97, 0], [274, 0], [0, 222], [0, 240], [3, 0], [3, 0], [-648, 0], [0, -265], [70, 0], [-372, 0], [0, 540], [0, 301], [0, 26], [1122, 0], [470, 0], [0, -1116], [968, 0], [0, -93], [0, -136], [-1653, 0], [0, -1188], [0, -1242], [921, 0], [0, 997], [0, -1164], [0, -447], [-3602, 0], [-1672, 0], [0, 1459], [0, 1008], [1998, 0], [-4534, 0], [2754, 0], [0, -446], [0, -1592], [-731, 0], [0, 1195], [5438, 0], [0, 1257], [6073, 0], [0, 909], [0, -3632], [0, -1881], [660, 0], [-1641, 0], [0, 1477], [60, 0], [0, 1627], [0, -2428], [0, -3014], [0, -2354], [0, -3797], [0, 3918], [2934, 0], [7180, 0], [7713, 0], [-9349, 0], [0, -1838], [0, -849], [0, -3075], [11547, 0], [0, -2048], [5894, 0], [0, 2216], [-5431, 0], [312, 0], [1512, 0], [-10210, 0], [-10368, 0], [0, -9013], [8802, 0], [-2537, 0], [0, -2208], [-12004, 0], [0, -7579], [1560, 0], [10890, 0], [0, -10246], [0, -5932], [8978, 0], [9111, 0], [0, -7636], [-9200, 0], [0, -676], [-3872, 0], [0, -11245], [14010, 0], [9900, 0], [0, 9290], [0, -8668], [0, 8908], [0, 4847], [0, 4198], [0, -4724], [0, -9477], [7300, 0], [-5703, 0], [0, 9652], [12630, 0], [0, 1592], [0, 7526], [0, -16248], [-6942, 0], [-9220, 0], [7393, 0], [-15390, 0], [-12598, 0], [7131, 0], [-4890, 0], [0, 2638], [-14438, 0], [0, 6194], [0, 7772], [-4068, 0], [3065, 0], [0, 1330], [13795, 0], [-23406, 0], [-6518, 0], [0, 154], [0, -19277], [0, 19839], [6301, 0], [17026, 0], [0, 7260], [0, -7911], [-10155, 0], [0, 19440], [14106, 0], [0, 308], [0, -7431], [0, -1718], [-3664, 0], [0, 18214], [-24829, 0], [-6048, 0], [0, 6730], [0, -19167], [16196, 0], [10728, 0], [0, -27362], [20664, 0], [27532, 0], [0, -17218], [-6406, 0], [35046, 0], [0, -13742], [-42558, 0], [0, 5802], [0, -7704], [-1899, 0], [0, 14876], [0, 25984], [-51840, 0], [-17133, 0], [11241, 0], [-14567, 0], [0, 17248], [0, 2301], [38961, 0], [0, 24366], [48341, 0], [0, -5110], [0, 7750], [-42109, 0], [66300, 0], [0, 27363], [35292, 0], [0, 16772], [0, -34880], [13528, 0], [0, -39348], [-60122, 0], [0, 5400], [-30177, 0], [14082, 0], [0, -5712], [-8386, 0], [0, -2135], [0, -8572], [-37556, 0], [0, -7633], [-47693, 0], [-6696, 0], [0, -3969], [63486, 0], [0, -7953], [26588, 0], [0, 17927], [0, -38046], [0, 40138], [0, 21146], [-22636, 0], [0, -20628], [56226, 0], [-53361, 0], [42023, 0], [0, -26729], [0, 7074], [-8567, 0], [0, -7042], [78948, 0], [-50054, 0], [-40179, 0], [0, -18388], [-65969, 0], [0, 34958], [0, -38526], [-63447, 0], [-38838, 0], [0, 12463], [0, 51250], [3228, 0], [-40408, 0], [0, -53210], [0, -8296], [-93783, 0], [-474, 0], [0, -43842], [0, -16302], [78320, 0], [0, -871], [0, -973], [0, 51320], [61720, 0], [0, 28374], [19585, 0], [0, -13476], [99630, 0], [-37668, 0], [29721, 0], [0, 39562], [78022, 0], [-33035, 0], [0, -13859], [0, 49004], [34090, 0], [57918, 0], [0, -19706], [0, -2318], [0, -8764], [0, 51106], [-80721, 0], [-25805, 0], [0, -4456], [0, -8464], [590, 0], [0, 61478], [38961, 0], [0, -23604], [0, -14102], [0, -38610], [0, -43068], [0, -28168], [9930, 0], [-109784, 0], [56250, 0], [121962, 0], [0, -2460], [0, -30181], [68879, 0], [-76360, 0], [112660, 0], [0, 47465], [0, -24480], [-90668, 0], [46665, 0], [0, -60121], [0, -16413], [0, 74408], [0, 78481], [-42848, 0], [0, 60195], [0, 48295], [0, 91606], [-141774, 0], [-40258, 0], [0, 73371], [133816, 0], [0, 51854], [83826, 0], [-97683, 0], [0, -87857], [0, -72926], [0, 11936], [0, -21062], [-61652, 0], [687, 0], [0, 36586], [0, -24940], [0, -19760], [0, 15121], [0, 72163], [-51045, 0], [-154856, 0], [-40628, 0], [153339, 0], [176821, 0], [-98934, 0], [0, 21412], [0, -27373], [39684, 0], [0, 53970], [65926, 0], [0, -77809], [0, -86381], [-9150, 0], [0, -68442], [-157364, 0], [0, 48686], [0, 70326], [135094, 0], [0, -61784], [25654, 0], [0, -76724], [-126115, 0], [149659, 0], [53644, 0], [0, 55342], [0, 80559], [0, 6593], [69603, 0], [0, -45359], [0, -52835], [0, -19487], [23841, 0], [52535, 0], [0, -57243], [-155302, 0], [0, -32680], [-58294, 0], [143478, 0], [0, -49434], [176, 0], [-38658, 0], [0, -88666], [-133945, 0], [182252, 0], [0, -51414], [124899, 0], [0, 3265], [-25738, 0], [-112956, 0], [0, -107798], [0, 114952], [0, -108183], [131172, 0], [0, 12352], [0, 96244], [-149376, 0], [0, 25794], [0, -12928], [136548, 0], [0, 34752], [24694, 0], [-142130, 0], [0, -30667], [0, 123210], [0, -53959], [182478, 0], [-104821, 0], [0, 62511], [0, 19692], [0, 28302], [-114428, 0], [-107100, 0], [0, -24024], [0, 9972], [0, 112262], [0, -89524], [89610, 0], [62118, 0], [0, -117118], [0, -51157], [0, 33737], [-186312, 0], [41740, 0], [-133426, 0], [0, 151374], [98913, 0], [143411, 0], [-22305, 0], [104148, 0], [-17552, 0], [-18750, 0], [0, -134826], [0, -70465], [-138882, 0], [16787, 0], [0, -159892], [0, 123241], [268143, 0], [0, -158284], [-185805, 0], [0, 110956], [0, 35821], [-128410, 0], [0, 52264], [146374, 0], [31866, 0], [0, 55136], [0, 39480], [33879, 0], [0, -14417], [0, 362], [259962, 0], [0, -49362], [-5566, 0], [-81474, 0], [0, 61347], [52566, 0], [0, 6106], [-186096, 0], [0, 27110], [72668, 0], [-102510, 0], [98259, 0], [0, -47716], [155852, 0], [0, 21206]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1815_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1815_4_a_l();".
// 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_1815_4_a_l(:prec:=2)
    chi := MakeCharacter_1815_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_1815_4_a_l();".
// 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_1815_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1815_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-12, 0, 1]>,<7,R![-972, 0, 1]>],Snew);
    return Vf;
end function;