
// Make newform 72.8.d.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_72_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_72_d_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_72_8_d_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_72_8_d_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 := [32768, -3072, -320, -24, -10, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [2560, 320, 24, 10, 3, -1], [-6656, 7872, -24, -10, -3, 1], [26624, 3136, 760, 242, -49, -5], [-15872, -1088, -104, 50, 7, 3], [-90112, -2496, 3032, -182, 51, 15]];
    Rf_basisdens := [1, 512, 256, 512, 256, 512];
    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_72_d();"
function MakeCharacter_72_d()
    N := 72;
    order := 2;
    char_gens := [55, 37, 65];
    v := [2, 1, 2];
    // 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_72_d_Hecke();"
function MakeCharacter_72_d_Hecke(Kf)
    N := 72;
    order := 2;
    char_gens := [55, 37, 65];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0], [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 := 8;
    raw_aps := [[-1, -1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, -2, 0, -1, 1, 1], [-112, 16, 2, -6, 2, -2], [0, 208, -16, -8, 11, 8], [0, 438, -32, -5, 37, 5], [-194, 1296, 92, -108, 36, -36], [0, -1296, 80, -88, 65, 88], [208, -1200, -70, 18, -6, 6], [0, 3394, -256, -95, -2209, 95], [-14656, -9024, -408, -504, 168, -168], [0, -12942, 928, 25, -7097, -25], [-85690, -13344, -248, -2664, 888, -888], [0, 7392, -608, -560, -275, 560], [-260064, -18144, -588, -2268, 756, -756], [0, -38810, 2720, -365, 16589, 365], [0, 57088, -3584, 3456, -9141, -3456], [0, 22638, -1056, 3927, 7881, -3927], [0, 30192, -1968, 1320, 5001, -1320], [1276272, -12048, 3534, -22698, 7566, -7566], [347114, 171536, 9052, 2580, -860, 860], [2669216, -290912, -16204, 228, -76, 76], [0, -106112, 9088, 10560, 8775, -10560], [-357466, -38928, -476, -9108, 3036, -3036], [-164494, 223600, 19460, -38004, 12668, -12668], [0, -359762, 28704, 21047, -169559, -21047], [-11085616, -171184, -12038, 13650, -4550, 4550], [0, 577456, -41584, -2360, 201035, 2360], [0, -11322, -5248, -42397, -78307, 42397], [798510, 747456, 52752, -60624, 20208, -20208], [20119424, -1348736, -62272, -68352, 22784, -22784], [0, 116272, -19184, -76152, -129081, 76152], [6946278, 127392, -36456, 235080, -78360, 78360], [0, 1690080, -123232, -17584, -570883, 17584], [0, -102506, 6464, -6005, 473141, 6005], [-36496336, -3044944, -204698, 191886, -63962, 63962], [0, -2132706, 154144, 12655, 446065, -12655], [0, 2301408, -194912, -213680, 707137, 213680], [41246000, -1822032, -162794, 332478, -110826, 110826], [0, -1641734, 103136, -98915, -72829, 98915], [0, 4166752, -296672, 6672, 571527, -6672], [0, -206982, 11264, -24643, 269891, 24643], [-13182464, -1844736, -156112, 289584, -96528, 96528], [31469330, 2447984, 114628, 115404, -38468, 38468], [0, -1208354, 54976, -219345, -1121775, 219345], [8347664, 1021072, 9074, 257322, -85774, 85774], [0, 4825824, -380768, -252464, -818807, 252464], [-72265408, -7554240, -494760, 405432, -135144, 135144], [0, -4201088, 223872, -533440, -205073, 533440], [0, 982770, -91072, -146119, 3057287, 146119], [6622262, -10105488, -521276, -216756, 72252, -72252], [88936992, -4173024, -58908, -933804, 311268, -311268], [-119975326, -1144464, 171012, -1266804, 422268, -422268], [0, 51136, 70208, 517024, -2076853, -517024], [-115683138, 2151744, 59568, 323856, -107952, 107952], [-249189136, 782448, 391006, -1876698, 625566, -625566], [0, -14306582, 1084736, 439861, -435061, -439861], [-222521440, 13456544, 673348, 400884, -133628, 133628], [0, 14427210, -1067680, -260155, -612133, 260155], [-152031258, -11468688, -236796, -2161908, 720636, -720636], [0, -5480112, 569968, 1249720, -4049603, -1249720], [0, 14323054, -909376, 795895, 1986377, -795895], [0, -6400656, 333264, -867480, 5929905, 867480], [-110164976, 35272848, 1355666, 3261258, -1087086, 1087086], [142032938, 15901728, 1220856, -1822104, 607368, -607368], [0, 28735474, -2332416, -1959175, 2179591, 1959175], [0, 7414032, -578384, -341672, 12947749, 341672], [-449686030, -3555008, -755536, 3013392, -1004464, 1004464], [0, 435616, 182496, 1495280, 13109515, -1495280], [0, 62348574, -4502720, -344753, -10440335, 344753], [-579373986, -23219712, -2081664, 4275072, -1425024, 1425024], [159463216, -42779472, -3225274, 4582638, -1527546, 1527546], [113932640, 39842912, 2429404, -1165908, 388636, -388636], [0, -6866310, 818720, 2297885, 12552131, -2297885], [0, -59215968, 4047584, -1274896, -9133819, 1274896], [-236881152, 47112960, 1274400, 7252128, -2417376, 2417376], [0, -53333858, 3500128, -2166033, -23193423, 2166033], [0, -13004010, 368000, -3926005, -16621963, 3926005], [1237300158, -38166000, -3382500, 6815700, -2271900, 2271900], [161616842, -54182624, -1236808, -9576024, 3192008, -3192008], [0, 60782800, -4181008, 1124344, 10589063, -1124344], [0, -75996654, 4761728, -4666231, 15547127, 4666231], [-1459232352, 19627680, 2316660, -6621660, 2207220, -2207220], [-1296860254, 94188912, 3772164, 7886988, -2628996, 2628996], [-1120288528, -10075024, 268942, -4474794, 1491598, -1491598], [0, -94342256, 6477104, -1831400, -858973, 1831400], [-1808173458, 69175056, 3890652, -257004, 85668, -85668], [-747851494, 88254240, 5430840, -2850264, 950088, -950088], [0, -44287478, 3634496, 3297733, -14287621, -3297733], [650488736, -151553888, -7049836, -7397052, 2465684, -2465684], [0, 41223664, -2890416, 378920, 24768751, -378920], [-1881553216, -161510208, -10963736, 10751112, -3583704, 3583704], [-515810224, 33669840, -799110, 14416146, -4805382, 4805382], [0, 32568256, -1810112, 3613344, 34954467, -3613344], [0, -2288064, 1684416, 10646880, 25924809, -10646880], [1297681680, -158377584, -7402878, -7537734, 2512578, -2512578], [0, -103602830, 7705952, 2140249, 9265223, -2140249], [1299187302, 49336992, 3704664, -5204088, 1734696, -1734696], [0, 178932240, -14540880, -12320040, 27138501, 12320040], [0, -228343266, 14945632, -9552209, 4069873, 9552209], [0, 209754480, -13918000, 7451240, -5376103, -7451240], [0, -56796806, 3048224, -7060835, 36074051, 7060835], [0, -50740016, 3690224, 461560, -50353873, -461560], [-1754327274, -127424352, -10617384, 19106568, -6368856, 6368856], [0, 61256112, -4307824, 473288, 94168829, -473288], [4457627906, 43590080, 1586320, 4510896, -1503632, 1503632], [0, 99125008, -7748432, -4676520, 10563339, 4676520], [3613000782, 17004672, 2994144, -11066976, 3688992, -3688992], [-969906992, -262021296, -13673782, -4767966, 1589322, -1589322], [1087601882, -292379760, -19433220, 17225460, -5741820, 5741820], [-4009477696, 1476544, 1240088, -6253512, 2084504, -2084504], [0, 181725426, -15547264, -17968135, 22093703, 17968135], [1842527158, -8945808, -1664956, 6307020, -2102340, 2102340], [0, -191606928, 13039824, -4524696, -150246939, 4524696], [5969912816, 80736112, -3515746, 43205862, -14401954, 14401954], [-4255897682, 109948560, 1818620, 23164020, -7721340, 7721340], [0, -413719824, 32074576, 17662120, 6205033, -17662120], [-117100560, -105366672, -17145474, 60975558, -20325186, 20325186], [0, 125639338, -8057152, 6419605, -100903765, -6419605], [0, -338345792, 22611776, -10890464, 122706119, 10890464], [0, 119718186, -6177152, 16619029, -73496213, -16619029], [3456636338, 86251248, 5343396, -2978964, 992988, -992988], [0, 456147406, -34906144, -16269305, 96378905, 16269305], [0, 133492864, -8667776, 6072000, 165802467, -6072000], [0, 142167648, -9508576, 4523792, 132240281, -4523792], [0, 217020754, -17262048, -12323959, -144610217, 12323959], [0, -213420030, 10553888, -32832799, -14406913, 32832799], [-2799737504, 393879648, 31380716, -51291972, 17097324, -17097324], [6353269808, 718168496, 43160662, -17617026, 5872342, -5872342], [0, 360340638, -24127232, 11279695, 208203697, -11279695], [0, -204443712, 10476352, -28887392, -44732687, 28887392], [4523210672, 18465072, 1924294, -4851666, 1617222, -1617222], [-4596942112, 215298528, 21702876, -52605972, 17535324, -17535324], [0, 118772442, -3002688, 38367405, -165459309, -38367405], [-3942277226, 35916768, 8955656, -37585512, 12528504, -12528504], [1091432786, -882950672, -42391324, -35972052, 11990684, -11990684], [0, -679204898, 51661152, 22025615, 141353233, -22025615], [0, -623825184, 42607776, -13658160, -60137751, 13658160], [0, -766011230, 52672480, -14298255, -53965137, 14298255], [-2741240250, 27955680, 18746760, -92845800, 30948600, -30948600], [0, -815185296, 60613072, 16698856, -72902267, -16698856], [0, 629143078, -40351776, 32109107, 85422061, -32109107], [-3339096592, 529316208, 46329966, -91386954, 30462318, -30462318], [0, -250614416, 21949904, 28342120, 33860531, -28342120], [0, -417787218, 22142624, -53895241, -268383319, 53895241], [19246649840, 640249200, 46283950, -57858570, 19286190, -19286190], [0, 644905578, -39834912, 43608405, -212738613, -43608405], [1459090998, -822961248, -23381736, -120627000, 40209000, -40209000], [0, 1169944224, -82856480, 4976752, -278764715, -4976752], [-22737014592, -472545600, -27998520, 9428328, -3142776, 3142776], [0, -713599482, 56687168, 40010435, 60367613, -40010435], [-208153810, 1611554496, 82449232, 38240496, -12746832, 12746832], [0, 180528912, -9689168, 22440280, 363266305, -22440280], [21714192528, -231833328, -8330046, -24567750, 8189250, -8189250], [0, -614070528, 50254592, 44746880, 317599661, -44746880], [-22247368608, 1138834272, 47909724, 82937772, -27645924, 27645924], [-3914129104, -967592272, -72738074, 102507918, -34169306, 34169306], [17172800206, -1080120432, -69599044, 51798708, -17266236, 17266236], [10930855946, -420351600, -60503940, 200615796, -66871932, 66871932], [0, -1324651622, 100907264, 44025037, -342376909, -44025037], [0, -807025328, 64798832, 50079160, -417889873, -50079160], [1492089750, 2316344736, 128873112, -1011384, 337128, -337128], [6780832016, -466262640, -41472270, 84071466, -28023822, 28023822], [0, 1333255552, -105687424, -73184192, -55027021, 73184192], [-16973907074, 816970896, 10298492, 189479412, -63159804, 63159804], [27353852624, 586417488, 33142186, -3042558, 1014186, -1014186], [-5173711936, -526722624, -50104008, 112544856, -37514952, 37514952], [0, 59010258, -13668192, -66172215, -192298857, 66172215]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_72_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_72_8_d_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_72_8_d_b(:prec:=6)
    chi := MakeCharacter_72_d();
    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_72_8_d_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_72_8_d_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_72_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![412405245440000, 0, 19577926400, 0, 254032, 0, 1]>],Snew);
    return Vf;
end function;