
// Make newform 192.12.a.i in Magma, downloaded from the LMFDB on 10 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_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_192_12_a_i();".
// 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_192_12_a_i();".
// 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_192_a();"
function MakeCharacter_192_a()
    N := 192;
    order := 1;
    char_gens := [127, 133, 65];
    v := [1, 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_192_a_Hecke(Kf)
    return MakeCharacter_192_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 := 12;
    raw_aps := [[0], [-243], [7130], [19536], [-196148], [-361414], [-130942], [18516692], [-21560872], [-191663742], [-207933800], [200784930], [-1435256598], [712703116], [496082400], [3350114330], [4583222956], [-3427501702], [17079378356], [7915078504], [31559658778], [-41023578808], [-19974672172], [-10640163606], [6441105794], [-106774096950], [27903788864], [-149670449028], [-205730420806], [603547314], [-694981202776], [501508814132], [396826788330], [-587790113604], [-549939471062], [-10946743616], [1986667735802], [508774087812], [1665826013784], [-2938490355774], [848881575972], [-5030140419486], [1407959465088], [-194985229822], [-5161396591542], [1020778049792], [9121661601604], [468107560808], [-13219590088572], [847551401906], [-17763725248358], [-11063299622480], [-13145153010510], [24902912991548], [-19057205544958], [-25811337229384], [16011398330674], [21430636765816], [-22564396253758], [14564295518282], [-24349544715700], [432740298954], [-58935552427740], [-12935931986712], [-25694933772822], [-13366523664126], [-6252445138084], [60917046728754], [38568500255196], [-34885308942822], [96756949175042], [-164649865702584], [-119182534162552], [161182649445586], [133387933161404], [63815765511168], [38590856281562], [26431703015242], [45935379116322], [42388976175210], [-441929193640956], [310369233601426], [-30655824660416], [-206582778277934], [197201448831024], [-198873825987652], [687389329278418], [389942474142650], [-708640257481438], [600543029594104], [-29527723755852], [-1009613295634928], [821836599923888], [-864714104977284], [607789013944740], [490521850647288], [1074786451056642], [-82550981625526], [-687128482898612], [-1399335996293910], [1412572621637540], [-1026863788519774], [-1088460062776652], [-1959001364723558], [1583270220851916], [269377946699138], [-720364190470628], [-1271920905164462], [-483468690669384], [3681746903477770], [2302790259001096], [-123428342219198], [-2941672129069830], [-3624051076905380], [-1122938803785760], [3607336842539218], [-4134363294367932], [-5007650804978456], [5806752415253058], [3093360976450020], [399503555567698], [-2161110393186590], [-4726220175508390], [-4379112415062260], [7378711565027348], [-2972019018988542], [3844200134134546], [-3490142102416960], [-1264766846338560], [7506785945405194], [7206500875334900], [1394256951879800], [7663851876949992], [-2129200503550334], [244002927043898], [7872769977752066], [11213748259644234], [13440767759788276], [16439752001009810], [13707404002315082], [-4588249879145588], [-10392054042270150], [-5907879809906432], [6405383528186252], [6316958173600586], [-10965221390230776], [-3398963250918830], [10536989679404538], [-12924959453054628], [14559787243205984], [6575484464453802], [-21745705506853102], [1892977338148244], [-20357857288988216], [-20816908116852404], [-1567400213276848], [1457148292479776], [-17007351418114414], [-37152842100145158], [-20913641217674046], [35369853562586148], [14576079098507994], [-15720192673569632], [13497967987395180], [-3809048435941086], [-54234446829471192], [-12002995695992968], [-2900117970014206], [30454258331165810], [-492784979366806], [1710101393537100], [-21253001277761382], [31230751422707800], [17570056116269722], [46896072270096232], [-22306864060967350], [-57938453644081588], [-21827702036417670], [-45704812083373888], [7903316722784458], [-1312195692733736], [-23419025394596092], [-79517874896583342], [-26606378514853158], [-61003264461204432], [20987508274757130], [53322415228960202], [107385413588960724], [-53753344461910886], [98140990846854912], [-63792386868236990], [80802659014064316], [6062883541565380], [77072344736045714], [127951128966528084], [147646227496427066], [47479913962414546], [118881597961622186], [-50668171529876734], [168858451841280408], [-52705942822726814], [159286097251911160], [115718753588690434], [17086668655674850], [136877865416232012], [192014901240391938], [-110642343198261656], [197382715476762564], [68604335239058234], [-70656945515217332], [-112067772352558158], [-62165020136127990], [-242738703075724912], [-102069649709301940], [-216860962978470104], [-1438321797911878], [-239141407950673496], [-76253185843938110], [-4520370816495576], [104297005427754162], [8926491024274834], [231747456465640368], [-183810732355260366], [-413839933407947912], [-105497839797636204], [63676679489366866], [-304877252151766806], [-41899665407335344], [143553390079911456], [-145129835055549380], [-150495267766920582], [-30778102235839436], [332752973117855176], [507049304435093914], [12703232760064908], [-171995263982343584], [83313780102578834], [-410977131890479126], [478623027877766396], [220750034377417736], [-580762060118819340], [446900942321992460], [307708058259210512], [403692408064480874], [-458685093372678990], [324517416368642680], [28618290612355544], [-702804795698535756], [-7700427763919300], [-100478834532619472], [-157993676436422454], [421315614560719266], [327722344024647784], [-690405104924463974], [-105927635875331214], [-446943293349279132], [347453954168877826], [280291839306149356], [-65922838508639190], [-437612928376606166], [-849694850496014680], [473534766640820340], [-443137988104700878], [263648301843450810], [-187610618323080494], [-205612991497668748], [-67995901479973406], [635725896134251850], [190710376540334300], [738472249748558362], [-988414524466922998], [809768167732891172], [464979465495356554], [254441182427635064], [907514065829981266], [303425870653320688], [61397514062456604], [1069472350672830394], [-770259514168606694], [420989226349155364], [1348446843926827472], [1063157420803693760], [-1422004935178087912], [-174046293728734622], [-410133570154617172], [-863137791468616240], [1345454288593382930], [90987133268519946], [1309955219532057664], [-706793767699911934], [236580045738622370], [736371882456448932], [-2003023276414197878], [1141097021454498492], [1031087532733624362], [181890633667335986], [471064918521613192], [300418357989764058], [-70974406377873252], [44411174730039524], [-858494071024389286], [1240399847303559682], [1625393688262897384], [-2047657902750237116], [2182142721584216508], [-804371453543260414], [-1486234961924583252], [1871987139669592474], [733523019828754264], [-2337860752216102814], [330503137350497712], [-1682701557847099974], [-2017046203027725454], [1589229855350146660], [2252972960689599992], [-2069681534974620358], [1322610992892922308], [2730894631018893456], [750129912101750402], [-2548562698846282350], [324393934073800516], [1815022469825652874], [-1501190702500456382], [2042477524084040792], [2326108471151185834], [1412947114192569138], [-708243478562347452], [-816517494524245188], [4403785198255388384], [2160642075839829882], [1744759317643370426], [1170250451925119442], [-485262799798279032], [3103055531138599572], [-3441159423956067012], [-2952237061889356740], [1660598710199987450], [3435299156938332354], [-3411802245409960006], [3337452158096155896], [1004341112159531762], [-1951914175114480422], [-3381383451996659286], [2091935764405745856], [4427701188474459746], [2319430017272484580], [-1109515849732153998], [2975107024851245116], [-1131267548669872416], [-5894789451577814534], [5325372950007937380], [5845426213106538938], [3446654042380804178], [-3130492157540237928], [3244684916667670354], [740363015008042826], [1657332789850043264], [-7209777699413899972], [-4667880667978828574], [388848802424648040], [6968402372163977410], [-4875885056073978630], [4521638550181639344], [1053878084051750780], [-1626360040259112908], [2959587614810089338], [5304952186641823890], [2439955425711490928], [-4123826344185004022], [-7691184194588535484], [3682245722166012972], [-5277089601847665968], [6935950250243875610], [-6409967828603860768], [-2614637826066318806], [-4660793806590177900], [4590454374348934176], [5503984663811363170], [1948391460358092354], [-71639092935884470], [7837201891944570066], [10253835044547447338], [-5186863988118412032], [-3001290850973616990], [5363537801916796900], [6611396877881781720], [-92704118780807448], [1689787559992290850], [-3234974022894196436], [-6344776334388875280], [-10095448621359421118], [-9499111615146285958], [7678754035013620668], [-8888680964823907308], [-7119221237726771256], [-6269456987058854102], [12570635812814224968], [1103383022657878506], [903343406206403948], [-11640895655042455606], [-3606273777376318022], [-12744096805120917966], [-13920591673731042472], [9392782912541591354], [-10739390455731698422], [15206999985562260944], [-7243792147432475974], [8834444936603717442], [9736113923181166388], [-8704940143119232572], [4238502894779540594], [-6246570755672497846], [677933454759453212], [11183609768296850884], [-13571828765412147078], [4207129776957599954], [-12434477951220648576], [3194872971843626800], [6177204661623851298], [-13037804629988288264], [5125634151168220018], [-8815064613987923486], [-8055868339719656528], [-5716461640546380580], [-12324570756916065638], [-8647963257917413838], [616068083235866740], [-11372138987104077078], [19092814988510587356], [-4490362328520663496]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_192_12_a_i();".
// 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_192_12_a_i(:prec:=1)
    chi := MakeCharacter_192_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_192_12_a_i();".
// 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_192_12_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_192_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<5,R![-7130, 1]>,<7,R![-19536, 1]>],Snew);
    return Vf;
end function;