
// Make newform 2352.3.m.f in Magma, downloaded from the LMFDB on 24 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_f();".
// 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_f();".
// 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 := [4, -2, -1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [1, 3, 1, -1], [-3, -1, 1, 1], [-5, 0, 0, 2]];
    Rf_basisdens := [1, 1, 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_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, 0, -1, 0], [-1, 1, 0, 0], [0, 0, 0, 0], [0, 0, 1, -1], [-8, 2, 0, 0], [13, 3, 0, 0], [0, 0, 4, 4], [0, 0, -5, -7], [-2, 0, 0, 0], [0, 0, 8, 12], [20, 6, 0, 0], [-17, 13, 0, 0], [0, 0, 16, -16], [0, 0, -14, 6], [4, -10, 0, 0], [0, 0, 18, -22], [66, -12, 0, 0], [0, 0, 14, 18], [0, 0, -3, 23], [68, 6, 0, 0], [0, 0, -46, 6], [0, 0, 24, -28], [43, 17, 0, 0], [-80, -6, 0, 0], [109, -1, 0, 0], [0, 0, -20, -32], [0, 0, -27, 43], [-22, 40, 0, 0], [106, -16, 0, 0], [0, 0, -54, 14], [0, 0, -20, -40], [-164, -14, 0, 0], [0, 0, 4, 64], [284, -2, 0, 0], [0, 0, 16, 56], [54, -24, 0, 0], [0, 0, -134, -2], [0, 0, 134, 2], [141, 7, 0, 0], [0, 0, -13, -43], [-108, 6, 0, 0], [0, 0, -7, -45], [-144, -6, 0, 0], [48, 2, 0, 0], [0, 0, -100, 68], [0, 0, -36, -44], [0, 0, -60, -4], [0, 0, -138, -26], [292, 14, 0, 0], [296, -18, 0, 0], [0, 0, -57, -115], [152, 42, 0, 0], [0, 0, 238, 30], [-65, -59, 0, 0], [0, 0, -153, -83], [115, -19, 0, 0], [0, 0, -76, 56], [-112, -54, 0, 0], [140, 26, 0, 0], [0, 0, -84, -12], [209, 19, 0, 0], [0, 0, 48, -96], [0, 0, 50, 126], [-18, 56, 0, 0], [228, 78, 0, 0], [0, 0, -84, 28], [142, 60, 0, 0], [0, 0, 27, 189], [-214, 68, 0, 0], [37, -77, 0, 0], [0, 0, 209, -125], [0, 0, 16, -200], [146, -88, 0, 0], [0, 0, 116, -12], [0, 0, -240, -8], [-106, -24, 0, 0], [110, -80, 0, 0], [200, 78, 0, 0], [48, -14, 0, 0], [0, 0, 370, -22], [-232, -94, 0, 0], [0, 0, -231, 43], [50, -132, 0, 0], [0, 0, -64, -96], [0, 0, 115, 93], [-18, 60, 0, 0], [-534, -24, 0, 0], [157, -41, 0, 0], [0, 0, -218, -22], [0, 0, 82, -62], [0, 0, 294, 58], [0, 0, 228, -140], [0, 0, 479, -55], [0, 0, -100, -244], [0, 0, 52, 228], [-137, 49, 0, 0], [-131, -13, 0, 0], [0, 0, 52, 256], [-464, -6, 0, 0], [0, 0, 294, 202], [104, 10, 0, 0], [0, 0, 86, 270], [-96, -146, 0, 0], [0, 0, 234, -106], [-326, -132, 0, 0], [0, 0, 434, -158], [-607, 79, 0, 0], [0, 0, 17, -237], [-38, 60, 0, 0], [0, 0, 200, 88], [10, 0, 0, 0], [-88, -234, 0, 0], [0, 0, 72, 148], [0, 0, -526, -114], [244, -62, 0, 0], [0, 0, -292, 116], [0, 0, 394, -178], [-994, 0, 0, 0], [0, 0, 613, -61], [-354, -72, 0, 0], [388, -58, 0, 0], [-279, 19, 0, 0], [0, 0, -193, 241], [0, 0, 392, -132], [218, 108, 0, 0], [-462, -112, 0, 0], [0, 0, -268, 164], [0, 0, -404, -224], [-256, -174, 0, 0], [0, 0, -118, 14], [0, 0, -7, -229], [0, 0, 616, 56], [-198, 264, 0, 0], [43, -55, 0, 0], [-62, 12, 0, 0], [-55, 11, 0, 0], [0, 0, -368, -36], [109, -41, 0, 0], [22, -228, 0, 0], [0, 0, 24, 12], [-296, 138, 0, 0], [0, 0, -18, 138], [0, 0, 161, 519], [-452, -122, 0, 0], [0, 0, 418, -146], [314, 212, 0, 0], [-917, -55, 0, 0], [0, 0, 680, 40], [0, 0, 471, 77], [-542, 184, 0, 0], [1077, 99, 0, 0], [0, 0, 276, -60], [0, 0, -298, -302], [0, 0, 48, 568], [0, 0, -439, 155], [0, 0, 148, -260], [-937, 69, 0, 0], [-86, 84, 0, 0], [15, -175, 0, 0], [0, 0, 469, -69], [-414, 192, 0, 0], [0, 0, -414, 134], [0, 0, 28, 560], [-484, -78, 0, 0], [0, 0, 460, 308], [0, 0, -292, 52], [-778, -32, 0, 0], [-180, -242, 0, 0], [-367, -101, 0, 0], [0, 0, 497, -289], [254, -16, 0, 0], [0, 0, 417, -205], [500, -178, 0, 0], [0, 0, -500, 324], [-275, -165, 0, 0], [0, 0, -130, -214], [-142, 212, 0, 0], [0, 0, -80, 348], [-450, 120, 0, 0], [0, 0, -402, -126], [0, 0, 136, 692], [592, -62, 0, 0], [721, 127, 0, 0], [0, 0, -997, -135], [2029, -9, 0, 0], [-50, 188, 0, 0], [0, 0, 84, -208], [532, -178, 0, 0], [0, 0, -208, 32], [472, -158, 0, 0], [0, 0, 393, -433], [0, 0, -80, 32], [789, -97, 0, 0], [0, 0, -15, -361], [-1243, 3, 0, 0], [372, -250, 0, 0], [-288, -254, 0, 0], [1055, -75, 0, 0], [0, 0, -586, 250], [840, -238, 0, 0], [0, 0, -732, -28], [992, 106, 0, 0], [1400, 74, 0, 0], [0, 0, 480, 276], [1225, -101, 0, 0], [0, 0, 260, 500], [0, 0, -1035, -133], [-998, -240, 0, 0], [0, 0, 144, -16], [1210, -72, 0, 0], [-497, -351, 0, 0], [0, 0, -324, 460], [0, 0, -148, -408], [0, 0, -198, 270], [330, 156, 0, 0], [0, 0, 324, 76], [-659, -109, 0, 0], [0, 0, -481, 5], [1294, -160, 0, 0], [1282, 192, 0, 0], [0, 0, 852, -112], [970, 152, 0, 0], [0, 0, 240, -592], [0, 0, -284, -488], [-388, 334, 0, 0], [1071, -331, 0, 0], [0, 0, 291, 617], [0, 0, -428, 72], [0, 0, -537, 225], [-286, -288, 0, 0], [0, 0, -104, -800], [0, 0, -820, 196], [-738, 236, 0, 0], [0, 0, 472, -488], [0, 0, -392, -184], [304, -118, 0, 0], [-772, -242, 0, 0], [0, 0, 55, -119], [0, 0, 36, 180], [0, 0, -173, 469], [0, 0, -296, -308], [0, 0, -52, -156], [1984, 154, 0, 0], [-1213, 313, 0, 0], [0, 0, -450, 34], [0, 0, 24, -28], [0, 0, -698, 486], [0, 0, 1146, -378], [0, 0, 75, 913], [46, -244, 0, 0], [961, -1, 0, 0], [0, 0, 517, 183], [-1348, 30, 0, 0], [1157, 375, 0, 0], [0, 0, -547, -397], [56, -166, 0, 0], [0, 0, 176, 80], [-1227, 343, 0, 0], [746, -388, 0, 0], [0, 0, -974, -514], [0, 0, -1105, -191], [-1164, -106, 0, 0], [-150, 140, 0, 0], [-747, 443, 0, 0], [0, 0, -504, 204], [-1572, -178, 0, 0], [-155, -237, 0, 0], [0, 0, -834, -326], [66, -380, 0, 0], [1666, 20, 0, 0], [0, 0, -1000, 176], [52, -666, 0, 0], [0, 0, -628, -364], [1244, 70, 0, 0], [0, 0, -1596, 176], [0, 0, -319, 535], [-1832, -270, 0, 0], [376, -686, 0, 0], [0, 0, 606, 686], [0, 0, -604, -204], [0, 0, 1530, -106], [0, 0, -244, 196], [1526, -160, 0, 0], [0, 0, 524, 760], [0, 0, -255, -61], [-38, 88, 0, 0], [892, -410, 0, 0], [0, 0, -548, -40], [-2121, -67, 0, 0], [1232, 474, 0, 0], [0, 0, -1684, 248], [32, 462, 0, 0], [0, 0, -658, 46], [586, -64, 0, 0], [2205, 23, 0, 0], [0, 0, -660, -580], [-1301, -27, 0, 0], [0, 0, 222, -730], [0, 0, 204, 1096], [1102, 464, 0, 0], [-362, -688, 0, 0], [0, 0, -842, -278]];
    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_f();".
// 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_f(: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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![-20, 2, 1]>],Snew);
    return Vf;
end function;