
// Make newform 76.6.a.b in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_76_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_76_6_a_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_76_6_a_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 := [3103, -84, -140, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 4, 0, 0], [287, -79, -5, 1], [-71, -2, 1, 0]];
    Rf_basisdens := [1, 1, 12, 2];
    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_76_a();"
function MakeCharacter_76_a()
    N := 76;
    order := 1;
    char_gens := [39, 21];
    v := [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_76_a_Hecke(Kf)
    return MakeCharacter_76_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 := 6;
    raw_aps := [[0, 0, 0, 0], [3, 0, 0, 1], [-26, 1, 2, 3], [10, -1, 3, 5], [176, -3, -10, -1], [202, -14, 15, 10], [75, -36, 48, 30], [-361, 0, 0, 0], [1450, 4, 95, -42], [1382, -67, 19, 144], [-174, -5, 150, 82], [-5004, 133, 330, 358], [-2580, 13, -320, -58], [-3146, -81, 378, -15], [-1424, -299, 32, -435], [-19254, 53, 251, -266], [5779, -661, -420, -391], [-8072, -611, -570, 97], [1667, 1426, -660, 823], [30112, 376, -130, -426], [-26095, -1382, 96, 160], [29016, 17, 1326, -532], [23412, 1344, 834, 408], [-742, -953, 1494, -4478], [3510, -908, 1104, -4466], [-14766, 1694, 2312, 2404], [30914, -1358, 1536, -1280], [50633, -819, 3704, 3083], [-13422, -1467, -999, 642], [120298, 4123, -5656, 2448], [-152156, -2101, 1902, -6862], [45750, -2277, -3606, -261], [109451, 3386, -3236, 4014], [-163210, 2923, 4542, 1909], [-33088, -8783, 7056, -6173], [-149482, -1896, 1044, 11220], [-167656, 6554, -9294, -4726], [93230, 6408, -11394, 14778], [66980, -5549, 4932, -2426], [36536, 172, -8514, -2870], [131804, 11053, -6792, -8066], [-16676, 2148, -5850, 6666], [58762, -507, 6823, 32545], [317016, -5097, 26226, 19728], [253576, 1282, -7024, -15906], [106430, 8745, -3717, -6027], [-383029, -8321, 21480, 13189], [52018, 12061, 11688, 9316], [48711, -5879, 27520, 23591], [-272140, 9909, -24570, -25041], [282630, -753, 35556, 29967], [565258, -22915, -3249, -5131], [-60416, -16143, -7596, 25566], [96334, 33421, -7396, -10785], [-286978, 9648, -11626, 2630], [221916, -1581, 29796, 59445], [616856, 16411, 8238, 11860], [-220230, 15178, -47505, -10610], [-826802, 6753, -11214, -8919], [186732, 39358, 6964, -28930], [-623544, -6729, -8082, -1161], [34602, 18948, -55899, -37662], [613452, -14499, 22140, -52236], [-234362, 3075, -33869, 31063], [557881, -42743, 28140, 59959], [-995690, 12332, -17139, 33860], [1060557, 31304, -68424, -35071], [1185754, 28338, 63810, -1062], [464106, -64535, -6260, -13933], [-454232, 67983, 24606, 10983], [1683417, -6807, 4464, -44637], [514902, -14757, 19545, 116193], [-1917620, 41532, 13968, 109308], [1829178, 25124, 65649, 48506], [2096363, -28103, -16644, -36947], [3410866, 1269, -14360, -73742], [75830, 114079, -65220, -49673], [-2492566, -18927, -84510, -19839], [-1477912, -11041, -27380, -30744], [-939358, 96701, -26070, 98546], [-1819670, -12136, -34950, -60058], [1174846, -39563, 124251, 134446], [-101836, -36026, -86010, -7844], [1683928, 79915, -26634, -124262], [1883212, 66571, -164964, 11206], [-618320, 64563, -114014, 35329], [2124988, -18354, 108898, 105532], [-3485643, -66562, -97476, 101930], [-6329920, 4395, 11012, 8543], [57704, -74083, -114468, -255823], [-1868826, 74293, -69848, -46105], [1786948, 75240, -55016, 64912], [839786, -53506, -15468, -78628], [3487988, 125526, -48760, -46840], [2812398, -71153, 62070, 101047], [-2105030, -133018, 235743, -36550], [-1474512, -66114, -53106, 9840], [-822912, 125213, 14816, 74020], [-2767079, -45461, 173292, -81365], [6334082, 42627, 77832, -106557], [792816, 496, -446988, -214364], [-6653198, -110763, -41354, -129779], [1312648, -247237, 156048, 170474], [6383420, -23680, 223396, 385620], [-1299008, 44740, -138756, 207340], [3939139, -117098, -270624, -217448], [-3505892, 91949, -148800, -293659], [-5217222, -20906, 122368, 82748], [-1613832, 76125, -199668, -263496], [6089734, -321852, -92250, -272364], [-149956, 99924, -408150, -303132], [254146, -316101, 32112, 90813], [-5726966, 120491, -242712, -141955], [-3689022, 122404, 251952, 394894], [5739020, 135177, -242100, 287055], [-897268, 82654, -431742, -60356], [-1449714, 299449, -16176, -148859], [-10936842, -37867, 23699, 272125], [625182, 31731, 271002, 136317], [570201, -180103, 44060, -488897], [396894, -179198, 67713, -271838], [-88504, 137118, -30276, 263706], [-7290350, 144111, 98413, 100252], [1826520, 246466, 81436, 244196], [-11652130, 28747, -248484, -227837], [-5584664, 736, 343004, 451218], [7726300, 264470, -52206, 121634], [8459818, -377469, 274987, 22933], [-2612990, -391347, 169263, 11691], [2080354, -23494, -60522, 330440], [6010848, -350623, -95496, -882553], [12438710, 259443, -135886, -37870], [3469048, 421330, -336, 455632], [-2441900, 217203, 431982, -19299], [-3444653, -48490, 100392, 348482], [2207913, -395270, 151116, -113486], [12316046, 82048, -505023, 148744], [-1193689, -98689, 17400, -872449], [2594162, 265897, -319089, 648454], [-11006347, 138280, 129756, -244274], [8141929, 98813, 507756, 964973], [-1646134, -631247, 430542, -404423], [-2704494, 35879, -71511, 905837], [10087367, -16092, 529796, 33299], [-5103442, -429452, -52383, 547642], [12084558, 460598, -702454, 66712], [13694546, -132518, -534432, -321632], [-18005820, -304956, -79800, 43938], [-8620848, -580853, 608370, -628901], [18137192, -103655, 354678, 396622], [-8970774, -459656, 602745, 253108], [9698922, 683475, -201972, 316329], [4355854, 293343, -950148, -748431], [13254868, -125514, -173282, -13874], [-27703255, 547932, -37728, 142737], [-2910598, -854540, 1036374, 638548], [11302618, -846014, -115815, -342950], [-66551, 476725, -1034272, -135249], [5097513, 252962, 849288, 539408], [6452974, -623958, 165859, -1438604], [11022382, -160678, -344766, -433990], [-11513888, -450455, -699574, 378780], [3085896, -799092, -768312, -392904], [22033428, -503056, 1080368, 1692160], [-5763438, -83635, 526910, 976486], [-22951980, -1004808, 140802, 554424], [-2460726, 193807, -1456842, 122356], [-12986386, 423053, -121038, -966187]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_76_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_76_6_a_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_76_6_a_b(:prec:=4)
    chi := MakeCharacter_76_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_76_6_a_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_76_6_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_76_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![123588, 5988, -875, -10, 1]>],Snew);
    return Vf;
end function;