
// Make newform 448.6.f.b in Magma, downloaded from the LMFDB on 16 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_448_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_448_f_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_6_f_b();".
// 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_6_f_b();".
// 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 := [1830609, 0, 287808, 0, 15517, 0, 208, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-45923360, 0, 567504, 0, 27552, 0, 196, 0], [-570933138, 0, -56404144, 0, -831924, 0, -4040, 0], [0, 809257932, 0, 27739628, 0, 303786, 0, 1222], [0, -11248398780, 0, -1214256788, 0, -18153962, 0, -93146], [52462110921, -5108756376, 5186588396, -552201520, 77029898, -8341306, 406802, -40870], [0, 17813518128, 0, 713838720, 0, 12942020, 0, 77668], [367234776447, 35761294632, 36306118772, 3865410640, 539209286, 58389142, 2847614, 286090]];
    Rf_basisdens := [1, 154009, 462027, 18943107, 625122531, 208374177, 208374177, 208374177];
    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_f();"
function MakeCharacter_448_f()
    N := 448;
    order := 2;
    char_gens := [127, 197, 129];
    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_448_f_Hecke();"
function MakeCharacter_448_f_Hecke(Kf)
    N := 448;
    order := 2;
    char_gens := [127, 197, 129];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 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 := 6;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, -2, -1, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0], [0, 0, 0, 5, 0, 0, 1, 0], [0, 0, 0, -10, 0, 0, 1, 0], [0, 0, 0, 0, -5, 7, 0, -1], [0, 0, 5, 0, 0, 14, 0, 2], [1218, -6, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -62, -35, 0, 5], [-2422, 18, 0, 0, 0, 0, 0, 0], [0, 0, 0, -54, 0, 0, 10, 0], [0, 0, -27, 0, 0, -14, 0, -2], [0, 0, 0, 0, 1014, -63, 0, 9], [-12774, 60, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -759, -63, 0, 9], [0, 0, 0, -249, 0, 0, -12, 0], [0, 0, -27, 0, 0, 294, 0, 42], [0, 0, -92, 0, 0, 35, 0, 5], [0, 0, 0, 144, 0, 0, 45, 0], [0, 0, 54, 0, 0, -203, 0, -29], [0, 0, 0, 0, 1953, -378, 0, 54], [0, 0, 0, -172, 0, 0, -55, 0], [0, 0, 0, -458, 0, 0, 11, 0], [0, 0, 0, -1345, 0, 0, 67, 0], [0, 0, 0, 0, 5602, -98, 0, 14], [0, 0, -183, 0, 0, 406, 0, 58], [-27230, -384, 0, 0, 0, 0, 0, 0], [-107382, -183, 0, 0, 0, 0, 0, 0], [0, 0, -27, 0, 0, 1274, 0, 182], [0, 0, 0, 0, 1413, 378, 0, -54], [132090, 312, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -9655, 119, 0, -17], [95274, 72, 0, 0, 0, 0, 0, 0], [0, 0, 621, 0, 0, 630, 0, 90], [0, 0, 0, -79, 0, 0, -275, 0], [0, 0, 135, 0, 0, 1148, 0, 164], [0, 0, 0, 0, -5226, -2016, 0, 288], [0, 0, 0, 3897, 0, 0, 527, 0], [0, 0, 507, 0, 0, -952, 0, -136], [0, 0, 0, 3505, 0, 0, 242, 0], [0, 0, 1466, 0, 0, 609, 0, 87], [554602, -267, 0, 0, 0, 0, 0, 0], [698346, 990, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 9770, 2198, 0, -314], [0, 0, 729, 0, 0, 4634, 0, 662], [0, 0, 0, 0, -2368, 3668, 0, -524], [0, 0, 0, 0, 37203, -63, 0, 9], [0, 0, 0, 6167, 0, 0, -473, 0], [287322, -3648, 0, 0, 0, 0, 0, 0], [0, 0, -231, 0, 0, 4718, 0, 674], [0, 0, 0, 6622, 0, 0, -463, 0], [0, 0, 0, 0, -31545, 5292, 0, -756], [0, 0, 0, 1404, 0, 0, -946, 0], [0, 0, -1408, 0, 0, 3367, 0, 481], [0, 0, 0, -1251, 0, 0, -187, 0], [0, 0, 0, 0, 31072, 1498, 0, -214], [-1284886, -678, 0, 0, 0, 0, 0, 0], [-1269030, -2208, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 77695, 3724, 0, -532], [0, 0, 0, -8985, 0, 0, 1407, 0], [0, 0, 0, 0, 5329, 2842, 0, -406], [0, 0, 0, 0, 15888, -4473, 0, 639], [0, 0, 0, -31910, 0, 0, 44, 0], [1707282, -5706, 0, 0, 0, 0, 0, 0], [0, 0, -1917, 0, 0, -6076, 0, -868], [-1269142, -903, 0, 0, 0, 0, 0, 0], [0, 0, -1595, 0, 0, -17094, 0, -2442], [0, 0, 0, 27547, 0, 0, -2542, 0], [0, 0, 0, -29192, 0, 0, 0, 0], [0, 0, -2883, 0, 0, 6958, 0, 994], [0, 0, 0, 0, 103160, 8330, 0, -1190], [-270518, 5598, 0, 0, 0, 0, 0, 0], [0, 0, 243, 0, 0, -9268, 0, -1324], [0, 0, 0, 0, 80646, 315, 0, -45], [-632310, -2058, 0, 0, 0, 0, 0, 0], [0, 0, 0, -28397, 0, 0, 3344, 0], [742266, 9, 0, 0, 0, 0, 0, 0], [0, 0, 0, 19702, 0, 0, 1046, 0], [0, 0, 0, 0, -107955, -2646, 0, 378], [360890, -14340, 0, 0, 0, 0, 0, 0], [0, 0, 677, 0, 0, 7378, 0, 1054], [0, 0, 0, -25046, 0, 0, -1969, 0], [0, 0, 0, 0, 20756, 8225, 0, -1175], [0, 0, 3407, 0, 0, 3472, 0, 496], [1387986, 9780, 0, 0, 0, 0, 0, 0], [-16846, 17667, 0, 0, 0, 0, 0, 0], [0, 0, 0, -36593, 0, 0, 4126, 0], [0, 0, 8046, 0, 0, -7147, 0, -1021], [0, 0, 0, 0, 140475, -12033, 0, 1719], [0, 0, 0, 0, -248406, -43407, 0, 6201], [0, 0, -3915, 0, 0, 4438, 0, 634], [0, 0, 11209, 0, 0, -15554, 0, -2222], [0, 0, -16065, 0, 0, -4788, 0, -684], [0, 0, 0, 0, 95628, -315, 0, 45], [0, 0, 0, -28685, 0, 0, -286, 0], [0, 0, 0, 6922, 0, 0, -10538, 0], [0, 0, 0, 0, 144833, 10955, 0, -1565], [878882, -1884, 0, 0, 0, 0, 0, 0], [0, 0, 25839, 0, 0, -8988, 0, -1284], [2573346, -7512, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -122349, -56385, 0, 8055], [6232674, -19509, 0, 0, 0, 0, 0, 0], [0, 0, -10287, 0, 0, 4270, 0, 610], [0, 0, 0, 114156, 0, 0, 8910, 0], [0, 0, 0, 0, 258957, -30807, 0, 4401], [0, 0, 0, -79748, 0, 0, -2960, 0], [0, 0, -15688, 0, 0, 34783, 0, 4969], [0, 0, 0, -143336, 0, 0, -9373, 0], [0, 0, 0, 0, 85664, -18844, 0, 2692], [914074, -8940, 0, 0, 0, 0, 0, 0], [10131618, -3813, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 382151, 34790, 0, -4970], [0, 0, 4212, 0, 0, -45325, 0, -6475], [-12635574, -7899, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 278575, -71981, 0, 10283], [0, 0, 0, 0, -383046, 55062, 0, -7866], [5384274, 12876, 0, 0, 0, 0, 0, 0], [0, 0, 9605, 0, 0, 43526, 0, 6218], [0, 0, 0, 111231, 0, 0, 14157, 0], [-3498782, 45252, 0, 0, 0, 0, 0, 0], [0, 0, 0, 168893, 0, 0, 12794, 0], [0, 0, 12725, 0, 0, 106778, 0, 15254], [0, 0, 0, 0, -742639, -30142, 0, 4306], [-14286174, 15420, 0, 0, 0, 0, 0, 0], [3129994, -3372, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 684006, -44667, 0, 6381], [0, 0, 0, 0, -419906, 25354, 0, -3622], [0, 0, 0, -149941, 0, 0, -16094, 0], [0, 0, -24813, 0, 0, -105056, 0, -15008], [0, 0, -27659, 0, 0, -63210, 0, -9030], [0, 0, -41607, 0, 0, 56350, 0, 8050], [-8536598, 58332, 0, 0, 0, 0, 0, 0], [0, 0, 0, 72310, 0, 0, -16510, 0], [0, 0, 0, 202090, 0, 0, -16039, 0], [0, 0, 0, 29217, 0, 0, -3344, 0], [0, 0, 0, 0, -438853, 105455, 0, -15065], [0, 0, 0, -188331, 0, 0, 18799, 0], [-5494446, -45333, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 738707, 115220, 0, -16460], [12070026, 58698, 0, 0, 0, 0, 0, 0], [0, 0, -9072, 0, 0, -70385, 0, -10055], [0, 0, -44465, 0, 0, 76776, 0, 10968], [0, 0, 0, 227375, 0, 0, -21296, 0], [0, 0, 0, 0, 119874, -54558, 0, 7794], [0, 0, 0, -290577, 0, 0, 3477, 0], [0, 0, 0, 181626, 0, 0, -16400, 0], [0, 0, 0, 0, 768175, 171892, 0, -24556], [0, 0, -38214, 0, 0, -72303, 0, -10329], [14168098, -3654, 0, 0, 0, 0, 0, 0], [0, 0, 0, 28156, 0, 0, 14916, 0], [0, 0, -23139, 0, 0, -33250, 0, -4750], [0, 0, 0, 0, 562782, 59598, 0, -8514], [0, 0, -73089, 0, 0, 68824, 0, 9832], [0, 0, -48807, 0, 0, -51282, 0, -7326], [0, 0, -24084, 0, 0, 58947, 0, 8421], [0, 0, 0, 127618, 0, 0, 28721, 0], [0, 0, 0, 338996, 0, 0, 32251, 0], [0, 0, 0, -378187, 0, 0, -21187, 0], [0, 0, 57577, 0, 0, -26110, 0, -3730], [-12957894, -39960, 0, 0, 0, 0, 0, 0], [0, 0, 20925, 0, 0, -148386, 0, -21198], [0, 0, 0, 0, -653499, -151011, 0, 21573], [-11341470, 44736, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1262922, 77742, 0, -11106], [0, 0, -44766, 0, 0, -62559, 0, -8937], [0, 0, 0, 418845, 0, 0, 18402, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_448_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_448_6_f_b();".
// 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_6_f_b(:prec:=8)
    chi := MakeCharacter_448_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_f_b();".
// 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_6_f_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![49392, 0, -784, 0, 1]>],Snew);
    return Vf;
end function;