
// Make newform 1862.2.a.d in Magma, downloaded from the LMFDB on 20 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1862_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_1862_2_a_d();".
// 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_1862_2_a_d();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1862_a();"
function MakeCharacter_1862_a()
    N := 1862;
    order := 1;
    char_gens := [1179, 1275];
    v := [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_1862_a_Hecke( : Kf := Kf)
    return MakeCharacter_1862_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 := 2;
    raw_aps := [[1], [0], [-1], [0], [-5], [2], [6], [-1], [-5], [0], [-4], [-4], [-4], [-11], [-3], [4], [-14], [-5], [6], [6], [-1], [-16], [13], [-18], [12], [9], [0], [12], [-4], [16], [-14], [12], [-3], [9], [-1], [-8], [5], [-7], [22], [4], [-6], [-26], [-13], [6], [-7], [-11], [-2], [14], [18], [30], [-2], [16], [-20], [-15], [-14], [12], [-20], [11], [-5], [-16], [19], [12], [-16], [0], [5], [34], [-18], [22], [3], [-34], [18], [-7], [-12], [8], [-12], [-30], [-6], [30], [2], [34], [-11], [10], [-18], [-20], [2], [-4], [-20], [3], [25], [-41], [-21], [15], [-22], [-25], [15], [-19], [-2], [-4], [4], [33], [8], [43], [-18], [22], [-9], [-23], [12], [33], [-34], [-12], [44], [-30], [1], [-19], [-41], [-30], [0], [-39], [-6], [32], [34], [-34], [-16], [-30], [20], [15], [-37], [16], [-13], [-22], [-44], [32], [18], [37], [-33], [-51], [-8], [26], [8], [27], [-30], [39], [-31], [36], [-44], [30], [19], [28], [-13], [-56], [2], [-18], [-56], [0], [8], [-24], [45], [21], [-25], [-38], [-12], [-40], [0], [20], [-10], [-24], [38], [10], [26], [5], [-30], [40], [-24], [-21], [-24], [45], [9], [-33], [50], [15], [13], [-2], [-40], [8], [-8], [-42], [-2], [-66], [44], [11], [-42], [-52], [20], [-28], [36], [52], [-23], [-19], [-55], [23], [22], [32], [52], [50], [36], [-7], [-39], [-66], [-6], [38], [-53], [-46], [-11], [6], [42], [-60], [-15], [0], [60], [49], [4], [-44], [24], [-16], [-30], [29], [6], [-10], [2], [21], [-47], [10], [46], [28], [-28], [56], [-1], [42], [1], [-44], [-42], [49], [-39], [8], [2], [-67], [56], [-18], [-38], [-9], [-7], [34], [32], [-62], [75], [-15], [63], [34], [-62], [-38], [32], [26], [-6], [60], [17], [-8], [78], [49], [14], [9], [-52], [48], [23], [-55], [-28], [-16], [31], [52], [-72], [63], [30], [-64], [-51], [-30], [48], [59], [18], [38], [13], [12], [-9], [-29], [36], [-60], [-8], [-38], [34], [26], [-26], [-69], [-21], [78], [-77], [66], [33], [8], [10], [-14], [56], [-19], [33], [57], [-68], [-26], [-12], [-58], [-47], [-30], [26], [-19], [10], [-62], [78], [-40], [-79], [6], [64], [-18], [76], [58], [37], [48], [64], [9], [44], [5], [-34], [-36], [-71], [45], [82], [-11], [54], [50], [0], [-36], [26], [26], [24], [-3], [-40], [-52], [-19], [0], [-86], [-54], [33], [-63], [-87], [0], [-30], [-58], [12], [-24], [35], [-54], [-18], [-18], [-98], [0], [24], [69], [54], [-40], [-82], [-28], [-87], [69], [45], [62], [48], [-25], [-24], [-53], [46], [36], [-21], [77], [56], [-12], [68], [30], [37], [-92], [-96], [36], [2], [54], [40], [-3], [20], [-93], [94], [-12], [-90], [-55], [-46], [-102], [38], [-48], [10], [-95], [-44], [28], [-11], [-59], [0], [-10], [-17], [34], [18], [58], [105], [70], [-26], [-42], [-46], [15], [7], [-67]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1862_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1862_2_a_d();".
// 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_1862_2_a_d(:prec:=1)
    chi := MakeCharacter_1862_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_1862_2_a_d();".
// 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_1862_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1862_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![0, 1]>,<5,R![1, 1]>],Snew);
    return Vf;
end function;