
// Make newform 12.8.b.b in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_12_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_12_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_12_8_b_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_12_8_b_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 := [1048576, 0, 41984, 0, 1008, 0, 41, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 41984, 0, 1008, 0, 41, 0, 1], [-827392, 97280, -23040, -144, -288, -87, -32, 1], [-4864, 0, 1328, 0, -9, 0, -1, 0], [2195456, 97280, 73728, -144, 3648, -87, 64, 1], [-827392, -203776, -23040, -11376, -288, -57, -32, -17], [-1654784, -236544, -46080, -720, -576, 133, -64, -3], [0, -68608, 0, 18224, 0, -267, 0, -19]];
    Rf_basisdens := [1, 16384, 24576, 128, 24576, 24576, 16384, 16384];
    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_12_b();"
function MakeCharacter_12_b()
    N := 12;
    order := 2;
    char_gens := [7, 5];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_12_b_Hecke();"
function MakeCharacter_12_b_Hecke(Kf)
    N := 12;
    order := 2;
    char_gens := [7, 5];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 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 := 8;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0], [0, -1, 1, 0, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0, 0, 1], [0, 4, 8, 1, 4, 0, 4, 0], [0, 127, 31, 0, 0, -46, 5, 0], [6806, -2, 2, 2, -8, 0, -2, 0], [0, -382, -28, 0, 0, -14, 14, -12], [0, 49, 267, -30, -120, 0, 49, 0], [0, 298, -514, 0, 0, 208, 102, 0], [0, -12817, -1128, 0, 0, -564, 564, 31], [0, -530, -1346, -61, -244, 0, -530, 0], [-2722, -526, 526, 526, -2104, 0, -526, 0], [0, -17110, -1600, 0, 0, -800, 800, 258], [0, 2137, 2675, 934, 3736, 0, 2137, 0], [0, 7848, 3508, 0, 0, -3700, 64, 0], [0, -30511, -1664, 0, 0, -832, 832, -2275], [0, 5085, -18745, 0, 0, 8920, 3275, 0], [-378490, 2866, -2866, -2866, 11464, 0, 2866, 0], [0, 7379, 38041, -3976, -15904, 0, 7379, 0], [0, -140798, 43026, 0, 0, 9324, -17450, 0], [460346, -1312, 1312, 1312, -5248, 0, -1312, 0], [0, -8706, -51250, 6283, 25132, 0, -8706, 0], [0, 115741, -14039, 0, 0, -19150, 11063, 0], [0, 266108, 24212, 0, 0, 12106, -12106, -2466], [-1985902, -5866, 5866, 5866, -23464, 0, -5866, 0], [0, -105055, -22600, 0, 0, -11300, 11300, 30969], [0, -44888, -88892, -11443, -45772, 0, -44888, 0], [0, 414949, -247077, 0, 0, 37284, 69931, 0], [-8391658, 554, -554, -554, 2216, 0, 554, 0], [0, -650776, -42264, 0, 0, -21132, 21132, -32948], [0, -43806, -185430, 13503, 54012, 0, -43806, 0], [0, 747527, -124039, 0, 0, -105716, 76585, 0], [0, -109162, 3672, 0, 0, 1836, -1836, -30278], [0, 201119, 637213, -8464, -33856, 0, 201119, 0], [0, 276953, -18528, 0, 0, -9264, 9264, 98005], [0, -101220, -301552, -527, -2108, 0, -101220, 0], [-16037242, 89614, -89614, -89614, 358456, 0, 89614, 0], [0, -259723, -1038393, 64806, 259224, 0, -259723, 0], [0, -671106, -484702, 0, 0, 415864, 22946, 0], [0, 4928399, 533856, 0, 0, 266928, -266928, -242189], [0, -2099345, 630285, 0, 0, 145080, -258455, 0], [-69372178, -33690, 33690, 33690, -134760, 0, -33690, 0], [0, -1941948, 167176, 0, 0, 358124, -175100, 0], [135589826, 40528, -40528, -40528, 162112, 0, 40528, 0], [0, -2712127, -247768, 0, 0, -123884, 123884, 27441], [0, 620604, 1545744, 79017, 316068, 0, 620604, 0], [0, -672585, -1186379, -207844, -831376, 0, -672585, 0], [0, 548582, 833030, 203179, 812716, 0, 548582, 0], [0, -9899287, 1877053, 0, 0, 1273730, -1050261, 0], [-133676098, 68134, -68134, -68134, 272536, 0, 68134, 0], [0, -17181256, -1580764, 0, 0, -790382, 790382, 199506], [0, -2277840, -1261900, 0, 0, 1205140, 18920, 0], [-25940398, 185080, -185080, -185080, 740320, 0, 185080, 0], [0, 10572207, -4411149, 0, 0, -64506, 1491885, 0], [0, -3468532, 56232, 0, 0, 28116, -28116, -823040], [0, 8027866, 186226, 0, 0, -1952860, 588878, 0], [0, -34881817, -2998048, 0, 0, -1499024, 1499024, -80853], [0, -903130, -2834586, 31299, 125196, 0, -903130, 0], [-104631442, 342194, -342194, -342194, 1368776, 0, 342194, 0], [0, 14789960, 728220, 0, 0, 364110, -364110, 1283086], [0, 3019107, 6113113, 736052, 2944208, 0, 3019107, 0], [0, 41069489, 3344376, 0, 0, 1672188, -1672188, 521833], [0, -561, 3687069, -922188, -3688752, 0, -561, 0], [0, -24489218, -1716754, 0, 0, 6575764, -1619670, 0], [474682586, -297782, 297782, 297782, -1191128, 0, -297782, 0], [0, 42410123, 3848112, 0, 0, 1924056, -1924056, -368633], [0, 1402775, 8584037, -1093928, -4375712, 0, 1402775, 0], [-33623902, 282854, -282854, -282854, 1131416, 0, 282854, 0], [0, 13291959, -10470997, 0, 0, 2570854, 2633381, 0], [-424461562, -1078954, 1078954, 1078954, -4315816, 0, -1078954, 0], [0, 87115664, 7008656, 0, 0, 3504328, -3504328, 1303224], [0, 45672130, -5734230, 0, 0, -7452060, 4395430, 0], [0, -3155426, -7713682, -438149, -1752596, 0, -3155426, 0], [-80249554, -2911162, 2911162, 2911162, -11644648, 0, -2911162, 0], [0, 1648629, 7426071, -620046, -2480184, 0, 1648629, 0], [0, -20394124, 23310776, 0, 0, -7845620, -5155052, 0], [0, -18215107, 600272, 0, 0, 300136, -300136, -5023647], [-32924362, 1906514, -1906514, -1906514, 7626056, 0, 1906514, 0], [0, -21206650, -2266020, 0, 0, -1133010, 1133010, 970516], [-664921942, 191656, -191656, -191656, 766624, 0, 191656, 0], [0, -20579635, 8887685, 0, 0, -36530, -2950385, 0], [-866934850, 2816926, -2816926, -2816926, 11267704, 0, 2816926, 0], [0, 7907552, -10007964, 0, 0, 3564084, 2147960, 0], [746379266, -1316962, 1316962, 1316962, -5267848, 0, -1316962, 0], [0, 7732324, 16008776, 1797049, 7188196, 0, 7732324, 0], [0, 3665403, 7487851, 0, 0, -4877782, -870023, 0], [0, -146583802, -14504588, 0, 0, -7252294, 7252294, 4043792], [625643258, 121864, -121864, -121864, 487456, 0, 121864, 0], [0, 128224955, 14340440, 0, 0, 7170220, -7170220, -7338021], [0, -5687918, -16497446, -141577, -566308, 0, -5687918, 0], [0, -36227607, 40753713, 0, 0, -13584090, -9056541, 0], [0, -23278960, 6019720, 0, 0, 2130680, -2716800, 0], [0, 12410824, 39130020, -474387, -1897548, 0, 12410824, 0], [0, -84262543, 3279971, 0, 0, 17679064, -6986345, 0], [0, -6147801, -23809403, 1341500, 5366000, 0, -6147801, 0], [0, 10132998, -21225234, 0, 0, 9090588, 4044882, 0], [0, 43946603, -1275568, 0, 0, -637784, 637784, 11723127], [0, 105058070, 15010840, 0, 0, 7505420, -7505420, -13513318], [0, -10155263, -35023029, 1139310, 4557240, 0, -10155263, 0], [1114853990, -2455894, 2455894, 2455894, -9823576, 0, -2455894, 0], [0, -19316011, -27691417, -7564154, -30256616, 0, -19316011, 0], [0, 135036203, 8027432, 0, 0, 4013716, -4013716, 8544147], [0, -98061487, 2398121, 0, 0, 21338278, -7912133, 0], [0, -234866062, -25243848, 0, 0, -12621924, 12621924, 11087638], [0, 21739635, 65612425, -98380, -393520, 0, 21739635, 0], [145274738, 608174, -608174, -608174, 2432696, 0, 608174, 0], [0, 239590893, -2688077, 0, 0, -53842780, 18843619, 0], [0, 272676524, 25419536, 0, 0, 12709768, -12709768, -3929628], [0, 116087050, -12648850, 0, 0, -19978400, 10875750, 0], [-1687784278, -10527200, 10527200, 10527200, -42108800, 0, -10527200, 0], [0, 6862514, 1992346, 4648799, 18595196, 0, 6862514, 0], [-294946594, 5906058, -5906058, -5906058, 23624232, 0, 5906058, 0], [0, -452188732, -37612788, 0, 0, -18806394, 18806394, -3928334], [0, -7549921, -23505187, 213856, 855424, 0, -7549921, 0], [0, -40642000, -124232100, 576525, 2306100, 0, -40642000, 0], [0, -191605510, -28221780, 0, 0, -14110890, 14110890, 26588992], [0, -1162723, 24517279, -7001362, -28005448, 0, -1162723, 0], [0, -362454106, 69143418, 0, 0, 46412184, -38518534, 0], [0, 50965019, 2228216, 0, 0, 1114108, -1114108, 5068107], [0, 317230815, -170677355, 0, 0, 18696080, 50660425, 0], [6022377902, 6971530, -6971530, -6971530, 27886120, 0, 6971530, 0], [-7207275694, 10950838, -10950838, -10950838, 43803352, 0, 10950838, 0], [0, 77447513, 20761832, 0, 0, 10380916, -10380916, -32262711], [0, -476074477, 35280111, 0, 0, 90866358, -42048823, 0], [0, 68656505, 125897411, 20018026, 80072104, 0, 68656505, 0], [0, 846793895, 74063480, 0, 0, 37031740, -37031740, -987225], [12055580222, 6787234, -6787234, -6787234, 27148936, 0, 6787234, 0], [0, 149090340, 54600180, 0, 0, -63805560, 3068460, 0], [0, -21216096, -97755988, 8526925, 34107700, 0, -21216096, 0], [-4339188154, -20828722, 20828722, 20828722, -83314888, 0, -20828722, 0], [0, 38584539, 162424209, -11667648, -46670592, 0, 38584539, 0], [0, -440130714, -15830014, 0, 0, 110092480, -31420822, 0], [0, 52178570, 130076002, 6614927, 26459708, 0, 52178570, 0], [-1671599122, -3082386, 3082386, 3082386, -12329544, 0, -3082386, 0], [0, 219549830, 4273200, 0, 0, 2136600, -2136600, 34081606], [-1207828798, -4898216, 4898216, 4898216, -19592864, 0, -4898216, 0], [0, 1137611129, 83607896, 0, 0, 41803948, -41803948, 35224065], [0, -35871871, -135465413, 6962450, 27849800, 0, -35871871, 0], [0, -443825257, -31775928, 0, 0, -15887964, 15887964, -15680417], [0, -849395182, -56754448, 0, 0, -28377224, 28377224, -39343806], [0, -62613015, -204164253, 4081302, 16325208, 0, -62613015, 0], [0, -85218355, -17862840, 0, 0, -8931420, 8931420, 24040861], [0, 38215832, 65967028, 12170117, 48680468, 0, 38215832, 0], [0, -477366127, 192023583, 0, 0, 6764100, -66262561, 0], [373838438, 21942366, -21942366, -21942366, 87769464, 0, 21942366, 0], [0, 874922570, -69919550, 0, 0, -164256220, 78058590, 0], [13007421326, -7571602, 7571602, 7571602, -30286408, 0, -7571602, 0], [0, -28603342, -29460408, 0, 0, -14730204, 14730204, 62038270], [0, -97447731, -332628929, 10071434, 40285736, 0, -97447731, 0], [0, 97153916, -18427824, 0, 0, -12497460, 10308428, 0], [-13525685962, 16407934, -16407934, -16407934, 65631736, 0, 16407934, 0], [0, -273522160, -35068520, 0, 0, -17534260, 17534260, 25953164], [0, 37784377, 143739267, -7596534, -30386136, 0, 37784377, 0], [0, -277827002, 73317518, 0, 0, 24635260, -32650926, 0], [0, -148146271, -354521941, -22479218, -89916872, 0, -148146271, 0], [0, 655723472, -456410324, 0, 0, 94438604, 120657240, 0], [0, -68280776, -116013996, -22207083, -88828332, 0, -68280776, 0], [0, -665572582, -65490948, 0, 0, -32745474, 32745474, 17514664], [-8907667222, 4598954, -4598954, -4598954, 18395816, 0, 4598954, 0], [0, 1701829355, 175292520, 0, 0, 87646260, -87646260, -62806925], [0, -706325861, 7204213, 0, 0, 159119084, -55441099, 0], [0, 2069880314, 165553256, 0, 0, 82776628, -82776628, 33203574], [0, -7120136, -156963788, 33900845, 135603380, 0, -7120136, 0], [0, -418790653, 179656551, 0, 0, -94146, -59854135, 0], [0, 1131469298, 86392292, 0, 0, 43196146, -43196146, 27591588], [0, -808983282, 698433286, 0, 0, -189391012, -169680758, 0], [0, -124579950, -264570438, -27292353, -109169412, 0, -124579950, 0], [4422824798, -51474806, 51474806, 51474806, -205899224, 0, -51474806, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_12_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_12_8_b_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_12_8_b_b(:prec:=8)
    chi := MakeCharacter_12_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_12_8_b_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_12_8_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_12_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![4200928000, 0, 205120, 0, 1]>],Snew);
    return Vf;
end function;