
// Make newform 3200.2.a.bo in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3200_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_3200_2_a_bo();".
// 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_3200_2_a_bo();".
// 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 := [1, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-2, 0, 1], [2, 2, -1]];
    Rf_basisdens := [1, 1, 1];
    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_3200_a();"
function MakeCharacter_3200_a()
    N := 3200;
    order := 1;
    char_gens := [1151, 901, 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_3200_a_Hecke(Kf)
    return MakeCharacter_3200_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, 1, 0], [0, 0, 0], [-1, 0, -1], [0, -2, 0], [2, 1, 1], [-2, 2, 0], [0, 0, -2], [-3, 0, 1], [2, 0, 0], [-4, 2, 2], [4, -3, -1], [2, -3, -1], [-5, -1, 2], [-1, -2, 1], [6, -1, -1], [0, 0, 2], [4, -3, 1], [-3, -3, 2], [4, 2, -2], [-6, -4, 2], [-4, -2, -2], [-9, -1, -2], [-2, 0, -4], [-10, 2, 0], [-2, 4, -4], [-7, -4, 1], [1, 3, 4], [-8, -1, -1], [-8, 4, 4], [-9, 2, 1], [8, 4, -2], [0, -2, -6], [-8, 2, 0], [-4, -1, 3], [16, -4, 0], [4, 3, 1], [-9, 1, 0], [-1, 0, 3], [4, 1, -5], [0, 2, 4], [-2, 4, 4], [-8, -4, -4], [-10, 2, 0], [6, 1, 5], [12, -2, 2], [8, 4, -2], [-15, 10, 3], [1, 7, 0], [2, 8, 0], [-6, -4, 2], [4, -2, 6], [-2, 5, -1], [-16, 10, 4], [8, -4, 4], [5, 0, -3], [-20, 7, 3], [-4, -10, 6], [4, 1, -5], [-6, 5, 3], [-9, 1, 0], [0, -1, 1], [-3, -7, -2], [8, 4, 0], [0, -2, -6], [-6, -1, -5], [-16, -4, 2], [-4, -4, 0], [5, -3, 2], [18, 4, -4], [12, 4, 0], [-8, -4, -8], [-5, -10, 1], [-4, 7, -3], [-8, 6, 4], [-11, 10, -1], [12, -5, -1], [26, -5, -1], [-6, 0, -4], [-10, 3, -7], [-16, 6, 0], [4, -3, 1], [-12, 6, -2], [-10, 2, -8], [8, 12, 0], [15, 1, 0], [2, 3, -7], [-4, 10, 2], [-2, -12, -4], [13, -10, -9], [-3, 3, 0], [8, -8, 0], [-5, 8, -5], [8, 0, -2], [16, -10, 0], [9, 4, -7], [26, 0, 0], [-6, -4, 4], [7, -11, 4], [14, -4, -4], [-27, 7, 4], [-20, -9, 5], [19, -3, -8], [6, 7, 5], [0, -2, -8], [-12, 4, -8], [17, -7, -6], [8, 0, 0], [-12, 6, 10], [-14, 5, -5], [-9, -2, 9], [-6, -17, 3], [2, -12, -6], [-16, 16, 2], [0, 4, -8], [22, -7, 3], [3, 3, -10], [3, 4, -1], [-26, -3, 1], [-24, -2, 0], [0, -3, -11], [2, -2, 8], [-6, -3, -3], [-5, -1, -6], [0, 0, 10], [0, 9, -7], [10, -4, -4], [28, -2, -2], [-13, 0, -5], [0, 9, -1], [16, -14, -4], [13, -4, 1], [0, -4, -4], [8, -3, 3], [14, -8, -4], [-6, 20, 4], [-2, 3, 3], [-7, 9, 10], [-2, -5, -5], [6, -12, -4], [16, -6, 4], [-24, 9, 9], [-7, -8, -3], [9, -3, 6], [20, 15, -5], [-16, 4, -8], [-2, -1, 15], [36, 6, -2], [8, 0, 10], [21, 2, 11], [0, 11, 5], [-2, 13, -5], [-13, -3, 0], [11, -12, -9], [13, -13, -8], [28, -6, 2], [4, -10, -6], [-14, -9, 5], [-10, -8, 2], [-10, 12, 12], [13, -7, -10], [20, -14, 2], [-37, 12, 3], [24, 0, 14], [-6, 22, 0], [1, 4, 5], [16, 8, -8], [34, -3, -3], [-6, 4, -12], [10, -5, 7], [40, 6, -4], [-2, 20, -4], [-8, 0, 12], [-10, -8, -6], [-16, -12, 4], [-6, -4, 12], [-8, 18, 4], [22, -8, 0], [1, 20, 1], [-40, -1, -9], [-13, 2, -11], [-40, -8, 2], [26, -17, -13], [-22, -4, 10], [9, 14, 3], [-22, 12, 4], [4, 11, 1], [-33, 3, -6], [6, 3, -7], [24, -16, -8], [-12, -16, 4], [19, -11, -8], [-24, 0, -6], [8, -19, 5], [9, 21, -2], [6, -4, -2], [6, 1, 15], [-14, 13, -3], [-16, 20, 4], [-39, 8, -3], [-14, -8, 16], [-8, -8, -8], [34, 9, 1], [2, 12, 8], [40, 0, -6], [-16, 23, 9], [-12, 10, 2], [-9, -5, 18], [10, -4, -4], [32, 8, -10], [-22, -18, 8], [-12, -7, 5], [9, -12, -3], [9, -3, -2], [-12, -6, 14], [26, 1, 3], [-5, 18, 13], [10, -24, 4], [3, -28, 3], [30, 9, -3], [0, 1, -15], [8, -12, 8], [22, -16, 4], [-47, 10, 3], [-11, 9, -2], [-8, -1, 15], [-10, -12, 14], [-4, 26, -6], [-65, 0, 3], [8, 0, -2], [6, -3, -15], [16, -10, 8], [24, 20, -12], [-22, -7, -1], [-45, 7, 2], [19, -10, 9], [26, -21, -7], [18, 3, -1], [32, -4, -2], [-48, 16, 4], [-9, 15, -10], [8, -18, 0], [-31, -4, -3], [-14, -8, 0], [4, -16, -4], [-48, 16, 4], [-45, 6, -7], [-16, 10, 16], [8, -16, 2], [-59, 10, 3], [58, -1, 3], [30, 20, -8], [15, 20, -13], [-26, -13, 5], [-40, 5, 3], [-24, 0, 14], [14, -24, 0], [-19, -3, -14], [-12, 13, -9], [-36, 18, 2], [17, -10, 3], [1, -9, 8], [2, -4, 4], [24, -15, 7], [2, -22, 4], [40, -10, -8], [-22, -8, -16], [22, 4, -12], [-29, -7, -12], [28, 3, -7], [6, -16, 0], [-51, -5, -8], [-22, -4, -22], [-4, 14, 6], [-20, -12, 8], [-43, -4, 9], [17, 7, -16], [34, -8, -16], [-22, -11, 3], [-16, -10, 12], [-11, -10, -17], [-12, 6, -6], [3, -4, -5], [-10, -12, 12], [-35, -7, 6], [8, -4, -12], [-18, -10, -12], [10, -7, -7], [44, 6, 2], [-14, 3, -11], [-4, -3, 1], [13, -15, -10], [6, -8, -14], [-8, 4, 2], [16, 21, -13], [4, 7, 3], [-8, -16, 24], [-16, 35, 5], [32, -12, 6], [21, -25, -12], [-32, 6, 10], [28, -25, -11], [-24, 24, 8], [-1, -9, -26], [0, 18, 4], [-38, 18, 4], [25, 19, 4], [-6, 12, 20], [-8, 32, -4], [-44, 19, 9], [21, 14, 3], [-14, -16, -8], [-58, 4, 4], [-21, 9, 4], [-5, 16, 23], [14, 16, 12], [-24, 8, -10], [4, 18, 10], [24, -4, 20], [10, 15, 17], [40, 4, -2], [8, -2, 10], [-28, 21, 1], [-3, -14, 3], [44, 10, 10], [14, 1, 3], [24, 18, 4], [-9, 25, 0], [63, 6, -7], [26, -25, -13], [-4, -11, 17], [-24, -1, 1], [-24, 8, 16], [51, -21, -10], [-40, 16, -2], [-27, -9, 4], [0, -9, -1], [20, -12, -8], [34, -3, -13], [-21, -2, -11], [-8, -5, 13], [-44, -6, 2], [16, -1, 23], [24, 4, 8], [-4, -19, -1], [0, 6, 24], [-20, 25, 13], [-31, -7, 10], [0, -4, -4], [-18, 5, 1], [-32, 6, -20], [40, -2, -14], [16, 13, -11], [1, 6, 15], [34, -4, 12], [-22, 20, 2], [-4, -18, 6], [-8, 8, -10], [-6, 2, -20], [33, -4, -3], [-6, 5, -3], [-14, -8, 12], [11, 18, 13], [24, -10, -12], [-15, 13, -10], [-34, 4, -2], [-10, 15, 15], [33, 20, -11], [-22, 17, 19], [32, 14, -4], [-48, -2, -12], [-11, 6, -17], [-24, 7, 23], [48, 12, 0], [-22, -17, 11], [-8, -24, -10], [40, -24, -16], [-8, 0, -8], [10, 7, -3], [-4, -6, 10], [-26, -4, -20], [-4, -30, 18], [-33, -20, -1], [48, -20, -4], [0, -2, 32], [-3, 16, -15], [-40, -8, -8], [-4, -15, -5], [3, 17, -12], [-5, 14, 5], [18, -21, 13], [-12, -5, 9], [40, -14, 8], [-7, 27, -12], [4, 22, 2], [80, 2, -2], [-32, 0, -16], [-10, 8, -8], [-24, 2, 12], [-44, 1, -11], [-12, -25, -5], [34, -14, -20], [31, 10, -15], [-24, -18, -6], [-12, -9, 3], [-12, 26, 6], [6, 7, -25], [10, -8, -12], [15, 7, -2], [0, -16, 6], [12, -12, -8], [-60, -7, 11], [-21, 25, -12], [64, -20, -10], [18, 4, -22], [30, 16, -8], [-12, 26, 18], [27, 20, -5], [-18, 6, 4], [37, -16, -3], [8, -29, 3], [42, -11, -19], [-37, -10, -19], [-16, 28, 6], [44, 6, 6], [-44, -17, 5], [43, 15, 2], [-18, -29, -3], [-16, -2, 8], [36, -14, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3200_2_a_bo();".
// 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_3200_2_a_bo(:prec:=3)
    chi := MakeCharacter_3200_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_3200_2_a_bo();".
// 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_3200_2_a_bo( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, -4, 2, 1]>,<7,R![-20, -4, 4, 1]>,<11,R![-8, -20, 2, 1]>,<13,R![16, 8, -8, 1]>],Snew);
    return Vf;
end function;