
// Make newform 630.4.k.i in Magma, downloaded from the LMFDB on 11 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_630_k();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_630_k_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_630_4_k_i();".
// 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_630_4_k_i();".
// 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_630_k();"
function MakeCharacter_630_k()
    N := 630;
    order := 3;
    char_gens := [281, 127, 451];
    v := [3, 3, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_630_k_Hecke();"
function MakeCharacter_630_k_Hecke( : Kf := false)
    N := 630;
    order := 3;
    char_gens := [281, 127, 451];
    char_values := [[1, 0], [1, 0], [0, -1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 4;
    raw_aps := [[0, 2], [0, 0], [0, -5], [21, -7], [-30, 30], [44, 0], [-24, 24], [0, -2], [0, -183], [279, 0], [40, -40], [0, 76], [423, 0], [305, 0], [0, 456], [-198, 198], [-462, 462], [0, -281], [499, -499], [534, 0], [-800, 800], [0, 790], [597, 0], [0, 1017], [-1330, 0], [1035, -1035], [0, -827], [0, 81], [-215, 215], [-390, 0], [2144, 0], [0, -2400], [972, -972], [158, 0], [0, 435], [-1316, 1316], [3814, -3814], [0, -2036], [303, 0], [0, 3816], [2256, -2256], [1895, 0], [0, 3930], [-1370, 1370], [1326, 0], [1132, -1132], [-4138, 0], [-484, 0], [-2676, 2676], [0, -1190], [0, -5052], [-1140, 0], [-2018, 2018], [-7260, 0], [0, -6696], [2583, -2583], [-5685, 5685], [0, -6626], [4192, -4192], [2502, 0], [-1604, 1604], [-7692, 0], [-6883, 0], [6966, -6966], [0, 6736], [0, -3156], [0, -10724], [2786, 0], [537, -537], [-11491, 0], [6042, -6042], [0, -5616], [10321, -10321], [0, 9196], [-1978, 0], [0, -4587], [-12822, 12822], [0, 634], [0, -4977], [-14627, 14627], [-14160, 0], [-979, 0], [-12978, 12978], [-8902, 0], [0, 6028], [0, 11901], [6513, 0], [0, 14296], [2694, 0], [-16105, 0], [0, -8343], [-10428, 10428], [13672, -13672], [2448, 0], [0, 13846], [5295, 0], [0, 6225], [14862, -14862], [0, -4412], [0, 19045], [8309, 0], [-15018, 15018], [-7677, 7677], [0, -2442], [-14570, 14570], [24622, -24622], [-9396, 0], [0, -1314], [924, -924], [11618, 0], [0, 8845], [-4304, 4304], [-540, 0], [-3350, 3350], [23006, 0], [-15195, 15195], [15740, 0], [10647, -10647], [0, -12264], [-8550, 0], [-15749, 15749], [18320, 0], [0, -6924], [17025, -17025], [0, -4010], [29151, 0], [0, -3269], [0, 30], [-15583, 0], [0, 22858], [-19802, 19802], [10029, 0], [0, -30404], [24428, 0], [0, 4890], [26306, 0], [-8724, 8724], [5443, -5443], [-22584, 0], [-12675, 12675], [-21544, 0], [0, -17802], [-28505, 28505], [11289, 0], [-10346, 10346], [-48138, 0], [-13390, 0], [38502, -38502], [0, -34040], [0, -42993], [0, -3962], [1503, 0], [17732, 0], [0, -24177], [-18335, 18335], [30102, 0], [0, -27614], [0, -10797], [-16732, 0], [-35166, 35166], [0, -1851], [35292, 0], [-21241, 0], [0, -7320], [-38718, 38718], [15795, -15795], [35116, -35116], [-46718, 46718]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_630_k_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_630_4_k_i();".
// 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_630_4_k_i(:prec:=2)
    chi := MakeCharacter_630_k();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_630_4_k_i();".
// 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_630_4_k_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_630_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![900, 30, 1]>,<13,R![-44, 1]>],Snew);
    return Vf;
end function;