
// Make newform 588.3.m.a in Magma, downloaded from the LMFDB on 15 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_588_m();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_588_m_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_m_a();".
// 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_m_a();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_m();"
function MakeCharacter_588_m()
    N := 588;
    order := 6;
    char_gens := [295, 197, 493];
    v := [6, 6, 5];
    // 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_m_Hecke();"
function MakeCharacter_588_m_Hecke( : Kf := false)
    N := 588;
    order := 6;
    char_gens := [295, 197, 493];
    char_values := [[1, 0], [1, 0], [0, 1]];
    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], [-1, -1], [-2, 1], [0, 0], [3, -3], [4, -8], [10, 10], [-12, 6], [0, -36], [-51, 0], [7, 7], [0, -22], [14, -28], [10, 0], [-104, 52], [-51, 51], [-43, -43], [-80, 40], [-68, 68], [0, 0], [12, 12], [0, -125], [89, -178], [-84, 42], [-85, 170], [-12, -12], [176, -88], [0, 33], [32, -32], [-186, 0], [131, 0], [-114, 57], [144, -144], [86, -172], [0, 150], [233, -233], [-84, -84], [0, 148], [16, -32], [216, -108], [162, -162], [-150, 300], [0, -96], [-295, 295], [-330, 0], [68, 68], [220, 0], [-87, 174], [-63, -63], [436, -218], [0, 210], [120, 0], [7, 7], [79, -158], [-156, 78], [-162, 162], [-223, -223], [-250, 125], [100, -100], [228, 0], [-10, -10], [161, -322], [16, -32], [-38, -38], [-138, 69], [0, 201], [0, -448], [-293, 0], [-390, 390], [-80, 160], [292, 292], [0, -300], [117, 117], [0, -410], [-374, 0], [332, -166], [138, -138], [-712, 356], [0, -516], [-151, -151], [-308, 616], [-76, 0], [-606, 606], [20, -40], [-114, 57], [0, -621], [504, 0], [0, 443], [104, -208], [158, 0], [-24, 12], [-238, -238], [-115, 115], [273, 0], [0, -466], [-418, 836], [410, -205], [530, 530], [-560, 280], [0, -62], [-802, 0], [111, -111], [-111, -111], [0, 426], [580, -580], [557, 557], [-579, 1158], [1016, -508], [156, -156], [649, -1298], [462, -231], [856, -856], [444, 0], [148, 148], [-85, 0], [132, -132], [-412, 824], [-576, -576], [0, 375], [1038, 0], [-258, -258], [1093, 0], [1398, -699], [3, -3], [1316, -658], [447, 0], [0, 422], [-196, 98], [29, -58], [-340, 170], [-98, 98], [-180, 0], [0, -721], [-644, 0], [656, -328], [-159, 318], [580, 580], [-460, -460], [-315, 630], [-48, 48], [252, -504], [0, -1191], [250, -250], [-1137, 0], [-42, -42], [-818, 1636], [504, -1008], [400, 400], [1028, -514], [0, -630], [0, -1640], [732, -1464], [226, 0], [-8, 4], [-1144, 1144], [-480, 0], [0, 1742], [-1340, 670], [-769, 1538], [-469, -469], [0, 1290], [174, 0], [41, 0], [-1138, 569], [-1278, 1278], [134, 134], [833, -833], [-676, -676]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_588_m_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_588_3_m_a();".
// 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_m_a(:prec:=2)
    chi := MakeCharacter_588_m();
    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_m_a();".
// 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_m_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_588_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![3, 3, 1]>],Snew);
    return Vf;
end function;