
// Make newform 42.6.e.a in Magma, downloaded from the LMFDB on 14 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_42_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_42_e_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_42_6_e_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_42_6_e_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_42_e();"
function MakeCharacter_42_e()
    N := 42;
    order := 3;
    char_gens := [29, 31];
    v := [3, 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_42_e_Hecke();"
function MakeCharacter_42_e_Hecke( : Kf := false)
    N := 42;
    order := 3;
    char_gens := [29, 31];
    char_values := [[1, 0], [-1, 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 := 6;
    raw_aps := [[-4, 4], [0, -9], [6, -6], [-7, 133], [0, 666], [-559, 0], [0, 1740], [-1157, 1157], [3468, -3468], [3372, 0], [0, -6293], [-3131, 3131], [-4866, 0], [-11407, 0], [-2310, 2310], [0, 28296], [0, -20544], [4630, -4630], [0, 18745], [-38226, 0], [0, -70589], [62293, -62293], [79818, 0], [18120, -18120], [124754, 0], [0, 93390], [167731, -167731], [-69180, 69180], [0, 219559], [-39354, 0], [317093, 0], [154830, -154830], [0, -67332], [-365215, 0], [168060, -168060], [0, -153536], [0, -202418], [179764, -179764], [217302, 0], [73980, -73980], [0, -789366], [-477739, 0], [-358974, 358974], [0, 181933], [717924, 0], [0, -203096], [1170980, 0], [1246352, 0], [0, 918942], [-1203749, 1203749], [919062, -919062], [-625338, 0], [0, -1253822], [-1513332, 0], [1554930, -1554930], [0, 1115316], [0, -35670], [292768, -292768], [0, -863213], [1471104, 0], [0, -688841], [722832, 0], [-20125, 0], [0, 1743558], [-1808543, 1808543], [-1023552, 1023552], [1007533, -1007533], [-1565707, 0], [0, -757284], [-455638, 0], [0, 3631386], [4024836, -4024836], [0, -2577875], [2531329, -2531329], [-3066769, 0], [3925200, -3925200], [0, 4026690], [-4574399, 4574399], [2269440, -2269440], [0, 4045963], [-3912810, 0], [-2780863, 0], [0, 4382070], [1249463, 0], [6744208, -6744208], [-478896, 478896], [724506, 0], [2339563, -2339563], [2982468, 0], [4284227, 0], [5740350, -5740350], [0, -2650512], [0, -2805539], [-4684500, 0], [-1475753, 1475753], [63606, 0], [-6211566, 6211566], [0, -1412052], [-5229347, 5229347], [-4413725, 4413725], [-11903764, 0], [0, -12913302], [0, 11369838], [5697954, -5697954], [0, 7042207], [0, 2581969], [4694592, 0], [-13423506, 13423506], [0, -5046012], [-10639081, 0], [-1416083, 1416083], [0, -9463034], [12938778, 0], [0, 3803761], [-9174976, 0], [0, -10245372], [-5723455, 0], [0, 9987942], [1198878, -1198878], [11806536, 0], [0, -4720391], [-8708257, 0], [-5111052, 5111052], [0, 17719776], [22599337, -22599337], [-818148, 0], [5091826, -5091826], [480858, -480858], [-14078329, 0], [-2039321, 2039321], [0, 16495699], [-23812086, 0], [-1924961, 1924961], [8980922, 0], [-14599092, 14599092], [27838055, 0], [0, 28285722], [0, -9872], [-10891908, 0], [0, 5235294], [12614744, 0], [15342378, -15342378], [0, 14959504], [28049790, 0], [0, -14731097], [23634660, 0], [14396459, 0], [0, -12470976], [12505888, -12505888], [-28028922, 28028922], [-23117282, 23117282], [-9598908, 0], [443183, 0], [24009666, -24009666], [0, -17585375], [-29559852, 0], [3914821, -3914821], [3220086, -3220086], [-51650353, 0], [0, 7286976], [31244778, -31244778], [-26827320, 0], [-10025665, 0], [-115800, 115800], [0, -8738094], [0, -23841264], [0, 33371923], [0, -54468659]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_42_e_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_42_6_e_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_42_6_e_a(:prec:=2)
    chi := MakeCharacter_42_e();
    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_42_6_e_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_42_6_e_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_42_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![36, -6, 1]>],Snew);
    return Vf;
end function;