
// Make newform 1620.2.a.h in Magma, downloaded from the LMFDB on 17 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1620_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_1620_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_1620_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 := [-3, 0, 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_1620_a();"
function MakeCharacter_1620_a()
    N := 1620;
    order := 1;
    char_gens := [811, 1541, 1297];
    v := [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_1620_a_Hecke( : Kf := Kf)
    return MakeCharacter_1620_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, 0], [1, 0], [-1, 1], [0, 1], [2, -2], [3, -1], [-1, 2], [0, 2], [6, -1], [-1, -4], [-1, 3], [6, -3], [5, 1], [3, 1], [9, 1], [6, -1], [-4, 0], [-4, -6], [6, -3], [5, 3], [-4, 6], [3, -7], [0, 3], [-1, -1], [6, 7], [8, -6], [0, 2], [-1, 4], [9, 5], [-1, -3], [-12, -1], [6, 6], [5, -6], [0, 0], [-7, 6], [5, 1], [17, -1], [9, -7], [0, -14], [0, -7], [-13, 2], [0, 11], [5, 9], [0, -8], [2, -8], [-13, 4], [8, 8], [-21, 3], [-4, 8], [-9, 9], [-12, -2], [-7, -10], [-24, -2], [-12, 2], [0, -14], [18, 1], [-4, -12], [-7, -7], [-12, 10], [20, 2], [-9, 9], [-7, -3], [-6, -13], [8, -4], [9, 7], [-19, 6], [-10, 14], [-27, -3], [-25, 0], [3, -15], [-18, -5], [-16, 6], [5, 11], [8, 2], [6, 14], [-24, 2], [20, -10], [-6, -12], [-4, 8], [-18, 2], [-7, -12], [18, -9], [8, -2], [17, 6], [-39, -1], [-12, 7], [17, -3], [6, 9], [8, 6], [-21, 3], [12, 5], [-34, -2], [6, 1], [17, -6], [18, -10], [6, -12], [0, -6], [14, 6], [-1, -2], [-16, -12], [-6, -6], [-21, 1], [24, -11], [-13, -8], [17, 3], [-9, -3], [30, 4], [30, 9], [-7, 10], [-13, -9], [14, -6], [12, 0], [-10, 0], [-7, -4], [18, 3], [-1, -9], [24, 14], [6, 2], [6, 2], [5, -6], [-28, 6], [-6, 20], [-18, 2], [-10, 0], [30, 7], [14, 2], [12, -3], [2, 18], [2, -24], [5, 18], [21, 9], [20, -12], [-10, 6], [18, -7], [11, -14], [-9, 5], [-31, 3], [-6, 10], [24, 9], [-1, 14], [-12, -5], [-10, 4], [42, -2], [-31, 12], [24, 9], [5, 3], [36, 4], [-13, -12], [27, -13], [-10, -14], [-12, -3], [-7, 23], [-15, -1], [-22, -12], [12, 3], [41, -6], [-24, -13], [26, 4], [12, 2], [18, -20], [6, 2], [23, 9], [-24, -1], [6, 6], [51, -1], [35, -12], [47, -3], [-13, -6], [-15, -7], [-18, 17], [-19, -6], [48, 1], [2, 4], [50, 4], [-30, 17], [2, -28], [-6, 5], [-28, -8], [-19, 22], [-37, 11], [-24, -10], [-19, 15], [-24, -22], [-3, 11], [-24, -1], [20, 6], [5, -13], [-19, -22], [18, 22], [-28, -10], [21, 23], [-4, 10], [18, -27], [-9, 21], [15, -17], [11, 12], [-37, 15], [-33, -1], [-24, -8], [-12, 11], [11, 0], [47, 9], [-1, -12], [-6, -6], [0, -4], [-31, -4], [-24, -20], [36, -18], [20, 8], [-4, -22], [-48, 1], [-16, -24], [0, -12], [12, -5], [-1, 30], [-16, 22], [-36, -13], [12, 26], [12, -18], [5, 14], [-25, 24], [-42, -11], [-40, -12], [-9, 3], [-25, -26], [-18, 12], [6, -6], [23, -13], [-18, -10], [-31, -5], [35, 12], [26, 28], [-6, 32], [-16, -12], [18, -16], [-13, 18], [3, -21], [12, 24], [-18, 23], [-9, 31], [-4, -6], [-7, 21], [-40, 0], [-36, -20], [-24, -3], [-31, -19], [0, 40], [23, 20], [27, -23], [59, -9], [-6, 25], [-21, 1], [-1, 30], [9, 23], [-54, -10], [17, -12], [-40, -18], [-21, -25], [41, -9], [-13, -13], [3, -15], [-19, 12], [-10, -2], [-21, 17], [-67, 6], [12, 20], [-30, -9], [-16, 12], [-36, -6], [23, -26], [-22, 30], [-34, -6], [47, -6], [56, 14], [5, -27], [-24, 14], [23, 20], [38, -16], [-18, -14], [33, 11], [2, 12], [30, -8], [38, 6], [-19, -9], [-6, 5], [-43, 1], [-15, 7], [-7, 0], [-18, 28], [12, -9], [0, 20], [45, -11], [18, 35], [-7, -33], [-30, 11], [59, 2], [-21, 15], [-18, -3], [-34, 24], [-28, -18], [21, 1], [29, 4], [12, -30], [11, -12], [41, 7], [-33, -21], [-25, -24], [-24, -9], [-22, 6], [24, 10], [-18, 7], [-24, -17], [17, -7], [81, -3], [-7, 28], [6, -17], [0, -29], [23, 23], [66, 7], [-52, -6], [-7, -29], [0, 9], [-49, 17], [66, 6], [35, 0], [-1, -12], [14, 24], [-42, -10], [0, 22], [-13, 6], [75, -3], [11, 2], [21, 21], [-1, 18], [-75, 3], [29, 18], [-84, 6], [11, -44], [56, 12], [-61, -1], [54, 12], [24, -15], [-4, 22], [3, 19], [36, 20], [-13, 6], [17, 13], [-24, 13], [12, -28], [-13, -32], [-46, 18], [30, 28], [-34, 24], [65, 0], [-12, 2], [6, 19], [36, -7], [-24, 22], [-18, 6], [-34, -34], [72, -9], [15, 27], [30, 1], [5, -3], [14, 10], [24, 0], [-37, 15], [5, 28], [-72, 5], [32, 4], [42, 4], [24, -19], [41, 6], [17, 23], [42, 13], [-6, 19], [-1, 7], [6, 17], [65, -9], [30, 4], [60, -2], [-67, -3], [36, -22], [23, -6], [15, -25], [-4, -6], [-46, 24], [17, 15], [-36, -18], [-4, -28], [-12, -28], [-12, -28], [-19, 41], [30, 27], [35, -21], [-19, 2], [-36, -24], [-76, 16], [24, -7], [-79, -12], [-60, -8], [-46, 8], [33, 17], [30, 17], [-34, 24], [-25, 5], [36, 8], [-1, 15], [0, -9], [11, -43], [-36, 10], [21, 37], [29, 6], [14, 34], [-18, 16], [-42, -17], [38, -16], [45, -7], [-42, 28], [60, 26], [-13, -17], [84, 0], [-42, -19], [-13, 15], [27, 21], [-39, -9], [12, 28], [-67, -18], [-48, -16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1620_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1620_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_1620_2_a_h(:prec:=2)
    chi := MakeCharacter_1620_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_1620_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_1620_2_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1620_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-2, 2, 1]>,<11,R![-3, 0, 1]>,<17,R![6, -6, 1]>],Snew);
    return Vf;
end function;