
// Make newform 3344.2.a.m in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3344_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_3344_2_a_m();".
// 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_3344_2_a_m();".
// 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 := [-2, 0, 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_3344_a();"
function MakeCharacter_3344_a()
    N := 3344;
    order := 1;
    char_gens := [2927, 837, 2433, 705];
    v := [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_3344_a_Hecke(Kf)
    return MakeCharacter_3344_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, 0], [1, 1], [-1, 0], [0, -1], [-1, 0], [0, -1], [0, 1], [1, 0], [1, -4], [-4, -3], [1, -3], [-7, -1], [-4, 0], [6, 0], [-2, 6], [4, -2], [3, 3], [-2, -1], [-3, 9], [3, -3], [-8, 6], [-2, 9], [0, -11], [1, 1], [3, -1], [4, 7], [-8, 0], [-6, 8], [-14, 0], [1, -1], [0, -5], [-6, 2], [-9, -4], [8, -3], [10, -8], [2, 6], [-7, -4], [-14, -6], [-20, 3], [-6, 3], [7, -1], [-15, 1], [-11, 0], [0, 10], [-8, -1], [-10, 6], [8, -3], [3, -3], [14, -1], [5, -4], [2, 9], [-2, 4], [-8, -8], [-1, 8], [14, -6], [2, 10], [-2, -16], [12, 6], [10, 10], [2, 12], [-2, 3], [0, 11], [-4, 5], [-10, -8], [3, 16], [7, -3], [11, -7], [-14, 13], [26, 1], [-20, 11], [19, -8], [12, -10], [-7, 10], [-14, -8], [33, 1], [-13, -3], [15, 12], [-6, 8], [-10, 20], [2, 5], [-2, -22], [-2, 22], [18, 14], [-5, -21], [4, -19], [1, 8], [15, -19], [18, -13], [-4, 12], [-5, -14], [-15, -16], [22, -3], [-9, -7], [6, 9], [18, -4], [-2, 6], [23, 3], [-9, 5], [16, 0], [14, -13], [0, -21], [-2, -8], [12, -3], [-24, -3], [-6, -7], [-27, 0], [-18, 16], [-20, 0], [-26, -8], [-18, -21], [14, -1], [-2, -13], [20, 6], [-9, 10], [-17, -8], [-19, 17], [-5, -24], [-1, 16], [23, -2], [30, -6], [7, -17], [10, 2], [18, 16], [12, 2], [5, 28], [10, 16], [-17, 8], [-5, -16], [-11, -6], [34, -3], [-24, -13], [-8, 5], [-15, -1], [4, -4], [8, 2], [12, -18], [22, 20], [4, 12], [9, 7], [-24, -14], [-10, -15], [0, 13], [13, 8], [-16, -17], [-15, 25], [-33, -5], [26, 4], [-4, -33], [-41, -4], [-16, -8], [28, -2], [29, -6], [18, 18], [-22, 0], [0, -18], [32, -14], [4, -29], [8, -16], [-2, 5], [18, -25], [1, 8], [-26, 13], [-10, -13], [3, -11], [25, -15], [37, 13], [-20, 4], [4, 3], [-22, -18], [-27, -14], [30, 2], [-6, -12], [32, 20], [-32, -10], [-17, 23], [-11, -20], [14, 16], [-25, 8], [-4, -13], [6, 37], [-16, -4], [38, -18], [-43, 5], [-46, 10], [7, 6], [-44, 10], [0, -43], [36, -18], [-2, -39], [-18, 16], [33, 19], [36, 13], [-15, -17], [10, 22], [-24, 2], [-9, -25], [-46, -10], [-13, -20], [-4, -29], [34, 14], [0, 32], [-18, 20], [12, -26], [-16, 10], [-7, -12], [-41, 12], [-5, -4], [-32, -18], [-30, -5], [42, 12], [22, -5], [9, -14], [-17, 8], [12, 0], [14, -21], [-7, 5], [-34, -3], [-4, -35], [-8, -18], [3, 16], [-12, 38], [8, 14], [-41, 23], [5, 32], [-32, -4], [-18, 0], [-14, -28], [-8, -36], [-36, -10], [38, 9], [31, 18], [0, -26], [-30, 10], [28, 19], [21, 4], [46, -6], [7, 28], [-48, -12], [-25, 18], [-9, 17], [-33, 15], [-12, 2], [-50, 12], [13, 39], [12, 14], [60, 10], [-36, -20], [8, 30], [-54, -7], [28, -1], [-16, -40], [6, -30], [-1, 26], [-14, -34], [18, 2], [6, 27], [-52, -10], [2, 25], [-3, -15], [44, -7], [-8, -30], [16, -9], [-32, -25], [6, 8], [-36, -26], [-44, 2], [49, -15], [9, 22], [-34, 13], [-18, 18], [-39, 15], [9, 31], [8, -14], [4, 42], [-16, -7], [-9, 46], [-53, -8], [-6, -14], [-24, 0], [-46, 3], [40, -14], [-21, -18], [16, 8], [18, 24], [-50, 13], [11, -10], [2, -8], [70, 10], [-27, -32], [30, 21], [-17, 4], [-50, -18], [4, -16], [-34, -16], [18, -30], [4, 40], [-9, -45], [-39, -22], [-2, 37], [-6, -40], [-30, -6], [16, -13], [-26, 5], [52, 16], [29, -14], [-33, 29], [-9, -1], [13, 1], [-46, 16], [10, -27], [46, -9], [-48, 10], [-26, -12], [-39, -3], [60, -14], [-34, 24], [35, 2], [-62, 11], [62, -8], [40, 14], [-40, -25], [-5, 44], [54, -17], [49, -17], [-36, 35], [33, -33], [-17, -1], [-15, 25], [28, -45], [-72, -10], [32, -1], [20, -6], [22, -16], [54, -15], [14, 29], [1, -6], [-15, 39], [24, -18], [-1, 12], [-14, 4], [27, 17], [37, 28], [-20, 4], [63, -3], [11, -29], [26, 15], [-21, -34], [27, 39], [24, 18], [-63, 6], [84, 3], [9, 25], [16, 40], [0, -60], [18, 55], [30, -29], [-19, 38], [-22, -24], [-22, 0], [-11, -3], [-54, 0], [0, -13], [73, 1], [-10, 28], [-5, -4], [-25, -21], [30, -45], [14, 45], [-44, 20], [-25, 26], [60, 10], [32, 19], [-24, -50], [12, -7], [-65, 2], [-24, -20], [-2, -36], [40, 29], [-36, 3], [42, 36], [36, -18], [13, 32], [-8, 19], [-48, 1], [-12, -6], [81, 1], [18, -46], [-21, -22], [6, -11], [-11, -57], [-3, -29], [-19, 19], [-25, -50], [1, 2], [21, -19], [-16, -12], [-30, -8], [14, 38], [-32, -32], [16, -27], [-14, -2], [1, 42], [52, -2], [-8, 18], [4, -33], [6, 50], [52, -14], [4, 17], [58, 24], [-85, -6], [82, 12], [-4, -17], [-60, -4], [58, -24], [-24, -15], [-35, 14], [-4, 29], [63, -1], [56, -6], [18, -45], [29, 9], [-40, -32], [106, 0], [14, -24], [84, 14], [37, 9], [31, 7], [-18, -46], [-83, -12], [36, -18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3344_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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