
// Make newform 768.7.g.g in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_768_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_768_g_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_768_7_g_g();".
// 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_7_g_g();".
// 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 := [366025, -33880, -31349, -772, 2532, -2, -53, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-148555417725, -13895005095, 16532702568, 1561303692, -318001302, -46400868, 5475258, 828747], [-974690090, 9273241226, 356343028, -392579888, -31230312, 11306672, 579378, -26514], [296213011050, 33621027330, -10886465316, -12869361504, 483802824, 284961216, 3940254, -6425154], [3833648818285, 245471527351, -397943114152, -37349169868, 11629186678, 1247954852, -175563642, -19492379], [427089143140, 1788467062604, 39175429432, -77436405152, -1485058128, 1655284448, 66004572, -22028796], [-24850917216, 257700960, -83443392, -4436352, 3708288, 2184192, -678816, -49248], [-39175581258, -5588889570, 1809678564, 1635589152, -80423496, -47369664, -986094, 1068066]];
    Rf_basisdens := [1, 9239308925, 263980255, 839937175, 1847861785, 1847861785, 3054317, 33597487];
    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_g();"
function MakeCharacter_768_g()
    N := 768;
    order := 2;
    char_gens := [511, 517, 257];
    v := [1, 2, 2];
    // 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_768_g_Hecke();"
