
// Make newform 5544.2.a.x in Magma, downloaded from the LMFDB on 06 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5544_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_5544_2_a_x();".
// 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_5544_2_a_x();".
// 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_5544_a();"
function MakeCharacter_5544_a()
    N := 5544;
    order := 1;
    char_gens := [4159, 2773, 4313, 1585, 2521];
    v := [1, 1, 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_5544_a_Hecke(Kf)
    return MakeCharacter_5544_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], [0], [3], [1], [-1], [-1], [2], [7], [4], [-7], [2], [1], [12], [-12], [9], [-12], [-3], [10], [-7], [12], [-15], [12], [18], [10], [-4], [6], [-10], [-3], [-10], [6], [-2], [20], [-18], [0], [5], [6], [-8], [9], [24], [-12], [0], [20], [6], [24], [-14], [-12], [-22], [-10], [18], [0], [10], [-9], [-5], [-5], [-13], [-15], [-18], [3], [-20], [-11], [7], [16], [12], [-8], [26], [16], [16], [-12], [8], [-13], [25], [20], [22], [-14], [-33], [-24], [0], [18], [-8], [10], [35], [7], [-31], [16], [19], [0], [0], [-8], [-8], [9], [-23], [18], [-24], [37], [15], [40], [22], [11], [9], [-40], [12], [-11], [-40], [-42], [4], [-30], [-41], [-36], [12], [21], [35], [34], [42], [-22], [-20], [18], [-12], [27], [8], [-15], [0], [-8], [18], [6], [-46], [-6], [11], [-1], [-32], [2], [16], [1], [-23], [-23], [-28], [11], [-25], [-15], [1], [25], [1], [3], [-23], [-27], [-40], [-47], [6], [-6], [-20], [-36], [-8], [3], [-49], [18], [-28], [10], [56], [-31], [-50], [-40], [50], [-23], [-58], [-17], [-48], [32], [-7], [22], [-22], [-29], [-11], [50], [32], [-26], [-50], [6], [12], [6], [49], [29], [1], [0], [-38], [8], [-52], [-45], [44], [-54], [-38], [34], [-46], [-29], [41], [1], [-11], [-7], [54], [50], [0], [0], [-34], [25], [-48], [-19], [20], [-18], [-12], [-9], [54], [60], [-46], [-35], [19], [0], [14], [14], [40], [10], [42], [-34], [6], [-31], [-32], [-61], [-28], [58], [-31], [-6], [17], [-41], [38], [29], [34], [-23], [16], [-18], [22], [9], [-30], [13], [-32], [-68], [-26], [-46], [-36], [-64], [-4], [21], [-28], [9], [62], [60], [30], [26], [54], [-20], [53], [1], [-59], [-63], [6], [-60], [38], [-11], [-51], [-30], [-66], [43], [24], [-74], [-32], [-23], [64], [-62], [5], [-70], [-12], [50], [58], [-64], [4], [24], [78], [-23], [35], [0], [-5], [-10], [34], [-78], [-42], [-56], [-31], [-36], [20], [-24], [30], [30], [-60], [55], [3], [7], [-80], [32], [-51], [-53], [52], [40], [36], [44], [6], [68], [89], [-28], [-56], [-70], [-36], [-48], [68], [54], [-9], [-25], [-30], [-16], [23], [52], [-68], [-16], [-5], [-19], [16], [48], [-49], [54], [-80], [9], [-1], [-76], [58], [64], [-38], [-6], [86], [-13], [-34], [-35], [-6], [-72], [-20], [90], [4], [-27], [-24], [39], [-70], [-26], [-11], [32], [57], [48], [-60], [0], [-60], [45], [76], [-17], [38], [2], [78], [-78], [-2], [75], [95], [32], [47], [-33], [-25], [41], [54], [22], [-39], [-24], [-54], [-23], [-60], [81], [49], [-58], [-78], [75], [5], [26], [36], [52], [-6], [66], [31], [-19], [-32], [53], [-37], [-74], [-10], [-82], [0], [25], [-57], [70], [10], [0], [-82], [54], [0], [-56], [90], [-57], [-91], [38], [58], [78], [90], [79], [-42], [-74], [26], [-13], [14], [69], [22], [20]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5544_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5544_2_a_x();".
// 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_5544_2_a_x(:prec:=1)
    chi := MakeCharacter_5544_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_5544_2_a_x();".
// 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_5544_2_a_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5544_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-3, 1]>,<13,R![1, 1]>,<17,R![-2, 1]>],Snew);
    return Vf;
end function;