
// Make newform 1280.4.d.k in Magma, downloaded from the LMFDB on 23 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_k();".
// 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_k();".
// 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+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, 2], [0, 5], [6, 0], [0, 60], [0, 50], [-30, 0], [0, -40], [178, 0], [0, 166], [-20, 0], [0, -10], [250, 0], [0, 142], [-214, 0], [0, -490], [0, -800], [0, 250], [0, 774], [100, 0], [230, 0], [1320, 0], [0, -982], [-874, 0], [-310, 0], [0, 1498], [1402, 0], [0, 1194], [0, 650], [-1510, 0], [-1246, 0], [0, -2660], [-2770, 0], [0, -560], [0, 2350], [580, 0], [0, -1310], [0, -1862], [726, 0], [0, 3250], [0, 1120], [0, 2842], [-3180, 0], [-4670, 0], [0, 2990], [-4240, 0], [0, 4060], [5622, 0], [0, -1554], [0, -1134], [1710, 0], [-4440, 0], [-850, 0], [0, -660], [-7590, 0], [762, 0], [0, -150], [6580, 0], [0, -4530], [-6950, 0], [0, -3882], [0, -1370], [0, -4106], [2220, 0], [9430, 0], [0, -6470], [0, 900], [530, 0], [0, -414], [0, 8614], [-2270, 0], [8080, 0], [-2374, 0], [0, -1810], [0, 8120], [11782, 0], [0, 4350], [0, -7470], [11698, 0], [3650, 0], [0, 1120], [0, -4850], [12580, 0], [13130, 0], [8560, 0], [0, -4258], [2550, 0], [6710, 0], [0, -14482], [-162, 0], [0, 15974], [10760, 0], [-9266, 0], [0, 2860], [0, -7160], [-1398, 0], [0, 7446], [16438, 0], [0, -7322], [0, 10878], [0, -16114], [0, 3690], [0, 2562], [6050, 0], [0, 8260], [-16870, 0], [0, -966], [26290, 0], [-11640, 0], [25450, 0], [-16694, 0], [0, -15890], [1230, 0], [0, -10840], [-14060, 0], [-17650, 0], [0, -27358], [-6786, 0], [0, -9030], [0, 15600], [0, -16850], [-7990, 0], [0, -18690], [0, 19182], [0, 23380], [0, 11850], [0, -25646], [30280, 0], [17446, 0], [0, -16750], [0, 36560], [-30142, 0], [-11860, 0], [0, -37010], [11718, 0], [4706, 0], [0, 28670], [0, -20434], [0, 3930], [4854, 0], [0, -13140], [0, -22050], [14578, 0], [0, -37054], [0, -6150], [-8200, 0], [0, 42990], [-32130, 0], [0, 15440], [-46938, 0], [0, -31230], [25550, 0], [0, -4318], [1766, 0], [0, 41906], [-25140, 0], [32920, 0], [10150, 0], [-28530, 0], [0, 9678], [0, -36986], [3350, 0], [43774, 0], [0, 8740], [-48310, 0], [2282, 0], [31580, 0], [0, 2790], [23954, 0], [0, 20830], [0, 1720], [0, -24338], [58140, 0], [37590, 0], [-33280, 0], [-9786, 0], [0, -21980], [0, 21018], [-30862, 0], [0, 32650], [-27734, 0], [0, -14580], [0, -24010], [8390, 0], [50502, 0], [0, 49746], [0, -9830], [0, 29122], [42050, 0], [31180, 0], [-5990, 0], [0, -39138], [0, 58980], [0, 22650], [0, -16034], [32190, 0], [22350, 0], [0, -7590], [-67230, 0], [-35478, 0], [0, 44134], [27540, 0], [0, 4790], [32914, 0], [0, 34560], [0, 64290], [44720, 0], [0, -49518], [-36874, 0], [0, -18700], [6130, 0], [0, 33950], [49002, 0], [0, 50794], [34280, 0], [7850, 0], [-20446, 0], [1218, 0], [24326, 0], [0, 27730], [0, 62750], [9880, 0], [32946, 0], [11278, 0], [0, 33246], [0, 16750], [-14890, 0], [19760, 0], [76414, 0], [0, 63780], [0, 71250], [0, 47480], [-70300, 0], [-26550, 0], [0, 87718], [46834, 0], [52950, 0], [0, 32790], [0, -16760], [58380, 0], [0, 6778], [0, -107700], [-49742, 0], [0, -8314], [33170, 0], [-106080, 0], [45874, 0], [0, 82020], [0, -71520], [-71682, 0], [0, -64350], [402, 0], [11694, 0], [-18750, 0], [0, -87710], [0, 67560], [0, -34438], [0, -2254], [0, 24030], [46550, 0], [-23738, 0], [0, 58526], [0, -12494], [0, -75990], [-20190, 0], [0, 126920], [0, -38346], [-93962, 0], [0, -8578], [0, -85530], [0, -93378], [0, -68986], [-22130, 0], [-78720, 0], [17850, 0], [56018, 0], [0, -63134], [0, -29226], [106650, 0], [0, -74100], [104822, 0], [114460, 0], [135214, 0], [0, -104118], [0, 56874], [-42580, 0], [-46270, 0], [0, -99890], [118840, 0], [92950, 0], [0, 42650], [0, -68994], [87270, 0], [0, -107140], [0, -84830], [0, -14950], [-49300, 0], [0, 156470], [0, 13320], [0, 44934], [72110, 0], [0, 34530], [-58280, 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_k();".
// 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_k(: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_k();".
// 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_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1280_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![4, 0, 1]>,<7,R![-6, 1]>,<11,R![3600, 0, 1]>],Snew);
    return Vf;
end function;