
// Make newform 1800.2.a.a in Magma, downloaded from the LMFDB on 17 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1800_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_1800_2_a_a();".
// 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_1800_2_a_a();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1800_a();"
function MakeCharacter_1800_a()
    N := 1800;
    order := 1;
    char_gens := [1351, 901, 1001, 577];
    v := [1, 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_1800_a_Hecke( : Kf := Kf)
    return MakeCharacter_1800_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]];
    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], [0], [0], [-5], [6], [-3], [2], [1], [2], [-6], [3], [-6], [-4], [11], [10], [8], [6], [3], [-1], [12], [10], [-8], [6], [16], [-7], [8], [4], [8], [-7], [-12], [8], [-16], [-6], [-12], [6], [9], [7], [-7], [-16], [6], [-2], [-19], [10], [3], [2], [21], [-15], [3], [12], [-3], [-20], [-24], [-7], [20], [12], [12], [30], [8], [1], [-26], [13], [2], [13], [14], [-29], [16], [-20], [-23], [18], [10], [-18], [4], [13], [-25], [-5], [-20], [12], [11], [0], [-11], [-32], [30], [-22], [19], [-5], [0], [4], [22], [16], [-8], [14], [6], [-3], [-8], [17], [-36], [-6], [14], [21], [17], [16], [14], [18], [-10], [1], [43], [-24], [-4], [-44], [-13], [0], [2], [32], [-19], [31], [-36], [-12], [-12], [6], [28], [10], [-34], [18], [24], [16], [14], [-35], [42], [-13], [-34], [-44], [12], [24], [-3], [52], [27], [-28], [-3], [-28], [24], [9], [10], [-49], [32], [50], [-26], [55], [52], [48], [8], [-17], [40], [19], [-42], [-44], [14], [1], [30], [23], [-46], [2], [-24], [56], [-46], [-10], [36], [-25], [-54], [29], [30], [14], [-25], [-50], [-35], [5], [24], [-63], [30], [-21], [-1], [7], [-8], [61], [6], [18], [-62], [5], [41], [-35], [30], [-23], [-12], [55], [-42], [-26], [-62], [46], [-26], [-18], [-46], [52], [68], [-38], [-46], [-20], [-54], [-19], [62], [12], [-41], [-13], [-2], [7], [52], [-38], [-2], [-5], [2], [-4], [-66], [-55], [-55], [-18], [32], [20], [55], [-6], [42], [37], [-42], [41], [-52], [-55], [-70], [60], [-24], [10], [0], [50], [-40], [54], [47], [21], [11], [-22], [30], [1], [30], [-33], [-26], [22], [-30], [68], [5], [-46], [-12], [-47], [-44], [48], [62], [-17], [10], [22], [-49], [-74], [16], [22], [-16], [-44], [22], [-25], [-48], [58], [-65], [9], [-81], [78], [-33], [15], [24], [60], [16], [62], [67], [13], [-6], [-15], [52], [-56], [-12], [-34], [12], [12], [32], [-77], [4], [-5], [-36], [-18], [-4], [-74], [-68], [-65], [-30], [-36], [-67], [-44], [81], [-16], [38], [-2], [60], [-44], [55], [-38], [-47], [14], [12], [33], [78], [-40], [3], [48], [-69], [38], [18], [-23], [41], [-42], [-20], [-47], [58], [79], [34], [73], [4], [3], [-24], [13], [-72], [43], [36], [2], [-43], [14], [-10], [-7], [-47], [-40], [-84], [41], [-38], [-42], [89], [-25], [-94], [36], [-74], [-46], [26], [47], [18], [-42], [40], [28], [-37], [-72], [-28], [47], [12], [71], [-10], [92], [-64], [-83], [60], [66], [-9], [-36], [-91], [42], [-10], [-48], [60], [20], [34], [59], [-42], [-44], [-98], [93], [-28], [-88], [-65], [-22], [-63], [19], [16], [47], [44], [82], [-72], [45], [88], [-96], [64], [-83], [-36], [25], [-12], [-9], [36], [74], [1], [-67], [68], [-30], [-67], [-60], [0], [-80], [43], [54], [-14], [-50], [-60], [-52], [-24], [-17], [102]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1800_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1800_2_a_a();".
// 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_1800_2_a_a(:prec:=1)
    chi := MakeCharacter_1800_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_1800_2_a_a();".
// 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_1800_2_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![5, 1]>,<11,R![-6, 1]>,<13,R![3, 1]>],Snew);
    return Vf;
end function;