
// Make newform 2312.4.a.a in Magma, downloaded from the LMFDB on 15 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_2312_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_2312_4_a_a();".
// 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_2312_4_a_a();".
// 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_2312_a();"
function MakeCharacter_2312_a()
    N := 2312;
    order := 1;
    char_gens := [1735, 1157, 1737];
    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_2312_a_Hecke( : Kf := Kf)
    return MakeCharacter_2312_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], [2], [-24], [44], [22], [0], [44], [56], [-198], [160], [162], [198], [52], [528], [-242], [-668], [-550], [188], [-728], [-154], [656], [236], [714], [478], [1566], [-968], [780], [1994], [942], [1408], [2692], [1626], [684], [302], [1352], [3142], [-3036], [264], [2826], [3084], [2418], [-960], [-2882], [-1086], [-88], [3476], [928], [-156], [-1634], [902], [1616], [-4818], [-2140], [770], [-7400], [2794], [8624], [1874], [3338], [-7172], [5214], [396], [4056], [-2154], [7386], [-1132], [3342], [-2244], [-6522], [-11230], [1848], [-7120], [6350], [7900], [10368], [8830], [-9878], [13134], [906], [5412], [-4642], [-656], [9490], [-5544], [7652], [446], [1562], [10582], [-10768], [-9876], [352], [15176], [-8844], [-19404], [-16488], [-12954], [-10970], [-16940], [-198], [15268], [20854], [-19316], [7018], [-24420], [23234], [-10604], [-13838], [-3960], [5942], [3040], [-2530], [19206], [-10996], [-6680], [-6274], [-9084], [-23656], [6762], [15276], [11054], [21278], [-8926], [-8116], [11764], [-4698], [-24638], [-16624], [30216], [-3322], [-14692], [-28600], [29616], [2894], [14762], [-7678], [27390], [-19756], [38854], [14278], [716], [23538], [6616], [-27236], [12070], [42024], [-2414], [37686], [40644], [-18656], [13002], [-49490], [1100], [14104], [12716], [39632], [5704], [-8162], [-55110], [-16374], [-8460], [-20502], [-36520], [20244], [50034], [-37128], [-27808], [28514], [-3026], [52658], [-41820], [39270], [-54296], [27610], [-7504], [18934], [12028], [-5982], [9592], [-50314], [704], [30532], [-22206], [-34662], [-20112], [-28050], [-29062], [39708], [-53242], [-55680], [40574], [-2388], [-596], [-32186], [30756], [-6074], [36590], [69722], [-52802], [-7080], [-24662], [-22256], [46574], [-58718], [-58764], [-15258], [-80128], [-71940], [-41690], [-69932], [-7986], [-41298], [20792], [40964], [-20600], [-48698], [37136], [36850], [-4488], [-80250], [-27874], [51480], [-44670], [15568], [26796], [85550], [-13962], [1056], [-8712], [-41140], [82422], [65780], [84800], [-96998], [95508], [-7696], [-41330], [35090], [-41540], [73912], [38964], [-38236], [-21992], [44566], [-92466], [-51656], [-49504], [26532], [-87500], [-103408], [11814], [18750], [-19240], [118118], [77526], [-21780], [-110], [81980], [3042], [-11222], [-85888], [101244], [51842], [-60486], [-61666], [80348], [-34570], [-43030], [-57572], [122942], [33194], [63596], [31306], [36256], [35794], [10088], [101796], [17510], [2266], [-47828], [93280], [-110200], [136664], [-41026], [97900], [115312], [-110066], [-40302], [-41080], [-18910], [85706], [10164], [165418], [-38484], [131946], [6842], [-144928], [-122994], [75804], [18236], [-135142], [-169642], [73744], [28820], [-71748], [-11426], [60276], [-18614], [84584], [-3586], [-73392], [118866], [-36194], [-119204], [-159368], [-61894], [-64884], [115008], [-116930], [48114], [-186604], [5174], [160646], [46624], [-74746], [102738], [-164220], [-35460], [-29920], [-161502], [130826], [-75174], [37824], [-179652], [37356], [-137028], [212230], [13662], [49030], [202320], [-91826], [183210], [23298], [-79080], [9670], [189092], [157602], [126772], [41712], [-49166], [-65604], [201574], [-101930], [114576], [-9874], [-79414], [53536], [-109556], [107438], [166632], [-175742], [-141402], [-149712], [-47492], [204508], [124602], [23562], [-103592], [-14410], [135068], [-12660], [114352], [61006], [149608], [159898], [28116], [-85344], [129634], [-147822], [60266], [55770], [-22630], [-155784], [206046], [166628], [-14904], [-94512], [194510], [48092], [-87168], [195710], [-77182], [206676], [-273492], [-91320], [374], [107232], [-274758], [215116], [81550], [96346], [125250], [47344], [-62282], [-181346], [-16312], [-53834], [190674], [-112948], [242436], [214990], [236206], [91652], [-174940], [45882], [-218230], [204864], [107560], [-98802], [103304], [103046], [61666], [226864], [48932], [28838], [184982], [-238252], [178038], [105348], [56408]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2312_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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