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