
// Make newform 7581.2.a.h in Magma, downloaded from the LMFDB on 16 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_7581_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_7581_2_a_h();".
// 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_7581_2_a_h();".
// 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_7581_a();"
function MakeCharacter_7581_a()
    N := 7581;
    order := 1;
    char_gens := [2528, 6499, 1807];
    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_7581_a_Hecke( : Kf := Kf)
    return MakeCharacter_7581_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 := [[0, -1], [1, 0], [-3, 2], [-1, 0], [-2, -2], [0, 2], [6, 0], [0, 0], [1, 0], [-4, 2], [-1, -1], [3, 2], [1, -4], [-5, 2], [3, -8], [6, 1], [-11, 4], [12, -1], [-9, -4], [11, -8], [-11, 2], [-4, -2], [-7, 5], [-5, 8], [7, -6], [14, 3], [9, -3], [-6, 1], [-5, -2], [13, 3], [1, -2], [-7, 7], [5, -5], [4, 7], [5, -15], [-19, -1], [-17, 9], [16, 1], [-10, -2], [-6, -5], [-21, -1], [12, -12], [-3, 12], [-11, 19], [-3, -6], [-18, 1], [-15, 5], [-13, -2], [-16, 21], [-11, 0], [3, 2], [-1, 17], [15, -17], [16, 7], [14, -16], [18, -17], [27, 3], [2, -17], [7, 4], [12, -4], [-17, -8], [-11, 5], [6, -17], [-2, 5], [-18, 16], [-12, -14], [-14, 21], [-18, -6], [0, -6], [7, -10], [13, -24], [-14, 14], [-23, -6], [-17, 15], [-13, 8], [-11, 8], [25, -16], [-14, -1], [-21, 21], [15, -18], [7, -22], [9, -13], [-2, -13], [-2, 20], [19, -16], [5, 12], [14, -11], [-12, -8], [-3, 9], [-6, -4], [-4, 7], [-22, -2], [-4, 3], [17, -4], [-21, 17], [22, -13], [-6, 0], [10, -16], [-13, 21], [-9, 24], [-10, -18], [-13, 22], [4, -20], [-9, 28], [1, 21], [-11, -4], [-5, 29], [19, -25], [7, 19], [-7, -24], [11, -26], [-6, -25], [-6, 9], [-3, 9], [27, -8], [-30, 16], [35, -20], [7, -11], [-2, 21], [-3, -17], [-1, -24], [10, 5], [-3, -3], [-17, 10], [19, -13], [6, -25], [5, -18], [-36, 17], [-28, -12], [-7, -1], [36, -18], [20, 2], [-14, 4], [-24, 16], [5, 16], [35, -5], [8, 6], [-26, -4], [-3, -4], [7, -15], [-23, 8], [2, 16], [-8, -12], [-32, 8], [-2, -13], [5, -24], [4, 4], [16, -20], [-17, -16], [-17, -5], [-22, -21], [-18, -6], [-43, 8], [-3, 3], [31, -18], [-9, 12], [2, -13], [11, 11], [-51, 6], [-40, 20], [15, 24], [-25, 0], [-5, 40], [23, -24], [22, -39], [-15, 3], [12, 21], [-12, -25], [-46, 12], [12, 8], [-19, -12], [-7, 7], [-8, -14], [-7, 36], [-30, 45], [-23, -18], [1, 13], [-19, -13], [56, 0], [-30, -9], [11, -4], [3, 9], [12, 19], [10, 9], [9, -19], [-2, -30], [-26, 44], [-56, 13], [-30, 40], [-21, 14], [1, -11], [-20, 22], [2, 36], [-23, 3], [-17, -12], [-21, -15], [34, -14], [-15, 18], [7, -10], [31, 13], [-25, 20], [6, -18], [-1, 5], [19, 4], [42, 10], [61, -8], [-21, 16], [-22, -11], [19, -12], [-12, 2], [33, -16], [24, -14], [20, 6], [-2, 33], [-21, 45], [-43, 46], [-43, -8], [-13, 26], [26, -6], [37, -2], [13, -52], [-28, 36], [-17, -6], [-38, 15], [54, 6], [1, 28], [6, -41], [-11, 6], [37, 10], [29, -5], [2, -34], [-16, 15], [-3, 10], [-54, 25], [-24, 6], [31, -12], [-5, -8], [-57, 17], [3, -38], [20, -3], [-28, 20], [22, -45], [-22, -10], [-21, 48], [-47, 19], [45, -32], [-23, 55], [-32, 19], [16, -55], [-34, 47], [28, 0], [-44, -21], [-31, 33], [-29, 58], [-4, 36], [35, -2], [-19, 57], [-5, 26], [9, -6], [37, 5], [26, -34], [14, 21], [-11, 55], [7, -36], [-6, 37], [-33, 34], [-1, -15], [1, -23], [23, -26], [16, -24], [13, -37], [-9, -3], [6, -26], [39, -14], [-56, 36], [-14, 39], [-54, 26], [-30, 0], [40, -32], [39, 26], [44, -7], [75, -3], [47, 18], [18, 12], [10, -1], [4, 28], [-56, 7], [-7, 18], [20, 40], [-38, 69], [-8, -18], [-62, 7], [-16, -1], [-36, -8], [-35, 40], [-32, 33], [-27, 14], [16, 8], [32, -42], [68, -28], [53, -4], [-24, -16], [35, -7], [-20, 4], [17, 37], [-61, 18], [-40, -13], [60, -39], [29, -18], [-12, 3], [69, 2], [-14, 45], [-22, -30], [-26, 67], [15, -21], [-6, -21], [36, -39], [32, -28], [-17, 21], [-1, 39], [43, 30], [-30, 67], [33, -76], [42, 3], [46, 27], [-7, -36], [-31, 4], [-1, 20], [56, -4], [40, 3], [30, 22], [-13, 5], [35, 10], [53, -27], [38, 16], [0, 6], [11, 30], [-11, -17], [72, 0], [-19, 38], [-16, 30], [28, 24], [52, -13], [17, 25], [19, -56], [36, -44], [-49, 25], [54, 14], [34, -5], [22, 14], [-15, -18], [9, -7], [-35, -2], [-70, 29], [-46, 24], [-30, -39], [13, 19], [-24, 8], [31, -23], [-45, 43], [3, 3], [45, -31], [-48, 41], [-1, -48], [-9, -37], [8, -28], [39, 24], [-55, 23], [5, -57], [18, -59], [-57, 50], [2, 0], [35, -78], [26, -11], [-1, -22], [3, 2], [18, -26], [-23, 64], [29, 12], [-28, -25], [1, -22], [-33, -20], [40, -36], [-59, 24], [-25, 41], [-21, 39], [-10, 3], [-73, 22], [41, -47], [-4, 16], [-33, -33], [1, -7], [16, -12], [-21, -46], [-23, -32], [62, 6], [-67, 4], [62, -42], [26, 35], [11, -45], [30, -41], [-4, -16], [19, -54], [68, -30], [-58, 26], [-15, -3], [55, -23], [-22, -1], [-18, 7], [-12, 37], [-7, 58], [-37, 60], [35, 9], [8, -14], [38, -7], [-37, 20], [-50, -13], [60, 16], [33, 9], [47, -34], [17, -21], [13, 29], [-59, 0], [33, -9], [21, -42], [59, 18], [-89, 14], [12, 42], [13, 4], [48, -8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7581_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7581_2_a_h();".
// 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_7581_2_a_h(:prec:=2)
    chi := MakeCharacter_7581_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_7581_2_a_h();".
// 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_7581_2_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7581_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1, 1]>,<5,R![-1, 4, 1]>],Snew);
    return Vf;
end function;