
// Make newform 60.6.a.a 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_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_a_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
        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], [44], [216], [770], [534], [1580], [2904], [-4566], [2744], [1442], [-13350], [17204], [-10824], [-9942], [-15576], [39302], [55796], [57120], [50402], [-10552], [108564], [-116430], [-2782], [27618], [10556], [-67668], [-230362], [73182], [-208636], [18792], [-142218], [-297604], [381738], [-302680], [423458], [-358300], [4392], [128226], [559104], [753470], [-329016], [-262294], [-977814], [172088], [-931900], [-840460], [-667140], [1029446], [-1608450], [1625448], [426818], [-1335312], [-2086818], [940824], [1013706], [-288016], [860738], [420306], [455372], [2115402], [1283132], [1432704], [-1250494], [-2064606], [-2362108], [-3092998], [2094612], [-3063514], [596502], [-3112536], [2055764], [-350566], [-3866212], [2706792], [1544106], [-339478], [4701786], [-3989254], [4420152], [3749990], [-5096592], [4952666], [4140248], [3418116], [-5724102], [-847750], [5665746], [2523212], [-7622508], [-5174376], [6047108], [-5230656], [848204], [-7602624], [-423318], [-852558], [-1106788], [-6983482], [-6698452], [-698142], [2682540], [3808146], [5153780], [-446782], [14248524], [-10238706], [11411496], [-79222], [-947908], [-9323998], [13658286], [10261484], [10346192], [6764994], [-4133404], [7185552], [-13460286], [-7303032], [-19782082], [536090], [6251274], [9835356], [-13162612], [-22681974], [-8778826], [-25022112], [10621508], [2224394], [-9330820], [9450096], [549512], [-15743614], [4005042], [18799682], [-9138342], [-2172652], [18234258], [-2889654], [23383820], [-949374], [35543012], [7487988], [10588502], [-7274856], [34090418], [19749438], [-26494660], [-13725552], [16799906], [35296650], [-41222812], [-15670296], [-17958028], [-40657632], [-3010192], [-30286662], [26586842], [-27644670], [-38400948], [22553526], [-22991860], [25716288], [-15446682], [27870192], [13291088], [16794266]];
    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_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_a_a(: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_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_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_60_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![-44, 1]>],Snew);
    return Vf;
end function;