
// Make newform 2112.2.a.b in Magma, downloaded from the LMFDB on 14 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2112_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_2112_2_a_b();".
// 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_2112_2_a_b();".
// 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_2112_a();"
function MakeCharacter_2112_a()
    N := 2112;
    order := 1;
    char_gens := [2047, 133, 1409, 1729];
    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_2112_a_Hecke( : Kf := Kf)
    return MakeCharacter_2112_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], [-1], [-2], [-2], [-1], [-6], [-4], [-2], [8], [0], [0], [6], [0], [10], [0], [-14], [-12], [14], [4], [0], [6], [-2], [16], [-14], [-2], [-8], [12], [16], [18], [-10], [6], [4], [14], [14], [4], [-10], [10], [16], [12], [-8], [-4], [-22], [-24], [10], [-16], [-8], [-10], [-12], [-24], [-2], [16], [4], [-2], [-4], [2], [12], [-14], [10], [10], [32], [-14], [20], [-26], [8], [14], [-18], [8], [-18], [32], [6], [-6], [-24], [4], [-10], [-16], [-8], [-18], [14], [-2], [22], [12], [10], [12], [14], [2], [4], [-22], [22], [28], [12], [-12], [12], [16], [-16], [-4], [-20], [-14], [-42], [-22], [26], [-22], [-12], [4], [-20], [34], [2], [-12], [24], [0], [-14], [-34], [-42], [38], [32], [8], [-6], [32], [-8], [42], [-12], [18], [26], [32], [-12], [24], [12], [-18], [0], [48], [34], [26], [8], [40], [-38], [36], [34], [18], [-38], [6], [-44], [38], [-40], [28], [-16], [14], [24], [-18], [44], [40], [-8], [-18], [-2], [-44], [0], [16], [48], [34], [-42], [-38], [0], [12], [12], [-34], [60], [-10], [0], [16], [-10], [-2], [34], [44], [-2], [24], [38], [12], [-2], [50], [18], [30], [46], [8], [-36], [-6], [-12], [24], [10], [-38], [0], [-42], [44], [26], [-24], [60], [30], [-4], [-46], [18], [34], [-12], [24], [-28], [-58], [-22], [6], [-36], [-2], [-68], [28], [60], [68], [-54], [18], [32], [60], [48], [14], [2], [40], [32], [26], [-22], [14], [46], [20], [-4], [6], [-2], [24], [26], [-24], [-50], [-2], [70], [-20], [20], [-24], [-22], [-36], [-36], [-40], [60], [-46], [32], [-38], [-16], [-32], [-48], [-68], [-46], [-56], [-22], [24], [32], [-42], [-44], [-24], [22], [46], [30], [18], [26], [12], [66], [54], [66], [-52], [-46], [30], [-66], [-32], [-50], [72], [34], [-22], [22], [16], [-68], [-74], [58], [44], [-12], [32], [-72], [-50], [42], [72], [46], [48], [0], [-32], [-50], [-60], [24], [12], [-10], [28], [32], [58], [-48], [38], [-22], [-28], [-10], [-84], [28], [-18], [12], [34], [-24], [46], [-36], [-18], [24], [36], [68], [-74], [44], [-32], [-54], [12], [-42], [-38], [-28], [8], [16], [2], [-36], [44], [12], [-64], [-6], [78], [22], [32], [-6], [-36], [30], [-64], [-54], [-10], [-10], [-54], [44], [-76], [18], [88], [-70], [8], [16], [-46], [38], [-22], [-78], [78], [-18], [4], [40], [-88], [84], [56], [-2], [40], [-40], [-40], [-52], [26], [4], [30], [26], [36], [0], [72], [72], [42], [34], [-76], [44], [-46], [-20], [-82], [22], [90], [-98], [20], [2], [72], [80], [38], [42], [-48], [46], [90], [-92], [36], [16], [-58], [30], [-38], [24], [-72], [-10], [6], [-82], [-14], [-100], [-98], [-2], [-24], [-92], [-20], [26], [44], [-60], [18], [22], [46], [4], [-52], [26], [84], [-6], [54], [-32], [0], [74], [42], [36], [-16], [-56], [-108]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2112_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2112_2_a_b();".
// 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_2112_2_a_b(:prec:=1)
    chi := MakeCharacter_2112_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_2112_2_a_b();".
// 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_2112_2_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2112_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, 1]>,<7,R![2, 1]>,<13,R![6, 1]>,<17,R![4, 1]>,<19,R![2, 1]>,<23,R![-8, 1]>],Snew);
    return Vf;
end function;