
// Make newform 1764.4.a.r in Magma, downloaded from the LMFDB on 14 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1764_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_1764_4_a_r();".
// 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_a_r();".
// 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 := [-96, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_1764_a();"
function MakeCharacter_1764_a()
    N := 1764;
    order := 1;
    char_gens := [883, 785, 1081];
    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_1764_a_Hecke(Kf)
    return MakeCharacter_1764_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 := 4;
    raw_aps := [[0, 0], [0, 0], [0, -1], [0, 0], [0, 1], [-54, 0], [0, -2], [2, 0], [0, 10], [0, 5], [201, 0], [-202, 0], [0, 24], [-244, 0], [0, -12], [0, 33], [0, -31], [-588, 0], [-302, 0], [0, -8], [-446, 0], [-267, 0], [0, 37], [0, -6], [595, 0], [0, 62], [1664, 0], [0, -81], [358, 0], [0, 56], [2127, 0], [0, 77], [0, -130], [-2438, 0], [0, -78], [-947, 0], [-1540, 0], [-1090, 0], [0, -106], [0, -94], [0, -60], [-2004, 0], [0, -228], [4649, 0], [0, 214], [-616, 0], [-3208, 0], [-2065, 0], [0, -93], [-3908, 0], [0, 226], [0, -78], [-3913, 0], [0, 237], [0, -102], [0, -24], [0, -103], [1197, 0], [1532, 0], [0, -26], [-6284, 0], [0, 189], [1762, 0], [0, -340], [1321, 0], [0, 321], [-9736, 0], [-6747, 0], [0, -108], [9646, 0], [0, 24], [0, 326], [-6757, 0], [8644, 0], [7372, 0], [0, 382], [0, -694], [-4632, 0], [0, -264], [-4573, 0], [0, -132], [6096, 0], [0, 864], [-5206, 0], [-12411, 0], [0, -683], [0, -238], [14827, 0], [0, 74], [-2276, 0], [0, 284], [0, 568], [18467, 0], [0, -195], [-13922, 0], [0, -1062], [0, 717], [0, -648], [16466, 0], [384, 0], [10110, 0], [0, 83], [0, 697], [0, -762], [-10536, 0], [2287, 0], [0, 199], [0, 798], [0, 1098], [-17089, 0], [4947, 0], [-18030, 0], [0, -836], [26308, 0], [-10813, 0], [0, -644], [11174, 0], [0, -996], [0, 747], [0, -500], [-8024, 0], [-29791, 0], [0, -453], [0, 255], [27176, 0], [0, -475], [-5434, 0], [0, 918], [29353, 0], [-11436, 0], [-78, 0], [0, 882], [26391, 0], [-660, 0], [0, 262], [8773, 0], [0, -562], [-5880, 0], [0, 1167], [0, 164], [-6062, 0], [0, -347], [-32240, 0], [0, -1443], [32002, 0], [0, 274], [-19966, 0], [0, -708], [-33376, 0], [0, 458], [-4520, 0], [0, -1914], [-7636, 0], [0, 1242], [-12102, 0], [0, 264], [-33788, 0], [0, -72], [17603, 0], [0, -973], [0, -2836], [0, -884], [-4747, 0], [0, -1677], [0, -1068], [0, -1728], [13469, 0], [14282, 0], [-25957, 0], [0, 387], [0, -1957], [16072, 0], [0, -3138], [12501, 0], [36507, 0], [0, 272], [-19944, 0], [0, -2957], [2660, 0], [-58312, 0], [-9507, 0], [0, -725], [42706, 0], [0, 1298], [0, -574], [0, -1941], [14460, 0], [-32506, 0], [-13413, 0], [0, -3198], [57181, 0], [0, -2649], [9658, 0], [0, -1142], [0, -1395], [0, 1990], [-20866, 0], [59320, 0], [0, 1884], [0, -3036], [0, 2715], [41256, 0], [13790, 0], [-48174, 0], [0, 3372], [0, -555], [-2296, 0], [0, -1413], [0, 2526], [-38962, 0], [-1282, 0], [0, 3383], [7425, 0], [0, 2243], [0, -942], [-57514, 0], [-35345, 0], [0, 334], [0, 1426], [0, 118], [73564, 0], [-53888, 0], [0, 2400], [-89315, 0], [0, 2043], [-64276, 0], [0, 1714], [0, 164], [-67863, 0], [0, -408], [-47004, 0], [35224, 0], [8149, 0], [0, 726], [-47374, 0], [0, 402], [-55697, 0], [0, -4101], [0, -2328], [0, 5942], [0, 3448], [4016, 0], [28499, 0], [-99066, 0], [0, -3386], [0, 1152], [74097, 0], [0, 28], [75224, 0], [0, -3336], [-94898, 0], [0, 3408], [0, -6030], [-22262, 0], [0, 1141], [0, 505], [127196, 0], [-20568, 0], [0, -3847], [38465, 0], [-43856, 0], [0, 2081], [-52358, 0], [-21404, 0], [0, -5244], [2518, 0], [0, -3477], [0, 4178], [2620, 0], [0, -1257], [-84264, 0], [-112870, 0], [-32919, 0], [107087, 0], [-72275, 0], [64680, 0], [0, -1241], [-46878, 0], [-50966, 0], [0, -1428], [0, -1800], [25101, 0], [0, -7746], [64556, 0], [-9450, 0], [0, 6382], [-14601, 0], [0, -6509], [11723, 0], [0, -1392], [0, 1398], [0, 1455], [0, 4140], [0, -2380], [84566, 0], [0, -2817], [14744, 0], [0, 114], [0, 5796], [-7068, 0], [-59990, 0], [0, 2535], [50731, 0], [0, 7173], [64364, 0], [62462, 0], [0, 4181], [-170182, 0], [0, 1438], [-17926, 0], [0, -9390], [0, -5134], [0, -3166], [-76120, 0], [0, 6554], [57062, 0], [0, 7053], [0, 2102], [69449, 0], [0, -4056], [-133516, 0], [101242, 0], [0, -1143], [4936, 0], [0, 3908], [-64381, 0], [146768, 0], [-105026, 0], [0, 1234], [0, 19], [-51904, 0], [0, 4699], [102912, 0], [0, -3548], [155434, 0], [0, 308], [-65574, 0], [0, 2600], [92381, 0], [91243, 0], [57224, 0], [0, -8586], [0, 5265], [-182181, 0], [0, 2301], [0, 807], [114494, 0], [167690, 0], [0, -4530], [0, -1431], [-160342, 0], [46055, 0], [0, 8298], [70035, 0], [119692, 0], [0, 3184], [0, -11164], [0, -4287], [0, -4304], [0, -5498], [-139760, 0], [0, -10856], [0, 446], [0, -8852], [-17642, 0], [-148885, 0], [0, 9354], [114624, 0], [93133, 0], [0, -10673], [-141608, 0], [0, -7758], [0, 3449], [121816, 0], [108142, 0], [0, -11892], [0, 2986], [134575, 0], [0, 9166], [-14698, 0], [0, 2946], [0, 2756], [-87320, 0], [0, -5730], [-4676, 0], [0, 1508], [123824, 0], [-24920, 0], [-130586, 0], [0, 10174], [-183247, 0], [0, -12174], [0, 11401], [-193132, 0], [0, 1814], [-87705, 0], [-214361, 0], [0, 8026], [-26286, 0], [0, -2549], [243026, 0], [0, -3822], [-100700, 0], [0, 2366], [0, 13341], [-94141, 0], [85990, 0], [0, -6408], [-107704, 0], [0, 4873], [211855, 0], [0, -8597], [0, 11047], [-132708, 0], [-91078, 0], [0, 373], [0, -2768], [27172, 0], [0, 1938], [0, 10964], [0, 5767], [-26518, 0], [0, -2012], [0, -6147], [-50890, 0], [0, 6422], [0, 7919], [0, 15426], [216258, 0], [0, -8132]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1764_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1764_4_a_r();".
// 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_a_r(:prec:=2)
    chi := MakeCharacter_1764_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_1764_4_a_r();".
// 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_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1764_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-385, 0, 1]>,<11,R![-385, 0, 1]>,<13,R![54, 1]>],Snew);
    return Vf;
end function;