
// Make newform 1152.3.e.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1152_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1152_e_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_1152_3_e_a();".
// 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_1152_3_e_a();".
// 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 := [3, -10, 11, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-9, 19, -3, 2], [10, -2, 2, 0], [-42, 88, -12, 8]];
    Rf_basisdens := [1, 3, 1, 3];
    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_1152_e();"
function MakeCharacter_1152_e()
    N := 1152;
    order := 2;
    char_gens := [127, 901, 641];
    v := [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_1152_e_Hecke();"
function MakeCharacter_1152_e_Hecke(Kf)
    N := 1152;
    order := 2;
    char_gens := [127, 901, 641];
    char_values := [[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, 0, 0], [0, 1, 0, -1], [-2, 0, 0, 0], [0, 6, 0, -2], [-8, 0, 1, 0], [0, -1, 0, -2], [8, 0, 2, 0], [0, -6, 0, 4], [0, -13, 0, -1], [-2, 0, -4, 0], [-26, 0, 0, 0], [0, -11, 0, -2], [28, 0, -4, 0], [0, -38, 0, -4], [0, -21, 0, 3], [0, 52, 0, 0], [-30, 0, -4, 0], [84, 0, 2, 0], [0, 22, 0, -8], [-28, 0, -12, 0], [-38, 0, 4, 0], [0, -6, 0, 6], [0, -47, 0, 12], [-88, 0, 2, 0], [0, -79, 0, 5], [-86, 0, -12, 0], [0, 88, 0, 8], [-128, 0, -1, 0], [0, 5, 0, -12], [6, 0, 8, 0], [0, -60, 0, -12], [0, -37, 0, -26], [-36, 0, 22, 0], [0, 47, 0, -19], [-130, 0, -12, 0], [-26, 0, 20, 0], [156, 0, -8, 0], [0, 108, 0, 4], [0, 61, 0, -17], [0, -48, 0, -36], [-48, 0, -1, 0], [0, -172, 0, 4], [-38, 0, 24, 0], [0, 5, 0, -11], [-190, 0, 8, 0], [-28, 0, 14, 0], [166, 0, 8, 0], [0, -106, 0, 26], [16, 0, 21, 0], [0, 139, 0, -20], [0, 8, 0, -28], [84, 0, -14, 0], [0, -14, 0, 34], [0, 103, 0, 16], [0, -4, 0, 32], [0, 225, 0, 17], [366, 0, -8, 0], [64, 0, -13, 0], [0, 13, 0, 16], [-104, 0, -16, 0], [0, 43, 0, 27], [60, 0, -6, 0], [0, 260, 0, 16], [310, 0, 0, 0], [0, -247, 0, -19], [-372, 0, -2, 0], [316, 0, 0, 0], [0, -90, 0, -54], [186, 0, 40, 0], [0, 13, 0, -20], [0, 154, 0, 0], [294, 0, -16, 0], [138, 0, 28, 0], [-288, 0, 14, 0], [0, 248, 0, 20], [0, -181, 0, -71], [-206, 0, 32, 0], [0, 255, 0, -54], [-48, 0, -2, 0], [0, -86, 0, -18], [408, 0, 31, 0], [0, 10, 0, 116], [-58, 0, 40, 0], [6, 0, -24, 0], [0, -78, 0, -18], [0, 65, 0, -30], [136, 0, 50, 0], [0, 155, 0, 13], [-166, 0, 24, 0], [0, -34, 0, -78], [0, -214, 0, 8], [202, 0, -68, 0], [0, -256, 0, 4], [-112, 0, -64, 0], [0, 2, 0, -80], [0, -197, 0, -69], [0, -9, 0, 58], [-368, 0, 66, 0], [376, 0, 63, 0], [44, 0, -36, 0], [0, 527, 0, -27], [0, 78, 0, 6], [0, -533, 0, -22], [568, 0, 12, 0], [126, 0, -40, 0], [0, 276, 0, 32], [0, -285, 0, 84], [0, -350, 0, 28], [-286, 0, -56, 0], [-690, 0, 52, 0], [-206, 0, 96, 0], [0, 221, 0, 88], [560, 0, 12, 0], [-294, 0, 8, 0], [0, -309, 0, -114], [-484, 0, -56, 0], [0, -282, 0, -36], [0, 725, 0, -13], [0, 716, 0, 32], [54, 0, -116, 0], [-94, 0, 8, 0], [0, -551, 0, -37], [0, -486, 0, -42], [44, 0, 40, 0], [0, -425, 0, -73], [184, 0, -59, 0], [0, -194, 0, 112], [-390, 0, -12, 0], [392, 0, 85, 0], [568, 0, 92, 0], [0, -100, 0, 52], [-818, 0, -12, 0], [-528, 0, 89, 0], [0, -111, 0, -118], [-938, 0, -32, 0], [0, -57, 0, -93], [-488, 0, 30, 0], [0, -471, 0, 15], [0, 21, 0, -126], [64, 0, 38, 0], [0, -15, 0, -55], [886, 0, 12, 0], [0, 60, 0, -116], [-224, 0, -33, 0], [0, -1094, 0, 16], [-858, 0, 20, 0], [0, -411, 0, 54], [1212, 0, -4, 0], [0, 796, 0, -52], [-646, 0, -48, 0], [0, 223, 0, 128], [-476, 0, 52, 0], [0, 284, 0, -16], [236, 0, 20, 0], [0, -244, 0, -100], [-242, 0, -88, 0], [0, -369, 0, -30], [-282, 0, -80, 0], [0, 731, 0, 85], [0, 292, 0, 32], [0, 111, 0, 98], [546, 0, 80, 0], [0, 18, 0, -34], [0, -279, 0, -138], [0, -348, 0, -160], [510, 0, 44, 0], [450, 0, 36, 0], [-960, 0, -34, 0], [0, 933, 0, 47], [0, 632, 0, 68], [782, 0, -104, 0], [0, 472, 0, -52], [648, 0, -88, 0], [-1198, 0, 72, 0], [0, 197, 0, 104], [-1552, 0, 52, 0], [0, 295, 0, -43], [-202, 0, -4, 0], [-594, 0, 44, 0], [386, 0, 156, 0], [0, -42, 0, -126], [960, 0, -63, 0], [0, -11, 0, -96], [0, 752, 0, 140], [0, -355, 0, 47], [752, 0, 93, 0], [-840, 0, -44, 0], [-364, 0, -34, 0], [0, 172, 0, -112], [1304, 0, -28, 0], [0, -288, 0, 36], [104, 0, -108, 0], [0, -389, 0, -103], [0, -172, 0, -132], [0, 659, 0, 48], [-194, 0, 64, 0], [1208, 0, 89, 0], [0, -819, 0, 64], [0, 872, 0, 152], [0, 601, 0, -157], [798, 0, 88, 0], [920, 0, 107, 0], [-44, 0, -48, 0], [0, 618, 0, 18], [0, 141, 0, 9], [1498, 0, 28, 0], [0, -662, 0, -190], [0, -341, 0, -268], [-276, 0, 68, 0], [1158, 0, 8, 0], [0, 257, 0, -5], [846, 0, 116, 0], [0, 72, 0, 196], [0, 474, 0, -72], [1078, 0, -120, 0], [98, 0, -140, 0], [0, -819, 0, 98], [0, 648, 0, 204], [0, 417, 0, 171], [392, 0, 195, 0], [-570, 0, -12, 0], [0, -245, 0, 322], [1394, 0, 136, 0], [0, -922, 0, 90], [-1106, 0, -56, 0], [0, 1263, 0, 4], [0, 110, 0, -296], [158, 0, -108, 0], [0, 796, 0, 128], [264, 0, 59, 0], [1180, 0, 96, 0], [1314, 0, -128, 0], [0, -437, 0, 48], [-476, 0, -144, 0], [0, -362, 0, -184], [184, 0, 70, 0], [0, 1071, 0, 61], [0, 470, 0, -22], [0, 886, 0, -116], [0, -234, 0, -18], [-2436, 0, -50, 0], [1962, 0, 8, 0], [-842, 0, 36, 0], [0, -141, 0, -160], [0, 334, 0, -112], [386, 0, 104, 0], [0, -836, 0, 220], [1500, 0, -22, 0], [0, 356, 0, -328], [624, 0, 147, 0], [0, 515, 0, -212], [0, 1102, 0, -196], [-960, 0, -20, 0], [0, -491, 0, 141], [0, 188, 0, -20], [-352, 0, 171, 0], [80, 0, -248, 0], [0, -173, 0, 103], [1102, 0, -40, 0], [914, 0, -196, 0], [0, -656, 0, 12], [-2008, 0, 15, 0], [-426, 0, -196, 0], [0, 365, 0, 86], [2164, 0, -94, 0], [0, -695, 0, 87], [0, -877, 0, 44], [1272, 0, -154, 0], [0, -41, 0, -67], [1058, 0, -108, 0], [1480, 0, -36, 0], [-1344, 0, 40, 0], [-1794, 0, -68, 0], [-2248, 0, 88, 0], [822, 0, -236, 0], [0, 158, 0, 94], [-3214, 0, 16, 0], [638, 0, 16, 0], [0, -1536, 0, -48], [0, 854, 0, 112], [814, 0, -48, 0], [0, 406, 0, -260], [-798, 0, 256, 0], [392, 0, 210, 0], [0, 448, 0, -40], [1652, 0, 86, 0], [0, -545, 0, 265], [-1930, 0, -48, 0], [0, -1555, 0, -188], [0, -275, 0, -117], [0, 708, 0, -120], [0, -863, 0, -236], [0, 960, 0, 300], [1406, 0, 140, 0], [0, 219, 0, -531], [558, 0, 296, 0], [0, -495, 0, -115], [0, 1246, 0, 70], [2168, 0, -114, 0], [1018, 0, 184, 0], [0, -277, 0, -295], [-2942, 0, 8, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1152_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1152_3_e_a();".
// 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_1152_3_e_a(:prec:=4)
    chi := MakeCharacter_1152_e();
    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_1152_3_e_a();".
// 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_1152_3_e_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1152_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![1764, 0, 92, 0, 1]>,<7,R![2, 1]>,<13,R![-24, 16, 1]>],Snew);
    return Vf;
end function;