
// Make newform 432.6.a.q in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_432_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_432_6_a_q();".
// 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_432_6_a_q();".
// 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 := [-10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-9, 18]];
    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_432_a();"
function MakeCharacter_432_a()
    N := 432;
    order := 1;
    char_gens := [271, 325, 353];
    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_432_a_Hecke(Kf)
    return MakeCharacter_432_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+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], [0, 0], [0, -1], [16, 3], [-243, -8], [104, 12], [972, -20], [316, 6], [-3402, -4], [5832, 38], [-1664, 81], [-4978, 60], [6804, -58], [-2480, -162], [-9234, 264], [-5832, 341], [-972, -376], [4088, -720], [-45032, -450], [22356, 788], [-60607, 504], [-14384, -840], [7533, -1752], [-89424, 358], [44471, 1272], [-101088, -1055], [-131936, 1260], [-92583, 1240], [-150226, -324], [-16524, 1350], [139768, -2835], [-261711, 952], [95256, 1670], [-163976, -1500], [-40824, -2777], [41416, -315], [-113212, -7128], [-47924, -2544], [-222102, -4176], [-268272, 3963], [-35721, -3224], [363536, 7584], [264384, -5812], [-590971, 2304], [-511272, -1643], [-290024, 6909], [23476, -5178], [429160, 1296], [308124, 1416], [-1192906, 4536], [272160, 12074], [205578, -9396], [32366, -10056], [474336, -8864], [1293732, -1632], [486, 15236], [672624, -4138], [-709856, -1557], [696848, 16200], [1806948, 12668], [10036, 35802], [730944, -24254], [365236, -20412], [375678, -23612], [1528661, -12936], [1174176, 25873], [1395160, 16422], [-1284718, 9960], [462915, 4152], [600554, -12828], [1670868, -29950], [1352538, 10248], [49408, 25101], [767732, -43116], [2124064, 24708], [2530116, 3868], [-2482488, -8177], [-1192552, -17820], [-1671840, -48004], [-702265, 6432], [821340, 29040], [3869696, 11832], [2579202, -34096], [-1866859, 74520], [707584, 27945], [-774684, -77424], [4349700, -58374], [-651145, -77112], [-6837048, -35713], [-2910848, -6105], [-4930227, 57184], [-5557410, -52296], [1935280, 55392], [-1279881, 149576], [-1523672, -79218], [-5937462, -55140], [-2313360, -15067], [628884, -11384], [3156580, 13428], [5301692, 53448], [4661188, 49356], [-1249992, 39583], [-6434397, -117336], [2288088, -100292], [4852948, 80544], [500030, 36504], [-2441907, 129848], [-3888000, -167126], [-3045762, 38696], [-1190533, -92664], [8475520, -127968], [10498094, -76320], [6956604, -130534], [12170068, 27432], [2255104, -46437], [-9345780, 167630], [-3553280, -177876], [-6424920, 171048], [-11508480, -103901], [-6103917, -103504], [-9818446, 167220], [-9894211, -12912], [-624024, 161434], [1960524, 256080], [-2100704, 103356], [-6213024, 75533], [189308, 266736], [710532, 63264], [3186040, -106677], [-2846674, 32724], [5301916, -328212], [-15240960, 164916], [-9419288, -260115], [1223882, 68472], [-2109240, 224760], [-69583, -159792], [13452480, -2106], [7035520, -232416], [17494056, -223893], [21978864, -226694], [-6105836, 163134], [-9789984, 93214], [9117904, -61347], [-16990560, -84448], [504314, 319368], [6443388, -294876], [14133854, -256392], [21433572, 186324], [-19208840, 308208], [14604300, -412432], [7548602, -504480], [-31433508, -250072], [-2184524, 577086], [592920, -198068], [-14374748, -395706], [26267814, 24000], [17315800, -339471], [-12649608, 233244], [-885997, -151464], [-9288432, 422155], [-130005, 271488], [14193144, 650148], [-12869456, 115803], [51366069, -80136], [4420656, 3790], [-22851234, -81448], [-12408992, -102285], [-36702976, -135108], [-22669885, -312552], [-709560, 622538], [-16923249, 5272], [44619902, 184680], [-2843586, 243040], [8630642, -67656], [36264136, -397083], [-3881196, 346630], [50329444, -64314], [4920264, -705333], [48332224, -11037], [5097164, 384588], [-21202760, 801597], [-15588207, -603928], [-19767286, -123444], [-11498760, -244404], [-23232744, -278132], [51383808, 221275], [16052786, 161532], [-24210524, 257196], [13480331, -622176], [-9482346, 1276076], [23587370, 665256], [-45663345, 244608], [-46542968, 810354], [-36605520, 85459], [-45788004, -212128], [-25703568, 448588], [-32949697, 175368], [6439790, 673824], [-58953744, 168148], [-2907252, 649832], [21232368, 970131], [-28616816, -312267], [10372172, 821100], [6551669, -1345464], [71960319, -15488], [20349792, 772102], [42009904, 1171572], [-1469907, 836464], [3851064, -1346414], [6317284, 1407612], [39426641, 85560], [-52406352, -1205378], [-66002456, -548721], [72612531, -280576], [-6531840, -165480], [-39662575, -176328], [-7497080, -634392], [10480104, 125322], [7647210, -358568], [87967944, 739306], [9634226, 345972], [-30197312, -418932], [8887968, 590696], [115519408, 284148], [-16023663, 1245360], [806024, -960], [-61926120, -193776], [27325350, -748484], [-18261560, 1713648], [33527196, -365624], [17632958, 1125600], [-6482648, 798336], [-110133224, -294192], [78111864, 297236], [8276560, 2050014], [4139748, 805480], [12313598, 1269552], [23230800, -1201782], [16373583, 1507008], [-44370828, 91600], [-75428172, 283544], [-38999456, 1038006], [-35198744, -3285], [1743380, -842652], [-49324140, -276164], [52740720, 924604], [106763320, 170457], [-67957623, -13880], [-152759852, -236358], [10763928, -1652748], [4914476, -2237544], [-29378700, -39684], [36674046, 1569056], [-8053207, 1843272], [43125696, -2539287], [90991593, 518720], [12946472, -1896516], [132485512, -364176], [-119363544, -339291], [87791033, 638280], [-96067352, -197877], [-38409309, -1326624], [-75818794, 170208], [-134380180, -320196], [-82682208, 467516], [53981896, -1265220], [68012784, -2243882], [18587556, -1934478], [39611188, -974592], [-36413064, -270918], [-67620100, 1870620], [-109984616, -344184], [219944741, 57024], [20850880, -30033], [-126930295, -294840], [128783440, 1698669], [143943237, -1015616], [18316724, -1318356], [49618559, -1054944], [-225143388, 635024], [-96886044, -409760], [91654768, 1592217], [18962262, 799924], [-69034930, -1269468], [-30764480, -148590], [-42202782, 3527856], [85338107, -2653224], [123607296, 1682527], [-35984360, -478440], [118202976, 2363232], [21757248, -2764590], [-142507107, 1312744], [-107400168, -1526516], [-76608909, -3693168], [-30406, 1818612], [24249456, -4902470], [101704264, -2698059], [-126078120, -34811], [225426969, -1518912], [247276744, -597270], [-145063534, -1736952], [-287626464, -265209], [55429432, 2194371], [-230894955, 1255936], [-97308104, -2497398], [-44274265, -3852360], [194502060, 251728], [70235618, -2367684], [-22068288, -4563112], [-188035804, 163956], [167117904, -2405468], [-168002424, -1514139], [65344644, 1843038], [-55004216, -1793892], [-82196208, 1910744], [166765682, -1822824], [250483185, 1279408], [-61216560, 3582788], [225942242, 146448], [171330552, 3820542], [-75120176, -3783420], [130614341, 1536600], [-84254904, -1580479], [200024080, -2563569], [-26467560, 3636496], [46859471, -3901440], [108016, -5554494], [-210472124, -1116828], [33884892, -4158900], [-23121936, 2791067], [-34568386, 5346684], [-91535184, 564370], [-233723792, -414627], [-70996824, 4466256], [-168972716, -1458972], [176224329, 1407784], [-82936954, 2140884], [82988388, -3668530], [307529009, -415368], [86160256, 1737207], [246281978, -384936], [48683592, -4806760], [-79896456, -1183335], [199178944, 2774568], [-182160576, -1945691], [-203073156, -2350400], [-268255762, -242028], [-183586244, 3222018], [-26906418, -392764], [-104262552, 4239446], [265237780, -1749588], [-107939845, 7185792], [193070304, 1726954], [-402458576, 126117], [174519950, 868176], [152050932, -3864418], [251057394, 990708], [-25165809, -4385656], [230950116, 785038], [-141723918, -628280], [-109240504, 749064], [107579988, 2588396], [88725132, 1780392], [301451463, -4879984], [-63929780, 2565438], [60281390, -4689264], [59257008, 4553974], [236509840, 1135113], [269122409, 4636416], [29801277, 1463056], [-103626080, -7520892], [77988906, -4512404], [261745992, -1079075], [155329816, -180507], [72507860, -776472], [35376912, -818448], [81052650, 969300], [32140043, 6640320], [111776112, 9703282], [-231811666, -37152], [-311629032, 1699439], [-19970712, 7620622], [-137974184, -1563360], [-26425764, -9856628], [15374236, 709224], [167440122, 3168836], [263696944, 5500548], [-73985152, 2922468], [224538652, 3990318], [555033384, -787428], [-381642439, -3366360], [-297593352, -6549950], [141971292, 4766432], [55061656, 2241786], [61882380, 9879960], [42846998, 389736], [-550063448, 2640792], [276210324, 8439054], [47774188, -10420002], [-138004560, -1804069], [-112910896, 6370164], [-217633716, 536410], [179274592, 5512536], [-31010688, -12623928], [187063344, 1805793], [-401349080, -3221127], [-515357422, 2706312], [-169931844, -9677248], [675944392, 2369844], [251513019, -1904392], [138762383, -1136592], [-77085432, -8674165], [-18770535, 228976], [-131152880, 8315820], [279597785, -7421664], [75048120, -4244195], [-90723078, 5979016], [-85863800, -2995536], [281301660, -4193218], [-701710614, -61712], [432738288, 4129574], [281181350, -340524], [10290564, 3317000], [-282944583, 1798440], [-246507307, 3948912], [33718680, 5857045], [-688828455, 4020952], [83835972, -3519486], [-114192776, 5781456], [-115232544, 203564]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_432_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_432_6_a_q();".
// 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_432_6_a_q(:prec:=2)
    chi := MakeCharacter_432_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_432_6_a_q();".
// 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_432_6_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_432_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-3321, 0, 1]>,<7,R![-29633, -32, 1]>,<11,R![-153495, 486, 1]>],Snew);
    return Vf;
end function;