
// Make newform 768.4.a.q in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_768_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_768_4_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_768_4_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 := [-12, -11, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-29, 0, 4], [-29, -8, 4]];
    Rf_basisdens := [1, 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_768_a();"
function MakeCharacter_768_a()
    N := 768;
    order := 1;
    char_gens := [511, 517, 257];
    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_768_a_Hecke(Kf)
    return MakeCharacter_768_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 := [[0, 0, 0], [-3, 0, 0], [-3, 0, -1], [5, -1, 0], [0, 2, -2], [-18, -1, 3], [6, 2, 6], [-12, 2, 6], [54, 2, 0], [-57, 2, -5], [109, 3, -12], [-96, -11, 3], [-42, 14, -6], [84, -10, 18], [66, -6, 12], [-369, 10, 11], [-60, -8, -8], [-516, 9, 3], [204, 0, 48], [-270, -6, -36], [-146, -16, -24], [1, 7, 12], [-384, 2, 14], [42, -4, -12], [-418, -4, 36], [-921, -30, -37], [-193, 13, -96], [-252, 20, -20], [-870, 7, -33], [858, -12, 12], [-77, -59, 36], [804, 8, -40], [-42, -78, 102], [-732, -56, 72], [-999, -32, 83], [749, 7, -48], [-1080, -79, -33], [1020, -74, -78], [-1524, -44, -48], [-1215, 32, 43], [-996, -16, 32], [-750, -109, -165], [-1668, 160, -12], [-1438, 64, -120], [-645, 182, -157], [2327, 29, 216], [-3636, 64, -48], [3211, -3, -108], [2376, 78, 290], [2190, -13, 207], [546, 140, -300], [-1776, -180, 132], [938, 36, -252], [384, 74, 310], [-2094, 72, 120], [-2664, -44, 468], [3687, 50, -437], [1483, 53, -420], [2106, 71, -321], [-3246, 72, 264], [1836, -256, 192], [2271, -254, 131], [-4212, -96, 144], [-6012, 152, -108], [2602, 0, 168], [1839, 78, 487], [-348, 92, 36], [-3466, 128, 312], [2424, 138, -890], [4404, -67, -297], [3066, 252, -444], [-6366, 26, -372], [421, -37, 516], [1668, 113, -333], [2460, 82, 534], [-6420, 48, -12], [4989, -136, -409], [3900, -299, 471], [-3066, -186, -366], [-3578, 484, -612], [4152, 238, -958], [4770, -289, 543], [-3906, -66, 828], [-2818, -456, -168], [7211, 145, 96], [5496, -262, 310], [-1818, -510, -90], [-3482, 252, -732], [837, 224, -425], [3847, -359, -180], [-9912, -42, 26], [1890, -274, -936], [-799, -69, -936], [-11892, -188, -212], [-6060, -144, -240], [3690, 498, 396], [-3753, -34, -209], [9918, 150, -702], [1692, -510, -378], [-5790, -13, 555], [2988, -310, 174], [-9351, -268, 1087], [-6984, -542, -610], [-6090, -306, 282], [4524, 292, -1620], [2174, -464, -168], [7548, 244, 508], [-486, 276, 1260], [8370, -514, -72], [-2186, -456, 1104], [-8045, 445, -564], [-9372, 833, -957], [11106, 376, 216], [-13908, -168, -312], [-6727, -445, 1368], [-15090, 338, -186], [11628, 274, -1146], [-5346, 282, -288], [-11151, -52, -209], [-5148, 508, 596], [1944, -815, 1455], [6686, -240, -384], [-13227, 340, 275], [-7296, 214, 154], [-6228, 230, -222], [-2085, -714, -989], [-18594, -313, -501], [3774, 946, -24], [-5623, 955, -912], [-8802, 179, 255], [-6252, -812, -132], [6216, -8, 672], [-13139, -117, -948], [-13770, -9, 1251], [-9378, 490, -162], [-10318, -40, 432], [1467, -978, 587], [564, -378, -1230], [-10011, 1300, -509], [12294, -1302, -18], [-8868, -490, -318], [4167, 990, -673], [-3763, -729, -2832], [-444, -796, -356], [4314, -1313, 903], [27486, 286, 828], [10416, 1125, 1923], [-21498, -522, -78], [6228, 458, -690], [20844, 72, -1188], [-4116, -1223, -2205], [25986, 64, 480], [18300, 94, 714], [2424, 756, 84], [17028, 130, 1878], [16824, -300, 2100], [-9115, 871, -840], [-474, -1786, 2226], [-12950, 1200, -48], [33669, 752, -569], [27180, 880, -1312], [-21618, -138, 1890], [-19081, 1197, 264], [20880, -346, 682], [19062, -346, -1134], [37080, 244, -1548], [-10691, 243, -2028], [1236, -15, 2211], [3710, 1972, 780], [12969, 540, 263], [-8628, 396, -476], [30408, 949, 891], [14352, -152, -2424], [-19286, -752, -1104], [6529, 79, 1476], [-20478, -1272, -984], [3996, -1616, -48], [27921, -352, -1093], [-11461, 113, 2736], [-6264, 457, -57], [-2903, -1385, 180], [11664, -2198, -538], [19374, 1143, -3381], [32610, -56, 1992], [30732, 24, 1068], [7641, 1276, -2185], [-2298, 239, -741], [-49260, 664, -504], [-8990, -780, -1740], [648, 1728, -2088], [18290, 1560, -504], [36612, 800, 304], [5316, -1024, -192], [39885, -716, 1723], [-51804, -600, 2072], [10338, 1320, -408], [-13618, -1488, -3048], [9966, -1057, 99], [-12822, 656, 2784], [4500, -984, -396], [-25083, 1280, 1303], [36739, 1485, 204], [-16854, -805, 2907], [-1834, -608, 2040], [-19704, -194, 994], [-21477, 3326, -3461], [-35345, -1215, -2052], [3384, 2650, 2342], [67314, -372, 372], [42324, 34, -1674], [-26878, -184, 4032], [29037, -1268, 1571], [19763, 2097, 2136], [-20268, 224, 3184], [17214, -890, 1716], [-1802, -1240, 5448], [-18335, -1689, 4716], [9390, -70, 3486], [-23316, -1340, 4800], [-9987, -2048, 703], [18354, -253, 5067], [37499, -1607, -312], [-8130, -1442, -1974], [-38249, -455, 4476], [27120, -1150, 3470], [-20736, 1733, -3885], [-4758, 1500, 1812], [26466, 1334, -1776], [50939, -1279, 384], [-12036, 644, -4532], [-39918, 1231, -2241], [60924, -1526, -690], [3727, 2425, -1212], [57138, -864, -1488], [53220, 1346, -3690], [-4686, 918, -96], [-4690, 1124, 924], [-27927, 2616, -1429], [25872, -1442, 562], [14046, 1298, -408], [48168, 1266, -3058], [-5340, -3028, -3180], [7337, 2779, -336], [-25776, -27, 2403], [12522, -288, -2256], [-9666, -122, -1548], [4033, 279, 1788], [-39060, -140, 1964], [-39468, -2180, 4356], [-4068, 2556, 3096], [-66030, 2523, -237], [-3798, -1452, 4140], [-9186, 330, 5808], [-38726, 1800, 2904], [-52437, -902, -1841], [-4308, 44, -3532], [-19350, 2343, -81], [19548, 3556, -1236], [-49545, -698, -4633], [7318, 744, 5640], [73399, -647, -900], [11628, -536, -5272], [-23142, -2577, 3063], [-24672, -931, -741], [17886, -402, 2874], [-54084, 4612, -2916], [-10899, 2676, 187], [-101934, -820, -684], [-14052, 1582, 2538], [-63783, -1968, 3107], [18180, 1205, 2127], [-14844, 3788, -2460], [43402, -848, 720], [-33923, 1043, -2220], [33314, -64, 1728], [-83749, -631, 5400], [1128, 1350, 5626], [-56652, 269, -3321], [12790, 1176, 5712], [-21348, 540, -2428], [-9534, -186, 672], [10763, 4137, 3432], [-20166, -4690, -4704], [85116, 657, -1029], [68700, 966, -8526], [-106836, 1132, -744], [3434, -1732, 4428], [-16383, 420, -3673], [62501, 2647, -4344], [-27654, -1364, 8148], [19161, 468, -5537], [3228, -1704, 6776], [-32166, 2428, 1620], [92820, 696, 2296], [14856, 261, 5547], [17469, -2112, 799], [88579, -267, -2172], [52767, 274, -6829], [-15336, -922, 4282], [28932, -3314, 1098], [-87734, -2952, -720], [1797, -764, 3667], [-41255, -1881, 564], [-48684, -456, 3176], [-2172, 3574, -558], [-66838, -1660, -828], [-75264, -2630, -3482], [29838, 2619, -2361], [-58074, -2394, 8652], [-6060, 581, 3183], [-7476, -2088, -2004], [-25929, -3638, 8867], [9342, 2122, -10674], [28164, 434, -11466], [-41028, 1048, -4740], [2026, -296, -7224], [-8604, 4876, -3004], [-6258, -4590, -1992], [45542, -432, 936], [59586, -2108, 3948], [-104748, 792, -1848], [9274, 4504, -5040], [101415, -1158, -4445], [-78443, -1509, -4332], [-57402, -2554, 9666], [29438, -3828, -6252], [78948, 3570, -10026], [-39900, -5490, -870], [-26088, 4872, -9600], [12201, 1512, 8027], [119850, 1179, -933], [-92259, -816, 1231], [162859, 1141, -324], [53868, 700, 4676], [-8892, 5520, 864], [30216, 5958, 3610], [53136, 2421, 1683], [15234, -4532, 5604], [31918, 4360, 432], [10267, 4613, -2436], [-24888, 25, 13815], [-18306, -5146, 2898], [83979, 2602, -8449], [96923, -4095, 288], [49287, 4974, 2287], [28200, -3542, 4406], [103782, 1615, -9573], [-50316, 2636, -10476], [2190, 5346, 4008], [-61881, 2638, -625], [71028, 3838, -9894], [-15530, -5108, 5076], [142467, -1738, 5179], [46039, 2737, -828], [-14376, -1071, 5295], [94554, -3024, -144], [-122616, 4, 3636], [-109188, -1756, -1748], [43950, -966, 3486], [-10212, -1216, 11892], [-18048, -3371, -6525], [131082, -1604, -300], [71268, -7648, 1068], [32136, -314, 2650], [62004, -2108, 5196], [-24362, 5512, 4512], [-78933, -4006, -4145], [-114655, 2339, 2736], [-97466, -4880, -3744], [-24192, 8758, -6838], [-133428, 1730, -4314], [31392, -3752, 5256], [-101529, 4666, -4381], [9809, -4461, -1680], [-114162, 595, -2769], [-63048, 6818, -5698], [-90444, 824, 5892], [106226, -3888, -1392], [-111666, -2458, -6942], [-58334, -3796, 1788], [134385, 3016, 7699], [-46146, -3606, -2946], [-100603, -2737, 5712], [74994, -2880, 1248], [-43812, 1978, 4542], [23532, 2372, 2688], [79717, -2797, 7404], [-38286, 3439, 7935], [2388, 3304, 3720], [46398, 7886, -852], [-15598, 2616, -13272], [-36303, -3788, 1607], [-35220, 4568, -3704], [-83628, 5162, 606], [-51696, 5632, 1008], [6646, 7340, -5196], [-146969, -4007, -1428], [-132210, 2630, -6606], [19068, 2962, 10134], [-46503, 3112, -6613], [-112260, 1993, 3843], [-5634, 894, 10026], [19891, 1621, 3828], [7494, 3318, -14862], [-35973, -3470, -4057], [-52831, 27, 4440], [-150198, 1691, -6021], [10950, 3654, -9966], [-42636, -1038, 10038], [165960, -4022, 2486], [-88402, -592, -10728], [-155775, -468, 287], [-46752, 4962, -13634], [94620, -4386, 4074], [73342, -4200, 11904], [-2205, -7558, 10519], [41268, -1016, -9420], [191297, -2157, 2592], [-58890, 2678, -6078], [78078, 2454, 4836], [-191127, -1984, 8995], [-186288, -887, -1185], [22764, -8292, 5736], [59280, -5978, -7574], [2890, -1800, -8400], [-68829, 6642, 415], [-25800, -6706, 13154], [65994, 4340, -8292], [-65004, 3154, 7878], [52686, -7118, -8424]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_768_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_768_4_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_768_4_a_q(:prec:=3)
    chi := MakeCharacter_768_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_768_4_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_768_4_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_768_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-104, -164, 10, 1]>,<7,R![5816, -580, -14, 1]>,<11,R![-49152, -2816, 0, 1]>,<19,R![274752, -11088, 28, 1]>],Snew);
    return Vf;
end function;