
// Make newform 105.6.a.e in Magma, downloaded from the LMFDB on 13 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_105_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_105_6_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_105_6_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 := [-58, -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_105_a();"
function MakeCharacter_105_a()
    N := 105;
    order := 1;
    char_gens := [71, 22, 31];
    v := [1, 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_105_a_Hecke( : Kf := Kf)
    return MakeCharacter_105_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]];
    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 := [[0, 1], [-9, 0], [-25, 0], [-49, 0], [-88, -20], [42, -52], [570, -208], [-548, -68], [848, 136], [-638, 168], [-7068, 396], [-4470, 696], [1230, 160], [6840, 1792], [-4604, 192], [12654, -556], [-17636, -2952], [-8862, 2856], [34776, -4088], [16312, 1620], [-30194, 692], [-75296, -56], [-39964, -2904], [65534, 5216], [14750, -18436], [-9558, 16672], [-69840, 16576], [129500, 7680], [-99122, -336], [-182422, 5604], [-210056, -16504], [-327612, 8032], [-55614, -17284], [-120244, -27620], [179194, -9328], [41408, -51904], [242266, -10652], [-12032, 46144], [-155924, 58840], [-140294, 4184], [-17960, -16260], [-265102, -46528], [-256312, -4436], [226714, 51984], [222358, 34396], [-68412, -50420], [98868, -94872], [-270320, 71368], [-638932, 104952], [-11678, 33496], [1110450, -24764], [-585976, -32444], [248874, 86648], [70820, 151864], [272186, -107272], [-356400, -47456], [-528814, 131616], [-1318852, -9612], [186610, 55640], [1417410, 85336], [-504196, 160608], [226906, 161832], [802956, -45672], [16800, 331616], [-140890, 204044], [312934, 305812], [-600324, 139416], [-2165638, -169984], [-194084, -351896], [525530, -340312], [2909170, 80560], [940312, -365988], [-2999224, -89832], [3168914, 18240], [-164156, -277616], [4071676, -107464], [2142010, -459776], [-194198, -471140], [1226002, -297136], [-2002598, 504224], [721916, -631360], [-957466, 289296], [-644096, -731788], [1619662, -354644], [-419748, 868092], [-2556372, 25512], [1081834, -334576], [-539358, 1118344], [2326946, -370624], [1037008, 156104], [-4619452, -278888], [-3278920, 797312], [-4111072, -406856], [4342192, -167140], [-2315108, -471760], [-5187108, -423736], [4413106, -59392], [-6136498, -729648], [514604, -301720], [2191142, 5152], [-1691320, 486008], [-3610906, 25124], [3261076, 947664], [-519910, 92896], [-12946516, 124688], [132446, -780468], [-5778836, 511936], [3604570, 1100752], [-1034800, 714956], [822658, 1154264], [7822880, -725016], [9102154, -880248], [10305314, 35876], [2763172, 1676988], [-13859456, -6200], [-1487486, 786216], [-276700, -468632], [6356, -432680], [17201646, -464884], [-406472, -786140], [1226106, 2143096], [2767010, -1685800], [5137282, -1715416], [-18376956, 438888], [13076612, 855364], [-1436510, -371416], [3180542, -2116576], [-4585504, -551624], [-17591848, -481048], [10205210, -596340], [8782172, 1313104], [3133960, -3566432], [-5773768, -1995928], [11244786, -828960], [5641270, 1480688], [-6595054, 383848], [23758586, -916840], [19377756, -1774376], [-1981318, 2321112], [7461666, 2457688], [-5508132, 1492156], [-301766, 1275384], [-2363224, 368776], [21040292, 1271328], [-20437118, 1582336], [-11729696, 227896], [22778914, 1039404], [-30993310, -304648], [12814108, 128548], [-2312112, 2006408], [-6366102, 1368440], [-5865474, -2084368], [19803336, 12712], [-8746524, 66544], [15330016, -4217784], [12166040, 2558780], [36328192, 1497208], [417102, 779856], [6753278, -5459308], [-16830974, -3539360], [3909356, 2332824], [5583826, 2705828], [4868376, 3029344], [-42883116, 1025016], [-11299734, 5609860], [20182124, -2836080], [-16468952, 474200], [-29896654, 210492]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_105_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_105_6_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_105_6_a_e(:prec:=2)
    chi := MakeCharacter_105_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_105_6_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_105_6_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_105_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-58, -1, 1]>],Snew);
    return Vf;
end function;