
// Make newform 630.4.a.n in Magma, downloaded from the LMFDB on 07 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_630_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_630_4_a_n();".
// 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_630_4_a_n();".
// 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_630_a();"
function MakeCharacter_630_a()
    N := 630;
    order := 1;
    char_gens := [281, 127, 451];
    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_630_a_Hecke( : Kf := Kf)
    return MakeCharacter_630_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 := [[2], [0], [-5], [-7], [44], [54], [-98], [-60], [144], [210], [-208], [-226], [502], [484], [232], [530], [764], [814], [60], [-848], [-958], [-152], [-308], [1094], [554], [-1134], [-488], [828], [-42], [-2138], [1072], [-1004], [-642], [-1604], [2394], [800], [-890], [668], [-816], [-1334], [1236], [358], [888], [-4030], [1714], [-4264], [3316], [2128], [-980], [4102], [-2466], [-1192], [-3854], [-4020], [-1922], [-2480], [1002], [-2832], [4206], [-5978], [2684], [7490], [-6860], [4920], [-4558], [-5830], [5020], [-3662], [860], [-3458], [-2994], [-1760], [-608], [-7090], [14268], [4104], [-15110], [-10682], [10526], [-6], [15108], [10094], [12696], [12122], [-8552], [3548], [16686], [778], [-838], [-7456], [-10724], [-768], [-10744], [-3540], [15732], [8496], [-17638], [-1802], [9196], [-5130], [5916], [-24166], [-15572], [12294], [-4740], [12442], [22036], [-9666], [4800], [-6150], [-9920], [-17442], [-27746], [28172], [30752], [-1154], [20308], [-12256], [-4838], [5588], [9430], [-16430], [-12606], [-23444], [14980], [25298], [-25634], [8448], [-23112], [10582], [27124], [-11616], [1544], [-39506], [26022], [-27230], [4866], [-5852], [-16326], [-7578], [6860], [25722], [-21320], [22156], [-45394], [31048], [-16354], [-11274], [-21204], [31304], [23894], [-15458], [-24276], [-80], [21716], [-26760], [11984], [28622], [17474], [-6998], [-44204], [30], [20104], [18156], [-13002], [-11264], [-10424], [-9730], [-5102], [-19726], [-116], [-23410], [12096], [19962], [-35296], [46022], [-47684], [-46662], [51992], [-49874], [-42928], [37572], [-21346], [-18794], [-27048], [5346], [42214], [70772], [-21062], [-13104], [-53286], [69164], [-49052], [8746], [32916], [46998], [66802], [25702], [-31458], [15760], [-31966], [-57424], [-21042], [-61038], [8508], [41146], [9728], [-74412], [44310], [-49972], [-4254], [-33870], [-73016], [49924], [8568], [31898], [-38048], [126], [64496], [-56214], [-49666], [19064], [-95586], [61440], [87340], [24254], [92822], [54376], [-49064], [-38852], [-16778], [19764], [-42776], [46326], [31948], [86424], [-49214], [-16526], [10588], [-4120], [-5308], [110060], [18552], [-74570], [-88818], [-19560], [-105136], [-55020], [83564], [62872], [65158], [-25746], [29856], [-16998], [97098], [-5164], [-10738], [3484], [3426], [72786], [-67584], [-86908], [-104234], [6998], [84558], [-2524], [55650], [80230], [-49772], [3954], [-39522], [-84948], [112130], [-8664], [72266], [-119992], [-118484], [-101722], [-64614], [-45484], [-7912], [-88480], [-120096], [-88650], [-33700], [-85896], [44386], [-48894], [62072], [44718], [-59646], [28204], [69998], [-23636], [-22026], [71946], [126880], [23282], [140124], [-86908], [-54510], [-92966], [-104936], [1572], [160172], [81954], [-112580], [69102], [-152640], [145022], [-128328], [-4278], [-54610], [123788], [116880], [-16054], [-80220], [120072], [12858], [106126], [113380], [-34406], [65578], [67632], [33822], [124082], [-162076], [16716], [-121912], [-18942], [-42586], [73002], [-64160], [105708], [-129556], [-109116], [105430], [120318], [-758], [-146944], [2446], [29630], [142146], [16688], [84858], [-39628], [-144858], [99604], [-133920], [-155310], [-85228], [-159798], [125586], [1472], [52590], [78918], [125664], [-18676], [-187626], [-74832], [-219202], [-209258], [42472], [-26644], [-21884], [204874], [-8566], [-113336], [-195254], [-108828], [-89924], [-131128], [51690], [99752], [-149210], [-174812], [153864], [190778], [-54690], [-66270], [220010], [-151282], [-115032], [-99834], [52068], [-133488], [144696], [-59938], [-260956], [-90184], [117506], [270242], [-31636], [33396], [-105952], [-89558], [23296], [-139114], [-192660], [-106470], [134814], [136038], [144832], [234774], [-77278], [-61784], [-66634], [201534], [3732], [-106188], [143834], [16434], [-200628], [47860], [107834], [-233974], [-244008], [-97368], [-86274], [189856], [-252622], [-283234], [-279528], [245596], [98082], [28202], [157252], [-182442], [129628], [99736]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_630_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_630_4_a_n();".
// 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_630_4_a_n(:prec:=1)
    chi := MakeCharacter_630_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_630_4_a_n();".
// 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_630_4_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_630_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![-44, 1]>,<13,R![-54, 1]>],Snew);
    return Vf;
end function;