
// Make newform 3675.2.a.bo in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3675_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_3675_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_3675_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, 2, -3, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1, -2, 1, 0], [1, -2, -2, 1]];
    Rf_basisdens := [1, 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_3675_a();"
function MakeCharacter_3675_a()
    N := 3675;
    order := 1;
    char_gens := [1226, 1177, 2551];
    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_3675_a_Hecke(Kf)
    return MakeCharacter_3675_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, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-1, -1, 1, 1], [0, -1, 1, 0], [0, -1, -1, -1], [0, -1, -3, 0], [-1, 1, 1, -3], [1, -1, -3, 1], [-4, 4, 0, -3], [-5, 2, 0, 2], [-8, 2, 2, -2], [-1, -6, -2, 6], [2, 3, -3, 0], [2, 4, 2, -2], [2, -5, -3, 2], [-8, 0, 0, 2], [-7, 4, 4, -4], [-3, 3, 5, 1], [4, -7, -1, 3], [-5, 8, 2, -4], [-2, -6, 0, 7], [-2, -3, 3, -4], [8, 0, -4, 1], [-8, 1, 1, 3], [-4, 1, 3, -2], [4, -6, 4, 8], [-7, 6, 0, 2], [3, -3, -3, 9], [-5, 0, -4, -4], [-8, 7, 3, 1], [8, 6, 0, -4], [-4, -5, 1, 1], [1, -3, 1, -3], [1, 2, 2, 6], [-4, 8, 4, -2], [4, -4, -6, -8], [2, -1, 5, 0], [-6, 5, -5, -10], [8, -2, -8, 8], [-16, 1, 3, 1], [6, 0, -4, -8], [-3, -6, 6, -2], [7, -5, 1, -3], [-8, 6, 10, -8], [2, -8, 0, 4], [-4, 9, -1, -11], [-10, -1, 1, 10], [0, -12, 0, 11], [-1, 3, -3, -3], [0, 2, 6, -10], [-8, 3, 9, -6], [-8, 1, 5, -13], [-2, 8, -2, -11], [19, -5, -3, 1], [-14, -2, 0, -3], [0, -7, -5, 8], [-2, 8, 4, 4], [5, -9, -5, 7], [0, 6, -2, 11], [-2, 1, 3, 16], [-4, -3, -9, -1], [4, -5, -1, 13], [-8, 1, 3, 4], [17, -3, -11, 5], [5, -2, 0, -2], [-14, 8, 2, -4], [11, -3, 3, -5], [-16, 1, -1, -4], [-14, 14, 4, -7], [1, -1, -5, 3], [-24, 10, 2, -4], [3, -16, 6, 8], [-1, 6, 4, -14], [6, 1, 3, -4], [9, -19, -5, 11], [-4, 12, -4, 1], [3, 1, 3, 7], [-16, 15, 1, -2], [-6, -2, 4, 13], [19, -8, -4, 0], [-18, 12, 14, -2], [-4, 12, 4, -8], [12, -11, -9, -6], [4, 2, -6, -2], [3, 11, 1, -15], [-5, -2, 2, 2], [10, -9, -19, 2], [-14, 4, 10, 0], [-22, 2, 8, -1], [-10, 3, -7, -16], [-17, 2, 4, -6], [-21, 5, -7, -11], [12, 0, 0, 8], [6, 6, 12, 5], [-10, 17, -9, -12], [-2, -12, -10, 9], [12, 6, -14, 4], [3, -4, 6, 16], [-1, 0, 6, 4], [21, -5, 3, 11], [18, 6, -4, -5], [-1, 1, 1, 17], [-1, -8, -10, 8], [-12, -3, -1, -12], [-12, 15, 7, -13], [-4, 4, 12, -12], [13, 1, 3, 7], [16, -2, 6, 10], [-8, 5, -1, -8], [-9, 0, -2, -16], [11, -11, -3, -11], [-16, -1, 1, 14], [19, -8, -6, -12], [9, -11, -5, -13], [28, -6, 2, -2], [-6, 18, 4, -7], [6, 4, -2, 14], [18, -12, -6, -6], [-20, 7, 9, -4], [14, -4, -8, 12], [-2, -14, 0, -3], [3, 9, 3, -1], [16, 0, -4, 14], [-20, 18, 4, -12], [10, -16, 4, 12], [16, 0, -4, 8], [-24, 5, 3, -13], [0, -16, -8, 14], [15, -8, -18, 8], [12, -6, -6, 14], [-12, -16, 2, 12], [9, -2, -2, -2], [-20, 8, 0, -4], [8, -4, 0, -20], [18, -18, -16, 9], [8, -19, -9, 15], [4, -15, 1, 9], [-15, 31, -1, -17], [12, 4, 12, -3], [16, -2, 6, 18], [-9, 12, 8, -4], [7, -5, -9, 3], [4, -27, 3, 13], [0, -9, -5, 19], [12, -8, 4, -10], [-8, -4, 0, 12], [-12, 4, 12, 5], [19, -5, 5, -3], [-14, -4, 12, -12], [2, 26, 0, -21], [19, -14, -20, -2], [-16, 0, -4, 0], [2, 4, -14, -4], [-3, -3, 1, -19], [17, -22, -8, 2], [16, -7, 1, 15], [4, -2, 2, 6], [-10, 8, -10, 3], [22, 12, 2, -6], [-3, -1, -7, 5], [-38, 8, 4, -8], [38, -23, -9, 0], [17, 1, -5, 19], [10, -14, 0, -1], [-3, -10, 2, 22], [36, -21, -11, 0], [5, -20, -6, 4], [8, -5, -17, -9], [5, 7, 13, -3], [-4, 15, 5, 4], [19, 3, -1, 3], [-8, 4, 8, -12], [24, -23, -21, 9], [16, -1, -5, 1], [7, 0, 2, -24], [-14, 28, 6, -18], [24, -3, -21, 8], [-40, 18, 6, -7], [21, 0, -8, -4], [12, -34, -6, 24], [15, -24, 10, 20], [34, -8, -6, -11], [-9, 1, 3, 11], [-34, 22, 0, -9], [21, -18, -4, 26], [24, 4, 12, 1], [37, -12, 6, 12], [4, -9, 3, 37], [-12, -4, -4, 13], [35, -15, -3, 9], [9, 2, 12, -14], [-30, 26, 20, -11], [7, -5, -5, -13], [12, -16, 8, 18], [3, -10, -14, -14], [-11, 12, 16, -4], [-14, 21, 23, -22], [6, 0, 10, 17], [-34, -4, -2, 2], [-24, 10, 2, -23], [12, 2, 2, -37], [-12, -12, -12, 12], [-16, 0, 0, -4], [12, -6, 18, 10], [16, 6, -6, -9], [20, -6, 4, 4], [-29, 7, -5, -5], [24, -24, 4, 12], [17, 4, -20, -4], [-12, -13, 19, -3], [-9, 6, 6, -22], [4, -10, -18, 12], [-4, 7, -9, -15], [-8, -25, 9, 15], [-17, -18, 0, 6], [-18, 13, 11, -16], [23, 9, 1, 13], [-21, 19, 15, -1], [-11, 6, -14, -10], [-20, 11, 13, -7], [-5, -13, -17, 19], [-27, -2, -6, -18], [-6, -7, -1, -24], [-10, 8, 12, 8], [-24, 17, 17, -21], [-45, 5, 3, 19], [-12, 5, 11, 21], [-9, 13, 5, -31], [7, 2, -2, 10], [-24, 4, 4, 13], [-16, 0, 2, -8], [7, -1, 11, -21], [-24, 5, 19, -8], [30, -20, -22, 11], [16, 0, -12, 6], [7, 9, -9, -1], [5, 15, 1, -3], [-12, 12, 24, 0], [7, -21, -1, 31], [4, -9, 9, 30], [8, 30, 2, -13], [25, -14, -30, 2], [-46, 17, 11, -10], [-40, 39, 7, -1], [12, 2, -6, 15], [42, -42, -8, 7], [34, -8, -10, 16], [-2, 28, 2, -30], [-42, 4, 10, 8], [4, -14, -30, -4], [8, -10, -8, -12], [8, 13, 11, 3], [-10, 21, 7, 6], [-16, -2, -4, -4], [-5, -28, -4, 16], [-20, 27, 5, -23], [46, -25, -11, 8], [36, -29, 1, 16], [-18, -8, -8, 20], [-17, 9, 17, -23], [-8, 32, -12, -3], [8, 10, 10, 15], [28, -1, 11, 11], [20, 6, -10, -18], [-35, 1, -3, 13], [-12, -33, -17, 33], [-25, 12, 14, -16], [-27, -17, 13, 9], [-48, 0, -12, -12], [0, -4, -16, -12], [-32, 4, 0, -12], [-1, -10, -2, -2], [28, -9, -19, 23], [0, -17, -19, 5], [35, -13, 9, 13], [12, -16, -22, 16], [-13, 2, 6, -6], [-4, 17, 17, -17], [-28, 17, 5, -7], [-22, 16, 0, 16], [6, 23, 17, -16], [-16, -9, 5, -1], [-16, 23, 9, -41], [9, 23, 11, -41], [35, -18, -18, 14], [-17, 23, -11, -23], [12, 10, 14, 10], [14, 18, -4, -1], [63, -39, -23, -7], [-30, 18, 8, 5], [-31, -1, -13, -13], [-4, 13, -11, -9], [27, 0, -8, -20], [-24, -13, 3, 23], [36, -24, 8, 26], [-10, -7, -5, 4], [16, -4, 4, 36], [20, -6, -22, -7], [-64, -5, -7, -1], [8, 2, -10, -30], [31, 20, -12, 0], [-31, 5, 19, -33], [-29, 0, -8, -16], [0, 20, 4, -40], [-21, 19, -9, -5], [0, 5, -17, -14], [-11, -7, 13, -15], [10, 4, -20, 20], [20, 5, 5, 25], [-26, 24, 32, -16], [35, -13, -1, 15], [16, -24, 8, 28], [29, -25, 3, 19], [-12, 7, 5, -11], [42, -22, -12, -5], [28, 22, -8, 8], [16, -22, -14, -4], [-17, -27, 7, 11], [-8, 25, 15, -27], [-42, 28, 12, -4], [-50, 23, 21, -10], [25, -10, -4, 22], [-35, -9, 15, 7], [-52, 22, 14, -1], [11, 8, 2, -24], [-20, 12, 20, -19], [-3, 1, 3, 7], [-55, -3, -7, 9], [-22, 24, 14, -8], [25, -15, -15, -7], [-4, -32, -4, 37], [40, 1, 1, 7], [-14, -20, 14, 24], [10, -23, -9, -20], [17, -4, -22, 28], [-30, -11, 3, -22], [0, -5, 9, 10], [0, 11, 9, 1], [6, 16, 0, -32], [-37, 1, 1, 13], [-60, 6, 14, -10], [19, 22, -2, 2], [-25, 11, 1, 33], [-17, 23, -3, 17], [-36, 13, 7, 15], [7, 10, -6, -2], [14, -37, -15, 34], [-20, 23, 11, -27], [72, -15, -9, -9], [5, 4, 10, -4], [46, 12, -22, 10], [0, -21, -23, 4], [17, 32, 14, -36], [-26, 23, 17, -26], [54, -12, -2, 25], [-4, 19, -17, -1], [50, -24, -10, 14], [32, -42, -18, 10], [23, -20, 16, 44], [-30, 6, 0, -7], [34, -4, -4, -28], [41, 1, 3, -17], [-16, -7, 7, -12], [40, -16, -10, 0], [-18, 22, -8, -19], [-1, 0, -2, 24], [-25, 46, 8, -10], [39, -31, 13, 17], [8, -18, -6, -21], [-23, 37, 31, -17], [24, -26, 12, 40], [36, -2, -6, 9], [33, 0, -16, -20], [20, -22, -30, -4], [-7, 13, -7, -15], [12, -17, 9, 7], [-46, 43, -7, -18], [60, -47, -13, -7], [-28, 5, 21, -11], [-41, -9, -11, -11], [19, -10, -16, 42], [-43, 19, 25, -11], [0, 25, -9, 11], [64, -40, -8, 10], [51, -26, -24, 22], [-24, 12, 44, -7], [23, -36, 16, 24], [-4, 32, -20, -4], [-57, 12, 14, -8], [-26, -18, 16, -21], [-17, -1, 27, 7], [-32, -28, -12, 35], [29, -29, -19, 21], [7, 18, -12, -22], [20, 4, 4, -20], [26, -39, 15, 18], [-52, 16, 18, -20], [19, 5, -9, -29], [-8, -35, -5, 30], [-13, -1, 21, 13], [-59, 32, 16, -4], [22, 15, 9, -34], [38, -29, -7, -16], [28, 5, 3, 16], [-29, 20, -4, 16], [44, -6, -16, -4], [-24, -26, 2, 26], [-22, -2, -4, 1], [24, -23, -25, 40], [19, -7, -9, -41], [10, 12, 8, 12], [-5, 14, -12, 14], [-49, -4, 12, 4], [-2, -11, -17, 38], [-40, 30, -4, -8], [-12, 25, -17, -31], [36, -30, -22, 10], [22, -24, -18, 43], [10, -4, 4, -16], [-36, 49, 3, -17], [2, 28, -6, -2], [32, 14, 10, -20], [-32, -14, 6, 17], [36, -39, -31, 33], [53, -9, -1, -9], [-34, -4, 22, -2], [28, -1, 13, -25], [74, -34, -8, 9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3675_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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