
// Make newform 49.10.c.a in Magma, downloaded from the LMFDB on 20 August 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_49_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_49_c_Hecke();"
// 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_10_c_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_49_10_c_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
        poly := [1, -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_49_c();"
function MakeCharacter_49_c()
    N := 49;
    order := 3;
    char_gens := [3];
    v := [2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_49_c_Hecke();"
function MakeCharacter_49_c_Hecke( : Kf := false)
    N := 49;
    order := 3;
    char_gens := [3];
    char_values := [[0, -1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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]];
    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 := 10;
    raw_aps := [[0, 5], [0, 0], [0, 0], [0, 0], [42908, -42908], [0, 0], [0, 0], [0, 0], [0, -1396040], [7571426, 0], [0, 0], [0, -22743450], [0, 0], [37101780, 0], [0, 0], [58133290, -58133290], [0, 0], [0, 0], [-262469860, 262469860], [-413067632, 0], [0, 0], [0, 603893176], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, -1862391820], [-209637234, 209637234], [2599459970, 0], [4290298000, 0], [0, 0], [-6089507510, 6089507510], [0, 0], [0, 7538658314], [-4766148648, 4766148648], [0, 0], [0, 17486436980], [0, 0], [0, 0], [-26806410724, 26806410724], [0, 0], [0, -17600930888], [-2290735890, 2290735890], [39894961990, 0], [0, 0], [36684570708, 0], [0, 0], [0, 0], [0, 0], [0, -73670275030], [-99204389744, 0], [0, 0], [0, 0], [0, 0], [-14859963680, 14859963680], [0, 0], [0, 0], [75480859690, -75480859690], [-207161852378, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, -327479448830], [0, -111156785028], [345418765470, 0], [-444996652900, 444996652900], [0, 0], [0, 0], [0, -592645690184], [0, 0], [0, 551473419530], [-254153516076, 0], [0, 0], [-692557443706, 692557443706], [0, 0], [0, 305042218402], [0, 0], [0, 0], [138476109382, 0], [-1429713987872, 1429713987872], [0, 0], [0, 0], [0, -1568179479820], [710022480386, 0], [0, 1779596750790], [0, 0], [1911870502040, 0], [0, 0], [0, 0], [-2222419596840, 2222419596840], [1220406478412, 0], [0, -2318376780036], [0, 0], [0, 0], [0, 0], [0, 0], [0, 3539370997762], [-4186329965620, 0], [2034824014130, -2034824014130], [0, 0], [0, 4608266198954], [-3478383589732, 3478383589732], [0, 0], [0, 0], [0, 0], [-813708059936, 813708059936], [0, 0], [0, 0], [6990743755910, -6990743755910], [6985170768550, 0], [0, 0], [1773143632528, 0], [6314968266962, -6314968266962], [0, 0], [0, 0], [0, 2803265373550], [1542995694284, 0], [0, 0], [-7132995528930, 0], [0, 0], [6956674584340, -6956674584340], [0, 0], [4264299429602, 0], [0, 11439447454566], [0, 0], [0, 0], [0, 0], [-14420632296044, 14420632296044], [-15032889184360, 0], [0, -3095989391952], [3074283150570, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [7213209468134, -7213209468134], [0, 0], [0, 10248604043018], [21539160705760, -21539160705760], [26900463027020, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, -30707372208200], [0, -12973427138450], [0, 0], [-34923484383660, 0], [0, 0], [-28642021848540, 28642021848540], [27642474609808, 0], [0, 40349321897904], [0, 0], [0, 0], [0, 0], [0, 8028056926580], [-50925510473990, 0], [-235823891560, 0], [0, 0], [-52194492718510, 52194492718510], [0, 0], [-22421191163688, 22421191163688], [0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_49_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_49_10_c_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_49_10_c_a(:prec:=2)
    chi := MakeCharacter_49_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_10_c_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_49_10_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_49_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![25, -5, 1]>,<3,R![0, 1]>],Snew);
    return Vf;
end function;