
// Make newform 49.6.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_49_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_49_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_49_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
        poly := [-39, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 4]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_49_a();"
function MakeCharacter_49_a()
    N := 49;
    order := 1;
    char_gens := [3];
    v := [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_49_a_Hecke(Kf)
    return MakeCharacter_49_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 := [[-2, 0], [0, 1], [0, 3], [0, 0], [-284, 0], [0, 21], [0, -6], [0, 87], [1496, 0], [-4366, 0], [0, -258], [-12630, 0], [0, -378], [-1356, 0], [0, 402], [14150, 0], [0, -1497], [0, -1425], [-3644, 0], [35632, 0], [0, 1632], [-54616, 0], [0, -21], [0, -816], [0, 7350], [0, 3039], [0, -438], [218188, 0], [-96030, 0], [-137422, 0], [170368, 0], [0, -13941], [-75562, 0], [0, 3885], [361030, 0], [32280, 0], [0, -5319], [-61364, 0], [0, 15246], [0, 20709], [610564, 0], [0, -17367], [341192, 0], [-616158, 0], [231478, 0], [0, -16218], [776820, 0], [0, 3276], [0, 30171], [0, 1053], [47542, 0], [1088992, 0], [0, -54018], [0, 25221], [0, -77424], [-1117120, 0], [0, 60873], [0, 40848], [1896422, 0], [1319110, 0], [0, 19167], [0, 60123], [0, -47901], [0, -52632], [0, -106194], [-1599922, 0], [-111708, 0], [1593006, 0], [-3336764, 0], [0, -64155], [0, 72444], [920792, 0], [0, 53964], [3137734, 0], [-1831884, 0], [0, -1110], [-548342, 0], [0, -16167], [-4164274, 0], [0, -101730], [0, -92127], [-2799914, 0], [954320, 0], [0, 20790], [0, 239424], [3748204, 0], [99458, 0], [-161814, 0], [0, -179823], [3593816, 0], [0, 82155], [0, -80058], [2171256, 0], [3045548, 0], [-7992252, 0], [0, 379428], [0, 404337], [0, 204954], [0, 140703], [-3475474, 0], [-7857652, 0], [9065374, 0], [0, 232569], [10555942, 0], [7995844, 0], [0, -104460], [0, 176841], [0, -221820], [5086112, 0], [0, 96600], [0, 305112], [3601258, 0], [7229014, 0], [0, -503733], [5983504, 0], [-7740002, 0], [0, 272769], [0, -428826], [13416674, 0], [13857356, 0], [0, -483321], [-5324898, 0], [0, -938823], [18226988, 0], [0, 304587], [314162, 0], [24828522, 0], [0, 688278], [0, -852390], [0, -784725], [14418092, 0], [5575208, 0], [508800, 0], [11046618, 0], [0, -271086], [0, -993006], [0, -652329], [0, -577317], [0, -44079], [-24514550, 0], [0, 1215291], [-25459898, 0], [5952320, 0], [-7858996, 0], [0, 450927], [0, -312438], [0, 602805], [0, 915678], [0, 329409], [4099016, 0], [787778, 0], [0, 693840], [12399060, 0], [0, -670758], [-39654276, 0], [29913760, 0], [19899696, 0], [0, 479034], [0, -247464], [0, -1198665], [-48427892, 0], [22678042, 0], [-3604312, 0], [0, 1164159], [-18195986, 0], [0, -133230], [52542024, 0], [0, 49239]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_49_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_49_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_49_6_a_c(:prec:=2)
    chi := MakeCharacter_49_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_49_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_49_6_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_49_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![2, 1]>,<3,R![-624, 0, 1]>],Snew);
    return Vf;
end function;