
// Make newform 22.4.c.a in Magma, downloaded from the LMFDB on 10 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_22_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_22_c_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_22_4_c_a();".
// 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_22_4_c_a();".
// 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, -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_22_c();"
function MakeCharacter_22_c()
    N := 22;
    order := 5;
    char_gens := [13];
    v := [4];
    // 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_22_c_Hecke();"
function MakeCharacter_22_c_Hecke( : Kf := false)
    N := 22;
    order := 5;
    char_gens := [13];
    char_values := [[0, 0, 1, 0]];
    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], [-3, 3, 0, 8], [1, 0, 0, -1], [0, 11, -3, 11], [11, 22, 0, -22], [29, 4, 29, 0], [77, -104, 104, -77], [9, -9, 0, 32], [-44, 0, 24, -24], [0, -159, 107, -159], [-143, 202, -143, 0], [0, -79, -97, -79], [129, -129, 0, -40], [256, 0, -68, 68], [21, -21, 0, 188], [-223, 424, -223, 0], [0, -301, 225, -301], [429, 24, -24, -429], [-80, 0, -116, 116], [-783, 342, -342, 783], [0, -51, 51, -51], [537, -934, 537, 0], [-63, 538, -538, 63], [-38, 0, -940, 940], [665, 24, 665, 0], [-1091, 416, -1091, 0], [0, -273, -1043, -273], [-1175, 1175, 0, 1036], [-14, 0, 1136, -1136], [277, -277, 0, -132], [-1867, 1222, -1222, 1867], [968, 0, 792, -792], [661, -1412, 1412, -661], [0, 363, -627, 363], [2013, -1304, 1304, -2013], [517, -517, 0, -2444], [-2919, 2919, 0, 1764], [-1055, 1778, -1055, 0], [-1731, 58, -1731, 0], [1789, -1789, 0, -228], [1581, -1581, 0, -2264], [-1583, -160, 160, 1583], [0, -2153, 2485, -2153], [-1479, -2344, 2344, 1479], [-1678, 0, -2764, 2764], [-4700, 0, -316, 316], [1033, -202, 1033, 0], [3109, -3109, 0, 176], [0, 647, 1317, 647], [-879, 4516, -879, 0], [-3419, 2832, -3419, 0], [29, -29, 0, -340], [2758, 0, 2480, -2480], [4669, -2162, 4669, 0], [0, 4209, -2733, 4209], [-2156, 0, -1780, 1780], [-2607, 3492, -3492, 2607], [0, -1309, -3231, -1309], [5721, -852, 5721, 0], [-5103, 1976, -1976, 5103], [2585, -2585, 0, -5956], [0, 2401, -621, 2401], [-6104, 0, 968, -968], [-2683, 2683, 0, -448], [4653, -4248, 4248, -4653], [-463, -6940, -463, 0], [5068, 0, -3208, 3208], [0, -4279, 1147, -4279], [-3319, 7218, -7218, 3319], [9537, -9537, 0, -5540], [3310, 0, -868, 868], [0, -3053, 2417, -3053], [0, 6547, -5339, 6547], [-1026, 0, 2172, -2172], [-3919, 1754, -1754, 3919], [345, 866, 345, 0], [0, -683, -865, -683], [-2030, 0, -3428, 3428], [4345, 1100, -1100, -4345], [4017, -3004, 4017, 0], [3280, 0, 5200, -5200], [-1763, 1763, 0, 8872], [3437, -11058, 3437, 0], [0, 1693, -2641, 1693], [-4364, 0, 3904, -3904], [9609, -9609, 0, -3500], [-2951, -8104, -2951, 0], [7757, -7756, 7756, -7757], [11386, 0, 3468, -3468], [-13300, 0, -2036, 2036], [3017, -402, 402, -3017], [-11655, -1202, 1202, 11655], [-167, 167, 0, 3572], [0, 7435, 8541, 7435], [0, -4225, 7805, -4225], [-12039, 12039, 0, 5472], [-1335, 1335, 0, 1576], [0, 11157, -3769, 11157], [9749, -10530, 10530, -9749], [-6487, 5228, -6487, 0], [-10119, 10119, 0, 13124], [0, -2747, -865, -2747], [-3243, 9742, -3243, 0], [-6955, 6955, 0, 17936], [1144, 0, 1984, -1984], [14861, -16500, 16500, -14861], [0, -1849, -16887, -1849], [16754, 0, 10796, -10796], [-3347, 10194, -10194, 3347], [0, -4379, 183, -4379], [4397, 11870, 4397, 0], [-8675, 8675, 0, 12768], [-10222, 0, -8148, 8148], [-14223, 14223, 0, -1180], [0, -10481, -9107, -10481], [-6511, 6511, 0, 18956], [-531, -9210, 9210, 531], [12029, -13182, 12029, 0], [0, -2067, 4523, -2067], [-15248, 0, -280, 280], [-3526, 0, -9808, 9808], [-7651, -3772, -7651, 0], [6953, -5216, 5216, -6953], [-7772, 0, -16408, 16408], [-13851, -5082, -13851, 0], [-15031, 15031, 0, -11528], [-27115, 31792, -31792, 27115], [0, 14407, -13567, 14407], [6240, 0, 14040, -14040], [0, 13853, -29509, 13853], [4561, 22310, 4561, 0], [18705, -17738, 17738, -18705], [5085, -5085, 0, -9440], [10961, -20464, 10961, 0], [16649, -5804, 16649, 0], [8706, 0, 2892, -2892], [2581, -2581, 0, 16328], [24909, -24354, 24354, -24909], [25397, -19060, 19060, -25397], [-13243, 22964, -22964, 13243], [6449, -6449, 0, 22940], [0, -8535, 26703, -8535], [9141, 2990, 9141, 0], [-26827, 23414, -26827, 0], [0, -1979, -297, -1979], [-719, 719, 0, -19272], [-31919, 36772, -36772, 31919], [-9098, 0, -7780, 7780], [14380, 0, 7200, -7200], [-13403, -7234, 7234, 13403], [3429, -3429, 0, 704], [-10218, 0, 7868, -7868], [34809, -34809, 0, -27352], [0, 1855, 9613, 1855], [1273, -12382, 12382, -1273], [-10551, 39670, -10551, 0], [18693, -37938, 37938, -18693], [2549, 19004, -19004, -2549], [-3503, -14652, -3503, 0], [6557, -20532, 20532, -6557], [-4284, 0, -28040, 28040], [0, 941, -16841, 941], [-13260, 0, -32516, 32516], [-17959, 17959, 0, 13392], [-41779, 23632, -41779, 0], [0, 38071, -26919, 38071], [20648, 0, 35736, -35736], [0, -2795, 36631, -2795]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_22_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_22_4_c_a();".
// 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_22_4_c_a(:prec:=4)
    chi := MakeCharacter_22_c();
    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_22_4_c_a();".
// 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_22_4_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_22_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![961, -434, 76, 1, 1]>],Snew);
    return Vf;
end function;