
// Make newform 3822.2.a.bz in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3822_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_3822_2_a_bz();".
// 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_3822_2_a_bz();".
// 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 := [28, 12, -11, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-6, -1, 1, 0], [0, -8, -1, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_3822_a();"
function MakeCharacter_3822_a()
    N := 3822;
    order := 1;
    char_gens := [2549, 3433, 1471];
    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_3822_a_Hecke(Kf)
    return MakeCharacter_3822_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+1)]];
    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 := [[1, 0, 0, 0], [-1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [2, 0, 0, 1], [-1, 0, 0, 0], [0, 0, 0, 1], [0, 1, 0, 0], [2, 1, 0, 0], [2, 0, -1, -1], [0, -1, 0, -1], [2, -1, -3, 0], [0, -1, 1, -1], [2, -1, 0, -2], [2, 1, -3, 1], [4, 1, 1, 1], [0, -1, 0, -1], [0, -2, -2, -1], [6, 2, 1, 0], [2, 3, 0, -1], [4, -1, 0, 0], [2, -1, -4, -1], [0, -2, 4, 0], [0, 0, -3, 2], [-2, 0, 2, -2], [0, -1, 2, 1], [4, -3, -7, 0], [2, 2, 3, -2], [2, -3, 5, 0], [2, -1, -2, 3], [0, -3, 2, -1], [0, 2, -6, 3], [4, -2, -4, -3], [8, 0, 2, 4], [2, 2, 2, 4], [10, -2, 2, 1], [4, -6, 0, -3], [-2, -5, -5, 3], [0, 0, 11, -3], [2, -5, -2, -3], [2, 0, -3, -2], [-6, -4, 4, -2], [2, 1, 14, 0], [6, -5, 0, -1], [2, 5, -2, 1], [8, 1, -1, 4], [2, 1, 0, 2], [8, 0, 10, -2], [-8, 1, -2, -1], [12, 3, -2, 5], [-6, 6, 6, 0], [-2, -1, -12, -1], [6, 2, 2, -2], [2, -2, 4, -3], [2, 0, -4, -2], [12, 4, -4, 4], [-4, 5, -2, 1], [0, 1, -8, -1], [-2, 3, 14, -1], [-8, -2, -4, 0], [20, -2, -4, -2], [2, 2, 6, 0], [8, 2, 8, 0], [-16, 6, 2, 4], [4, 2, 1, 4], [-14, -7, 10, -3], [-6, -4, -1, -6], [-14, 1, -10, 2], [6, 2, -9, 4], [-4, -5, -2, 1], [0, 1, -3, 7], [-10, -6, 6, -4], [2, 7, -7, 5], [-2, -3, 4, -5], [-2, 4, 3, -4], [-12, 4, 5, 1], [-16, 3, 7, -1], [0, -2, -4, 4], [-12, -2, 4, -2], [0, -3, -8, -6], [-8, -8, -2, 1], [-8, 3, -13, 1], [4, 8, -12, 2], [-4, -3, -7, -7], [20, 1, 7, -2], [6, -9, 1, 3], [-16, -6, 12, -1], [-10, 11, 0, 3], [-8, 1, -14, 0], [10, -6, 2, -1], [-12, 2, -2, -3], [-20, -2, -3, 3], [4, -2, -4, 4], [-2, -1, 9, -1], [-6, -4, 1, -4], [-4, 5, 2, -3], [0, -11, 6, -4], [-8, -4, 10, 1], [-4, 3, 4, -7], [10, 3, -9, 4], [0, -2, -6, 0], [2, -2, -10, 8], [6, 6, -8, 3], [-6, 2, -8, 6], [-12, 2, 16, 0], [-2, 0, 4, -6], [12, -2, -2, 4], [0, 0, 7, -2], [2, -7, 6, 0], [-16, 5, -9, -3], [4, -3, -1, 6], [-6, 9, -7, -4], [-10, -8, 8, -11], [18, -5, -6, 0], [-14, 0, 10, -1], [-10, -5, 14, -5], [6, -3, -2, 4], [20, 0, 4, -4], [18, -8, -17, -3], [10, -3, -13, -3], [-2, 0, 24, 0], [-6, 9, 14, 2], [-4, -4, -12, -2], [2, 0, -14, 1], [16, -12, -8, -2], [-20, -3, -9, -3], [-12, 7, -5, -7], [4, 1, 18, 5], [-16, -7, 9, -2], [22, 1, -2, 7], [6, -1, -5, -5], [12, 2, 8, 4], [4, -5, -14, -1], [-2, 5, 6, 1], [-16, 1, -5, 5], [16, 5, 0, 0], [-12, -5, 12, 0], [14, -13, 6, 2], [-10, -5, -10, -5], [-18, 5, 16, 1], [0, 1, -4, -2], [10, -2, 10, -8], [10, -5, 12, 5], [-18, 6, 22, 1], [28, -2, 2, -1], [-18, -9, 11, -1], [10, -6, -12, -4], [-26, 10, 8, -2], [16, 0, 8, -4], [2, 6, 6, 2], [20, -11, -1, -3], [12, 10, -10, -1], [-10, 1, -4, 2], [-20, -8, -2, -4], [-4, 8, 4, 2], [-2, -1, -28, 4], [-2, -4, 18, 0], [-8, 7, 17, -1], [-16, -4, -5, 4], [-10, -2, 18, 2], [2, -4, 14, -3], [26, 8, -6, 2], [2, 0, -30, 5], [-30, 2, 2, 0], [-14, 2, 4, 5], [0, -6, -1, -5], [-2, 10, 10, 2], [-14, 6, 14, 6], [2, -5, 24, -7], [4, 13, 6, 3], [-2, 6, 24, 1], [18, -3, -22, 1], [12, 2, 2, -4], [6, 2, -14, 6], [-4, -7, -11, -4], [-18, 2, -16, -6], [10, -6, -1, -4], [-26, 5, -6, 5], [30, -1, -1, 1], [0, 8, 18, -3], [6, -6, -14, 1], [-30, 10, -6, -4], [6, -10, -8, -6], [28, 5, -9, -1], [2, -3, -8, 1], [-8, 3, -14, 5], [-2, 0, 2, 2], [2, 11, 2, 8], [18, -4, 20, 0], [0, 0, 3, -3], [-20, 9, 7, -3], [6, -8, 0, -1], [16, 0, 0, -2], [0, 1, 6, 6], [14, -7, 1, 5], [44, 2, 2, -3], [-26, -9, 16, -1], [30, 1, -6, 1], [16, -12, -7, -6], [-12, -1, -10, -3], [2, 4, 4, 6], [-24, -7, -5, -4], [18, 9, -2, 1], [-8, 8, -25, 4], [-8, -4, 16, -8], [6, -2, 16, -10], [16, -11, 14, 1], [18, -1, 1, 1], [18, 0, -16, 9], [20, -3, 12, -9], [-28, -3, 2, -10], [-30, 0, -16, -6], [20, 0, 12, 6], [-12, 4, -22, 2], [0, 10, -23, 5], [0, 11, 16, -6], [22, 0, 22, 0], [-44, 2, 0, 1], [24, -19, -6, -9], [-10, 5, 26, 5], [-2, -16, -12, 2], [24, 7, 10, -5], [-30, -6, -12, 1], [20, 2, 12, -6], [18, -6, 12, 1], [10, 15, -18, 7], [12, -8, 10, 9], [12, -6, 2, -10], [0, -5, -15, 8], [-14, -6, -6, -3], [2, 9, -18, 1], [-8, 3, -24, -5], [-6, -2, 6, 7], [-6, -6, 20, 0], [-16, 6, 14, 8], [-44, 4, -9, 3], [-8, -7, 32, 0], [6, -4, 10, -6], [34, -1, 7, -1], [-20, -7, -6, 3], [32, -4, -6, -2], [8, -12, 14, 4], [-16, 7, 5, -12], [-32, -5, 11, 1], [-8, 14, 5, -4], [-24, 13, 24, 7], [-24, -3, 14, -5], [-12, 15, -4, 3], [30, 7, -9, -1], [14, 3, 26, -14], [14, 5, -3, 10], [16, 0, 29, -4], [-8, -9, -18, 1], [44, -12, 3, 4], [-24, 8, 28, 4], [-6, -2, -36, 5], [6, 4, -18, 6], [30, -16, -26, -4], [-2, 1, -2, 3], [-36, 5, -2, 4], [6, -15, 4, -17], [14, 4, -5, 6], [8, -8, -20, 2], [0, 4, -2, 13], [24, 8, -7, 16], [-8, 3, 4, -1], [18, -3, 6, 11], [-20, -6, 17, 0], [10, -2, 25, 2], [28, -3, 31, 1], [2, 0, -4, 12], [10, 13, 13, -7], [-8, -7, 8, 0], [22, -8, 2, 10], [-12, 15, 11, 3], [-24, 8, -4, 4], [-22, 14, -8, 5], [6, 7, -33, 4], [-18, 6, -8, 4], [-8, 6, 20, 0], [20, -2, -2, 14], [42, -12, -8, -7], [-36, 5, 8, -5], [0, 6, 4, 2], [22, 1, -26, 4], [12, -14, 4, 8], [18, -1, -26, -2], [-26, -7, -28, 7], [0, 14, -16, 6], [-8, 12, 24, -3], [-2, -4, 37, 1], [12, -2, -10, 11], [32, -10, -16, 1], [-32, -12, 20, -12], [30, -10, -2, 6], [-30, -1, -18, -9], [-34, 13, 15, -1], [26, 12, 8, 0], [8, -6, 6, 1], [2, 13, 6, -6], [-20, 10, -11, -12], [-22, 16, -6, -10], [-4, -6, -28, 12], [-10, -8, 7, 2], [-6, -3, 6, -18], [-26, -1, 10, -13], [30, -11, 11, 11], [-8, 0, 30, -7], [-28, -11, 14, -7], [26, 6, 40, -14], [-8, -1, -18, -3], [22, 4, 2, 2], [-2, 15, 2, 1], [-10, 15, 0, 0], [-10, -16, 34, -8], [-36, -1, -19, -1], [-12, 8, 32, -4], [0, 7, 18, 1], [-32, -1, -6, -2], [18, -8, 18, -8], [-24, -7, 0, -19], [-30, 9, 14, 1], [-14, 11, -14, 15], [26, -2, -8, 1], [-12, 10, -4, 3], [-16, 15, 7, 17], [22, 9, 13, -1], [0, -1, -28, 10], [10, -7, 26, -2], [-2, -8, 9, -1], [58, 1, 11, 4], [-10, 4, 17, -5], [-10, -3, 15, 3], [-8, 11, -2, 5], [-14, -9, -29, 13], [-4, 4, 22, -6], [2, 3, 33, 4], [44, 9, 15, -7], [-10, -14, -8, 0], [-20, 23, 7, 4], [40, 9, -9, 9], [-22, 5, -30, -5], [44, 5, 6, -8], [6, -10, 14, 2], [2, -5, 0, 9], [42, -2, 7, 6], [-12, 14, 0, 19], [14, 4, -35, 2], [18, -11, -15, 13], [22, -10, -8, -14], [0, -6, 20, -8], [10, -5, -24, 11], [46, 4, -14, -2], [-18, -9, 43, -3], [-34, -11, 20, 1], [24, -24, -6, 1], [-20, -8, 5, -11], [8, -1, -4, -3], [18, -1, 24, 3], [24, 15, -34, 5], [2, -5, 15, -16], [28, 4, -10, 3], [2, 13, -24, 10], [32, 8, 0, 4], [24, -8, -28, -2], [-22, -16, 0, 2], [12, 1, 6, -10], [18, -14, -4, -13], [26, -9, -22, 8], [-2, -16, 1, 4], [-24, 17, -16, 3], [16, 7, 10, 1], [-26, 8, -7, -5], [16, 7, -9, 10], [-2, -15, 12, 7], [-4, 12, -14, 24], [22, 1, 14, 0], [-28, -9, 14, -10], [16, -10, 28, 3], [-40, 18, -15, -10], [26, 6, 20, 8], [12, -8, 28, -3], [6, 4, 6, 15], [-20, 0, 8, -14], [0, -2, -28, -4], [28, 10, 13, -1], [-14, 14, 12, 9], [-56, -4, 18, -3], [42, 3, 19, 5], [28, -1, -8, 11], [10, -14, -18, -2], [18, 6, -6, 12], [-20, 14, -20, 14], [-12, 5, 0, -9], [16, -1, 2, 5], [34, -4, 8, 2], [-20, 5, -32, -5], [-16, 2, -28, -7], [18, 15, -14, 6], [-22, -5, -4, -19], [22, 12, 12, -6], [10, 13, 0, 5], [42, 4, 8, 17], [68, 3, -11, 3], [42, -4, -12, 2], [-28, -1, -21, -4], [-20, -17, 19, -23], [-20, 12, -24, -9], [22, 9, 30, -12], [16, 8, 12, -12], [-28, -18, 5, 2], [46, 4, 13, 9], [-14, -11, 13, -13], [42, -9, -12, -8], [-48, -1, 10, 6], [18, -10, -28, 0], [-20, 15, 2, 7], [-40, 7, -7, -16], [72, 5, -7, 7], [8, -16, -6, 4], [34, -10, -25, -1], [-60, -8, 0, 2], [26, -14, -6, 0], [-30, -6, -10, 2], [-4, 7, 10, -12], [46, -6, 22, -2], [22, -12, 17, -4], [-18, 20, 20, 6], [-14, -15, 10, 2], [-32, 4, 22, -12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3822_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3822_2_a_bz();".
// 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_3822_2_a_bz(:prec:=4)
    chi := MakeCharacter_3822_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_3822_2_a_bz();".
// 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_3822_2_a_bz( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3822_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![28, 12, -11, -2, 1]>,<11,R![-64, 80, -9, -6, 1]>,<17,R![28, 4, -21, 2, 1]>,<29,R![-2, 12, 7, -10, 1]>],Snew);
    return Vf;
end function;