
// Make newform 2005.2.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2005_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_2005_2_a_c();".
// 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_2005_2_a_c();".
// 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, -3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_2005_a();"
function MakeCharacter_2005_a()
    N := 2005;
    order := 1;
    char_gens := [402, 1206];
    v := [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_2005_a_Hecke(Kf)
    return MakeCharacter_2005_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], [-1, -2, 1], [1, 0, 0], [-1, 1, -3], [0, -1, 2], [-1, 3, -2], [-2, 2, 1], [3, 0, 0], [-3, -1, 2], [0, -4, 1], [2, -1, 3], [5, 0, 3], [-6, 3, -2], [-2, 3, -3], [0, -5, 2], [-5, 0, -1], [-2, 6, -1], [-1, -1, -4], [-9, -4, 2], [0, 5, -7], [1, 1, -4], [1, 10, -4], [-13, 1, -2], [-1, 5, -7], [-4, -1, 7], [-2, 4, 0], [-3, -7, -1], [3, -1, 5], [3, 1, 3], [-3, 2, -4], [-7, -6, 5], [-7, -8, 4], [4, 3, 3], [-2, -11, 10], [5, 12, -8], [-1, -7, -2], [-6, 3, 3], [9, -7, 3], [1, -4, 4], [-7, -6, 7], [-9, 5, -3], [-13, 7, 4], [-11, 1, -1], [-4, -2, -8], [2, 8, -11], [4, 9, -1], [12, -4, 4], [8, 4, 4], [-12, -10, 10], [2, -5, 1], [7, 1, 8], [0, -15, 0], [24, -1, -3], [1, 18, -13], [11, -3, 3], [-5, 5, -9], [-5, -5, -10], [3, -6, 4], [-2, -10, -4], [-6, 1, -3], [-14, -3, 1], [5, -9, 1], [0, -8, 17], [-1, -17, 12], [-2, 9, -7], [-5, -14, 14], [-24, -8, 5], [4, -17, 11], [-22, 6, 3], [24, -2, 2], [5, 10, 3], [5, 3, -4], [9, 13, 3], [-5, -6, -7], [5, -3, 9], [-3, 6, 0], [15, -6, 16], [4, 9, 0], [1, 0, 0], [-18, 2, -1], [-10, 12, 4], [-19, -4, -6], [-7, 4, 16], [-18, 3, -10], [10, -10, 26], [-9, 1, 0], [-15, 2, -14], [0, -11, 3], [13, -3, 2], [2, 2, 8], [5, -12, 8], [-1, -11, 2], [-17, -24, 14], [3, -5, -11], [-3, -8, 2], [-16, 9, 5], [-3, -21, 7], [0, -5, 13], [-2, -2, -8], [-10, 12, -30], [15, 29, -22], [-11, -17, 11], [15, -11, 8], [-3, -13, -3], [1, -2, -5], [19, -1, -9], [-20, -13, 13], [-22, 2, -5], [-23, 3, 7], [27, 7, 2], [-1, 15, -22], [12, -13, 25], [-9, 5, -12], [-1, -8, -1], [-4, 20, -3], [3, 2, -20], [14, 11, -18], [8, 1, 3], [-7, -16, 12], [-17, 0, -20], [-8, -25, 23], [1, 18, -26], [4, 12, 1], [-6, -4, -10], [4, -9, -1], [-6, 11, 17], [22, 1, 16], [27, 7, -11], [-20, -20, 19], [3, -9, -8], [-17, -9, -5], [-35, 0, 5], [-12, 21, -24], [11, 7, 2], [5, -22, 13], [25, -9, -12], [-5, 1, -1], [-18, 22, 12], [8, -9, -19], [3, 10, -23], [-15, 8, -13], [-32, 1, -10], [12, -8, 21], [-7, 27, -12], [9, -14, -17], [31, -14, -7], [-24, 1, 8], [0, -13, 19], [-37, 4, 4], [17, 23, -24], [-1, -19, 18], [-17, -18, 18], [1, -20, 22], [41, 2, -5], [-16, 18, 4], [14, 12, -2], [37, 8, -4], [-16, 14, -3], [0, 21, -17], [4, 15, -19], [15, -17, 20], [1, 12, -20], [-21, 5, -24], [23, 9, 1], [7, -25, 4], [13, -7, 8], [34, 19, -5], [1, 2, 4], [28, 14, -20], [6, 9, 14], [30, 2, 4], [0, -9, 29], [3, 20, -1], [10, -10, -16], [24, 25, -22], [-19, -22, 3], [2, 5, 30], [-31, -16, 6], [-5, 33, -6], [9, 2, -9], [-1, 17, 2], [-3, -21, -11], [8, 2, 1], [21, -4, -7], [3, 2, 18], [21, -7, -9], [-13, -5, -3], [21, -9, -8], [-29, 20, -16], [-24, 2, -25], [23, -6, 0], [-23, 15, -23], [14, 8, 11], [-41, 5, -9], [-25, 7, -20], [30, 13, -15], [-1, 23, -7], [8, -33, -4], [42, 2, 8], [-40, 11, -5], [18, 32, -28], [-36, 5, 10], [15, -15, 13], [37, 17, -4], [-10, 3, 14], [-7, 22, 17], [1, 1, 5], [-35, 18, -1], [8, 18, -8], [-23, 8, 21], [11, 30, -10], [-5, -6, 8], [-17, 7, 18], [-40, 18, 5], [45, 5, -1], [32, -16, 0], [-22, 8, -15], [-3, 22, -41], [27, -13, -4], [1, 3, 23], [4, -28, 35], [4, -3, -10], [-38, 24, 13], [-26, 29, 18], [40, 16, -18], [1, -21, 44], [14, 23, -26], [7, 22, -29], [28, -13, 33], [8, -6, -18], [-13, 5, -27], [-45, 0, 10], [38, 7, -14], [23, 8, -2], [20, -14, -14], [6, 27, -3], [-3, -26, 17], [-30, 10, 7], [-40, -1, -17], [44, 15, -5], [-17, 10, 7], [16, 5, 2], [-38, -3, 2], [-27, 17, -30], [18, 9, -8], [20, 6, 2], [11, 0, 19], [-8, -22, 27], [25, -21, 8], [-44, 12, -11], [34, 23, -5], [21, -18, -6], [-10, 14, -19], [33, 24, -11], [8, -19, -3], [-30, 0, -31], [59, -6, 19], [3, 5, -23], [14, -16, 0], [26, 11, -10], [-31, 26, 5], [20, -25, 29], [-13, -7, -6], [32, -6, -18], [10, -12, 24], [-46, -4, -6], [-58, 0, -8], [6, -11, -17], [3, -21, 23], [-2, -30, 2], [2, -35, 26], [15, -7, 11], [-28, 11, -35], [4, -17, -26], [-29, 19, -15], [-41, 10, -2], [-11, 20, -12], [28, -15, -9], [18, 0, -13], [-19, -15, 22], [22, 5, 19], [50, -9, 30], [2, 18, -24], [-30, -11, 17], [-7, -6, -28], [2, -12, -19], [9, 24, -9], [-1, -4, 34], [45, -16, 6], [50, -2, 1], [5, -22, 15], [-26, -2, 14], [-40, 21, 0], [39, 23, -21], [14, -14, -14], [-27, 11, -31], [37, -2, -9], [22, -6, 7], [21, -36, -17], [51, -11, 14], [11, -11, 17], [-11, -5, -13], [24, 0, -25], [1, 6, 19], [12, -23, -10], [-25, -6, -9], [53, 6, 13], [12, 23, -42], [-39, -7, 5], [22, -13, 16], [6, -6, -12], [2, -16, 24], [13, -2, 2], [54, 6, -1], [-9, 2, -49], [19, -9, 41], [-9, 36, -51], [-83, 3, -5], [-23, 12, 11], [-29, 7, -4], [-7, 14, -4], [0, 16, 21], [-57, 15, -8], [-28, 9, 3], [-22, -3, 11], [20, 44, -10], [-45, -23, 12], [29, -34, -22], [-25, 6, -36], [29, -28, 15], [1, -16, 32], [34, -8, 16], [3, 18, 2], [-24, -1, -34], [-16, 31, -41], [-30, 7, -8], [-42, -8, 28], [31, 31, -12], [-17, 30, -4], [20, 3, 21], [34, 22, -6], [-4, 21, -31], [13, -48, -6], [2, -40, 22], [3, -28, 23], [3, -9, 20], [-16, -5, 22], [-34, -5, -11], [7, 12, -20], [-19, 4, -37], [28, -6, 50], [-3, 25, -36], [1, 11, 28], [-39, -11, 3], [19, 22, 4], [-28, -29, 38], [-31, 4, 25], [-1, 5, -2], [-39, 11, -19], [-15, 41, 3], [-36, -5, 2], [-1, 22, 11], [-23, 31, 10], [-11, 1, 30], [-47, 8, 0], [-6, -12, 34], [18, 20, 21], [-28, 26, -30], [1, -14, -3], [11, -10, -23], [48, -3, -13], [-11, 22, -1], [10, -18, -38], [-10, -42, -4], [-41, 22, 1], [-25, -15, -9], [-2, 31, -38], [12, -35, 60], [-11, -18, 34], [-3, -13, 31], [16, -35, 8], [16, -18, 13], [-16, 2, -15], [-12, -8, 29], [-22, -16, 8], [7, -18, -17], [19, 32, 7], [-10, -6, 24], [-3, -9, 39], [51, -1, 6], [-25, -13, 17], [-16, -60, 47], [-1, -9, -28], [52, -22, 23], [36, -10, -20], [2, 41, -45], [14, 28, 19], [26, 42, -28], [36, -6, 12], [-12, -1, -51], [-9, -9, -16], [29, -25, -29], [16, -7, 39], [5, -10, 51], [39, 0, -13], [6, -44, -4], [-17, -63, 34], [31, 26, -1], [42, 30, -18], [-17, -18, 22], [-76, 5, -10], [0, 44, -9], [16, 0, 23], [50, -22, 7], [17, 31, -12], [-52, 26, -4], [-11, -62, 26], [1, 2, -34], [-4, -49, 10], [31, 25, -18], [79, 6, 0], [-50, 25, -1], [-7, -35, -3], [-20, -55, 30], [33, 18, 8], [1, 21, 10], [-56, -32, 25], [-5, 31, -12], [-17, 11, -37], [11, 2, 55]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2005_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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