
// Make newform 3712.2.a.n in Magma, downloaded from the LMFDB on 09 February 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_3712_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_3712_2_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_3712_2_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_3712_a();"
function MakeCharacter_3712_a()
    N := 3712;
    order := 1;
    char_gens := [639, 2437, 2177];
    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_3712_a_Hecke( : Kf := Kf)
    return MakeCharacter_3712_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 := 2;
    raw_aps := [[0], [2], [2], [-4], [6], [-6], [6], [2], [4], [-1], [4], [10], [10], [-2], [4], [2], [-14], [10], [-2], [-12], [6], [-4], [6], [-10], [6], [10], [12], [18], [10], [2], [4], [2], [10], [-6], [10], [-4], [-6], [-22], [-12], [-6], [-18], [-14], [-12], [-10], [18], [12], [2], [-8], [14], [-14], [14], [0], [-18], [-10], [2], [-24], [10], [4], [-14], [-18], [-30], [10], [2], [-16], [-22], [34], [-18], [2], [26], [2], [-30], [-24], [28], [26], [22], [-16], [-30], [26], [-2], [10], [-18], [-14], [0], [38], [-20], [6], [-10], [-38], [-22], [-8], [-30], [12], [28], [22], [14], [8], [-6], [42], [-14], [-22], [38], [-14], [26], [10], [-22], [-14], [-14], [2], [-32], [-10], [-4], [-30], [6], [14], [-20], [6], [-2], [-12], [-6], [-22], [-22], [14], [42], [10], [38], [-22], [-14], [-16], [-32], [42], [-14], [-32], [20], [26], [10], [22], [34], [14], [18], [-38], [-38], [-14], [-16], [-26], [-22], [0], [18], [26], [-18], [0], [34], [-30], [6], [-48], [6], [-12], [20], [-34], [46], [-6], [-30], [-6], [16], [-18], [-2], [-24], [32], [-38], [30], [-22], [-46], [10], [-4], [-26], [16], [-50], [50], [50], [24], [18], [-28], [-6], [50], [-18], [-32], [34], [34], [50], [26], [8], [-46], [46], [-14], [18], [10], [-50], [-46], [2], [-62], [-12], [-14], [-40], [-62], [-46], [-18], [-22], [20], [30], [-50], [30], [-10], [-6], [-24], [-18], [40], [-22], [8], [22], [12], [-6], [2], [4], [38], [12], [6], [42], [-26], [-20], [48], [-6], [-46], [70], [-28], [22], [-14], [-12], [70], [-14], [-54], [40], [-62], [26], [-44], [10], [-14], [60], [8], [62], [-14], [28], [-62], [2], [-16], [-42], [-6], [54], [2], [-42], [42], [42], [44], [66], [-22], [-6], [54], [-6], [66], [38], [-2], [-6], [42], [30], [-34], [4], [50], [64], [-58], [-46], [-42], [38], [-24], [-60], [-12], [58], [14], [-28], [-58], [-62], [84], [66], [-54], [-42], [-18], [70], [-62], [26], [-84], [58], [-38], [50], [26], [42], [20], [58], [22], [30], [-18], [-54], [-20], [58], [-72], [66], [78], [38], [-60], [-50], [10], [-40], [-14], [-46], [-86], [-86], [-6], [44], [-54], [38], [22], [34], [-12], [66], [26], [18], [-48], [-14], [38], [-22], [58], [66], [54], [-32], [10], [-22], [-14], [44], [74], [-30], [2], [62], [-36], [-14], [22], [-86], [-54], [40], [34], [38], [36], [18], [-58], [20], [10], [62], [-68], [50], [2], [70], [-22], [-44], [-38], [50], [-30], [-32], [-6], [-68], [10], [50], [60], [-46], [78], [42], [-30], [-6], [88], [18], [-34], [12], [92], [-94], [-98], [100], [82], [34], [6], [-46], [96], [-54], [-48], [-70], [50], [-54], [-14], [54], [-44], [90], [-6], [-52], [34], [-26], [-54], [-50], [-46], [18], [66], [-10], [-90], [-54], [44], [-100], [38], [-96], [98], [26], [-12], [-18], [26], [-14], [54], [-10], [66], [-24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3712_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3712_2_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_3712_2_a_n(:prec:=1)
    chi := MakeCharacter_3712_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    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_3712_2_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_3712_2_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3712_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 1]>,<5,R![-2, 1]>,<7,R![4, 1]>],Snew);
    return Vf;
end function;