
// Make newform 2064.2.a.k in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2064_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_2064_2_a_k();".
// 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_2064_2_a_k();".
// 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_2064_a();"
function MakeCharacter_2064_a()
    N := 2064;
    order := 1;
    char_gens := [1807, 517, 689, 433];
    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_2064_a_Hecke(Kf)
    return MakeCharacter_2064_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], [1], [-2], [2], [5], [3], [-3], [-2], [1], [0], [5], [8], [-7], [1], [8], [3], [-12], [-8], [15], [14], [12], [16], [-15], [10], [11], [-9], [-5], [0], [11], [-4], [3], [-16], [18], [5], [-16], [2], [-6], [-16], [1], [-10], [26], [-10], [8], [-21], [-14], [14], [6], [-14], [8], [5], [-22], [-16], [-4], [-25], [14], [-18], [-9], [17], [-18], [3], [-1], [18], [7], [5], [12], [5], [4], [-23], [-18], [-32], [-27], [5], [-16], [4], [13], [36], [18], [2], [-23], [22], [-34], [18], [-31], [-14], [7], [-12], [24], [32], [18], [22], [14], [-13], [4], [-16], [-22], [-14], [-39], [12], [6], [-3], [1], [-43], [-1], [27], [-28], [-10], [18], [18], [-11], [-12], [-36], [-2], [-25], [-28], [-2], [-30], [-12], [32], [-26], [-1], [-1], [12], [-26], [9], [14], [26], [31], [8], [-16], [-36], [54], [24], [20], [-40], [24], [38], [-38], [-36], [2], [-26], [-32], [53], [9], [-44], [12], [38], [-5], [14], [-4], [-2], [13], [-3], [-15], [58], [21], [-12], [37], [-34], [-30], [-15], [13], [36], [-53], [45], [22], [-10], [4], [58], [-38], [50], [-30], [38], [48], [-35], [-34], [-2], [-20], [-18], [-64], [-12], [54], [60], [40], [-2], [0], [-32], [26], [-38], [42], [0], [-59], [-6], [-28], [-4], [-2], [24], [-3], [-39], [18], [-12], [23], [10], [-20], [10], [30], [0], [4], [-3], [-10], [41], [-22], [-17], [1], [23], [24], [7], [-4], [24], [18], [-45], [-54], [32], [4], [-53], [56], [69], [5], [12], [-62], [-18], [-16], [7], [-11], [60], [-23], [-4], [-36], [69], [24], [39], [-52], [-12], [-40], [38], [12], [40], [-12], [-17], [-1], [-29], [-34], [-63], [-33], [-14], [18], [52], [12], [73], [-74], [-3], [26], [-18], [-70], [46], [60], [-78], [30], [35], [46], [-71], [-59], [2], [54], [-22], [10], [36], [53], [-68], [-3], [32], [-85], [8], [71], [-22], [16], [54], [-27], [-50], [-72], [63], [-33], [-39], [66], [-50], [11], [9], [77], [-25], [60], [8], [-31], [-24], [25], [-3], [62], [-50], [47], [-12], [66], [56], [-78], [6], [-33], [-14], [-21], [-23], [12], [-32], [55], [-54], [69], [-24], [42], [20], [-36], [29], [-22], [23], [40], [22], [82], [-9], [-44], [-48], [-44], [-9], [-92], [-78], [32], [8], [-73], [-16], [-48], [36], [25], [45], [34], [-12], [-68], [21], [24], [32], [66], [38], [58], [30], [36], [-80], [27], [-41], [82], [18], [62], [-58], [-31], [80], [-12], [-56], [42], [-34], [-94], [8], [70], [95], [-28], [66], [8], [-55], [-12], [-70], [-21], [-71], [-7], [54], [-77], [7], [30], [-43], [52], [-33], [17], [22], [-4], [-15], [12], [-26], [-25], [52], [-18], [28], [65], [-94], [7], [-22], [-58], [72], [94], [-90], [-48], [69], [22], [78], [86], [23], [26], [9], [-63], [-80], [-82], [-20], [-88], [-58], [-72], [-69], [58], [8], [34], [96], [-9], [30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2064_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2064_2_a_k();".
// 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_2064_2_a_k(:prec:=1)
    chi := MakeCharacter_2064_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_2064_2_a_k();".
// 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_2064_2_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2064_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, 1]>,<7,R![-2, 1]>,<11,R![-5, 1]>,<13,R![-3, 1]>],Snew);
    return Vf;
end function;