
// Make newform 3630.2.a.bi in Magma, downloaded from the LMFDB on 14 September 2025.
// 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_bi();".
// 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_bi();".
// 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 := 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]];
    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], [1, -1], [0, 4], [-1, 1], [0, 3], [6, -6], [-6, -2], [1, -1], [-2, 7], [-4, 2], [-1, -1], [2, -5], [-13, -1], [-8, -2], [8, -10], [-10, 6], [2, -8], [-2, 4], [-8, 8], [-10, 3], [2, 8], [-4, 0], [-5, -3], [8, -16], [-4, 0], [-6, -4], [-11, -1], [-8, -8], [-4, 12], [6, 1], [-4, 8], [6, 4], [-4, -1], [-8, 16], [-3, 9], [10, 9], [-16, 3], [8, -20], [-4, -6], [-6, 6], [-2, -1], [0, -8], [4, 12], [6, 1], [-12, 10], [-18, 4], [26, -6], [-6, -10], [24, 1], [-16, 17], [-18, 8], [13, -3], [-28, 2], [22, -14], [-16, 15], [18, -16], [6, -6], [10, -13], [12, -24], [-2, -16], [-4, 6], [19, -5], [19, -7], [20, 0], [-20, 10], [-10, 0], [-2, -14], [-22, -2], [-24, 20], [9, 3], [-2, -19], [12, -25], [10, -4], [24, -7], [-13, 7], [23, -23], [-29, 11], [14, 8], [14, -10], [-4, -18], [-4, -10], [-10, 24], [-17, -1], [16, -16], [28, -2], [-5, 1], [20, -8], [-16, 34], [8, 20], [-9, 7], [10, -27], [-13, 11], [-6, -12], [26, 7], [-12, 6], [28, -8], [16, 2], [-25, 7], [0, -28], [-10, -3], [-6, 17], [22, -18], [-4, 24], [22, -12], [-14, 6], [27, 5], [-16, 20], [-26, -12], [36, -8], [-7, 19], [-8, 6], [-3, 25], [16, -12], [8, -24], [-11, -3], [-4, -15], [-20, 38], [10, 22], [18, -20], [2, 18], [26, -17], [-22, 26], [-2, -14], [2, -16], [10, -35], [22, 4], [-26, -1], [12, -3], [28, -36], [-3, 3], [-18, 16], [17, 11], [-14, 11], [2, 10], [-17, 19], [31, -17], [-2, -15], [-16, 2], [41, -5], [0, 6], [22, -28], [4, 18], [24, -45], [-52, -2], [30, 13], [-5, 3], [25, -1], [-10, 11], [-20, 28], [-32, 19], [4, 16], [12, -14], [-24, 26], [14, -13], [-16, -20], [-24, 8], [42, -28], [48, -2], [35, -19], [-12, 11], [14, -24], [-12, -13], [-4, 8], [-38, 32], [-3, 23], [-18, 4], [3, -13], [6, 12], [-30, 6], [12, 22], [-10, 32], [15, -33], [5, -5], [28, -28], [2, 23], [-48, 8], [20, 8], [-5, -25], [-18, 32], [-8, 4], [-9, 19], [14, 20], [46, -32], [16, -44], [-30, 12], [-26, 10], [-20, 8], [-40, 8], [1, 35], [-18, 26], [-32, 4], [-2, 2], [31, -7], [30, -36], [20, 10], [-28, 9], [-14, -20], [-48, -12], [-33, -3], [6, 4], [-24, 8], [-43, 45], [-32, 52], [-32, 10], [22, 9], [-20, 4], [32, 0], [10, 2], [30, 13], [18, 24], [-38, 46], [39, -3], [-4, 24], [1, -23], [12, -48], [-30, 40], [-34, 42], [50, -30], [-6, 5], [-6, 13], [-22, -22], [52, 0], [-54, 10], [-36, 6], [21, -37], [-40, 21], [-73, 5], [30, 3], [20, -16], [-10, 25], [-68, 10], [-12, -28], [-7, -13], [57, 5], [44, -40], [0, 16], [24, -58], [58, -15], [-62, 9], [-16, 42], [64, 0], [-2, -18], [-35, -9], [-8, 40], [-16, -8], [-28, 15], [-12, 39], [23, -41], [17, -3], [36, -45], [1, -19], [-17, 39], [16, -18], [14, -22], [27, 3], [0, 2], [24, -16], [-20, -6], [14, -46], [4, 35], [-2, 0], [-29, -19], [44, -34], [5, -15], [-14, 4], [-29, 39], [34, -38], [-74, 8], [-22, 38], [-32, 10], [0, -26], [-29, 17], [44, 8], [-32, -18], [-29, 37], [12, 20], [12, -45], [2, 28], [-21, 47], [8, -2], [-32, 40], [22, -20], [22, -34], [11, -53], [26, 16], [6, -29], [-50, 50], [-8, 14], [-12, 10], [-4, -3], [-8, -9], [-16, 32], [-38, 6], [22, -27], [25, -35], [40, -32], [-20, -18], [-38, -9], [-38, 2], [48, -64], [63, -31], [28, 14], [62, -6], [-18, 36], [68, 8], [8, 21], [-4, 12], [-14, 48], [-2, 0], [-34, 40], [31, 3], [-2, -32], [-20, -11], [-22, 38], [4, -20], [-41, -25], [-2, -41], [-18, 46], [8, -12], [10, -57], [-4, 30], [40, 3], [-38, -5], [-36, 14], [-36, 5], [-27, 41], [-46, -20], [41, -71], [-52, 20], [10, 0], [47, -31], [-14, 6], [-36, -18], [-44, -16], [29, 19], [32, 20], [32, -37], [8, -10], [-18, 12], [-18, 0], [54, -1], [-5, -29], [-12, -12], [38, 16], [40, 10], [5, 41], [8, 32], [-34, 34], [-64, 38], [-19, 15], [-34, 56], [40, -42], [14, 30], [28, -21], [56, -2], [44, -24], [37, -45], [-49, 11], [24, -60], [12, -29], [-30, 54], [60, -2], [-18, -3], [-23, 51], [28, -35], [28, 11], [21, -17], [-59, 25], [78, 10], [8, 8], [-80, 33], [32, -24], [50, -28], [-54, 48], [17, 45], [26, 30], [-18, -36], [46, -2], [34, 21], [-54, 18], [-22, 49], [-12, 61], [46, -72], [17, -17], [-4, 4], [-53, 75], [32, -5], [33, -39], [-48, 9], [58, -50], [14, 18], [-14, -22], [-32, -16], [13, 1], [-4, 36], [-54, 42], [-80, 18], [32, 30], [6, -63], [-16, 10], [30, 32], [12, -62], [-48, -19], [30, 5], [-28, -20], [-48, 33], [28, -52], [65, 13], [18, 12], [19, 13], [-60, 22], [52, -48], [16, -12], [-32, 8], [-12, -20], [8, 15], [-54, 2], [30, -52], [-32, 11], [-41, -9], [-4, 40], [74, -55], [38, -28], [50, 3], [-31, 15], [14, 2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3630_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3630_2_a_bi();".
// 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_bi(: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_bi();".
// 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_bi( : 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![-1, -1, 1]>],Snew);
    return Vf;
end function;