
// Make newform 272.4.b.c in Magma, downloaded from the LMFDB on 17 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_272_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_272_b_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_272_4_b_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_272_4_b_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 := [2, 0, 21, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [0, 42, 0, 2], [42, 0, 4, 0]];
    Rf_basisdens := [1, 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_272_b();"
function MakeCharacter_272_b()
    N := 272;
    order := 2;
    char_gens := [239, 69, 241];
    v := [2, 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_272_b_Hecke();"
function MakeCharacter_272_b_Hecke(Kf)
    N := 272;
    order := 2;
    char_gens := [239, 69, 241];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, 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+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 := 4;
    raw_aps := [[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 1, -1, 0], [0, 1, -2, 0], [-8, 0, 0, 1], [7, -6, 5, -1], [-40, 0, 0, 2], [0, 13, 13, 0], [0, 20, 5, 0], [0, -19, 19, 0], [0, -28, -17, 0], [0, -40, 14, 0], [36, 0, 0, 4], [-280, 0, 0, 4], [6, 0, 0, 12], [84, 0, 0, -12], [0, 92, 25, 0], [-80, 0, 0, 6], [0, 21, -19, 0], [0, 92, -20, 0], [0, 9, 81, 0], [-556, 0, 0, -8], [-784, 0, 0, -5], [0, 84, -138, 0], [-432, 0, 0, 9], [1048, 0, 0, 24], [0, -15, -58, 0], [0, 160, -133, 0], [0, 96, 4, 0], [-488, 0, 0, 12], [0, 301, -158, 0], [-1516, 0, 0, -11], [0, -151, -182, 0], [2294, 0, 0, 4], [-1680, 0, 0, -20], [-1938, 0, 0, -28], [0, 425, -20, 0], [0, -119, 163, 0], [0, -164, -195, 0], [592, 0, 0, 62], [0, 368, 253, 0], [304, 0, 0, 80], [0, 52, -250, 0], [0, -208, -79, 0], [0, 309, 141, 0], [0, 189, -378, 0], [-776, 0, 0, -60], [0, -575, 160, 0], [1176, 0, 0, 29], [0, 12, 196, 0], [3816, 0, 0, 36], [0, -692, 350, 0], [-312, 0, 0, -138], [2444, 0, 0, -83], [-1648, 0, 0, 148], [0, -220, 185, 0], [-752, 0, 0, -120], [0, 568, 17, 0], [2078, 0, 0, 58], [0, 337, -382, 0], [-4050, 0, 0, 72], [2132, 0, 0, -40], [0, -1039, -309, 0], [0, 400, -130, 0], [0, 1124, -667, 0], [4916, 0, 0, -148], [0, 136, -568, 0], [0, 517, 880, 0], [4838, 0, 0, -96], [-410, 0, 0, -142], [432, 0, 0, -36], [0, -319, -851, 0], [-368, 0, 0, -95], [0, -515, -124, 0], [-672, 0, 0, -48], [-4928, 0, 0, -79], [0, 292, -463, 0], [0, -772, -370, 0], [9638, 0, 0, 126], [0, -967, -948, 0], [-8800, 0, 0, 33], [0, -87, -343, 0], [4800, 0, 0, -241], [0, 1173, 609, 0], [-56, 0, 0, 134], [0, 764, 818, 0], [-1408, 0, 0, -213], [-986, 0, 0, -232], [-7432, 0, 0, -268], [9352, 0, 0, -22], [0, 705, 977, 0], [0, -1779, 249, 0], [11424, 0, 0, 186], [0, -2187, 1602, 0], [0, 2037, -895, 0], [-12562, 0, 0, 100], [0, -1624, 590, 0], [10240, 0, 0, 234], [0, 1288, -829, 0], [0, 797, -158, 0], [-5216, 0, 0, -43], [-2436, 0, 0, -228], [3594, 0, 0, 240], [0, 1085, 1588, 0], [-1380, 0, 0, 53], [-9744, 0, 0, 258], [-13742, 0, 0, 176], [-10408, 0, 0, 16], [0, 1924, 740, 0], [0, 1493, -161, 0], [15062, 0, 0, 156], [0, 836, 2168, 0], [0, -1763, 800, 0], [8016, 0, 0, -92], [0, 1164, -2414, 0], [0, -999, -1116, 0], [13192, 0, 0, -280], [0, -2160, -2141, 0], [-2572, 0, 0, 280], [6654, 0, 0, -88], [0, -1476, -1206, 0], [0, 2324, 71, 0], [0, 1589, -1572, 0], [0, -2323, 1486, 0], [-13840, 0, 0, -107], [0, -72, 981, 0], [0, -991, -27, 0], [3392, 0, 0, -724], [-6610, 0, 0, -300], [-4904, 0, 0, 522], [0, 1017, 155, 0], [0, 2281, 617, 0], [-7984, 0, 0, 657], [5892, 0, 0, 165], [-14060, 0, 0, 193], [16216, 0, 0, -19], [0, -779, -2542, 0], [-14562, 0, 0, 396], [0, -1648, 1946, 0], [0, 613, -2260, 0], [0, 3924, -2645, 0], [0, 973, -1531, 0], [0, 1217, -3558, 0], [5878, 0, 0, 184], [0, -319, 1263, 0], [0, -3064, -527, 0], [0, 2024, 458, 0], [22012, 0, 0, -72], [-36808, 0, 0, 28], [0, 1600, 875, 0], [0, 2424, -1400, 0], [-896, 0, 0, -282], [0, -1355, 49, 0], [0, 1601, 1198, 0], [0, -3651, 2687, 0], [19880, 0, 0, 512], [0, 636, -590, 0], [-162, 0, 0, 674], [0, 596, -2911, 0], [0, 1221, -94, 0], [-27072, 0, 0, -189], [-16424, 0, 0, 144], [-38404, 0, 0, -320], [7186, 0, 0, -16], [0, -5923, 3141, 0], [0, -1271, -2419, 0], [0, 1128, 1869, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_272_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_272_4_b_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_272_4_b_c(:prec:=4)
    chi := MakeCharacter_272_b();
    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_272_4_b_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_272_4_b_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_272_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![32, 0, 84, 0, 1]>],Snew);
    return Vf;
end function;