
// Make newform 60.6.h.a in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_60_h();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_60_h_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_6_h_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_6_h_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 := [9, 0, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -1, 0, 1], [0, 6, 0, -1], [-10, 0, 5, 0]];
    Rf_basisdens := [1, 3, 1, 1];
    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_h();"
function MakeCharacter_60_h()
    N := 60;
    order := 2;
    char_gens := [31, 41, 37];
    v := [1, 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_60_h_Hecke();"
function MakeCharacter_60_h_Hecke(Kf)
    N := 60;
    order := 2;
    char_gens := [31, 41, 37];
    char_values := [[-1, 0, 0, 0], [-1, 0, 0, 0], [-1, 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 := 6;
    raw_aps := [[0, 4, 0, 0], [0, 10, 1, 0], [0, 0, 0, 5], [0, -1, -2, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -2419, 0, 0], [0, 0, 0, 796], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1882], [0, 1439, 2878, 0], [0, 16667, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [25448, 0, 0, 0], [0, -1195, -2390, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -81631, 0, 0], [0, 0, 0, -632], [0, 0, 0, 0], [0, 0, 0, -13604], [0, 13205, 26410, 0], [0, 121433, 0, 0], [233264, 0, 0, 0], [0, 0, 0, 0], [0, 13433, 26866, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 38602], [0, 0, 0, 0], [0, 0, 0, 0], [0, -36967, -73934, 0], [0, -154717, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [320402, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 47519, 95038, 0], [0, -1092133, 0, 0], [1066814, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1110452, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 947969, 0, 0], [0, 0, 0, 121390], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, -60746], [0, -109195, -218390, 0], [0, 0, 0, 0], [0, -171589, -343178, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -1133917, 0, 0], [-2954614, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 131039, 262078, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 2430119, 0, 0], [0, 0, 0, -529466], [0, 0, 0, 0], [0, 0, 0, 396784], [-3215764, 0, 0, 0], [0, 0, 0, 0], [6044648, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 2457431, 0, 0], [0, 0, 0, -271010], [0, 0, 0, 0], [0, 0, 0, -707684], [0, 40547, 81094, 0], [0, -5994283, 0, 0], [0, 0, 0, 0], [0, 325913, 651826, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -3884269, 0, 0], [0, 0, 0, 821620], [0, 0, 0, 1001608], [0, 731291, 1462582, 0], [-13584202, 0, 0, 0], [0, 293759, 587518, 0], [0, 0, 0, 0], [0, -1579219, 0, 0], [0, 0, 0, -584906], [0, 0, 0, 0], [0, 0, 0, 0], [0, -10113733, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-1812748, 0, 0, 0], [0, -1145995, -2291990, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, -680702], [0, -1326013, -2652026, 0], [0, -14480167, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-4836448, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 16650131, 0, 0], [0, 0, 0, 0], [0, 0, 0, -1909010], [23476514, 0, 0, 0], [0, 0, 0, 0], [0, -1664623, -3329246, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -11386681, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1076464], [31382414, 0, 0, 0], [0, 0, 0, 0], [0, -1812733, -3625466, 0], [0, 0, 0, 0], [0, 0, 0, 3328648], [0, 0, 0, 0], [0, 0, 0, 861574], [0, -2420395, -4840790, 0], [0, 3776117, 0, 0], [15230936, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 21314219, 0, 0], [0, 0, 0, 0], [0, 0, 0, 2164786], [0, 2765273, 5530546, 0], [0, 26364017, 0, 0], [0, 2941181, 5882362, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 4704898], [0, 0, 0, 0], [0, 0, 0, -3930380], [0, -27916417, 0, 0], [0, 0, 0, 0], [0, -1662973, -3325946, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -17587369, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_60_h_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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