
// Make newform 2352.3.m.d 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_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_2352_3_m_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 := [4, 0, 2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 0, 1], [1, 0, 1, 0], [0, 4, 0, 1]];
    Rf_basisdens := [1, 2, 1, 2];
    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], [-6, 1, 0, 0], [0, 0, 0, 0], [0, 0, 6, 4], [-12, 7, 0, 0], [-6, 5, 0, 0], [0, 0, 0, -6], [0, 0, 18, 4], [24, -6, 0, 0], [0, 0, 4, 18], [0, 24, 0, 0], [18, 7, 0, 0], [0, 0, -12, -20], [0, 0, -8, -6], [-22, 36, 0, 0], [0, 0, -28, 18], [-24, -41, 0, 0], [0, 0, -12, -4], [0, 0, 18, -24], [-12, 35, 0, 0], [0, 0, 24, 20], [0, 0, -20, 12], [30, -19, 0, 0], [-108, 11, 0, 0], [18, -37, 0, 0], [0, 0, 4, 42], [0, 0, -54, 32], [-12, -60, 0, 0], [14, 72, 0, 0], [0, 0, 36, -68], [0, 0, -36, -12], [144, -30, 0, 0], [0, 0, -20, 72], [2, 36, 0, 0], [0, 0, -12, 96], [-48, 5, 0, 0], [0, 0, -108, 24], [0, 0, -96, -30], [102, 61, 0, 0], [0, 0, -78, 16], [-180, 29, 0, 0], [0, 0, -30, 0], [-86, 72, 0, 0], [-98, -36, 0, 0], [0, 0, -112, -24], [0, 0, -72, -92], [0, 0, -24, 24], [0, 0, -92, 90], [-12, -7, 0, 0], [264, -114, 0, 0], [0, 0, 42, -124], [84, 97, 0, 0], [0, 0, -164, 6], [114, 163, 0, 0], [0, 0, -18, 80], [6, -337, 0, 0], [0, 0, -20, -78], [-178, -72, 0, 0], [24, 78, 0, 0], [0, 0, -224, 42], [-150, 215, 0, 0], [0, 0, -80, -66], [0, 0, -32, 126], [264, -49, 0, 0], [262, 108, 0, 0], [0, 0, 120, 56], [120, -180, 0, 0], [0, 0, 198, -4], [144, 17, 0, 0], [-162, -173, 0, 0], [0, 0, 30, -12], [0, 0, 184, 108], [-218, -216, 0, 0], [0, 0, 48, 16], [0, 0, 128, -96], [48, 90, 0, 0], [96, -197, 0, 0], [408, 246, 0, 0], [732, -49, 0, 0], [0, 0, 28, -90], [38, 288, 0, 0], [0, 0, 42, 140], [384, -71, 0, 0], [0, 0, 280, 24], [0, 0, -174, -48], [494, -144, 0, 0], [-74, -144, 0, 0], [54, 169, 0, 0], [0, 0, -252, -80], [0, 0, 100, 222], [0, 0, 312, -30], [0, 0, -252, 32], [0, 0, 174, 248], [0, 0, -324, -48], [0, 0, 72, 12], [558, 59, 0, 0], [-738, -149, 0, 0], [0, 0, -108, 108], [274, -504, 0, 0], [0, 0, -144, 164], [454, 324, 0, 0], [0, 0, -12, -222], [912, 66, 0, 0], [0, 0, 72, -244], [-168, 553, 0, 0], [0, 0, 284, 258], [-606, -31, 0, 0], [0, 0, -318, 64], [552, -193, 0, 0], [0, 0, 120, -240], [-252, -216, 0, 0], [264, 402, 0, 0], [0, 0, 20, -228], [0, 0, -204, 232], [648, -402, 0, 0], [0, 0, 344, -30], [0, 0, 424, 138], [168, 594, 0, 0], [0, 0, -354, 116], [-24, 581, 0, 0], [-588, -264, 0, 0], [558, 229, 0, 0], [0, 0, 162, -416], [0, 0, -372, -36], [72, -330, 0, 0], [-684, 420, 0, 0], [0, 0, 576, -156], [0, 0, 268, -78], [-684, 233, 0, 0], [0, 0, 348, -184], [0, 0, -534, 132], [0, 0, -48, -268], [36, 36, 0, 0], [606, 173, 0, 0], [-336, -335, 0, 0], [-834, -227, 0, 0], [0, 0, 460, 300], [690, -445, 0, 0], [-62, 1008, 0, 0], [0, 0, 12, 12], [238, -396, 0, 0], [0, 0, -288, 60], [0, 0, 162, 392], [-612, 259, 0, 0], [0, 0, 128, -198], [-432, 113, 0, 0], [-402, -427, 0, 0], [0, 0, -144, -234], [0, 0, 642, 144], [156, 264, 0, 0], [90, -7, 0, 0], [0, 0, -276, 160], [0, 0, 208, -114], [0, 0, 756, -8], [0, 0, 258, 20], [0, 0, -12, -532], [294, -103, 0, 0], [-192, -157, 0, 0], [318, -469, 0, 0], [0, 0, -462, 68], [346, -504, 0, 0], [0, 0, -252, 52], [0, 0, -420, -192], [48, -558, 0, 0], [0, 0, 296, 0], [0, 0, -348, -156], [888, 5, 0, 0], [-130, -792, 0, 0], [378, 647, 0, 0], [0, 0, -150, 0], [-480, -845, 0, 0], [0, 0, -558, -328], [-1380, -204, 0, 0], [0, 0, 176, -360], [990, 319, 0, 0], [0, 0, -648, 200], [336, 1182, 0, 0], [0, 0, -556, -246], [-840, 5, 0, 0], [0, 0, -552, 104], [0, 0, 220, 312], [360, -228, 0, 0], [-1674, 127, 0, 0], [0, 0, 162, 20], [-426, 313, 0, 0], [238, 576, 0, 0], [0, 0, -148, 264], [-324, 684, 0, 0], [0, 0, -240, -324], [-852, -119, 0, 0], [0, 0, -522, 136], [0, 0, -1176, 84], [258, 719, 0, 0], [0, 0, -654, -352], [522, -343, 0, 0], [1260, -48, 0, 0], [744, -324, 0, 0], [-138, 137, 0, 0], [0, 0, -680, -30], [290, -1260, 0, 0], [0, 0, 80, -36], [180, -53, 0, 0], [-1020, 205, 0, 0], [0, 0, -484, 468], [-306, -407, 0, 0], [0, 0, 680, 264], [0, 0, -258, 508], [254, 432, 0, 0], [0, 0, -912, -390], [456, -720, 0, 0], [-1266, -589, 0, 0], [0, 0, 876, 88], [0, 0, -340, -252], [0, 0, 208, 138], [216, 253, 0, 0], [0, 0, 348, 476], [654, 1087, 0, 0], [0, 0, -318, -384], [-528, 258, 0, 0], [1692, -492, 0, 0], [0, 0, -308, 198], [922, -216, 0, 0], [0, 0, 264, 676], [0, 0, 244, 264], [-384, 48, 0, 0], [-666, -1183, 0, 0], [0, 0, 102, 660], [0, 0, -668, -222], [0, 0, 354, 156], [372, 1644, 0, 0], [0, 0, -880, -90], [0, 0, 84, -556], [302, -360, 0, 0], [0, 0, -448, 318], [0, 0, -1016, 204], [-228, 829, 0, 0], [-1822, 180, 0, 0], [0, 0, 150, -464], [0, 0, -304, 120], [0, 0, 990, 20], [0, 0, -460, -480], [0, 0, -816, 336], [418, -144, 0, 0], [954, 43, 0, 0], [0, 0, 928, 270], [0, 0, 260, 126], [0, 0, -444, 726], [0, 0, -456, 764], [0, 0, 246, -736], [1726, -360, 0, 0], [-1290, -665, 0, 0], [0, 0, -990, -232], [-804, 1069, 0, 0], [114, -397, 0, 0], [0, 0, -798, 176], [-936, 780, 0, 0], [0, 0, -320, 582], [-1806, -433, 0, 0], [792, 829, 0, 0], [0, 0, 168, -336], [0, 0, 750, -180], [660, 751, 0, 0], [2808, 305, 0, 0], [90, 1817, 0, 0], [0, 0, 932, -360], [-1966, 468, 0, 0], [-2262, 245, 0, 0], [0, 0, -384, -40], [-1632, -762, 0, 0], [-984, 1157, 0, 0], [0, 0, 120, 88], [-324, -1643, 0, 0], [0, 0, -1032, -164], [-156, -1775, 0, 0], [0, 0, -1412, -414], [0, 0, 930, -140], [-58, 648, 0, 0], [-1142, 1080, 0, 0], [0, 0, 636, 810], [0, 0, -224, 600], [0, 0, 36, -232], [0, 0, -1184, 276], [1464, 955, 0, 0], [0, 0, -268, 708], [0, 0, -1782, 196], [-1750, 1008, 0, 0], [-2426, -468, 0, 0], [0, 0, -404, -414], [-858, -523, 0, 0], [-1630, 180, 0, 0], [0, 0, -52, -1176], [-1392, -222, 0, 0], [0, 0, -284, 42], [-70, -1512, 0, 0], [-894, 755, 0, 0], [0, 0, 256, 84], [978, -1079, 0, 0], [0, 0, 316, 66], [0, 0, -204, -240], [2256, 899, 0, 0], [-2256, -666, 0, 0], [0, 0, -2004, 0]];
    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_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_2352_3_m_d(: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_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_2352_3_m_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![34, 12, 1]>],Snew);
    return Vf;
end function;