
// Make newform 83.13.b.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_83_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_83_b_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_83_13_b_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_83_13_b_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
        poly := [-62, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-3, 5]];
    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_83_b();"
function MakeCharacter_83_b()
    N := 83;
    order := 2;
    char_gens := [2];
    v := [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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_83_b_Hecke();"
function MakeCharacter_83_b_Hecke(Kf)
    N := 83;
    order := 2;
    char_gens := [2];
    char_values := [[-1, 0]];
    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 := 13;
    raw_aps := [[0, 0], [294, -29], [0, 0], [116246, 915], [1616006, 33459], [0, 0], [15722966, 819195], [0, 0], [-231011422, 0], [-488546170, 14431227], [31361078, -38902557], [2494043174, -24141909], [-9474786718, 0], [0, 0], [0, 0], [0, 0], [25092046406, 1512658419], [-42601298362, 1231426923], [0, 0], [0, 0], [0, 0], [0, 0], [326940373369, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [-542282187706, 69141454395], [974144673110, -79833591237], [3138820667318, 125285043939], [2003395005362, 0], [0, 0], [0, 0], [0, 0], [7170628488086, -407481592701], [0, 0], [0, 0], [-14602899090346, -718307128029], [4049994879686, -1159372748325], [0, 0], [0, 0], [20200850171894, 1957491522195], [-58405186312702, 0], [-58462209935962, -27844038741], [-123112933322398, 0], [0, 0], [0, 0], [16846458044978, 0], [166485137369042, 0], [0, 0], [0, 0], [123809350152278, 6786053274363], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [483137365180178, 0], [0, 0], [0, 0], [-1260212655757102, 0], [0, 0], [0, 0], [201161715007862, 40513231807467], [-993373434874618, -10100013621573], [0, 0], [0, 0], [0, 0], [-1803726776501818, 3324883312491], [596786182637078, 81366761378139], [1863267811354838, 48098310761283], [0, 0], [60278485382822, 118242579628347], [0, 0], [1774882996468022, 116293820795907], [0, 0], [-7340951071684942, 0], [-7698267117575998, 0], [4682057854223414, 5733907243035], [-2298490491873562, -217252531368237], [0, 0], [3120824984268278, -242783805543357], [0, 0], [0, 0], [5121168145449734, -239123633402109], [0, 0], [0, 0], [0, 0], [-9153303155651914, -168912805959885], [0, 0], [-1904090171239690, -525395630643213], [0, 0], [0, 0], [-15177374954242522, 110333154668883], [0, 0], [-1686282928332730, 758128762018347], [28177347340931042, 0], [-16326304168838650, -557603787937197], [0, 0], [25795288539338150, -293098224498717], [-23861088429860302, 0], [-3209125158504538, -1393849101648333], [0, 0], [0, 0], [0, 0], [0, 0], [-6370964905566058, -1894279950307893], [0, 0], [0, 0], [71648154976418498, 0], [0, 0], [40587852230505398, -1601695813086741], [-3254690733824698, -2468223543580509], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [-57523083368904718, 0], [0, 0], [25375246297888214, 3948038613015531], [0, 0], [0, 0], [-32247931737021658, 4532985210990291], [235083154357321202, 0], [0, 0], [0, 0], [-128720294170023850, -3300535715247597], [-145170900747626362, 2261534566113339], [325530944132854322, 0], [0, 0], [229571139496204802, 0], [-141601352771235994, 5305644375159435], [0, 0], [0, 0], [-281962373462031022, 0], [467726649839141618, 0], [0, 0], [0, 0], [-547610081219596078, 0], [0, 0], [0, 0], [0, 0], [0, 0], [296039543513263382, -7815989150698989], [371164769794870310, -4180321309460997], [395116057059373622, -944654184989733], [-398997779767123642, -2481651361333677], [-121679671253123914, -17446648563247485], [0, 0], [9065538539707286, 20529339056196459], [0, 0], [0, 0], [-338609114254713274, 19074544891577475], [-571579030758677578, 83155684487091], [0, 0], [-640053376696308778, 2073506476597611], [0, 0], [-593883593500906618, -16368518604604629], [0, 0], [63216922955268278, -32705034881469861], [0, 0], [0, 0], [-813294638677347946, -14330076921075189], [-1664569617641741662, 0], [914714290635502070, 11712711728560947], [-542998656333264922, -36449682576067461]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_83_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_83_13_b_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_83_13_b_b(:prec:=2)
    chi := MakeCharacter_83_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 13));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_83_13_b_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_83_13_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_83_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,13,sign)));
    Vf := Kernel([<2,R![0, 1]>,<3,R![-1213634, -617, 1]>],Snew);
    return Vf;
end function;