
// Make newform 3675.2.a.bc in Magma, downloaded from the LMFDB on 16 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_bc();".
// 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_bc();".
// 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, -1, 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_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 := [[0, 1], [1, 0], [0, 0], [0, 0], [1, -2], [0, -4], [-4, 4], [-4, 4], [1, 2], [-3, 0], [-4, 0], [3, -4], [4, -8], [-5, 6], [-4, -4], [-6, 0], [0, -4], [-12, 0], [-3, -6], [5, 2], [8, 4], [7, -6], [-4, -8], [-8, 4], [4, 0], [-16, 4], [12, -12], [-4, 8], [-3, 12], [17, -4], [-3, -10], [-20, 4], [-6, 16], [-8, 12], [-13, 16], [-3, 6], [-12, 8], [-12, 0], [16, 4], [4, -4], [12, -8], [0, -4], [16, -8], [-3, 16], [21, 0], [-4, 16], [-12, 16], [-16, 12], [-12, 12], [-16, -8], [11, -4], [-8, -8], [-12, -4], [4, 4], [-4, 8], [-5, -10], [-4, 8], [-16, 12], [10, -16], [13, -20], [0, 0], [-16, 20], [12, 12], [12, -20], [-12, 12], [5, -8], [-17, -10], [2, 0], [15, -6], [-4, -12], [12, -16], [-15, 2], [4, 0], [-11, -4], [-1, 6], [0, 12], [25, -8], [16, -16], [9, 12], [12, -12], [-4, -16], [-9, 12], [-24, 8], [0, 8], [-8, -12], [28, -8], [-13, 4], [13, 8], [-24, -4], [-24, 16], [24, -16], [24, 4], [-5, -6], [21, -10], [-12, 0], [0, 8], [-16, 4], [8, 8], [-24, 16], [-9, -12], [-31, 10], [5, -16], [-8, 8], [9, -28], [15, -2], [-20, 12], [8, 4], [-32, -8], [3, 6], [-24, -8], [16, 12], [23, -36], [15, 12], [24, -4], [23, -14], [-7, 20], [-24, 0], [24, -16], [14, -16], [-28, 8], [12, -20], [-30, 0], [24, 16], [11, 10], [28, -24], [-14, 32], [26, 0], [-12, 8], [28, -28], [-32, 0], [-11, -6], [16, -8], [32, -32], [-1, 4], [40, 8], [-20, 0], [-12, 32], [40, -4], [-28, -4], [15, -4], [0, -24], [6, -32], [-31, 30], [11, 2], [-4, 4], [-16, 44], [32, -24], [-12, -16], [0, 16], [27, -18], [-18, 0], [-28, -8], [5, -30], [12, -24], [20, 16], [-1, -34], [-1, 10], [24, -12], [-28, 0], [-20, 32], [-20, -8], [21, -20], [-8, 32], [4, -28], [27, -12], [-36, 8], [-9, -30], [12, -12], [-5, 8], [-36, -12], [7, 26], [-36, 28], [27, 6], [26, 0], [0, 12], [-36, 12], [11, -2], [-6, 0], [-16, -20], [-12, 24], [27, -38], [24, -24], [3, -12], [0, 8], [33, -6], [16, -40], [21, -36], [-24, 0], [-47, 24], [24, 20], [32, -32], [-23, 38], [-23, 18], [0, 0], [43, 10], [52, -16], [45, 0], [39, -12], [36, -36], [-20, 40], [14, 16], [24, -8], [-20, 24], [20, -24], [28, -56], [-20, 16], [-16, -24], [-4, -8], [39, -28], [44, -24], [27, -8], [-20, 4], [-13, -6], [-24, 24], [8, -28], [4, -12], [-41, 18], [-20, -20], [-27, 50], [-5, 8], [25, -4], [28, -28], [19, 20], [29, -2], [16, 20], [-6, -16], [24, 28], [7, 22], [-60, 12], [33, -42], [-29, -12], [20, -56], [-8, 32], [-37, -4], [16, 20], [20, 8], [12, 0], [-59, -8], [5, -10], [56, -8], [53, -10], [-40, 4], [28, -24], [-17, -4], [48, -12], [4, 4], [48, -8], [-16, 32], [-44, -16], [-48, 8], [18, 16], [-36, 40], [8, 8], [-12, -36], [20, -20], [12, -24], [21, -20], [12, -36], [-36, 28], [-44, 36], [0, -32], [-9, -30], [-60, 24], [-20, 48], [-56, 4], [-32, 0], [-13, 40], [0, 44], [15, 30], [-1, -16], [-32, 48], [-28, 0], [24, 0], [-37, -14], [12, 4], [36, 4], [-33, 18], [-2, 0], [27, -24], [-44, 44], [-24, -12], [0, 0], [-40, 4], [-12, -36], [24, -44], [-15, 26], [-31, 24], [-15, 40], [-16, 48], [0, -8], [-33, 8], [28, -32], [-49, -4], [32, -4], [-19, 4], [-36, -4], [-60, 0], [0, 20], [-36, 8], [0, -32], [-16, 12], [-34, 32], [15, 26], [-33, -6], [55, -34], [18, -32], [53, -34], [-24, 36], [39, -10], [42, -16], [24, -12], [26, 32], [-43, -20], [-44, 48], [-27, 50], [-28, 60], [0, -24], [48, -40], [-28, 24], [29, 20], [28, -36], [-70, 16], [-36, 36], [25, -18], [25, -44], [28, 0], [39, -26], [40, 24], [17, -46], [-5, -32], [-50, 0], [15, 32], [72, -8], [36, -4], [12, 32], [44, -4], [-51, 52], [16, 4], [16, -36], [-40, 12], [-6, 48], [23, -20], [76, -32], [15, -6], [-81, 0], [41, -10], [-56, 12], [67, 6], [12, 12], [24, -60], [8, -44], [25, 8], [-2, -32], [20, -12], [-45, -12], [4, -44], [-20, 64], [-8, 44], [-50, -16], [-48, 8], [-43, 28], [44, -64], [56, -56], [-3, 14], [-12, 60], [26, -48], [-32, -8], [-69, 2], [-13, 24], [-51, 78], [60, 8], [37, -62], [22, -32], [12, -16], [29, -12], [24, 24], [-55, 50], [60, 12], [60, -12], [24, 4], [-40, 44], [-47, 28], [-7, -26], [69, -12], [48, 4], [-40, -8], [-39, 14], [-4, 24], [15, -2], [-44, -16], [-35, 24], [-84, 0], [-51, -18], [16, -40], [-15, -30], [-1, 0], [56, -72], [16, 28], [-4, 0], [21, -24], [8, 4], [-75, -4], [-95, 6], [48, -52], [-12, -12], [8, -12], [69, -12], [-46, -16], [-68, 0], [68, -16], [40, -4], [-37, -40], [-12, -24], [-69, -18], [7, -24], [12, -12], [-32, 8], [64, -12], [-96, 16], [52, -56], [-30, 16], [72, -36], [16, -8], [-24, 48], [60, 0], [24, 12], [-41, 82], [6, 16], [68, -12], [-24, 0]];
    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_bc();".
// 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_bc(:prec:=2)
    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_bc();".
// 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_bc( : 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, -1, 1]>,<11,R![-5, 0, 1]>,<13,R![-16, 4, 1]>],Snew);
    return Vf;
end function;