
// Make newform 21.10.a.c in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_21_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_21_10_a_c();".
// 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_21_10_a_c();".
// 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 := [-86, -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_21_a();"
function MakeCharacter_21_a()
    N := 21;
    order := 1;
    char_gens := [8, 10];
    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_21_a_Hecke(Kf)
    return MakeCharacter_21_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 := [[15, -1], [-81, 0], [564, -70], [2401, 0], [36642, -1718], [70550, -528], [-50892, 14830], [240872, -2892], [-491106, 95690], [-1275462, 142260], [-2467924, -196092], [-8128258, 442296], [24353928, -196590], [3994820, 168744], [42786204, 768164], [13282662, 3803152], [57600480, 1648036], [-71410102, 6373980], [13760696, -5935140], [19035090, -19134282], [-1047658, -7076172], [217548524, 20624004], [132144372, 34502856], [321336888, -11924350], [172680614, 38859852], [-989104344, -3901850], [-22075180, 86932260], [287689146, -73056574], [-159407602, -68354640], [-2980892574, -10125168], [-3572355196, -66737364], [2849017524, 52475480], [3187883838, -134448212], [4682525084, -140749944], [2213129094, 310888976], [-3435006976, 215536680], [1972241114, -286972932], [-69376768, -41261724], [9946470132, -487129980], [474626616, -348785074], [340102542, 585149302], [-5333638930, 151033536], [2101914474, -387977386], [2073424106, 100423800], [29116520550, -443220672], [22937471264, 608344056], [31588930412, 1159117176], [20231597216, -2215561824], [1373151432, -781843196], [-10032868474, -1605617352], [-14001137346, -1856634196], [63111109734, 1135441338], [-28557026530, 1656345636], [28375631928, 2063980284], [-95762863920, 905638034], [88659237126, 104881666], [-40294316436, -86568902], [-27372622876, 307878732], [-135943001530, 2281919184], [100949706558, -3612475044], [78393841112, 6581067660], [34639197624, 3705547446], [33435304136, -9912853356], [-115329634332, -9033890252], [23317890746, 4870415184], [-147093143898, -6965742280], [193080159572, 1739069304], [-63309193126, -3698551368], [-85359138738, -12670251410], [348107127866, 5767055292], [-181810813020, -18445240322], [-151628987766, 18118289102], [84866231552, 11591282256], [128109000326, 26151828720], [-151380942940, -5493739848], [-73315464168, -6802833160], [287700778722, 1767120916], [-267960167350, -28643230116], [-160486949010, -13028136700], [455165222294, 23161170708], [309374556048, 2102350572], [357468200822, -21314339280], [-208207147974, 6397734598], [-398064850678, 1874483832], [-220458834544, 21757503048], [-463210746258, -8020688290], [1286218237266, 19964175600], [-647034326422, -7936550496], [337004494416, 55258615158], [439302627452, 29472191604], [-875595995400, -45290295004], [449592123180, -30249719228], [-2023879360072, 3565444416], [302798481030, -40405101834], [-390332932396, 57235330512], [-1244989027728, 18325198440], [88035035964, -73704686758], [1125549558948, -3608325578], [-1929661078300, 75724719696], [556542833486, -98206008528], [-67649105872, 79711058388], [189175499526, 85748667592], [1750504874736, 99884542108], [2958501666678, 11277945572], [324548727296, 81360090780], [-1995620784982, -14326556040], [1025393423256, -131440163220], [3973231527396, -51375504082], [-1924868260230, -154806195170], [972756904130, 162395661144], [929145163352, -253768562328], [-2049469005778, -88636435704], [1031173034382, -7984935588], [-2343721946524, -43706263824], [-645723789076, -227155678548], [672773523150, -105427662188], [1330666615736, -30947936316], [958469896236, 170358457612], [1343967943794, 234111293516], [-1401742210950, -219186375846], [-4237786175998, -16041557028], [530915287322, 18038018952], [1839337509120, 170225820446], [-6036210794634, 135407886502], [5414966490692, 196082692920], [-7683884686134, -167649264540], [-6614149469290, -229207479264], [-6169210851360, -213047327392], [5324286850388, -454618732812], [-9327703764346, -204908798016], [3934690985792, 301663357092], [-6779182132422, -80139485538], [-5589285419632, 554186615856], [-547519797946, 913815280128], [-7978891790280, 148304444882], [-1929372415846, -822214222632], [3384514523136, 46983077326], [6912696073340, 165587407776], [3907542396600, 157559065086], [15442526768610, -136006139576], [16101504289532, 18506875896], [553731340398, -182408940184], [-3169677788404, 427302578124], [8476517583954, 588276966714], [5713299258998, -432806112336], [-18829539448092, 428837290932], [-18253322106910, 592162543116], [655829092920, 412110791122], [2646723807416, -877544297028], [-11433819795546, 71452515578], [-10243315171690, -339982772472], [-6143802126660, -186198083178], [-1329994213180, 873959524992], [-8582073656844, -180525589132], [9348520895156, 606365935848], [-14580672922854, -821683096122], [-793703178664, 738188525664], [5123457027096, -396002682982], [8049283032122, 267514309488], [-6682294102020, -1381522404710], [3655877845290, 1195496234762], [-21107597641830, 761796324384], [-20097680585572, -1606926559812], [-19524223342308, -157147028296], [23837260530414, 698342106244], [-47602314713976, -540182329952], [3176519261456, -851257805616], [3595512093698, -345883529556]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_21_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_21_10_a_c();".
// 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_21_10_a_c(:prec:=2)
    chi := MakeCharacter_21_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_21_10_a_c();".
// 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_21_10_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_21_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![-120, -30, 1]>],Snew);
    return Vf;
end function;