
// Make newform 35.4.a.c in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_35_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_35_4_a_c();".
// 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_35_4_a_c();".
// 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 := [-14, -17, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-11, -1, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_35_a();"
function MakeCharacter_35_a()
    N := 35;
    order := 1;
    char_gens := [22, 31];
    v := [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_35_a_Hecke( : Kf := Kf)
    return MakeCharacter_35_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 := 4;
    raw_aps := [[-1, 1, 0], [1, 1, -1], [5, 0, 0], [7, 0, 0], [-25, 3, 1], [13, -13, 5], [-21, 13, 11], [54, -10, 6], [-42, -14, 2], [105, 19, 17], [108, 24, -4], [-14, 16, -12], [120, 10, 2], [6, 30, -34], [-239, -51, -13], [44, -130, -22], [-76, -176, 48], [416, -34, -26], [32, -12, 108], [-32, 72, -40], [78, 124, 76], [-315, -83, -89], [-556, -160, 8], [108, -98, -82], [55, -87, -65], [510, 316, -40], [389, 313, -73], [-1054, -138, 106], [323, 437, -17], [326, -24, 4], [-236, -348, 28], [834, -14, 26], [820, -146, -122], [626, -2, -22], [-598, 244, -60], [605, -363, 183], [282, 100, -356], [-206, 390, 178], [-1515, 505, 71], [-121, -371, 195], [212, -792, -8], [1732, 246, -302], [651, -277, -215], [-3292, 518, -2], [28, -110, 178], [-772, 540, 252], [-2543, 285, 55], [3037, -383, -9], [1165, 165, -109], [1504, 62, 302], [-2244, 34, -202], [-2879, -847, 363], [-254, -260, -504], [1366, 1186, -26], [-5822, -120, -112], [1298, -262, 638], [1706, 508, 588], [-812, 1760, 164], [4194, 796, -500], [497, 1127, -739], [1403, -1181, 101], [-4837, 681, 7], [3387, 843, 173], [1622, -918, -14], [1805, -1545, 57], [-914, 2016, 8], [-1524, 664, 328], [2178, -384, 656], [-3150, 1930, -334], [666, 1224, -124], [-5713, 201, -1097], [2768, 1800, 232], [-7175, 5, 11], [3380, -1310, 602], [-10860, 400, -80], [-3444, -1148, 1172], [9119, -135, -149], [-505, -1643, -13], [-117, -863, 755], [-254, 1808, 728], [1600, -1516, -468], [2867, 485, 1495], [-6257, 1239, -619], [742, 548, -196], [-6666, 222, -358], [5166, 262, 422], [5109, 1267, -223], [-5436, -1082, -314], [-6148, 758, -1726], [-10716, 120, 68], [1607, -1481, 81], [2650, -2890, -1290], [-8378, -34, 1082], [4429, -1287, -253], [3, -1865, -83], [13755, -49, -455], [7426, -2452, -972], [6742, -1128, 1196], [-788, 1256, 968], [7305, 2451, -655], [-380, -1756, -1072], [5228, 1334, -910], [5708, -1152, -32], [778, 832, 928], [-3556, -1680, -2952], [-2679, -885, -475], [-1320, 2636, -2276], [-4807, 1483, -987], [655, 895, -2195], [9594, -2592, -1168], [755, -5825, 281], [-12974, 2212, -228], [-3730, 220, 1356], [-5134, 2274, 306], [1031, -337, 805], [-2334, -1600, 2656], [9369, 2649, -505], [664, -5400, -208], [-22362, 756, 792], [4739, -321, -1187], [9372, -2970, 170], [9500, -2354, -730], [-4579, 2563, -531], [-9524, 396, -496], [-348, 6880, 280], [-12915, 311, -515], [-3231, -2341, 2913], [23610, 3470, -650], [-5368, 6376, -208], [4457, -2945, 1385], [-6489, 2907, -2455], [-7080, 152, -4112], [-1451, -1171, 215], [23812, -4610, -1086], [5194, -2492, -1208], [-6046, -7504, 2944], [-523, -3933, 421], [-3323, -651, 1051], [-5353, 4989, -1949], [331, -4039, 27], [9302, -6710, -730], [-23009, -879, 779], [-3660, 4080, 1292], [14326, 3234, -1018], [19080, 4574, 462], [3894, 4618, 1250], [-1782, 1692, 20], [-10194, 148, -1876], [-13100, -2832, 1264], [7640, 4988, 176], [3926, -8732, -2296], [6772, 4066, 3478], [4728, 5872, -2420], [-576, 1400, 5032], [-26906, -490, 1742], [-28488, -192, 2184], [6873, 1, 3115], [20036, -2166, 2086], [6735, 5505, 5231], [-2520, 5814, -5106], [-13016, 2096, -900], [-9396, 7798, 3422], [9478, 2902, 3594], [-4448, -6440, -2180], [18258, 2276, -3704], [-23253, 6175, 1385], [-22848, 8288, -96], [34667, -759, 87]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_35_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_35_4_a_c();".
// 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_35_4_a_c(:prec:=3)
    chi := MakeCharacter_35_a();
    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_35_4_a_c();".
// 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_35_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_35_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-30, -14, 3, 1]>],Snew);
    return Vf;
end function;