
// Make newform 1083.6.a.b in Magma, downloaded from the LMFDB on 15 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1083_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_1083_6_a_b();".
// 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_1083_6_a_b();".
// 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_1083_a();"
function MakeCharacter_1083_a()
    N := 1083;
    order := 1;
    char_gens := [362, 724];
    v := [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_1083_a_Hecke(Kf)
    return MakeCharacter_1083_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 := 6;
    raw_aps := [[2], [-9], [-98], [240], [336], [-342], [-6], [0], [2836], [5902], [-2744], [-13670], [-10990], [-4996], [-17124], [4470], [-26292], [29134], [42052], [26112], [-49046], [-79056], [9472], [-82894], [-39850], [99542], [-69368], [110204], [217786], [84618], [-89608], [255992], [50226], [-242108], [-352506], [272120], [124942], [-28900], [-370200], [277414], [439108], [-25406], [640644], [224846], [325438], [-983576], [866308], [76928], [969612], [840150], [575914], [-352188], [-451290], [145752], [1878178], [895068], [-1272906], [306672], [-192026], [-1000550], [-1268468], [1525598], [1196652], [2371444], [353738], [-2704266], [327444], [-367946], [566160], [-4506866], [-1097782], [-1952228], [1491632], [-1483046], [2794356], [-2069096], [4616958], [875870], [3366154], [-6586546], [-1067752], [-3606206], [-1053096], [3456974], [5886104], [-4802160], [3179666], [483546], [707982], [8240912], [2136400], [1207364], [8779696], [4234000], [-1734500], [-4723524], [2497414], [-2864126], [-2462276], [6881918], [4996796], [-8428866], [10178092], [-11379222], [-7574260], [-6064878], [16201112], [9922914], [9550200], [-1570090], [-8838696], [-4940682], [-5446078], [9256484], [-18422000], [18364042], [5308244], [-3322764], [-5810962], [16006604], [12799818], [-9838226], [8544166], [10081596], [-7713196], [4924398], [5354678], [9395068], [6830552], [12953566], [11529180], [-3201312], [-5528224], [16270838], [-8400430], [7665426], [25982910], [-25984460], [-21201066], [-10637350], [11920468], [8144310], [-9576752], [2951068], [-8795462], [1468416], [23778886], [40901298], [-7997308], [4406344], [25505746], [-35082182], [-24781380], [6854632], [36439196], [28312336], [-3755872], [-5553662], [24616586], [38995558], [21655912], [19404682], [7267888], [24339108], [30941466], [-35316856], [-49600024], [-53355082], [5863590], [-55672266], [7998332], [-15122446], [30424996], [-14750294], [39051928], [63962554], [44607748], [662566], [42569952], [51382782], [30838832], [47372316], [-9004814], [-30818118], [19569084], [-18273994], [18518442], [-36583100], [60195070], [37070060], [51381254], [14916160], [43718684], [31890878], [95213592], [4112306], [-29207278], [10262398], [23332962], [80245244], [-43494850], [34098712], [36290658], [-22806602], [79991184], [41758686], [88240816], [4398596], [-70016206], [52684388], [-81618590], [54390462], [-56058568], [-51165492], [-52960128], [13494790], [53659520], [-23200278], [-40395168], [-105447546], [-28556158], [52732184], [-64404774], [93006216], [74401292], [114836198], [2675514], [118787352], [-117673712], [95069280], [-6468594], [42786492], [36355400], [28652610], [-10254764], [-24896660], [103958546], [-23381666], [-155388912], [-108951696], [-160856364], [-34171428], [130248904], [-145498334], [-137599598], [125534668], [-62616536], [-146444900], [-15832540], [-43051124], [28264382], [147073154], [-26213372], [45107454], [104399862], [-150588168], [7905958], [-86261116], [-120091674], [-120358518], [-39990416], [96484540], [-77168890], [11717346], [29298882], [-50248668], [-56802914], [-37951798], [-193362220], [76529758], [112497666], [-41530588], [114747946], [-132927864], [-36337674], [-121139744], [-79567704], [22499730], [-190774122], [-250851552], [191165928], [18519328], [-116884740], [232400042], [132175308], [126208428], [116562386], [-145159842], [231301568], [-52606750], [-178404914], [-289463808], [-134088022], [128764860], [276383650], [-245353674], [-85927504], [154197886], [198163092], [-24985684], [123472058], [-100052466], [127350496], [228413572], [-8060412], [-301406826], [-112366620], [171060074], [55854420], [-12806762], [22790932], [-233165794], [223209994], [-363763540], [-374453532], [15611086], [74589144], [-291845008], [-292821838], [395089658], [16368388], [-143701958], [259381982], [-71830432], [326518770], [-139887306], [152660956], [-273542644], [-130310328], [57657398], [-59248274], [387377838], [81721304], [-16005144], [-99552276], [-23211208], [-192964190], [211471658], [291929290], [-42996640], [-66534310], [-206954462], [305752566], [430223872], [165209774], [29645740], [-152111130], [31401356], [-145449648], [58174630], [131786116], [236788078], [-516655386], [-46239096], [-128151046], [512284338], [339772308], [32623480], [277663002], [-418997136], [-75651658], [-198745614], [-345571272], [85579500], [449109004], [483085846], [-4503346], [146261488], [496562982], [585497792], [-516262444], [165485644], [-335754762], [221271480], [380617198], [51321932], [-428608868], [258807970], [-573072990], [-193503746], [-277954050], [-136164582], [-424499336], [228786930], [-498526796], [-605115392], [-689582672], [-522715450], [286562036], [544899456], [-371747194], [-341964666], [747663808], [550066844], [540914368], [-197420514], [-36842840], [-645219030], [89863020], [-222936370], [-703498638], [417184034], [146425360], [451833978], [229801278], [-749874568], [253740606], [278465970], [196771692], [479205832], [-152621986], [670508510], [51505284], [695875844], [571592554], [7769502], [796836784], [-422983120], [216266602], [680724352], [-657759330], [-627592838], [-507829172], [-453276300], [-350221674], [857650230], [-228794108], [-240589110], [271355908], [544066116]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1083_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1083_6_a_b();".
// 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_1083_6_a_b(:prec:=1)
    chi := MakeCharacter_1083_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_1083_6_a_b();".
// 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_1083_6_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1083_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-2, 1]>],Snew);
    return Vf;
end function;