
// Make newform 3450.2.a.bo in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3450_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_3450_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_3450_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], [-1, 2, 0], [-4, -2, 2]];
    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_3450_a();"
function MakeCharacter_3450_a()
    N := 3450;
    order := 1;
    char_gens := [1151, 277, 1201];
    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_3450_a_Hecke(Kf)
    return MakeCharacter_3450_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], [1, 0, 0], [0, 0, 0], [-1, -1, 0], [0, 0, -1], [-1, 1, 0], [-2, 0, 1], [-1, 1, 0], [-1, 0, 0], [5, 1, 2], [-4, 0, 0], [-7, 1, 1], [-2, 0, 2], [-3, 1, -1], [2, -2, -2], [-3, 1, 0], [0, -2, -2], [-5, -1, -3], [-7, 1, 1], [3, 3, 2], [-2, 2, 0], [-2, -2, -3], [-7, -1, -1], [2, -2, 0], [1, -3, 0], [7, -1, -2], [-3, 1, 2], [-3, -1, -3], [-3, -3, 3], [-10, 0, 1], [-5, -3, -2], [0, -2, 0], [-10, -4, 1], [-6, -2, 2], [8, 0, -1], [4, 0, 2], [-3, 1, -3], [-2, -2, 2], [-10, 2, -2], [-2, 4, 4], [2, 4, 0], [-5, 7, 3], [2, 2, -4], [2, 2, 0], [16, 2, 0], [-2, -2, 3], [-2, -6, 0], [-9, -3, -2], [5, 3, -3], [-5, 3, -3], [-14, 0, -4], [9, -3, -4], [4, 6, 2], [2, 6, 5], [6, 0, 4], [10, 2, 4], [13, 5, -4], [-8, -8, 2], [1, -5, 0], [4, -4, 0], [13, 1, 1], [13, 1, 0], [-8, 4, -2], [5, 1, 4], [-1, -9, -2], [-4, 2, 4], [-14, -6, 4], [-25, -1, 0], [18, 2, -2], [-2, 4, 4], [-22, 0, -4], [-12, 4, -2], [3, -5, 0], [9, -3, -3], [-23, -1, -4], [-8, 8, 2], [2, -6, 1], [11, 1, 2], [-24, -4, 2], [-2, 4, 0], [-8, -4, 3], [7, -1, -1], [-12, -4, -8], [3, -1, 8], [-18, -2, -4], [-8, 4, -2], [26, 0, 2], [11, 3, 2], [-17, -5, -8], [7, 9, -2], [9, 7, 5], [-6, -6, -2], [-17, -7, 2], [-4, 2, 8], [4, 0, -6], [12, 0, 8], [-11, -7, 2], [12, -4, -2], [27, 3, -1], [16, 6, -4], [12, 0, -2], [-1, -5, -8], [17, 3, 3], [-6, 10, 6], [1, 7, 10], [4, 0, 0], [6, -2, -8], [-2, -8, -4], [-5, 3, 8], [6, 0, -4], [15, 9, 2], [-17, 7, 1], [-10, -4, 7], [-23, -1, 0], [0, -4, -1], [-6, 2, -6], [3, -5, -9], [-4, -4, -8], [18, -4, -4], [18, -6, -1], [-7, 9, 1], [28, 4, 4], [3, -5, 4], [-10, -2, -4], [-20, -4, -10], [0, -8, -1], [-7, 5, -5], [15, -1, 4], [-3, 1, 0], [17, 1, -1], [-10, 10, 2], [8, 8, 2], [8, 4, -3], [13, 1, 1], [-12, -6, 8], [8, -10, -4], [-23, 1, 4], [23, -1, 3], [9, -3, 8], [28, 6, -4], [-16, 4, -2], [9, -7, 2], [23, 5, -2], [27, 5, -5], [-20, -6, 8], [10, 2, 6], [27, 1, 2], [-18, -4, -6], [-6, -6, -2], [10, -10, -8], [-11, -5, 0], [8, 0, 4], [6, -2, -6], [24, -8, -6], [3, 3, 1], [-10, -2, -4], [-14, 2, 5], [-6, 8, -2], [3, -5, -8], [12, -4, -9], [-10, -2, 8], [-12, -6, -7], [-7, -13, 2], [6, 2, 5], [-6, 12, 11], [-2, 2, -6], [12, 0, -4], [5, 3, 6], [28, 6, 10], [16, 2, -8], [-18, -2, 1], [6, -4, 2], [-4, -12, -2], [-23, 1, -4], [16, -8, -2], [-2, -10, -8], [22, -2, -2], [3, 3, 8], [39, 7, -2], [5, 1, -3], [-43, 3, 2], [6, 2, 1], [1, 11, 8], [2, 4, 10], [-20, 8, 0], [46, -2, 1], [27, 5, 10], [-19, -3, -11], [4, -6, 6], [33, 1, 10], [-4, -8, -12], [14, 6, -10], [-25, -7, 6], [13, -3, 4], [-27, 3, 3], [-12, -10, 1], [22, -8, -4], [15, 7, -3], [-12, -2, -11], [6, -6, 4], [-10, -2, 5], [12, 12, -2], [3, 9, -8], [-6, -8, 0], [-16, -4, -7], [16, 10, -4], [-26, 6, 3], [-24, 4, 6], [16, 14, -2], [24, 4, -6], [22, -6, 4], [17, -7, -4], [-15, -3, -6], [-15, 3, 1], [-45, 3, 2], [0, -10, 6], [-3, 3, 2], [24, 6, 0], [-20, 4, 8], [24, -2, -4], [20, 2, 10], [-32, 4, -1], [52, -2, 4], [19, 3, -10], [16, -4, 0], [10, 8, -2], [-14, 12, 9], [-39, -3, -6], [35, 7, 2], [-36, 2, 2], [3, -7, -6], [-1, 1, -4], [8, -4, -5], [4, 14, -2], [-11, 9, 13], [-12, 16, 12], [-44, -6, -12], [-17, -1, 6], [-30, 4, 0], [-23, 9, 6], [-35, -1, 7], [-30, -2, 4], [-29, 9, 2], [14, 8, 6], [-10, -4, 0], [19, -1, 4], [-21, -11, -2], [12, 12, -5], [13, 11, 12], [-30, 10, 2], [27, -5, -5], [-14, 18, 8], [4, -12, -2], [-34, 8, 6], [12, 2, 20], [-14, -4, 6], [1, 9, 7], [-13, -13, -5], [-6, 4, -12], [14, 14, 8], [1, -3, -6], [7, -15, 1], [22, -4, 6], [-9, -1, 5], [30, -8, -6], [3, -3, -16], [22, -10, -3], [8, -12, 0], [-13, -1, 15], [-8, 6, 4], [20, -6, -2], [-25, 11, 9], [3, 7, -2], [-20, -8, -3], [-10, 10, -8], [1, -9, -14], [-28, -8, 10], [44, -6, -4], [-6, 4, 8], [-48, 0, -3], [14, -14, -8], [16, -12, 1], [6, -14, -8], [-23, -3, 11], [30, 10, 6], [1, -11, -12], [21, -3, -6], [21, 13, 2], [22, 6, 8], [-52, -6, 2], [-16, 0, 13], [29, -9, -11], [42, 8, -8], [-2, 6, 9], [-13, -11, -18], [-28, -4, -3], [-6, 18, 11], [4, -10, 4], [16, -2, -6], [-44, 0, 4], [-31, -11, 0], [-47, -11, 8], [-14, -14, -7], [32, -12, -2], [-5, 13, 8], [-8, -4, -16], [-36, 16, 6], [63, -1, 1], [-12, 4, -4], [-43, -9, 8], [-22, 6, -4], [-30, 2, 13], [20, -4, -6], [-24, -12, 4], [10, 14, 6], [-30, 8, -8], [26, 0, -6], [37, 5, -6], [5, 5, 12], [16, 10, 10], [33, 7, 6], [-55, -3, -4], [-1, 11, -8], [-27, 7, 6], [-20, 6, 3], [-36, -10, 6], [-43, 11, 2], [-4, -16, -20], [-2, 14, 6], [-3, 1, 4], [10, 0, -2], [0, -18, -4], [-20, -20, 8], [30, 14, 10], [-31, -9, -12], [2, -6, 10], [31, -1, -11], [10, 16, 7], [22, 16, -12], [-3, 13, -6], [-19, -1, 0], [-26, 0, 1], [1, -3, 0], [10, 18, -3], [-1, 19, 10], [-4, 18, -2], [-20, -6, -6], [6, 18, -6], [40, 16, -10], [-29, -5, -10], [-6, 26, 6], [-42, -6, -12], [31, -9, 4], [-5, 7, -8], [39, 11, 17], [6, -4, -16], [-26, 6, -10], [-18, -6, -13], [38, -8, -2], [16, -16, 2], [-25, 3, 13], [-52, 10, 6], [8, -16, 6], [-38, -14, 1], [-16, -16, 4], [10, 10, 8], [24, -2, 0], [-21, 3, 16], [16, 14, -12], [32, -6, 4], [14, 6, 8], [-24, 8, -6], [-24, -16, 3], [60, -8, -3], [-11, -5, -22], [-32, -6, -12], [-14, -14, 4], [11, -9, 6], [48, 0, 6], [-24, 12, 4], [38, 14, 5], [-48, -2, 3], [-27, -1, 10], [-50, -4, -2], [-19, 3, -20], [56, 8, 0], [-8, 0, 2], [1, -21, 4], [-3, 1, -5], [-56, 4, -4], [38, 8, 8], [-10, -16, 0], [-2, -4, 18], [-8, -16, -6], [-32, -16, 0], [-1, -5, -4], [24, 4, 11], [40, 0, -6], [-9, -7, -2], [25, 1, 12], [-30, 12, 8], [6, 0, -14], [-57, -5, -12], [32, 14, 1], [-3, 1, -12], [18, 6, 14], [7, -1, 3], [30, 0, -2], [29, -7, 1], [-62, 0, 4], [62, 10, 4], [-46, -16, 0], [17, -9, -13], [-37, -3, -10], [37, 9, 18], [-9, 27, 10], [15, 11, -14], [35, 13, -2], [16, 22, 3], [6, 2, 24], [-14, 2, -17], [7, 7, 19], [-46, 22, 12], [52, 6, 10], [28, 16, -8], [50, 0, 12], [11, 1, -15], [-2, 12, 4], [-66, 6, 4], [9, -19, -10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3450_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_3450_2_a_bo(:prec:=3)
    chi := MakeCharacter_3450_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_3450_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_3450_2_a_bo( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-8, -12, 2, 1]>,<11,R![-16, -16, 0, 1]>,<13,R![-16, -8, 4, 1]>,<17,R![-8, -4, 6, 1]>],Snew);
    return Vf;
end function;