
// Make newform 2352.3.m.g in Magma, downloaded from the LMFDB on 20 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_g();".
// 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_g();".
// 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 := [25, -5, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-15, -4, 4, 1], [5, 9, 1, -1], [25, 2, -2, -3]];
    Rf_basisdens := [1, 10, 5, 10];
    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], [0, 0, -1, 0], [0, 0, 0, 0], [0, 7, 0, 5], [7, 0, -1, 0], [-12, 0, 4, 0], [0, -8, 0, -13], [0, 0, 0, -4], [-6, 0, 11, 0], [0, 21, 0, 12], [13, 0, -7, 0], [-6, 0, 10, 0], [0, -22, 0, 5], [0, 14, 0, 0], [-82, 0, -5, 0], [0, -13, 0, -17], [-50, 0, 4, 0], [0, -6, 0, -9], [0, -26, 0, -40], [95, 0, 1, 0], [0, -19, 0, 18], [0, 47, 0, -23], [-60, 0, -2, 0], [28, 0, -31, 0], [-38, 0, -28, 0], [0, -8, 0, 35], [0, 5, 0, 37], [-125, 0, 5, 0], [-118, 0, -14, 0], [0, 31, 0, 74], [0, 35, 0, 61], [-104, 0, -18, 0], [0, 14, 0, -43], [72, 0, -26, 0], [0, -27, 0, 29], [-38, 0, 22, 0], [0, 64, 0, 28], [0, -38, 0, 4], [-176, 0, -26, 0], [0, -140, 0, -58], [107, 0, 23, 0], [0, -80, 0, -78], [-217, 0, 38, 0], [-136, 0, 2, 0], [0, 0, 0, 4], [0, -146, 0, -14], [0, -77, 0, 43], [0, 117, 0, -49], [-13, 0, -45, 0], [-26, 0, 14, 0], [0, -120, 0, -94], [136, 0, 9, 0], [0, 79, 0, 87], [-354, 0, 16, 0], [0, -66, 0, 130], [24, 0, 49, 0], [0, -55, 0, 73], [-5, 0, -121, 0], [-436, 0, 30, 0], [0, -62, 0, 33], [-98, 0, -57, 0], [0, -28, 0, -75], [0, 120, 0, -18], [111, 0, 102, 0], [-362, 0, 79, 0], [0, 200, 0, 13], [-47, 0, 84, 0], [0, -76, 0, -168], [38, 0, -56, 0], [106, 0, 50, 0], [0, 18, 0, 190], [0, -5, 0, -64], [-75, 0, 25, 0], [0, -76, 0, -255], [0, 294, 0, -10], [478, 0, -52, 0], [93, 0, -67, 0], [32, 0, 0, 0], [185, 0, -130, 0], [0, 400, 0, -14], [-265, 0, -51, 0], [0, -100, 0, 130], [289, 0, -57, 0], [0, 45, 0, 45], [0, 27, 0, 87], [-2, 0, -86, 0], [489, 0, 6, 0], [-152, 0, -118, 0], [0, -192, 0, -139], [0, 116, 0, -46], [0, 322, 0, 266], [0, 219, 0, -68], [0, 223, 0, -25], [0, 286, 0, -127], [0, -316, 0, -186], [-432, 0, 1, 0], [-488, 0, -70, 0], [0, 272, 0, 353], [-309, 0, -127, 0], [0, -168, 0, 196], [-292, 0, 207, 0], [0, -73, 0, 9], [298, 0, -2, 0], [0, 442, 0, 41], [-669, 0, 112, 0], [0, 341, 0, 305], [-10, 0, -170, 0], [0, -246, 0, -18], [-641, 0, -76, 0], [0, -253, 0, -244], [-62, 0, 114, 0], [274, 0, 128, 0], [0, 50, 0, 323], [0, 79, 0, 159], [688, 0, -66, 0], [0, 98, 0, 73], [0, 338, 0, -176], [424, 0, -109, 0], [0, 88, 0, -352], [-379, 0, 95, 0], [223, 0, -150, 0], [566, 0, -187, 0], [0, 269, 0, 289], [0, -324, 0, -339], [-94, 0, 291, 0], [-150, 0, 360, 0], [0, 730, 0, 28], [0, -587, 0, 50], [747, 0, 5, 0], [0, -26, 0, -139], [0, 710, 0, -76], [0, 207, 0, 482], [190, 0, 172, 0], [724, 0, 152, 0], [-469, 0, -174, 0], [-386, 0, -96, 0], [0, -166, 0, -150], [-186, 0, 1, 0], [1190, 0, 22, 0], [0, 394, 0, 18], [760, 0, -27, 0], [0, -108, 0, 168], [0, 631, 0, 117], [-65, 0, 215, 0], [0, 144, 0, -4], [-467, 0, 39, 0], [60, 0, -74, 0], [0, 82, 0, 338], [0, -286, 0, 344], [546, 0, -262, 0], [-200, 0, 94, 0], [0, 292, 0, -51], [0, 8, 0, 146], [0, 460, 0, -71], [0, -62, 0, -202], [0, 88, 0, 109], [-830, 0, 264, 0], [107, 0, 108, 0], [-62, 0, -119, 0], [0, 72, 0, -102], [180, 0, -342, 0], [0, -379, 0, -10], [0, -283, 0, -575], [806, 0, 180, 0], [0, -148, 0, -428], [0, -423, 0, 16], [313, 0, -237, 0], [405, 0, 150, 0], [-262, 0, -35, 0], [0, 541, 0, 353], [986, 0, -200, 0], [0, -284, 0, -280], [-575, 0, 200, 0], [0, 207, 0, 474], [504, 0, -380, 0], [0, 422, 0, 431], [-340, 0, 51, 0], [0, -588, 0, 48], [1045, 0, -53, 0], [0, -499, 0, -312], [0, 29, 0, -239], [-509, 0, 261, 0], [188, 0, -258, 0], [0, 318, 0, -84], [-2, 0, 197, 0], [-918, 0, -112, 0], [0, 70, 0, 679], [89, 0, -194, 0], [0, 892, 0, 298], [-255, 0, -344, 0], [0, -99, 0, 203], [0, 532, 0, 356], [-588, 0, -30, 0], [0, 291, 0, 239], [-284, 0, 546, 0], [-1379, 0, 43, 0], [370, 0, 112, 0], [1002, 0, -220, 0], [0, -226, 0, 350], [-524, 0, 139, 0], [0, -48, 0, 13], [-798, 0, -16, 0], [666, 0, -400, 0], [0, -16, 0, 66], [340, 0, 101, 0], [0, 52, 0, 160], [0, -11, 0, 83], [596, 0, -68, 0], [0, 470, 0, -542], [813, 0, -289, 0], [-1182, 0, -239, 0], [0, -335, 0, -635], [0, -411, 0, -135], [0, -428, 0, -540], [-571, 0, -289, 0], [0, -721, 0, 31], [188, 0, -420, 0], [0, -18, 0, 830], [-682, 0, 16, 0], [-1705, 0, 19, 0], [0, 840, 0, 151], [678, 0, 68, 0], [0, -1303, 0, -79], [0, 929, 0, -205], [-982, 0, -246, 0], [44, 0, 362, 0], [0, 276, 0, 434], [0, -31, 0, 78], [0, 388, 0, -402], [-109, 0, -303, 0], [0, -840, 0, -436], [0, -391, 0, -518], [-650, 0, -368, 0], [0, -46, 0, 65], [0, -820, 0, -698], [-1043, 0, -46, 0], [4, 0, 71, 0], [0, -300, 0, -224], [0, 712, 0, 114], [0, -836, 0, -110], [0, -260, 0, 503], [0, 591, 0, -210], [-574, 0, 388, 0], [968, 0, 220, 0], [0, -860, 0, 380], [0, 413, 0, 22], [0, 356, 0, 1062], [0, -136, 0, 24], [0, -1048, 0, -56], [-1697, 0, 357, 0], [2520, 0, -26, 0], [0, -430, 0, -216], [2059, 0, 93, 0], [1422, 0, -265, 0], [0, 423, 0, 1067], [119, 0, 525, 0], [0, -208, 0, -587], [1216, 0, -455, 0], [-1236, 0, 239, 0], [0, -904, 0, -535], [0, -349, 0, 199], [-1329, 0, 81, 0], [-199, 0, -175, 0], [526, 0, -20, 0], [0, 158, 0, -99], [704, 0, 335, 0], [-470, 0, 686, 0], [0, 452, 0, 400], [-2396, 0, -233, 0], [-1203, 0, 265, 0], [0, 174, 0, 770], [1497, 0, 256, 0], [0, 767, 0, -460], [-1080, 0, 119, 0], [0, -972, 0, -1052], [0, 1025, 0, -425], [-1067, 0, 537, 0], [-527, 0, -105, 0], [0, -544, 0, -404], [0, -682, 0, 150], [0, 97, 0, 302], [0, -1084, 0, -886], [1745, 0, -23, 0], [0, -214, 0, -466], [0, 1448, 0, 50], [-467, 0, -558, 0], [2296, 0, -333, 0], [0, 427, 0, 298], [2714, 0, 86, 0], [-1376, 0, -514, 0], [0, -1415, 0, -599], [-1914, 0, -14, 0], [0, -700, 0, 392], [-1763, 0, -3, 0], [-2148, 0, -141, 0], [0, 416, 0, 439], [-2092, 0, 210, 0], [0, -284, 0, 754], [0, -674, 0, 107], [-130, 0, -672, 0], [-1968, 0, 395, 0], [0, -141, 0, -785]];
    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_g();".
// 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_g(: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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![-14, 1, 1]>],Snew);
    return Vf;
end function;