
// Make newform 768.6.d.s in Magma, downloaded from the LMFDB on 02 November 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_768_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_768_d_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_6_d_s();".
// 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_6_d_s();".
// 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 := [64, 0, -15, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -7, 0, 1], [0, 46, 0, -2], [-240, 0, 32, 0]];
    Rf_basisdens := [1, 8, 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_d();"
function MakeCharacter_768_d()
    N := 768;
    order := 2;
    char_gens := [511, 517, 257];
    v := [2, 1, 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_d_Hecke();"
function MakeCharacter_768_d_Hecke( : Kf := false)
    N := 768;
    order := 2;
    char_gens := [511, 517, 257];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0], [1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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], [0, -9, 0, 0], [0, 18, 0, 1], [-60, 0, -1, 0], [0, 100, 0, -6], [0, -142, 0, 6], [1338, 0, -6, 0], [0, 36, 0, -10], [1920, 0, 30, 0], [0, -5106, 0, -19], [-5244, 0, 5, 0], [0, 6574, 0, -84], [-2082, 0, 50, 0], [0, 2916, 0, -130], [-760, 0, 198, 0], [0, 4506, 0, 71], [0, 27548, 0, -216], [0, 31722, 0, 48], [0, 18396, 0, -488], [18832, 0, 438, 0], [18918, 0, 552, 0], [-72444, 0, -295, 0], [0, -54636, 0, 222], [16278, 0, -572, 0], [34546, 0, 60, 0], [0, 106698, 0, -801], [79692, 0, -1311, 0], [0, 45596, 0, 1212], [0, -12446, 0, 1338], [-44862, 0, -644, 0], [85356, 0, -1489, 0], [0, 163292, 0, -912], [98382, 0, -330, 0], [0, 28812, 0, 4592], [0, 178914, 0, -2319], [-126156, 0, 2367, 0], [0, 220666, 0, 3876], [0, 71844, 0, -1102], [193528, 0, 840, 0], [0, -7146, 0, -1077], [0, 665580, 0, 72], [0, -623962, 0, 1998], [127488, 0, 3288, 0], [16530, 0, -1848, 0], [0, 40890, 0, 4027], [306492, 0, 3733, 0], [0, -490548, 0, -3928], [868476, 0, -4853, 0], [0, -151788, 0, -5670], [0, 280550, 0, 5490], [234342, 0, 9876, 0], [-423168, 0, -3588, 0], [584242, 0, -1764, 0], [0, 791892, 0, -870], [228354, 0, 20032, 0], [872472, 0, 2976, 0], [0, -380226, 0, -8643], [215820, 0, 627, 0], [0, -229562, 0, -10914], [-1257306, 0, 1248, 0], [0, 917436, 0, -4096], [0, 871626, 0, -3033], [0, 756204, 0, -2184], [-837096, 0, -11172, 0], [-1642, 0, -29592, 0], [0, 2211582, 0, -1095], [0, -979908, 0, 6140], [-1841086, 0, 18552, 0], [0, 564596, 0, 24546], [0, -1155958, 0, -13584], [-1503630, 0, 16124, 0], [688496, 0, -17610, 0], [132084, 0, 29037, 0], [0, 323150, 0, -2376], [0, -4028220, 0, 15802], [751136, 0, 12048, 0], [0, 1459698, 0, -18207], [0, 41882, 0, -33336], [1650762, 0, 25502, 0], [-674794, 0, 9276, 0], [0, -1545676, 0, -17886], [0, 1546646, 0, 8718], [-1143528, 0, 1626, 0], [2480434, 0, 19128, 0], [-3184164, 0, -1351, 0], [0, 2681172, 0, 16050], [5632266, 0, 17906, 0], [3267910, 0, 31956, 0], [0, 3915414, 0, 3], [-3273492, 0, -35077, 0], [0, 883460, 0, -49758], [1108200, 0, 49626, 0], [1406148, 0, -1273, 0], [0, -4165316, 0, -10068], [0, -4696596, 0, 20256], [2057088, 0, -70242, 0], [0, 939774, 0, 24177], [-2649474, 0, -48774, 0], [0, 1653204, 0, -40278], [0, 442034, 0, 87522], [0, -9223404, 0, 654], [0, 8997030, 0, -27577], [0, -2380908, 0, 77310], [-4087602, 0, 6002, 0], [0, 6202188, 0, 64732], [-8756718, 0, -37896, 0], [0, 7378428, 0, 33492], [-6556638, 0, -40068, 0], [-8362352, 0, 90354, 0], [4509590, 0, 4320, 0], [-3309972, 0, 121223, 0], [0, 5268510, 0, 75888], [3730230, 0, 6072, 0], [0, -4304724, 0, -69912], [-11824044, 0, -33329, 0], [-477174, 0, -15574, 0], [0, -2381292, 0, -42234], [9912144, 0, -48594, 0], [0, -8284410, 0, -14225], [0, -8125380, 0, 63324], [0, -3185794, 0, 184572], [4891394, 0, -181968, 0], [0, 4618242, 0, -111019], [0, -11681580, 0, 22878], [0, 2330580, 0, 87602], [0, 4937214, 0, 173577], [0, 16266886, 0, 40914], [9041672, 0, 57270, 0], [-6709452, 0, 219471, 0], [0, 1867810, 0, 174], [0, 12381516, 0, -124204], [15861480, 0, 144516, 0], [1667076, 0, 63665, 0], [0, -19851978, 0, -8334], [-2783298, 0, 265062, 0], [13328242, 0, -68304, 0], [0, 8039418, 0, -175149], [0, 16013460, 0, 16098], [0, 31134294, 0, -27537], [-10374162, 0, -16826, 0], [0, 4879428, 0, 30910], [0, 14185770, 0, 979], [895812, 0, -202789, 0], [0, 1917196, 0, -269964], [0, 2224210, 0, -199974], [-5419424, 0, -12006, 0], [0, -13474722, 0, -161004], [21277230, 0, -99854, 0], [0, -2349852, 0, -158638], [-22692832, 0, 177000, 0], [0, 14594330, 0, -42648], [-5418030, 0, 204072, 0], [0, -11052876, 0, 46234], [-4593432, 0, -193776, 0], [0, 12256500, 0, 336250], [23011584, 0, -94476, 0], [-6015900, 0, 114891, 0], [29878650, 0, -25194, 0], [29856886, 0, -41136, 0], [0, 2869974, 0, 370987], [0, -19878420, 0, -137688], [-26200434, 0, -274566, 0], [45158988, 0, -3735, 0], [0, -12540908, 0, -170586], [14512938, 0, 241510, 0], [-11232024, 0, 406152, 0], [24014772, 0, -58351, 0], [0, 19311390, 0, 261288]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_768_d_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_768_6_d_s();".
// 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_6_d_s(:prec:=4)
    chi := MakeCharacter_768_d();
    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_768_6_d_s();".
// 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_6_d_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_768_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![57942544, 0, 16520, 0, 1]>,<7,R![-4336, 120, 1]>],Snew);
    return Vf;
end function;