
// Make newform 1805.2.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1805_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_1805_2_a_e();".
// 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_1805_2_a_e();".
// 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, -1, 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_1805_a();"
function MakeCharacter_1805_a()
    N := 1805;
    order := 1;
    char_gens := [362, 1446];
    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_1805_a_Hecke(Kf)
    return MakeCharacter_1805_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], [1, 1], [-1, 0], [-3, 2], [-3, -1], [5, 0], [-6, 0], [0, 0], [0, -1], [3, -3], [9, -3], [3, -3], [-5, 10], [2, -3], [-7, -2], [4, 1], [-8, 5], [-3, 0], [5, -6], [7, -2], [-1, 0], [8, 0], [-2, 4], [3, -6], [-2, 5], [1, -8], [6, 7], [3, 0], [3, 2], [-10, 8], [7, -6], [-6, 3], [-5, -10], [10, 3], [-7, 1], [-8, -1], [-16, 13], [11, 4], [7, -2], [4, -16], [13, 4], [12, 6], [11, 8], [4, 0], [19, 4], [6, -12], [-10, -5], [9, -2], [9, -14], [-21, 1], [-13, -10], [18, -9], [7, -18], [9, -10], [16, 4], [-10, 16], [6, 7], [17, 1], [-18, 12], [17, -17], [4, -1], [14, -13], [-3, 15], [-12, -8], [-3, 11], [-12, 2], [-4, -6], [28, 0], [-10, 16], [10, -19], [-17, 31], [27, 1], [-7, -14], [-3, 6], [-12, 24], [15, -29], [-20, 7], [-7, 16], [8, 2], [2, 6], [6, 8], [15, -18], [-19, 10], [-15, 23], [1, -4], [-17, 20], [39, -4], [-6, 0], [-6, -8], [25, -13], [-21, 6], [-10, 1], [-28, 12], [13, 7], [18, -14], [-7, -8], [4, -11], [-1, -1], [-3, -22], [19, -22], [25, -21], [-19, 4], [-24, 10], [-6, -9], [25, -3], [21, 2], [-41, 2], [-7, 14], [-5, -20], [22, 0], [-11, 9], [9, 8], [-16, -5], [-13, -8], [15, 0], [15, 15], [18, -22], [19, -28], [6, -3], [40, -4], [0, 6], [-21, -16], [-9, -1], [21, -4], [19, -4], [22, -43], [-12, 6], [19, 11], [-18, -12], [-1, -2], [-7, 24], [35, -2], [3, 9], [-15, -1], [25, -20], [-3, -27], [-28, 19], [-12, 38], [4, 10], [32, 5], [36, -7], [13, 1], [-4, -20], [-21, 24], [23, -33], [-14, -1], [27, -42], [-32, 1], [0, -22], [4, 14], [-14, -10], [17, -13], [29, -29], [10, -4], [-10, 36], [12, -39], [13, -16], [11, -1], [-3, -9], [0, -17], [48, 0], [3, 24], [30, 2], [-31, 11], [45, -14], [12, -3], [20, 3], [-2, 2], [-34, 36], [-12, -19], [12, 6], [-15, 28], [43, -32], [-18, -18], [20, 12], [-33, 13], [-23, 20], [-20, 46], [30, 7], [-33, 26], [-25, 30], [-12, -22], [-19, 36], [6, -5], [-19, -22], [3, 10], [-33, 30], [25, -40], [-21, 6], [-34, 5], [20, -23], [-12, 9], [1, 18], [-19, 5], [0, -30], [24, -23], [-30, 21], [15, -30], [11, 2], [-36, 28], [54, -5], [-34, 10], [-9, 12], [22, -33], [-24, 24], [7, -29], [-13, 42], [47, -2], [21, 24], [27, -21], [7, -9], [-16, 4], [-48, 16], [-16, 7], [-23, 29], [-12, 0], [12, -42], [23, 7], [55, -5], [-45, 20], [-2, 23], [20, 15], [-14, -32], [5, 19], [-38, 19], [-42, 39], [-52, 14], [-5, -25], [19, -30], [33, -33], [6, 5], [61, 0], [42, -3], [9, 33], [-13, 4], [-19, -28], [-50, 0], [19, -25], [11, -13], [14, -49], [22, -7], [13, 8], [45, -23], [10, -28], [-24, 0], [-21, 57], [44, -27], [2, -25], [22, -42], [-21, 39], [-27, -13], [-30, 35], [16, -56], [-27, -28], [-53, -7], [9, -33], [16, 0], [47, 12], [53, -26], [-1, -33], [-40, 3], [-11, 34], [2, -21], [-15, -30], [3, -14], [-11, 30], [20, -4], [-31, 28], [-43, 27], [-33, -18], [31, -54], [-38, -10], [-33, 42], [27, -47], [18, -2], [-21, -27], [-51, 20], [-30, -9], [-14, 60], [-8, -5], [1, -19], [-21, 30], [7, -19], [31, 2], [31, 11], [0, -36], [-60, 28], [31, -56], [-39, 26], [21, -25], [46, -17], [-15, 11], [35, 5], [-29, -14], [33, -36], [-41, 31], [-9, -3], [-42, 6], [41, -4], [54, -26], [-30, 24], [-51, 42], [9, 39], [-3, -3], [7, 20], [-18, -25], [39, -24], [-8, -46], [-14, 23], [-25, -6], [-31, 10], [-19, 17], [23, -40], [-34, -23], [3, 15], [-18, 51], [-20, 13], [-1, 23], [12, -11], [-39, 14], [5, 30], [30, -18], [62, -4], [-1, -26], [-21, 51], [37, 8], [-10, 18], [5, 27], [-25, -19], [30, -12], [-12, -19], [-12, 15], [-78, 0], [51, -24], [9, 11], [-18, -2], [-56, 30], [21, 15], [-16, -6], [-47, -3], [-32, 12], [10, 1], [43, -56], [-54, 48], [-48, 39], [21, 9], [-72, -5], [-6, 13], [-39, -16], [51, -6], [15, 10], [17, -51], [31, -13], [-25, 15], [-42, 1], [19, -32], [-33, 1], [52, 16], [-41, 4], [20, -49], [71, -11], [-36, 6], [-52, 8], [6, 17], [21, -36], [-17, 24], [54, -51], [42, -28], [46, -46], [38, -32], [42, -78], [22, 34], [-41, 14], [24, 27], [23, -33], [54, -19], [-12, 34], [-24, 54], [-46, 68], [41, -44], [-61, 50], [77, -20], [77, 6], [6, 34], [36, -24], [68, -53], [-23, -13], [1, 20], [33, 2], [-12, 68], [-16, 43], [5, 46], [-27, -11], [-71, -16], [-9, -3], [-14, -40], [8, 33], [-19, -37], [-42, 83], [56, 4], [39, 18], [-49, 25], [78, -20], [-69, 2], [-6, 42], [10, 24], [22, 6], [9, -38], [-45, -12], [68, -26], [55, -12], [2, -53], [-9, 10], [3, -15], [3, -2], [59, -14], [56, -38], [49, -12], [12, 27], [-76, 19], [-3, -4], [-10, 36], [16, -7], [13, 52], [76, 6], [15, -75], [33, -6], [65, -7], [-65, 15], [25, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1805_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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