
// Make newform 60.4.j.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_60_j();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_60_j_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_60_4_j_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_60_4_j_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 := [16, 0, 0, 0, 1, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 2, 0, 0, 0], [0, 11, 0, 0, 0, 1, 0, 0], [0, 0, 5, 0, 0, 0, 1, 0], [0, 1, 0, 0, 0, -1, 0, 0], [0, 0, 0, 7, 0, 0, 0, -1], [0, 0, 3, 0, 0, 0, -1, 0], [0, 0, 0, 13, 0, 0, 0, 5]];
    Rf_basisdens := [1, 3, 6, 12, 6, 24, 4, 24];
    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_60_j();"
function MakeCharacter_60_j()
    N := 60;
    order := 4;
    char_gens := [31, 41, 37];
    v := [2, 4, 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_60_j_Hecke();"
function MakeCharacter_60_j_Hecke(Kf)
    N := 60;
    order := 4;
    char_gens := [31, 41, 37];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 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 := 4;
    raw_aps := [[0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 3, 0, 0], [-3, 0, -2, 9, 0, 0, 0, 1], [0, -5, 0, 0, -6, 0, 5, 0], [0, -12, 0, 0, 5, -5, 0, 0], [40, 0, 0, -40, 0, 0, 0, 6], [30, 0, -10, 30, 0, 0, 0, 0], [0, 0, 0, 0, -30, -30, 22, 0], [0, -30, 0, 0, 0, -38, -30, 0], [0, 0, 35, 78, 0, 0, 0, 35], [0, -12, 0, 0, 150, -150, 0, 0], [-80, 0, -66, -80, 0, 0, 0, 0], [138, 0, -30, 0, 0, 0, 0, 30], [0, -10, 0, 0, 0, 396, -10, 0], [0, 120, 0, 0, -70, 0, -120, 0], [-150, 0, 0, 150, 0, 0, 0, 188], [0, 0, 0, 0, 255, 255, 108, 0], [-34, 0, 150, 0, 0, 0, 0, -150], [0, 190, 0, 0, 156, 0, -190, 0], [0, -60, 0, 0, 320, -320, 0, 0], [55, 0, 0, -55, 0, 0, 0, -48], [0, 0, 0, 0, -330, -330, -32, 0], [0, -180, 0, 0, 0, -26, -180, 0], [0, 0, -100, -366, 0, 0, 0, -100], [-5, 0, 48, -5, 0, 0, 0, 0], [966, 0, -105, 0, 0, 0, 0, 105], [0, -175, 0, 0, 0, -1182, -175, 0], [0, -240, 0, 0, -382, 0, 240, 0], [0, 0, 30, 1098, 0, 0, 0, 30], [-240, 0, 0, 240, 0, 0, 0, -430], [0, 295, 0, 0, 834, 0, -295, 0], [0, -24, 0, 0, -1255, 1255, 0, 0], [-420, 0, 290, -420, 0, 0, 0, 0], [0, 0, 0, 0, 120, 120, 238, 0], [0, 0, -415, -894, 0, 0, 0, -415], [0, 246, 0, 0, -180, 180, 0, 0], [430, 0, -246, 430, 0, 0, 0, 0], [0, 560, 0, 0, 0, -744, 560, 0], [0, 390, 0, 0, 1214, 0, -390, 0], [-840, 0, 0, 840, 0, 0, 0, -1138], [0, 0, 0, 0, 225, 225, 192, 0], [-718, 0, 570, 0, 0, 0, 0, -570], [0, 444, 0, 0, 1490, -1490, 0, 0], [-185, 0, 0, 185, 0, 0, 0, 1080], [-2070, 0, 116, -2070, 0, 0, 0, 0], [0, 0, 0, 0, 420, 420, -842, 0], [0, 510, 0, 0, -2040, 2040, 0, 0], [0, 125, 0, 0, 0, 222, 125, 0], [0, -1020, 0, 0, -736, 0, 1020, 0], [0, 0, 420, 2226, 0, 0, 0, 420], [-1350, 0, 0, 1350, 0, 0, 0, 386], [0, 0, 0, 0, 1020, 1020, -96, 0], [704, 0, 1680, 0, 0, 0, 0, -1680], [0, -432, 0, 0, 1985, -1985, 0, 0], [4140, 0, 14, 4140, 0, 0, 0, 0], [0, 870, 0, 0, 0, -386, 870, 0], [0, 0, -55, -186, 0, 0, 0, -55], [0, -126, 0, 0, 1200, -1200, 0, 0], [940, 0, 1950, 940, 0, 0, 0, 0], [-2514, 0, 30, 0, 0, 0, 0, -30], [0, -670, 0, 0, 0, -144, -670, 0], [2910, 0, 0, -2910, 0, 0, 0, 1064], [0, 70, 0, 0, 3096, 0, -70, 0], [0, 2388, 0, 0, 1760, -1760, 0, 0], [3805, 0, 0, -3805, 0, 0, 0, 1656], [2220, 0, -790, 2220, 0, 0, 0, 0], [0, 2082, 0, 0, -1290, 1290, 0, 0], [-1595, 0, -2208, -1595, 0, 0, 0, 0], [0, 720, 0, 0, 5444, 0, -720, 0], [0, 0, 2790, -858, 0, 0, 0, 2790], [690, 0, 0, -690, 0, 0, 0, 554], [0, 0, 0, 0, 1710, 1710, -84, 0], [0, -905, 0, 0, 3774, 0, 905, 0], [-4910, 0, 0, 4910, 0, 0, 0, -2250], [0, 0, 0, 0, -3840, -3840, -662, 0], [0, 120, 0, 0, 0, 9034, 120, 0], [0, 0, 35, 1074, 0, 0, 0, 35], [-1970, 0, -3066, -1970, 0, 0, 0, 0], [1710, 0, -1200, 0, 0, 0, 0, 1200], [0, 0, 240, -11220, 0, 0, 0, 240], [0, 0, 0, 0, -5145, -5145, -1296, 0], [12494, 0, 480, 0, 0, 0, 0, -480], [0, -3936, 0, 0, 3470, -3470, 0, 0], [-215, 0, 0, 215, 0, 0, 0, -12], [0, 0, 0, 0, -6180, -6180, 1138, 0], [0, 120, 0, 0, 0, -16352, 120, 0], [0, 0, -1810, 2118, 0, 0, 0, -1810], [-4685, 0, 2448, -4685, 0, 0, 0, 0], [-1518, 0, 1965, 0, 0, 0, 0, -1965], [0, -3055, 0, 0, 0, 6462, -3055, 0], [0, 2340, 0, 0, -3802, 0, -2340, 0], [0, 0, 0, 0, 4740, 4740, 3084, 0], [0, 655, 0, 0, -4710, 0, -655, 0], [0, -5844, 0, 0, -3145, 3145, 0, 0], [0, 0, 0, 0, -7050, -7050, 2506, 0], [0, -600, 0, 0, 0, 13702, -600, 0], [0, 0, 35, -14214, 0, 0, 0, 35], [2754, 0, 1710, 0, 0, 0, 0, -1710], [0, -3490, 0, 0, 0, -2340, -3490, 0], [-9070, 0, -210, 0, 0, 0, 0, 210], [0, 1750, 0, 0, -18024, 0, -1750, 0], [-1290, 0, 764, -1290, 0, 0, 0, 0], [0, -660, 0, 0, 0, -308, -660, 0], [0, 0, 980, 11766, 0, 0, 0, 980], [0, -1218, 0, 0, 3270, -3270, 0, 0], [-6875, 0, -1524, -6875, 0, 0, 0, 0], [0, 900, 0, 0, 11486, 0, -900, 0], [3360, 0, 0, -3360, 0, 0, 0, -2674], [0, 0, 0, 0, -330, -330, 2472, 0], [20126, 0, 1740, 0, 0, 0, 0, -1740], [0, 4555, 0, 0, -8118, 0, -4555, 0], [-350, 0, 0, 350, 0, 0, 0, -522], [-9990, 0, 1958, -9990, 0, 0, 0, 0], [0, 0, 0, 0, 8520, 8520, 2722, 0], [0, 1152, 0, 0, 11370, -11370, 0, 0], [8970, 0, 3000, 0, 0, 0, 0, -3000], [0, -40, 0, 0, 0, -6540, -40, 0], [0, -780, 0, 0, -13198, 0, 780, 0], [-12360, 0, 0, 12360, 0, 0, 0, 4430], [0, 0, 0, 0, -16005, -16005, -636, 0], [-11842, 0, -690, 0, 0, 0, 0, 690], [13255, 0, 0, -13255, 0, 0, 0, -4932], [600, 0, -4066, 600, 0, 0, 0, 0], [0, -60, 0, 0, 0, 11686, -60, 0], [0, -2706, 0, 0, -17790, 17790, 0, 0], [22266, 0, -945, 0, 0, 0, 0, 945], [0, 0, -360, -5250, 0, 0, 0, -360], [0, 0, 0, 0, 9540, 9540, -4308, 0], [0, -3065, 0, 0, -9750, 0, 3065, 0], [-7700, 0, 0, 7700, 0, 0, 0, -4938], [0, 0, 0, 0, -150, -150, 3010, 0], [0, -2340, 0, 0, 0, -12854, -2340, 0], [0, -4980, 0, 0, 18690, -18690, 0, 0], [5860, 0, -294, 5860, 0, 0, 0, 0], [-9138, 0, -3450, 0, 0, 0, 0, 3450], [0, 0, -1380, -4146, 0, 0, 0, -1380], [-13620, 0, 0, 13620, 0, 0, 0, 26], [0, 1630, 0, 0, 3336, 0, -1630, 0], [2760, 0, -11434, 2760, 0, 0, 0, 0], [0, 0, -3520, -4350, 0, 0, 0, -3520], [0, 6786, 0, 0, -15180, 15180, 0, 0], [-582, 0, -375, 0, 0, 0, 0, 375], [0, 5045, 0, 0, 0, -2226, 5045, 0], [0, 1020, 0, 0, 24620, 0, -1020, 0], [0, 0, -1470, 4986, 0, 0, 0, -1470], [0, 0, 0, 0, -10110, -10110, -5148, 0], [19330, 0, 0, -19330, 0, 0, 0, -3222], [-9570, 0, 2378, -9570, 0, 0, 0, 0], [0, 0, 0, 0, -4380, -4380, -15458, 0], [0, 2430, 0, 0, 0, 1678, 2430, 0], [13570, 0, 11106, 13570, 0, 0, 0, 0], [-9462, 0, 3600, 0, 0, 0, 0, -3600], [0, -340, 0, 0, 0, 26880, -340, 0], [0, -3150, 0, 0, -23518, 0, 3150, 0], [0, -10220, 0, 0, 13332, 0, 10220, 0], [0, 7512, 0, 0, -11650, 11650, 0, 0], [0, 0, 0, 0, -14610, -14610, 8428, 0], [0, 0, -1810, -5322, 0, 0, 0, -1810], [15265, 0, -1584, 15265, 0, 0, 0, 0], [22290, 0, 915, 0, 0, 0, 0, -915], [0, -2220, 0, 0, 8264, 0, 2220, 0], [23460, 0, 0, -23460, 0, 0, 0, 5570], [0, 6715, 0, 0, 19158, 0, -6715, 0], [0, -336, 0, 0, -24205, 24205, 0, 0], [11010, 0, -3586, 11010, 0, 0, 0, 0], [0, 60, 0, 0, 0, 11602, 60, 0], [0, -5562, 0, 0, 15000, -15000, 0, 0], [4540, 0, -19098, 4540, 0, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_60_j_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_60_4_j_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_60_4_j_a(:prec:=8)
    chi := MakeCharacter_60_j();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_60_4_j_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_60_4_j_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_60_j();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![9721171216, 0, 0, 0, 398792, 0, 0, 0, 1]>],Snew);
    return Vf;
end function;