
// Make newform 768.6.a.h in Magma, downloaded from the LMFDB on 19 September 2025.
// 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_6_a_h();".
// 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_a_h();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := 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]];
    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], [9], [-80], [-36], [-36], [-404], [-2], [2916], [2808], [4408], [-5796], [-2316], [-6874], [17244], [5688], [-32072], [43308], [-18012], [-11628], [8712], [-15846], [-40356], [-66204], [-66086], [-119682], [-32392], [109476], [-106596], [-77524], [179506], [-339804], [-334188], [393766], [244620], [368240], [-380052], [513204], [-31500], [106560], [-249680], [362916], [-506644], [-806256], [-438418], [334664], [-63324], [662436], [-1330380], [717156], [198316], [-860662], [-443520], [-34242], [-236052], [929282], [-1690704], [900056], [1583892], [-1954660], [-2160806], [-659556], [-802664], [178452], [-1258272], [923062], [-568408], [-2606436], [232002], [-3219732], [4403412], [-556766], [1863144], [-4199364], [-3741516], [2471004], [472176], [3391568], [-3949500], [-200354], [3293574], [970740], [-5404900], [-5466456], [-2994226], [2044692], [7493436], [-1920946], [-6202410], [4108400], [5940], [-4127148], [4342968], [9158220], [-3332052], [-4360284], [7824744], [-2185976], [4423846], [-2868660], [4400588], [-7052796], [10866464], [4507092], [-2578730], [-6022116], [-15147502], [-13008996], [900818], [13964904], [-12841142], [7620228], [15044436], [1253290], [-7565508], [-8006004], [5208622], [-5082876], [-10266984], [20643424], [5875524], [-5076876], [6129886], [-3140864], [-15741684], [10514484], [5869672], [-12769700], [24324264], [16577532], [-15094772], [18126468], [5970384], [4936716], [10626172], [30518870], [22573486], [8227432], [26458452], [599296], [-5978746], [-32295924], [19484744], [-25263396], [6511644], [-12974164], [700056], [-2985084], [-18284938], [9648252], [-10241136], [-14225340], [-39199054], [-21787452], [-29540592], [-42670116], [28010880], [-29468484], [-22928306], [2940298], [31106192], [-21502188], [-7047242], [-13322988], [-17205300], [34352030], [18348624], [-22780980], [25026756], [25792302], [2976928], [10451484], [-7597212], [-38796912], [1460010], [-31340196], [-15741542], [43404300], [-58285168], [38954484], [-20945724], [5604444], [18705636], [8766604], [-27192758], [-30073392], [-30233984], [-47932868], [-27728892], [-7893882], [45411840], [-33747198], [2548620], [-40083372], [31160288], [-28845756], [60713066], [-52438078], [-65073956], [-46922270], [10600992], [-64535120], [-47824668], [35692028], [-86908782], [-68457924], [23390024], [87753636], [-102991068], [-47819350], [-89902260], [12050206], [-28900832], [-10719468], [16690140], [21032856], [82554134], [64609452], [-87642850], [-80354880], [-82796912], [-49248100], [42111684], [99867790], [76244868], [79329780], [144178500], [-130531366], [59488920], [-71107164], [-37454580], [37489868], [-61732188], [111669300], [19953482], [60445404], [85518648], [-16539186], [-133136464], [115695324], [-46808424], [-115462332], [72418140], [53833500], [180334980], [94585970], [-81397224], [11814012], [58953492], [36826380], [146033424], [4417532], [60204098], [163569816], [158771946], [-38792104], [21484548], [118131500], [-97040916], [-76117592], [164023238], [-178819596], [-24882876], [-142124500], [129060036], [123487022], [48493620], [50596768], [-176091046], [123229404], [-149403952], [121915092], [-181117836], [184538682], [-171826020], [168464370], [135930564], [-158872644], [-178317564], [-54042118], [-47910924], [-199099944], [-67018284], [-99299736], [14942676], [92856636], [-171342864], [114934686], [45070688], [-101628900], [-47985950], [-28349216], [-177079212], [-18915974], [82452060], [37118676], [-206522032], [315376884], [205022936], [76066236], [-13913244], [-147715930], [169043072], [-316783332], [124997220], [-200079540], [-7134066], [58636188], [-356567444], [30173112], [152602500], [-283444272], [-365421928], [148241678], [90371268], [88591968], [-111388086], [180875844], [328078440], [53918706], [-117687310], [344672100], [77099030], [87740152], [-250877412], [-49554458], [-21940242], [49625172], [77126508], [216160704], [-245564240], [-330695428], [170209840], [399023604], [-232271820], [-144573012], [-109405332], [38706852], [374835266], [-39908934], [-172621260], [-24715212], [22845878], [-68040040], [-214807932], [143065768], [301025700], [365631244], [139021308], [-19187352], [-471704024], [318116628], [203548566], [-43584760], [-43631676], [305932980], [92021690], [-328481856], [-387064116], [-335509058], [362866464], [-258991212], [-39556982], [100495152], [-408350196], [129766788], [15421658], [204825592], [359170956], [192886630], [639512532], [526198572], [-614275776], [590325016], [205631964], [216222316], [-196274844], [495809712], [-87523166], [-468113954], [-102474762], [-348402704], [-95540986], [-242991540], [562820450], [340032564], [440089920], [38954988], [-508801924], [492119532], [32533128], [619523778], [-289978016], [473959260], [734184468], [569361168], [432074310], [345963348], [561552134], [565367292], [166837072], [255950868], [-348938482], [278351604], [-525350602], [151629400], [784200060], [-73681636], [-288030722], [-467306028], [117224820], [230943074], [485601248], [-288812628], [-2450988], [-136419654], [822887704], [-821064528], [-161833140], [-548314210], [77601528], [822993488], [502303572], [-465597360], [68773932], [736176422], [-251066984], [-474616044], [470543834], [-668845908], [-503167752]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_768_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_768_6_a_h();".
// 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_a_h(:prec:=1)
    chi := MakeCharacter_768_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(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_6_a_h();".
// 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_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_768_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![80, 1]>,<7,R![36, 1]>,<11,R![36, 1]>],Snew);
    return Vf;
end function;