
// Make newform 3630.2.a.bc 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_bc();".
// 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_bc();".
// 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], [3, -1], [0, 0], [0, -1], [-4, 4], [0, 1], [3, -3], [0, -6], [-8, 2], [0, 1], [-5, 7], [2, 2], [-2, 1], [-3, 5], [-14, 1], [10, -2], [-2, 10], [-4, -6], [6, -8], [-2, 4], [0, 8], [-7, -3], [10, -8], [4, 0], [-8, 3], [8, -16], [4, 0], [-10, 4], [12, -1], [16, -8], [8, -12], [-7, 1], [-4, 8], [-10, 4], [-5, 1], [8, -16], [-6, 9], [-19, 9], [-13, -3], [-12, 20], [-10, 6], [0, 6], [3, -1], [-8, 8], [-16, 12], [7, -1], [2, 10], [-14, -4], [-20, -6], [16, -10], [-25, 1], [1, -17], [-10, -8], [-10, -3], [-26, -2], [-8, -14], [1, 15], [-2, -16], [0, -6], [3, -13], [12, -24], [-18, 16], [2, -6], [14, 5], [12, 7], [-20, 0], [10, 10], [10, 0], [-16, 14], [24, -2], [-4, -20], [-12, 3], [-21, 19], [-13, 25], [6, 4], [17, 7], [-6, -7], [0, -23], [-18, -11], [22, -8], [-4, -10], [-22, 18], [14, -10], [14, -24], [-18, 1], [0, -16], [-26, -2], [-4, -1], [12, 8], [-18, 34], [28, -20], [2, 7], [-17, 27], [2, 11], [-18, 12], [33, -7], [6, 6], [-20, -8], [-18, 2], [18, 7], [28, -28], [13, -3], [-11, 17], [4, 18], [20, -24], [-10, -12], [-8, -6], [-32, 5], [-4, 20], [38, -12], [28, 8], [12, -19], [-2, -6], [22, -25], [4, 12], [-16, 24], [-14, 3], [19, -15], [18, -38], [-32, 22], [2, -20], [20, -18], [9, 17], [-4, 26], [-16, 14], [-14, 16], [-25, 35], [-26, 4], [27, -1], [-9, -3], [-8, 36], [0, -3], [2, 16], [-28, 11], [-3, -11], [-12, 10], [2, -19], [-14, -17], [17, -15], [14, 2], [36, 5], [-6, 6], [-6, 28], [22, -18], [21, -45], [54, -2], [43, -13], [-2, -3], [-24, -1], [1, -11], [8, -28], [13, 19], [20, -16], [-2, 14], [-2, 26], [1, 13], [36, -20], [16, 8], [14, 28], [-46, -2], [-16, -19], [-1, -11], [-10, 24], [-25, 13], [4, -8], [6, 32], [-20, 23], [-14, -4], [10, -13], [18, -12], [24, 6], [-34, 22], [22, -32], [-18, 33], [0, -5], [0, 28], [-25, 23], [40, 8], [28, -8], [30, -25], [14, -32], [4, 4], [10, -19], [34, -20], [-14, -32], [-28, 44], [18, 12], [16, 10], [-12, -8], [32, 8], [36, -35], [8, -26], [28, 4], [0, -2], [-24, -7], [-6, 36], [-30, 10], [19, 9], [34, -20], [60, -12], [-36, 3], [-10, 4], [-16, -8], [2, -45], [20, -52], [22, 10], [-31, 9], [-16, -4], [-32, 0], [12, -2], [43, -13], [42, -24], [-8, 46], [36, 3], [-20, 24], [22, -23], [-36, 48], [10, -40], [-8, 42], [-20, -30], [-1, -5], [7, -13], [44, -22], [-52, 0], [-44, -10], [-30, -6], [16, -37], [19, 21], [-68, -5], [-33, 3], [-4, -16], [-15, 25], [-58, -10], [40, -28], [-20, 13], [-62, 5], [4, 40], [16, -16], [-34, 58], [-43, -15], [-53, -9], [26, -42], [-64, 0], [20, -18], [-44, 9], [32, -40], [24, -8], [13, 15], [-27, 39], [18, -41], [14, 3], [-9, 45], [18, -19], [-22, 39], [-2, 18], [8, -22], [30, -3], [-2, 2], [-8, -16], [26, -6], [32, -46], [-39, 35], [-2, 0], [-48, 19], [10, 34], [-10, 15], [10, 4], [-10, 39], [-4, 38], [-66, -8], [16, -38], [22, 10], [26, -26], [-12, -17], [52, -8], [50, -18], [-8, 37], [-32, 20], [33, -45], [30, -28], [-26, 47], [-6, -2], [-8, 40], [2, 20], [-12, 34], [42, -53], [42, -16], [23, -29], [0, -50], [6, -14], [2, 10], [7, -3], [17, -9], [-16, 32], [-32, -6], [-5, 27], [10, -35], [-8, -32], [38, -18], [47, -9], [36, 2], [-16, 64], [32, 31], [42, -14], [56, 6], [18, -36], [76, -8], [-29, 21], [-8, 12], [34, -48], [2, 0], [6, -40], [-34, 3], [34, -32], [-31, 11], [-16, 38], [-16, 20], [66, -25], [43, -41], [28, -46], [4, -12], [-47, 57], [-26, 30], [43, -3], [-43, 5], [-22, -14], [31, 5], [-14, 41], [66, -20], [-30, 71], [32, 20], [-10, 0], [-16, -31], [-8, -6], [-54, 18], [60, -16], [48, -19], [-52, 20], [-5, 37], [-2, 10], [6, 12], [-18, 0], [53, 1], [34, -29], [-24, 12], [54, -16], [-50, 10], [46, -41], [-40, 32], [0, -34], [-26, -38], [4, 15], [-22, 56], [2, -42], [44, -30], [-7, -21], [-54, -2], [20, 24], [8, -45], [38, 11], [-36, 60], [17, -29], [24, -54], [58, 2], [21, -3], [-28, 51], [7, -35], [39, -11], [4, 17], [34, 25], [-88, 10], [-16, 8], [-47, -33], [8, 24], [-22, -28], [6, 48], [-62, 45], [-56, 30], [-54, 36], [44, 2], [-55, 21], [36, 18], [-27, 49], [49, -61], [-26, 72], [0, 17], [0, 4], [22, -75], [27, 5], [-6, 39], [-39, -9], [8, 50], [32, -18], [36, -22], [48, -16], [14, -1], [32, -36], [12, 42], [62, 18], [62, -30], [57, -63], [-6, -10], [-62, 32], [50, -62], [-67, 19], [-35, 5], [-48, 20], [-15, -33], [24, -52], [-78, 13], [30, -12], [-32, 13], [38, 22], [4, 48], [-4, -12], [-24, -8], [-32, 20], [-23, 15], [-52, -2], [22, -52], [-21, -11], [50, -9], [36, -40], [19, 55], [10, 28], [-53, 3], [-16, -15], [-16, 2]];
    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_bc();".
// 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_bc(: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_bc();".
// 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_bc( : 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;