
// Make newform 960.3.c.j in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_960_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_960_c_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_c_j();".
// 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_c_j();".
// 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, 34, 0, 305, 0, 616, 0, 305, 0, 34, 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], [-647, 1295, -1261, 1261, -956, 956, -340, 340, -35, 35, -1, 1], [-647, -1295, -1261, -1261, -956, -956, -340, -340, -35, -35, -1, -1], [-282, -851, -2380, -3875, -3072, -1964, -1288, 4, -138, 25, -4, 1], [-282, 1289, -2380, 3641, -3072, 4028, -1288, 1628, -138, 173, -4, 5], [-577, 0, -9755, 0, -21220, 0, -10640, 0, -1189, 0, -35, 0], [1038, 219, 17128, -117, 38208, 1032, 19384, 816, 2172, 99, 64, 3], [-280, -2393, -5966, -36521, -14860, -81680, -7796, -41480, -880, -4649, -26, -137], [-280, 2393, -5966, 36521, -14860, 81680, -7796, 41480, -880, 4649, -26, 137], [0, -7337, 0, -162043, 0, -383900, 0, -197572, 0, -22205, 0, -655], [-2461, -10235, -42923, -186485, -98884, -423692, -50492, -215732, -5665, -24191, -167, -713], [491, -15391, 16069, -201049, 41660, -439804, 21892, -222244, 2471, -24883, 73, -733]];
    Rf_basisdens := [1, 216, 72, 36, 36, 27, 18, 36, 36, 108, 72, 72];
    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_c();"
