
// Make newform 1805.2.a.h in Magma, downloaded from the LMFDB on 25 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_h();".
// 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_h();".
// 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 := [7, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, 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_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], [0, 0, 1], [-1, 0, 0], [1, 0, -1], [-2, 0, 1], [-5, 0, 0], [-1, 3, 1], [0, 0, 0], [0, 3, 1], [-1, 0, 1], [-1, 1, 1], [-1, -2, 3], [1, -2, -3], [-2, 3, 2], [3, -2, -1], [3, -1, 3], [3, -2, -1], [-1, -4, -2], [-6, -2, 0], [-10, -1, 2], [-6, -3, -1], [-10, 4, 2], [1, -3, -3], [-6, 4, 0], [4, -4, -1], [1, -1, -5], [2, 5, -1], [4, -3, 1], [2, -1, -6], [0, 6, -1], [8, -6, -6], [1, 0, 5], [-6, 5, 0], [-1, 2, 0], [-2, 1, -1], [-15, 4, 4], [5, -1, 0], [7, -5, 1], [9, 0, 1], [1, 0, -3], [-14, 1, -1], [7, -8, -6], [-2, -6, -6], [-9, -3, -1], [11, -6, -5], [4, -3, 0], [-8, 0, -4], [-4, 6, 9], [4, 0, 0], [2, -2, 5], [13, -9, -10], [9, 7, -1], [-14, 2, 4], [0, -8, -1], [10, -2, -3], [10, -4, -6], [5, 6, 8], [-4, 1, 1], [8, -2, -10], [7, -3, -4], [3, 5, 2], [6, 3, -1], [12, 0, -5], [-5, 6, 5], [-28, 7, 5], [-4, 1, -2], [0, 2, 5], [-12, -2, -8], [4, -7, -4], [-5, 1, 6], [-19, -1, -3], [-17, 11, 3], [7, 2, 12], [-4, 7, 0], [-16, 5, 4], [4, 5, 12], [-4, -8, -11], [1, 0, 7], [10, 7, 4], [0, 9, 9], [-23, -1, -1], [-12, -2, -3], [-13, -2, 5], [4, 8, 3], [4, 12, -5], [-5, 4, 13], [12, 5, -3], [9, -11, -15], [7, -6, -1], [10, -3, 5], [-7, 4, 6], [-37, 1, 0], [-25, -1, -1], [-28, -3, 3], [2, 3, 6], [16, 0, 1], [9, -13, -13], [-9, -3, 10], [8, -10, -17], [-4, 1, 4], [-27, 1, -3], [16, -5, -2], [13, -6, -16], [0, -12, -6], [-3, 10, 10], [-15, 15, 9], [17, -1, -10], [8, -10, 4], [-3, 10, 10], [4, 2, -4], [8, -13, 1], [2, -1, 9], [-24, -1, 7], [16, -8, -9], [8, -6, 8], [7, 5, -11], [-19, 2, 7], [-14, 5, 16], [14, 2, 5], [-8, 7, -5], [-1, 12, 15], [-6, 10, 7], [10, -5, -2], [-22, -10, -3], [3, -12, -19], [20, 0, 7], [-15, 6, 17], [-13, 0, 14], [-8, -3, 2], [-24, 6, -5], [25, -21, -19], [22, -13, -14], [-9, 2, -5], [31, -12, -8], [-6, 15, 6], [11, 1, -11], [21, -5, -12], [-19, -1, -1], [28, 0, 1], [1, 5, 11], [-13, -4, 2], [7, 3, -8], [24, -8, 4], [-16, 10, 7], [8, 9, -6], [9, -5, -3], [-22, -3, -5], [-23, 6, 11], [8, 11, -4], [-2, 15, 16], [-21, -12, 1], [10, -16, -6], [-30, 17, 10], [-21, 7, 10], [-22, 8, 4], [-5, 0, -6], [-7, 23, 6], [-18, 1, 14], [11, -13, -12], [-4, 14, 6], [25, -3, -4], [18, 6, -11], [-50, 0, 4], [13, -1, 4], [2, 9, 3], [-4, -9, -8], [10, -4, 2], [1, 6, -4], [28, 4, 6], [12, -1, -14], [10, -1, 16], [0, 1, 4], [-15, -2, 0], [-11, -8, -17], [3, 7, -9], [0, -1, 21], [-28, 18, 12], [12, 11, 13], [18, -5, -16], [11, -16, -11], [5, -5, -15], [-14, -7, 16], [16, 12, 8], [24, -6, -9], [-12, 2, 8], [-20, 9, 1], [4, 3, 14], [-11, 12, -5], [33, -27, -23], [7, -23, -6], [-10, 16, -5], [-19, -16, 1], [-38, -10, 3], [-30, 2, -6], [28, -13, -8], [-1, -2, 12], [-9, 14, 10], [-16, -6, 10], [-26, 8, 0], [21, -3, -14], [3, -1, 19], [-1, -5, -21], [-8, 6, -2], [14, -7, 14], [24, 6, 20], [22, 20, -6], [9, 1, -7], [-5, 18, 19], [10, 9, 4], [0, 5, 1], [-4, 7, 5], [38, -3, -4], [-9, 19, 9], [-31, -5, 3], [-17, -7, 15], [29, -17, -15], [-6, 9, 4], [2, 6, 23], [5, 22, 6], [31, 2, 13], [-25, 8, 13], [-38, 30, 27], [17, -14, -9], [-21, 9, -7], [-9, 21, 6], [1, 1, -1], [42, -17, -11], [-26, -8, 1], [21, 3, 4], [-21, -5, -5], [-44, 7, 9], [-4, -7, -12], [-26, -7, 4], [18, 24, -11], [10, 5, 24], [-23, -1, -8], [7, -10, -9], [15, -22, -18], [15, 8, -6], [-5, -7, -7], [-3, -7, 17], [-30, 10, 11], [-11, 0, 13], [32, -16, -13], [24, -15, -4], [4, 6, -5], [15, 17, 7], [-8, -16, -28], [32, -28, -17], [-21, -3, -20], [0, 20, 8], [8, 7, -14], [16, -12, -11], [20, -19, 4], [-16, -1, -6], [-12, -3, -11], [29, 5, 13], [-5, 20, -3], [28, 1, 13], [10, 5, 18], [-26, -26, 8], [16, -9, -3], [-2, -1, 21], [20, -3, -18], [-9, 15, 20], [26, 3, 15], [1, 3, 32], [26, -15, -21], [16, 5, 13], [10, -15, -4], [28, 4, 2], [-29, 11, -2], [-10, 23, 25], [-18, 7, -7], [-11, -24, -5], [3, 1, -22], [32, -3, 16], [-65, -3, 5], [13, -8, -15], [55, -11, -6], [26, -3, 17], [3, -15, 13], [-9, -9, 0], [3, 12, 27], [5, 9, 6], [-19, -10, -17], [-25, -15, 7], [18, 13, -4], [9, 1, -2], [-35, 7, 11], [10, -22, -11], [44, -22, -9], [46, -2, -12], [6, -4, -21], [8, 8, -9], [17, 3, 3], [1, 18, 13], [59, -15, -8], [2, 4, 3], [-42, -7, 0], [16, 11, 2], [-31, -3, -1], [1, -16, -21], [3, -10, -2], [-22, -9, -3], [-29, -14, -21], [18, -18, -2], [-32, -17, 10], [10, -6, -25], [59, 7, -7], [-16, -25, 16], [-26, 13, 16], [-51, 30, 27], [-5, 9, -22], [-34, 8, -14], [-25, 17, 12], [0, 34, 6], [-4, 31, 0], [31, 18, 7], [-28, 20, 5], [-5, -27, -5], [-36, -22, 7], [-14, -1, -7], [11, 20, -2], [-42, 1, 10], [-10, 26, 1], [-34, -7, -17], [-51, 3, -4], [4, 18, 7], [-7, -10, -2], [-2, 22, 5], [-14, -23, -10], [48, -31, -24], [-33, 27, 17], [36, -9, -2], [8, 3, -16], [12, -30, -3], [-33, 33, 25], [-4, 5, 2], [-10, -8, -34], [-9, 7, -7], [-20, 22, 26], [4, 8, -12], [2, -21, -30], [15, -14, -16], [16, -9, -28], [33, -20, -9], [-14, 17, 0], [-52, -11, -8], [-37, -25, 9], [26, -22, -23], [-31, 14, 14], [-8, -7, 24], [31, 3, 1], [52, 0, -7], [9, 8, -11], [-18, -27, -3], [11, -26, -10], [8, -14, 22], [3, 9, -8], [-32, 23, 7], [46, 9, -13], [17, -8, -26], [26, -13, 4], [32, 2, -5], [20, -16, -11], [46, 9, -9], [30, -22, -2], [-60, 37, 30], [11, -18, -1], [17, -5, -9], [18, 11, 17], [-23, 24, 15], [-3, 30, 0], [10, 7, 12], [-14, -14, 8], [11, 29, -6], [30, -25, -11], [27, -4, 7], [-19, 9, 15], [-24, 0, 18], [-14, 6, 5], [-38, 6, -8], [30, -1, 21], [-21, -21, -25], [-19, -6, 8], [44, 16, -13], [58, -13, -10], [-11, -20, -8], [15, 11, 24], [-63, 11, -1], [-52, 26, 14], [-22, -10, 1], [-42, 14, 1], [19, 9, -13], [6, 4, -7], [-37, 6, 4], [18, -12, -19], [-39, -19, 5], [12, 4, 17], [60, -19, -16], [-19, 3, -22], [-70, 9, 1], [7, 10, -25], [-3, 11, -6], [4, -9, -12], [-7, -20, -31], [8, 3, 3], [-52, 32, 21], [-8, 14, -24], [22, 0, 25], [45, 1, -13], [-25, 11, 17], [33, -6, -5], [23, -28, -5], [-34, 15, 16], [29, 7, 23], [53, -7, -5], [39, 8, -7], [60, 9, 1], [-2, 4, -5], [-28, 21, 9], [-7, 27, 13], [-72, -2, -12], [9, -20, -21], [2, -15, -13], [54, -41, -35], [48, -7, -9], [-2, 25, 11], [58, 1, -16]];
    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_h();".
// 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_h(:prec:=3)
    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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1805_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![7, -6, -1, 1]>,<3,R![7, -6, -1, 1]>],Snew);
    return Vf;
end function;