
// Make newform 1260.2.a.i in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1260_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_1260_2_a_i();".
// 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_1260_2_a_i();".
// 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_1260_a();"
function MakeCharacter_1260_a()
    N := 1260;
    order := 1;
    char_gens := [631, 281, 757, 1081];
    v := [1, 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_1260_a_Hecke(Kf)
    return MakeCharacter_1260_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 := 2;
    raw_aps := [[0], [0], [1], [1], [-6], [-4], [-6], [2], [0], [-6], [-10], [2], [6], [-4], [0], [12], [0], [14], [-4], [-6], [-4], [-16], [12], [-6], [-16], [-6], [-16], [0], [2], [0], [8], [12], [12], [-22], [-18], [-4], [8], [20], [0], [-6], [-6], [2], [-18], [26], [24], [-10], [20], [-4], [-12], [14], [24], [-6], [-10], [-24], [-18], [12], [-6], [2], [26], [-6], [-4], [18], [-16], [24], [8], [12], [-4], [-22], [-12], [-10], [-30], [30], [-4], [14], [-16], [0], [-18], [-4], [6], [-22], [-12], [-10], [18], [8], [-10], [-12], [6], [-34], [-18], [-16], [12], [-24], [32], [18], [-40], [0], [-30], [6], [32], [38], [-28], [-12], [12], [30], [32], [32], [-36], [-6], [30], [-10], [-4], [2], [0], [2], [-16], [-30], [32], [-48], [-48], [-42], [-10], [14], [18], [-12], [-34], [42], [38], [36], [-28], [20], [8], [36], [32], [-10], [-30], [-10], [18], [-16], [-30], [-30], [-46], [-6], [-16], [48], [26], [12], [-4], [-42], [14], [-24], [-22], [-30], [-52], [0], [20], [6], [-16], [-6], [20], [-18], [36], [-48], [56], [0], [-48], [0], [-40], [-28], [14], [18], [18], [50], [-54], [-46], [50], [30], [20], [30], [44], [-22], [8], [0], [14], [-54], [12], [-54], [50], [8], [-34], [-12], [-16], [-24], [-16], [54], [12], [-54], [-34], [62], [-18], [-48], [18], [38], [-40], [-10], [48], [-30], [50], [-24], [42], [14], [38], [-54], [-16], [12], [12], [14], [8], [18], [-60], [24], [38], [-58], [-6], [-16], [-12], [-22], [-66], [-42], [8], [42], [-58], [74], [20], [-6], [8], [0], [74], [24], [42], [-60], [-24], [26], [32], [-22], [6], [36], [-28], [-36], [-52], [-24], [-22], [18], [24], [26], [42], [18], [-22], [-4], [42], [-16], [8], [60], [-34], [-16], [66], [-58], [-6], [54], [-4], [-24], [-22], [-52], [-40], [-40], [-16], [-28], [-48], [-34], [-70], [-24], [48], [-16], [24], [-46], [-64], [-18], [38], [36], [14], [-54], [-54], [-84], [-72], [60], [-10], [-18], [50], [6], [0], [56], [-76], [-48], [-4], [-36], [32], [74], [48], [86], [-30], [-10], [48], [-30], [54], [44], [48], [-82], [60], [-66], [80], [30], [-34], [62], [54], [-16], [60], [38], [-16], [44], [48], [-36], [-46], [-72], [-46], [12], [-52], [-12], [-10], [-66], [38], [-52], [86], [-48], [-30], [44], [72], [-90], [-34], [-52], [-36], [18], [50], [-34], [66], [80], [50], [66], [12], [-36], [0], [12], [38], [54], [-12], [6], [32], [-82], [30], [-40], [26], [18], [38], [36], [6], [74], [98], [12], [30], [8], [78], [44], [-78], [48], [-16], [12], [-22], [72], [80], [-76], [44], [0], [-10], [78], [-90], [8], [18], [2], [2], [42], [-40], [42], [-94], [24], [56], [-18], [6], [-22], [2], [6], [-4], [0], [-4], [12], [12], [20], [-22], [-54], [90], [-28], [-78], [-96], [-90], [-28], [36], [-72], [56], [66], [24], [6], [38], [60]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1260_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1260_2_a_i();".
// 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_1260_2_a_i(:prec:=1)
    chi := MakeCharacter_1260_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_1260_2_a_i();".
// 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_1260_2_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1260_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![6, 1]>,<17,R![6, 1]>],Snew);
    return Vf;
end function;