
// Make newform 1805.2.a.f in Magma, downloaded from the LMFDB on 24 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_f();".
// 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_f();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -1, 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 := [[0, -1, 0], [-1, 1, 1], [1, 0, 0], [0, 0, 2], [-2, -2, 0], [-3, 1, -1], [0, 2, -2], [0, 0, 0], [-2, 2, 0], [4, -2, -2], [0, -4, 0], [-7, 1, -1], [0, 2, -2], [0, -4, -6], [0, 0, 2], [-5, -1, 1], [6, 2, 2], [-2, 4, -2], [1, -5, -1], [0, 4, 4], [0, 2, 2], [2, -6, -6], [-10, -2, 0], [0, -2, -6], [-9, 7, 5], [-6, 0, 2], [5, -5, -1], [-5, 1, 1], [2, 4, 4], [-5, 7, 5], [-1, 5, -3], [8, -4, 4], [8, -6, 2], [-2, 6, -4], [-10, -4, -2], [2, -2, -2], [4, 2, 2], [-4, 0, 2], [-3, -9, 3], [7, -1, -7], [-2, 2, -6], [-10, 4, 4], [-4, 12, 0], [-9, -1, -3], [6, -8, 4], [12, -12, -4], [2, -6, 6], [1, -5, -5], [-5, 1, 1], [6, -4, -6], [-6, 8, 4], [16, 0, -4], [-4, -2, 2], [4, 0, 12], [9, 5, 7], [10, -2, 0], [-2, 0, 8], [2, -10, 0], [-16, -2, -10], [12, -2, -2], [6, -2, -4], [-5, -1, 1], [-13, 1, -7], [2, 6, 8], [22, 4, 0], [-3, -7, -1], [6, -2, 2], [-1, 3, 1], [-6, 2, -8], [-10, 0, 0], [0, -6, -2], [6, 2, -8], [0, 0, 2], [11, -9, -7], [12, -8, 8], [-5, 5, -11], [-14, -4, 4], [8, 14, 2], [6, 0, -12], [-30, 8, 4], [0, 12, 16], [-12, 18, 14], [-10, 2, -2], [-21, -1, 5], [-10, 14, 2], [-2, -10, 4], [2, 0, 12], [-6, 8, 0], [-10, 8, -8], [-10, 2, -8], [-18, 6, 12], [18, -10, -12], [1, 7, 15], [4, 8, -4], [-10, 6, 8], [-10, 18, 0], [-12, -2, -18], [2, 12, 20], [9, -9, 11], [2, -8, 6], [-17, 9, 13], [8, 6, -2], [-23, -1, 3], [10, 0, 0], [-30, 2, 4], [10, 0, 12], [-18, -2, -12], [-2, -20, 4], [2, 18, 6], [8, 10, -10], [9, -1, -1], [-16, -2, 14], [-20, 14, 14], [-10, 14, 12], [-10, 18, 12], [12, -10, -6], [2, 2, 4], [-26, -6, -12], [24, 6, -2], [-6, -10, -6], [4, -6, -2], [-19, 13, -1], [3, -17, -15], [-35, -5, -1], [2, -14, -12], [2, 16, -2], [-18, 16, 0], [30, -14, -12], [16, 8, 2], [-2, -8, 0], [-20, 0, 0], [23, -3, -7], [-2, -6, 22], [2, 12, 0], [2, -12, 14], [2, 12, -2], [-7, -11, -21], [11, 13, -7], [-5, -1, -15], [-18, 4, 4], [20, 12, 8], [14, -8, 8], [-28, -4, -14], [21, 11, -13], [22, 16, 0], [10, 2, 26], [-30, 4, 8], [9, -11, -1], [-16, -12, 8], [-37, 1, 5], [15, 3, -3], [10, 4, 10], [-4, -16, 14], [-1, -7, 21], [-5, 25, -7], [22, 2, -10], [-40, -8, -4], [18, -16, 0], [12, -18, -10], [2, 8, 8], [22, -2, 8], [17, 13, 15], [18, -2, 4], [28, 4, 12], [9, 1, -5], [-21, 13, -3], [-34, 2, -6], [20, 2, -2], [-28, 18, 6], [-16, 14, 2], [-12, -8, 4], [10, -8, 8], [42, -2, 4], [-18, -12, -8], [24, -24, -8], [10, -4, -2], [-16, -4, -20], [-14, 8, 18], [11, 9, -3], [6, 4, -22], [18, -2, 24], [-12, -12, 4], [-19, -7, -1], [25, -15, 3], [26, -10, -8], [10, 12, -4], [-17, 15, 1], [-19, -13, -9], [-2, -4, -4], [-4, -12, 8], [1, -3, -9], [-26, 14, -8], [-56, 8, 0], [-16, 6, 14], [-20, 32, 18], [3, 15, -3], [-26, 20, 12], [-18, 0, -12], [10, -24, -20], [-4, -4, -10], [-8, 2, 18], [30, 10, 2], [-15, 13, -13], [-24, 14, -2], [-6, 2, 20], [-12, 26, -2], [6, 2, -8], [-41, -3, 9], [-22, 8, -8], [24, -8, -8], [6, 4, -20], [-42, 20, 6], [38, -14, -8], [-11, 3, 11], [-24, -8, 12], [-36, -2, -10], [4, -12, -30], [10, -4, 0], [47, -11, -3], [14, 16, 8], [20, 18, -14], [-32, -16, 0], [44, 2, -10], [-18, -6, 0], [3, 1, 9], [-34, 24, 8], [17, -23, -13], [-44, 4, -12], [-33, -15, 5], [-8, 4, -8], [-2, 16, -8], [24, -12, 8], [10, 14, -6], [28, -18, 6], [18, 2, 0], [-24, -16, -10], [38, 0, 18], [-54, 12, 8], [-10, -2, 24], [30, -6, 14], [1, 19, 27], [-8, -4, -12], [28, -4, -18], [4, -18, -30], [43, -13, -7], [-28, 20, 12], [20, -12, 6], [14, -18, 2], [-28, 16, 0], [8, 24, -14], [-10, 32, 8], [34, -16, -16], [6, -22, 12], [-6, -16, -4], [18, -28, -20], [-12, -24, -24], [34, 12, 28], [-31, -21, -1], [-17, -5, 21], [-4, -18, -26], [13, 11, 15], [17, -25, -25], [-6, 16, 2], [3, 23, 1], [38, -20, -20], [-26, 10, -6], [12, -2, 26], [42, 4, 2], [-25, 13, -7], [-14, 28, 16], [10, -32, -24], [5, -5, 3], [8, -14, -18], [2, 14, 24], [11, -5, -31], [-8, -24, -14], [-12, -24, -2], [8, 2, 14], [8, 10, 30], [18, 10, 16], [-29, -11, -3], [-10, 10, -32], [30, -38, -12], [-26, 4, 8], [-66, -2, 0], [-42, 18, 0], [-18, 20, 8], [-3, -23, 31], [-12, 4, 0], [-18, -28, -12], [14, 16, 0], [-8, -12, 18], [-1, 15, 13], [-2, -26, 2], [-9, -1, -23], [-42, -12, 2], [20, -32, -4], [10, 20, -4], [24, -20, -16], [24, -4, 14], [32, 2, 14], [-41, -1, 9], [38, -46, -20], [27, -19, -11], [4, 0, 32], [27, 7, 21], [9, 7, -17], [12, 14, -26], [-20, -20, 20], [-6, 28, -16], [0, -8, 2], [10, 0, 10], [-14, 4, 0], [-3, -29, -1], [-14, 38, 12], [-20, -6, -38], [-2, -10, -32], [-34, 2, 14], [30, -28, -28], [2, -8, -32], [8, -16, -8], [-16, -6, 18], [20, -22, -14], [27, -19, -11], [-4, -18, -42], [-44, -10, -2], [-26, -22, 18], [-59, 3, -1], [19, 17, -7], [-40, -18, 2], [14, -28, -2], [15, -1, -15], [-6, -10, 4], [44, -32, -6], [-14, 2, 20], [-24, -4, 6], [26, -12, -20], [-11, -7, 27], [-14, 24, 16], [-2, -22, 4], [7, 15, 41], [-12, -10, -10], [50, -4, 8], [-12, 8, 24], [-45, -1, 1], [10, 6, -2], [-18, -8, -24], [29, 3, 11], [8, -4, -12], [0, 6, 30], [-4, 28, 32], [-27, -3, 7], [-26, 44, 14], [-53, 29, 13], [4, -18, 30], [-35, 29, -9], [48, 16, -4], [-12, -16, 8], [28, -34, -22], [19, 9, 5], [20, 18, 6], [26, 28, -2], [-27, 11, -21], [28, 16, -4], [26, -14, 16], [-33, 3, -15], [16, -34, -14], [-5, -27, 13], [-36, 30, 6], [-6, -6, 4], [-34, 34, -2], [12, -4, 26], [-22, 4, -40], [-16, -8, 28], [-4, 2, 14], [-12, 0, 28], [-16, -16, -36], [34, -40, -20], [-10, -28, -4], [35, -45, -7], [18, 24, -8], [-6, -16, 12], [-4, -12, 2], [10, 8, -4], [-62, 38, 22], [25, -25, -21], [10, 14, 20], [-20, 10, 2], [-12, 0, 14], [-7, -17, 15], [14, -12, 8], [7, -33, -23], [-4, -24, 4], [2, -30, -36], [-46, -10, -34], [-67, 13, -9], [22, -10, -18], [-12, 18, -18], [8, 40, -20], [-34, -24, -8], [-18, 40, 12], [-38, 32, 4], [9, -13, 23], [-35, 5, 23], [14, -16, 36], [40, 16, -24], [-60, 18, 6], [-18, 16, -8], [25, -41, -29], [-12, 0, 8], [-11, -23, 19], [-6, 4, 8], [-33, -3, -23], [-10, 14, 0], [-44, 6, 6], [10, -20, -12], [-18, -10, -18], [-21, 25, 17], [52, -2, -2], [-5, 13, 13], [70, 8, 24], [47, -5, 5], [12, 20, 34], [-32, 44, 20], [-37, -17, 21], [39, 23, 1], [41, -33, -29], [22, -24, -10], [16, -4, 12], [26, 14, 28]];
    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_f();".
// 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_f(: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_f();".
// 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_f( : 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, 1]>,<3,R![-4, -4, 2, 1]>],Snew);
    return Vf;
end function;