
// Make newform 1620.4.i.f in Magma, downloaded from the LMFDB on 12 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1620_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1620_i_Hecke();"
// 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_4_i_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_1620_4_i_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, -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_1620_i();"
function MakeCharacter_1620_i()
    N := 1620;
    order := 3;
    char_gens := [811, 1541, 1297];
    v := [3, 2, 3];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1620_i_Hecke();"
function MakeCharacter_1620_i_Hecke( : Kf := false)
    N := 1620;
    order := 3;
    char_gens := [811, 1541, 1297];
    char_values := [[1, 0], [0, -1], [1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 4;
    raw_aps := [[0, 0], [0, 0], [0, -5], [28, -28], [-24, 24], [0, 70], [-102, 0], [20, 0], [0, -72], [306, -306], [0, 136], [-214, 0], [0, -150], [292, -292], [-72, 72], [414, 0], [0, -744], [418, -418], [0, -188], [-480, 0], [434, 0], [-1352, 1352], [-612, 612], [30, 0], [286, -286], [-1542, 1542], [0, -1172], [-1956, 0], [-1858, 0], [0, 174], [-2068, 0], [0, 312], [2646, -2646], [0, 1276], [0, -3198], [760, -760], [0, 166], [3020, 0], [0, -984], [1962, -1962], [-576, 0], [-1210, 0], [3384, -3384], [0, 2038], [-4098, 0], [-2248, 0], [0, -3260], [2980, -2980], [-3180, 3180], [0, -3374], [-1950, 0], [0, 2232], [1822, -1822], [-1488, 0], [0, -2994], [-2472, 2472], [-3954, 0], [-2176, 0], [-1034, 1034], [-6654, 6654], [0, 1756], [0, 3234], [2036, 0], [0, -96], [-1202, 1202], [-3798, 3798], [5668, -5668], [0, 454], [0, -5604], [11266, -11266], [-6426, 6426], [-6936, 0], [388, -388], [0, 8062], [-3388, 0], [0, 6984], [-2526, 2526], [6146, 0], [0, 9786], [0, 886], [0, -11352], [-10190, 10190], [-2448, 0], [-7078, 0], [18088, -18088], [3852, -3852], [-6522, 0], [-2090, 2090], [-9894, 9894], [0, -3044], [-10236, 0], [11496, -11496], [-15316, 0], [0, -11616], [0, -14996], [21648, 0], [0, 3378], [16158, 0], [-76, 0], [9278, 0], [-14564, 14564], [-2154, 0], [0, -8700], [4194, -4194], [0, 8020], [-2686, 0], [3012, -3012], [15522, 0], [0, 19224], [6502, -6502], [0, -29396], [-10006, 0], [0, 23118], [-14036, 14036], [-4288, 0], [1314, -1314], [0, 628], [10944, 0], [0, 1098], [312, -312], [0, -8678], [14470, -14470], [-11838, 11838], [25548, 0], [18412, -18412], [8814, 0], [17314, -17314], [768, 0], [18196, -18196], [0, 18142], [-13660, 0], [0, -12768], [0, -22952], [15818, 0], [0, -18558], [0, -14978], [-8946, 0], [0, 18436], [0, 16314], [25446, 0], [42740, 0], [29946, -29946], [0, 32596], [-3804, 0], [3278, 0], [-5784, 5784], [-17306, 17306], [31134, -31134], [0, 10780], [-3456, 0], [0, -2618], [26550, 0], [27596, 0], [0, -37848], [4804, -4804], [28608, -28608], [-40768, 0], [27642, -27642], [28106, 0], [0, 14730], [-9564, 9564], [53898, 0], [0, -15140], [-23808, 0], [0, 23094], [7584, -7584], [-26752, 0], [-7778, 7778], [-9886, 0], [0, 39858], [37032, -37032], [0, -54902], [0, 19512], [9694, -9694], [0, -38936], [0, 57762], [63676, -63676], [36750, 0], [36380, 0], [-30326, 30326], [43132, -43132], [34536, -34536], [0, 30886], [-65142, 0], [0, 29640], [15330, -15330], [58778, 0], [45796, -45796], [0, 45718], [12456, 0], [-59542, 0], [-2388, 2388], [32876, 0], [-30246, 30246], [38244, 0], [0, -32202], [0, 51118], [-59690, 59690], [-59778, 59778], [18720, 0], [0, 47754], [-56504, 56504], [0, -33554], [-50834, 50834], [-31224, 0], [14118, 0], [-1384, 0], [0, -72252], [-23214, 23214], [0, -22748], [-70294, 0], [0, 52530], [-73988, 73988], [69612, -69612], [0, 14784], [67030, -67030], [0, -48524], [14586, -14586], [93216, 0], [0, -35622], [0, -51662], [0, 16504], [0, -86910], [12692, 0], [0, -10260], [79234, -79234], [-4074, 4074], [-91008, 0], [-27644, 27644], [-14280, 14280], [0, 109702], [21260, 0], [0, 15520], [0, 24738], [-77924, 77924], [-94752, 94752], [0, 101230], [-40818, 0], [0, -34392], [87408, 0], [3252, -3252], [-65332, 0], [0, 10084], [-13618, 0], [0, -22458], [72192, -72192], [33500, 0], [0, -34224], [0, -7820], [36336, 0], [0, 88414], [-95682, 0], [0, 17784], [41878, -41878], [15834, -15834], [101832, 0], [-28138, 0], [-74612, 74612], [-64530, 0], [68978, 0], [-33788, 33788], [5844, -5844], [0, -88958], [-36910, 0], [0, 46062], [-13412, 13412], [75942, 0], [68538, -68538], [0, 29932], [0, -54174], [0, 109594], [-18412, 0], [-102242, 102242], [0, -73304], [0, 42310], [21956, 0], [0, -32052], [-26990, 26990], [34298, 0], [-99048, 99048], [0, -9168], [0, -102872], [-41952, 41952], [-108782, 108782], [0, 88372], [-3048, 0], [20882, 0], [0, 40722], [52936, -52936], [3294, 0], [-55494, 55494], [-124956, 0], [0, -9330], [0, -164184], [-109874, 109874], [0, -8886], [107800, -107800], [-91470, 91470], [-22776, 0], [157948, -157948], [0, -99074], [30966, 0], [6512, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1620_i_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1620_4_i_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_1620_4_i_f(:prec:=2)
    chi := MakeCharacter_1620_i();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_4_i_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_1620_4_i_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1620_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![784, -28, 1]>,<11,R![576, 24, 1]>],Snew);
    return Vf;
end function;