
// Make newform 60.6.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_60_a();"
// 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_a_c();".
// 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_a_c();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_60_a();"
function MakeCharacter_60_a()
    N := 60;
    order := 1;
    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;

function MakeCharacter_60_a_Hecke(Kf)
    return MakeCharacter_60_a();
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], [9], [-25], [-244], [-144], [50], [-1914], [140], [-624], [-3126], [-5176], [15698], [12570], [11516], [-26736], [-19158], [27984], [22022], [-12676], [-59520], [-67102], [11048], [-115284], [73650], [35522], [-112062], [-106516], [-29292], [125318], [166638], [-201724], [131472], [-102042], [-243604], [-309462], [-147160], [268082], [-276580], [-592272], [29154], [131784], [-297730], [851784], [292394], [-869526], [-143992], [836420], [1220900], [-173580], [120806], [592590], [706008], [1561538], [-1484712], [624558], [778896], [-11574], [118064], [659282], [-1490574], [-1131292], [896298], [-1386412], [3192384], [2516834], [-2218974], [-27148], [2196698], [-989652], [-3050554], [-339642], [-2206776], [2071316], [-1949974], [3850028], [-67152], [4323306], [118298], [-3139014], [-452614], [3735792], [-1874650], [-4740192], [-4353766], [1049288], [6007884], [1372218], [-389830], [-3151374], [4669388], [-4924452], [-4030296], [4142132], [-1228536], [3647564], [-1984536], [-5758518], [-6840078], [7269908], [-1888762], [-2648668], [-2827038], [9220500], [-2967054], [1567460], [-10792318], [-13436844], [-3535074], [-8568504], [-11573302], [3766508], [5551058], [8663934], [-6117796], [4113152], [64674], [-2428516], [7437768], [19976226], [-742752], [-12083842], [-7144870], [20325546], [-6654156], [-11143012], [14740746], [20111894], [9179328], [-17252428], [27993626], [-6967780], [13572024], [8176472], [-8607406], [-22859598], [15479042], [-29967078], [-1066948], [-5280078], [5685546], [-27174580], [33095106], [6906308], [23748972], [-32201098], [-16282056], [-40672798], [-1991538], [-3622420], [23801352], [10895474], [17938890], [7706012], [-35677584], [19090508], [7404528], [24741488], [8858298], [-30656902], [12930210], [20570148], [20048934], [-4372660], [26118408], [-26144298], [15246648], [-29066512], [2926634]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_60_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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