
// Make newform 49.7.d.b in Magma, downloaded from the LMFDB on 13 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_49_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_49_d_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_7_d_b();".
// 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_7_d_b();".
// 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_d();"
function MakeCharacter_49_d()
    N := 49;
    order := 6;
    char_gens := [3];
    v := [5];
    // 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_d_Hecke();"
function MakeCharacter_49_d_Hecke( : Kf := false)
    N := 49;
    order := 6;
    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 := 7;
    raw_aps := [[0, 12], [7, 7], [-210, 105], [0, 0], [-1479, 1479], [280, -560], [1743, 1743], [-7938, 3969], [0, 5913], [3978, 0], [7399, 7399], [0, 61577], [-63840, 127680], [-17414, 0], [35406, -17703], [60513, -60513], [124551, 124551], [-187922, 93961], [268777, -268777], [101922, 0], [-183393, -183393], [0, -362231], [125160, -250320], [1541022, -770511], [874160, -1748320], [764799, 764799], [-73906, 36953], [0, -660543], [73169, -73169], [1603506, 0], [-3229966, 0], [-2304162, 1152081], [-1421583, 1421583], [-1406440, 2812880], [0, -3143751], [2282201, -2282201], [85743, 85743], [0, 7097473], [-372960, 745920], [-3620946, 1810473], [-10162791, 10162791], [-5037480, 10074960], [0, -4238439], [-6148207, 6148207], [790554, 0], [-4691449, -4691449], [11672362, 0], [-1673280, 3346560], [9682743, 9682743], [20181742, -10090871], [0, 10204353], [1431138, 0], [-8951201, -8951201], [1986600, -3973200], [26849886, -13424943], [28261833, -28261833], [-9128049, -9128049], [-42149842, 21074921], [-31480703, 31480703], [6623682, 0], [23237207, 23237207], [7320600, -14641200], [1023400, -2046800], [21088599, 21088599], [-13400226, 6700113], [0, -21164103], [0, 59219921], [36779794, 0], [-33977463, 33977463], [31641400, -63282800], [2748207, 2748207], [0, 5311689], [-46093257, -46093257], [0, -42260087], [12883978, 0], [30896334, -15448167], [10755729, -10755729], [-10996594, 5498297], [0, -76788399], [-17354449, -17354449], [-27504120, 55008240], [-27919078, 0], [-3314439, 3314439], [-26543440, 53086880], [-62861778, 31430889], [0, -105887007], [114053298, 0], [0, -98472943], [-20688360, 41376720], [180999506, 0], [-97980834, 48990417], [91928151, 91928151], [80614217, -80614217], [-14654358, 0], [0, 31255649], [82341840, -164683680], [12069582, -6034791], [-1570401, -1570401], [264509854, -132254927], [0, -229389239], [78798554, 0], [107355057, -107355057], [-132395193, -132395193], [0, 147104529], [-2755559, 2755559], [1846943, 1846943], [-138479880, 276959760], [219293214, -109646607], [-385150551, 385150551], [171690400, -343380800], [341001486, -170500743], [337212433, -337212433], [368150274, 0], [17943751, 17943751], [-325405918, 0], [55563681, -55563681], [53887400, -107774800], [111541143, 111541143], [0, -362447367], [239985258, 0], [11155599, 11155599], [-42717134, 0], [335729646, -167864823], [-82193127, 82193127], [-40088482, 20044241], [-304543398, 0], [0, 228891689], [-517187538, 258593769], [-21463120, 42926240], [-698789266, 349394633], [201787129, -201787129], [-98119614, 0], [0, 425827001], [30742714, 0], [-428657922, 214328961], [265542480, -531084960], [396195807, 396195807], [324696743, 324696743], [-574577640, 1149155280], [-715167231, 715167231], [192772440, -385544880], [0, 483959481], [-157007447, 157007447], [884715834, 0], [47009151, 47009151], [-269510640, 539021280], [-508316760, 1016633520], [-103864257, -103864257], [1047148382, -523574191], [0, -54414327], [0, 126036937], [-79591680, 159183360], [741287626, 0], [403998126, -201999063], [-732341143, 732341143], [-809031438, 0], [0, -1239482071], [1398988542, -699494271], [-73244080, 146488160], [244406799, 244406799], [0, 1595494017], [-342253854, 0], [-1568346526, 0], [-693667842, 346833921], [117902097, -117902097], [-600896793, -600896793], [1418759081, -1418759081], [-470123857, -470123857]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_49_d_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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