
// Make newform 325.4.a.d in Magma, downloaded from the LMFDB on 07 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_325_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_325_4_a_d();".
// 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_325_4_a_d();".
// 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_325_a();"
function MakeCharacter_325_a()
    N := 325;
    order := 1;
    char_gens := [27, 301];
    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_325_a_Hecke( : Kf := Kf)
    return MakeCharacter_325_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 := [[5], [7], [0], [13], [-26], [-13], [-77], [-126], [96], [-82], [196], [131], [336], [201], [105], [432], [-294], [-56], [-478], [9], [-98], [1304], [308], [-1190], [-70], [420], [-588], [684], [373], [1734], [-1892], [1435], [1776], [-1869], [2466], [-3323], [2730], [544], [-1624], [336], [-3029], [-28], [422], [-492], [-2991], [-70], [2851], [-217], [2576], [455], [-3061], [-3477], [-1610], [1008], [-6041], [3708], [8344], [-1617], [3820], [-6214], [5292], [903], [-2114], [3402], [10689], [7054], [9704], [10449], [621], [12481], [1400], [-4968], [-8722], [-10012], [-3372], [847], [11314], [-1862], [6820], [-12992], [-7343], [-5059], [3243], [-11599], [-17374], [-989], [-14474], [1594], [-5915], [11072], [-1260], [-12033], [2280], [16767], [12840], [2198], [-17066], [2583], [-18620], [-16833], [8615], [-8535], [4641], [-4793], [-5563], [-24038], [21224], [-4354], [7310], [-7595], [826], [-14590], [-4888], [-11004], [-4975], [3950], [3682], [-10402], [31680], [21940], [-31374], [-18013], [10640], [9336], [4200], [9872], [28450], [32718], [22834], [-7875], [-2140], [-31971], [-7432], [-20176], [-9478], [-12096], [-17941], [-6664], [1442], [30207], [21140], [569], [8538], [32702], [-21154], [-2184], [-36687], [-36806], [4900], [13697], [-6239], [133], [26003], [31248], [38253], [36374], [-27648], [756], [-20846], [-41321], [-54966], [44553], [27907], [-16443], [45414], [8981], [-17414], [23702], [39846], [5922], [7086], [-23429], [-26920], [-10152], [56070], [4095], [-38820], [-14670], [-26404], [504], [34480], [-30156], [-29234], [-52542], [15916], [-24738], [2882], [-57974], [42380], [30240], [-38773], [-15892], [-8951], [-20902], [14691], [-11802], [-58280], [-65116], [65296], [81774], [38313], [2072], [59969], [24857], [-19656], [28126], [-61019], [63068], [7226], [-52367], [66106], [14910], [69424], [-18046], [-42203], [52724], [964], [81725], [-78276], [-59439], [-16420], [41965], [-46100], [20459], [21735], [-6326], [-52479], [-10876], [-76342], [-106258], [-58494], [-67228], [71192], [79851], [-17773], [693], [-11830], [53933], [33896], [68950], [97298], [32431], [21616], [-27585], [-87318], [35532], [-58345], [102732], [38810], [18870], [61507], [17402], [115407], [61495], [107856], [-84782], [48848], [66094], [82404], [-10990], [-5868], [96773], [15659], [-490], [-27720], [22099], [119765], [-73752], [-118316], [-64780], [104468], [118158], [-52906], [33392], [40530], [-121240], [70838], [22150], [40420], [-124047], [-74004], [20897], [24962], [116354], [-17696], [-70838], [54647], [-44739], [-154021], [-96502], [115572], [12369], [-73824], [114198], [-17026], [53788], [-8358], [11900], [67193], [-79646], [87409], [-92941], [-127538], [-52628], [2081], [72924], [179905], [4900], [66852], [-70716], [-125636], [58011], [-178673], [-43948], [92587], [121709], [-12726], [-46520], [16688], [-134706], [25004], [9056], [-145572], [146823], [-127248], [-24150], [18566], [78680], [-19756], [-29472], [23942], [-9648], [119392], [-98420], [-188480], [164024], [-138458], [89068], [-9100], [-166642], [74079], [55277], [-54103], [-52414], [-23963], [151419], [238], [-116524], [-112987], [213038], [215082], [-190038], [47049], [117040], [89630], [-159866], [-82159], [27342], [1125], [76739], [-146274], [37086], [-103686], [-13872], [-165844], [-213817], [-214851], [169496], [-172527], [78969], [-2583], [-55267], [-210810], [-62832], [245334], [200970], [142578], [90776], [-219422], [79674], [-72282], [237522], [-146708], [45750], [-53564], [-141463], [151335], [40908], [17386], [-124544], [99542], [156541], [196898], [-138803], [247235], [53303], [-69559], [-137403], [-102884], [28149], [-134155], [52134], [151247], [-99708], [99659], [20594], [-142711], [-231040], [51786], [213864], [95935], [147754], [-70317], [-237473], [32751], [-96768], [-133243], [143584], [256158], [50218], [157264], [-101682], [67240], [145313], [20944], [-166474], [205413], [194616], [201320], [250194]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_325_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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