
// Make newform 112.6.a.h in Magma, downloaded from the LMFDB on 01 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_112_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_112_6_a_h();".
// 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_112_6_a_h();".
// 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 := [-14, -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_112_a();"
function MakeCharacter_112_a()
    N := 112;
    order := 1;
    char_gens := [15, 85, 17];
    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_112_a_Hecke( : Kf := Kf)
    return MakeCharacter_112_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 := 6;
    raw_aps := [[0, 0], [3, 3], [-9, 5], [-49, 0], [-198, 62], [-175, 63], [900, -38], [1633, 9], [-1044, -284], [3348, 126], [10, -270], [3116, 270], [-3024, -546], [1510, 2394], [-5850, -1874], [4734, -104], [21969, 1025], [-32377, -2403], [-12392, 972], [-48708, 2100], [8726, -2628], [-25628, -7452], [-58779, -7875], [42138, -11104], [10388, 4410], [-77913, 13717], [-25226, 5238], [65484, -10952], [-98656, 1674], [47196, 11970], [101008, -4032], [261585, -11639], [192222, -25724], [-191849, -23121], [14274, 16748], [-40280, -1296], [216857, -40617], [460438, 2754], [-96390, 24234], [20781, -10453], [-60300, 35720], [-113407, 51975], [254484, 25252], [-128728, -79218], [-48438, -41916], [157930, -59238], [-542768, -27468], [-779828, 32508], [457425, -6199], [-44515, 142371], [325746, -58936], [212868, 5460], [514364, 118962], [1622943, 6951], [758826, -4216], [-119268, 45716], [1902429, -12869], [50416, 220320], [74678, 285552], [344682, 175728], [896185, -66231], [816291, -231231], [-474047, -179991], [247824, 271400], [-1237168, -289746], [2992914, -6604], [614998, -209430], [-1139248, 168966], [366462, -95614], [1326269, -194229], [3006378, 62920], [-1421568, -43880], [790660, 129636], [-2977918, -156852], [-2103110, 196686], [3768102, 45502], [2314692, 305446], [3165293, 252747], [-26928, -192538], [-3799540, -97254], [68607, -23793], [2275646, -488376], [1929492, -398140], [1922480, -295722], [-2724272, -391032], [-1037520, -400292], [-2177334, -634200], [-1151968, 390366], [-2368359, 33831], [1511704, -367416], [1299573, 303277], [-81414, 330914], [989644, 556884], [1235736, -877548], [2324944, 128628], [3396708, 960876], [-6674355, 520763], [-2104560, 937150], [-5735819, 439749], [6325250, -775260], [683674, -1102122], [-1471734, -399524], [7019883, -643045], [-6437808, -648322], [3930946, -408906], [-3806638, 207792], [-5026077, -939477], [1266102, 892148], [-12792096, -238120], [3603530, -1625904], [3986656, 1234368], [-3283684, 746334], [9635544, -42], [-3656615, 1128249], [9841564, -429660], [7005672, 986350], [9830443, 747243], [-17723430, 140234], [-7431192, -783310], [-7237134, 1489278], [202619, 1403721], [-63922, 1453788], [-10905687, -353761], [-3585528, 2153444], [-2374727, -628479], [-12849408, 375354], [-2579548, -829818], [4530906, -1471790], [-18715466, -16506], [11081663, -1836459], [24595702, 39906], [-152280, 531552], [8458036, -2011356], [18394532, 448182], [-11392740, -1896022], [423584, -1835946], [9827955, 2745649], [13860829, -1560843], [872613, -908397], [452664, 2547574], [253141, -1159515], [-5320818, 524360], [6095080, -627264], [5225148, -2026248], [-9930721, 568341], [10467198, 154686], [12723053, 2092419], [12313116, -2949782], [-685025, 2068551], [-32094756, -847508], [21204548, -1563138], [1685502, -77028], [-13921868, 775656], [7513326, 990334], [-10177988, 801576], [-7128648, -4410504], [-12957176, -1178496], [7189740, 462866], [-29524474, -1375668], [6709455, -713387], [23614506, 532150], [5768226, -4842264], [-2158844, -101556], [-23484375, 2742217], [-24279498, 4207540], [16037262, -4505890], [-26594696, -1415016], [45670811, 406809], [11590280, -2314242], [1286325, 4343435], [28580760, 3923492], [3574025, 5247207], [-17555364, 3296212], [6821810, -2677464], [-5378174, 1984986], [25593246, -1636236], [30483556, 3026016], [17097516, -559250], [33573988, -4809924], [-34332097, -641979], [6132916, -5540364], [-5032125, 6043107], [-21472960, -4400046], [34559586, 2569208], [-17970696, 977528], [-15362343, -7511969], [1107038, 6109776], [9095761, 482121], [-3904354, 148068], [46319598, 4250438], [17324690, -6281424], [-25503984, 1983660], [27873124, 7293240], [39126393, 650039], [20265516, -1372624], [30977622, 6466492], [-9916576, -2331594], [-17250988, 2470878], [51279102, 2477580], [14375160, -3613664], [-6274602, 7395256], [-84543410, 1552950], [32514011, 4109481], [-36862402, 2417580], [22686237, 257901], [-48012849, 1709509], [11935870, 1486998], [-11695986, 2250202], [30781620, 6350946], [-14885189, 2075139], [61237352, -5585058], [5670567, -1171611], [69460648, -79632], [-54193095, 1154953], [30516552, -7687600], [-51822724, -9267750], [26697256, 11066040], [37239192, 2500894], [21433824, 12488920], [-37466280, -8235822], [399680, 5447250], [-15740312, -318528], [49772682, 7314920], [-25929212, -11987532], [113122737, 45465], [82645040, -3988782], [68020146, -542824], [31188204, -1933492], [25939468, 1111140], [-10128798, -11617946], [57066536, -2135790], [37934599, -7835769], [-61521728, -741888], [-12365694, -16581704], [-104236643, 3476781], [-9182520, -5333416], [25466852, -2951622], [-96767334, 9339236], [74212416, -7187124], [111436668, 1379700], [70413642, -1868938], [89927581, 3944061], [-11111636, -11978460], [91307126, 3269592], [85589406, 4114908], [44034930, -10581422], [129877048, 1718136], [-134148375, -2170207], [-112606706, -2671614], [30843720, -18412296], [53421314, -10455228], [28200114, -7763632], [28002420, 8050412], [-15283870, -11633832], [40582791, -12189299], [15684444, 18675184], [15744584, -18142326], [-31722485, -18512253], [94170951, 13683957], [-89758300, 4673394], [557380, 10635876], [-70870410, 5199138], [16453511, -11269611], [-28160209, -12955131], [146531844, 9381418], [-19835177, -10771353], [-56855790, -15325212], [66065706, 1556688], [-66954932, 4398408], [182464200, 3130], [67498877, -8396901], [127262266, 4682502], [-95918602, -1078164], [134964136, -13251816], [-138467854, -8999424], [-110858564, 10535940], [-129402162, -11251118], [-63535414, -12207348], [87176468, -17913150], [-45362259, -25589723], [-47816388, 4188908], [-413072, -15966504], [42133014, 10536582], [76320587, 8488809], [47171917, -2803491], [-30169224, 9917176], [-77703190, 20928888], [-140163966, 337932], [5538550, 16650630], [-21243222, -14711928], [-58065138, -20627984], [-23039811, -6106027], [-96255144, 7119494], [103479957, 18251205], [-97067626, 9933336], [-25387659, 8570083], [-46787648, -13055040], [90915993, 27104511], [150823143, -1054961], [105517195, 1291563], [53608868, -16711326], [39761352, 26511986], [30517744, 5388480], [-220018626, 8575770], [66697462, 2595834], [181104254, 7563276], [-94172850, 15900002], [-130237093, 3926097], [9204012, -5743196], [160143782, 16605936], [-127800468, -2011700], [52310484, -40944602], [-164938122, 11934500], [13309966, -9202950], [-216421956, -5545932], [123254786, -25022952], [161749035, -4693605], [-69348456, -21104392], [-259607698, 4911228], [-127591686, -14496888], [-167959313, 6269679], [159980150, 29593260], [-20521809, 29095941], [241203268, 9981972], [-35105040, 23937166], [186012272, -12997098], [142910746, 3015414], [120799093, -24626187], [9428544, 19071664], [-218206224, -18497598], [-128859646, 13759092], [-45308016, 26152330], [-169155770, 2804382], [188238375, -13693033], [-232676012, -18843840], [19827045, 8483013], [-40350952, -29348046], [-166758678, -2372344], [215270762, -15261120], [203344486, -3927474], [-195062782, 9631980], [-66139848, 10360518], [208374201, 11939151], [-253272308, -22791132], [85408632, -51223630], [231187122, -36496530], [302635001, 12650607], [-154741742, 38557494], [68155668, 42730548], [311915763, 18508481], [242172667, 1651995], [-8797822, 20880504], [120157830, 17831016], [50198158, -42122826], [-162231166, -17341236], [64329174, -51561972], [152398458, -17586014], [-385807167, 12085601], [17015202, -7047568], [-326439612, 13057212], [-158685406, -44422308], [-244569978, 4204268], [287483544, -9900808], [104478156, 23240584], [2060089, 52595217], [-152611024, -36940914], [147541149, -38354085], [352050172, 11333412], [-210447424, 33353838], [-19619532, 38831960], [34940383, -45774153], [-367481304, -10813352], [-407598966, 16702644], [78944344, 59453712], [12189458, 27784404], [-318999447, 12966257], [-128933100, 25134228], [127499726, 35805564], [-252148500, -14013022], [-244528564, -1330182], [329519565, -18904133], [-485529336, 25607526], [235804168, -8664768], [-156182598, 37262968], [-187698245, -7940709], [-105973200, 5786840], [-15298124, -47504556], [-229848769, 17459901], [171933376, 1697580], [-4238514, -57240666], [454352096, 31797990], [277580511, 33625037], [353956356, 26180720], [-80713841, 59024079], [-102743712, -23248376], [-99255826, -62086716], [-130905758, -57113046], [218945160, 5902134], [30836020, 42319872], [529772868, 28448470], [42446927, 36948357], [-237976038, -9261640], [211162552, 39058344], [139117788, -87280342], [509244957, 14193379], [313109638, 28784646], [-647463514, 13335624], [235912392, 68009214], [182151343, 75182607], [-154039149, -29007053], [-108474634, 5739732], [-353839464, 42810842], [416392002, -13243818], [-453363296, -45763596], [28658282, 95955552], [109310409, 33705719], [-251854884, 27488044], [-340604450, 21775806], [368860716, 39368322], [348505236, 52168636], [383086944, -20836262], [-278355373, 37695537], [-161534088, -82084632], [658506051, 972699], [609497840, -26873154], [-499324437, 33063937], [-135284598, -61233386], [-296858574, 873432], [-214732445, -45108837], [514948122, 29763674]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_112_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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