
// Make newform 1520.4.a.g in Magma, downloaded from the LMFDB on 20 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1520_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_1520_4_a_g();".
// 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_1520_4_a_g();".
// 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_1520_a();"
function MakeCharacter_1520_a()
    N := 1520;
    order := 1;
    char_gens := [191, 1141, 1217, 401];
    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_1520_a_Hecke( : Kf := Kf)
    return MakeCharacter_1520_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], [4], [5], [20], [44], [42], [-86], [-19], [164], [-162], [312], [226], [34], [432], [-580], [506], [-364], [518], [-924], [-320], [-542], [1208], [1120], [-1022], [1166], [-898], [-1152], [1156], [1046], [-530], [-568], [924], [-702], [2116], [1454], [680], [462], [-4136], [1464], [-1422], [3212], [-3234], [296], [-2770], [-1154], [2680], [2180], [4296], [-500], [4366], [2970], [144], [1738], [3012], [1014], [-4284], [38], [-5888], [5254], [-2558], [6776], [-2086], [-7428], [4040], [-3318], [-7302], [-1428], [6302], [-2608], [-8234], [-7254], [-6000], [10204], [-3094], [-2708], [8272], [-4066], [15438], [14514], [7818], [3684], [-5834], [-6944], [-738], [-544], [792], [7362], [-14278], [-1002], [-8916], [-6344], [1800], [-3704], [-3468], [-5348], [2228], [-18082], [-10166], [-6268], [-1594], [-7940], [-12626], [21660], [14346], [5404], [1426], [18704], [-14270], [-15296], [10002], [2992], [-13930], [-23022], [-26284], [-8408], [-16262], [-24448], [-10548], [7662], [-32452], [-17690], [-15802], [-10518], [7092], [-508], [-31466], [-31282], [-18232], [8884], [6838], [-32380], [4584], [-10384], [-2002], [-2854], [2322], [-27678], [-12532], [4562], [-1350], [-12892], [-32802], [-24916], [1596], [25910], [-27504], [-14514], [41790], [6332], [-3488], [23426], [-31230], [-24120], [33696], [7412], [-18288], [34040], [41778], [14834], [-18026], [-57112], [-7842], [25068], [-11628], [-22554], [38136], [-22720], [18230], [-36902], [25734], [14988], [46246], [-43944], [6298], [30224], [-15270], [15060], [-13570], [39432], [-59402], [4916], [30284], [-9134], [1454], [-33908], [-37506], [31106], [-57076], [66346], [59512], [17910], [53400], [17180], [-12978], [80064], [22950], [55858], [-13658], [-4894], [-27684], [-55362], [-40672], [47826], [-63110], [40980], [22206], [84616], [2388], [-13686], [-8924], [-25966], [5678], [63492], [-14996], [-50728], [15186], [13036], [-10206], [33104], [72326], [3158], [-35320], [-29942], [94348], [46252], [-52786], [32286], [1648], [49008], [-39756], [43334], [-93580], [-96704], [35346], [-23640], [-73684], [13394], [64926], [-30268], [72536], [-16228], [53060], [31388], [12750], [92734], [38440], [35116], [6324], [-23060], [-51804], [108262], [-98622], [40380], [-59270], [-35674], [-86460], [-45522], [-2036], [-65046], [-30190], [-9016], [-76860], [67710], [-76094], [2962], [64204], [-108946], [858], [11964], [-134898], [68150], [-31404], [104050], [56984], [89054], [52396], [-184], [-109714], [53282], [-97516], [-97056], [88360], [-47364], [-14898], [-36736], [-16896], [72194], [95810], [89288], [-71182], [105414], [-126608], [-77002], [41916], [-24974], [-65274], [-7384], [137918], [86684], [78976], [-117086], [48050], [105960], [113588], [122612], [27406], [-42004], [-109618], [-73272], [6046], [-137516], [41486], [26130], [-129028], [-41028], [-55358], [-88388], [146880], [74050], [35426], [50716], [-181886], [37278], [-62064], [169810], [120874], [21260], [177044], [-80808], [-16650], [123862], [104962], [-112248], [-67368], [169308], [-57384], [-114618], [128902], [-132726], [-90124], [-3062], [-199870], [22206], [204048], [33026], [-201252], [-187490], [-93236], [81576], [176230], [140], [106894], [80310], [187536], [-38522], [-191442], [-132480], [83892], [-143942], [105576], [-101066], [-25494], [205824], [158620], [-35096], [114582], [-25170], [-199352], [116130], [-118588], [227572], [66884], [165070], [-160704], [73278], [-83644], [-32728], [-187726], [-201182], [6774], [217542], [208666], [324], [3410], [-41636], [-122400], [18496], [238806], [20528], [47472], [-76014], [-201318], [-177252], [-248840], [15336], [143902], [222424], [-179486], [270772], [40110], [86486], [-76846], [182576], [132254], [-85490], [-46208], [88446], [165138], [-13220], [34628], [-70666], [-127058], [-97428], [-146540], [22434], [241270], [-250776], [208432], [42794], [232456], [-161322], [39130], [-222964], [173324], [-169898], [-111054], [-283572], [-248566], [-278476], [38736]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1520_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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