
// Make newform 960.3.bg.i in Magma, downloaded from the LMFDB on 06 November 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_960_bg();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_960_bg_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_3_bg_i();".
// 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_3_bg_i();".
// 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 := [9, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 3, 3];
    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_bg();"
function MakeCharacter_960_bg()
    N := 960;
    order := 4;
    char_gens := [511, 901, 641, 577];
    v := [4, 4, 4, 3];
    // 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_bg_Hecke();"
function MakeCharacter_960_bg_Hecke( : Kf := false)
    N := 960;
    order := 4;
    char_gens := [511, 901, 641, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 1, 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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, -1], [1, 2, -3, -1], [1, 2, 1, 0], [-4, -3, 0, 3], [8, 0, -8, 2], [-10, -6, -10, 0], [0, -6, 6, -6], [14, 0, -14, 2], [0, -7, -18, -7], [-4, 6, 0, -6], [-16, 18, -16, 0], [-14, 6, 0, -6], [2, 0, -2, -20], [32, 10, 32, 0], [-14, 0, 14, -12], [0, 31, -36, 31], [-50, 18, 0, -18], [50, -4, 50, 0], [-68, 0, 0, 0], [19, 0, -19, -48], [0, -10, 0, -10], [4, 0, -4, 14], [0, 36, -6, 36], [-5, -16, -5, 0], [-34, 57, 0, -57], [-77, 0, 77, 10], [-32, -30, -32, 0], [0, -6, -54, -6], [56, 0, -56, -34], [25, 114, 25, 0], [-40, -27, 0, 27], [-76, -74, -76, 0], [0, 56, 54, 56], [0, 7, -102, 7], [2, 60, 0, -60], [-34, 14, -34, 0], [-160, 0, 160, -24], [26, -58, 26, 0], [-56, 0, 56, 74], [0, -75, 0, -75], [154, 54, 0, -54], [4, 18, 0, -18], [-89, 0, 89, 136], [82, 12, 82, 0], [0, -12, 222, -12], [-206, 24, 0, -24], [67, 0, -67, -82], [-116, -112, -116, 0], [0, -4, 234, -4], [-22, 0, 22, 150], [0, -4, -336, -4], [-16, 48, 0, -48], [368, -15, 0, 15], [-28, 50, -28, 0], [-310, 0, 310, -26], [0, 99, 246, 99], [14, 48, 0, -48], [92, -158, 92, 0], [358, -6, 0, 6], [38, 0, -38, 32], [70, 0, -70, 136], [-22, 120, -22, 0], [-116, -192, 0, 192], [25, 0, -25, 104], [268, -130, 268, 0], [-122, 150, 0, -150], [253, -32, 253, 0], [-80, 196, -80, 0], [0, 178, -138, 178], [122, 0, -122, 118], [0, 54, -84, 54], [-47, 158, -47, 0], [122, 0, -122, 170], [0, 0, 210, 0], [80, 0, -80, 74], [0, 221, -6, 221], [-82, -30, -82, 0], [-50, 192, 0, -192], [0, -176, -84, -176], [0, -101, 336, -101], [22, 96, 0, -96], [496, 126, 0, -126], [-95, 0, 95, 204], [0, 140, 90, 140], [88, 0, -88, 272], [0, 18, 342, 18], [31, -208, 31, 0], [98, 255, 0, -255], [103, 0, -103, 190], [-452, 30, -452, 0], [0, 100, 60, 100], [-275, -126, -275, 0], [260, 63, 0, -63], [0, -226, 186, -226], [-208, 0, 208, -162], [0, -119, -486, -119], [-134, 186, 0, -186], [362, 0, -362, -180], [-446, -6, 0, 6], [554, 88, 554, 0], [-170, 36, -170, 0], [-236, 0, 236, -356], [0, 76, -786, 76], [586, -138, 0, 138], [-395, 84, -395, 0], [-452, -130, -452, 0], [488, 0, -488, -30], [0, -82, -168, -82], [374, 228, 0, -228], [325, 154, 325, 0], [314, 0, -314, -246], [74, 386, 74, 0], [0, 136, -486, 136], [32, -30, 0, 30], [106, -24, 0, 24], [152, 0, -152, 500], [20, -246, 20, 0], [40, 0, -40, 106], [0, -25, -1020, -25], [118, 210, 0, -210], [199, 0, -199, -28], [-248, 242, -248, 0], [-500, 0, 500, -234], [-254, 42, 0, -42], [-70, 333, 0, -333], [0, -296, 6, -296], [0, -252, 12, -252], [-131, -94, -131, 0], [332, 0, -332, 50], [0, 66, 354, 66], [188, 0, -188, -190], [-316, -222, 0, 222], [596, 294, 596, 0], [-602, 114, 0, -114], [0, 388, -258, 388], [220, 0, -220, 486], [-862, -40, -862, 0], [-152, 130, -152, 0], [0, 0, -150, 0], [-602, -300, 0, 300], [-238, 111, 0, -111], [391, 0, -391, -74], [340, -564, 340, 0], [0, 150, 330, 150], [0, 250, -540, 250], [-310, 0, 310, -314], [62, -290, 62, 0], [0, 260, 150, 260], [-742, 0, 742, 270], [-286, 38, -286, 0], [298, -96, 0, 96], [452, 0, -452, 240], [-178, 170, -178, 0], [188, -620, 188, 0], [-488, 270, 0, -270], [0, 150, 780, 150], [0, -14, -186, -14], [133, -432, 133, 0], [674, -351, 0, 351], [-164, 824, -164, 0], [-388, 0, 388, 198], [385, -626, 385, 0], [464, 219, 0, -219], [650, -46, 650, 0], [-676, 0, 676, 442], [-838, 120, 0, -120], [716, -326, 716, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_960_bg_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_960_3_bg_i();".
// 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_3_bg_i(:prec:=4)
    chi := MakeCharacter_960_bg();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_bg_i();".
// 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_3_bg_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_960_bg();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![100, 40, 8, -4, 1]>],Snew);
    return Vf;
end function;