
// Make newform 960.3.bg.o in Magma, downloaded from the LMFDB on 21 September 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_o();".
// 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_o();".
// 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 := [69169, 0, 84370, 0, 38883, 0, 8580, 0, 947, 0, 50, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-12928291, -3586587, -12845709, -2914783, -4262178, -824426, -592802, -103594, -36031, -5887, -789, -123], [11296639, 562474, 9870916, 660696, 3065002, 295452, 411858, 48828, 24459, 3274, 526, 76], [-12928291, 3586587, -12845709, 2914783, -4262178, 824426, -592802, 103594, -36031, 5887, -789, 123], [258792, -562474, 1875453, -660696, 1044636, -295452, 175684, -48828, 11572, -3274, 263, -76], [11037847, 10937541, 7995463, 9169589, 2020366, 2629098, 236174, 329722, 12887, 18661, 263, 389], [0, 4132751, 0, 3788099, 0, 1197788, 0, 161892, 0, 9661, 0, 209], [-30365717, 7244531, -28560748, 6204009, -9142406, 1875308, -1235574, 244492, -73377, 14161, -1578, 299], [-32580177, 3977582, -29765288, 4770638, -9294946, 1719696, -1240834, 248024, -73377, 15322, -1578, 338], [-44536683, 11752151, -42966047, 12456059, -13870094, 4263818, -1873086, 599642, -110723, 36531, -2367, 799], [-13511099, -10659639, -11075456, -10313951, -3217542, -3299552, -417118, -443688, -24459, -26209, -526, -561], [-30365717, -18996682, -28560748, -18660068, -9142406, -6139126, -1235574, -844134, -73377, -50692, -1578, -1098]];
    Rf_basisdens := [1, 210400, 105200, 210400, 105200, 210400, 105200, 105200, 105200, 210400, 105200, 105200];
    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, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -1, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0], [3, -1, -1, -1, 0, -1, 1, 0, -1, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, -1, 1, 0, 1], [2, 4, 2, 0, 1, -1, -2, -2, 0, 1, -1, 2], [-2, 4, -1, -4, 0, 2, -4, -1, 1, 2, 1, -2], [6, 0, -1, -2, 2, 2, 8, 1, -1, 4, 1, 0], [-3, 0, -1, 0, 2, 7, 7, 1, -1, 3, 4, -3], [-12, 2, 0, 2, -2, 0, 0, -2, -2, 0, -2, 0], [4, -4, -2, 0, -3, 5, -8, -2, 2, -1, -1, -4], [-10, -4, 2, -4, 5, 0, 0, 2, 3, -2, 3, -1], [-6, 0, 0, 0, 2, 4, -6, 2, -2, 4, 0, 2], [2, -2, 1, 0, -4, 4, -8, -1, 3, 2, 1, -2], [-10, 0, 6, -16, 1, 3, -12, 2, -6, 1, -1, 2], [3, 1, 0, -1, 2, 1, -13, 11, -2, -3, -1, -6], [-18, 4, -8, 4, -5, 0, 0, 4, 3, 2, 3, 1], [-18, -8, 2, 0, -4, 0, 14, -4, 2, 4, -4, 0], [-24, 4, 2, 4, 2, 0, 0, 6, 0, 12, 0, 6], [-1, 0, 2, 36, -2, -2, -1, -2, -2, -2, 0, 0], [-4, 14, 0, -14, 4, 12, 52, 10, -4, 4, 8, -10], [-26, 0, 13, -18, 8, 0, -20, 5, -11, 6, 3, -8], [2, 20, 0, -20, 3, 4, 20, 8, -3, -2, 1, -3], [19, 24, 0, 0, -4, 2, -23, 12, 2, 2, 12, -2], [-13, 8, 5, 8, 8, -3, 3, -3, -3, -3, 0, -3], [-5, 0, 15, -8, 10, 4, -9, 12, -5, 0, -2, -6], [-8, -2, -19, 0, -8, 2, 14, 15, -3, -8, 1, -16], [-6, -20, 2, 20, -6, -6, 0, -14, 4, 6, 2, 4], [-40, 0, 6, 60, 0, 3, -44, 2, -5, -1, -2, 3], [29, -24, -12, 0, -6, 0, -25, 11, -2, -4, 1, -10], [-1, 31, 5, 31, 6, -5, 5, -6, -9, 1, -4, -2], [20, 52, -10, 0, -5, 11, -24, -6, 2, -7, -7, -12], [-8, 6, 3, -6, 4, 16, -50, 1, -7, 8, 15, -2], [17, -56, 1, 56, -3, -23, 51, 3, 2, -17, -19, 12], [66, 34, 7, 34, 10, -8, 8, -5, -13, 8, -5, 0], [82, -68, 18, 0, 7, -23, -74, -2, -4, 15, -3, 22], [36, 0, -2, -32, 6, 0, 28, 10, 16, -8, -4, -6], [-24, -10, 17, 0, 0, -8, 18, -3, 3, 14, 3, 14], [-30, 0, -2, -80, -4, -9, -38, 0, 15, -17, -4, -5], [9, 31, -10, -31, -2, -13, 53, 3, 12, -9, -21, -6], [-4, 32, -10, 32, 6, -6, 6, 14, 4, 14, 10, 4], [2, 58, -12, 58, -16, 14, -14, 10, 24, -14, 10, 0], [-25, 0, -30, 68, -4, 4, -5, -14, 2, 24, 10, 8], [-24, -56, 6, 0, 10, 7, 22, -22, 1, -5, -10, 5], [12, -2, 17, 2, -12, -36, 70, 7, -5, -12, -7, 10], [-130, 42, -3, 42, 14, -8, 8, 13, 1, 16, 9, 4], [-101, 0, -11, -52, -22, -8, -117, -14, 13, -24, -8, 14], [60, -80, 14, 0, 20, -36, -32, 14, -14, 8, 6, 28], [-10, -64, 10, 64, -5, 0, -4, -10, -5, 10, 15, 5], [-10, 0, -2, 92, 10, 5, -18, 14, 15, -3, -4, -5], [8, 44, 4, -44, 2, -4, -164, -8, -6, -8, -2, 22], [4, 12, 12, 12, 0, 20, -20, 16, 28, -4, 8, 8], [-53, 71, -35, 71, -20, 11, -11, 10, 37, -43, 26, -16], [-28, 12, -6, 0, 13, -35, 64, 22, -18, -1, -1, 12], [22, 0, 5, -30, -10, -14, -4, 3, 25, -40, -13, -4], [1, -32, -7, 32, 11, 21, 7, 19, -4, -1, 3, -14], [194, 58, -23, 58, -18, 4, -4, 1, 13, -20, 9, -8], [-12, -20, -6, 0, -27, 15, -12, 34, 12, 9, 31, -18], [30, -20, 12, -20, 15, 0, 0, 0, 3, -6, 3, -3], [66, 0, -26, -100, -36, -20, 74, -40, 2, -12, 4, 16], [-106, 0, 6, -120, 21, 17, -92, 14, -16, 31, 7, -4], [-90, -92, 0, 0, 14, -28, 118, -22, -14, 0, -36, 14], [28, 100, 18, 100, 30, -12, 12, -10, -12, -8, 0, -10], [69, 0, -54, 52, -6, -18, 109, -26, 26, 22, 20, -12], [-50, -72, -32, 0, -7, -5, 70, 38, -10, -15, 11, -22], [-204, 96, -19, 96, -22, 2, -2, -21, 1, -42, -1, -20], [-7, 12, 30, 0, 12, -12, 3, -38, 2, 16, -22, 28], [100, 4, 24, 0, 16, 52, -140, -24, 20, -12, 32, 4], [-12, -40, -20, 40, 11, 34, -130, -4, 9, 12, 3, -17], [-150, 0, 50, 36, -4, -29, -154, -2, -21, -33, -2, -25], [10, 46, 2, -46, -18, -46, -150, -4, 16, -10, -26, -2], [221, -140, -6, 0, 12, 0, -209, 29, -6, -12, 29, 0], [-14, 0, -6, -36, -20, -11, 14, -34, -31, 17, 14, 9], [40, -6, -3, 6, 16, -8, -278, 31, -13, -40, -27, 22], [16, 0, 39, -86, -14, -18, 6, -9, -25, -28, -5, -4], [-21, 16, 17, -16, 1, 23, 209, 23, -18, 21, 39, -26], [-22, 0, 12, 0, 1, 31, -6, -4, 14, -3, 25, -2], [126, -16, 22, -16, 14, -4, 4, -6, -16, 16, -12, 6], [2, -48, 26, 48, -13, -28, -162, -2, -13, -2, 11, 17], [3, 93, -2, -93, -20, -43, 139, -67, 22, -3, -25, 48], [176, 24, -38, 24, -13, -22, 22, 2, -19, 20, 3, -1], [-286, 18, -58, 18, -26, -18, 18, -8, -4, -26, 14, -22], [69, 0, 4, 40, -22, 12, 9, 8, 22, -48, -30, 34], [4, -6, -21, 6, -4, -12, 402, -19, 25, -4, -29, -2], [-124, 0, -6, -88, -20, 8, -152, -6, 6, -20, -14, 28], [6, -32, 10, 32, 14, 22, 208, 54, -24, -6, 18, -24], [55, 32, -40, 0, -40, 0, -55, 24, 0, 0, -16, -40], [193, -56, -11, -56, 30, -45, 45, 1, -49, 55, -4, 5], [95, 0, 45, 44, 12, 36, 43, 38, -17, -16, -26, 24], [-40, -94, 23, 0, -40, 18, -14, -39, 27, 36, -25, -4], [8, 128, 30, -128, 22, 36, 40, 86, -52, -8, 44, -26], [217, -80, 8, 0, -14, -64, -189, 51, -14, 36, 9, 22], [225, 129, -3, 129, -10, 1, -1, 20, -5, 51, -6, 26], [-22, 124, 21, -124, -8, 6, -508, 61, -13, 22, 35, -70], [32, 0, 5, -170, 22, 2, 34, 21, 13, 4, 1, -20], [13, 72, 5, -72, -16, -45, 39, -41, 11, -13, -24, 43], [240, 0, 14, 0, -22, 22, -22, -2, 8, 2, -14, 12], [142, 0, 28, -232, 56, 40, 154, 50, -24, 52, 6, -16], [-128, -52, 42, -52, 32, 38, -38, 22, 66, -50, 28, -6], [-110, -148, -4, 0, 14, -72, 170, 46, -30, 12, 0, 26], [-200, 144, 42, 0, 14, -13, 190, -54, 5, 23, -30, 37], [-144, 0, -52, -52, 48, 52, -80, 16, -16, 116, 32, 4], [4, -152, -18, 152, 4, 4, -38, 6, 14, -4, -18, -16], [-112, 116, -105, 116, -34, -46, 46, 29, -21, 54, 25, 4], [-223, -140, -6, 0, 6, 78, 179, -2, 22, -34, 48, -28], [212, 26, -17, 0, -36, -10, -218, -31, 3, 16, -61, -20], [-316, 0, -42, -108, 8, 29, -328, 14, 33, 17, -6, 21], [22, -94, 20, 94, 10, -2, -254, 82, -30, -22, 8, -30], [-252, 80, -22, 80, -73, 38, -38, -30, 25, -72, -13, -17], [229, -64, -4, 0, -16, 48, -269, -73, 20, -8, -49, -24], [106, 0, 12, 208, -10, -29, 110, -12, 3, -25, 2, -19], [-202, -156, 10, 0, -7, 19, 178, -34, 12, 5, -17, -2], [-24, -38, -43, 38, 12, 48, -590, -9, 31, 24, -7, -46], [212, 154, -98, 154, -26, -52, 52, 40, -32, 92, 20, 20], [108, 124, -106, 124, -27, -38, 38, 26, 3, 8, 41, -15], [24, 0, 40, 92, -46, -48, 20, -44, -34, -52, -2, -2], [-146, 86, -31, 0, -16, 36, 132, -21, 7, -22, -23, -38], [-34, 0, -38, 160, -28, -17, 22, -56, -29, 39, 28, 11], [-37, 137, -28, -137, 26, 89, 227, 71, 2, 37, 35, -110], [-202, -180, -28, -180, 15, -40, 40, -16, -37, 2, 3, -19], [151, 0, 4, -344, 48, 26, 175, 36, -6, 50, 12, -22], [-294, 144, -4, 0, -5, -7, 298, 98, -2, 3, 89, -2], [-126, 0, 45, -170, 40, 28, -104, 29, -55, 50, 11, -12], [-200, -32, 15, -32, -6, -30, 30, 1, -81, 134, -51, 52], [37, -16, -51, -16, -61, 31, -31, 1, 52, -71, 21, -20], [42, 140, 50, -140, 25, 8, -60, 130, -75, -42, 33, -13], [-12, 88, 18, -88, 0, 12, -136, 34, -18, 12, 30, -28], [57, 208, 8, 0, -26, 80, -133, -37, 38, -4, 13, -30], [188, 0, -14, 116, 34, 39, 180, 38, 17, 31, -4, 5], [34, 112, -51, -112, 40, 46, -196, -47, 11, -34, -45, 70], [20, 0, -69, -118, 46, 30, 82, 15, 23, 92, 31, -16], [292, -138, 64, -138, 38, 16, -16, 2, 6, 8, -10, 12], [164, 4, -86, 0, 27, -73, -40, 78, -62, -51, -19, -24], [220, 176, 70, 176, 38, 22, -22, -10, 12, -22, -10, 0], [58, -240, 6, 240, 9, -40, -12, 10, -15, -58, -43, 63], [-262, 0, 38, 200, 60, 85, -246, 52, -79, 101, 8, 25], [-46, -76, -20, 0, -92, 24, -18, 10, 32, 40, -18, -52], [-142, 40, -36, 0, -49, -49, 166, 54, -12, 25, -19, -24], [-42, -180, 6, 180, -1, 40, 508, -90, -5, 42, 47, 53], [-390, 114, 179, 114, 42, 64, -64, -49, -9, -16, -73, 24], [-17, 96, -3, 96, -85, 45, -45, -59, 8, -89, -37, -22], [-217, 0, 189, -4, -14, 16, -401, 78, -35, -168, -92, 30], [220, 4, -20, 0, 44, -128, -92, 40, -64, 0, -44, 44], [-22, 92, -18, -92, 52, 126, 72, 94, -34, 22, 56, -82], [-66, -86, -26, 86, 6, 78, -138, -124, 20, 66, 46, 38], [-122, 0, 112, 200, 72, 7, -114, 68, -55, 15, 4, -65], [-6, -348, 2, 0, 51, -179, 158, 46, -76, 27, -55, 78], [-36, -118, 79, 118, -88, -140, -446, -79, 9, 36, 27, 34], [270, 0, -11, 282, -26, 26, 212, 3, 17, -32, -29, 52], [134, 76, -38, 0, 3, 149, -206, -66, 36, -77, 9, -74], [184, -28, -56, -28, 13, 2, -2, 40, 73, -64, 71, -31], [160, 0, 50, 48, 94, 104, 104, 122, -4, 48, -28, 10], [-420, 42, 47, 0, 24, 4, 402, 35, 9, 14, 77, 38], [-128, 292, 36, 0, -44, 4, 72, 32, 28, 52, 44, 8], [-186, -286, 34, -286, 86, 2, -2, 84, 56, 58, 54, 30], [-56, -158, 70, 158, -20, 16, 252, -44, -50, 56, 106, 38], [-6, 32, 38, -32, -64, -122, 276, -6, 26, 6, -20, -26], [133, -16, -52, 0, 76, 38, -73, 8, -30, -98, 24, -22], [255, -232, -35, -232, 44, -59, 59, 37, -39, 93, 20, 17], [176, -184, -134, 0, -20, -24, -84, 114, -46, -68, 2, -88], [-252, 0, -70, -188, 76, 63, -256, 78, 87, 59, -2, -13], [265, 124, -38, 0, 66, 80, -249, -67, -8, -96, -17, -30], [-119, 85, 87, 85, 76, -7, 7, -26, -25, -9, -18, -8], [-54, 52, 14, 0, -47, 89, -46, 26, 50, 11, 79, -36], [68, 0, -97, -158, -70, -2, 50, -61, 47, -20, -9, 68], [246, -170, -133, -170, -6, -84, 84, -5, -41, -12, 43, -48], [-48, 136, -32, 0, 5, -53, 108, 56, -30, -7, 1, -2]];
    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_o();".
// 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_o(:prec:=12)
    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_o();".
// 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_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_960_bg();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![64000000, -111616000, 97329152, -15843840, 1648400, -631424, 555520, -94144, 7624, 224, 128, -16, 1]>],Snew);
    return Vf;
end function;