
// Make newform 1764.4.k.f in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1764_k();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1764_k_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_1764_4_k_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_1764_4_k_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_1764_k();"
function MakeCharacter_1764_k()
    N := 1764;
    order := 3;
    char_gens := [883, 785, 1081];
    v := [3, 3, 2];
    // 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_1764_k_Hecke();"
function MakeCharacter_1764_k_Hecke(Kf)
    N := 1764;
    order := 3;
    char_gens := [883, 785, 1081];
    char_values := [[1, 0], [1, 0], [0, -1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, 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+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 := 4;
    raw_aps := [[0, 0], [0, 0], [0, -6], [0, 0], [36, -36], [-62, 0], [-114, 114], [0, -76], [0, -24], [-54, 0], [-112, 112], [0, 178], [378, 0], [-172, 0], [0, 192], [-402, 402], [-396, 396], [0, 254], [1012, -1012], [-840, 0], [890, -890], [0, -80], [-108, 0], [0, 1638], [-1010, 0], [-6, 6], [0, -472], [0, -972], [1786, -1786], [2286, 0], [1328, 0], [0, 1212], [-1254, 1254], [340, 0], [0, 1038], [-2936, 2936], [-1330, 1330], [0, 3364], [3048, 0], [0, 2706], [4716, -4716], [-1910, 0], [0, 4080], [2686, -2686], [-510, 0], [1352, -1352], [-3364, 0], [4768, 0], [-420, 420], [0, -1882], [0, 5082], [5424, 0], [-2590, 2590], [-4932, 0], [0, 3438], [6120, -6120], [18, -18], [0, 6896], [-6254, 6254], [-1194, 0], [-7156, 7156], [-3738, 0], [844, 0], [-6312, 6312], [0, 8282], [0, 9318], [0, -1652], [-1294, 0], [3636, -3636], [-10478, 0], [7566, -7566], [0, -8040], [7568, -7568], [0, 13522], [2468, 0], [0, 12336], [-3762, 3762], [0, -8770], [0, 6642], [-1510, 1510], [-1260, 0], [3998, 0], [-2736, 2736], [-2690, 0], [0, -1240], [0, -3900], [10878, 0], [0, -2330], [15150, 0], [-2992, 0], [0, -8724], [-9744, 9744], [-4136, 4136], [-16212, 0], [0, -2396], [13128, 0], [0, -12798], [-7386, 7386], [0, 5180], [0, -4070], [14780, 0], [-6858, 6858], [-6660, 6660], [0, -150], [8188, -8188], [-5854, 5854], [17580, 0], [0, -17154], [-18120, 18120], [-17546, 0], [0, -14560], [4498, -4498], [5478, 0], [6044, -6044], [-15352, 0], [-22398, 22398], [-3764, 0], [17688, -17688], [0, 19878], [20004, 0], [-1306, 1306], [-13054, 0], [0, -5046], [12468, -12468], [0, -23212], [-35958, 0], [0, -6446], [0, 4704], [10600, 0], [0, 12542], [-23324, 23324], [6312, 0], [0, -35840], [-34594, 0], [0, -23946], [-18770, 0], [-30342, 30342], [-26188, 26188], [-34818, 0], [-21702, 21702], [20356, 0], [0, -19890], [-4232, 4232], [-9636, 0], [35294, -35294], [-3768, 0], [39466, 0], [34038, -34038], [0, -3364], [0, 13104], [0, 40858], [-37374, 0], [9788, 0], [0, -50424], [12412, -12412], [-6576, 0], [0, -8264], [0, -39426], [4678, 0], [17346, -17346], [0, 19452], [-4458, 0], [52520, 0], [0, 10404], [-7566, 7566], [-44376, 44376], [27328, -27328], [2774, -2774], [-36526, 0], [0, -18438], [-39324, 39324], [-2990, 0], [0, 58632], [-45146, 45146], [16928, -16928], [5274, 0], [-36940, 0], [-16242, 16242], [6568, 0], [0, 782], [0, 25072], [25236, 0], [56270, 0], [0, -26346], [2832, -2832], [-16326, 16326], [68506, -68506], [-51388, 51388], [0, 43750], [23760, -23760], [0, -29758], [-11316, 0], [0, -76124], [0, 3810], [-26244, 26244], [-30282, 30282], [47470, -47470], [0, 7306], [-48174, 0], [0, 2952], [-330, 330], [-19232, 0], [0, 14150], [36290, -36290], [30684, 0], [-36750, 36750], [0, 64496], [0, -41748], [4710, 0], [-42100, 42100], [0, 20590], [14454, 0], [18488, 0], [0, 49428], [-20184, 20184], [0, 27914], [-61904, 61904], [-24882, 24882], [0, 45336], [-76566, 0], [0, -5966], [49912, 0], [0, 68418], [0, -45056], [-54636, 0], [48350, 0], [0, 16038], [-45408, 45408], [0, 632], [0, 69924], [-15590, 15590], [33860, -33860], [92672, 0], [-11238, 11238], [11140, 0], [-85008, 85008], [0, 68450], [0, 8910], [-3300, 0], [65592, 0], [109692, -109692], [0, 20492], [-103816, 103816], [0, 49354], [35778, 0], [0, -48984], [40384, 0], [88188, -88188], [-11540, 11540], [90912, 0], [15302, 0], [0, -49170], [114408, -114408], [-60026, 0], [28482, -28482], [0, -30420], [-4766, 4766], [68828, -68828], [-97914, 0], [0, 118298], [27472, -27472], [30132, 0], [-78538, 78538], [133666, 0], [-52866, 52866], [0, 89492], [-22806, 0], [65562, 0], [4628, 0], [-37458, 37458], [0, -125314], [-107660, 107660], [33098, -33098], [0, 110416], [8206, 0], [0, 107336], [0, 2196], [-135014, 135014], [0, -99674], [0, 122124], [39072, -39072], [-83480, 83480], [-46824, 0], [-149558, 0], [0, 102044], [0, 79728], [-44018, 44018], [30546, 0], [-135400, 135400], [-41646, 0], [-93546, 93546], [-27636, 27636], [0, 27786], [-57732, 0], [97238, 0], [73794, -73794], [0, 33920], [89286, 0], [0, -116796], [55180, 0], [0, -83446], [0, -108858], [132784, -132784]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1764_k_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1764_4_k_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_1764_4_k_f(:prec:=2)
    chi := MakeCharacter_1764_k();
    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_1764_4_k_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_1764_4_k_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1764_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![36, 6, 1]>,<11,R![1296, -36, 1]>,<13,R![62, 1]>],Snew);
    return Vf;
end function;