
// Make newform 35.10.a.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_35_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_35_10_a_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_35_10_a_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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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_35_a();"
function MakeCharacter_35_a()
    N := 35;
    order := 1;
    char_gens := [22, 31];
    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_35_a_Hecke(Kf)
    return MakeCharacter_35_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 := [[-12, 1], [-87, 54], [625, 0], [2401, 0], [9283, 9124], [-25545, -18334], [-186955, -15186], [-71638, 31138], [-249454, -821442], [-5788777, -296772], [-1976880, -2191070], [-1602706, 3997070], [529496, 10352502], [7974090, -9725678], [32750645, -9479722], [-12557344, -5256968], [-58079604, 39092800], [-22344272, 15794106], [59046248, 76121736], [-147082912, -76576000], [-28709666, 17548324], [-346426427, 28471816], [-270339964, 92242900], [-389521852, -97352322], [-1336519703, 45681470], [967885202, 75714126], [328339569, 583281894], [620734954, -160126796], [30551389, -373335408], [2065457314, -279353630], [-3382104332, 169252184], [1226814230, 291651282], [3148552468, 37771082], [-3715671486, -1609407672], [-3345447486, 1561545484], [5176725725, -1132675452], [-6556607222, 686027176], [5261938018, 354724352], [-2646589855, -1262230098], [2106015189, 2427523834], [4076158060, 4789949920], [-3115726232, 1675215320], [17240556691, -205231476], [11101554148, 4607705634], [14280663988, -6427281502], [-23147563420, 1555173444], [8620049653, -3827193976], [-37789150183, 3979868954], [4505043485, 25916897738], [22689592200, 9112540118], [-19353603976, -1587208632], [51615583737, 3879876500], [-50320226386, -10373358274], [-77005767578, 7972924592], [-92154411766, 13656575348], [-45468139198, -4481060072], [27107432514, 6940439668], [16771022424, 3550972970], [-20063449958, 46885452004], [-7548258853, -13621651676], [-4900385805, 29807186262], [-39128052791, -36110890382], [-89148090117, 11778002542], [165288200986, -39823576670], [-64381584277, -66069987882], [57500970686, -61694891188], [-312836161388, 21714106720], [198510502818, -48566868008], [-266182970938, 34476883578], [-111221178306, -77767918982], [21155247577, 126361605730], [194903786848, -125525781080], [190816609725, 114204942158], [210486867828, -98138258874], [357816399580, 20383808992], [211112910932, -199081897644], [-215093835143, -15898235912], [93547654317, 226553439054], [175560819857, 223705525296], [-408426770550, -177740595172], [330491735688, 57847577624], [-282146632259, 95682891972], [-689971212337, -89294516080], [649163644110, 130576615736], [48896646582, -296367249104], [239924719010, 292663223994], [-261617463169, 91323022260], [-866848178372, 57877339582], [-462453167104, -494787756032], [487929417984, -210321581258], [283208040663, 46241010046], [-143828331186, 20652890978], [665180295414, -60242405728], [24607533809, 384321898244], [242219260231, 203702351116], [-23775063497, 119203738998], [-307808904750, -253757568376], [-2144177153350, -369583421050], [1959612585396, -359176472728], [1046164106055, -680513206580], [-524460584976, 346721604194], [-266871752416, 674110124392], [918596031028, -170569963280], [-24711140198, 631993715504], [-1575807296596, 641006181588], [-429755800857, -1163558867666], [-715952545832, 24669729564], [-2116732858857, -1039801714994], [-243823800809, -76991337760], [-3063815953590, -1150529152232], [161991302871, -570902281746], [476360680514, 256283324648], [3329461583406, -68593621484], [-5934195981970, 269733472038], [-2871695258249, -1238007030300], [-1460629523198, -1513602706800], [3306453727953, -1375884327626], [2684439178400, -1588723145428], [446505535362, 704453870850], [4907302133359, 891328604536], [-4351744883496, -705999500972], [-1577613354468, 1679193342906], [422151025527, -970344414602], [-1141387827568, 1742231200982], [-3534707766188, -767426842628], [5260959622147, 350245106652], [-1627735959313, -2259992714624], [-645949611866, 705680919630], [-9163203434256, -1985058617748], [-10096026386133, 1200265724322], [-13610252900757, -104360338028], [5170802316160, -3044212889724], [4385342704629, 2014193914688], [1435091275808, -4138496806516], [824880989950, -1425980397526], [-251753723486, 5475363956712], [558342620455, -499407533942], [-4356261393011, 3042830312726], [15329267478517, 1727608102066], [-6824617096791, 58973802752], [-10396602895026, 368175142740], [5869368607697, 3639379047020], [11582622598800, -1984213804682], [5404608398198, 834255932576], [-6065000756176, 696201184198], [7033798565882, -2328876521238], [15469452878922, 4181597967328], [11963772947654, -1516058946264], [94544976700, -5943836106448], [-22123599652156, -2276151599354], [7672499158002, -5685011042286], [-4299832673648, -5540040427144], [-12433440055508, -3965571684722], [15267855027856, -6755149982208], [-27026453963838, 1354853048918], [-8263131838992, 8958145855092], [153246342841, 5223138012028], [-5351666959400, 2924839524508], [-23028771468831, -4373733292886], [-15651641380440, -10987352853846], [7249349071836, -4411406287450], [-12996922434196, -4102909156278], [8851899932846, 1256633438852], [-1337829504500, 2347971403274], [-10395707059082, -1455718589670], [-17451455562793, -6612150525930], [34162888328816, 5392877499808], [-18763509430711, -4097221849062]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_35_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_35_10_a_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_35_10_a_b(:prec:=2)
    chi := MakeCharacter_35_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_35_10_a_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_35_10_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_35_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![136, 24, 1]>],Snew);
    return Vf;
end function;