
// Make newform 448.4.p.f in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_448_p();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_448_p_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_448_4_p_f();".
// 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_448_4_p_f();".
// 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 := [576, -672, 808, -20, 29, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-428592, 19488, -23432, 1629, -841, 29], [596328, -82172, 30793, 5459, 989, 64], [-4176, -159176, -986, -5713, 197, -203], [543504, 35804, 24959, 4792, 1012, -133], [11952, 481472, 2822, 16351, 221, 581]];
    Rf_basisdens := [1, 45520, 68280, 136560, 68280, 45520];
    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_448_p();"
function MakeCharacter_448_p()
    N := 448;
    order := 6;
    char_gens := [127, 197, 129];
    v := [3, 6, 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_448_p_Hecke();"
function MakeCharacter_448_p_Hecke(Kf)
    N := 448;
    order := 6;
    char_gens := [127, 197, 129];
    char_values := [[-1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 1, 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, 0], [0, 0, 0, 2, 0, 1], [0, 1, 1, 0, 0, 0], [-4, 0, 0, 9, -1, 0], [22, 1, 0, 11, -1, 1], [23, 0, 1, 46, -1, 0], [0, 11, 0, 0, -5, 8], [49, -2, 1, 49, -2, -1], [0, 5, 6, 0, 0, 1], [51, 22, -1, 0, -1, 0], [0, 1, 2, 77, -1, -23], [73, 26, -2, 73, 4, 24], [141, -8, -9, 282, 9, -16], [20, -22, -16, 40, 16, -44], [-33, 22, -1, -33, 2, 21], [0, -6, -12, -237, 6, 48], [0, -2, -4, -108, 2, -3], [189, 2, -6, -189, 0, -8], [88, -8, 0, 44, 42, -25], [322, -26, 14, 644, -14, -52], [190, -58, 0, 95, -42, -8], [372, 33, -14, -372, 0, -47], [42, -92, -22, 0, -22, 0], [-291, 4, -28, 291, 0, -32], [45, 48, -1, 90, 1, 96], [432, 125, 0, 216, -35, 80], [-770, 119, -48, -770, 96, 71], [-503, 64, 13, 503, 0, -51], [0, -19, -38, 94, 19, -168], [-399, 242, 25, 0, 25, 0], [-420, -118, -32, -840, 32, -236], [606, 233, 4, 606, -8, 237], [0, -11, -22, 1596, 11, 72], [688, 60, 80, 0, 80, 0], [-228, 71, 73, -228, -146, 144], [30, -235, 0, 15, -81, -77], [-438, 110, 0, -219, -2, 56], [-34, 45, -172, 34, 0, -217], [1581, -48, 45, 0, 45, 0], [1815, -4, 12, -1815, 0, 16], [-742, -17, 0, -371, -107, 45], [544, -56, -52, 1088, 52, -112], [697, -138, -167, -697, 0, -29], [0, -79, -158, -1544, 79, -336], [-495, 26, -23, 0, -23, 0], [0, 31, 62, -2009, -31, -187], [-628, 50, -128, -1256, 128, 100], [-1202, 224, -42, 0, -42, 0], [0, 35, 70, -2889, -35, 159], [-668, -3, -43, 668, 0, -40], [-1956, -235, -101, -1956, 202, -336], [-2011, -96, 109, -4022, -109, -192], [-594, 462, 0, -297, -82, 272], [1113, -44, -31, 0, -31, 0], [2682, 101, -3, -2682, 0, -104], [1088, -108, 0, 544, 130, -119], [-498, 104, 0, -249, 120, -8], [1636, 265, -134, 1636, 268, 131], [0, 120, 240, -1759, -120, 48], [-3189, 478, 23, 0, 23, 0], [0, -23, -46, 4169, 23, 91], [2856, -144, 132, 5712, -132, -288], [-6244, -300, 52, 0, 52, 0], [0, 204, 408, -6, -204, 375], [433, -64, -200, -433, 0, -136], [-1011, 614, -134, -1011, 268, 480], [88, -745, -310, -88, 0, 435], [-3967, 954, 153, 0, 153, 0], [7376, -268, 0, 3688, 310, -289], [-495, -440, -1, -990, 1, -880], [-2496, -1189, 0, -1248, -133, -528], [-1115, 34, 181, 1115, 0, 147], [0, -114, -228, 976, 114, 731], [1049, -142, 286, 1049, -572, 144], [4195, -76, -173, 8390, 173, -152], [2427, -1054, -101, 2427, 202, -1155], [0, -313, -626, -744, 313, -1008], [226, -645, -29, -226, 0, 616], [-180, 629, 259, -180, -518, 888], [-1096, -777, 0, -548, -217, -280], [-720, -620, 248, 0, 248, 0], [-1429, -594, 351, 0, 351, 0], [-8506, -183, 0, -4253, -269, 43], [1475, 272, -415, 2950, 415, 544], [-1069, -1230, -77, -1069, 154, -1307], [1871, -146, 695, -1871, 0, 841], [2061, -478, -227, 0, -227, 0], [-3143, -936, -336, -3143, 672, -1272], [4905, -344, -25, 9810, 25, -688], [1630, -570, -206, 3260, 206, -1140], [-2118, -667, 160, -2118, -320, -507], [0, 34, 68, 1620, -34, 531], [6152, 944, 0, 3076, 14, 465], [-1185, -308, 207, -2370, -207, -616], [-3542, 905, 264, 3542, 0, -641], [9342, -632, 86, 0, 86, 0], [780, -555, -1019, -780, 0, -464], [10266, 444, 0, 5133, -484, 464], [1511, -592, -517, 1511, 1034, -1109], [-6758, -703, 367, -6758, -734, -336], [-3093, 316, 939, -6186, -939, 632], [0, -297, -594, -3336, 297, 72], [0, -118, -236, -13344, 118, 1125], [3351, -1222, -50, 3351, 100, -1272], [-8646, 1295, 0, -4323, -1003, 1149], [13870, 238, 0, 6935, -18, 128], [4188, 1644, 36, 0, 36, 0], [2028, 503, 151, -2028, 0, -352], [-7336, 1440, 0, -3668, -1058, 1249], [5161, -880, -997, 10322, 997, -1760], [-9271, -924, 13, -9271, -26, -911], [0, -75, -150, -5162, 75, 216], [-8913, -754, -29, 0, -29, 0], [0, -584, -1168, -4286, 584, 257], [-9532, -62, -680, -19064, 680, -124], [0, -574, -1148, 3969, 574, -1296], [11978, -2412, -254, 0, -254, 0], [0, 96, 192, 17238, -96, 687], [15783, -292, -284, 15783, 568, -576], [-1164, 770, 552, -2328, -552, 1540], [-6214, -1178, 0, -3107, -234, -472], [-4547, 850, -259, 0, -259, 0], [-2844, -1811, 101, 2844, 0, 1912], [14334, -1579, 0, 7167, -669, -455], [5780, 179, -322, 5780, 644, -143], [-210, -1832, 188, 0, 188, 0], [10763, -872, 560, 10763, -1120, -312], [2352, -915, 606, 2352, -1212, -309], [-17020, 536, 524, 0, 524, 0], [743, -1380, -148, -743, 0, 1232], [4842, -1137, 0, 2421, 629, -883], [11252, 514, 280, 22504, -280, 1028], [6261, 562, -995, -6261, 0, -1557], [-12527, 602, -23, 0, -23, 0], [-9066, -1479, 625, 9066, 0, 2104], [3641, 216, 611, 7282, -611, 432], [-21636, 1675, 0, -10818, -1173, 1424], [0, -118, -236, 20104, 118, -1723], [-6573, 1384, 885, -13146, -885, 2768], [0, -118, -236, 19545, 118, 1752], [3142, 3820, 238, 0, 238, 0], [-306, -3379, 235, -306, -470, -3144], [-2768, 1668, 0, -1384, -910, 1289], [-922, -1994, -950, -1844, 950, -3988], [-5960, -767, 0, -2980, 529, -648], [16830, -696, 702, 0, 702, 0], [3755, -176, 165, 7510, -165, -352], [-2118, 2524, 0, -1059, 1548, 488], [-3239, 342, 305, -3239, -610, 647], [4770, 1743, 1836, -4770, 0, 93], [-14428, 1399, 713, -14428, -1426, 2112], [-10572, -2952, -724, -21144, 724, -5904], [6466, -2106, -626, 12932, 626, -4212], [24261, -856, -215, 24261, 430, -1071], [-26124, -1886, 0, -13062, 44, -965], [-4596, -1830, -648, -9192, 648, -3660], [-2207, 3230, 537, 2207, 0, -2693], [9963, 1530, -830, -9963, 0, -2360], [7372, 1712, 316, 14744, -316, 3424], [6762, -66, 0, 3381, 1822, -944], [4738, 2633, -8, -4738, 0, -2641], [4929, -3934, -479, 0, -479, 0], [-2842, 1454, -1326, -5684, 1326, 2908], [-38130, -335, -508, -38130, 1016, -843], [0, 225, 450, 23208, -225, 48], [0, -409, -818, 13815, 409, 981], [8600, -4672, 0, 4300, -258, -2207], [16054, -3300, 0, 8027, 2700, -3000]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_448_p_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_448_4_p_f();".
// 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_448_4_p_f(:prec:=6)
    chi := MakeCharacter_448_p();
    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_448_4_p_f();".
// 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_448_4_p_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_p();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![97969, 17215, 5216, 241, 104, 7, 1]>],Snew);
    return Vf;
end function;