
// Make newform 3675.2.a.cb in Magma, downloaded from the LMFDB on 24 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_cb();".
// 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_cb();".
// 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 := [3, 4, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, -1, 1, 0], [2, -3, -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, 0, 1], [-2, 1, -2, 0], [1, -1, 2, 0], [3, 1, 1, 0], [5, -1, 2, 2], [-1, -2, 1, -2], [1, 0, -2, 0], [6, -1, 0, -1], [-1, -1, -2, 1], [2, -1, -2, 1], [2, -1, -1, -1], [6, 0, 2, 0], [-1, 0, -1, 0], [0, 3, 1, -2], [0, 3, -2, 2], [-3, -2, -3, 2], [-4, 3, 2, -1], [-1, 3, 1, 4], [1, 3, 0, 2], [-7, 5, -4, -1], [0, 0, 0, -1], [-3, -4, 3, 0], [-6, 7, 2, 1], [3, 2, -1, 1], [-5, 5, -3, 2], [4, 2, 0, -2], [10, 1, -2, 0], [-6, -1, 1, -5], [3, -4, -3, -3], [9, -1, -3, 2], [-6, 5, -3, -1], [-2, -3, -1, -4], [-8, 0, -2, -2], [-6, 4, -4, -2], [3, 2, -3, -3], [-6, -1, -3, 3], [4, 0, 6, 0], [7, -1, 1, 4], [4, 4, -2, -2], [0, 9, 0, 1], [3, 10, -5, 5], [2, 7, 1, 4], [10, 3, 3, 2], [14, 0, 6, 2], [-13, 0, -5, 3], [-1, 0, 0, -2], [0, -1, -3, -5], [4, 3, -1, 1], [2, 1, -1, -6], [1, -5, 6, -5], [7, -2, 1, 3], [12, -7, 1, -3], [-16, -1, 3, -3], [18, -9, 7, 4], [6, 5, 4, -7], [-4, 3, 1, -5], [0, -1, 2, -5], [6, -7, -1, -9], [18, -11, 0, 2], [-11, 6, 5, 4], [-4, 1, 2, -7], [1, 9, -4, -2], [-9, 4, 8, 0], [6, -7, 4, -6], [-2, -6, 4, -2], [-6, -10, 4, -8], [13, -2, -1, -1], [-9, 14, 1, 2], [16, -5, 8, 4], [20, 1, 6, 8], [-11, 8, -8, 2], [-6, -12, 6, -4], [-23, 6, -3, 2], [6, 1, 4, 5], [8, 6, -6, 2], [-9, 8, -2, -4], [10, -10, 2, -2], [-5, 7, 3, 4], [-12, 11, -5, -7], [0, -3, -6, -2], [4, -3, -5, -2], [-4, 7, 7, 1], [4, 2, 8, 6], [18, -5, 14, 4], [3, 1, 2, 9], [8, -3, 2, 2], [-26, 2, -2, -2], [6, -3, 5, 3], [-8, 7, 4, 10], [6, 1, 9, 5], [-9, 2, -6, -10], [0, 10, 0, 0], [6, -2, 14, 0], [-18, -6, 0, -4], [-12, 5, -6, 10], [9, -4, 14, 0], [-10, -12, 2, -2], [16, -1, -7, 3], [4, -2, -4, 4], [17, -1, 12, -1], [-3, 1, -7, 6], [4, 5, -8, -4], [1, -4, -1, -5], [-13, 10, -7, 3], [-6, -5, -5, -13], [-9, 9, -7, 4], [-6, -9, 4, 0], [20, -6, 2, 3], [-16, 0, -6, -6], [13, 6, 0, 2], [-28, 0, -6, -8], [-1, -13, 4, -5], [2, -9, 2, 4], [-1, 10, -3, -5], [3, -3, -8, -4], [20, 4, 4, 2], [-11, 9, -9, -2], [14, -3, 10, 8], [-15, 7, 2, 4], [1, 2, -3, -13], [-15, 8, -4, 10], [9, -7, -4, -5], [8, 3, 7, -6], [-6, -5, 1, -9], [20, -13, -2, -3], [4, -21, 2, -6], [11, -7, 1, 10], [-9, -4, -5, 1], [5, 0, -6, 2], [14, -10, 14, -2], [-3, 12, -3, 2], [13, -3, -9, 4], [-17, 5, -4, -14], [-8, 6, -12, 2], [-5, -2, 11, 5], [-22, 9, 3, 11], [16, -15, 1, 2], [13, -15, -2, -3], [4, -6, 4, -3], [6, -7, 9, -9], [11, -19, 9, -4], [-9, 20, -5, 6], [16, 3, -6, 1], [23, -14, -9, -1], [4, 9, -13, 2], [-18, 5, -7, 15], [18, -10, -2, 2], [-6, -11, -7, -1], [-6, 17, 2, 3], [13, -6, 7, -1], [-12, 15, 0, 1], [7, -19, 10, -5], [-9, 8, 2, 14], [-17, -5, 2, -7], [-20, -19, 8, -7], [3, -4, -1, 12], [-37, 10, 5, -1], [-24, 4, -12, -6], [-20, 11, -16, 5], [-34, 9, 5, 3], [21, 3, 8, 6], [-3, 6, -15, 9], [21, -13, -9, -4], [28, -1, 10, 17], [-29, 4, -10, 0], [9, 12, -1, 3], [-6, 4, -10, 6], [-14, 13, 1, 10], [-23, 5, 12, 5], [22, 7, 6, 0], [23, -20, 0, 6], [-34, 15, -1, -1], [9, -2, -8, 4], [-16, -6, -12, -10], [0, -8, 0, -10], [-3, 4, 20, -2], [-20, 1, -16, 11], [-19, 8, 1, 2], [-8, -1, -6, -16], [-6, 22, 0, -6], [4, 12, -18, 6], [-6, -12, 18, -6], [36, -10, 0, -2], [-12, -3, -8, 1], [23, -11, 3, 10], [19, -9, 6, 5], [-28, -13, 2, 0], [15, -19, 4, -2], [12, -20, -4, -2], [-20, 0, 0, -4], [-5, 1, 14, -2], [29, 3, 14, 2], [-17, -10, 0, -8], [24, 2, 14, 7], [-10, -5, -9, 11], [9, 11, 10, 0], [32, -13, 3, -1], [7, -2, 10, 8], [38, -6, 4, -2], [-12, 5, -11, 16], [-17, -6, -13, 8], [-18, 28, 4, -6], [24, -22, 4, -2], [8, 9, -1, 5], [8, -1, -3, -9], [-28, 5, -9, -6], [12, 11, -4, 4], [27, 2, 9, -14], [16, 2, 12, -18], [-18, 7, -15, 3], [-35, 7, -26, 3], [7, -21, 3, -12], [-22, 18, -18, -4], [8, 4, 4, -14], [0, -15, 1, 1], [18, 16, 0, 4], [-15, 13, -3, -14], [15, 11, -3, -2], [-37, 0, -11, -18], [10, -20, 16, -8], [-2, 21, -7, 7], [-4, -11, 13, -8], [8, 2, 18, 12], [16, -9, 3, 5], [-26, 3, -22, 1], [-15, -23, 2, -9], [0, 21, -20, 9], [8, -4, 2, -16], [21, -7, 9, -16], [9, 8, 15, 0], [18, -15, 6, -1], [7, -26, 1, 5], [21, 12, -10, 10], [27, -1, 10, -12], [12, 1, -13, -3], [-7, 2, -15, 16], [7, -2, 17, 7], [31, -9, 25, 8], [-6, -19, 16, 0], [22, 1, -5, 8], [-28, 1, 1, -1], [-42, 19, -5, -3], [40, 7, -4, -3], [-29, -2, -9, -20], [-20, 1, -7, 18], [24, -5, -1, 5], [12, 1, -4, -4], [14, -21, 7, 5], [-28, -6, -8, -14], [-11, -5, -7, 14], [-14, -16, 2, -14], [-11, -14, 11, -10], [9, -5, 13, 2], [-22, -11, -2, -14], [-53, 11, -18, -14], [14, -4, -16, 8], [-18, -11, 6, -3], [10, -2, -16, 0], [11, 16, 0, -12], [6, -21, 12, 4], [-18, -18, -6, -24], [19, -18, 4, 2], [19, 10, 11, -2], [-8, 23, 3, -11], [-8, -16, -6, -17], [37, -14, 3, -1], [-9, -21, -9, -12], [-52, 2, -4, -5], [2, 17, 0, 21], [17, 20, -2, 12], [14, -22, -8, 2], [24, -4, -2, 14], [-27, 1, -10, 0], [23, -16, -10, -12], [35, -1, 3, 12], [-16, 9, -17, 5], [-12, -6, -10, -4], [-19, -3, 7, -18], [26, -21, 3, 5], [-5, -19, -5, -16], [-8, -8, 18, -10], [23, -31, 12, 11], [-24, -7, -20, -7], [25, 15, 0, 2], [5, 15, -1, 4], [5, 22, -7, 0], [-30, 6, -16, -6], [-14, 11, 21, 1], [-19, 0, -7, 15], [-25, 19, -8, 1], [38, -7, -8, -3], [-26, 8, 0, 6], [21, 7, -9, 2], [31, -21, 0, 8], [5, 11, 4, 21], [30, 3, 14, 19], [18, 14, -10, -8], [22, -22, -14, -8], [20, 9, 1, 2], [-8, 14, -14, 2], [7, -6, 12, -6], [6, 13, -10, 14], [0, -6, -12, 6], [-19, 34, -6, -16], [32, -27, 3, -1], [2, 31, -12, 6], [7, -16, -11, -17], [-37, -5, 6, -13], [5, 16, 11, -10], [-20, 14, -4, -12], [-14, 0, -2, 4], [-11, -8, -14, -6], [13, -34, 5, -12], [33, 10, 11, 10], [-42, 9, 12, 2], [43, 5, 12, 13], [29, -16, 10, -2], [14, 15, -4, -13], [48, 9, -3, 7], [-14, -11, 2, 12], [16, -4, -2, -8], [-1, -9, 1, 10], [7, -17, -11, -10], [-2, 19, 8, 6], [-30, 33, -5, -3], [18, -17, -5, -13], [-5, -10, -14, 18], [11, -16, 15, -7], [7, -16, 26, -8], [-9, -25, 6, 2], [-15, -13, 5, 2], [44, 0, 22, -4], [12, -1, 3, 8], [29, -4, -13, 7], [17, -23, 1, 0], [4, 27, -4, -1], [2, -3, 14, -2], [5, -26, 5, -25], [56, -9, 21, 17], [5, -14, -18, 8], [21, 8, 17, 9], [38, 4, -4, -6], [-33, 13, -1, 20], [-68, -8, 0, -8], [19, -3, 8, 17], [44, -2, 16, 8], [-6, 27, -3, 16], [10, 8, 16, -18], [46, -2, 10, 4], [-30, -4, -12, -18], [-7, 11, -27, 6], [-26, 26, 14, 2], [-8, -23, 21, -19], [10, 1, -15, -1], [46, -4, 22, 18], [-51, 17, -14, -6], [-12, -4, -8, -11], [25, 8, 15, -18], [-46, -3, 13, 3], [-42, 12, 20, 0], [14, 3, 10, 4], [0, 14, 14, -7], [13, -25, 22, -14], [20, -11, 30, 1], [-12, -15, 9, -20], [-20, 3, -23, 1], [-35, 29, 9, 0], [13, 3, -16, 16], [57, -14, 13, 10], [3, -2, 0, -16], [50, -15, 0, 10], [27, -17, 16, -13], [-36, 1, 11, 11], [28, 14, 16, 2], [-33, 20, 19, 6], [-50, 9, -14, -25], [-2, -14, -28, 2], [-39, 17, 20, 0], [-10, -14, 10, 4], [-8, 11, -9, 5], [24, 15, -3, 8], [-6, 13, 7, 13], [7, -10, -18, 14], [16, -16, 8, -12], [4, -7, 2, -8], [-7, 9, -22, 8], [5, -14, -8, 4], [81, -8, 1, 5], [-11, 9, -24, 1], [-6, 11, 20, 7], [-7, 15, -20, 11], [-40, -6, -10, 9], [44, -12, 36, 10], [60, -5, -1, 9], [23, 7, 5, -2], [-46, -2, -18, 8], [14, 5, -19, -4], [11, -10, -1, -3], [-32, 30, 16, 19], [-3, -16, 5, -21], [15, -14, -21, -6], [-15, 20, -12, -10], [-8, 2, 20, 6], [64, -5, 5, 13], [22, 7, -8, 6], [8, -13, 21, 1], [-22, -8, 16, -10], [46, 8, 14, -20], [7, -10, 19, 9], [4, 18, -4, 8], [-20, -5, 4, -24], [37, -1, -4, -7], [-49, 2, -21, -12], [26, -11, 2, -16], [-34, 2, -8, 2], [2, -23, 7, 13], [-16, 17, 15, -7], [-46, 17, -2, -9], [-23, -11, -20, -2], [-10, -5, 5, -1], [-26, 8, 14, -8], [37, 17, 10, 10], [-20, -24, 2, -26], [12, 3, -31, 3], [-24, -6, 14, 0], [-49, -1, -12, 17]];
    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_cb();".
// 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_cb(: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_cb();".
// 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_cb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3675_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, 6, -4, -2, 1]>,<11,R![30, -14, -18, 0, 1]>,<13,R![127, -36, -28, 2, 1]>],Snew);
    return Vf;
end function;