
// Make newform 722.4.a.f in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_722_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_722_4_a_f();".
// 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_722_4_a_f();".
// 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 := [-18, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_722_a();"
function MakeCharacter_722_a()
    N := 722;
    order := 1;
    char_gens := [363];
    v := [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_722_a_Hecke(Kf)
    return MakeCharacter_722_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 := 4;
    raw_aps := [[-2, 0], [-4, -1], [-3, -3], [-7, -4], [-9, 1], [-2, -13], [-39, -2], [0, 0], [30, 13], [-12, 21], [-128, 44], [-110, 28], [30, -10], [335, 7], [-159, -71], [618, -17], [156, -25], [101, 111], [-650, 77], [-42, -116], [281, -184], [-704, 58], [-432, 194], [24, 188], [-596, -102], [-1266, 116], [790, -160], [-180, 193], [394, 333], [-522, 260], [-1370, -260], [-687, -111], [2001, -174], [-1717, 303], [987, 179], [-650, -560], [110, 28], [-2140, -96], [-282, 162], [642, -480], [126, -514], [3454, 248], [-27, 1108], [-1820, 378], [702, 646], [245, -36], [736, 463], [-3278, 32], [-1638, 1093], [-3337, -307], [1005, 1011], [4113, -576], [538, 442], [-735, 567], [5568, 492], [2157, 237], [5160, -86], [-1690, 405], [2459, -1381], [-1074, 14], [191, 449], [954, 133], [-488, -748], [7119, -890], [4232, 19], [3084, -1173], [-3782, 1751], [-7112, -396], [5145, 883], [2099, 773], [8748, -621], [-6267, -810], [1424, -1764], [-38, -1359], [2896, 1443], [-420, -1982], [-843, -1477], [-817, -413], [-1608, 72], [4552, 752], [-2844, -1416], [-6194, 103], [-3180, 1510], [2626, -268], [4318, -1766], [3801, 663], [7524, -2214], [7031, 1038], [2175, -2997], [1613, -1679], [-4671, 1187], [7212, -120], [7882, 672], [1788, -3144], [-10627, 2313], [-14910, 1153], [-6636, -806], [9900, -1408], [-8300, 2653], [-5371, -3837], [8404, -216], [-5397, 2131], [-9882, 546], [8280, 504], [20468, -1176], [-4957, 1712], [1725, -5039], [6438, -3068], [-20280, 2032], [10474, -298], [-14852, 1410], [18047, 909], [-4785, 3381], [-8944, -34], [-24649, -657], [19812, -598], [-4489, 1937], [-10395, -180], [-12609, -609], [-9840, -1543], [11662, -2927], [70, 2970], [13752, -57], [-12852, -3096], [12557, 1019], [-15078, 4222], [-14182, -540], [12129, -3356], [13655, -1506], [22430, 590], [10163, -1453], [-5820, -2736], [-30584, 1192], [-21787, -3021], [11637, -46], [37019, 502], [-4872, 4011], [-6302, 1933], [7290, 91], [32931, 2106], [250, -6077], [3783, -7137], [-1267, 3890], [4614, -543], [30598, 2649], [13422, -8562], [362, -4472], [-11238, 8814], [-30301, -1879], [16038, 1696], [-12080, -5721], [9027, 4581], [-6973, 7369], [618, -708], [-12674, 6631], [13086, 7470], [8534, -9301], [28248, -1113], [5321, 8928], [38760, -2707], [11004, 5356], [-29040, -162], [920, 6160], [-11796, -3072], [-33300, 648], [22800, -3546], [-578, 9034], [5447, 183], [34000, -6260], [3351, -8073], [-31608, 3333], [-24698, -4349], [-40584, -3744], [9416, -8599], [1924, -1940], [53229, 63], [13268, -6332], [5667, 11165], [4552, 8456], [-10663, 8825], [-16189, 7700], [-21294, -145], [21418, -7460], [-2202, 11782], [-39231, -5800], [-15885, 9177], [15676, -3177], [24838, 2110], [-9686, -608], [28026, -3919], [-6122, -2212], [-13497, 2091], [-25436, -260], [-3912, -5925], [-9528, 11220], [-28956, -8808], [-48355, -5308], [15230, -934], [-15804, 6113], [-43677, 5868], [30480, -4170], [-30386, 1702], [-10802, -6469], [-32294, -1490], [5784, 11322], [17571, 459], [-39301, 9846], [28950, 5649], [36825, 492], [-47360, 2823], [17876, -15393], [-33882, -418], [48251, -2393], [55014, -5705], [11070, 626], [-32762, -11584], [34958, 6537], [-35712, 13878], [-24588, 5762], [13317, -12973], [-20126, 13152], [-9110, -92], [16338, -6124], [-40525, 114], [-1212, -16859], [13709, -849], [-30402, -10416], [47208, -10910], [-20594, -5944], [-60057, 11649], [-15487, -19245], [59686, -6251], [-20288, -7296], [-35226, -6384], [-15811, 535], [21849, -122], [-83833, 2385], [8253, 4293], [51468, 2758], [-25968, -1684], [-19050, 18050], [-4363, 21431], [-41614, -529], [-71624, 9077], [45102, -13150], [-26847, -11395], [13025, -1719], [-40908, 2160], [97000, -1044], [-19401, -13494], [-2878, -12484], [10347, -11400], [-22806, 11973], [-3008, -14690], [36681, 11957], [31368, -6702], [-817, 15685], [30850, 9486], [-73914, -4428], [-646, 1380], [-30134, -14810], [-53178, 7818], [-1483, 5005], [-7436, 3565], [29721, 13687], [32146, 12213], [67518, 8209], [-27729, 2820], [-17120, 21065], [849, 7551], [64366, 9315], [-34904, 18917], [-18943, 31976], [7877, 21782], [29608, 11262], [-59398, 14427], [10863, -31019], [67858, -2361], [-14906, 19242], [-20481, -14537], [-6606, -18540], [52202, -4851], [46011, -9366], [-52760, -6439], [-673, -11533], [-35745, -10305], [28451, -9798], [-6312, 12634], [59861, -5770], [-22140, 31762], [11214, 15252], [66627, -14665], [-62868, -11834], [19494, -28662], [9718, -4832], [-42138, 282], [87172, -4502], [-77835, -9049], [154110, 623], [-18079, -16365], [-87289, -9079], [-32676, -13781], [36713, -16844], [-124254, 12041], [92981, 4673], [55636, -13454], [-18102, 4349], [-95456, -2025], [11127, -5625], [124526, -5638], [97047, -22657], [57570, -7804], [9708, 630], [-2738, -14654], [-17400, 14616], [17404, -14516], [74001, -23629], [-56904, 18042], [31727, 19580], [-21573, 1469], [27736, -32415], [77429, 7454], [29796, -15171], [-84584, -17026], [86412, -11219], [-73532, -9146], [51154, 22045], [69100, 1537], [103170, 9090], [-165993, 7971], [-42631, 28217], [62112, -5857], [-34162, 22777], [47799, 8805], [-69361, -10055], [-95595, 14541], [-27578, -14683], [-68706, 6854], [17651, -22244], [-150118, 3947], [58714, -2327], [-8031, 1130], [-71220, -8235], [48832, -28078], [46104, -21107], [12936, -22380], [-7054, -14368], [54268, -38019], [-5172, -8058], [-139113, 9559], [-51158, 26386], [-31520, -8558], [-110211, -14355], [170170, -670], [-1784, 1066], [-86832, 36048], [128598, 15393], [-53868, -7236], [-94443, -23354], [-182910, 9360], [-136393, -16513], [2226, 43452], [11994, 6864], [14490, 29677], [112061, -6585], [-127946, 22922], [53154, -6756], [224314, 216], [-24752, 2582], [120792, 3970], [61108, -27171], [-25221, 50974], [95808, -24223], [88967, -24581], [-59497, 31111], [-116466, 25343], [-148176, 19840], [-171115, -4209], [-91257, 19162], [141496, -4684], [3798, 47904], [22005, 36451], [18875, 6640], [-66603, 8471], [-104600, 7983], [-212316, 3966], [32546, 24567], [-55906, 1906], [171173, 8747], [117414, -9570], [-80498, 33428], [16104, 23511], [5076, -4458], [-154123, 51], [-184458, 16698], [10582, 7012], [-62804, 1746], [-84006, 11474], [-41294, 5886], [-44634, 5526], [89332, 20346], [-81183, 9647], [31732, 19498], [-144438, 1186], [113928, -34810], [-57913, 21582], [41591, 24769], [-60210, -19230], [217168, -1923], [-203355, -12443], [34540, 35748], [-170007, 26227], [167796, 22155], [96617, -19665], [-209356, 17959], [76122, -45290], [-140916, -17250], [7432, -53844], [-100104, -1075], [-12090, 52558], [243696, -4542], [-130772, 27823], [-98793, 11644], [13668, 23477], [-17552, -60230], [-172314, -23667], [-84276, -25461], [-21045, 2024], [-121093, -26293], [31047, 5646]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_722_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_722_4_a_f();".
// 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_722_4_a_f(:prec:=2)
    chi := MakeCharacter_722_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_722_4_a_f();".
// 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_722_4_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_722_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![2, 9, 1]>,<5,R![-144, 9, 1]>],Snew);
    return Vf;
end function;