
// Make newform 2352.3.m.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2352_m();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2352_m_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_2352_3_m_j();".
// 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_2352_3_m_j();".
// 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 := [81, 9, 10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [36, -10, 10, -1], [14, 0, 0, 1], [9, 38, -2, 2]];
    Rf_basisdens := [1, 45, 5, 9];
    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_2352_m();"
function MakeCharacter_2352_m()
    N := 2352;
    order := 2;
    char_gens := [1471, 1765, 785, 2257];
    v := [1, 2, 2, 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_2352_m_Hecke();"
function MakeCharacter_2352_m_Hecke(Kf)
    N := 2352;
    order := 2;
    char_gens := [1471, 1765, 785, 2257];
    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], [3, 0, 1, 0], [0, 0, 0, 0], [0, 1, 0, 1], [0, 0, 0, 0], [-9, 0, 1, 0], [0, -2, 0, -2], [0, 11, 0, -1], [12, 0, 6, 0], [0, 10, 0, -2], [16, 0, -6, 0], [33, 0, -1, 0], [0, -16, 0, 0], [0, -12, 0, 4], [48, 0, 6, 0], [0, 0, 0, 4], [66, 0, 6, 0], [0, 6, 0, 6], [0, -7, 0, 5], [-6, 0, 6, 0], [0, 50, 0, -6], [0, -24, 0, -4], [69, 0, -13, 0], [150, 0, -6, 0], [-63, 0, -13, 0], [0, 22, 0, -14], [0, -15, 0, 9], [-70, 0, -12, 0], [-42, 0, -12, 0], [0, -14, 0, -6], [0, -108, 0, 0], [6, 0, -24, 0], [0, -48, 0, 12], [48, 0, 6, 0], [0, -8, 0, -24], [-102, 0, 30, 0], [0, -62, 0, 18], [0, -108, 0, 4], [213, 0, -1, 0], [0, 51, 0, 3], [168, 0, -24, 0], [0, -59, 0, -23], [-40, 0, -18, 0], [216, 0, -18, 0], [0, 16, 0, -8], [0, 12, 0, 12], [0, -172, 0, -4], [0, 120, 0, 12], [180, 0, -36, 0], [-306, 0, 0, 0], [0, 159, 0, 3], [-102, 0, -42, 0], [0, 12, 0, -16], [141, 0, 11, 0], [0, 131, 0, -1], [-69, 0, 25, 0], [0, -102, 0, 6], [-104, 0, 30, 0], [162, 0, 36, 0], [0, 138, 0, 18], [297, 0, -13, 0], [0, 10, 0, -14], [0, -180, 0, 4], [120, 0, 24, 0], [36, 0, -54, 0], [0, 92, 0, -36], [-10, 0, 24, 0], [0, 223, 0, 7], [-6, 0, -66, 0], [75, 0, 13, 0], [0, -111, 0, 21], [0, -272, 0, 16], [26, 0, -48, 0], [0, -92, 0, -12], [0, 48, 0, -56], [492, 0, -42, 0], [-294, 0, -66, 0], [-330, 0, 24, 0], [-294, 0, 6, 0], [0, 132, 0, 56], [64, 0, -42, 0], [0, 325, 0, 25], [84, 0, 60, 0], [0, 84, 0, 60], [0, -13, 0, -37], [306, 0, 0, 0], [298, 0, -24, 0], [-255, 0, 59, 0], [0, -146, 0, -42], [0, -108, 0, 0], [0, -192, 0, 8], [0, -12, 0, -12], [0, 355, 0, -29], [0, 268, 0, 12], [0, -60, 0, -68], [-117, 0, 49, 0], [507, 0, 61, 0], [0, -20, 0, 40], [376, 0, 30, 0], [0, -298, 0, 6], [240, 0, -42, 0], [0, -48, 0, 60], [-150, 0, -84, 0], [0, -166, 0, -54], [-60, 0, -84, 0], [0, 336, 0, 12], [-753, 0, -47, 0], [0, 517, 0, 1], [-228, 0, 84, 0], [0, 180, 0, 12], [-266, 0, -96, 0], [402, 0, -60, 0], [0, 296, 0, -4], [0, -110, 0, 42], [282, 0, -84, 0], [0, 406, 0, -2], [0, -84, 0, -84], [60, 0, -42, 0], [0, 109, 0, 85], [882, 0, 54, 0], [-32, 0, 90, 0], [-471, 0, 107, 0], [0, 575, 0, 23], [0, -156, 0, -48], [60, 0, -42, 0], [-886, 0, -12, 0], [0, 72, 0, 64], [0, -330, 0, 18], [-768, 0, 48, 0], [0, -78, 0, -78], [0, 5, 0, 41], [0, 432, 0, 0], [170, 0, 180, 0], [-387, 0, 59, 0], [-1116, 0, -36, 0], [465, 0, 83, 0], [0, 240, 0, -60], [-615, 0, 11, 0], [-714, 0, 84, 0], [0, 356, 0, 32], [-216, 0, -162, 0], [0, -386, 0, 6], [0, 557, 0, -19], [-168, 0, 24, 0], [0, -72, 0, 16], [-678, 0, 30, 0], [-75, 0, -157, 0], [0, 286, 0, -26], [0, -321, 0, -69], [-482, 0, -72, 0], [-213, 0, 229, 0], [0, -620, 0, 36], [0, 612, 0, 4], [0, -416, 0, 0], [0, 525, 0, -15], [0, -140, 0, -60], [-459, 0, -133, 0], [-24, 0, 24, 0], [147, 0, -215, 0], [0, -223, 0, -31], [522, 0, 72, 0], [0, 330, 0, 114], [0, -192, 0, 68], [-210, 0, -96, 0], [0, -564, 0, 28], [0, -172, 0, 36], [234, 0, 270, 0], [124, 0, -222, 0], [-183, 0, -109, 0], [0, 165, 0, 45], [18, 0, -234, 0], [0, 213, 0, 33], [-436, 0, -138, 0], [0, -416, 0, -104], [-969, 0, -71, 0], [0, -90, 0, -90], [348, 0, -186, 0], [0, -478, 0, 62], [738, 0, 54, 0], [0, -130, 0, -42], [0, 252, 0, -16], [272, 0, -246, 0], [-261, 0, 37, 0], [0, 427, 0, -113], [-615, 0, -13, 0], [-866, 0, 36, 0], [0, -108, 0, -48], [1388, 0, 6, 0], [0, -372, 0, -148], [-6, 0, 6, 0], [0, -183, 0, -39], [0, 136, 0, 72], [-99, 0, 191, 0], [0, 133, 0, -107], [-213, 0, -107, 0], [-344, 0, -222, 0], [-1024, 0, -54, 0], [1365, 0, 107, 0], [0, 204, 0, 68], [132, 0, -150, 0], [0, -220, 0, 20], [492, 0, -60, 0], [-978, 0, -30, 0], [0, 396, 0, -152], [333, 0, 287, 0], [0, -924, 0, -12], [0, -547, 0, 77], [150, 0, -60, 0], [0, 822, 0, -18], [358, 0, -168, 0], [435, 0, -119, 0], [0, -1180, 0, -12], [0, 36, 0, -16], [0, 408, 0, 152], [-408, 0, -312, 0], [0, 692, 0, -60], [-825, 0, 73, 0], [0, 407, 0, -109], [-1548, 0, -18, 0], [-238, 0, -36, 0], [0, -642, 0, -78], [-1062, 0, -216, 0], [0, -160, 0, 48], [0, -384, 0, 116], [832, 0, 138, 0], [1077, 0, -85, 0], [0, -209, 0, 43], [0, -254, 0, 190], [0, 1039, 0, 7], [-286, 0, 60, 0], [0, 98, 0, 146], [0, 692, 0, 84], [-1206, 0, 216, 0], [0, -926, 0, 10], [0, -456, 0, -24], [726, 0, -150, 0], [552, 0, -354, 0], [0, -525, 0, -117], [0, -396, 0, -116], [0, -209, 0, 151], [0, -436, 0, 200], [0, 140, 0, 20], [-1408, 0, -138, 0], [1545, 0, -97, 0], [0, 0, 0, -200], [0, -278, 0, 22], [0, -648, 0, -4], [0, -518, 0, 90], [0, -1025, 0, 19], [886, 0, 252, 0], [675, 0, -83, 0], [0, -783, 0, 21], [330, 0, -42, 0], [1401, 0, 203, 0], [0, 737, 0, -55], [128, 0, -102, 0], [0, 110, 0, -10], [909, 0, 47, 0], [600, 0, -312, 0], [0, 978, 0, -102], [0, -253, 0, -205], [-1812, 0, 84, 0], [2106, 0, -18, 0], [723, 0, 61, 0], [0, -1336, 0, 20], [48, 0, 150, 0], [2295, 0, 49, 0], [0, 934, 0, 102], [156, 0, 6, 0], [150, 0, 66, 0], [0, -168, 0, 264], [1218, 0, 222, 0], [0, 68, 0, 180], [-90, 0, -342, 0], [0, 542, 0, 98], [0, -403, 0, -43], [-304, 0, -378, 0], [-496, 0, -90, 0], [0, -456, 0, -4], [0, -684, 0, -4], [0, -1054, 0, -6], [0, -612, 0, -20], [3162, 0, 78, 0], [0, 508, 0, 40], [0, -595, 0, 65], [1618, 0, -96, 0], [-1596, 0, -294, 0], [0, 1538, 0, -58], [-543, 0, 263, 0], [-1212, 0, 330, 0], [0, -828, 0, -64], [-702, 0, 180, 0], [0, -696, 0, 92], [-238, 0, -264, 0], [-2919, 0, 107, 0], [0, -1024, 0, 176], [63, 0, -299, 0], [0, 360, 0, 116], [0, -56, 0, 4], [-540, 0, -468, 0], [2424, 0, -174, 0], [0, 126, 0, -90]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2352_m_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2352_3_m_j();".
// 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_2352_3_m_j(:prec:=4)
    chi := MakeCharacter_2352_m();
    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_2352_3_m_j();".
// 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_2352_3_m_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![-28, -6, 1]>],Snew);
    return Vf;
end function;