
// Make newform 8.14.b.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_8_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_8_14_b_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_8_14_b_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 := [20, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    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_8_b();"
function MakeCharacter_8_b()
    N := 8;
    order := 2;
    char_gens := [7, 5];
    v := [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_8_b_Hecke();"
function MakeCharacter_8_b_Hecke(Kf)
    N := 8;
    order := 2;
    char_gens := [7, 5];
    char_values := [[1, 0], [-1, 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 := 14;
    raw_aps := [[-56, -4], [0, 129], [0, -1270], [-175832, 0], [0, 148245], [0, -1748546], [-133520302, 0], [0, -1956439], [-35585416, 0], [0, 89285286], [-5765001568, 0], [0, 740167642], [-23546348918, 0], [0, 821222629], [-68107736592, 0], [0, 9353966274], [0, -7179956339], [0, -23861087370], [0, 21163131297], [-1309471657368, 0], [478647871914, 0], [-364547231600, 0], [0, 49098397129], [-102457641350, 0], [-6157717373342, 0], [0, 90530220410], [19880406159624, 0], [0, -422848521723], [0, -798398566354], [2537391877554, 0], [81958549675648, 0], [0, 4953200794945], [-132281901046422, 0], [0, 879793461461], [0, 4984221296946], [-86085598831368, 0], [0, -14115886908698], [0, 6234470216209], [220904256334408, 0], [0, 6016750532814], [0, 33397467163321], [0, -21959393171710], [105716583207872, 0], [-384016552426686, 0], [0, 24743057767402], [-1153224881221400, 0], [0, -90876017245175], [1761110272951904, 0], [0, 197273031131057], [0, -166672619050054], [1858830230030794, 0], [-3719897631961680, 0], [3834412942853042, 0], [0, -323914981145235], [5369129663777538, 0], [5067132210369064, 0], [0, -178532083241154], [-7509709948556208, 0], [0, 250895535127922], [-13198027610561478, 0], [0, 305015577105469], [0, 757774937973594], [0, -95796172382343], [-16655677747052008, 0], [-13829057389444006, 0], [0, -630056714366218], [0, 2319413069219125], [-6127440512372462, 0], [0, -3146261711497123], [0, -1674528744960314], [-46264202174424606, 0], [56738530314696200, 0], [-86095196645544912, 0], [0, -2883367533926686], [0, 751505785621421], [66621624170934144, 0], [0, -1409371097008694], [0, 192727409048702], [-63111990462083118, 0], [46823794592777530, 0], [0, -9969584667508719], [0, -2599019351788390], [-148095091972299408, 0], [184376361087376754, 0], [-146083562587661160, 0], [0, -2092807097341491], [-118165684794264510, 0], [123577683557960618, 0], [0, 11940289312381470], [-134235434552696816, 0], [0, -471932782227703], [-232520629306946720, 0], [-279559785788054392, 0], [0, 18508630007351365], [0, 6780337655519961], [154880512134383064, 0], [0, 17577498611682006], [634136586932379882, 0], [0, 30109331230825749], [0, -58870818880820570], [0, -23382038555225263], [0, 1843408801848462], [0, 55382542813705209], [64727028372714330, 0], [0, -32202176147641075], [400636334258910018, 0], [0, 25482137369373877], [-640223677404125166, 0], [147545646215931320, 0], [-2187188966122398598, 0], [-926715504261434912, 0], [0, -27015718266340486], [-1373891175902528182, 0], [0, 142290662224001541], [2146021550496743512, 0], [-909161994401533438, 0], [0, -50795290746186431], [-1807605387773218392, 0], [0, 122128035053025534], [0, -5412190000145559], [0, 58264487868032050], [1089363827366688674, 0], [0, -246156727880597478], [0, -210234472140446171], [0, -171543337195441735], [0, -211697001110767690], [0, -54916815780974614], [-3074359851516797680, 0], [1901984480629399608, 0], [0, 356729178084815494], [0, -40682654886165839], [-4909506683834963576, 0], [-1581813281336557648, 0], [0, 353504798350076322], [9498583013244900122, 0], [-7218061243962700670, 0], [0, 200073249924651914], [0, -601667468439730263], [0, -331509656375869658], [-4318402356113895030, 0], [0, -390909849145200155], [0, -577500362504928190], [-6635152523887436776, 0], [0, 768114282565549197], [0, 550521743003264246], [1817365648672660840, 0], [0, -612089530717469166], [-11405381834925697542, 0], [0, 226575760693965661], [12371247696424338144, 0], [0, 87853521846772142], [7206633302758923442, 0], [0, 1126750108919468569], [26964152806748422488, 0], [0, -414902685929024683], [-29399390474378929968, 0], [16946970092816135160, 0], [712343396686758050, 0], [28217783741967576458, 0], [0, 2101603549286959950], [0, -323070804672028743], [-2242726641057780006, 0], [-16224548153462683672, 0], [0, -2322676116319604235], [11281928669127891218, 0], [-30690800886691263176, 0], [-35415136909022934688, 0], [0, -1006519491753043398]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8_14_b_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_8_14_b_a(:prec:=2)
    chi := MakeCharacter_8_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 14));
    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_8_14_b_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_8_14_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<3,R![5258556, 0, 1]>],Snew);
    return Vf;
end function;