
// Make newform 2112.3.j.d in Magma, downloaded from the LMFDB on 04 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2112_j();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2112_j_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_2112_3_j_d();".
// 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_2112_3_j_d();".
// 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 := [22, 4, 12, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [23, 2, 1, 1], [10, 28, 1, 1], [9, -32, 10, -3]];
    Rf_basisdens := [1, 13, 13, 13];
    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_2112_j();"
function MakeCharacter_2112_j()
    N := 2112;
    order := 2;
    char_gens := [2047, 133, 1409, 1729];
    v := [2, 2, 2, 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_2112_j_Hecke();"
function MakeCharacter_2112_j_Hecke(Kf)
    N := 2112;
    order := 2;
    char_gens := [2047, 133, 1409, 1729];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, -1, 0, 0], [-1, -3, 0, 0], [0, 0, 1, 0], [5, 1, -2, 1], [0, 0, -1, 6], [0, 0, 2, -2], [0, 0, 4, 2], [23, -5, 0, 0], [0, 0, 4, -8], [-20, 18, 0, 0], [16, -2, 0, 0], [0, 0, -6, -4], [0, 0, 12, 2], [-25, 3, 0, 0], [-7, 11, 0, 0], [10, -42, 0, 0], [0, 0, 11, 2], [-34, 0, 0, 0], [71, -1, 0, 0], [0, 0, -10, 4], [0, 0, -5, 24], [0, 0, -6, 16], [76, 18, 0, 0], [-94, -42, 0, 0], [0, 0, -14, 16], [-68, -42, 0, 0], [0, 0, 12, 30], [0, 0, 13, -34], [52, 66, 0, 0], [0, 0, -19, 40], [0, 0, -22, 12], [-50, 12, 0, 0], [0, 0, 2, 50], [0, 0, -2, -48], [0, 0, 15, 76], [190, -48, 0, 0], [-28, -52, 0, 0], [0, 0, 6, 4], [0, 0, -12, -28], [-50, -50, 0, 0], [-44, -74, 0, 0], [-91, -27, 0, 0], [0, 0, -8, -36], [0, 0, 2, -8], [-50, -164, 0, 0], [0, 0, 18, 22], [-110, -16, 0, 0], [0, 0, 32, -70], [-230, -40, 0, 0], [0, 0, -62, -4], [0, 0, 30, 4], [0, 0, -32, 76], [232, -96, 0, 0], [-272, 38, 0, 0], [0, 0, 18, 8], [257, -49, 0, 0], [0, 0, -61, 76], [0, 0, -11, 66], [0, 0, 70, -42], [0, 0, 54, -26], [0, 0, 32, 80], [0, 0, -42, 90], [47, 147, 0, 0], [-58, 184, 0, 0], [-349, -59, 0, 0], [188, 24, 0, 0], [0, 0, -58, 8], [0, 0, 18, 176], [0, 0, -57, 10], [-2, -112, 0, 0], [0, 0, -16, -212], [-110, -144, 0, 0], [0, 0, -67, 54], [212, -276, 0, 0], [-139, -111, 0, 0], [83, -291, 0, 0], [-32, 262, 0, 0], [-260, -54, 0, 0], [0, 0, 18, -164], [-128, 132, 0, 0], [244, -126, 0, 0], [0, 0, -94, 172], [-274, -132, 0, 0], [0, 0, -71, -12], [-248, -360, 0, 0], [-254, 76, 0, 0], [0, 0, -94, 96], [0, 0, -32, -8], [-152, -118, 0, 0], [406, -62, 0, 0], [0, 0, 2, 96], [58, 376, 0, 0], [0, 0, -108, -70], [-388, 240, 0, 0], [0, 0, -98, -52], [251, 1, 0, 0], [-68, -314, 0, 0], [0, 0, -44, -34], [0, 0, -67, -170], [0, 0, -120, 134], [0, 0, 0, -144], [0, 0, 0, -190], [0, 0, 126, -122], [0, 0, -58, -226], [158, -46, 0, 0], [-194, 222, 0, 0], [0, 0, -22, 202], [869, 13, 0, 0], [0, 0, 62, 24], [0, 0, -53, -164], [0, 0, -115, 70], [64, 198, 0, 0], [-406, 108, 0, 0], [88, -158, 0, 0], [580, -118, 0, 0], [-46, -236, 0, 0], [-823, 57, 0, 0], [155, 105, 0, 0], [0, 0, -36, -38], [250, 336, 0, 0], [0, 0, 42, 224], [0, 0, 26, 156], [16, 496, 0, 0], [326, 300, 0, 0], [0, 0, 124, -148], [-458, -444, 0, 0], [-415, 41, 0, 0], [-122, -48, 0, 0], [0, 0, -91, 174], [0, 0, 38, -314], [0, 0, -160, -52], [-980, 210, 0, 0], [-560, 274, 0, 0], [0, 0, -62, -170], [0, 0, -108, 184], [-301, -363, 0, 0], [0, 0, -56, 30], [-493, -219, 0, 0], [0, 0, -26, -292], [0, 0, 12, 174], [0, 0, -82, 0], [682, 212, 0, 0], [0, 0, -114, 264], [58, -368, 0, 0], [791, 235, 0, 0], [0, 0, -13, 278], [0, 0, 90, -380], [-4, 60, 0, 0], [-13, 819, 0, 0], [0, 0, 31, -326], [454, -20, 0, 0], [854, 8, 0, 0], [0, 0, -160, 20], [-178, -356, 0, 0], [-43, -123, 0, 0], [0, 0, -89, -220], [1102, 192, 0, 0], [0, 0, -228, -60], [0, 0, -98, -276], [-1256, -156, 0, 0], [0, 0, -114, -12], [0, 0, 83, 72], [-1040, 144, 0, 0], [-500, 110, 0, 0], [-805, 159, 0, 0], [-176, -498, 0, 0], [0, 0, 83, 374], [0, 0, 34, -124], [-817, 181, 0, 0], [0, 0, -226, 188], [256, 450, 0, 0], [0, 0, -104, 216], [0, 0, -272, -20], [-542, -684, 0, 0], [-812, -30, 0, 0], [0, 0, 106, -266], [461, -333, 0, 0], [0, 0, 29, 28], [0, 0, 161, 242], [184, 422, 0, 0], [0, 0, -22, 116], [124, -298, 0, 0], [0, 0, -2, -76], [623, -885, 0, 0], [191, 429, 0, 0], [0, 0, 349, -370], [242, -756, 0, 0], [0, 0, 64, -132], [0, 0, 234, 192], [1238, 114, 0, 0], [0, 0, -318, 232], [-352, 212, 0, 0], [917, -497, 0, 0], [0, 0, 248, -122], [-134, -900, 0, 0], [0, 0, 10, 168], [-512, 114, 0, 0], [0, 0, -14, -60], [0, 0, -160, 196], [0, 0, -130, -16], [0, 0, -189, 364], [1408, 66, 0, 0], [0, 0, 234, -208], [1036, 64, 0, 0], [-913, 593, 0, 0], [-1400, 90, 0, 0], [0, 0, 30, 524], [0, 0, -58, 542], [1850, -260, 0, 0], [0, 0, 392, -260], [-889, 745, 0, 0], [364, -1062, 0, 0], [-404, -712, 0, 0], [0, 0, -8, 324], [-250, 30, 0, 0], [0, 0, -187, -132], [0, 0, 90, 574], [1463, 23, 0, 0], [1817, -9, 0, 0], [0, 0, 85, 274], [0, 0, 41, 180], [-92, 1206, 0, 0], [1078, -620, 0, 0], [0, 0, 160, 526], [0, 0, 255, -314], [-386, -148, 0, 0], [197, -151, 0, 0], [0, 0, 291, 88], [0, 0, -176, -390], [358, 1104, 0, 0], [0, 0, -228, -66], [0, 0, -173, 676], [0, 0, -22, 90], [-1324, 364, 0, 0], [0, 0, 404, -408], [1334, 108, 0, 0], [0, 0, 212, 76], [-1016, 476, 0, 0], [-1387, -595, 0, 0], [1666, 30, 0, 0], [0, 0, 18, 126], [1228, -126, 0, 0], [-458, 604, 0, 0], [0, 0, -274, -390], [0, 0, -384, -112], [-1346, -456, 0, 0], [652, 836, 0, 0], [0, 0, 58, 294], [0, 0, -116, 464], [0, 0, 251, 414], [0, 0, -34, 484], [-1309, 987, 0, 0], [-214, -750, 0, 0], [0, 0, -450, 236], [0, 0, 226, 200], [1390, -212, 0, 0], [0, 0, 246, 674], [1823, -531, 0, 0], [0, 0, 114, -240], [0, 0, -7, 200], [0, 0, -270, -140], [0, 0, 63, -118], [0, 0, 83, 346], [-428, -1434, 0, 0], [-1474, 324, 0, 0], [2093, -357, 0, 0], [130, -624, 0, 0], [0, 0, 188, -70], [0, 0, 120, -308], [1696, 570, 0, 0], [-598, 416, 0, 0], [914, -42, 0, 0], [0, 0, -29, -872], [0, 0, -132, -248], [-626, 1452, 0, 0], [-986, 194, 0, 0], [0, 0, -107, 282], [0, 0, 426, -396], [0, 0, -72, 634], [0, 0, 66, 724], [706, -324, 0, 0], [0, 0, 112, 388], [0, 0, 575, -226], [0, 0, -292, 770], [-121, 527, 0, 0], [62, 206, 0, 0], [0, 0, -292, -208], [1426, 372, 0, 0], [0, 0, -34, -734], [1067, 1177, 0, 0], [2170, -782, 0, 0], [0, 0, -634, 426], [0, 0, 136, -278], [0, 0, -395, -150], [0, 0, 194, 296], [1126, -828, 0, 0], [-301, -899, 0, 0], [0, 0, -694, 304], [0, 0, -304, 90], [0, 0, 680, -568], [0, 0, -24, 180], [0, 0, -273, -72]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2112_j_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2112_3_j_d();".
// 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_2112_3_j_d(:prec:=4)
    chi := MakeCharacter_2112_j();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_2112_3_j_d();".
// 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_2112_3_j_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2112_j();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![-26, 2, 1]>,<23,R![454, -46, 1]>],Snew);
    return Vf;
end function;