
// Make newform 768.4.a.h in Magma, downloaded from the LMFDB on 19 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_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_4_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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    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, 5], [20, 0], [0, 14], [-34, 0], [52, 0], [0, 22], [0, 71], [0, -39], [0, -96], [-26, 0], [252, 0], [0, 122], [0, -241], [364, 0], [0, 260], [628, 0], [0, -118], [338, 0], [0, -279], [1036, 0], [234, 0], [-178, 0], [0, 91], [0, 667], [1404, 0], [0, -14], [1378, 0], [0, -633], [1572, 0], [2854, 0], [1964, 0], [0, 533], [0, 801], [0, -1248], [2932, 0], [0, -1300], [0, -511], [-1308, 0], [0, 706], [0, 332], [-2490, 0], [0, 963], [0, 763], [-924, 0], [0, -805], [156, 0], [0, -226], [2826, 0], [0, 872], [-3354, 0], [-6396, 0], [6882, 0], [0, 0], [0, 507], [0, -2101], [0, -390], [6266, 0], [-8596, 0], [0, -2969], [-4940, 0], [0, 1196], [-3106, 0], [0, 2379], [2908, 0], [4298, 0], [-9996, 0], [0, 1412], [6738, 0], [0, 754], [0, 2697], [0, -2964], [-12788, 0], [0, 820], [0, 949], [0, 780], [3582, 0], [5126, 0], [2924, 0], [0, 2586], [0, -5602], [-6274, 0], [0, -1625], [-5084, 0], [14190, 0], [-6474, 0], [0, -2235], [0, 4043], [-3796, 0], [0, -3710], [0, -5447], [15452, 0], [52, 0], [0, 4394], [0, -5785], [-714, 0], [5980, 0], [0, -4854], [18500, 0], [0, -3099], [268, 0], [-13866, 0], [-5140, 0], [9386, 0], [8844, 0], [-9406, 0], [0, -8294], [-1262, 0], [0, 5759], [0, -2524], [16874, 0], [20748, 0], [0, -5247], [17758, 0], [-1148, 0], [0, 9542], [0, 7449], [18356, 0], [0, 5392], [-12082, 0], [0, 4505], [33508, 0], [-364, 0], [0, -1361], [0, -8346], [0, -5586], [0, 1629], [0, 9270], [27924, 0], [0, -3160], [0, -4979], [0, -5258], [-15834, 0], [-16666, 0], [0, -10945], [20228, 0], [0, 3185], [-9242, 0], [10972, 0], [0, -3301], [0, 1261], [18876, 0], [0, 2466], [0, -10634], [0, -14552], [-25194, 0], [9308, 0], [0, -9476], [0, 508], [-42830, 0], [-23964, 0], [0, -9984], [-31972, 0], [0, 9496], [0, 14261], [-13650, 0], [7098, 0], [0, -14611], [-9900, 0], [-46938, 0], [0, 2471], [-53052, 0], [-41890, 0], [0, -3840], [0, 117], [0, 14124], [30238, 0], [0, 4065], [36396, 0], [0, -14360], [0, -17368], [-15782, 0], [0, -21207], [-64934, 0], [-41444, 0], [0, 13741], [0, 10439], [0, -20832], [0, -15951], [-70356, 0], [0, -8730], [1482, 0], [0, 22516], [0, 9945], [0, -21450], [-22828, 0], [19422, 0], [0, -17072], [-2302, 0], [-74932, 0], [16420, 0], [0, -28379], [31156, 0], [-23894, 0], [8762, 0], [0, 21862], [49394, 0], [0, 26260], [0, -8663], [0, 7455], [0, 6410], [-44134, 0], [-13884, 0], [0, -11245], [0, 6239], [-39236, 0], [9546, 0], [-79412, 0], [51766, 0], [0, 6481], [0, -22809], [66716, 0], [0, -22554], [-48106, 0], [0, -7059], [-84018, 0], [0, 28548], [0, 29905], [0, -25038], [0, 3619], [57694, 0], [0, 25663], [93660, 0], [0, -2288], [-15510, 0], [0, -35094], [0, -1677], [13916, 0], [0, 16770], [10948, 0], [0, 25363], [-40214, 0], [-59684, 0], [0, -20422], [12350, 0], [0, -37315], [59956, 0], [0, 26214], [44668, 0], [34588, 0], [0, -25571], [0, 17016], [-76158, 0], [0, -12770], [0, 8601], [38740, 0], [79564, 0], [0, -42172], [0, -2358], [114898, 0], [0, -11578], [-117606, 0], [0, 891], [50980, 0], [0, 25746], [107900, 0], [0, 9871], [123942, 0], [0, 19331], [28068, 0], [0, 26586], [0, 26072], [106366, 0], [123956, 0], [0, -15679], [6522, 0], [63180, 0], [0, 3653], [0, -42228], [104260, 0], [-60470, 0], [0, 16969], [-17134, 0], [0, -20733], [78468, 0], [0, -6812], [78338, 0], [34260, 0], [0, 25162], [0, -39057], [0, -5622], [0, 14508], [-12564, 0], [0, -37284], [107782, 0], [0, 3821], [0, 27165], [20114, 0], [0, -37583], [-10828, 0], [101738, 0], [-121700, 0], [0, 9392], [0, -42003], [0, -12213], [0, -24453], [-9244, 0], [-87276, 0], [25358, 0], [0, 21757], [0, -38679], [-11596, 0], [-106068, 0], [35702, 0], [131412, 0], [0, 20670], [0, -51418], [0, -61932], [0, -12044], [0, 43419], [133470, 0], [112372, 0], [0, 32404], [-33606, 0], [-76492, 0], [0, 17446], [-173030, 0], [-78, 0], [-132428, 0], [-52130, 0], [0, 59183], [0, -5143], [11206, 0], [11102, 0], [-27164, 0], [-116532, 0], [0, 11904], [0, -57895], [0, 44642], [0, -12623], [0, -74133], [-118476, 0], [-67444, 0], [-83564, 0], [0, 26728], [-78078, 0], [25458, 0], [0, -3085], [0, -22008], [1158, 0], [0, -49525], [0, 36699], [0, 60943], [173724, 0], [0, 42510], [156124, 0], [0, 19534], [0, -12497], [-181948, 0], [48054, 0], [0, 48307], [0, 37375], [0, -55800], [-101142, 0], [0, 38576], [-57508, 0], [15790, 0], [0, -22996], [0, -20696], [83226, 0], [0, -6948], [-67596, 0], [136916, 0], [-119326, 0], [0, -12329], [0, 26169], [113030, 0], [54300, 0], [173724, 0], [0, 3528], [0, -10049], [0, 48997], [0, 80230], [-15492, 0], [0, -59852], [211714, 0], [12558, 0], [-241202, 0], [0, -34567], [-108842, 0], [0, -52887], [-230910, 0], [101940, 0], [0, -40292], [0, -32475], [0, 81098], [-16276, 0], [0, 1774], [-71422, 0], [0, 90817], [272428, 0], [218308, 0], [0, 31520], [161862, 0], [0, -55797], [14838, 0], [5356, 0], [0, 42297], [0, -18004], [-48802, 0], [0, 52083], [-130410, 0], [0, 61911], [0, -42523], [0, -27990], [89310, 0], [-70012, 0], [205452, 0], [-110118, 0], [0, -64363], [-110460, 0], [100820, 0], [-31790, 0], [0, -38305], [0, 94132], [0, -53079], [-57570, 0], [0, 43446], [0, -15739], [0, 43680], [0, -2236], [175332, 0], [127950, 0], [0, -42993], [288972, 0], [11050, 0], [-206804, 0], [0, 25382]];
    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_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_4_a_h(: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_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_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_768_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-8, 0, 1]>,<7,R![-200, 0, 1]>,<11,R![-20, 1]>,<19,R![-52, 1]>],Snew);
    return Vf;
end function;