function MakeCharacter_960_c()
    N := 960;
    order := 2;
    char_gens := [511, 901, 641, 577];
    v := [2, 2, 1, 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_c_Hecke();"
function MakeCharacter_960_c_Hecke(Kf)
    N := 960;
    order := 2;
    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], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 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, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0], [0, -1, 1, 0, 0, 1, 0, 0, 0, 1, -1, -1], [0, 0, 0, 0, 0, -1, 0, -1, -1, 0, 0, 0], [1, 0, 0, -1, 1, 0, 1, 0, 0, 0, -1, 1], [0, -3, -1, 0, 0, -1, 0, -2, -2, 0, 0, 0], [-1, 0, 0, 3, -1, 0, 1, 3, -3, 0, 1, -1], [5, 0, 0, -1, -3, 0, 1, 0, 0, 0, 1, -1], [0, 5, -1, 0, 0, 1, 0, 0, 0, -1, -1, -1], [-1, 0, 0, 1, 1, 0, 1, -2, 2, 0, 1, -1], [0, -9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 3, 1, 0, 0, 5, 0, -4, -4, 0, 0, 0], [0, 12, 4, 0, 0, -2, 0, 5, 5, 0, 0, 0], [2, 0, 0, -3, -1, 0, -2, -2, 2, 0, -2, 2], [-11, 0, 0, -1, 1, 0, 1, 0, 0, 0, -1, 1], [0, 5, -3, 0, 0, -2, 0, 0, 0, -4, 2, 2], [0, 0, 0, 2, -2, 0, 0, -12, 12, 0, 0, 0], [0, 14, -2, 0, 0, 4, 0, 0, 0, -2, -4, -4], [-39, 0, 0, 3, 5, 0, -3, 0, 0, 0, -1, 1], [0, 15, 5, 0, 0, 2, 0, -2, -2, 0, 0, 0], [0, 0, 0, 6, -6, 0, 0, -12, 12, 0, 0, 0], [0, 8, 0, 0, 0, 4, 0, 0, 0, 4, -4, -4], [-1, 0, 0, 1, 1, 0, 1, -1, 1, 0, 1, -1], [0, 16, -4, 0, 0, 2, 0, 0, 0, -1, -2, -2], [0, -9, -3, 0, 0, -18, 0, -2, -2, 0, 0, 0], [53, 0, 0, -1, 9, 0, 1, 0, 0, 0, -5, 5], [0, -12, -4, 0, 0, 11, 0, 3, 3, 0, 0, 0], [0, -10, -2, 0, 0, -8, 0, 0, 0, -15, 8, 8], [-2, 0, 0, -1, 5, 0, 2, -14, 14, 0, 2, -2], [0, -12, -4, 0, 0, -19, 0, 3, 3, 0, 0, 0], [57, 0, 0, 7, 9, 0, -7, 0, 0, 0, -1, 1], [2, 0, 0, 4, -8, 0, -2, -19, 19, 0, -2, 2], [73, 0, 0, 3, 5, 0, -3, 0, 0, 0, -1, 1], [0, 39, -11, 0, 0, 3, 0, 0, 0, 13, -3, -3], [0, -3, 5, 0, 0, 6, 0, 0, 0, 4, -6, -6], [0, 3, 1, 0, 0, 23, 0, -4, -4, 0, 0, 0], [0, 24, 8, 0, 0, 2, 0, -7, -7, 0, 0, 0], [-2, 0, 0, 23, -19, 0, 2, -10, 10, 0, 2, -2], [-56, 0, 0, 2, 6, 0, -2, 0, 0, 0, -2, 2], [-2, 0, 0, -12, 16, 0, 2, 14, -14, 0, 2, -2], [0, -20, 0, 0, 0, -10, 0, 0, 0, -32, 10, 10], [0, -36, -12, 0, 0, 24, 0, -3, -3, 0, 0, 0], [-175, 0, 0, -5, 9, 0, 5, 0, 0, 0, -7, 7], [29, 0, 0, -5, 21, 0, 5, 0, 0, 0, -13, 13], [0, 10, -6, 0, 0, -4, 0, 0, 0, 15, 4, 4], [0, 9, 3, 0, 0, -10, 0, -32, -32, 0, 0, 0], [130, 0, 0, -4, -28, 0, 4, 0, 0, 0, 12, -12], [0, 24, 8, 0, 0, 9, 0, -9, -9, 0, 0, 0], [6, 0, 0, -4, -8, 0, -6, -14, 14, 0, -6, 6], [79, 0, 0, -3, -1, 0, 3, 0, 0, 0, -1, 1], [4, 0, 0, -19, 11, 0, -4, -4, 4, 0, -4, 4], [0, -60, -20, 0, 0, -17, 0, 19, 19, 0, 0, 0], [0, 45, 15, 0, 0, 23, 0, 14, 14, 0, 0, 0], [2, 0, 0, -24, 20, 0, -2, 31, -31, 0, -2, 2], [209, 0, 0, -5, -3, 0, 5, 0, 0, 0, -1, 1], [0, 41, -21, 0, 0, -11, 0, 0, 0, 3, 11, 11], [-5, 0, 0, -17, 27, 0, 5, 24, -24, 0, 5, -5], [0, -1, -13, 0, 0, -20, 0, 0, 0, -6, 20, 20], [0, -24, -8, 0, 0, -30, 0, -31, -31, 0, 0, 0], [0, -27, 21, 0, 0, 18, 0, 0, 0, 10, -18, -18], [-4, 0, 0, 18, -10, 0, 4, -20, 20, 0, 4, -4], [0, -70, 26, 0, 0, 4, 0, 0, 0, 22, -4, -4], [0, -60, -20, 0, 0, -28, 0, -19, -19, 0, 0, 0], [61, 0, 0, 11, -11, 0, -11, 0, 0, 0, 11, -11], [0, 64, -28, 0, 0, -10, 0, 0, 0, 8, 10, 10], [0, 9, 3, 0, 0, -4, 0, -32, -32, 0, 0, 0], [232, 0, 0, 18, 14, 0, -18, 0, 0, 0, 2, -2], [0, 84, 28, 0, 0, -53, 0, 19, 19, 0, 0, 0], [-10, 0, 0, 2, 18, 0, 10, -26, 26, 0, 10, -10], [0, -26, 6, 0, 0, -4, 0, 0, 0, -13, 4, 4], [0, 9, 3, 0, 0, 9, 0, 0, 0, 43, -9, -9], [125, 0, 0, -21, -35, 0, 21, 0, 0, 0, 7, -7], [0, 3, 1, 0, 0, -27, 0, -36, -36, 0, 0, 0], [-6, 0, 0, 2, 10, 0, 6, -13, 13, 0, 6, -6], [0, 31, -15, 0, 0, -7, 0, 0, 0, -39, 7, 7], [10, 0, 0, 20, -40, 0, -10, 14, -14, 0, -10, 10], [-57, 0, 0, -11, -5, 0, 11, 0, 0, 0, -3, 3], [0, 0, 0, -1, 1, 0, 0, -40, 40, 0, 0, 0], [-99, 0, 0, -9, 25, 0, 9, 0, 0, 0, -17, 17], [16, 0, 0, -24, -8, 0, -16, -68, 68, 0, -16, 16], [0, -44, 12, 0, 0, -4, 0, 0, 0, 24, 4, 4], [-203, 0, 0, -1, 5, 0, 1, 0, 0, 0, -3, 3], [0, -15, -5, 0, 0, -70, 0, -16, -16, 0, 0, 0], [5, 0, 0, -47, 37, 0, -5, -46, 46, 0, -5, 5], [0, 106, -34, 0, 0, 2, 0, 0, 0, 6, -2, -2], [-9, 0, 0, 7, 11, 0, 9, 19, -19, 0, 9, -9], [0, 26, -26, 0, 0, -26, 0, 0, 0, -17, 26, 26], [0, 39, 13, 0, 0, 60, 0, 78, 78, 0, 0, 0], [-10, 0, 0, -4, 24, 0, 10, 38, -38, 0, 10, -10], [0, -12, 4, 0, 0, 0, 0, 0, 0, -5, 0, 0], [2, 0, 0, 9, -13, 0, -2, -18, 18, 0, -2, 2], [-79, 0, 0, -17, 9, 0, 17, 0, 0, 0, -13, 13], [0, 99, 33, 0, 0, 11, 0, -36, -36, 0, 0, 0], [5, 0, 0, 19, -29, 0, -5, 21, -21, 0, -5, 5], [-6, 0, 0, 34, -22, 0, 6, -94, 94, 0, 6, -6], [0, -85, 35, 0, 0, 10, 0, 0, 0, 44, -10, -10], [-142, 0, 0, -4, -20, 0, 4, 0, 0, 0, 8, -8], [0, -15, 1, 0, 0, -6, 0, 0, 0, 62, 6, 6], [0, -72, -24, 0, 0, -46, 0, 89, 89, 0, 0, 0], [0, -57, -19, 0, 0, 36, 0, -18, -18, 0, 0, 0], [-7, 0, 0, 55, -41, 0, 7, -22, 22, 0, 7, -7], [577, 0, 0, 15, 9, 0, -15, 0, 0, 0, 3, -3], [0, 76, -8, 0, 0, 26, 0, 0, 0, -52, -26, -26], [0, -63, -21, 0, 0, 70, 0, -16, -16, 0, 0, 0], [0, 36, 12, 0, 0, 55, 0, 3, 3, 0, 0, 0], [-10, 0, 0, -14, 34, 0, 10, -6, 6, 0, 10, -10], [47, 0, 0, -35, 19, 0, 35, 0, 0, 0, -27, 27], [0, 10, -2, 0, 0, 2, 0, 0, 0, -19, -2, -2], [0, -47, 31, 0, 0, 23, 0, 0, 0, 55, -23, -23], [0, 0, 0, 0, 0, 61, 0, 15, 15, 0, 0, 0], [37, 0, 0, 19, -11, 0, -19, 0, 0, 0, 15, -15], [493, 0, 0, -9, -3, 0, 9, 0, 0, 0, -3, 3], [-5, 0, 0, 15, -5, 0, 5, 62, -62, 0, 5, -5], [0, 61, -47, 0, 0, -40, 0, 0, 0, -30, 40, 40], [0, -3, -1, 0, 0, 3, 0, 14, 14, 0, 0, 0], [0, 36, 12, 0, 0, -22, 0, 5, 5, 0, 0, 0], [-18, 0, 0, 71, -35, 0, 18, 14, -14, 0, 18, -18], [237, 0, 0, 39, 41, 0, -39, 0, 0, 0, -1, 1], [0, 96, -32, 0, 0, 0, 0, 0, 0, 28, 0, 0], [0, -12, -4, 0, 0, -78, 0, -51, -51, 0, 0, 0], [0, 201, 67, 0, 0, 8, 0, 96, 96, 0, 0, 0], [297, 0, 0, 7, 65, 0, -7, 0, 0, 0, -29, 29], [-24, 0, 0, 36, 12, 0, 24, 89, -89, 0, 24, -24], [-312, 0, 0, -30, -10, 0, 30, 0, 0, 0, -10, 10], [16, 0, 0, 16, -48, 0, -16, -20, 20, 0, -16, 16], [0, 112, -56, 0, 0, -28, 0, 0, 0, 15, 28, 28], [0, -113, 37, 0, 0, -1, 0, 0, 0, -3, 1, 1], [-255, 0, 0, 31, -7, 0, -31, 0, 0, 0, 19, -19], [0, 3, 1, 0, 0, -125, 0, 28, 28, 0, 0, 0], [129, 0, 0, 27, 17, 0, -27, 0, 0, 0, 5, -5], [0, 105, -29, 0, 0, 9, 0, 0, 0, -85, -9, -9], [-10, 0, 0, -66, 86, 0, 10, -34, 34, 0, 10, -10], [172, 0, 0, 26, -30, 0, -26, 0, 0, 0, 28, -28], [0, 156, 52, 0, 0, -32, 0, -3, -3, 0, 0, 0], [0, 97, -11, 0, 0, 32, 0, 0, 0, 94, -32, -32], [0, 36, 12, 0, 0, 76, 0, 13, 13, 0, 0, 0], [-10, 0, 0, -54, 74, 0, 10, 22, -22, 0, 10, -10], [213, 0, 0, -29, 53, 0, 29, 0, 0, 0, -41, 41], [8, 0, 0, -34, 18, 0, -8, -123, 123, 0, -8, 8], [0, -4, -40, 0, 0, -62, 0, 0, 0, -125, 62, 62], [0, -33, -11, 0, 0, 4, 0, 94, 94, 0, 0, 0], [-27, 0, 0, 15, -7, 0, -15, 0, 0, 0, 11, -11], [26, 0, 0, -46, -6, 0, -26, 90, -90, 0, -26, 26], [0, 21, -5, 0, 0, 3, 0, 0, 0, 19, -3, -3], [0, 60, 20, 0, 0, 53, 0, -5, -5, 0, 0, 0], [-895, 0, 0, 15, -15, 0, -15, 0, 0, 0, 15, -15], [0, -141, -47, 0, 0, -63, 0, 108, 108, 0, 0, 0], [0, -133, 25, 0, 0, -29, 0, 0, 0, -71, 29, 29], [5, 0, 0, 11, -21, 0, -5, 76, -76, 0, -5, 5], [0, -23, 41, 0, 0, 50, 0, 0, 0, -8, -50, -50], [0, -3, -1, 0, 0, 95, 0, 14, 14, 0, 0, 0], [0, 103, -25, 0, 0, 14, 0, 0, 0, -110, -14, -14], [-12, 0, 0, 24, 0, 0, 12, 144, -144, 0, 12, -12], [-163, 0, 0, 23, -15, 0, -23, 0, 0, 0, 19, -19], [31, 0, 0, 7, -69, 0, -31, -38, 38, 0, -31, 31], [0, -182, 62, 0, 0, 2, 0, 0, 0, -70, -2, -2], [1, 0, 0, -73, 71, 0, -1, 65, -65, 0, -1, 1], [0, 105, 35, 0, 0, -38, 0, 16, 16, 0, 0, 0], [0, -12, -4, 0, 0, 33, 0, -93, -93, 0, 0, 0], [0, -140, 24, 0, 0, -34, 0, 0, 0, 13, 34, 34], [-28, 0, 0, 69, -13, 0, 28, 136, -136, 0, 28, -28], [0, 0, 0, 0, 0, -105, 0, 31, 31, 0, 0, 0], [0, 51, 17, 0, 0, 215, 0, 76, 76, 0, 0, 0], [717, 0, 0, -41, -15, 0, 41, 0, 0, 0, -13, 13], [0, -151, 31, 0, 0, -29, 0, 0, 0, 39, 29, 29]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_960_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_960_3_c_j();".
// 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_c_j(:prec:=12)
    chi := MakeCharacter_960_c();
    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_c_j();".
// 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_c_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_960_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![4096, 0, 7680, 0, 210, 0, 1]>,<17,R![-165888, 0, 13968, 0, -264, 0, 1]>,<19,R![5648, -780, 0, 1]>],Snew);
    return Vf;
end function;