
// Make newform 12.6.b.a in Magma, downloaded from the LMFDB on 23 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_6_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_12_6_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 := [912, -768, 223, -73, -11, 6, 7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [4238706, -8744833, -610094, -423169, -231, -62704, 30607, -9436], [5096288, -673868, -81692, -251008, -139528, -73822, -2252, -5694], [-1507299, -3343360, 3220092, 1228252, 488016, 129032, 72516, -8084], [-78787206, 30261501, -10020102, -436119, 1046763, 753588, -85191, 98436], [43615544, -24231757, 1647902, 723461, -1183333, -396078, 87389, -70008], [53217788, 2922499, 4344198, -3169901, -2951719, -1331716, -286197, -164992], [26548384, -14368388, 5776852, -1820252, -1647824, -485532, -63236, -83652]];
    Rf_basisdens := [1, 953786, 476893, 476893, 953786, 476893, 953786, 476893];
    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 := 6;
    raw_aps := [[0, 0, 1, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0], [0, -1, 0, 2, 1, 0, -2, -1], [0, -3, -32, 0, -1, 0, 0, 4], [14, 4, 0, -12, 0, 0, -4, -2], [0, 0, 148, 0, 0, -12, 0, 20], [0, 27, 0, -12, -13, 0, 12, 6], [0, 42, -256, 0, 14, 0, 0, 32], [0, 0, 247, 0, 0, 55, 0, 24], [0, -185, 0, 22, 69, 0, -22, -11], [806, -4, 0, 12, 0, 0, 4, 2], [0, 0, -614, 0, 0, -102, 0, -64], [0, 551, 0, -4, -185, 0, 4, 2], [0, 756, 1600, 0, 252, 0, 0, -200], [0, 0, -1043, 0, 0, -19, 0, -128], [0, -1215, 1664, 0, -405, 0, 0, -208], [7454, -164, 0, 492, 0, 0, 164, 82], [0, 847, 0, 304, -181, 0, -304, -152], [0, 798, -2496, 0, 266, 0, 0, 312], [-16150, -448, 0, 1344, 0, 0, 448, 224], [0, -1537, 0, -442, 365, 0, 442, 221], [0, -165, -800, 0, -55, 0, 0, 100], [0, 0, 11830, 0, 0, -234, 0, 1508], [-49006, 260, 0, -780, 0, 0, -260, -130], [0, 0, -1799, 0, 0, -711, 0, -136], [0, 2503, 0, 1882, -207, 0, -1882, -941], [0, -651, -14400, 0, -217, 0, 0, 1800], [75470, -724, 0, 2172, 0, 0, 724, 362], [0, 0, -6884, 0, 0, 1756, 0, -1080], [0, 1455, 0, -1650, -1035, 0, 1650, 825], [0, 11199, 23360, 0, 3733, 0, 0, -2920], [0, 0, -31982, 0, 0, -3758, 0, -3528], [0, -533, 0, -1184, -217, 0, 1184, 592], [0, 0, -20411, 0, 0, -1211, 0, -2400], [0, 15191, 0, -1534, -5575, 0, 1534, 767], [236894, 2212, 0, -6636, 0, 0, -2212, -1106], [0, -17733, 0, 3996, 7243, 0, -3996, -1998], [0, -16218, 10880, 0, -5406, 0, 0, -1360], [0, 0, -34277, 0, 0, 7963, 0, -5280], [0, 12147, -84864, 0, 4049, 0, 0, 10608], [242966, 1428, 0, -4284, 0, 0, -1428, -714], [0, 21168, 27712, 0, 7056, 0, 0, -3464], [-360382, -3872, 0, 11616, 0, 0, 3872, 1936], [0, 0, 103441, 0, 0, -7983, 0, 13928], [0, 13359, 0, -4398, -5919, 0, 4398, 2199], [0, -3089, 0, -14120, -3677, 0, 14120, 7060], [0, -45961, 0, 4070, 16677, 0, -4070, -2035], [0, 6231, 69088, 0, 2077, 0, 0, -8636], [129542, -10412, 0, 31236, 0, 0, 10412, 5206], [0, 0, 32890, 0, 0, 13530, 0, 2420], [0, 42372, 24512, 0, 14124, 0, 0, -3064], [-375694, 4048, 0, -12144, 0, 0, -4048, -2024], [0, -50751, -25440, 0, -16917, 0, 0, 3180], [0, 0, -90080, 0, 0, 6112, 0, -12024], [0, -9426, 136384, 0, -3142, 0, 0, -17048], [0, 0, 65011, 0, 0, -10509, 0, 9440], [0, -33969, 0, -1098, 10957, 0, 1098, 549], [-297514, 13628, 0, -40884, 0, 0, -13628, -6814], [0, 0, -81338, 0, 0, -26138, 0, -6900], [0, 42763, 0, -12152, -18305, 0, 12152, 6076], [0, 0, -82007, 0, 0, 4585, 0, -10824], [0, -38481, 0, 10056, 16179, 0, -10056, -5028], [0, -30270, 7616, 0, -10090, 0, 0, -952], [917354, -16484, 0, 49452, 0, 0, 16484, 8242], [0, 0, 46111, 0, 0, 24223, 0, 2736], [0, -21157, 0, 14960, 12039, 0, -14960, -7480], [158402, 13604, 0, -40812, 0, 0, -13604, -6802], [0, 30825, -114016, 0, 10275, 0, 0, 14252], [-278434, -7660, 0, 22980, 0, 0, 7660, 3830], [0, 0, -54440, 0, 0, -48936, 0, -688], [0, -69546, -73536, 0, -23182, 0, 0, 9192], [0, 105167, 0, 2534, -34211, 0, -2534, -1267], [-2234410, 26324, 0, -78972, 0, 0, -26324, -13162], [0, -32841, 0, -44748, -3969, 0, 44748, 22374], [0, -15360, 180800, 0, -5120, 0, 0, -22600], [0, 0, 366625, 0, 0, 15777, 0, 43856], [59054, -23716, 0, 71148, 0, 0, 23716, 11858], [0, 0, -198764, 0, 0, 44596, 0, -30420], [3122618, 5488, 0, -16464, 0, 0, -5488, -2744], [0, -47481, -332512, 0, -15827, 0, 0, 41564], [-3558778, -33308, 0, 99924, 0, 0, 33308, 16654], [0, -150828, 478656, 0, -50276, 0, 0, -59832], [-652702, -37900, 0, 113700, 0, 0, 37900, 18950], [0, -132841, 0, -8494, 41449, 0, 8494, 4247], [0, 76977, 176224, 0, 25659, 0, 0, -22028], [0, 0, -22688, 0, 0, -21952, 0, -92], [4235690, 3760, 0, -11280, 0, 0, -3760, -1880], [0, 0, 143299, 0, 0, 29955, 0, 14168], [0, 218551, 0, -60962, -93171, 0, 60962, 30481], [0, -126693, 511392, 0, -42231, 0, 0, -63924], [0, 151176, -573824, 0, 50392, 0, 0, 71728], [0, -124089, 0, 2970, 42353, 0, -2970, -1485], [0, 25653, -274816, 0, 8551, 0, 0, 34352], [0, 250591, 0, 80152, -56813, 0, -80152, -40076], [0, 272466, 543552, 0, 90822, 0, 0, -67944], [0, 0, 725839, 0, 0, 61647, 0, 83024], [0, 0, -847502, 0, 0, 43442, 0, -111368], [0, -60537, 0, -4020, 18839, 0, 4020, 2010], [5224766, -21268, 0, 63804, 0, 0, 21268, 10634], [0, 258491, 0, -39076, -99189, 0, 39076, 19538], [0, 0, -194981, 0, 0, 54555, 0, -31192], [0, -129597, 897440, 0, -43199, 0, 0, -112180], [0, 0, 264478, 0, 0, -128930, 0, 49176], [0, -102725, 0, -61304, 13807, 0, 61304, 30652], [-7311694, 19988, 0, -59964, 0, 0, -19988, -9994], [0, 136125, -4160, 0, 45375, 0, 0, 520], [0, 0, -877388, 0, 0, -8652, 0, -108592], [0, 396186, -368128, 0, 132062, 0, 0, 46016], [4731194, 43456, 0, -130368, 0, 0, -43456, -21728], [0, -113921, 0, -95474, 6149, 0, 95474, 47737], [1446950, 128076, 0, -384228, 0, 0, -128076, -64038], [0, 0, -142406, 0, 0, -12326, 0, -16260], [0, -113509, 0, 101312, 71607, 0, -101312, -50656], [0, -147969, 0, 104826, 84265, 0, -104826, -52413], [0, 0, -261968, 0, 0, 129232, 0, -48900], [0, -146021, 0, 43372, 63131, 0, -43372, -21686], [0, -214674, 360576, 0, -71558, 0, 0, -45072], [0, 0, -1325837, 0, 0, 116019, 0, -180232], [0, -125829, -1091840, 0, -41943, 0, 0, 136480], [-3366634, -5876, 0, 17628, 0, 0, 5876, 2938], [-6667054, -22076, 0, 66228, 0, 0, 22076, 11038], [0, 0, -886967, 0, 0, -158199, 0, -91096], [0, 465717, -405600, 0, 155239, 0, 0, 50700], [0, -148837, 0, -170428, -7197, 0, 170428, 85214], [0, 0, 1959007, 0, 0, -113505, 0, 259064], [-4058170, 132124, 0, -396372, 0, 0, -132124, -66062], [0, -565524, -1769088, 0, -188508, 0, 0, 221136], [0, 45263, 0, -251974, -99079, 0, 251974, 125987], [10922654, -156124, 0, 468372, 0, 0, 156124, 78062], [0, 86223, 0, 82560, -1221, 0, -82560, -41280], [0, -791082, -1051648, 0, -263694, 0, 0, 131456], [0, 838039, 0, 16462, -273859, 0, -16462, -8231], [6091670, -159996, 0, 479988, 0, 0, 159996, 79998], [0, 0, -1215890, 0, 0, -265490, 0, -118800], [-8471614, 160528, 0, -481584, 0, 0, -160528, -80264], [0, 0, -555935, 0, 0, 379809, 0, -116968], [0, -206597, 0, 79060, 95219, 0, -79060, -39530], [0, 0, 554743, 0, 0, 114871, 0, 54984], [0, 0, 2574490, 0, 0, 29466, 0, 318128], [0, 403335, 0, -305316, -236217, 0, 305316, 152658], [0, 0, -1630067, 0, 0, -169907, 0, -182520], [0, -54449, 0, 374506, 142985, 0, -374506, -187253], [0, -322719, -1459776, 0, -107573, 0, 0, 182472], [25072382, 48516, 0, -145548, 0, 0, -48516, -24258], [0, 262686, 2268352, 0, 87562, 0, 0, -283544], [-14327434, -112252, 0, 336756, 0, 0, 112252, 56126], [0, 0, -2794010, 0, 0, -75098, 0, -339864], [0, 1350583, 0, -227420, -526001, 0, 227420, 113710], [0, 1179336, -967104, 0, 393112, 0, 0, 120888], [308462, 256900, 0, -770700, 0, 0, -256900, -128450], [0, 0, 2221084, 0, 0, -471460, 0, 336568], [0, -753669, 0, 209796, 321155, 0, -209796, -104898], [0, 496626, 1834304, 0, 165542, 0, 0, -229288], [0, 613895, 0, -25204, -213033, 0, 25204, 12602], [0, -677796, -1648064, 0, -225932, 0, 0, 206008], [0, -1033665, 0, -122166, 303833, 0, 122166, 61083], [0, 0, 80248, 0, 0, 77080, 0, 396], [-8764006, 124316, 0, -372948, 0, 0, -124316, -62158], [0, 0, -2462021, 0, 0, 103291, 0, -320664], [0, 333267, 1698112, 0, 111089, 0, 0, -212264], [0, 0, 1823422, 0, 0, 520830, 0, 162824], [0, 1009495, 0, 397018, -204159, 0, -397018, -198509], [0, -413331, -2031840, 0, -137777, 0, 0, 253980], [0, 0, 1634308, 0, 0, -80028, 0, 214292], [0, -779238, -450752, 0, -259746, 0, 0, 56344], [0, -1144065, 0, -295986, 282693, 0, 295986, 147993], [-22202458, -55220, 0, 165660, 0, 0, 55220, 27610]];
    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_6_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_12_6_b_a(:prec:=8)
    chi := MakeCharacter_12_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_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_12_6_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_12_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;