
// Make newform 63.4.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_63_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_63_4_a_e();".
// 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_63_4_a_e();".
// 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 := [-14, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_63_a();"
function MakeCharacter_63_a()
    N := 63;
    order := 1;
    char_gens := [29, 10];
    v := [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_63_a_Hecke(Kf)
    return MakeCharacter_63_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 := 4;
    raw_aps := [[1, 1], [0, 0], [-2, -2], [7, 0], [8, -10], [14, -12], [2, 2], [44, -24], [-20, 34], [138, -24], [-16, 72], [-106, -36], [210, 30], [212, -48], [40, -68], [554, -4], [-460, 116], [-250, 72], [20, 108], [-492, 30], [530, 12], [-232, -108], [-924, -96], [-254, 142], [266, 276], [-586, 26], [-1384, -144], [-440, -170], [-106, -288], [222, -264], [-1048, -156], [-1052, 136], [974, -124], [644, 240], [778, -356], [-1240, 432], [2294, 192], [1028, 324], [-672, 300], [-1682, -494], [-1000, 890], [182, 684], [-356, 22], [2666, 324], [-870, 876], [-1528, -360], [1724, -264], [-3472, -72], [2396, -988], [1766, -612], [6574, 4], [516, -78], [1370, 36], [-3948, 372], [-2774, -2], [1436, -814], [2438, -1378], [-2896, 1296], [1910, 180], [558, 108], [740, -72], [630, 378], [3164, -1488], [-1552, 1148], [-1846, -96], [274, 1372], [7748, -168], [2018, 1944], [3872, -1366], [-7546, 744], [-2350, 1970], [-3884, -1346], [-3376, 912], [-4978, 1920], [2228, 1032], [6256, 1864], [-3982, 248], [-2266, 720], [1030, -788], [3890, -1548], [-1764, -2700], [1766, -2988], [5132, 326], [4802, -3864], [-3736, -2544], [6784, 1978], [-9858, -192], [-4390, 2016], [-4578, 858], [7688, -756], [10876, -1508], [-376, -556], [-568, -24], [5808, 570], [3548, 1080], [-7560, -144], [-9578, 2446], [1514, -3094], [1892, -2160], [-6994, -2076], [212, 492], [2066, 644], [9788, -2884], [7582, 3892], [-10900, -204], [13970, -792], [-5292, 3276], [10498, 1138], [-17548, -1978], [-4774, 5928], [2816, 3936], [-2626, 2592], [-1122, 5916], [-10348, 1944], [10544, 420], [6854, 788], [1148, -552], [-11632, 3380], [-9974, -2576], [-5952, 1950], [-2242, -1248], [18650, -1620], [-11930, -4766], [-16960, -3838], [5420, -1512], [4842, 1512], [9470, -5328], [-13232, 592], [-19768, 4128], [2270, -5580], [15140, -5868], [-5868, 702], [4976, -3696], [-15538, 240], [32674, 94], [-1582, 1944], [422, 5570], [-5812, -2664], [20958, -3918], [9542, 3296], [-5740, 7992], [-34502, -1148], [-736, 3996], [25464, -5082], [-41554, -852], [-16464, 132], [41006, -1656], [3362, 7502], [4916, -2736], [5188, 5962], [3926, 8640], [33810, 2346], [10460, 7992], [11632, 7564], [-8044, -1296], [36300, -4650], [-22408, -1656], [1594, -1178], [26474, -4872], [38054, 1550], [34672, 3334], [-6666, -10608], [-26752, -4764], [124, 1888], [-5242, 140], [-19192, -5800], [12368, -2520], [20270, 288]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_63_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_63_4_a_e();".
// 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_63_4_a_e(:prec:=2)
    chi := MakeCharacter_63_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_63_4_a_e();".
// 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_63_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_63_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-12, -3, 1]>],Snew);
    return Vf;
end function;