
// Make newform 3800.2.a.o in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3800_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_3800_2_a_o();".
// 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_3800_2_a_o();".
// 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 := [-2, 0, 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_3800_a();"
function MakeCharacter_3800_a()
    N := 3800;
    order := 1;
    char_gens := [951, 1901, 1977, 401];
    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_3800_a_Hecke(Kf)
    return MakeCharacter_3800_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 := [[0, 0], [0, 1], [0, 0], [2, 2], [2, 2], [2, -1], [0, 2], [-1, 0], [-2, -4], [-2, 4], [4, 2], [-2, 1], [-2, 2], [6, 2], [2, -2], [2, 7], [-4, -2], [0, -4], [0, -7], [0, -6], [4, -2], [0, 6], [-10, -4], [-2, -8], [6, -5], [-8, 0], [0, -7], [12, 3], [-2, -6], [10, 1], [0, 9], [-12, -4], [0, 2], [18, -2], [4, 0], [-8, 4], [4, -6], [6, 6], [4, -5], [-10, 1], [20, 2], [14, -8], [8, 8], [6, -5], [16, -4], [0, -8], [0, -16], [0, 7], [12, -5], [-8, 8], [12, 12], [8, -12], [6, -2], [4, 0], [-6, -3], [6, -8], [6, 10], [22, -2], [12, -2], [-14, -6], [14, -12], [-14, 3], [4, -1], [-26, 2], [4, 12], [2, -9], [-8, -4], [-6, -7], [-18, 0], [6, 16], [0, -10], [-2, -6], [6, 10], [18, 7], [-12, -8], [-12, -1], [2, -8], [16, -2], [-10, -12], [-34, -2], [12, -16], [18, -14], [4, -24], [-22, -11], [20, 6], [-6, 16], [-18, -6], [8, -12], [6, -8], [14, 12], [14, 4], [-10, -2], [-20, 9], [12, -4], [-10, 18], [-26, 0], [-10, -24], [-30, 4], [36, -1], [4, 0], [-4, -3], [12, 2], [-44, -1], [-14, 18], [-22, -18], [12, -4], [18, 0], [8, -16], [20, 18], [-26, 10], [-20, -15], [-16, -6], [-4, -2], [34, -2], [-2, -14], [-26, 10], [-6, 12], [-18, 20], [0, -2], [-24, -6], [2, 18], [-26, 3], [-22, 7], [-28, -5], [2, 26], [20, 8], [22, 8], [-6, 6], [6, 18], [24, -8], [-12, 0], [12, -7], [4, 28], [-16, -16], [4, -20], [-8, -20], [-6, -5], [4, -23], [-14, -17], [10, -32], [-24, -2], [22, -12], [18, 6], [-32, -1], [22, 6], [0, 6], [36, 8], [10, 33], [20, -24], [-20, 17], [-14, 27], [-8, 20], [-6, -26], [-16, 11], [4, -5], [28, -4], [-16, 0], [-14, 0], [12, -10], [-2, 24], [30, 8], [26, 13], [-34, 4], [28, -6], [-10, -5], [-28, 23], [8, -20], [-20, 18], [-18, -12], [-40, 14], [-40, 4], [-2, -36], [18, -26], [-32, 20], [0, 0], [-24, 12], [-20, 20], [-8, 8], [52, 1], [-16, -20], [30, 4], [-20, -10], [-6, -5], [-2, -25], [-2, -16], [18, -8], [-10, 9], [36, -5], [-30, -22], [16, -4], [-6, -7], [-2, -8], [36, 6], [6, 10], [6, 26], [-30, -23], [30, -20], [32, -8], [16, -20], [22, -30], [22, 12], [-48, 4], [10, -21], [10, -28], [6, -34], [-16, 30], [-2, 6], [32, 3], [-22, 24], [12, 30], [16, -24], [0, -20], [22, -32], [-24, 27], [-4, 8], [-14, -2], [50, 2], [-2, 28], [-8, -3], [8, -28], [6, -18], [24, 4], [6, -32], [50, 0], [-4, -5], [6, -40], [-18, 23], [-24, -24], [24, -13], [-4, -4], [44, 0], [-48, -4], [-4, 4], [-6, 18], [14, 8], [-10, -22], [-16, 12], [8, -4], [22, -6], [-20, 16], [-28, 29], [28, 16], [-34, -6], [10, 20], [-42, -13], [-16, 4], [14, -22], [-8, 20], [36, -4], [26, 2], [40, -8], [-22, 0], [42, 0], [38, 10], [12, -32], [-20, 24], [-6, 40], [0, -27], [-14, 27], [28, 14], [0, -23], [16, 39], [4, -40], [42, -9], [20, 16], [-4, 6], [18, 20], [-64, -12], [48, 7], [-20, 36], [-18, 8], [56, -1], [4, 38], [-30, -2], [62, 11], [26, 6], [-2, 42], [58, 0], [38, 22], [46, -6], [36, -25], [10, 34], [26, -20], [-22, 16], [-34, 24], [34, 18], [60, -12], [10, -13], [-40, -4], [2, -22], [-18, -12], [34, -18], [-10, 11], [32, 4], [38, -7], [-32, 12], [-68, -10], [60, -16], [-8, 40], [10, 38], [24, -26], [-2, -39], [18, 50], [-24, -11], [20, -8], [-6, -43], [24, -9], [38, 12], [-40, -12], [48, 4], [30, 18], [-4, 16], [-34, 28], [-60, 7], [-10, -8], [-6, 0], [-10, 6], [20, -44], [-28, -16], [2, -28], [-36, 26], [-60, -6], [14, -30], [-12, 19], [-16, -30], [50, 14], [-12, -18], [4, 27], [56, 5], [-8, 26], [0, -4], [-2, -63], [6, -62], [18, 2], [50, 6], [-22, 26], [-34, 42], [-6, 17], [-18, 8], [-26, -44], [14, -27], [-8, -14], [18, -18], [-24, 14], [-6, -37], [12, 14], [2, 32], [48, -17], [0, -14], [40, 38], [0, -6], [-34, -1], [80, -4], [-36, -13], [6, 16], [30, -17], [-8, 12], [-4, 56], [-32, 2], [20, 9], [36, -14], [4, 36], [-52, -23], [8, -28], [26, 0], [18, -19], [-48, 18], [-28, 15], [50, -18], [10, 50], [-8, -34], [46, -14], [10, -22], [0, -20], [36, 26], [0, -8], [-56, -20], [-28, 4], [-82, -8], [22, 27], [-2, 8], [0, -60], [30, 22], [-4, 24], [4, 38], [-56, -15], [90, 2], [-12, -2], [42, -34], [-4, -39], [22, -18], [-42, 1], [52, 0], [18, -16], [24, 56], [14, 39], [0, 34], [-10, -16], [24, 34], [-62, -16], [2, -14], [80, -8], [-68, 7], [14, -9], [-22, 18], [-40, 20], [32, -30], [-62, 28], [-68, 7], [28, -44], [2, 17], [-16, -16], [-56, 11], [-6, 34], [0, 34], [-22, 8], [96, -6], [8, -35], [44, 38], [44, 19], [62, 22], [10, 7], [-14, -2], [52, -16], [-22, 17], [-18, -35], [-60, -17], [-28, -32], [44, -12], [22, 26]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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