
// Make newform 2205.2.a.q in Magma, downloaded from the LMFDB on 26 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2205_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_2205_2_a_q();".
// 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_2205_2_a_q();".
// 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_2205_a();"
function MakeCharacter_2205_a()
    N := 2205;
    order := 1;
    char_gens := [1226, 442, 1081];
    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_2205_a_Hecke(Kf)
    return MakeCharacter_2205_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 := [[-1, 1], [0, 0], [1, 0], [0, 0], [-2, -2], [2, -2], [2, -2], [0, 2], [1, 1], [1, 0], [6, 0], [0, 0], [-5, 2], [5, 1], [2, 0], [4, 2], [-4, -6], [3, 6], [11, 1], [4, 6], [-2, -2], [12, -2], [1, -9], [-3, 4], [-6, 4], [1, 8], [1, -1], [-7, 3], [-5, 6], [-4, -6], [2, 8], [-8, 8], [4, -4], [2, -10], [5, 2], [6, -4], [-6, 8], [18, 4], [21, -1], [-8, -8], [10, 0], [3, 4], [10, -2], [-2, 0], [18, 4], [4, -4], [12, -6], [-6, -4], [10, 12], [6, -4], [14, -2], [10, -8], [-22, 4], [2, 8], [12, 4], [5, -17], [-5, -18], [-8, 6], [2, -10], [2, -20], [-14, 0], [-16, 0], [9, 3], [-16, -2], [12, 4], [-6, -14], [6, -12], [12, 2], [-15, -5], [21, 4], [-24, 2], [10, 0], [7, 3], [-4, 12], [24, -2], [7, 7], [-18, 4], [-6, -16], [-19, 8], [-5, -14], [-12, -8], [5, -6], [2, 14], [12, 14], [0, -24], [-9, 15], [-1, 2], [-4, -20], [30, -8], [-13, 17], [-13, -7], [-30, 4], [10, 4], [2, 8], [2, 2], [11, 19], [19, 4], [-2, -12], [-30, 4], [13, 4], [15, -7], [6, 20], [29, -9], [-2, 4], [12, 2], [10, -24], [-6, 20], [24, 14], [-12, -4], [-14, 4], [-17, 15], [10, -18], [0, 8], [-34, -6], [-6, 10], [-23, 6], [2, 20], [-7, 17], [22, 2], [-24, -2], [-29, 2], [24, -4], [-14, 10], [39, 3], [2, 2], [23, 14], [27, 8], [-10, -22], [39, 1], [22, 0], [10, 22], [9, -5], [-36, -4], [-6, 18], [-2, -8], [-22, -16], [-6, 22], [13, 11], [-8, 0], [-13, 16], [-2, -16], [-14, 24], [-5, -5], [5, -15], [-18, 8], [18, 2], [-28, -18], [6, -20], [-24, -16], [1, 11], [28, 2], [-1, -2], [-10, -20], [37, 5], [7, 15], [30, 14], [-12, 22], [-3, -6], [-12, 16], [-18, 20], [5, 27], [8, -4], [5, -23], [-24, 0], [-10, -8], [7, -15], [-10, -4], [-8, 18], [-11, -8], [20, -6], [-4, -4], [-29, -4], [14, -8], [24, 18], [18, 4], [5, -36], [44, 2], [2, 0], [-23, 21], [13, -22], [-3, 15], [-26, 8], [-26, 16], [-38, 8], [2, 28], [15, 24], [-32, 0], [-34, 20], [9, -18], [-6, 18], [28, 12], [-18, 4], [-6, 26], [5, -10], [18, 20], [-18, -24], [27, 18], [14, -8], [-36, -6], [-10, -28], [1, -8], [34, 20], [-16, 34], [19, 16], [18, 8], [4, 18], [-8, 18], [10, -20], [3, 36], [8, -36], [-12, 2], [5, 42], [-37, 1], [-17, -1], [2, -2], [18, -8], [1, 7], [-17, -16], [6, 28], [-40, -4], [9, 10], [46, -18], [47, 4], [-14, 24], [-21, -1], [-9, -10], [56, 0], [-6, -26], [-41, -3], [-2, -32], [-38, -14], [40, 10], [2, -10], [29, -14], [-45, -21], [-11, -31], [-17, 10], [-10, -46], [-32, 18], [2, 26], [18, -4], [-4, 36], [18, -32], [-21, 4], [-32, 20], [-38, 18], [-13, 11], [-22, -12], [20, -20], [-6, 12], [-16, 8], [11, -8], [15, -29], [19, -6], [46, -2], [-20, 42], [-15, -32], [45, 9], [-30, -24], [4, -10], [23, 5], [41, 15], [6, -24], [2, -26], [-16, 4], [-30, 18], [26, 0], [-18, 16], [41, 5], [-12, 8], [-1, -20], [26, -32], [4, -22], [0, -36], [-34, -32], [-6, 16], [22, 0], [-53, 8], [-21, -30], [-60, 10], [63, 7], [-4, 32], [50, 0], [27, 8], [25, 17], [-32, 0], [-24, 22], [-16, -8], [-2, 24], [34, -16], [-25, -14], [-57, -3], [18, 2], [6, -46], [-28, -26], [-9, -6], [-4, 10], [40, -14], [-42, -2], [22, 20], [34, -2], [28, -6], [18, 18], [19, -1], [-22, -44], [-42, -6], [-58, 16], [13, 12], [-42, -20], [-50, -10], [-17, 21], [-14, -8], [-47, 16], [-7, -31], [-45, -19], [7, 4], [-16, 32], [-24, -2], [22, 12], [19, 22], [6, 36], [-58, -10], [-11, -6], [7, 23], [50, -22], [-47, 14], [10, 12], [-25, -27], [6, -24], [-8, 42], [-26, 16], [48, -20], [-16, -30], [-23, 9], [-18, -6], [31, -11], [-18, -24], [10, -12], [-39, 18], [-78, 0], [48, 12], [-24, -44], [-13, 54], [0, 10], [-14, -20], [-32, 6], [31, 14], [51, 1], [2, -24], [-4, 12], [-22, -6], [18, 14], [55, -14], [-3, 23], [-37, -4], [32, 24], [-70, 12], [66, 6], [66, 2], [-7, -27], [12, -30], [-66, -20], [-49, -19], [8, -60], [13, -47], [-6, 26], [18, -18], [26, -40], [55, 10], [48, -10], [-22, -4], [13, -17], [-26, -52], [-44, 20], [-14, 26], [68, 10], [-42, 30], [-14, -10], [62, 24], [4, -10], [-7, -28], [14, 10], [21, -1], [-24, 52], [-26, 4], [-9, 45], [-22, -22], [24, -44], [29, -39], [5, -25], [14, 40], [24, 20], [62, -16], [-2, -20], [-62, 6], [-20, -58], [12, -30], [29, 16], [-20, -28], [-49, 22], [41, 10], [-22, 48], [-15, -19], [-36, -20], [-21, -22], [-48, 10], [28, 4], [-35, -32], [35, 27], [54, -24], [-4, -26], [-10, 32], [-54, 0], [68, 20], [-50, -24], [6, 28], [-74, -6], [-74, -8], [-50, 12], [-33, 13], [9, 26], [-28, 40], [27, -9], [-66, -4], [-74, 12], [-6, -8], [74, -8], [51, 6], [56, 24], [26, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2205_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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