function MakeCharacter_768_g_Hecke(Kf)
    N := 768;
    order := 2;
    char_gens := [511, 517, 257];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [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, -1, 0, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0, 0, 0], [0, -17, 0, 0, -1, 0, 0, 0], [0, 0, 0, 0, 0, -1, 0, 0], [-818, 0, 0, 0, 0, 0, 1, 0], [0, 195, 0, 0, -5, 0, 0, 0], [0, 0, 0, -2, 0, 0, 0, -4], [0, 0, -47, 0, 0, -14, 0, 0], [0, 0, 0, -61, 0, 0, 0, 20], [0, 0, -110, 0, 0, -27, 0, 0], [62446, 0, 0, 0, 0, 0, -1, 0], [0, 529, 0, 0, 25, 0, 0, 0], [0, 0, 0, 198, 0, 0, 0, 32], [0, 0, 949, 0, 0, -70, 0, 0], [0, -10620, 0, 0, -32, 0, 0, 0], [0, 0, 462, 0, 0, 5, 0, 0], [0, 10568, 0, 0, 140, 0, 0, 0], [0, 0, 0, -94, 0, 0, 0, 228], [245330, 0, 0, 0, 0, 0, 20, 0], [0, 0, 0, -1525, 0, 0, 0, -4], [0, 13683, 0, 0, -309, 0, 0, 0], [211874, 0, 0, 0, 0, 0, -38, 0], [954094, 0, 0, 0, 0, 0, -10, 0], [0, 0, 9513, 0, 0, 42, 0, 0], [0, 0, 0, -1135, 0, 0, 0, -168], [0, -80418, 0, 0, -62, 0, 0, 0], [0, 0, -1572, 0, 0, 319, 0, 0], [1180994, 0, 0, 0, 0, 0, 178, 0], [0, 0, 0, 1757, 0, 0, 0, 60], [0, 176368, 0, 0, -684, 0, 0, 0], [453934, 0, 0, 0, 0, 0, 301, 0], [0, -246344, 0, 0, -316, 0, 0, 0], [0, 0, 7427, 0, 0, 992, 0, 0], [0, 0, 0, -9669, 0, 0, 0, -872], [0, 0, -28758, 0, 0, -1223, 0, 0], [0, 115657, 0, 0, -2247, 0, 0, 0], [0, 0, 0, 7312, 0, 0, 0, 1852], [0, 0, 37315, 0, 0, -2208, 0, 0], [0, -7352, 0, 0, 6012, 0, 0, 0], [0, 0, -19172, 0, 0, 1811, 0, 0], [0, 0, 0, -5372, 0, 0, 0, 688], [-412802, 0, 0, 0, 0, 0, 1060, 0], [0, 0, -28431, 0, 0, -2914, 0, 0], [0, 0, 0, 145, 0, 0, 0, 3320], [0, -114972, 0, 0, -5208, 0, 0, 0], [0, 0, 0, -12479, 0, 0, 0, 6332], [0, -346371, 0, 0, -6355, 0, 0, 0], [0, 0, -1728, 0, 0, -1301, 0, 0], [2495906, 0, 0, 0, 0, 0, -358, 0], [0, 0, 0, 25648, 0, 0, 0, 3880], [-235394, 0, 0, 0, 0, 0, -218, 0], [0, -383373, 0, 0, -3421, 0, 0, 0], [3206402, 0, 0, 0, 0, 0, -328, 0], [0, 0, 0, -13956, 0, 0, 0, 4924], [0, 0, 5021, 0, 0, -7270, 0, 0], [0, 0, 0, -18463, 0, 0, 0, -492], [0, 0, -106980, 0, 0, 2847, 0, 0], [-1881598, 0, 0, 0, 0, 0, 2056, 0], [0, 36848, 0, 0, 28428, 0, 0, 0], [0, 0, 30949, 0, 0, 834, 0, 0], [0, -2276616, 0, 0, 5468, 0, 0, 0], [0, 0, 0, -107224, 0, 0, 0, -1308], [-40527170, 0, 0, 0, 0, 0, -1124, 0], [0, 0, -148883, 0, 0, -7506, 0, 0], [0, -586322, 0, 0, -4590, 0, 0, 0], [22654706, 0, 0, 0, 0, 0, -1748, 0], [0, -698981, 0, 0, -19285, 0, 0, 0], [0, 0, 329686, 0, 0, -11359, 0, 0], [14212706, 0, 0, 0, 0, 0, 6706, 0], [0, 0, 0, 74906, 0, 0, 0, -9868], [0, 0, 0, 31427, 0, 0, 0, 604], [0, 0, -38042, 0, 0, -21379, 0, 0], [0, 1597483, 0, 0, -6389, 0, 0, 0], [0, 0, 0, -13092, 0, 0, 0, 5088], [0, 0, -13933, 0, 0, 41848, 0, 0], [0, 0, 208982, 0, 0, -7947, 0, 0], [-53570546, 0, 0, 0, 0, 0, -7541, 0], [-61338194, 0, 0, 0, 0, 0, -2462, 0], [0, -5392171, 0, 0, -1611, 0, 0, 0], [0, 0, 238284, 0, 0, 21719, 0, 0], [0, 0, 0, 190514, 0, 0, 0, 17248], [39502414, 0, 0, 0, 0, 0, 12076, 0], [0, 0, 0, -21323, 0, 0, 0, 20720], [0, -679445, 0, 0, 21259, 0, 0, 0], [40709614, 0, 0, 0, 0, 0, -13675, 0], [-109031282, 0, 0, 0, 0, 0, 7174, 0], [0, 0, 120799, 0, 0, -64, 0, 0], [0, 0, 0, -321143, 0, 0, 0, 20068], [0, 5355481, 0, 0, -31831, 0, 0, 0], [0, 0, 0, -302906, 0, 0, 0, 12168], [0, 0, 0, 166907, 0, 0, 0, 16224], [0, 1303082, 0, 0, -78802, 0, 0, 0], [0, 4596632, 0, 0, -82868, 0, 0, 0], [0, 0, 0, 10186, 0, 0, 0, 74124], [0, 0, 440969, 0, 0, -36746, 0, 0], [112774414, 0, 0, 0, 0, 0, -16213, 0], [0, -1212833, 0, 0, -47553, 0, 0, 0], [0, 0, -1516204, 0, 0, -19185, 0, 0], [0, 3754451, 0, 0, 84811, 0, 0, 0], [0, 0, 411503, 0, 0, -12580, 0, 0], [0, 15547363, 0, 0, -3349, 0, 0, 0], [71755534, 0, 0, 0, 0, 0, 33079, 0], [0, -4219786, 0, 0, 43546, 0, 0, 0], [105966962, 0, 0, 0, 0, 0, 10556, 0], [0, -4176846, 0, 0, -13178, 0, 0, 0], [-36123070, 0, 0, 0, 0, 0, -25238, 0], [0, 0, 0, -623174, 0, 0, 0, -63140], [-163679086, 0, 0, 0, 0, 0, -12928, 0], [0, 0, 0, -14331, 0, 0, 0, 46972], [0, 0, 1846558, 0, 0, -47875, 0, 0], [143175266, 0, 0, 0, 0, 0, -20212, 0], [0, 3509848, 0, 0, 126676, 0, 0, 0], [0, 0, 0, 150579, 0, 0, 0, -31640], [-45510002, 0, 0, 0, 0, 0, -16079, 0], [0, 16845499, 0, 0, 106195, 0, 0, 0], [0, 0, 0, 154422, 0, 0, 0, -119196], [0, 0, -1309405, 0, 0, 34492, 0, 0], [0, 22143926, 0, 0, -11982, 0, 0, 0], [0, 0, -2675486, 0, 0, -95523, 0, 0], [-157294994, 0, 0, 0, 0, 0, 1160, 0], [0, 0, 1540223, 0, 0, -120332, 0, 0], [0, 18992421, 0, 0, 199789, 0, 0, 0], [0, 29255761, 0, 0, -115071, 0, 0, 0], [0, 0, -492567, 0, 0, 44206, 0, 0], [0, 0, -2704864, 0, 0, 61271, 0, 0], [0, 0, 0, -645726, 0, 0, 0, -4256], [0, 0, 0, 368911, 0, 0, 0, 10296], [0, 0, -2021320, 0, 0, 164671, 0, 0], [0, -17651418, 0, 0, 152386, 0, 0, 0], [0, 0, 0, -834252, 0, 0, 0, 63916], [0, 0, 0, -580057, 0, 0, 0, 118460], [0, 0, -1361072, 0, 0, 171719, 0, 0], [475515310, 0, 0, 0, 0, 0, -30163, 0], [-58751042, 0, 0, 0, 0, 0, 61064, 0], [0, 0, 716653, 0, 0, 185782, 0, 0], [0, 11697325, 0, 0, 229197, 0, 0, 0], [0, 0, -1237349, 0, 0, -181020, 0, 0], [143320942, 0, 0, 0, 0, 0, 48565, 0], [0, 33872993, 0, 0, 279257, 0, 0, 0], [0, 0, 2951785, 0, 0, -60114, 0, 0], [0, 0, 0, -327801, 0, 0, 0, -6968], [0, 39934694, 0, 0, 1290, 0, 0, 0], [0, 0, -4591412, 0, 0, -240937, 0, 0], [0, 0, 0, -316506, 0, 0, 0, 14180], [0, 0, -6382894, 0, 0, -95087, 0, 0], [-69098738, 0, 0, 0, 0, 0, -62137, 0], [0, 8093635, 0, 0, -511133, 0, 0, 0], [0, 0, 0, 19268, 0, 0, 0, 392800], [0, 0, 245126, 0, 0, 33477, 0, 0], [799808546, 0, 0, 0, 0, 0, -33828, 0], [0, 10345321, 0, 0, -438583, 0, 0, 0], [0, 0, 0, -474860, 0, 0, 0, -185292], [0, 59808879, 0, 0, 113951, 0, 0, 0], [0, 0, 0, -124272, 0, 0, 0, -116664], [0, 0, 0, 1088335, 0, 0, 0, -473336], [490388206, 0, 0, 0, 0, 0, 13247, 0], [-353696062, 0, 0, 0, 0, 0, 53896, 0], [0, 0, -2648793, 0, 0, -165560, 0, 0], [0, 10998592, 0, 0, -191612, 0, 0, 0], [611559406, 0, 0, 0, 0, 0, -11165, 0], [0, 0, 0, -324019, 0, 0, 0, -151320], [0, 22989237, 0, 0, 799677, 0, 0, 0], [889652686, 0, 0, 0, 0, 0, 109919, 0], [0, 0, 0, 1750468, 0, 0, 0, -421404], [0, 0, 0, 2225647, 0, 0, 0, -93260], [0, 0, -309474, 0, 0, 337481, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_768_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_768_7_g_g();".
// 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_7_g_g(:prec:=8)
    chi := MakeCharacter_768_g();
    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_768_7_g_g();".
// 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_7_g_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_768_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<5,R![277920000, 0, -45408, 0, 1]>],Snew);
    return Vf;
end function;