
// Make newform 350.10.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_350_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_350_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_350_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_350_a();"
function MakeCharacter_350_a()
    N := 350;
    order := 1;
    char_gens := [127, 101];
    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_350_a_Hecke(Kf)
    return MakeCharacter_350_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 := [[16], [6], [0], [2401], [-54152], [113172], [-6262], [257078], [266000], [1574714], [-4637484], [11946238], [21909126], [-27520592], [-52927836], [-16221222], [-140509618], [-202963560], [-153734572], [279655936], [404022830], [-130689816], [-420134014], [-469542390], [872501690], [-1209014800], [-690562580], [-179499372], [-1603608446], [-1427850374], [2358727632], [601665350], [5160087406], [-7143563462], [9104242062], [-289431992], [-13906779980], [-16623248120], [15801939652], [-3231248996], [-24140781132], [-3893317308], [-25898783016], [-15936730670], [3346846514], [-13426079236], [30170192972], [-53502952376], [40270393242], [19024711756], [36774761126], [6561095208], [-89681767450], [5337028890], [83557545870], [-108634879584], [141400522724], [-90835285488], [26507506282], [-186967895078], [5334125954], [-76543346856], [75194370218], [215133949112], [-95907461110], [-170586441702], [-123991685200], [72933538482], [155720400624], [108728480308], [-325585100370], [-227549694616], [421992952168], [-383283068014], [-121461549848], [397720958420], [67546230866], [-124655655588], [351195628398], [-38195614450], [215267665362], [1199326384470], [791117369544], [1154506168306], [-212728243464], [64829990396], [-1080312092590], [64672532042], [429253768988], [-1618833928912], [-327321126494], [284811101908], [714775787776], [1015055900868], [1334123745772], [568444757664], [357172977012], [2179724538534], [1570808102938], [2245436018118], [386061536160], [795101893786], [2136670256582], [2174610946758], [995075151576], [-4305882620962], [-5057615223346], [2802999830598], [3209070700824], [749501715818], [1740970575744], [4039771442622], [2933670336122], [-5776913813138], [3999849053072], [4683278788270], [1548770030710], [8144929554756], [2889250483566], [5202547085824], [2889729962440], [-9463624101818], [6522678603900], [-5372402067012], [2015629916966], [-10652253635950], [3461869130642], [-9620251283100], [3134792007356], [-6477745976040], [-1125100195080], [-1652656488024], [6032986696104], [8027976887166], [-6519228061394], [-13424998659842], [-7859342513192], [1477202904306], [6473266304220], [-15363091195834], [-12905612946746], [893771205094], [22984443440216], [2756179886244], [-3159246800024], [19240349793604], [26080432657540], [-21917671626510], [-3555880267366], [-22208405716232], [-3380040244138], [525102522474], [-33397192697588], [9619644405516], [20834077302996], [-13378939342224], [-13835163343064], [-17407270665258], [-1983612512306], [-23353307899336], [-35988225603728], [13766166749942], [3027178177936], [-25318283125746], [-9907290806298], [-24052310333748], [31578178461920], [-9322411318328], [14263087259198], [-2884725357516], [33059610389012], [63527206223212], [-48859046634720], [25430093859654], [24473797766868], [-17681671313038], [-24816375611508], [-55010675923358], [13028254032400], [-6402480802216], [-43522028054808], [35923723318138], [2097787307414], [52232553321622], [14904904659376], [51645393865236], [-89480089593150], [-103155515829830], [-22693217164686], [115121311033980], [56634054390974], [61191765645420], [-92206184370092], [-35481295231796], [-6508818152628], [61669438805294], [56404234466510], [61918168124390], [-48383370624378], [88697040328296], [82236513153726], [33108557731788], [3336160168408], [-112148726039622], [-146670358375146], [214637803224], [-62245200206404], [-77860011210408], [134324592242430], [-77709531468862], [158801039547106], [33101103932000], [100757220234936], [57750870380098], [-73108823885064], [162803130632606], [-150991359519856], [-166370484859010], [-115573014028312], [-203539896278626], [-43966292350934], [93004396959976], [279335906957010], [-71320180447432], [176091803097642], [-235662697687846], [145212824910566], [2321535565256], [290096868090048], [-154633502687928], [77579507369934], [290879291840146], [68003979090352], [-102196708263366], [-66019129933334], [-134043808303104], [93618399158134], [40900573495554], [-120553203687516], [-46788846135808], [-206884852233520], [381165122481062], [-222824221689536], [-176825740906050], [-248642082797962], [-451477923526116], [-88640715019152], [-421876486250378], [-192092543346976], [54946893661968], [376194678887834], [302113251964098], [-340613713087056], [-100196274876374], [62291435312504], [-159452859076988], [-157461541259062], [453218146356558], [5191074106960], [175198987668322], [-436905170698168], [95398073207368], [-94412823557264], [-260853067919752], [-281272675073670], [-436279549321694], [474199703403606], [-53736736794742], [-239927640453532], [-281308696589946], [551441392098756], [-117929446830608], [271265481471486], [26436902830976], [437987122641230], [303055104954864], [202056974431280], [-122487339408810], [185986405609342], [705397982341710], [-140020404602328], [-134436964329240], [843934879258812], [-741663247686376], [-838408206006390], [848278018062928], [867943198689342], [620135344492754], [-813603755186524], [-587539757280270], [-714795573359730], [-410423091831438], [950777794425162], [189178664416646], [644748027945442], [1148442990315012], [706952745884576], [-52297075990548], [416781805682154], [880388828241078], [416334053578898], [-1389207586783602], [921873600893440], [-599762667572664], [-865222522299712], [37479904864486], [-386142211928192], [-347059092784240], [-68255169937808], [-4193118105350], [1091452472422584], [777056545346402], [-1126906478666038], [347484754644760], [608674417883392], [-956502585318742], [634008776988186], [614977557172352], [1508806678436902], [256739264369250], [-1664973174523486], [-1333710532481266], [903303894317064], [943812640743560], [-541923880117430], [381745164380942], [-1891066585228192], [-1200734633427862], [352387613798288], [-127558076212618], [-1126473846417898], [796525802509070], [-2002146418790196], [-304343316244066], [-1933536674873828], [843929025107914], [-910230172800702], [934935661535086], [-100538900685670], [828668710943876], [-678761570984078], [806425061531754], [1212339751164036], [-1509171895564320], [-775507636538274], [203715969556944], [-1529688475794748], [-2720467245892136], [413439321479544], [2371678941044232], [2415033728584106], [-271783936068218], [-1839119452144866], [-1238287313742444], [-381318358417682], [167929516696862], [-2591758001485420], [64370263522110], [1608536711991278], [-1353034726826656], [-450595348935262], [964529707315570], [-766723349075408], [2176725515140828], [-1422138196113046], [-1106425329897014], [328192119522876], [-3813194702201184], [2487580865681446], [-3552922642405244], [852353782817290], [-2437902085443216], [3744807078918782], [1524247607003176], [-34926259424902], [-2828107623724890], [534236985186424], [3810897620961830], [-658507600830842], [-880920701574254], [-2557413305215500], [-1191760172348486], [3482001191940152], [-2178465348391698], [-1048692869234486], [1695650955373912], [-1976106051638680], [-612510923880112], [3470278028577404], [2940669841791908], [3171385928292350], [-130954214018304], [213343417858300], [-801566036072738], [5159139647145560], [-57839126836962], [2055990616910116], [1474951481353462], [-2773486783295652], [4510542356152642], [-1272536211112408], [-594878615400690], [-4074862702051408], [1411465265072050], [2687729491177932], [-3701143939666924], [19897487976482], [-1183288921331970], [1277760131430238], [4862450499914650], [-577209929158426], [-5908275576074410], [-2149110131610232], [-2696642178205188], [750989681580790], [1862456457967228], [-3311903642813912], [-6095263403343652], [1935247162771578], [-5179177649115008], [1102018653156178], [-2051960324974952], [6341202945364208], [4883888859074562], [-1020246748177766], [-4175864501393360], [-935098543273712], [-6089086610938518], [7242371384233218], [-396986761016276]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_350_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_350_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_350_10_a_c(:prec:=1)
    chi := MakeCharacter_350_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(2999) - 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_350_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_350_10_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-6, 1]>],Snew);
    return Vf;
end function;