
// Make newform 1280.4.d.v in Magma, downloaded from the LMFDB on 25 April 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_v();".
// 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_v();".
// 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, 3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 1], [0, 8, 0, 2], [6, 0, 4, 0]];
    Rf_basisdens := [1, 1, 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_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, 0, 0], [-1, 0, 0, 0], [1, 0, 0, 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+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, 0, 0], [0, 0, -1, 0], [0, 5, 0, 0], [0, 0, 0, -7], [0, 0, -2, 0], [0, -62, 0, 0], [-46, 0, 0, 0], [0, 0, -24, 0], [0, 0, 0, 43], [0, -90, 0, 0], [0, 0, 0, 34], [0, 214, 0, 0], [10, 0, 0, 0], [0, 0, -15, 0], [0, 0, 0, -89], [0, 678, 0, 0], [0, 0, -92, 0], [0, 250, 0, 0], [0, 0, -11, 0], [0, 0, 0, -82], [-522, 0, 0, 0], [0, 0, 0, -196], [0, 0, -85, 0], [-970, 0, 0, 0], [-934, 0, 0, 0], [0, 602, 0, 0], [0, 0, 0, -409], [0, 0, -341, 0], [0, 2154, 0, 0], [-2182, 0, 0, 0], [0, 0, 0, -293], [0, 0, 46, 0], [2094, 0, 0, 0], [0, 0, -308, 0], [0, 334, 0, 0], [0, 0, 0, 702], [0, 834, 0, 0], [0, 0, 691, 0], [0, 0, 0, 1], [0, -1838, 0, 0], [0, 0, -412, 0], [0, -1862, 0, 0], [0, 0, 0, 462], [3378, 0, 0, 0], [0, -66, 0, 0], [0, 0, 0, -272], [0, 0, 1182, 0], [0, 0, 0, -663], [0, 0, 977, 0], [0, 3250, 0, 0], [-3298, 0, 0, 0], [0, 0, 0, 124], [5150, 0, 0, 0], [0, 0, 310, 0], [-4166, 0, 0, 0], [0, 0, 0, 215], [0, -1494, 0, 0], [0, 0, 0, -1122], [0, 1006, 0, 0], [3210, 0, 0, 0], [0, 0, 813, 0], [0, 3622, 0, 0], [0, 0, -467, 0], [0, 0, 0, -1990], [-8778, 0, 0, 0], [0, -5046, 0, 0], [0, 0, -70, 0], [-2574, 0, 0, 0], [0, 0, 591, 0], [0, -10170, 0, 0], [-318, 0, 0, 0], [0, 0, 0, 2768], [0, 0, 0, 687], [0, 3278, 0, 0], [0, 0, 1144, 0], [0, 0, 0, 257], [0, -834, 0, 0], [0, -8734, 0, 0], [242, 0, 0, 0], [6514, 0, 0, 0], [0, 0, -3596, 0], [0, -7250, 0, 0], [0, 0, 0, -1114], [11482, 0, 0, 0], [0, 0, 0, 848], [0, 0, -167, 0], [-1306, 0, 0, 0], [9526, 0, 0, 0], [0, 1518, 0, 0], [0, 0, 0, -3867], [0, 0, 3797, 0], [0, 0, 0, -852], [0, 0, 0, 293], [0, 0, 662, 0], [0, 0, 4320, 0], [0, 0, 0, 687], [0, 18550, 0, 0], [2102, 0, 0, 0], [0, 0, 3957, 0], [0, -9922, 0, 0], [0, 0, -831, 0], [0, -15094, 0, 0], [0, 0, -1265, 0], [5906, 0, 0, 0], [0, 0, -1094, 0], [-13286, 0, 0, 0], [0, 0, 2019, 0], [11442, 0, 0, 0], [0, 0, 0, -3164], [-3110, 0, 0, 0], [0, 0, 0, 2503], [0, 5342, 0, 0], [-19714, 0, 0, 0], [0, 0, -2944, 0], [0, 0, 0, 2742], [-2690, 0, 0, 0], [0, 0, -2737, 0], [0, 0, 0, -4019], [0, -3478, 0, 0], [0, 0, 2364, 0], [0, 110, 0, 0], [-14278, 0, 0, 0], [0, -18386, 0, 0], [0, 0, 3425, 0], [0, 0, -2126, 0], [0, -15830, 0, 0], [0, 20050, 0, 0], [0, 0, 0, -4724], [0, 0, 0, -2535], [0, -17198, 0, 0], [0, 0, -1028, 0], [0, 0, 0, -541], [0, 0, 0, -1662], [0, -11474, 0, 0], [-31802, 0, 0, 0], [-5310, 0, 0, 0], [0, -37938, 0, 0], [0, 0, -8415, 0], [0, -17526, 0, 0], [-8970, 0, 0, 0], [0, 0, -794, 0], [0, 15550, 0, 0], [0, 0, 0, -5973], [0, 0, -193, 0], [0, 19066, 0, 0], [0, 0, 0, -10676], [0, 14462, 0, 0], [-29346, 0, 0, 0], [0, 0, 5100, 0], [0, 0, 0, -5535], [0, -32126, 0, 0], [-33570, 0, 0, 0], [0, 0, 1439, 0], [0, 0, 0, -10471], [0, 0, 2679, 0], [0, 0, 0, 5410], [0, 0, 0, -8388], [-21994, 0, 0, 0], [16286, 0, 0, 0], [0, 24302, 0, 0], [0, 0, -4443, 0], [22422, 0, 0, 0], [0, 0, 0, 9789], [0, 0, -5750, 0], [28986, 0, 0, 0], [0, 0, 0, 7183], [0, 0, 0, 2682], [0, 406, 0, 0], [5810, 0, 0, 0], [0, 28302, 0, 0], [0, 0, -12424, 0], [0, 26382, 0, 0], [0, 0, 0, -1390], [-3322, 0, 0, 0], [0, 0, 0, -8816], [45990, 0, 0, 0], [0, 0, -6006, 0], [0, 68858, 0, 0], [0, 0, 0, 5211], [0, 15626, 0, 0], [0, 0, 0, -3417], [0, 0, -3914, 0], [0, -46042, 0, 0], [-59946, 0, 0, 0], [0, 0, 0, 11073], [0, 33810, 0, 0], [0, 32506, 0, 0], [0, 0, -5697, 0], [55346, 0, 0, 0], [0, 0, 0, 10274], [68378, 0, 0, 0], [0, 0, -8951, 0], [0, 0, -4054, 0], [0, 38970, 0, 0], [0, 0, -7687, 0], [-60018, 0, 0, 0], [49310, 0, 0, 0], [0, -43478, 0, 0], [-7454, 0, 0, 0], [0, 0, 0, 2031], [0, -23770, 0, 0], [0, 0, 0, -8226], [0, -25754, 0, 0], [11410, 0, 0, 0], [0, 0, 15844, 0], [0, -23646, 0, 0], [0, 0, 0, 6840], [0, 0, 8791, 0], [25110, 0, 0, 0], [0, 0, -4030, 0], [-90366, 0, 0, 0], [0, 16830, 0, 0], [0, 0, 0, -2513], [0, 0, 14107, 0], [0, 0, 0, -14588], [15930, 0, 0, 0], [0, 0, 0, 13419], [-40062, 0, 0, 0], [0, 0, 0, -12775], [0, -18622, 0, 0], [0, 2270, 0, 0], [0, 0, 0, 6796], [-91630, 0, 0, 0], [0, 0, 0, -23331], [0, 0, 18761, 0], [0, 27886, 0, 0], [57798, 0, 0, 0], [0, 0, 0, -5704], [0, 0, 0, -1827], [0, 0, -17814, 0], [0, -107582, 0, 0], [0, 0, -13432, 0], [0, 0, 0, 7910], [16890, 0, 0, 0], [0, 0, 5749, 0], [0, 0, 0, -8861], [1414, 0, 0, 0], [0, 92358, 0, 0], [0, 0, -16896, 0], [0, 0, 0, -806], [0, 0, 20451, 0], [0, 0, -13722, 0], [0, 0, 0, -13205], [0, -25690, 0, 0], [-7758, 0, 0, 0], [0, 0, 0, -8296], [0, 0, 0, 6323], [0, 0, 4394, 0], [0, 0, -13548, 0], [0, 0, 0, 13397], [0, 2866, 0, 0], [29202, 0, 0, 0], [0, 0, 0, 725], [6194, 0, 0, 0], [0, 29282, 0, 0], [0, 0, -24704, 0], [0, -85638, 0, 0], [0, 0, 14439, 0], [0, 36606, 0, 0], [32726, 0, 0, 0], [0, 0, 0, -24335], [0, 0, -20103, 0], [0, -58030, 0, 0], [0, 13418, 0, 0], [42034, 0, 0, 0], [0, 0, -8976, 0], [0, 110230, 0, 0], [95862, 0, 0, 0], [0, 0, 7113, 0], [0, -12858, 0, 0], [0, -60898, 0, 0], [0, 0, 8581, 0], [88702, 0, 0, 0], [0, 0, 0, -2288], [27514, 0, 0, 0], [0, 0, 0, -2037], [0, 0, -19377, 0], [0, -100010, 0, 0], [-64630, 0, 0, 0], [0, 0, -4394, 0], [0, 0, 0, -15047], [0, 0, 0, 22402], [0, 0, 0, 23029], [0, 82858, 0, 0], [0, 0, -16949, 0], [0, 0, 0, 20162], [87218, 0, 0, 0], [0, -2946, 0, 0], [0, 0, 0, -13428], [-34874, 0, 0, 0], [0, -116870, 0, 0], [0, 0, 19929, 0], [26518, 0, 0, 0], [0, 0, 12686, 0], [0, -123678, 0, 0], [0, 314, 0, 0], [0, 0, 0, -19438], [0, -99658, 0, 0], [0, 0, -1440, 0], [0, 0, -11787, 0], [-82322, 0, 0, 0], [0, -128766, 0, 0], [0, 0, 0, 13204]];
    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_v();".
// 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_v(:prec:=4)
    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_v();".
// 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_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1280_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![20, 0, 1]>,<7,R![-980, 0, 1]>,<11,R![80, 0, 1]>],Snew);
    return Vf;
end function;