
// Make newform 10.12.b.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_10_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_10_b_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_10_12_b_a();".
// 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_10_12_b_a();".
// 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 := [6408200, -6762620, 3568321, 198, 2, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [2990639720130, -3161951077723, 4808106038, -3200275588, 842118, 807955], [19324355382560, -20394204345776, -11372932784, -315216, 6014576, -5715200], [-31530915177973145, -16157580597638917, 3127575282762, 509621899488, -14980310918, -4247878015], [-29393614134689930, -16155835619146117, 3079320290922, -412097187072, -13979944358, -4735302175], [12125790194228963, -9651607974962172, 1873448147736, 26667276564, 4096032176, -2690537304]];
    Rf_basisdens := [1, 604523721605, 604523721605, 5440713494445, 5440713494445, 1088142698889];
    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_10_b();"
function MakeCharacter_10_b()
    N := 10;
    order := 2;
    char_gens := [7];
    v := [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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_10_b_Hecke();"
function MakeCharacter_10_b_Hecke(Kf)
    N := 10;
    order := 2;
    char_gens := [7];
    char_values := [[-1, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 12;
    raw_aps := [[0, 0, -1, 0, 0, 0], [0, 1, 3, 0, 0, 0], [88, 1, -63, 0, 0, 1], [-1, -80, -366, 0, 1, 3], [-107146, 26, 26, -48, -30, 26], [-39, -1071, 14217, 0, 39, 117], [-78, 8982, -34738, 0, 78, 234], [-4017594, -366, -366, 1392, -294, -366], [-771, -10566, -484844, 0, 771, 2313], [-42739110, 2484, 2484, -9936, 2484, 2484], [76410748, 5676, 5676, -2976, -14052, 5676], [12077, 546097, -10293663, 0, -12077, -36231], [-27441925, -22723, -22723, 35976, 32193, -22723], [35314, -564469, 18157245, 0, -35314, -105942], [25683, -23832, -54935438, 0, -25683, -77049], [-129273, -2303649, 2542599, 0, 129273, 387819], [2944075010, -152122, -152122, 91728, 364638, -152122], [-836715361, -115683, -115683, 134448, 212601, -115683], [276718, -10748413, -331626195, 0, -276718, -830154], [9465111096, -215904, -215904, 907968, -260256, -215904], [-563408, -7876564, -17959356, 0, 563408, 1690224], [433047348, 1534068, 1534068, -599328, -4002876, 1534068], [1933902, -1064421, -140361035, 0, -1933902, -5801706], [41577331750, -2689220, -2689220, 5099760, 2967900, -2689220], [-3426482, 82860146, 1295726538, 0, 3426482, 10279446], [-68344165478, -4976804, -4976804, 7389456, 7540956, -4976804], [439685, -138568310, -399392844, 0, -439685, -1319055], [1517220, 10865961, 4614217779, 0, -1517220, -4551660], [117014508611, 4151313, 4151313, -16867584, 4413645, 4151313], [-4127556, -103005396, -4154005524, 0, 4127556, 12382668], [10979705, -790744214, -7651366836, 0, -10979705, -32939115], [239917062486, -11275566, -11275566, 20000496, 13826202, -11275566], [11200842, 746695746, -8664853950, 0, -11200842, -33602526], [162634332710, 3983178, 3983178, 783888, -12733422, 3983178], [-202211653333, 24343889, 24343889, -68493360, -4538307, 24343889], [-669481384628, 11863860, 11863860, 22343520, -57935100, 11863860], [37585939, 1720786655, -17910950001, 0, -37585939, -112757817], [-11527492, 1691336341, -1416025593, 0, 11527492, 34582476], [-55069383, -1326260970, -22311464592, 0, 55069383, 165208149], [-376665, -4444516125, -15378279469, 0, 376665, 1129995], [-2919310595902, 58963742, 58963742, -43930704, -132960522, 58963742], [818570829074, 23505828, 23505828, 70592304, -141109788, 23505828], [1391123758056, 167394696, 167394696, -185704512, -316479576, 167394696], [128021818, -1397863114, 17642486622, 0, -128021818, -384065454], [-83312937, -5466633273, 90298123615, 0, 83312937, 249938811], [-1031832221016, 19720272, 19720272, 71865024, -131025840, 19720272], [745647969294, -124525446, -124525446, 417073200, -43496862, -124525446], [280449325, -4784612506, 28257591384, 0, -280449325, -841347975], [-167397996, 2424686301, -42850642129, 0, 167397996, 502193988], [434807156074, 161096556, 161096556, -272326512, -210963156, 161096556], [-347840856, 16344385956, 69808785020, 0, 347840856, 1043522568], [-6116990150108, 68143876, 68143876, 409600032, -614031660, 68143876], [-3085363969049, 180953793, 180953793, -743897880, 201036501, 180953793], [987982575798, -426404598, -426404598, -22677360, 1301891154, -426404598], [284787840, 2251744128, -476477049792, 0, -284787840, -854363520], [1297720515, -499787316, 29063889694, 0, -1297720515, -3893161545], [-4021473500361, -925899291, -925899291, 1123191216, 1654506657, -925899291], [-7126142756708, 476465916, 476465916, 132281376, -1561679124, 476465916], [-143743399, -46441069331, -441878888547, 0, 143743399, 431230197], [27519528323367, -449304615, -449304615, 419097240, 928816605, -449304615], [-1631799988, -7807488407, 307264009443, 0, 1631799988, 4895399964], [94068153, 29201685381, 259847209317, 0, -94068153, -282204459], [-3458659710, -9607396905, -729829997823, 0, 3458659710, 10375979130], [-26230173694020, -953621820, -953621820, 967025184, 1893840276, -953621820], [503849998, 76666254854, 394819079718, 0, -503849998, -1511549994], [1801914657, -32926307535, 1885302864473, 0, -1801914657, -5405743971], [-64709769041726, -922305834, -922305834, -2251556208, 5018473710, -922305834], [1616494232, -41838671936, -108408925104, 0, -1616494232, -4849482696], [-3558741654, -145149565509, 1328791082397, 0, 3558741654, 10676224962], [-66833199516286, 1991170716, 1991170716, -1358727792, -4614784356, 1991170716], [362683596, -69103161756, -405262739788, 0, -362683596, -1088050788], [20042922128820, 3235475724, 3235475724, -10553236896, 846809724, 3235475724], [2158285769, -37581407774, -3315116366124, 0, -2158285769, -6474857307], [-1648343127, -66049303059, 2937283355517, 0, 1648343127, 4945029381], [-5955282314522, -8613639750, -8613639750, 10975195344, 14865723906, -8613639750], [3865552761, -227372690070, -329999780596, 0, -3865552761, -11596658283], [-86049465481277, -415730951, -415730951, -2088871152, 3336064005, -415730951], [-6818736715, 123449554069, -5029352504835, 0, 6818736715, 20456210145], [28074922515574, 3816063268, 3816063268, -13797452016, 2349262212, 3816063268], [-123907782072533, -2848041987, -2848041987, -8466110616, 17010236577, -2848041987], [181065918895042, 5801663182, 5801663182, -5639620752, -11765368794, 5801663182], [33821170063627, -1994628255, -1994628255, 26466491760, -20482606995, -1994628255], [-270534420045940, -5219587444, -5219587444, 21791199840, -6132437508, -5219587444], [-24296762, 414998536274, 11261112099258, 0, 24296762, 72890286], [-18924472328148, 3558184308, 3558184308, -28705388256, 18030835332, 3558184308], [8474888424, 931863832605, 38803895943, 0, -8474888424, -25424665272], [82066899102111, -22037747031, -22037747031, 38102760552, 28010480541, -22037747031], [-4938224242, -831625625474, 1637762638158, 0, 4938224242, 14814672726], [320362479501090, 3744382956, 3744382956, 17105301840, -28338450708, 3744382956], [2768798235, 152401239312, 5285963137050, 0, -2768798235, -8306394705], [-14852227608, -260308398735, 8325202291203, 0, 14852227608, 44556682824], [521399385117760, -9077298080, -9077298080, 27129053760, 102840480, -9077298080], [-10011601149, 867153901980, 7090795622670, 0, 10011601149, 30034803447], [-52919375810550, -36811583970, -36811583970, 19132743504, 91302008406, -36811583970], [-146918373970758, -92459082, -92459082, 38680327344, -38402950098, -92459082], [-5806305795, -86674134582, -9941532846588, 0, 5806305795, 17418917385], [585457385811450, -2601521868, -2601521868, -34021620048, 41826185652, -2601521868], [-533907350069222, -10785533888, -10785533888, 78522722880, -46166121216, -10785533888], [-5766517024, -1357960645955, 31004013546039, 0, 5766517024, 17299551072], [286896751757146, 33927654516, 33927654516, -70196339472, -31586624076, 33927654516], [13986220640, 1444321688593, -31796527830477, 0, -13986220640, -41958661920], [-21815734665, 1031187487059, -5060736802365, 0, 21815734665, 65447203995], [2642881548, -422116096131, -8254260967777, 0, -2642881548, -7928644644], [27364941421051, 36631693165, 36631693165, 11143559208, -121038638703, 36631693165], [235025559261550, -74268370974, -74268370974, 44422790160, 178382322762, -74268370974], [32781137996, -185221372940, -52803434300700, 0, -32781137996, -98343413988], [31143617706, -547358073597, 19654423346421, 0, -31143617706, -93430853118], [-71986717188, 1965845332476, -22253329204836, 0, 71986717188, 215960151564], [-2115898491583824, -1541212152, -1541212152, 69337834176, -64714197720, -1541212152], [-62390760127249, 37354817505, 37354817505, -52025232648, -60039219867, 37354817505], [-53577340613, 2607262439912, -13418619576798, 0, 53577340613, 160732021839], [22537889359, -4858053683521, 18133787789271, 0, -22537889359, -67613668077], [-27443312748, 1596060039384, 58138964765216, 0, 27443312748, 82329938244], [621877625177530, 47922723150, 47922723150, -98649867120, -45118302330, 47922723150], [275396673807500, -25604580780, -25604580780, 41761936224, 35051806116, -25604580780], [266855264004695, -36317069599, -36317069599, -116239350840, 225190559637, -36317069599], [89792597370, 88896615543, -7569252168783, 0, -89792597370, -269377792110], [15465819471, -2276997801696, -5716238852862, 0, -15465819471, -46397458413], [-34857799371, -4648288532715, -57002640112067, 0, 34857799371, 104573398113], [-634918636101334, -99413812282, -99413812282, 271157316336, 27084120510, -99413812282], [1536347522166887, -125010161331, -125010161331, 204288104544, 170742379449, -125010161331], [22994956758, 1407119591946, 46715141116482, 0, -22994956758, -68984870274], [-56298991773, 7118185647915, 15557975379923, 0, 56298991773, 168896975319], [141060503118, 3826846928655, 19661227638865, 0, -141060503118, -423181509354], [1617747869494006, 194447832738, 194447832738, -391206495120, -192137003094, 194447832738], [-3784367925266101, -54780846199, -54780846199, 231279422592, -66936883995, -54780846199], [-349151551543038, 247129732836, 247129732836, -180176624208, -561212574300, 247129732836], [1951298976083428, -26712975644, -26712975644, -131684130720, 211823057652, -26712975644], [-363316114989, -5349591237996, -65943102967722, 0, 363316114989, 1089948344967], [207407362247, 4987209781675, -27382481231253, 0, -207407362247, -622222086741], [-4020906530698822, -10506278298, -10506278298, -32328983184, 63847818078, -10506278298], [83632782759, 6633670016088, 14718460392954, 0, -83632782759, -250898348277], [1861582492571936, -316985881776, -316985881776, 522807130176, 428150515152, -316985881776], [311447397581, 4989167264425, 57790109728905, 0, -311447397581, -934342192743], [-3176258418377058, -68316369708, -68316369708, -129192937968, 334142047092, -68316369708], [7930694332738626, -196002854976, -196002854976, 274948344192, 313060220736, -196002854976], [128885201811, -7345649797173, 218425316148243, 0, -128885201811, -386655605433], [-328514320426, 14142636650995, -73468055980371, 0, 328514320426, 985542961278], [-141603450195, -6777202003947, -62866595849587, 0, 141603450195, 424810350585], [2945436655551258, 224931484128, 224931484128, 250601326272, -925395778656, 224931484128], [7736677431606190, -36952466862, -36952466862, 171445672272, -60588271686, -36952466862], [-13062806606100161, -152562470267, -152562470267, -257078663616, 714766074417, -152562470267], [-61904000487, 573113936430, -306233446047240, 0, 61904000487, 185712001461], [-117650621562, 1750008077775, 342671105180321, 0, 117650621562, 352951864686], [4234748232356991, -113458492995, -113458492995, -319730112912, 660105591897, -113458492995], [1307640529040756, -6161672596, -6161672596, 82957918752, -64472900964, -6161672596], [442416203399, 18148139648719, -96151398516969, 0, -442416203399, -1327248610197], [-728220455406, -15182788097646, -215762535828318, 0, 728220455406, 2184661366218], [-4514699373069470, -662750328186, -662750328186, 976285111824, 1011965872734, -662750328186], [910774639383, -13938613003476, 56560333790838, 0, -910774639383, -2732323918149], [763207497811, 2496487201847, 430028685744279, 0, -763207497811, -2289622493433], [-11134055780603037, 364680366237, 364680366237, 75190774680, -1169231873391, 364680366237], [-182686987080, -20834845971375, -367499219194749, 0, 182686987080, 548060961240], [527169412575, 103004245080, 5959363901322, 0, -527169412575, -1581508237725], [-525664496004, 2288245868673, -299739814615989, 0, 525664496004, 1576993488012], [-10813225088326572, 825466774932, 825466774932, -1045497066720, -1430903258076, 825466774932], [2864495300383632, -45478454232, -45478454232, 1019512951104, -883077588408, -45478454232], [16960761933437919, -1144067246007, -1144067246007, 1872762000360, 1559439737661, -1144067246007], [138475786264, -13631842370092, -421479420288660, 0, -138475786264, -415427358792], [-21195406377180742, -408911434204, -408911434204, 750372228144, 476362074468, -408911434204], [52382822910, 16651138527675, -714013561234443, 0, -52382822910, -157148468730], [-511632627582, 1587153141234, 511646573011298, 0, 511632627582, 1534897882746], [204539025553, -21741582065554, 113521819671048, 0, -204539025553, -613617076659], [-5341381506058230, -905153650434, -905153650434, -478057425840, 3193518377142, -905153650434], [-517029533970, -1684932939558, 134190817424706, 0, 517029533970, 1551088601910], [-297085933413, -31658564023668, 339563703747566, 0, 297085933413, 891257800239], [3618595785478528, 1147922397792, 1147922397792, -3272052787200, -171714406176, 1147922397792], [779978526987, -42743282882397, -81166011914901, 0, -779978526987, -2339935580961]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_10_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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