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