
// Make newform 76.7.c.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_76_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_76_c_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_76_7_c_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_7_c_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 := [827887219200, 0, 5831691048, 0, 8905881, 0, 5090, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [-4315657896, 0, -67416687, 0, -46859, 0, -4, 0], [-40102527312, 0, -211681665, 0, -204128, 0, -55, 0], [0, 41750573400, 0, 211681665, 0, 204128, 0, 55], [0, 121944861000, 0, 500211621, 0, 518666, 0, 157], [0, 48252931560, 0, 334817847, 0, 361397, 0, 106], [-46015049520, 0, -293772453, 0, -308974, 0, -89, 0]];
    Rf_basisdens := [1, 1, 21128796, 42257592, 42257592, 84515184, 21128796, 14085864];
    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_c();"
function MakeCharacter_76_c()
    N := 76;
    order := 2;
    char_gens := [39, 21];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_76_c_Hecke();"
function MakeCharacter_76_c_Hecke(Kf)
    N := 76;
    order := 2;
    char_gens := [39, 21];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 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 := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [46, 0, 1, 2, 0, 0, 0, -1], [112, 0, 2, 6, 0, 0, 0, 9], [0, -16, 0, 0, 1, 0, 0, 0], [206, 0, 1, 27, 0, 0, 0, -22], [771, -34, -5, -23, -1, 1, -1, 9], [-2328, 0, 3, 48, 0, 0, 0, -50], [0, -145, 0, 0, -2, 4, 1, 0], [0, -209, 0, 0, 7, 0, -7, 0], [0, -7, 0, 0, -11, 2, -13, 0], [0, -513, 0, 0, 35, 4, 9, 0], [-42068, 0, 100, -360, 0, 0, 0, 391], [-71560, 0, 22, -1020, 0, 0, 0, 23], [0, -29, 0, 0, -60, 4, -1, 0], [0, 964, 0, 0, -9, -20, 11, 0], [-79408, 0, -180, -1702, 0, 0, 0, -77], [0, -1509, 0, 0, 86, -48, 8, 0], [0, 4556, 0, 0, 74, -48, 40, 0], [-106742, 0, 895, -789, 0, 0, 0, -290], [0, 7625, 0, 0, -111, -48, -31, 0], [54774, 0, 882, -1644, 0, 0, 0, -140], [0, 12081, 0, 0, -41, -16, -141, 0], [0, -7162, 0, 0, 96, 60, -112, 0], [-229086, 0, -756, 468, 0, 0, 0, 8404], [0, -21378, 0, 0, -442, 60, -40, 0], [0, -11042, 0, 0, -3, -68, -103, 0], [0, 16785, 0, 0, 152, 220, 99, 0], [0, 3689, 0, 0, 85, 64, -257, 0], [0, 57515, 0, 0, 389, 12, 139, 0], [-1229308, 0, 3568, -21480, 0, 0, 0, 11927], [153698, 0, 3307, 11943, 0, 0, 0, -15670], [421032, 0, 2438, 4238, 0, 0, 0, 10353], [1293028, 0, -6346, 1518, 0, 0, 0, -8661], [0, 42122, 0, 0, -724, -8, 284, 0], [1627458, 0, -3568, 6062, 0, 0, 0, -6714], [778122, 0, 4736, -5770, 0, 0, 0, 14250], [0, -118045, 0, 0, -981, -340, 871, 0], [0, 2622, 0, 0, 80, -542, 492, 0], [0, -176043, 0, 0, -471, -594, 291, 0], [0, -138570, 0, 0, -856, -178, -392, 0], [-3191678, 0, -9373, -65274, 0, 0, 0, 39903], [0, 95915, 0, 0, 1923, -120, -553, 0], [3534354, 0, -11232, -43998, 0, 0, 0, 50242], [-3025226, 0, -4655, -3672, 0, 0, 0, -44291], [0, -20952, 0, 0, -1739, 588, -1613, 0], [0, 160317, 0, 0, -557, 1868, 675, 0], [0, 14118, 0, 0, 2539, 236, 1659, 0], [2543392, 0, -12428, 110294, 0, 0, 0, -61009], [-2843924, 0, -3790, -116496, 0, 0, 0, -5499], [11529202, 0, -28081, 93012, 0, 0, 0, -52539], [0, 208191, 0, 0, 167, 456, -2467, 0], [-5442648, 0, -20454, -17748, 0, 0, 0, 120439], [0, -174640, 0, 0, 712, -2024, -866, 0], [-7827360, 0, 28314, -50676, 0, 0, 0, -18305], [0, 121767, 0, 0, 4779, -2610, 3489, 0], [4487900, 0, 41781, 48312, 0, 0, 0, 23418], [3333916, 0, -18290, -180952, 0, 0, 0, -47995], [0, -52910, 0, 0, 670, -1428, 3290, 0], [569700, 0, 50096, 51852, 0, 0, 0, 156347], [0, 139452, 0, 0, -1589, -3496, 4734, 0], [0, 86181, 0, 0, 7081, 158, 4431, 0], [13696710, 0, 49905, -129264, 0, 0, 0, 134365], [-190104, 0, 23465, 197195, 0, 0, 0, -163359], [0, -164564, 0, 0, 1497, -5384, 6710, 0], [0, 205421, 0, 0, 16862, -40, 3732, 0], [0, -13870, 0, 0, -12502, 1616, -2220, 0], [47298300, 0, -16968, 7350, 0, 0, 0, 113989], [29703868, 0, 10810, 41622, 0, 0, 0, -61733], [-2004828, 0, 68535, -203829, 0, 0, 0, 234277], [-9260538, 0, 95661, -112350, 0, 0, 0, -425], [2872250, 0, 120792, 73284, 0, 0, 0, 424392], [0, 703990, 0, 0, 4317, -880, -7824, 0], [0, -939692, 0, 0, -2817, 5684, 1269, 0], [0, -402729, 0, 0, 19273, -2860, -5631, 0], [-6889788, 0, -60630, 251796, 0, 0, 0, 145561], [5584220, 0, 8046, -289464, 0, 0, 0, -8787], [0, -990919, 0, 0, 20707, 1492, -11903, 0], [0, 595841, 0, 0, -10495, 8380, -16279, 0], [-54821130, 0, -151974, 135096, 0, 0, 0, 422824], [0, -1394639, 0, 0, -37678, 4444, -3419, 0], [0, -561292, 0, 0, -39924, 4088, 928, 0], [0, 1383901, 0, 0, 12791, 12476, 6095, 0], [0, 710015, 0, 0, 16833, -5032, -3029, 0], [19941360, 0, 38634, 222414, 0, 0, 0, 105961], [0, 1328546, 0, 0, -10372, 9924, -8930, 0], [-66482446, 0, -93429, 303495, 0, 0, 0, 395874], [49987976, 0, -35840, -877998, 0, 0, 0, 23147], [84576936, 0, -125506, -541260, 0, 0, 0, -34201], [67864184, 0, 65266, -564360, 0, 0, 0, 401459], [-64574814, 0, 254412, 618156, 0, 0, 0, 345496], [0, 1499400, 0, 0, -43492, -17260, -5114, 0], [-31966002, 0, -1326, -55218, 0, 0, 0, -1177394], [73659836, 0, 190596, -565696, 0, 0, 0, 300415], [-84259152, 0, -215469, -227694, 0, 0, 0, 178336], [0, 2053216, 0, 0, -20122, -5182, -20542, 0], [0, 1204997, 0, 0, -23971, 14460, -1493, 0], [0, 2525980, 0, 0, -23273, 1772, 16801, 0], [-96279736, 0, 123756, 133404, 0, 0, 0, -605283], [0, -481378, 0, 0, 45084, -16862, 11796, 0], [31759888, 0, -190360, -517800, 0, 0, 0, -54447], [0, -3065623, 0, 0, 71013, 6734, -33269, 0], [0, 1577974, 0, 0, -16312, 21248, -57268, 0], [-60341950, 0, 176376, 1525812, 0, 0, 0, -471576], [81394486, 0, 265597, -1079569, 0, 0, 0, 840566], [75697212, 0, 484824, 1403010, 0, 0, 0, -483335], [-75671142, 0, 306324, 2486688, 0, 0, 0, 93856], [0, -1920563, 0, 0, 40515, 33808, -23611, 0], [0, 701840, 0, 0, 25906, 21448, 28492, 0], [0, -2233988, 0, 0, 30314, -15012, 25044, 0], [220475288, 0, -152028, -257476, 0, 0, 0, -893771], [-85537604, 0, -494062, -6120, 0, 0, 0, 943317], [-87040434, 0, 376874, -2338726, 0, 0, 0, 185082], [-119841424, 0, -599622, 782804, 0, 0, 0, -441089], [0, 5589076, 0, 0, 129836, -10408, 3530, 0], [47247184, 0, -47618, 2131260, 0, 0, 0, 365383], [-153303722, 0, -214255, 607260, 0, 0, 0, -740823], [154613476, 0, 301034, -227280, 0, 0, 0, 10869], [0, 7666228, 0, 0, 38577, 37228, -27889, 0], [0, -4157426, 0, 0, 20973, -38400, -10652, 0], [0, -6218058, 0, 0, 13420, -11036, -1516, 0], [0, 5509697, 0, 0, -98982, -29212, 47767, 0], [0, -3603880, 0, 0, -41666, 19606, -32870, 0], [180602372, 0, -58284, -1481238, 0, 0, 0, -1027383], [52892574, 0, 835902, -1094070, 0, 0, 0, 338038], [91131038, 0, 641958, 1989642, 0, 0, 0, -578298], [-160154622, 0, 604779, 1454238, 0, 0, 0, 957487], [142825598, 0, -55803, -3370152, 0, 0, 0, 1520277], [120419534, 0, -112302, -1631340, 0, 0, 0, 2983320], [85605396, 0, 30764, 1235726, 0, 0, 0, 1974981], [0, 95347, 0, 0, 6331, 63588, 24233, 0], [0, -2993456, 0, 0, 34898, 24492, 47088, 0], [70373064, 0, -438328, -390466, 0, 0, 0, -3573249], [-193548006, 0, -704169, -645861, 0, 0, 0, 874174], [-179370506, 0, 429241, 3122237, 0, 0, 0, -3047020], [0, -3021266, 0, 0, 164885, 4520, 86792, 0], [0, -2341092, 0, 0, -147303, -6460, 35321, 0], [0, 7778455, 0, 0, 61182, -19436, 30929, 0], [-17236686, 0, -532689, -942123, 0, 0, 0, -4574216], [0, 12329862, 0, 0, 73049, 21964, 13503, 0], [-158764508, 0, 648962, 2099736, 0, 0, 0, -4002483], [12924102, 0, 647957, 1682258, 0, 0, 0, -2339601], [0, 437579, 0, 0, 40892, -24504, -18584, 0], [0, 4592548, 0, 0, -47923, 79344, -37146, 0], [0, 12605496, 0, 0, -61884, 42852, -150102, 0], [274483742, 0, -516558, 5466084, 0, 0, 0, 3047976], [0, -4726156, 0, 0, -184336, -99012, -70508, 0], [-402352396, 0, 380568, -2242780, 0, 0, 0, -4422797], [0, -4163179, 0, 0, 308611, 2452, -26243, 0], [0, -7006976, 0, 0, -49403, 26792, -121364, 0], [223700660, 0, 617734, 1760832, 0, 0, 0, 664421], [-178225556, 0, 925240, -289678, 0, 0, 0, 774041], [0, 11968476, 0, 0, -90480, -62556, 11544, 0], [0, -12630083, 0, 0, 40790, -94784, 168046, 0], [0, -3942810, 0, 0, -451294, 23272, 25440, 0], [13222872, 0, -1212937, 3330626, 0, 0, 0, -4813464], [221618124, 0, -930945, -4538079, 0, 0, 0, -1625813], [-421615198, 0, -602625, -4670691, 0, 0, 0, 783144], [0, 6311936, 0, 0, -59479, -20784, 122404, 0], [386474118, 0, -374406, 4177800, 0, 0, 0, -1061216], [0, -2760627, 0, 0, -35593, -116072, -12405, 0], [-571960254, 0, 327404, -8102932, 0, 0, 0, 3395184], [0, 3676754, 0, 0, 82260, -116962, 58456, 0], [0, 24654269, 0, 0, -113835, -121264, 165409, 0], [0, -27768754, 0, 0, 108578, -10860, 123478, 0], [0, 13173941, 0, 0, -89813, -33316, 57767, 0], [20019372, 0, 740870, 439544, 0, 0, 0, -6746811]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_76_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_76_7_c_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_7_c_b(:prec:=8)
    chi := MakeCharacter_76_c();
    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_76_7_c_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_7_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_76_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<3,R![827887219200, 0, 5831691048, 0, 8905881, 0, 5090, 0, 1]>],Snew);
    return Vf;
end function;