
// Make newform 1728.4.c.a in Magma, downloaded from the LMFDB on 08 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1728_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1728_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_1728_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_1728_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];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_1728_c();"
function MakeCharacter_1728_c()
    N := 1728;
    order := 2;
    char_gens := [703, 325, 1217];
    v := [1, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1728_c_Hecke();"
function MakeCharacter_1728_c_Hecke( : Kf := false)
    N := 1728;
    order := 2;
    char_gens := [703, 325, 1217];
    char_values := [[-1, 0], [1, 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, 0], [0, 0], [0, -12], [0, 17], [-36, 0], [-19, 0], [0, 60], [0, -1], [108, 0], [0, 120], [0, -54], [109, 0], [0, -216], [0, -270], [468, 0], [0, -72], [36, 0], [145, 0], [0, -181], [576, 0], [-809, 0], [0, -287], [360, 0], [0, 156], [955, 0], [0, 144], [0, -1099], [-1548, 0], [-214, 0], [0, -804], [0, 1242], [792, 0], [0, 228], [0, 991], [0, -1248], [0, -827], [-1766, 0], [0, -161], [-2196, 0], [0, -1032], [-1152, 0], [-2215, 0], [4572, 0], [-937, 0], [0, -1068], [0, -1459], [0, 1315], [0, -918], [3312, 0], [1010, 0], [0, 480], [2736, 0], [3007, 0], [5112, 0], [0, -3912], [3024, 0], [0, -1164], [0, -1835], [-2734, 0], [0, 744], [0, 1458], [0, -2028], [0, -3942], [8676, 0], [-1333, 0], [0, -6024], [0, -4553], [6931, 0], [1296, 0], [9757, 0], [0, 5040], [8388, 0], [0, 5093], [181, 0], [0, -6157], [-11664, 0], [0, -3204], [11338, 0], [0, 1632], [6607, 0], [-8892, 0], [-5707, 0], [-6588, 0], [-4750, 0], [0, 594], [10152, 0], [0, -8820], [-13142, 0], [0, -3492], [0, 1385], [4500, 0], [2232, 0], [0, -2647], [-9108, 0], [0, -9558], [-252, 0], [0, 9036], [0, 10116], [0, -1189], [-2971, 0], [0, 12727], [0, -9708], [-13608, 0], [0, -4476], [0, -9577], [-10477, 0], [828, 0], [0, -9672], [11016, 0], [7418, 0], [0, -10927], [-12527, 0], [0, -6756], [0, -1225], [0, 3133], [0, 6528], [0, 8154], [13464, 0], [0, 2232], [23400, 0], [15409, 0], [-19693, 0], [0, 14940], [-17856, 0], [0, 1674], [0, 15828], [-1603, 0], [16344, 0], [0, 2322], [-38086, 0], [0, -4374], [18036, 0], [0, 5689], [40661, 0], [0, -5604], [-5041, 0], [0, -7512], [0, 15047], [0, -672], [0, 9120], [0, 14418], [0, 13092], [0, 6877], [43956, 0], [17225, 0], [-22680, 0], [-35819, 0], [0, -4272], [0, 4771], [4932, 0], [35821, 0], [0, -12636], [0, -377], [-26856, 0], [0, -11053], [-32904, 0], [0, 29106], [0, -20928], [-11989, 0], [0, -6036], [3780, 0], [0, 18012], [0, -3815], [-33012, 0], [0, -33048], [15084, 0], [0, -14203], [-3422, 0], [-25325, 0], [0, -13716], [-1224, 0], [55258, 0], [27396, 0], [-12653, 0], [0, -30691], [0, -5184], [0, 9234], [0, 4668], [0, 2161], [26170, 0], [0, -3095], [-33624, 0], [-33982, 0], [0, -23220], [34272, 0], [0, 12984], [-46927, 0], [0, 23635], [-16181, 0], [-7380, 0], [49735, 0], [57960, 0], [0, -25541], [0, -15828], [-25596, 0], [0, -44028], [58787, 0], [-47503, 0], [0, 16332], [63792, 0], [0, 39516], [0, -4283], [-40519, 0], [-13949, 0], [-64080, 0], [0, 6192], [0, -11987], [80676, 0], [0, 15372], [0, 8243], [-47305, 0], [0, 7500], [0, -29447], [48204, 0], [56736, 0], [37223, 0], [0, 33210], [0, -5052], [6192, 0], [0, 15648], [-35119, 0], [0, -25326], [0, 38688], [0, 15930], [53100, 0], [75097, 0], [0, 24012], [-22572, 0], [0, 14165], [-9396, 0], [-44299, 0], [0, 10746], [0, -38502], [0, -47868], [0, -33173], [9468, 0], [-94805, 0], [0, 9612], [-74664, 0], [-91800, 0], [24048, 0], [0, -3889], [0, 10981], [-39635, 0], [0, 61956], [33588, 0], [0, -60911], [-21672, 0], [0, -50382], [-52776, 0], [7706, 0], [0, 60324], [72324, 0], [-96677, 0], [0, 6276], [6084, 0], [61505, 0], [0, -42606], [0, -9696], [60698, 0], [0, -60679], [-82404, 0], [100853, 0], [-11231, 0], [0, 9792], [0, 74250], [0, -74508], [0, 39144], [0, 2322], [0, -38604], [-128447, 0], [0, 45523], [-36038, 0], [0, 75457], [-112574, 0], [0, -31051], [98604, 0], [35674, 0], [16202, 0], [-114840, 0], [-51372, 0], [0, -43470], [-72216, 0], [-15299, 0], [0, -41237], [80820, 0], [124687, 0], [0, 75312], [0, 67193], [0, 46356], [0, 86868], [-123336, 0], [0, -54408], [68760, 0], [-10118, 0], [0, -47400], [0, -31087], [0, 30900], [-16848, 0], [0, 54287], [-14005, 0], [0, -8640], [0, -29862]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1728_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1728_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_1728_4_c_a(:prec:=2)
    chi := MakeCharacter_1728_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(1999) - 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_1728_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_1728_4_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1728_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![432, 0, 1]>,<7,R![867, 0, 1]>,<11,R![36, 1]>],Snew);
    return Vf;
end function;