
// Make newform 60.6.h.b in Magma, downloaded from the LMFDB on 24 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_b();".
// 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_b();".
// 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, 2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -2, 2, -1], [-5, 1, -1, -2], [3, 15, -5, 5]];
    Rf_basisdens := [1, 1, 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, 0, -1, 0], [0, 9, 0, 0], [0, -5, -10, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 58, 116, 0], [118, 0, 0, -236], [0, -2818, 0, 0], [0, 0, 0, 0], [-358, 0, 0, 716], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -16026, 0, 0], [0, -3658, -7316, 0], [0, 0, 0, 0], [-34802, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [4442, 0, 0, -8884], [0, 59218, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -66774, 0, 0], [-125986, 0, 0, 0], [0, 21178, 42356, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 2690, 5380, 0], [15486, 0, 0, -30972], [0, 0, 0, 0], [2514, 0, 0, -5028], [0, 0, 0, 0], [0, 0, 0, 0], [0, -81074, 0, 0], [0, 65710, 131420, 0], [0, 0, 0, 0], [-879098, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -69898, -139796, 0], [57234, 0, 0, -114468], [-65162, 0, 0, 130324], [0, 0, 0, 0], [0, 895874, 0, 0], [1425814, 0, 0, 0], [0, -122110, -244220, 0], [0, 0, 0, 0], [571202, 0, 0, 0], [0, 0, 0, 0], [0, -87766, -175532, 0], [0, -224082, 0, 0], [0, 0, 0, 0], [115802, 0, 0, -231604], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -128954, -257908, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 80110, 160220, 0], [-65154, 0, 0, 130308], [0, 0, 0, 0], [0, -2557974, 0, 0], [2443886, 0, 0, 0], [0, 409514, 819028, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-251410, 0, 0, 502820], [0, 1345718, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-2315014, 0, 0, 0], [0, 0, 0, 0], [-2594602, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-157790, 0, 0, 315580], [0, 2785882, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -884926, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-439562, 0, 0, 879124], [0, -2470018, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-2905202, 0, 0, 0], [0, 0, 0, 0], [0, -817490, -1634980, 0], [0, -3717918, 0, 0], [0, 0, 0, 0], [804590, 0, 0, -1609180], [0, 0, 0, 0], [0, -3030326, 0, 0], [0, 679738, 1359476, 0], [0, 0, 0, 0], [17027002, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -1294238, -2588476, 0], [643326, 0, 0, -1286652], [-983390, 0, 0, 1966780], [0, 0, 0, 0], [0, 0, 0, 0], [0, 7512526, 0, 0], [0, 383438, 766876, 0], [0, 0, 0, 0], [18023302, 0, 0, 0], [0, 0, 0, 0], [0, -182714, -365428, 0], [0, 11392282, 0, 0], [-873482, 0, 0, 1746964], [0, 0, 0, 0], [-14922986, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [1430534, 0, 0, -2861068], [0, -1692882, 0, 0], [-1186934, 0, 0, 2373868], [0, 0, 0, 0], [0, 0, 0, 0], [32280914, 0, 0, 0], [0, -1164298, -2328596, 0], [0, 0, 0, 0], [0, -2689522, -5379044, 0], [0, 0, 0, 0], [1668606, 0, 0, -3337212], [0, 0, 0, 0], [0, 0, 0, 0], [0, -22187126, 0, 0], [648686, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 3189394, 6378788, 0], [1006190, 0, 0, -2012380], [0, -9531082, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -19729826, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-2439726, 0, 0, 4879452], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 3063026, 0, 0], [0, -729326, -1458652, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 1870138, 3740276, 0], [0, -9545218, 0, 0], [2838346, 0, 0, -5676692], [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_b();".
// 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_b(: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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_60_h();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![0, 1]>],Snew);
    return Vf;
end function;