
// Make newform 1280.4.d.d in Magma, downloaded from the LMFDB on 02 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1280_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1280_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_1280_4_d_d();".
// 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_1280_4_d_d();".
// 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 := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1280_d();"
function MakeCharacter_1280_d()
    N := 1280;
    order := 2;
    char_gens := [511, 261, 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_1280_d_Hecke();"
function MakeCharacter_1280_d_Hecke(Kf)
    N := 1280;
    order := 2;
    char_gens := [511, 261, 257];
    char_values := [[1, 0], [-1, 0], [1, 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]];
    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], [0, 4], [0, -5], [-16, 0], [0, -36], [0, -42], [-110, 0], [0, -116], [-16, 0], [0, 198], [240, 0], [0, 258], [-442, 0], [0, 292], [392, 0], [0, -142], [0, 348], [0, -570], [0, 692], [-168, 0], [134, 0], [784, 0], [0, 564], [-1034, 0], [-382, 0], [0, 674], [992, 0], [0, 500], [0, 1046], [-558, 0], [-328, 0], [0, -212], [-1434, 0], [0, -2196], [0, 2418], [-3672, 0], [0, 358], [0, 2564], [3056, 0], [0, -234], [0, 524], [0, 1138], [1520, 0], [-2142, 0], [0, 2306], [-3288, 0], [0, -3876], [-5688, 0], [0, -2796], [0, -4446], [-2522, 0], [816, 0], [-5422, 0], [0, 5900], [5250, 0], [-6240, 0], [0, -714], [2144, 0], [0, 4466], [5302, 0], [0, 6932], [0, 4034], [0, -3836], [-664, 0], [-2986, 0], [0, 2726], [0, 9212], [-3278, 0], [0, -4956], [0, 4678], [1890, 0], [6472, 0], [1960, 0], [0, -8750], [0, 380], [-9688, 0], [0, -3870], [0, 1622], [9906, 0], [4214, 0], [0, -7012], [0, 1602], [-3584, 0], [-3470, 0], [3416, 0], [0, -9708], [-10366, 0], [16742, 0], [0, -1258], [13528, 0], [0, 6916], [1728, 0], [-16656, 0], [0, 1084], [0, 5804], [-10512, 0], [0, -4314], [1190, 0], [0, 3780], [0, -11002], [0, 5908], [0, 14806], [0, -684], [2582, 0], [0, 2540], [22786, 0], [0, -7884], [-21902, 0], [-15080, 0], [19702, 0], [7320, 0], [0, -24350], [-19546, 0], [0, -3476], [-21880, 0], [20994, 0], [0, -18204], [2064, 0], [0, 9942], [0, 24236], [0, -17614], [13058, 0], [0, 33186], [0, 31716], [0, -2084], [0, -7418], [0, 18242], [3024, 0], [26176, 0], [0, -17818], [0, -22052], [-15840, 0], [21024, 0], [0, 38034], [-37802, 0], [15042, 0], [0, -5950], [0, 23364], [0, 19846], [-24762, 0], [0, -16644], [0, -3182], [7504, 0], [0, -12604], [0, 12230], [-9656, 0], [0, -5806], [39094, 0], [0, 18876], [32296, 0], [0, -9578], [-41710, 0], [0, 2260], [33696, 0], [0, -7756], [-5312, 0], [23576, 0], [-19038, 0], [-20570, 0], [0, -21386], [0, 38020], [-20202, 0], [-29840, 0], [0, 12476], [-36974, 0], [16368, 0], [-49552, 0], [0, -24414], [-63214, 0], [0, -5838], [0, 8060], [0, -13210], [-10376, 0], [-4090, 0], [-39184, 0], [-30666, 0], [0, -27252], [0, 59298], [48192, 0], [0, -18154], [-17384, 0], [0, -27412], [0, -18814], [6918, 0], [-17928, 0], [0, 24850], [0, 20198], [0, 7172], [-41722, 0], [75600, 0], [-27326, 0], [0, -46812], [0, 40444], [0, 26214], [0, -844], [-48986, 0], [-29870, 0], [0, -7898], [-14142, 0], [-63040, 0], [0, 28502], [76256, 0], [0, 9554], [-33118, 0], [0, -25076], [0, 67398], [-45568, 0], [0, -44060], [10470, 0], [0, 30332], [-21166, 0], [0, -6542], [28208, 0], [0, -26876], [-28760, 0], [-15418, 0], [22024, 0], [-41870, 0], [-67552, 0], [0, 77190], [0, 22594], [-32840, 0], [-36030, 0], [-72712, 0], [0, 57604], [0, -105550], [-72618, 0], [101664, 0], [-64432, 0], [0, -58020], [0, -35722], [0, 44780], [-67600, 0], [-5722, 0], [0, -64092], [-53784, 0], [72370, 0], [0, -76590], [0, 82460], [101528, 0], [0, 1044], [0, 49036], [65088, 0], [0, -76714], [-62606, 0], [12024, 0], [50776, 0], [0, 63468], [0, -70260], [22328, 0], [0, 28006], [-107070, 0], [-26800, 0], [-9242, 0], [0, 90934], [0, -97140], [0, -98350], [0, -38620], [0, 52098], [46678, 0], [-57848, 0], [0, 40436], [0, -33598], [0, -128026], [-69886, 0], [0, 110908], [0, -89290], [45590, 0], [0, 29972], [0, -125918], [0, 90326], [0, -73596], [38486, 0], [32416, 0], [-1134, 0], [-128592, 0], [0, 96036], [0, -1050], [66534, 0], [0, -6948], [-86040, 0], [-20200, 0], [145376, 0], [0, 53186], [0, 89780], [-44928, 0], [117714, 0], [0, -93038], [-12520, 0], [17250, 0], [0, -94826], [0, 138084], [75318, 0], [0, -142564], [0, 33526], [0, -21082], [11632, 0], [0, 146706], [0, -34116], [0, -77356], [63398, 0], [0, 100982], [70096, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1280_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1280_4_d_d();".
// 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_1280_4_d_d(:prec:=2)
    chi := MakeCharacter_1280_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1280_4_d_d();".
// 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_1280_4_d_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1280_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![16, 0, 1]>,<7,R![16, 1]>,<11,R![1296, 0, 1]>],Snew);
    return Vf;
end function;