
// Make newform 1280.4.d.c in Magma, downloaded from the LMFDB on 16 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_c();".
// 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_c();".
// 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, 4], [0, 5], [-16, 0], [0, 60], [0, -86], [18, 0], [0, 44], [48, 0], [0, 186], [-176, 0], [0, 254], [-186, 0], [0, 100], [-168, 0], [0, -498], [0, 252], [0, 58], [0, -1036], [168, 0], [-506, 0], [-272, 0], [0, 948], [1014, 0], [-766, 0], [0, -1314], [-448, 0], [0, -1548], [0, -278], [-558, 0], [-344, 0], [0, 780], [-666, 0], [0, -884], [0, -114], [-40, 0], [0, 154], [0, 2180], [3696, 0], [0, -1302], [0, -4308], [0, 1550], [-48, 0], [1058, 0], [0, -3714], [-1768, 0], [0, -4036], [-680, 0], [0, 2388], [0, -3874], [-3162, 0], [-5424, 0], [-3886, 0], [0, 5100], [2178, 0], [-6144, 0], [0, -822], [-8480, 0], [0, -1138], [-5706, 0], [0, 3028], [0, 3390], [0, -4156], [6552, 0], [1366, 0], [0, -2598], [0, 3292], [6194, 0], [0, 10020], [0, 3130], [4194, 0], [-4104, 0], [-7496, 0], [0, -5842], [0, 412], [-2568, 0], [0, 13086], [0, -10454], [-10830, 0], [8566, 0], [0, 13884], [0, 4286], [-6336, 0], [-8974, 0], [-2968, 0], [0, 12372], [11394, 0], [358, 0], [0, 7530], [13768, 0], [0, 13380], [6336, 0], [-5008, 0], [0, -12900], [0, -8116], [-4944, 0], [0, 5466], [-10074, 0], [0, 13828], [0, 15226], [0, -13228], [0, 8490], [0, -10284], [-1770, 0], [0, -6068], [21506, 0], [0, -12108], [15474, 0], [-2520, 0], [12790, 0], [-11576, 0], [0, 20126], [27942, 0], [0, 22540], [-5128, 0], [-12798, 0], [0, -21148], [16464, 0], [0, 24234], [0, -22836], [0, 26318], [28802, 0], [0, 2526], [0, 23076], [0, 7868], [0, -21510], [0, 30014], [816, 0], [-9952, 0], [0, 33946], [0, 23420], [-14592, 0], [-9056, 0], [0, -17554], [36438, 0], [-9022, 0], [0, 1470], [0, 5252], [0, -12294], [-15546, 0], [0, -19364], [0, -7314], [11984, 0], [0, -13500], [0, 44602], [35448, 0], [0, 12590], [-24906, 0], [0, -23204], [-19848, 0], [0, -27542], [-20718, 0], [0, 25172], [-12864, 0], [0, 23092], [14208, 0], [-26584, 0], [162, 0], [29734, 0], [0, -17142], [0, 26436], [-27882, 0], [12656, 0], [0, -2916], [-6894, 0], [-45264, 0], [-52016, 0], [0, -13858], [4370, 0], [0, -36786], [0, 57756], [0, -6374], [-22008, 0], [-40826, 0], [37264, 0], [-26058, 0], [0, -12308], [0, -27426], [-4000, 0], [0, 41194], [-69176, 0], [0, -24372], [0, -34306], [42630, 0], [-50904, 0], [0, 67950], [0, -47078], [0, 32132], [11782, 0], [20208, 0], [71234, 0], [0, -22812], [0, -70180], [0, -12390], [0, -59532], [-39642, 0], [47954, 0], [0, -51878], [-3390, 0], [25440, 0], [0, -55254], [59488, 0], [0, 6446], [3746, 0], [0, 46380], [0, -40518], [-9728, 0], [0, 43620], [-60186, 0], [0, -76196], [23762, 0], [0, 82062], [-60688, 0], [0, 51972], [67608, 0], [51910, 0], [-14120, 0], [2418, 0], [-93504, 0], [0, 68346], [0, 77246], [-78712, 0], [20802, 0], [72232, 0], [0, 27972], [0, -27058], [-16170, 0], [-64800, 0], [19856, 0], [0, 79164], [0, 66058], [0, 56972], [2512, 0], [74406, 0], [0, -85916], [94200, 0], [14258, 0], [0, -77394], [0, -46020], [-20760, 0], [0, 65172], [0, 27244], [-55840, 0], [0, -15830], [86130, 0], [-57144, 0], [111880, 0], [0, -33972], [0, -105044], [9576, 0], [0, 18970], [58818, 0], [35088, 0], [-23066, 0], [0, -27702], [0, -37332], [0, 121262], [0, 105892], [0, 894], [3670, 0], [-30824, 0], [0, 104244], [0, 96446], [0, 42010], [-73086, 0], [0, -78244], [0, 55626], [-89322, 0], [0, 14164], [0, -74274], [0, 102058], [0, -4156], [62422, 0], [-15776, 0], [123026, 0], [-31504, 0], [0, -68316], [0, 51610], [23782, 0], [0, 60732], [-99144, 0], [91496, 0], [-14976, 0], [0, -109378], [0, 30772], [-83904, 0], [11858, 0], [0, 131310], [-81880, 0], [104802, 0], [0, 79722], [0, 75684], [-29514, 0], [0, 63612], [0, -104438], [0, -68262], [60112, 0], [0, -1554], [0, 82140], [0, 33428], [-139610, 0], [0, -164982], [-33488, 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_c();".
// 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_c(: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_c();".
// 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_c( : 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![3600, 0, 1]>],Snew);
    return Vf;
end function;