
// Make newform 588.3.g.d in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_588_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_588_g_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_588_3_g_d();".
// 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_588_3_g_d();".
// 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 := [64, -96, 112, -88, 72, -44, 33, -22, 18, -11, 7, -3, 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], [-1236, 464, -380, -422, -479, -135, -94, -31, -60, -36, 12, -1], [-26112, 13840, -23920, 7348, -12672, 2849, -5626, 1666, -2675, 607, -887, 41], [29536, 1008, 23136, -3788, 13460, -217, 6410, -1078, 2967, -179, 955, -73], [14688, -13552, 15904, -10868, 8708, -4649, 4162, -2606, 2191, -1403, 731, -265], [-8, 40, -32, 28, -11, 11, -4, 7, -4, 4, -2, 1], [-6928, 8704, -8000, 6184, -4180, 3191, -1954, 1734, -1101, 793, -317, 191], [-6080, 14992, -7952, 13492, -3248, 4497, -1370, 2962, -819, 1215, -247, 409], [-13824, -1744, -3072, -6668, -3084, -3083, -2458, -1330, -747, -1017, -135, -443], [38528, -37776, 40864, -26724, 21560, -11091, 9222, -6790, 5209, -3005, 1581, -507], [-14048, 17296, -15200, 13140, -9364, 6371, -3918, 3658, -2005, 1641, -705, 355], [21568, -38400, 29792, -31316, 17930, -14617, 7022, -7808, 4309, -3545, 1445, -917]];
    Rf_basisdens := [1, 316, 2528, 2528, 2528, 8, 1264, 2528, 2528, 2528, 1264, 1264];
    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_588_g();"
