
// Make newform 1445.4.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1445_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_1445_4_a_a();".
// 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_1445_4_a_a();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1445_a();"
function MakeCharacter_1445_a()
    N := 1445;
    order := 1;
    char_gens := [1157, 581];
    v := [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_1445_a_Hecke(Kf)
    return MakeCharacter_1445_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 := [[-4], [-2], [5], [-6], [-32], [-38], [0], [100], [78], [50], [108], [-266], [-22], [442], [-514], [2], [500], [518], [126], [-412], [878], [-600], [282], [-150], [-386], [702], [-598], [1194], [550], [-1562], [1846], [2208], [-2334], [700], [2050], [1852], [-2494], [-2762], [-3126], [78], [-1300], [-1742], [3772], [358], [2214], [2600], [1168], [-6478], [-646], [3750], [-1482], [1400], [-3022], [-1248], [2106], [-3638], [6550], [-4388], [-546], [-6858], [-9282], [4842], [-2594], [-7332], [-1562], [-1426], [-4008], [-8866], [1714], [1150], [-4398], [1800], [5874], [-2078], [-7900], [-7518], [-1950], [-13786], [-6402], [11150], [13700], [-5438], [-7692], [-1118], [2600], [-11958], [17050], [-9494], [-11418], [7962], [6526], [-17400], [-1166], [7072], [-100], [-2602], [11150], [3638], [-2078], [-5622], [-16486], [11706], [-25038], [17550], [-10712], [-13654], [14166], [17842], [-17600], [-27302], [3794], [-13238], [11574], [-8300], [-7508], [27378], [-1842], [-10114], [-10402], [7100], [-7118], [31278], [30054], [4518], [-29272], [-5798], [-8950], [-7800], [-8554], [2882], [18700], [-12242], [31148], [-7694], [-4518], [-39550], [22122], [16634], [27586], [-3850], [-10032], [-20562], [-10322], [-8846], [-25350], [-46000], [16998], [26494], [-21500], [25762], [-30546], [-32942], [-27118], [38634], [1794], [-41732], [29200], [48650], [-11334], [31178], [-4686], [-598], [41726], [24312], [40946], [-42282], [-1172], [31614], [-2450], [-50362], [-12900], [1462], [30108], [8082], [5200], [-29850], [46248], [24018], [-30238], [35050], [27566], [8528], [-63442], [-67214], [-40398], [51350], [-36426], [-27278], [-6350], [47548], [-2602], [-23162], [8712], [-358], [-77766], [15158], [-20302], [25038], [-22626], [-56678], [66450], [-79692], [-75534], [-3950], [-56700], [40146], [24800], [43682], [26550], [-42328], [6214], [57202], [49398], [57206], [-30000], [-6662], [-20954], [-13518], [64874], [-13878], [-45758], [-20000], [28050], [-11722], [-29354], [-38350], [-17682], [-44800], [93886], [77448], [82602], [37100], [68012], [71942], [-34318], [-17034], [89850], [106958], [58500], [15732], [-84522], [36192], [47842], [-46050], [51198], [-33800], [-91526], [57688], [114500], [-34918], [60586], [25198], [-101394], [-64350], [-42638], [-9900], [23138], [1954], [58734], [73706], [82238], [-55274], [74650], [-19242], [-39786], [-5900], [104750], [-28838], [34678], [58682], [102778], [14686], [102602], [-78000], [-139254], [-43918], [68766], [105150], [80502], [89232], [75922], [140108], [38114], [-97218], [-49926], [-120588], [87878], [24054], [-120400], [40950], [-127402], [-113206], [-151038], [-30192], [-59282], [-83850], [-33148], [23322], [-152700], [89966], [96642], [-66814], [96200], [88398], [-149632], [24574], [20046], [-67550], [1800], [51402], [-92562], [38250], [-151842], [59282], [-47834], [-74150], [-114300], [71868], [-70362], [9750], [39208], [-90866], [26522], [-36758], [-22002], [-98018], [-156500], [116198], [79794], [-165362], [-85962], [102334], [-57800], [-161558], [-101552], [-28726], [-20950], [-53722], [69658], [-62634], [-156758], [-34214], [7950], [-78468], [-67318], [81900], [43678], [41086], [-113652], [-210106], [116112], [-142746], [-125558], [-53482], [-177450], [-35358], [69400], [-142632], [-28626], [102722], [54734], [59878], [-199314], [103900], [-42874], [-181478], [-49146], [107802], [34138], [-80208], [-128700], [358], [22050], [-98148], [187094], [25900], [-75972], [74642], [111750], [18226], [-32662], [81282], [146114], [-13906], [-161700], [67438], [-212788], [174746], [-234282], [-62034], [-206550], [-261842], [16100], [79406], [-136468], [162238], [-92200], [-40950], [-49792], [227922], [-25450], [160602], [62926], [249854], [-189950], [-66172], [-171214], [-77198], [201402], [142500], [-212082], [113466], [6242], [32448], [67106], [53818], [245600], [-247366], [170814], [-278798], [276250], [53174], [-174846], [-250300], [157798], [-214894], [191438], [-750], [51512], [-260600]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1445_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1445_4_a_a();".
// 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_1445_4_a_a(:prec:=1)
    chi := MakeCharacter_1445_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_1445_4_a_a();".
// 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_1445_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1445_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![4, 1]>,<3,R![2, 1]>],Snew);
    return Vf;
end function;