
// Make newform 1425.4.a.f in Magma, downloaded from the LMFDB on 21 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1425_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_1425_4_a_f();".
// 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_1425_4_a_f();".
// 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_1425_a();"
function MakeCharacter_1425_a()
    N := 1425;
    order := 1;
    char_gens := [476, 1027, 1351];
    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_1425_a_Hecke(Kf)
    return MakeCharacter_1425_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]];
    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 := [[3], [3], [0], [-32], [-12], [10], [30], [19], [48], [150], [224], [-254], [-54], [196], [504], [-78], [132], [230], [-740], [-120], [-122], [1184], [-612], [1050], [1006], [-642], [-1472], [2052], [1334], [414], [-1496], [1404], [-138], [-124], [2670], [-376], [682], [-3524], [912], [-3990], [2316], [-3346], [960], [3214], [-990], [3560], [-2740], [3448], [-5124], [-3010], [3510], [5280], [1106], [-2844], [4014], [5472], [1734], [5456], [-830], [3450], [-1964], [2466], [7468], [-3768], [6838], [-7014], [3092], [10270], [-396], [-5146], [9582], [4968], [-4088], [-2990], [4436], [9048], [-8034], [-11366], [-8382], [-6550], [-11412], [-8098], [10368], [4606], [9944], [14532], [16050], [10918], [16182], [-3560], [3372], [-2448], [4048], [-5580], [476], [-2832], [-2346], [-3990], [-3020], [5894], [22780], [-9366], [-19332], [-21222], [-26524], [-5186], [12516], [-15042], [6600], [-23830], [4552], [6802], [13686], [24836], [30056], [-3438], [5596], [-1968], [12138], [-2004], [24590], [-11762], [-21438], [-25644], [12332], [-1050], [13790], [-20160], [36976], [970], [17900], [-2496], [-9520], [6466], [-30198], [-14590], [34818], [1804], [-35718], [-44838], [17588], [-33522], [3904], [-11628], [-19738], [-31752], [10978], [-3450], [-46348], [47736], [33706], [-33774], [22444], [-30240], [-38972], [16128], [23576], [54882], [-33146], [-33786], [18060], [-26202], [-13856], [16644], [40446], [-17232], [48992], [-7310], [-13102], [11442], [14724], [50534], [57432], [43174], [44672], [2538], [-35164], [46782], [16192], [16598], [-62696], [-49140], [53122], [-43914], [-67608], [-30834], [-20774], [60268], [4250], [32640], [67822], [45108], [-75412], [-36426], [-59556], [-30954], [49682], [52138], [4974], [71808], [9894], [-81520], [30514], [-28702], [9636], [10074], [39152], [29484], [33114], [13460], [78286], [-23730], [73312], [-49836], [-40872], [25754], [3112], [45570], [-28512], [-64518], [33374], [-24232], [-3438], [-33704], [88620], [68558], [-54138], [93600], [19312], [87156], [10138], [-37540], [-65536], [-51222], [-76700], [76344], [18674], [34002], [97428], [-17880], [-99300], [18020], [105232], [8534], [92670], [-79944], [51640], [-25428], [-84988], [38376], [104074], [-26238], [69552], [-75526], [-1494], [69756], [-49042], [53236], [40194], [-81386], [-56648], [13596], [111326], [-29894], [-66546], [63980], [-136506], [5802], [-15548], [28002], [21398], [-129044], [-26282], [-17584], [-18626], [110944], [107892], [-14170], [4154], [-99540], [51672], [71768], [-26880], [-44098], [-94700], [66960], [-3218], [-137934], [74744], [-103086], [79350], [24780], [-46554], [-75420], [19882], [86310], [-107872], [-72654], [118404], [-131732], [-126362], [-85974], [-93760], [-155652], [30980], [-65810], [-48252], [43286], [-5640], [-22382], [-102552], [87534], [-12366], [-159572], [82704], [-70918], [-153060], [-117936], [-134882], [-63150], [-67348], [121846], [5238], [45784], [-85002], [94610], [1772], [161668], [95496], [-81438], [-29770], [64218], [-21904], [175404], [-200428], [133908], [3302], [-54258], [-121606], [36232], [62674], [-190266], [138510], [35768], [-197862], [207228], [45470], [-74108], [-31104], [181842], [-151012], [-94922], [-110154], [-57656], [-142162], [86982], [91152], [110292], [-119586], [20208], [-155630], [-151110], [76344], [-53340], [-230996], [-184970], [-159126], [-111392], [229994], [-174180], [102596], [-164088], [-50082], [-165496], [-198614], [251244], [18240], [170782], [-14766], [182278], [74838], [-109578], [17872], [-28434], [-117460], [-92448], [167408], [159010], [97972], [49128], [41570], [78786], [-98940], [123196], [-52008], [-20666], [-248080], [-177750], [68852], [47790], [60038], [-26514], [248344], [100230], [-47538], [234680], [-197606], [-64830], [159388], [92556], [-88514], [-268878], [-44028], [-143908], [-34202], [-236970], [128160], [114352], [-4482], [174192], [28950], [288034], [85848], [209604], [-151658], [203562], [-105924], [-129654], [242276], [-73224]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1425_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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