
// Make newform 1920.4.a.p in Magma, downloaded from the LMFDB on 29 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1920_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_1920_4_a_p();".
// 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_1920_4_a_p();".
// 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_1920_a();"
function MakeCharacter_1920_a()
    N := 1920;
    order := 1;
    char_gens := [511, 901, 641, 1537];
    v := [1, 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_1920_a_Hecke( : Kf := Kf)
    return MakeCharacter_1920_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 := [[0], [3], [5], [10], [-22], [26], [14], [-34], [-190], [-162], [-268], [-362], [-170], [16], [434], [594], [-170], [130], [-1024], [280], [282], [-160], [-732], [-746], [-534], [-306], [846], [948], [1570], [-898], [1094], [86], [1566], [-1886], [-762], [-1760], [1526], [804], [-3362], [3990], [1234], [138], [-60], [4010], [3914], [-556], [-4406], [-3462], [-744], [1074], [-5370], [-1312], [-2190], [6050], [-402], [-6598], [4206], [660], [-1914], [-1438], [-2184], [-418], [-520], [-5768], [-1654], [4138], [1102], [6738], [-9700], [5522], [10758], [-9012], [1246], [-1698], [-1374], [-1690], [-3178], [13290], [12606], [-11082], [-4758], [1618], [-7700], [-15182], [3052], [3912], [4762], [-7622], [13062], [-6926], [-1272], [-152], [4546], [-3550], [-2], [8586], [12030], [-18222], [-21280], [-17534], [-16256], [14806], [18004], [-1818], [2686], [5138], [25324], [12230], [-10772], [-27718], [20366], [-21534], [3430], [1130], [14704], [-24558], [4068], [-4178], [-1054], [23066], [2322], [29498], [-8086], [-23928], [3290], [22590], [11634], [2224], [34018], [-2786], [-9602], [13818], [25132], [-29338], [8658], [-29306], [-11742], [12320], [39434], [11706], [44566], [11366], [-1706], [29004], [3682], [22804], [-42094], [-674], [-22318], [-25674], [-32234], [46382], [-47100], [-8442], [-38228], [7236], [-4108], [39450], [28978], [-14386], [13104], [7806], [11154], [17274], [-29826], [-51550], [44116], [26210], [-5018], [40338], [59518], [57962], [63344], [1922], [60232], [390], [31950], [17166], [-30178], [-49270], [-23106], [-26962], [-56414], [39334], [-63442], [-23746], [46054], [8532], [-14346], [14412], [-32006], [14640], [-10966], [-39898], [34320], [62134], [-19042], [-20582], [29958], [-77358], [76718], [50932], [49474], [7234], [-74730], [-23994], [67968], [-63980], [-91978], [-68706], [-78750], [87462], [-68786], [-6380], [-20396], [-13938], [53894], [-37938], [1638], [-55854], [34202], [-46700], [-44802], [-3326], [-1624], [-60830], [6094], [-39264], [-89118], [-59502], [-16694], [67694], [-84484], [49410], [-47576], [-9246], [-44302], [-62766], [33702], [-64832], [-46828], [72662], [-95770], [66074], [51462], [54820], [49038], [-7394], [-22590], [46230], [-100326], [6130], [23870], [90122], [27638], [54522], [123650], [13484], [54142], [-58046], [-95118], [54344], [24010], [-99154], [-101058], [-27890], [-73042], [-88986], [53600], [-77890], [-95438], [-76144], [118690], [-82000], [-127334], [-50450], [-67052], [92626], [-63078], [-24202], [-86154], [77120], [-9858], [32978], [131068], [111652], [43378], [64554], [29412], [-147490], [-114690], [36664], [147990], [-64478], [-40498], [17430], [92196], [74126], [118166], [-12296], [-92606], [-24650], [-125888], [65932], [138310], [132418], [-107476], [70378], [-118140], [-16274], [-46266], [72974], [27726], [-82132], [55262], [172102], [-4302], [111116], [27618], [45102], [-56214], [103106], [-50082], [75210], [-20082], [-47342], [-149026], [91040], [19866], [1362], [-59390], [-93274], [193896], [-200196], [31718], [118396], [-101270], [-92258], [-60038], [-162594], [-168882], [108390], [-205194], [-158152], [-214650], [-145054], [158266], [-62332], [-44716], [-171302], [121738], [-100558], [-65690], [33002], [-2822], [-75234], [22680], [-6814], [-57866], [63554], [84450], [48294], [193794], [-16578], [-95384], [-59054], [51402], [-65690], [-4594], [184822], [71650], [87502], [-213626], [36640], [26970], [-94318], [138908], [216082], [-84374], [177346], [-67234], [110998], [48946], [-83714], [-141490], [58602], [60292], [-188938], [223264], [231674], [217398], [-127426], [10686], [223872], [-151520], [-217942], [-25944], [-196518], [-251722], [-9162], [259946], [88062], [211286], [99886], [-113674], [-129032], [-62838], [187262], [146948], [50226], [-208582], [-34994], [15376], [-36166], [287146], [-188154], [41936], [-81398], [284190], [299594], [110030], [-149326], [-3318], [-42434], [189362], [40278], [-148596], [96138], [193006], [231220]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1920_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1920_4_a_p();".
// 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_1920_4_a_p(:prec:=1)
    chi := MakeCharacter_1920_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_1920_4_a_p();".
// 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_1920_4_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1920_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-10, 1]>,<11,R![22, 1]>],Snew);
    return Vf;
end function;