
// Make newform 3630.2.a.bl in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3630_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_3630_2_a_bl();".
// 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_3630_2_a_bl();".
// 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_3630_a();"
function MakeCharacter_3630_a()
    N := 3630;
    order := 1;
    char_gens := [1211, 727, 3511];
    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_3630_a_Hecke(Kf)
    return MakeCharacter_3630_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], [-1, 0], [1, 0], [-2, -1], [0, 0], [-3, 3], [4, -4], [-3, 3], [-8, 1], [6, -2], [-6, 2], [-5, -3], [2, 5], [0, -2], [5, -11], [-10, 5], [-5, 7], [0, 6], [-12, 6], [2, -10], [2, 0], [-6, -4], [-4, 4], [6, -9], [-2, 0], [0, -12], [-3, 3], [4, 4], [0, -12], [-6, -4], [5, -9], [0, 0], [-12, 12], [-14, 11], [0, 4], [-14, -4], [-4, -3], [4, 12], [-15, 13], [-14, 1], [8, -5], [0, 0], [0, 10], [2, 6], [14, -1], [0, -4], [12, -4], [-14, -9], [12, -6], [10, 8], [-2, 2], [6, -10], [0, -9], [-8, -7], [-22, -4], [1, 1], [-8, 22], [-10, -6], [0, 19], [22, -8], [-6, 18], [-14, -5], [12, -24], [2, -16], [-4, 6], [-19, 5], [15, -3], [4, 12], [0, -6], [-6, 12], [2, -2], [26, 2], [16, 12], [29, -9], [6, 17], [4, -19], [6, 0], [-24, 19], [7, -5], [17, -9], [3, 11], [-30, 16], [-26, 14], [16, -18], [24, 6], [6, -4], [35, -5], [20, -24], [-12, 6], [5, 15], [-12, -4], [-4, -2], [-16, 12], [-15, -7], [18, 9], [-1, -25], [14, -20], [-6, 11], [-16, 22], [-8, 12], [24, -6], [31, -17], [-20, -4], [2, 7], [6, -21], [-14, 6], [-8, -8], [-14, 16], [-6, -10], [-11, 11], [-16, 12], [22, 12], [-24, 0], [21, -9], [12, -2], [25, -35], [40, 0], [-24, -16], [3, 27], [-20, 7], [12, -14], [22, 2], [2, 20], [22, -34], [18, 11], [6, 26], [14, -2], [30, -4], [6, 27], [-18, -12], [-6, -3], [-12, 1], [16, 12], [31, -31], [26, -16], [39, 5], [14, 5], [10, 6], [25, 5], [5, -19], [18, -29], [24, -34], [-9, -3], [12, 14], [-26, 8], [-20, 38], [-32, -1], [24, -22], [-2, 17], [-15, 33], [13, 3], [-2, -17], [8, -12], [-16, -1], [36, -36], [-20, 34], [0, -14], [-18, -9], [0, 24], [-16, 32], [-22, 8], [16, -34], [-45, 21], [-4, -13], [6, 8], [12, -15], [-12, 0], [-22, 0], [-29, 33], [34, -20], [-19, 13], [-42, 4], [-6, -26], [-24, 30], [-22, -12], [3, 19], [15, 25], [-12, 0], [-14, 23], [28, -36], [4, 8], [-35, 25], [-6, 32], [4, 16], [-27, 9], [-30, 8], [-10, -24], [-40, 16], [6, 12], [2, -14], [-8, -28], [-40, 20], [-51, 15], [-42, 18], [-36, -12], [18, -18], [9, -9], [18, -20], [-36, 6], [28, -43], [-22, 4], [-24, 16], [-27, 15], [-14, 12], [8, -8], [-37, -5], [12, -36], [-28, 26], [18, -45], [12, -28], [20, -44], [18, 2], [10, -13], [-6, 24], [-34, 2], [31, -51], [-4, 24], [19, -5], [4, 16], [-26, 32], [42, 2], [42, -18], [-62, 1], [6, -13], [-50, 2], [64, 0], [-14, 46], [4, 10], [-35, 27], [-16, -13], [45, -41], [-38, 41], [8, 24], [-22, 35], [0, 22], [28, -20], [-31, -21], [-7, -43], [4, -16], [-48, 24], [-20, 2], [14, 27], [-34, -9], [-8, -22], [-16, 32], [-50, 26], [-13, 1], [16, -40], [24, -48], [-12, 51], [-44, 3], [45, -35], [27, 7], [4, 27], [-47, 29], [41, -55], [-60, 10], [6, -10], [21, -19], [0, 42], [16, 0], [-4, 38], [2, 6], [-52, 7], [-34, 4], [-9, 17], [-12, -22], [57, -27], [34, -12], [-37, 55], [-54, -2], [-66, 12], [-30, 50], [-48, -14], [48, -54], [13, -1], [-12, -24], [-36, 18], [-11, -37], [-28, -4], [36, -9], [-18, 24], [63, -21], [16, 14], [0, 4], [-38, 40], [-6, 18], [-21, 27], [-46, 0], [42, -7], [22, -2], [-36, -14], [-12, -46], [44, -37], [-72, 3], [-48, -8], [-46, 18], [10, -29], [63, -21], [20, 4], [-40, 10], [10, 31], [58, 2], [28, -4], [35, -11], [0, -22], [-54, -18], [-22, -20], [56, -16], [-64, 9], [-28, 44], [42, -4], [50, -40], [34, -16], [-13, -25], [-62, 24], [-4, 29], [-14, -46], [4, -24], [13, 5], [-30, 53], [62, -26], [8, -16], [-26, -7], [-28, 14], [-64, 3], [18, 39], [-20, 6], [-4, -7], [21, 25], [18, 16], [-49, 7], [0, 36], [-30, -8], [-3, -5], [30, -54], [-24, 66], [0, 0], [-3, -53], [32, 12], [32, 9], [16, 26], [6, -48], [-2, -40], [42, -39], [5, 5], [-28, 24], [-26, 48], [4, 46], [-21, 15], [-24, -40], [-66, 30], [52, 22], [-43, 7], [18, 36], [24, -14], [34, -46], [-68, 29], [-28, -26], [28, 16], [-63, -9], [-43, 17], [32, -4], [60, -27], [6, -18], [32, 10], [54, -3], [33, 19], [4, 27], [-60, -5], [-71, 27], [25, -11], [-18, -18], [-20, -40], [48, 3], [16, -16], [26, -8], [54, -24], [3, -9], [-30, 18], [86, 8], [-10, 34], [34, -27], [42, 6], [30, 3], [20, 7], [62, -12], [3, 45], [32, -8], [49, 17], [-24, 59], [-25, 7], [32, -71], [2, -26], [58, 10], [34, -34], [-36, 68], [-31, 29], [-12, 20], [34, 26], [-92, 14], [0, -34], [6, 1], [-12, -42], [-70, 40], [24, -30], [8, -57], [18, 39], [4, -40], [24, 33], [-20, 0], [-23, 13], [-22, -20], [-31, -9], [24, 18], [-12, -16], [52, -20], [8, 48], [76, -8], [16, -29], [-42, 18], [-82, 36], [56, -31], [33, 33], [-72, 24], [-2, -17], [42, 12], [-34, -23], [-27, -5], [-86, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3630_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3630_2_a_bl();".
// 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_3630_2_a_bl(:prec:=2)
    chi := MakeCharacter_3630_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_3630_2_a_bl();".
// 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_3630_2_a_bl( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3630_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![5, 5, 1]>,<13,R![-9, 3, 1]>],Snew);
    return Vf;
end function;