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