
// Make newform 960.4.f.n in Magma, downloaded from the LMFDB on 18 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_960_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_960_f_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_960_4_f_n();".
// 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_960_4_f_n();".
// 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 := [1024, 0, 65, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 33, 0, 1], [33, 1, 1, 0], [-1056, 65, -32, 1]];
    Rf_basisdens := [1, 32, 1, 32];
    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_960_f();"
function MakeCharacter_960_f()
    N := 960;
    order := 2;
    char_gens := [511, 901, 641, 577];
    v := [2, 2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_960_f_Hecke();"
function MakeCharacter_960_f_Hecke( : Kf := false)
    N := 960;
    order := 2;
    char_gens := [511, 901, 641, 577];
    char_values := [[1, 0, 0, 0], [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 := ISA(Type(Kf), Fld), 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, 0], [0, -3, 0, 0], [-5, 5, -1, 0], [0, 1, -3, -3], [-36, -1, -1, 1], [0, -49, -1, -1], [0, 39, -5, -5], [-32, -8, -8, 8], [0, 20, -8, -8], [18, 7, 7, -7], [12, -18, -18, 18], [0, -17, -25, -25], [166, 6, 6, -6], [0, -108, 0, 0], [0, -438, 14, 14], [0, 317, 1, 1], [284, 49, 49, -49], [-154, 32, 32, -32], [0, -490, 34, 34], [192, -38, -38, 38], [0, -706, 38, 38], [-540, 14, 14, -14], [0, -124, 16, 16], [-390, 48, 48, -48], [0, 920, 32, 32], [-1270, 31, 31, -31], [0, 1067, -25, -25], [0, 16, -116, -116], [198, 78, 78, -78], [0, -133, -33, -33], [0, 921, -11, -11], [524, -35, -35, 35], [0, 1217, 93, 93], [-368, -30, -30, 30], [86, 115, 115, -115], [1316, -94, -94, 94], [0, 77, 21, 21], [0, -1526, 6, 6], [0, -1608, -52, -52], [0, 207, -197, -197], [316, 9, 9, -9], [1778, 162, 162, -162], [1096, 38, 38, -38], [0, -742, 298, 298], [0, 1503, -141, -141], [-316, -66, -66, 66], [-544, 198, 198, -198], [0, -3345, -133, -133], [0, 3356, 280, 280], [-1630, -314, -314, 314], [0, -975, -435, -435], [2408, -378, -378, 378], [2206, -116, -116, 116], [-1004, 33, 33, -33], [0, -279, 389, 389], [0, 3156, -136, -136], [-7538, 41, 41, -41], [-5812, 30, 30, -30], [0, -4749, 323, 323], [918, -204, -204, 204], [0, -1278, 142, 142], [0, 4753, -371, -371], [0, -5888, -228, -228], [-184, 310, 310, -310], [0, -6742, -70, -70], [0, 6621, 361, 361], [4504, -8, -8, 8], [0, 4198, -386, -386], [0, -1504, -356, -356], [-758, 796, 796, -796], [0, -3375, -643, -643], [-5320, 452, 452, -452], [0, -5911, 5, 5], [0, -8533, -141, -141], [3352, -614, -614, 614], [0, -1218, -606, -606], [-1450, -1001, -1001, 1001], [0, 663, -1073, -1073], [2258, -126, -126, 126], [-1930, -382, -382, 382], [5404, 683, 683, -683], [-9042, -286, -286, 286], [7064, 516, 516, -516], [0, 4506, -662, -662], [-764, -802, -802, 802], [0, 2352, -196, -196], [686, 730, 730, -730], [0, 3036, -380, -380], [7090, -823, -823, 823], [0, -9851, -719, -719], [0, 8736, -132, -132], [-8912, 322, 322, -322], [0, 979, -609, -609], [-3012, -1027, -1027, 1027], [-7288, 132, 132, -132], [0, -86, -18, -18], [10818, 527, 527, -527], [-3094, 750, 750, -750], [0, -1918, -1010, -1010], [9882, 362, 362, -362], [0, 9140, 1056, 1056], [0, 1047, -365, -365], [0, 9408, -132, -132], [4982, 466, 466, -466], [-4024, -864, -864, 864], [0, 5248, 928, 928], [0, 2440, -1516, -1516], [0, -8861, -201, -201], [-5688, 1084, 1084, -1084], [4534, -1474, -1474, 1474], [0, -5473, 1499, 1499], [0, -16867, 613, 613], [0, 8023, 1083, 1083], [-1488, -626, -626, 626], [-13876, -246, -246, 246], [590, -518, -518, 518], [0, 6102, 1922, 1922], [0, 17510, 698, 698], [0, 7167, 1363, 1363], [19684, 443, 443, -443], [-15186, -668, -668, 668], [0, 7166, -354, -354], [0, 9141, 129, 129], [0, -9188, 120, 120], [4288, -2188, -2188, 2188], [-6898, 569, 569, -569], [-5694, 1018, 1018, -1018], [13928, -1000, -1000, 1000], [0, -3933, 47, 47], [0, 8325, -1979, -1979], [-13832, -88, -88, 88], [0, -2358, -434, -434], [1260, 1418, 1418, -1418], [0, 18859, 1035, 1035], [3482, -1518, -1518, 1518], [-2542, 1638, 1638, -1638], [0, -4745, 3003, 3003], [0, 13834, -970, -970], [0, 25737, -643, -643], [202, 1058, 1058, -1058], [11848, 566, 566, -566], [-11610, 465, 465, -465], [0, 11053, -1415, -1415], [0, 6228, -2336, -2336], [-27306, -878, -878, 878], [1704, -3456, -3456, 3456], [0, -10015, -1095, -1095], [0, 38779, 95, 95], [6856, 2082, 2082, -2082], [0, 22272, -588, -588], [0, 9653, -691, -691], [-31298, 1336, 1336, -1336], [0, 26782, -2182, -2182], [0, 6624, 2276, 2276], [0, 29824, -196, -196], [-25200, 432, 432, -432], [12804, 654, 654, -654], [2158, -3206, -3206, 3206], [0, -4244, 2764, 2764], [23234, 1605, 1605, -1605], [0, -36336, 556, 556], [0, 7719, 4059, 4059], [0, -17411, -1303, -1303], [5588, 1297, 1297, -1297], [0, 40835, 455, 455], [0, -8674, 418, 418], [47572, 666, 666, -666], [0, 7161, 3233, 3233]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_960_f_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_960_4_f_n();".
// 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_960_4_f_n(:prec:=4)
    chi := MakeCharacter_960_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_960_4_f_n();".
// 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_960_4_f_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_960_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![1345600, 0, 2324, 0, 1]>,<11,R![1240, 74, 1]>],Snew);
    return Vf;
end function;