
// Make newform 3712.2.a.r 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_r();".
// 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_r();".
// 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
        poly := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0], [0, -1], [2, -1], [0, 0], [4, 1], [2, 1], [2, -2], [4, 0], [8, 0], [1, 0], [2, -1], [-6, 2], [-6, 4], [-4, 5], [-2, 3], [-6, -1], [-2, -2], [6, 2], [6, -4], [-4, -4], [2, 0], [2, -7], [2, 2], [-14, 2], [10, -2], [10, -4], [8, 4], [-2, 2], [2, 3], [2, 2], [6, 2], [-8, 4], [-6, -4], [-10, -4], [2, 1], [4, 2], [6, -6], [-4, -3], [20, -2], [6, 4], [14, 4], [10, -3], [6, -2], [-22, 2], [14, -4], [-8, 2], [4, -7], [20, 2], [10, 6], [-6, 6], [-14, 1], [12, -2], [2, -1], [-4, -9], [-6, 3], [-10, 11], [-6, 2], [-10, -3], [-26, 0], [2, -3], [10, -12], [-2, 6], [-16, 5], [-22, 6], [10, 7], [-2, 0], [16, 1], [2, -2], [2, -2], [2, -5], [-10, 12], [-10, 1], [6, -6], [-14, 13], [8, -4], [-8, 14], [6, 12], [-6, 9], [-14, -3], [18, -10], [6, 0], [-14, 4], [12, 0], [10, -8], [-20, 8], [-4, -8], [-30, 4], [6, -8], [10, 10], [-8, 6], [0, 13], [-18, 5], [16, 8], [-24, 7], [6, -8], [-6, -11], [18, 3], [-6, -7], [-18, 6], [-10, -10], [-6, 8], [-2, -8], [-4, -11], [-6, -10], [-10, 16], [18, 0], [-2, 6], [-22, 1], [22, 5], [-6, 8], [-34, 1], [-14, -13], [-38, 0], [-16, 17], [4, -10], [18, 0], [22, -2], [-12, 6], [26, -6], [24, -1], [22, -12], [2, -5], [34, -8], [30, -4], [-6, 2], [10, -15], [2, 9], [4, -8], [-6, 6], [18, -4], [0, -5], [6, -6], [-38, 2], [-42, 0], [-2, 12], [10, -10], [14, -6], [-2, 6], [2, 10], [-14, 18], [26, -12], [34, -3], [2, -18], [24, 5], [30, 4], [-22, 19], [6, -8], [26, -9], [-8, -5], [8, 6], [-30, -5], [34, -2], [-34, 14], [22, -9], [-36, 12], [30, -3], [-16, 12], [-30, -4], [-6, 4], [26, 3], [-16, -11], [46, 5], [-6, -13], [16, -12], [-2, 7], [18, 11], [8, -6], [26, -16], [-2, -5], [-10, 8], [26, -14], [10, 19], [40, 6], [-6, -4], [-20, -16], [10, 12], [14, 14], [-2, 6], [-18, 21], [-2, -4], [18, -27], [20, -15], [6, -20], [-10, 7], [4, 2], [-22, -7], [-14, 16], [12, -16], [2, 20], [-28, -14], [-2, 15], [36, -5], [40, -11], [-2, 12], [40, -16], [-10, -12], [10, -18], [-10, 28], [-2, -17], [44, -2], [42, -4], [-32, -2], [22, -8], [10, 6], [-12, 24], [10, -31], [-38, 17], [-6, 12], [-2, 13], [-24, 3], [10, -8], [-18, 24], [-6, 29], [-36, 1], [-6, 26], [-22, 3], [-8, 18], [2, -22], [12, -6], [-6, 22], [18, -28], [0, -6], [-38, -2], [18, -15], [-10, -6], [18, 0], [-30, 18], [-14, 14], [42, 11], [54, 0], [14, 8], [-58, 8], [-18, 6], [42, 2], [-22, -18], [18, -34], [-38, 4], [-22, -20], [30, 10], [-10, -13], [44, 3], [38, -12], [-36, 26], [14, 0], [18, 12], [28, -8], [36, 12], [-58, 10], [-22, -18], [-6, 9], [-10, -14], [-54, 1], [-6, -7], [42, 0], [10, -22], [26, 2], [2, -16], [-12, 23], [30, 0], [54, 3], [-62, 10], [-24, 9], [14, 4], [-6, 0], [-38, 20], [-40, 21], [6, -26], [-46, -2], [-12, 0], [10, -1], [50, -5], [26, 20], [-46, -5], [-34, 2], [-30, -6], [-42, 3], [36, 0], [2, -11], [-38, 6], [22, 20], [36, -2], [-44, -2], [32, -30], [-2, -24], [8, 20], [-38, 26], [34, 10], [-26, -12], [-48, -4], [14, -21], [42, 13], [14, 8], [-30, -5], [44, -13], [-10, -2], [-14, 1], [-34, -1], [-30, 15], [-26, -8], [-64, 4], [-54, 4], [-42, 16], [-6, -2], [8, -7], [68, -8], [-2, -9], [32, -19], [-46, -7], [-12, -6], [-30, -3], [24, -14], [-62, 0], [6, -28], [66, 2], [-4, -24], [18, -3], [4, -20], [44, 16], [-22, 23], [26, -12], [40, -1], [26, -9], [-18, -16], [46, -27], [30, -19], [-6, -24], [-10, 8], [34, 14], [-14, -7], [58, 11], [22, -2], [58, -15], [-32, -8], [40, -24], [72, 3], [26, -20], [38, -8], [-54, 12], [-78, 4], [28, -18], [-10, -8], [42, -16], [-10, 4], [-8, 16], [-74, 4], [8, -27], [2, -22], [4, -8], [-62, 13], [-14, 32], [46, 0], [6, -16], [-50, 0], [32, -18], [-46, 14], [-38, 28], [-46, 15], [-6, -2], [10, 32], [24, -32], [-30, -15], [-46, 27], [-6, 25], [-26, 24], [-32, -19], [42, 12], [14, -16], [20, -26], [10, -2], [4, -7], [46, -24], [20, -20], [-62, 8], [68, 2], [18, -25], [-40, -4], [30, -23], [-30, -2], [-42, 21], [26, 23], [-26, 26], [42, 11], [-54, 3], [18, 10], [10, 8], [0, -6], [-26, -6], [-30, 9], [-8, -23], [14, 2], [2, 26], [50, 3], [-12, 23], [-68, 15], [54, -21], [-6, -21], [-16, -18], [34, -38], [18, -6], [34, 16], [46, -8], [18, -12], [-22, 18], [22, -37], [-14, 13], [40, -12], [-78, 3], [-6, -30], [8, 21], [22, -26], [-2, 28], [-22, 43], [6, -4], [-50, 6], [-30, -4], [14, 24], [6, 33], [32, -10], [-22, -14], [-2, 5], [22, 8], [26, -20], [-10, 17], [-16, 15], [-50, 1], [-78, -1], [-18, 24], [34, -6], [50, 20], [26, -3]];
    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_r();".
// 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_r(:prec:=2)
    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_r();".
// 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_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3712_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, 1, 1]>,<5,R![-2, -3, 1]>,<7,R![0, 1]>],Snew);
    return Vf;
end function;