
// Make newform 7.10.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7_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_7_10_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_7_10_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 := [-48, -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_7_a();"
function MakeCharacter_7_a()
    N := 7;
    order := 1;
    char_gens := [3];
    v := [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_7_a_Hecke(Kf)
    return MakeCharacter_7_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+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 := 10;
    raw_aps := [[-3, -1], [-43, 11], [-1119, -95], [-2401, 0], [17658, -3326], [-13265, 10899], [-231960, 9426], [-462713, -1887], [389064, -38088], [-5001792, -94682], [1233630, -161430], [15367776, -248130], [-9551724, -860818], [2032550, 1048278], [-41097510, 1033182], [-27594906, 4685568], [-3534609, 1563825], [22158193, -3395319], [-120960668, -7026216], [103246908, 15075900], [-249576594, -2840484], [234267548, 16873716], [222011979, -21562275], [318133698, 1406968], [-816358032, 5731530], [78061857, 8592161], [-422511214, -61327074], [1526117856, 21108436], [732383964, -69376518], [-1472162844, -3431330], [540465732, 264103476], [-1709090865, -173634983], [-2176261818, 64556148], [527327409, -327568857], [683383194, -104457396], [-6100253260, -269734452], [2528073127, 396826539], [66984502, -657945282], [-6894860490, -139633382], [5837088531, 148398911], [-7418740920, 865035380], [-5243144417, 329110635], [-4194674844, 1026691084], [-7475763088, -886223934], [8136683802, -1359550388], [7498315950, -653514606], [-5030983172, 3559896144], [1762259548, 1606072356], [-19788700905, 1412070657], [-14714662045, 254594343], [-22135598334, 2064465192], [14479321992, -1696275840], [22183852424, -5457922494], [58388808177, -1376551673], [-57648416454, 3594800072], [12213192828, 1754525212], [-144497389821, -1510237137], [94515063784, -2864166120], [-23585177402, -137972304], [-8366784438, -1158875536], [55988777935, 9209960673], [156757051941, -1217680723], [52237638607, -12587434167], [-115506833184, -2059436760], [-163641040828, -7998029778], [70322466834, -13925678292], [62947577942, 19744379430], [-325813073528, 2999371578], [286321072398, -10620496258], [-24237272381, -9236918817], [-161130869502, 20569389040], [-136744473372, 4304973980], [-331062233580, -7597265028], [-18934358278, 13351119564], [225272021970, 13312373802], [151420639098, 39571543854], [212123972232, 45681550998], [763142867523, 8072323311], [-278999917248, 2268071826], [102338284880, -14193390942], [279009757593, 51411196599], [90363765326, 21447904632], [535039362288, -23505202680], [-98715317540, -17603442066], [245863164072, 25409045616], [-221003199420, -6058374624], [-262434206214, 36223754280], [389034407752, -10999361262], [-941016808809, -16568663797], [-496533423104, -93058182672], [-1028967605133, 46627177509], [-270087259506, -103752509542], [594255124936, 10398318888], [1885752228684, -26243487256], [-830615156444, -60938619624], [1013540399172, -51842000028], [-948760872765, -138652435681], [1141277683020, 39737751750], [1190321356939, -17409218187], [1889056740890, 51526182420], [1137637912546, 63208646466], [-2704225908534, -24309217052], [907561296837, 239810855995], [-992211323568, 81075063754], [-451101072166, 21586609218], [1256353422442, -223370283384], [-2588933695803, -27955471229], [-887553769458, 140254776084], [-2680184684544, -133230629400], [2284352728770, -240435445992], [-1859600192176, -100113636144], [1548615952216, -290468737098], [-3716695656336, -25159326486], [-4958288590865, 51178327953], [187227006836, 90270472740], [-913256263608, 498332741850], [4575203031077, -178838815029], [712101761790, -148356985822], [-2143652996292, -377132751990], [-729583749606, 293183089626], [1507096438189, 478028383893], [-1083004779722, -397412261316], [-771766147977, 283246099587], [4235712637188, 260792520288], [2957217221687, 18573326817], [-5931473653068, -10539094398], [-5262886137288, -110586981114], [7094363684934, -448526250750], [-5872910734054, -250092222282], [-1633161777687, -688958444367], [-3380697448362, -84721437858], [1239687620460, 167751356724], [-1346387112416, -74626180392], [3205072296512, 126807875166], [3943693810680, 447891897834], [3209755635044, -557493276858], [1936770434325, -401971712803], [-413907531269, -163177569411], [-14160699121317, 307873323079], [2949281727984, 956723771562], [-23017154455981, 11687459805], [13797919389342, 200975094200], [16444015604160, -472764507048], [1717652013072, -350645507436], [3495019667369, 1204810979313], [-14473555388838, -677920378058], [13556330423363, 234046300887], [-11680768712544, 359763055474], [-1606813171375, 1587980797287], [-3053860588404, -1129870051836], [21219405023128, -67913676594], [-20237282796738, -109703438124], [-25551177455872, -640841021268], [-4952602935006, 786995412878], [-19526891955112, 1224411216972], [30257901767508, 672606548292], [-20655076577824, -1398599716872], [573461687520, -644822367382], [-3681809836194, 433447089516], [-14710717544055, 593976428609], [-5128002757566, -1382353454350], [6183929454306, -264922129192], [9807462646144, 876822550128], [17756023067175, -1931514361431], [14102914903662, 951043273620], [9495999667818, 90556920150], [-5851237631704, -1061978914872], [18791547117181, 305669803317]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7_10_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_7_10_a_a(:prec:=2)
    chi := MakeCharacter_7_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_7_10_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_7_10_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![-184, 6, 1]>],Snew);
    return Vf;
end function;