
// Make newform 765.4.a.i in Magma, downloaded from the LMFDB on 25 June 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_765_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_765_4_a_i();".
// 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_765_4_a_i();".
// 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 := [-3, 0, 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_765_a();"
function MakeCharacter_765_a()
    N := 765;
    order := 1;
    char_gens := [596, 307, 496];
    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_765_a_Hecke( : Kf := Kf)
    return MakeCharacter_765_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]];
    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, 1], [0, 0], [-5, 0], [1, 9], [19, 13], [-40, 28], [17, 0], [-90, -6], [21, 101], [108, 46], [35, 141], [176, -106], [-172, 142], [-44, -166], [174, 8], [82, 64], [718, -66], [-38, 268], [-22, 308], [755, -119], [544, 18], [-479, -437], [-124, -238], [102, -742], [506, 436], [-282, 410], [606, 8], [-359, 237], [686, 176], [108, -562], [-1252, -462], [339, -151], [-1708, -132], [-373, -759], [-1458, 560], [-234, 978], [1650, -932], [-3269, -21], [109, -1927], [1620, -382], [-954, -434], [-1516, 1222], [1708, 1320], [-24, -902], [1900, 642], [-765, -751], [-2677, 569], [-1952, 530], [-2155, 1361], [2962, 1954], [-2854, -528], [-4480, -740], [420, -1406], [2552, -1940], [500, -1392], [236, -318], [3422, 2124], [-2428, -468], [-1530, -1820], [-2610, -1908], [2295, 3383], [-2694, -180], [1442, -3668], [2427, 1745], [-988, -2474], [3650, 4092], [-5486, 934], [-3546, 2556], [-367, 629], [3574, 4132], [-3214, -1956], [-4082, 142], [9485, 453], [-2144, 2924], [-6455, 1023], [-8052, -850], [1114, 6510], [-1346, 2392], [2442, 4812], [1546, -1600], [9993, -1369], [-1942, -8094], [-3505, 3153], [-2560, -1308], [-1839, -4577], [18, -6624], [4212, 3178], [9516, 568], [-15262, -1956], [3162, 4532], [12092, 1214], [-10035, -2609], [6217, 1057], [3298, -5898], [-15113, -3111], [-21, 7199], [7858, -1448], [4206, -3800], [8582, -6100], [-12716, -4162], [8447, -5085], [15052, 1952], [9968, -3114], [-18238, -3660], [15015, 1757], [-13440, -7032], [24828, -774], [20490, 1400], [-1228, 10448], [-1676, -1238], [6693, -4291], [-15830, -2712], [6732, -7826], [5329, -1365], [14414, 6622], [2316, 3170], [14371, 579], [6326, -12072], [-15400, 4574], [10724, 4236], [-158, -1864], [-8312, 8190], [14226, 3996], [30321, -2751], [3989, -3605], [-12546, -8122], [-4716, -4758], [8851, -6355], [10962, 5332], [-16166, -8880], [-11618, 2722], [-9285, -4857], [11557, -15649], [-232, -5248], [17706, -12274], [5370, -12538], [13632, 7128], [-30435, 925], [3938, -3396], [7474, -2208], [-15005, 10653], [9346, -19252], [32471, 7735], [5163, -17821], [10654, -2928], [21469, -5621], [8908, 8562], [-14404, 15874], [5910, -12062], [-16634, 8064], [6922, 9380], [-16404, 14550], [-446, 15708], [-17201, -4465], [9027, -2321], [-20803, 10919], [-22784, 5736], [-20740, -16474], [-33158, 1860], [-24412, 9406], [35467, -1437], [-15552, -12800], [3584, -11662], [158, -10298], [26882, -6528], [6753, 26065], [-56143, -2573], [-7028, -6610], [4746, -10372], [50644, 3990], [-8364, -136], [-13262, 3574], [-9945, -1919], [47968, -8080], [-42938, -2274], [-26254, -2476], [-33381, 13069], [-22344, 6566], [4768, 24666], [18662, -10470], [20670, -12876], [29745, -14577], [16794, 3716], [-31362, -7152], [14124, -12494], [-40966, 10518], [-8710, 7772], [3690, -30092], [464, 10450], [29029, -2877], [-35622, 5040], [-31013, 6303], [-28006, -26714], [42014, 6426], [7531, 13507], [-16396, -13590], [-41612, 15430], [-8974, 9712], [2640, 42078], [-8214, -7052], [-29616, -6714], [-28855, -11257], [-25042, 16484], [-37238, -6078], [-10904, 14652], [2304, -40808], [2524, 40748], [284, -49074], [-14842, 16896], [60748, -12652], [-15094, -11588], [5350, 5122], [23859, -13701], [1596, -12714], [47091, -18639], [-44024, -20154], [5178, -16616], [-14378, -3352], [17313, -3219], [-63772, 20640], [-36306, -5152], [-57539, -1181], [-870, -42352], [39551, -18249], [-14334, 19724], [-46418, -7330], [-82490, 7896], [-54739, -18565], [63052, -16562], [36313, -85], [17582, -44940], [-23691, -6981], [74298, 2662], [2942, -27182], [-202, 16500], [36976, 26622], [-1124, 31034], [-53874, 5436], [64223, 16905], [34626, 38738], [26195, -28265], [93160, -104], [63050, 21972], [-10310, -12438], [-56626, -17900], [-22701, -19531], [51045, 18253], [7065, -15245], [9590, 14922], [-44320, 35350], [-50470, 11660], [13538, 41296], [22836, -10846], [11816, 57294], [70656, 29336], [-10316, -55952], [-1924, -9366], [199, 27395], [44160, -21850], [103696, -10052], [-63017, 8719], [-19786, -16032], [-73040, 16878], [45618, -21304], [39118, 14708], [9972, -28784], [-48058, -50276], [3802, -19728], [-30605, -20245], [40366, 9764], [49816, 26846], [20766, 5664], [10426, 42172], [72746, -36974], [-25042, -34768], [-42500, 24814], [20248, -22578], [-43418, -15942], [-16978, -49210], [-878, -52754], [-5770, 21664], [-61707, 22887], [-75771, 18425], [64246, -14044], [123711, -14381], [60564, -4924], [-8388, -35702], [8204, 5998], [-86638, -19526], [-3174, 48678], [-12150, -23268], [-32383, 34525], [-3772, -40608], [-11309, 7765], [-46934, 55532], [-11362, 11684], [17572, -47668], [63952, -42292], [-34697, 34525], [32252, 45730], [-48940, 7620], [39348, -41708], [-23855, 34715], [29151, 31835], [-78335, -37349], [3482, -33084], [27914, 47816], [-45608, 54978], [4364, 32680], [-2706, 52576], [23105, 10553], [47520, 30014], [26242, 88848], [45508, -10206], [50330, -73556], [140894, 12280], [-84606, -50874], [78647, -57443], [-128822, 13868], [10646, -61616], [-56851, -22317], [-67518, -60704], [-15426, -25000], [-59070, -29204], [64362, 49476], [87670, 20196], [-9709, -45463], [98339, 20059], [-18959, 27341], [70986, 3876], [96902, -11828], [-130356, -9402], [81189, -17157], [-70170, -41740], [11119, 101085], [62007, -22433], [36966, 44016], [-12668, -1026], [-51980, -82074], [62076, 25254], [115262, -14196], [-3006, 64332], [2918, -76940], [-74936, 2396], [-86844, 54048], [-47375, 70399], [99986, 54080], [41726, 63780], [10397, -3829], [31228, -18170], [100442, 16658], [-32730, -75792], [-24742, 14048], [-33709, -4381], [28162, 12362], [-12780, 6940], [43278, -48018], [-150359, -9113], [-70476, -8262], [81024, 19086], [18436, -13998], [-29778, -4084], [-19198, 79232], [177009, 17415], [34760, 41634], [-13258, 108556], [-1066, -44968], [-7466, -34252], [225320, 12826], [40122, 99126], [55605, -14641], [-23583, 14497], [35634, -61054], [31636, -43256], [165296, 8490], [46929, -84565], [84537, 80875], [138368, -53388], [18486, 54292], [-62110, -65216], [-61892, 65666], [-213802, -8148], [151209, -9663], [-50586, -66204], [-94085, 70045], [152609, -59247], [-129534, -32662], [-61788, -36780], [96953, 3965], [-49538, -25012], [-102224, 101362], [-31986, -126984], [-76924, 14436], [-88482, -9292], [49530, -62482], [126504, -82950], [51224, 57948], [39994, 112288], [196983, 18285], [138526, 49166], [122342, -17928], [19136, 124144], [-5738, -126072], [-224494, -14260], [-62362, -109984], [-208013, -24107], [20012, -62220], [-9342, 89974], [102180, 46506], [77077, 34831], [-142070, 46360], [-147984, 18848], [-19090, 13040], [-14527, -59837], [50170, 26276], [-112848, -1050], [-67743, -28761], [43897, -3639], [147154, 57304], [58170, -72616], [16754, -5736], [-62814, 61232], [124193, 60869], [242518, -10866], [47186, -27320], [192834, 9168], [123871, 17867], [206208, -12990], [18240, -45208], [78165, 55075]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_765_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_765_4_a_i();".
// 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_765_4_a_i(:prec:=2)
    chi := MakeCharacter_765_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_765_4_a_i();".
// 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_765_4_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_765_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![1, -4, 1]>,<11,R![-146, -38, 1]>],Snew);
    return Vf;
end function;