
// Make newform 36.7.d.e in Magma, downloaded from the LMFDB on 15 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_36_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_36_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_36_7_d_e();".
// 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_36_7_d_e();".
// 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 := [25, -40, 64, -10, 8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [175, 79, 35, 13, 5, 1], [-105, -1721, 155, -307, -35, -39], [-525, 1073, -125, 131, -5, 17], [-1575, 2113, -415, 251, -5, 27], [-1085, 2017, -445, 179, -5, 33]];
    Rf_basisdens := [1, 20, 20, 10, 20, 10];
    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_36_d();"
function MakeCharacter_36_d()
    N := 36;
    order := 2;
    char_gens := [19, 29];
    v := [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_36_d_Hecke();"
function MakeCharacter_36_d_Hecke(Kf)
    N := 36;
    order := 2;
    char_gens := [19, 29];
    char_values := [[-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 := 7;
    raw_aps := [[2, -1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [7, 0, 1, 0, -1, 1], [3, -12, 2, 2, -4, -1], [5, -38, -28, -3, 8, 6], [-496, -176, 6, 8, 10, -2], [-1916, -352, 22, 16, 10, 6], [-119, 346, -36, 29, 72, 18], [-88, 252, 124, 110, -56, -30], [14533, -1056, -17, 48, 113, -65], [-319, 1400, 418, 68, 28, -65], [4982, -4048, -132, 184, 500, -316], [10936, -352, 202, 16, -170, 186], [-1173, 3294, 356, 767, 152, -34], [-402, -712, -316, 1196, -424, -18], [-78395, 352, -353, -16, 321, -337], [6099, -18902, -1424, -2603, -1856, -72], [-5374, 22000, -1416, -1000, -584, -416], [-561, -3822, -368, 3529, -1856, -248], [-7396, 20420, -756, 3346, 2952, 618], [-220198, 18656, -1464, -848, -232, -616], [3689, 3200, 7898, -5976, -1108, -1501], [4091, 910, 4772, -7209, 488, -714], [-116846, -11968, -1868, 544, 2956, -2412], [552974, -30976, -420, 1408, 3236, -1828], [323893, -84832, 4495, 3856, 3217, 639], [329, 3668, -8162, -7774, 7684, 2641], [779, -7678, -4008, 865, 240, 708], [-213196, -127600, 15114, 5800, -3514, 9314], [-1151390, 0, 1252, 0, -1252, 1252], [3675, -52872, -8346, 20820, -13548, -867], [3505, -130, -15584, -16833, 14080, 4944], [-178868, -85536, -1250, 3888, 9026, -5138], [46953, -122610, -5888, -31865, -8096, -368], [950479, 384384, -31895, -17472, -3049, -14423], [-26017, 132236, 36434, -4722, 8348, -4681], [972134, 292336, -8580, -13288, -17996, 4708], [58529, -213502, -76044, -39983, 12984, 14838], [71406, -191852, -25616, -54518, -2720, 3816], [3073255, -382272, 16849, 17376, 17903, -527], [27797, -185146, -83376, 7843, 4032, 14568], [-1463596, -56496, -38502, 2568, 43638, -41070], [19632, 2192, -79600, -91768, 74624, 25704], [-2069254, -200288, 55032, 9104, -36824, 45928], [8176465, -211552, 9643, 9616, 9589, 27], [39261, -169692, -31434, 1386, -16620, 2469], [-156749, 482218, 45232, 74133, 40000, -872], [-268049, 750760, -77602, 85708, 147428, 37505], [-178445, 902406, 241484, -34253, 61304, -30030], [6580160, -390896, 8934, 17768, 26602, -8834], [-9920798, -787072, -52988, 35776, 124540, -88764], [341568, -1024664, -51992, -151724, -109232, -9540], [-8100082, -774752, 19212, 35216, 51220, -16004], [-258279, 798930, -131196, 1785, 214728, 57654], [-5216258, 2509056, -62720, -114048, -165376, 51328], [-370714, 646132, -12064, 425082, -32224, -3360], [-446291, -143968, 138775, 6544, -125687, 132231], [39803, -64432, 269790, 104608, -186204, -75999], [-3645724, 529232, 22602, -24056, -70714, 46658], [-14176514, -1674816, 93376, 76128, 58880, 17248], [82981, -325130, -304448, -154629, 149248, 75616], [-3945971, 2301024, -184985, -104592, -24199, -80393], [-667557, 2073402, 362064, 399837, 57792, -50712], [-93370, -308532, -80936, 365510, -154448, -12252], [-11777590, -5984, 138408, 272, -137864, 138136], [25431865, -1061280, -42173, 48240, 138653, -90413], [510013, -1782674, 60008, 14551, -369712, -71620], [19648058, -441760, -17016, 20080, 57176, -37096], [-604527, 2156722, 265204, 146857, 216712, -8082], [-23453086, -1150864, -142728, 52312, 247352, -195040], [7541218, -3697408, 234436, 168064, 101692, 66372], [33524, -999532, -656628, 190714, 69384, 121002], [-1233051, 3486192, 31586, 595328, 414620, 63839], [7439594, -4823632, 258672, 219256, 179840, 39416], [455787, -937242, -691668, -834525, 483048, 195786], [431944, -1084432, -158624, -380808, 18784, 29568], [-42490025, -2660416, 167377, 120928, 74479, 46449], [-2084998, -1482448, -150576, 67384, 285344, -217960], [14934976, -1935648, 267922, 87984, -91954, 179938], [-19725562, 4086016, 255732, -185728, -627188, 441460], [-97829, -421402, -750980, 65379, 271960, 170490], [46683908, 954448, 267306, -43384, -354074, 310690], [1431658, -3555560, -66948, -1024900, -248856, -30318], [-44374, -3150400, -396456, 143200, 682856, -539656], [529965, -1020084, 990686, 10526, -690556, -280207], [-773943, 1543970, -930796, 244577, 663176, 265662], [46374268, 5557024, -875666, -252592, 370482, -623074], [13967054, 6121984, -802596, -278272, 246052, -524324], [-66747185, 5998784, -363047, -272672, -182297, -90375], [-1147405, 2483888, 8878, 1030928, 74692, 10969], [-1688817, 7325598, 1351068, -77121, 726936, -104022], [2368774, -8519712, -575332, -266144, -1209976, -105774], [-311453, -576092, -1652622, 137882, 666588, 386535], [216259, -1128910, 2062360, 1409913, -1771568, -638988], [2574187, -9405782, -2021504, -992427, -380672, 273472], [-882600, 2250492, -1190148, -109458, 1058088, 374706], [-93184847, -5994208, 4027, 272464, 540901, -268437], [-60996416, -4789664, -564302, 217712, 999726, -782014], [-1009121, 800254, 680172, 2180783, -1007832, -281334], [-85058644, -12776368, 606882, 580744, 554606, 26138], [-3204083, 11971042, 1542668, 509473, 1282184, -43414], [-176921189, -3589696, 496165, 163168, -169829, 332997], [-3426725, 11941838, -143996, 73335, 2283592, 404598], [-33197528, 18612000, -64934, -846000, -1627066, 781066], [-4635743, 11993254, -280952, 2725491, 1367152, 274684], [62718170, -2995168, 1183080, 136144, -910792, 1046936], [3334131, -6415582, 1601000, -2581711, -1035280, -439380], [333528994, 2258432, -420764, -102656, 215452, -318108], [-996388, 2973084, 1565284, 1260638, -697928, -377202], [50304482, -7381088, 1411728, 335504, -740720, 1076224], [4339083, -8235864, 389494, -4400852, -88652, -79691], [110299826, -15652560, -118152, 711480, 1541112, -829632], [-19964522, -23622720, 149752, 1073760, 1997768, -924008], [2444929, -12841490, -4601680, 37303, -120928, 746792], [-1955161, 7022396, -2202606, -1304090, 2907036, 851607], [23858116, 4421472, 271126, -200976, -673078, 472102], [-1421859, 6845106, 3401788, 793417, -714968, -686126], [7385116, -26389484, -2813316, -1523206, -2970168, -26142], [-191323565, -17543680, 1776541, 797440, -181661, 979101], [419697, -2501722, -343384, 452723, -467152, -20628], [-141849658, 12132208, -932052, -551464, -170876, -380588], [-58321342, -22822976, 1999824, 1037408, 74992, 962416], [160274971, 22535744, -742667, -1024352, -1306037, 281685], [3087505, -10639958, -4259412, -2651131, 1128888, 898050], [2164501, -3593222, 123668, -2566835, 227000, 17222], [9019513, -3622432, 422563, 164656, -93251, 257907], [-10620928, 35534224, -1028730, -1615192, -2201654, 586462], [2663070, 3004632, 6128868, -4516356, -807432, -1156050], [1099631, -14501332, -4913518, 4001118, -1762660, 525143], [99912200, -21446128, 2778654, 974824, -829006, 1803830], [7347819, -16025838, 768648, -6053463, -1119120, -314628], [-1273542, 18313300, 9683752, -3328310, -160016, -1640628], [-11407671, 37833072, 2324938, 3081952, 4775500, 408427], [463737008, -24012912, 1309878, 1091496, 873114, 218382], [-132956372, 3405600, -1791170, -154800, 1481570, -1636370], [206183906, 10693408, -236064, -486064, -736064, 250000], [351566137, -8670112, -735341, 394096, 1523533, -1129437], [8835381, -26137830, -1823852, -4434467, -2325992, -83690], [-53577029, -3220800, 3370789, 146400, -3077989, 3224389], [-428778692, -2853664, 617422, 129712, -357998, 487710], [-3594237, 14318382, 9205956, 4271271, -3520008, -2120994], [354699889, -20234016, 2646379, 919728, -806923, 1726651], [-3003333, 4129308, -2271878, 2911990, 818188, 515011], [-2509841, 3010282, -8647032, -1139563, 5315280, 2327052], [-33682588, 74005008, -3410694, -3363864, -3317034, -46830], [8717248, -18039132, 2966228, -6633566, -2377864, -890682], [890474126, -17134480, 930324, 778840, 627356, 151484], [-743247992, -25190880, 4124026, 1145040, -1833946, 2978986], [5199763, -6101210, 3091804, -6196221, -366296, -576350], [-9857336, 20516032, 5098800, 12255776, -3298560, -1399560], [-680929894, 26848624, -1782768, -1220392, -658016, -562376], [17352310, 9091456, 1273048, -413248, -2099544, 1686296], [-14447075, 50933242, 1395684, 1076621, 8448408, 1175454], [3735434, -16893684, 3804352, 4496006, -6755744, -1760016], [-7796153, 30715918, 6317612, 1683895, 1968968, -724774], [-7272032, 38595192, 6815864, -4294628, 5439152, -229452], [14912035, -42733364, -3267654, -8480434, -3198516, 11523], [462270328, 30263904, -4057622, -1375632, 1306358, -2681990], [-351896206, -14080000, -1214736, 640000, 2494736, -1854736], [-41513033, 86501184, -259775, -3931872, -7603969, 3672097], [4451813, -13537562, -13838704, -9380685, 7898816, 3622920], [-393302384, -39944608, 6771874, 1815664, -3140546, 4956210], [-3941335, 24046532, 16399630, 2921498, -4786652, -3531047], [2922001, -2837894, 3380412, -2922835, -1126248, -751110], [-166348808, 52332896, -3716150, -2378768, -1041386, -1337382], [-19818390, 42841148, 524144, 18057950, 998912, 79128], [16482861, -41013000, 3576858, -9265692, -6003732, -1596765], [244346138, 30772720, 2840352, -1398760, -5637872, 4239112]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_36_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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