
// Make newform 768.4.a.i in Magma, downloaded from the LMFDB on 24 April 2024.
// 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_4_a_i();".
// 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_4_a_i();".
// 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 := [-11, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 6]];
    Rf_basisdens := [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_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)
    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+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 := 4;
    raw_aps := [[0, 0], [-3, 0], [0, 1], [0, -1], [48, 0], [0, 4], [-42, 0], [-92, 0], [0, 2], [0, -1], [0, 7], [0, 10], [6, 0], [-92, 0], [0, -2], [0, -25], [516, 0], [0, -18], [524, 0], [0, -50], [430, 0], [0, 59], [432, 0], [-630, 0], [862, 0], [0, 23], [0, -27], [1380, 0], [0, 64], [2106, 0], [0, -7], [-540, 0], [1446, 0], [1892, 0], [0, 141], [0, 15], [0, -118], [-3188, 0], [0, 100], [0, -19], [2844, 0], [0, -112], [0, 44], [2882, 0], [0, -213], [0, -163], [-2356, 0], [0, 89], [3864, 0], [0, 28], [-2814, 0], [0, -232], [362, 0], [-5136, 0], [-174, 0], [0, 240], [0, -57], [0, 9], [0, -320], [-558, 0], [-2068, 0], [0, -169], [6860, 0], [0, -524], [-6262, 0], [0, 39], [-6460, 0], [-74, 0], [6888, 0], [0, -34], [-1830, 0], [0, 334], [0, 159], [0, -490], [8332, 0], [0, -340], [0, -295], [0, 134], [-2634, 0], [-506, 0], [-15480, 0], [0, -536], [0, -862], [2014, 0], [0, -39], [-408, 0], [-11658, 0], [16486, 0], [0, -207], [0, 677], [4440, 0], [0, 534], [0, 67], [7404, 0], [-5740, 0], [0, 806], [0, 823], [-22098, 0], [-16436, 0], [0, 560], [-1316, 0], [0, -171], [19560, 0], [20838, 0], [1100, 0], [-1730, 0], [7644, 0], [26874, 0], [0, -490], [-650, 0], [0, -839], [0, -378], [-2526, 0], [-4372, 0], [0, -1205], [1374, 0], [-4196, 0], [0, 874], [0, -939], [-16380, 0], [0, -294], [-13250, 0], [0, 721], [-28272, 0], [16828, 0], [0, -909], [0, -1852], [0, 1098], [0, -1773], [0, 412], [-35404, 0], [0, -488], [0, 1087], [0, 1356], [14382, 0], [32978, 0], [0, -1453], [-24572, 0], [0, -991], [35286, 0], [556, 0], [0, -1697], [0, 1319], [-1116, 0], [0, -1168], [0, 1490], [0, 858], [1206, 0], [34756, 0], [0, -52], [0, 974], [-5310, 0], [23308, 0], [0, -1104], [-27596, 0], [0, -608], [0, -705], [12438, 0], [-8278, 0], [0, 257], [-16980, 0], [31998, 0], [0, 405], [-29664, 0], [-3354, 0], [0, -1488], [0, 1935], [0, -2730], [-49538, 0], [0, 189], [-17940, 0], [0, 1410], [0, 2864], [-8854, 0], [0, -1061], [29826, 0], [4700, 0], [0, -2587], [0, -1943], [0, 554], [0, -125], [33792, 0], [0, 1572], [-62238, 0], [0, 1692], [0, -291], [0, -2964], [-10348, 0], [30242, 0], [0, 280], [-37006, 0], [43908, 0], [10244, 0], [0, 1313], [-60060, 0], [-67038, 0], [-13682, 0], [0, 548], [49962, 0], [0, -908], [0, 2873], [0, -3335], [0, 904], [-22250, 0], [-79656, 0], [0, -1781], [0, -2507], [46632, 0], [40722, 0], [7108, 0], [77474, 0], [0, 2201], [0, -687], [59220, 0], [0, -2814], [-9578, 0], [0, -1069], [-20994, 0], [0, 3732], [0, 3569], [0, 1216], [0, -2655], [55086, 0], [0, -2195], [-7392, 0], [0, -1478], [84618, 0], [0, -1674], [0, -479], [-82980, 0], [0, 5240], [-14420, 0], [0, -3379], [43890, 0], [15316, 0], [0, -1594], [103534, 0], [0, 1981], [-34464, 0], [0, 4794], [-33960, 0], [-35836, 0], [0, 51], [0, -5478], [7914, 0], [0, -3118], [0, -3637], [-93108, 0], [-37708, 0], [0, -1548], [0, -3840], [-73590, 0], [0, 298], [-85894, 0], [0, -4269], [38220, 0], [0, -6384], [13628, 0], [0, -121], [84598, 0], [0, 1973], [56364, 0], [0, 4224], [0, -422], [102798, 0], [-67876, 0], [0, 4729], [57714, 0], [54700, 0], [0, 941], [0, 4750], [-86236, 0], [76682, 0], [0, 1095], [-16414, 0], [0, -6015], [131832, 0], [0, 3182], [502, 0], [99132, 0], [0, 2358], [0, 697], [0, -6930], [0, 3198], [-15572, 0], [0, 1908], [74090, 0], [0, 3821], [0, -3681], [858, 0], [0, -3443], [-38436, 0], [-54534, 0], [61140, 0], [0, -702], [0, -7383], [0, -7135], [0, -3201], [-101592, 0], [-82028, 0], [113258, 0], [0, 7129], [0, -109], [22932, 0], [-33068, 0], [-166102, 0], [15984, 0], [0, -7572], [0, 6010], [0, 3134], [0, 2044], [0, -1641], [88974, 0], [-28172, 0], [0, -7156], [-87190, 0], [157956, 0], [0, 2186], [86182, 0], [-31518, 0], [-157228, 0], [135002, 0], [0, -2785], [0, -1169], [172278, 0], [-152642, 0], [131668, 0], [52, 0], [0, -4776], [0, -3083], [0, -4104], [0, -2447], [0, -8023], [-186996, 0], [206660, 0], [92952, 0], [0, 6906], [-42078, 0], [-75602, 0], [0, -999], [0, -5206], [18990, 0], [0, 4643], [0, -9007], [0, 9367], [110616, 0], [0, -1428], [-165292, 0], [0, 3610], [0, 4231], [31876, 0], [18070, 0], [0, -1805], [0, 7725], [0, 4842], [90522, 0], [0, -3488], [59868, 0], [61758, 0], [0, -7444], [0, 1786], [-91542, 0], [0, 3012], [-168936, 0], [118676, 0], [193750, 0], [0, -3029], [0, 2947], [-209882, 0], [81936, 0], [189628, 0], [0, 7008], [0, -9041], [0, 7243], [0, -2708], [84840, 0], [0, -6476], [74738, 0], [256830, 0], [-88414, 0], [0, 11933], [98958, 0], [0, 5719], [229746, 0], [-243380, 0], [0, 12964], [0, 3207], [0, -13000], [150932, 0], [0, -1534], [215570, 0], [0, 453], [-124500, 0], [-157628, 0], [0, 3760], [45430, 0], [0, 11381], [-23874, 0], [112300, 0], [0, -8091], [0, -2162], [-76242, 0], [0, -7199], [159030, 0], [0, 10011], [0, -9157], [0, -1240], [-3594, 0], [179620, 0], [7992, 0], [103534, 0], [0, -10291], [-158448, 0], [-214868, 0], [115198, 0], [0, -1469], [0, -3244], [0, 11459], [43878, 0], [0, -7902], [0, 9229], [0, -13966], [0, 8644], [-143328, 0], [107498, 0], [0, 1971], [-66552, 0], [246762, 0], [-29180, 0], [0, -3926]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_768_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_768_4_a_i();".
// 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_4_a_i(:prec:=2)
    chi := MakeCharacter_768_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_a_i();".
// 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_4_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_768_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-396, 0, 1]>,<7,R![-396, 0, 1]>,<11,R![-48, 1]>,<19,R![92, 1]>],Snew);
    return Vf;
end function;