
// Make newform 7744.2.a.bk in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7744_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_7744_2_a_bk();".
// 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_7744_2_a_bk();".
// 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_7744_a();"
function MakeCharacter_7744_a()
    N := 7744;
    order := 1;
    char_gens := [5567, 4357, 6657];
    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_7744_a_Hecke(Kf)
    return MakeCharacter_7744_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+1)]];
    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], [3], [3], [2], [0], [0], [6], [4], [1], [-8], [-7], [1], [-4], [6], [-8], [-2], [1], [4], [5], [3], [-16], [-2], [-2], [15], [-7], [-10], [-16], [2], [-14], [-7], [-4], [-2], [-15], [-22], [18], [18], [11], [4], [-16], [18], [5], [5], [-9], [-4], [6], [8], [20], [29], [18], [21], [16], [2], [0], [13], [-10], [-14], [-26], [0], [-2], [-6], [4], [12], [-4], [-12], [-9], [15], [35], [10], [-32], [-14], [3], [-24], [33], [-22], [-25], [1], [-13], [26], [-6], [-34], [28], [-30], [26], [13], [32], [9], [-21], [-12], [-28], [27], [33], [-8], [9], [8], [20], [30], [13], [37], [44], [12], [0], [42], [-12], [24], [-4], [-23], [-12], [4], [48], [-38], [18], [-16], [18], [3], [9], [-9], [-7], [15], [-11], [22], [7], [34], [-30], [-8], [29], [-10], [-19], [-23], [-35], [4], [-26], [36], [23], [-10], [0], [-16], [6], [24], [-1], [-12], [-26], [-34], [-31], [-16], [35], [21], [-26], [24], [-11], [-16], [56], [-19], [28], [34], [-28], [36], [50], [-22], [-4], [10], [-47], [34], [8], [-53], [-11], [25], [16], [2], [18], [21], [-30], [-38], [20], [-28], [-21], [49], [26], [-31], [-52], [44], [-32], [18], [39], [34], [-37], [-42], [-4], [-16], [-6], [-30], [1], [2], [1], [-14], [0], [-29], [-30], [61], [18], [58], [40], [-26], [-50], [16], [51], [51], [31], [60], [-24], [32], [32], [-15], [1], [4], [6], [15], [40], [-20], [-24], [29], [32], [40], [9], [-61], [16], [-6], [-42], [0], [-48], [48], [-21], [-64], [-50], [-56], [-59], [-70], [49], [24], [-21], [-5], [27], [0], [-28], [11], [8], [-52], [-12], [-12], [-42], [-38], [32], [42], [-9], [-2], [-58], [-36], [-54], [6], [51], [14], [12], [20], [46], [14], [78], [16], [-23], [-35], [-34], [-54], [3], [43], [-70], [-68], [-28], [37], [-45], [-6], [-8], [-24], [68], [-29], [72], [-82], [-52], [-69], [-70], [14], [-5], [70], [-33], [-12], [-76], [6], [-6], [-20], [-73], [-27], [22], [22], [-26], [52], [20], [-12], [-41], [-41], [-29], [-49], [68], [40], [80], [-6], [-30], [-27], [-48], [-34], [31], [-30], [50], [8], [-88], [17], [-38], [59], [18], [19], [15], [-5], [60], [36], [46], [-6], [-10], [-64], [24], [81], [-13], [12], [71], [34], [39], [39], [-56], [-11], [-31], [30], [-47], [55], [60], [53], [-40], [-37], [82], [60], [-70], [18], [75], [42], [-66], [-9], [22], [66], [45], [-18], [71], [93], [76], [-74], [-44], [-27], [40], [-2], [0], [30], [-17], [60], [42], [-14], [38], [-62], [-78], [23], [2], [62], [-56], [9], [-24], [-85], [36], [33], [77], [-59], [-3], [-85], [17], [-68], [-10], [-42], [-76], [-34], [-58], [-55], [32], [-18], [-12], [-66], [-86], [32], [-36], [83], [-66], [78], [-12], [98], [78], [3], [96], [-23], [-106], [-18], [53], [-16], [-56], [-74], [10], [-23], [-101], [-10], [23], [80]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7744_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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