function MakeCharacter_588_g()
    N := 588;
    order := 2;
    char_gens := [295, 197, 493];
    v := [1, 2, 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_588_g_Hecke();"
function MakeCharacter_588_g_Hecke( : Kf := false)
    N := 588;
    order := 2;
    char_gens := [295, 197, 493];
    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]];
    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, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [-1, 1, 0, 0, -1, 0, -1, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -1, 2, 0, 1, 0, -1, 0, 1, 1], [3, 0, 2, -1, -3, 1, 0, 0, 1, 1, 0, 0], [3, 3, -4, 0, 3, 2, -1, 0, 0, -3, -2, 0], [-1, 0, 4, 1, 1, -1, 2, 2, -1, 1, 0, 0], [-2, 0, -1, 1, -1, -2, -8, -5, -3, -1, -5, 0], [2, 2, -1, 2, 3, -2, -3, -1, -2, 5, 2, -1], [-1, 0, 0, -3, 1, -1, 2, -2, -5, 1, 0, 0], [-8, 0, -1, 2, 5, 6, -1, -1, -2, 3, 2, -1], [19, -3, 2, 2, -7, 0, -1, 2, -2, 3, 2, 2], [0, 0, 2, 4, -2, 0, 2, 2, 4, -6, 4, 2], [2, 0, -6, 0, -4, 2, -20, -2, 4, -4, 2, 0], [12, 0, 7, -2, -7, 10, -1, -1, 2, 7, 2, -1], [-2, 0, -4, 4, 2, -2, -6, -8, 0, -2, -10, 2], [-11, -2, 4, 3, -11, -11, -4, 2, -3, 9, 4, 2], [-6, 0, 6, 4, 4, -6, -8, -6, -8, -4, -6, 4], [-6, 0, 13, 7, -19, -6, -12, 1, -5, -11, 5, -4], [-16, -6, 10, -4, -16, 8, 4, 2, 4, 0, 0, 2], [4, 0, -4, -2, 12, 4, 34, 4, 6, 0, 6, 6], [-2, 0, 8, -2, -6, -2, -4, 4, -6, 2, 4, -4], [43, 1, 18, -6, -7, 4, -1, -6, 6, 19, 6, -6], [10, 6, 4, 6, 16, 14, -10, -8, -6, 28, 12, -8], [1, -5, -6, -4, 7, -8, 11, 2, 4, -23, -8, 2], [-3, 0, 16, 3, -13, -3, 2, 10, -3, -5, 12, -4], [12, 0, -26, -13, 4, 12, -33, -2, 11, 6, 5, -1], [-20, 0, -2, 6, -4, -6, -6, 2, -6, 8, 4, 2], [42, -4, 6, 4, -26, -20, -6, 6, -4, 10, 4, 6], [-2, 0, 4, -12, 2, -2, -50, 0, -16, -10, 22, 6], [4, 0, -24, -4, -28, 4, -20, -16, 4, -12, 0, -8], [16, -6, 0, 0, 34, -12, 10, -8, 0, -2, 4, -8], [2, 0, -8, 6, -34, 2, 0, -4, 10, -18, 8, -8], [-52, -8, 15, -2, 17, 18, 7, -9, 2, 15, 10, -9], [4, 0, 22, -4, 2, 4, 14, 30, 4, 14, 20, -6], [15, 22, -12, 1, -53, -1, -24, 14, -1, -1, -12, 14], [-14, 0, 10, 8, -48, -14, -16, -18, -20, -8, -18, -20], [10, 0, -14, 4, 4, 10, -40, 6, 24, -4, 6, 4], [-25, -5, 8, -10, 7, 6, 13, -4, 10, -11, -4, -4], [20, 0, -28, 1, -2, 20, -9, 12, 41, 0, 11, -1], [-5, -24, -4, 7, 23, -31, 18, 2, -7, -17, 4, 2], [2, 0, 19, 15, 19, 2, 34, 23, 19, 31, -23, -6], [-14, 12, 11, -4, -53, -20, -17, 7, 4, 17, -2, 7], [44, -4, -21, 18, 53, 14, -1, -5, -18, 3, 10, -5], [6, 0, -2, -10, 16, 6, -50, 10, 2, 20, 0, -2], [-10, 0, 26, 18, 32, -10, 50, 6, -2, 20, -32, 6], [12, 0, 14, 0, 18, 12, 10, 38, 24, 38, 0, -10], [-6, 0, 16, 28, -14, -6, 34, 4, 16, -2, -22, -6], [-109, 12, 6, -5, -63, 5, -16, 12, 5, 5, -8, 12], [-32, -2, 12, 20, -2, 16, -22, -4, -20, 58, 28, -4], [-10, 0, 3, -3, -53, -10, -64, -17, -23, 11, -25, -32], [-58, -22, 34, 6, -78, -10, -8, 14, -6, 34, 16, 14], [-12, 0, 0, 2, 0, -12, 22, -24, -22, -4, -22, 2], [75, -3, 26, -2, -15, 40, -5, -6, 2, 35, 14, -6], [-2, 0, -7, -7, -47, -2, -86, -11, -11, 13, -17, -30], [-51, -11, 18, 6, 75, 18, 9, -26, -6, 41, 28, -26], [-9, 0, 4, 17, 29, -9, -70, -14, -1, 13, -44, 8], [-118, -44, 29, 12, -31, 12, 13, 9, -12, 19, 22, 9], [-164, 6, -6, -8, 80, 36, 16, -22, 8, -8, 0, -22], [-19, 0, 36, 19, 35, -19, -98, -2, -19, -13, -8, 24], [59, 7, 4, -6, -41, 30, -7, 8, 6, -3, -8, 8], [-7, 0, 8, -5, -37, -7, 78, -6, -19, 27, -28, -32], [22, 0, -30, -4, -16, 22, 36, 14, 40, -16, 34, 0], [60, -24, 14, -22, -32, -18, 34, 10, 22, -52, -20, 10], [100, -36, 37, -22, -121, -26, 25, 29, 22, -39, -18, 29], [18, 0, -6, 14, -28, 18, -38, 30, 50, 8, 8, -18], [-106, -36, -28, 16, 8, -8, 24, 20, -16, -56, -8, 20], [-12, 0, -2, -11, 32, -12, 85, -26, -35, -10, -5, 21], [-141, -2, -34, 5, 137, 43, 26, -24, -5, -31, 0, -24], [201, 27, -2, -6, -17, 24, -19, -2, 6, 13, -6, -2], [-10, 0, -9, 3, -61, -10, -18, -29, -17, -41, 9, -10], [-18, 0, 78, -6, 80, -18, 138, 42, -42, 28, 20, 26], [22, 32, 20, -12, -48, -4, -28, -4, 12, 40, 0, -4], [26, 0, -46, -26, 20, 26, 98, 6, 26, 56, -24, -18], [32, 0, -52, 8, 76, 32, 12, 12, 72, -28, 32, 52], [-82, 10, -37, 6, 35, 2, 1, 3, -6, -35, -14, 3], [-181, 30, 8, -3, 35, 35, -20, -22, 3, 47, 12, -22], [-40, 38, 36, -12, -50, 0, -38, -12, 12, 74, 12, -12], [110, -6, -26, 6, -130, -34, -12, 50, -6, -58, -32, 50], [-4, 0, 0, 14, 0, -4, 162, -8, 6, 4, -26, -2], [-62, 76, -71, 12, 13, 28, -55, 5, -12, -9, -26, 5], [-34, 0, 51, 43, 15, -34, 82, -17, -25, -5, -55, 10], [156, -28, 22, -2, -40, -14, 14, 10, 2, -4, 4, 10], [4, 0, -42, -20, -46, 4, -186, -34, -12, 14, -28, -30], [-40, 0, 58, 57, 48, -40, -143, -22, -23, -18, -61, 33], [82, 12, -32, -12, 64, 20, 20, -8, 12, -56, -24, -8], [66, -56, 16, 8, 144, 88, 56, -32, -8, 0, 32, -32], [-27, 3, -6, 20, -85, 20, -33, 26, -20, 21, 4, 26], [18, 0, 44, -28, 134, 18, -38, 80, 8, 50, 58, 42], [-68, 0, 76, 22, -116, -68, 94, -60, -114, -24, -58, -46], [-8, 0, -54, 6, -2, -8, 60, -70, -10, -74, -2, 36], [36, 0, -70, -32, 14, 36, -194, 2, 40, 58, -24, -22], [0, 0, -4, -39, -54, 0, 139, -4, -39, 52, -17, -53], [-12, 0, -46, -12, -94, -12, -114, -70, -36, -42, -16, -26], [-6, 0, 72, -14, -10, -6, -16, 60, -26, 46, 28, -28], [-109, 1, 0, 24, 83, 84, -13, -24, -24, 61, 36, -24], [23, 3, 40, -36, -21, -74, 19, -12, 36, -3, -10, -12], [36, 0, -76, 12, 16, 36, 88, -4, 84, 24, -40, -4], [-394, 36, 13, 16, -3, -40, -51, -15, -16, 95, 30, -15], [-48, 0, 58, 30, 18, -48, 224, -38, -66, -46, -22, 32], [-204, -36, -41, 34, 17, -74, 11, 23, -34, -41, 2, 23], [-34, 0, 28, 32, -150, -34, -234, -40, -36, 14, -86, -82], [-116, 82, -98, 20, -68, -40, -72, 38, -20, -44, -48, 38], [-36, 0, -6, 54, -90, -36, -212, -78, -18, -50, -82, -20], [-230, -36, 32, -16, 100, 64, 52, -32, 16, -4, 16, -32], [6, 0, 48, 20, 78, 6, 62, 60, 32, 82, -42, -2], [-113, 23, 12, 12, -97, -38, -49, 16, -12, 57, 10, 16], [-6, 0, 57, 27, 17, -6, -20, 45, 15, -55, 73, 36], [-302, 52, 20, 16, 16, 48, -64, -28, -16, 128, 40, -28], [-16, 0, 58, 48, 82, -16, -150, 26, 16, 22, -44, 30], [-152, -36, 104, -26, 34, -22, 32, -44, 26, 90, 48, -44], [224, 18, -22, 24, 36, -4, -28, -6, -24, 36, 16, -6], [30, 0, 12, -26, -106, 30, -128, 72, 34, 38, 60, -72], [-30, 0, -16, 72, -54, -30, -334, -76, 12, -74, -74, 10], [-36, 22, -38, 8, 0, -76, -16, 10, -8, -24, -16, 10], [19, 0, -72, 21, 57, 19, 38, -34, 59, -79, 24, 68], [18, 0, -42, 8, 104, 18, 128, -6, 44, 64, -78, 20], [50, -46, 15, 2, 27, 14, 37, -1, -2, -19, 10, -1], [20, 0, -38, -37, -16, 20, 235, 2, 3, -54, 93, 19], [-35, 14, -46, 27, 83, -99, -14, -8, -27, 3, 8, -8], [286, -52, 69, -32, -55, -24, 49, 1, 32, -13, 2, 1], [211, -81, 4, 38, -121, -114, 13, 56, -38, -27, 12, 56], [16, 0, 38, 45, 28, 16, -95, 70, 77, 26, -1, 1], [-24, 0, 0, -4, -136, -24, -32, -48, -52, -64, 20, -36], [-290, 22, 51, 10, 3, 22, -43, -29, -10, 133, 50, -29], [128, 8, 98, -22, -148, 70, -34, -2, 22, 112, 28, -2], [0, 0, 64, 20, 200, 0, -140, 64, 20, 32, 12, 84], [33, 0, 44, -1, -5, 33, -170, 110, 65, 59, 52, -32], [497, -48, 44, 33, -95, -9, -18, 22, -33, 73, 44, 22], [38, 0, -14, -52, -124, 38, 40, 62, 24, 28, 86, -76], [18, 0, 103, -9, 151, 18, -138, 139, 27, 27, 121, 62], [82, 0, -122, 22, 12, 82, -6, 42, 186, 24, -4, -6], [500, 80, 22, 14, -36, 34, -94, -22, -14, 152, 36, -22], [-119, 1, 28, 68, 69, 106, -67, -32, -68, 195, 98, -32], [180, -4, 82, 22, 28, -14, -38, -42, -22, 184, 84, -42], [-639, 47, -110, 8, 111, -12, -1, 2, -8, -103, -48, 2], [-62, 0, 36, -30, 18, -62, 120, -88, -154, -78, 20, 48], [-321, 19, -12, 6, 139, -26, 1, -40, -6, 33, 20, -40], [322, 40, 78, 0, -178, 8, -82, 6, 0, 154, 36, 6], [-84, 0, 172, 0, 56, -84, 164, 4, -168, 8, -4, 24], [-116, -108, 83, 42, 85, -58, 39, -29, -42, 115, 98, -29], [-60, 0, 16, 42, -192, -60, -222, -104, -78, -172, 26, -10], [-56, 0, 120, 39, -118, -56, 377, 8, -73, -40, 9, -39], [353, 64, 2, -95, 31, -9, 44, -28, 95, -109, -80, -28], [-48, 0, 94, 50, -62, -48, -388, -2, -46, -38, -14, -12], [303, -50, 82, 25, -255, -105, -42, 52, -25, 97, 40, 52], [285, 73, -36, 40, -47, 134, -99, 8, -40, 95, 18, 8], [-77, 0, 68, 65, -43, -77, 302, -86, -89, -35, -116, -4], [-18, 0, 57, 9, 41, -18, 402, 21, -27, 21, -9, 10], [148, 116, -124, -14, -126, 62, -68, 56, 14, -126, -104, 56], [267, 43, -28, -12, 139, 130, 3, -40, 12, -3, -6, -40], [64, 0, -150, -88, -18, 64, 94, -22, 40, -30, 96, 6], [-62, 0, 54, 52, -224, -62, -140, -70, -72, -128, 6, -48], [64, 0, -118, -4, 14, 64, 50, 10, 124, 26, -12, -6], [-14, 0, 83, -17, 43, -14, -430, 55, -45, 23, 49, 10], [-80, 0, 110, 76, -82, -80, 82, -50, -84, -30, -96, -26], [-337, 21, -18, 22, 153, 36, -13, -42, -22, 59, 34, -42], [-334, 96, -114, 28, -86, -60, -90, 46, -28, -42, -52, 46], [-795, -31, 22, -18, -177, -50, 13, 50, 18, -59, -32, 50], [-8, 0, -80, -133, -54, -8, -219, -96, -149, 16, 21, -35], [266, -120, 40, 24, -24, -96, 64, 24, -24, -24, 32, 24], [-50, 0, 80, 100, -250, -50, -270, -20, 0, -78, -42, -86], [110, 0, -72, 18, 130, 110, 248, 148, 238, 82, 48, 24], [-32, -62, 36, -72, -34, 60, 110, 12, 72, -158, -60, 12], [-158, 0, 164, 50, -6, -158, -116, -152, -266, -70, -132, 32], [12, 0, -190, -64, -98, 12, 86, -166, -40, -134, 32, 18], [201, -66, -38, -57, 207, 41, 154, -24, 57, -225, -64, -24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_588_g_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_588_3_g_d();".
// 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_588_3_g_d(:prec:=12)
    chi := MakeCharacter_588_g();
    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_588_3_g_d();".
// 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_588_3_g_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_588_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![2752, 7808, 2976, -384, -112, 4, 1]>],Snew);
    return Vf;
end function;