
// Make newform 28.8.a.a in Magma, downloaded from the LMFDB on 26 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_28_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_28_8_a_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_28_8_a_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 := [-882, -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_28_a();"
function MakeCharacter_28_a()
    N := 28;
    order := 1;
    char_gens := [15, 17];
    v := [1, 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;

function MakeCharacter_28_a_Hecke(Kf)
    return MakeCharacter_28_a();
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 := 8;
    raw_aps := [[0, 0], [-7, -1], [21, -3], [343, 0], [3714, 42], [5915, -9], [7896, -318], [13307, -27], [16320, 1512], [-79008, 462], [-90370, -2646], [-22912, 7686], [-160860, 8142], [511934, 6174], [832986, -2994], [-205314, -4032], [851067, 21789], [-273763, 14589], [-1295308, 50904], [2064636, -8148], [-4004434, -5508], [1235228, -123228], [-4950393, -53079], [7711746, 36168], [-8688736, 143370], [6686925, -87291], [1021202, -253026], [17039184, 111300], [-5363716, -216846], [16084284, -155442], [-5247220, 582372], [1377579, -196731], [7353654, 67284], [-33208987, -396549], [41648610, -244692], [-10072612, 224028], [31642835, 887823], [-1240018, -1037610], [70175238, 21978], [18285183, 803427], [40213992, -835548], [41297627, -80721], [-61541244, -379092], [-41644648, -422478], [-36225486, -251412], [70509278, 802242], [-115452292, 578592], [212910236, 460116], [196966203, -2030571], [83046215, -2563677], [-189161742, 2148552], [-91440480, -132720], [-129524248, -422190], [-94666131, 3029859], [-237601014, -3200424], [-240155940, -3820404], [-133070721, 5606787], [-198794680, -574200], [335701598, -4898880], [-334905702, 3299856], [77543795, 4224933], [-155462223, -611631], [-100274965, 5022549], [39466224, 6081144], [405799604, 2113326], [380674026, -7145796], [297931502, 1120014], [1013665136, -1905750], [3029238, -4589802], [-121218265, 12859947], [-954609726, -714336], [1124382876, 9038988], [711709124, 154044], [-559193086, 1351980], [-338587990, -11683854], [570004554, -19584882], [-226030440, -32441682], [166157159, 371835], [-518953992, -4026750], [-803935552, -11836206], [1394225133, 2024475], [-154883674, -15176952], [1246200024, 21520632], [1535484860, -18688338], [608238008, 7827408], [1396203156, -33252576], [532414746, -50095416], [-178457872, -6649902], [353148411, 1778391], [-1734187744, 23896656], [48658407, 15040137], [2537995614, 9521802], [-2063441056, 2762424], [-3025150356, 21520632], [-2689337164, -18823896], [1226922228, -26136348], [-3322871097, -9745557], [200138988, -52668858], [-1394753017, -52237359], [-1057733278, 37630404], [917086346, 51044490], [434448786, -78139068], [3956875713, 275175], [461471400, 77412426], [-1433355790, 31267530], [-314927158, -79268328], [-4011215271, -76663305], [-7019564034, 20662404], [-873566784, 44070600], [-388427326, -129072888], [2389745120, 38877120], [-2801207896, 85982526], [-7024795464, -30094134], [-3332371021, -36766251], [5172995252, -19634076], [-1462161504, 151261194], [-2676989119, -137990313], [-2130330930, -17557806], [1410595932, -157546830], [749305506, -194784030], [2715028841, 120293001], [6429790262, 142009308], [-6672308013, 16177575], [5475986292, 66168144], [14279735939, 34195293], [2238333156, 162514842], [9429070328, 93678606], [-5985329322, 174086850], [-4946173750, 161479062], [874857221, -296061867], [-5979306226, -74716362], [-3642260124, 63703332], [-7499966296, 80903592], [-1347007408, 14867622], [-11266700424, -99031782], [-4444330492, 122514678], [11074164969, -65155239], [-11843876065, 84558897], [6139436919, 129914715], [7329829656, -211018710], [10090767575, -145469727], [27044161542, -1682856], [-7740238144, -58297176], [-14776464816, 117655860], [8828641157, -331891083], [3027431946, -189132570], [11521615847, -110580525], [21229008864, 211890930], [-20286754915, 232112403], [3604580268, -420926268], [-26590847800, -25562250], [7919434782, 15314820], [5215013456, 348564636], [-24434792718, 92500782], [5890157384, 52689420], [12890969580, 352763124], [-33264357568, -30526776], [-19928444256, -64123638], [-5067179026, 127095516], [24849508509, -131210547], [24541389450, -83987526], [-10760807502, 517776504], [7706420216, 268750944], [-43369383981, -195575403], [17159523534, -380488332], [2214845178, 579420774], [13601142536, -205909704], [23853254705, -172041327]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_28_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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