
// Make newform 1152.3.e.h in Magma, downloaded from the LMFDB on 25 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_h();".
// 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_h();".
// 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], [-2, 0, 2, 0], [0, 4, 0, -1]];
    Rf_basisdens := [1, 2, 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_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, 1, 0], [2, 0, 0, -2], [0, -2, 2, 0], [8, 0, 0, -3], [0, 1, -6, 0], [8, 0, 0, -2], [0, 10, 0, 0], [0, -3, -7, 0], [-30, 0, 0, 2], [22, 0, 0, 4], [0, -21, 10, 0], [36, 0, 0, 8], [0, 10, -8, 0], [0, -27, 5, 0], [0, 20, -24, 0], [50, 0, 0, 8], [28, 0, 0, 2], [0, 54, 12, 0], [68, 0, 0, -4], [-122, 0, 0, 6], [0, -78, -14, 0], [0, -17, -28, 0], [40, 0, 0, 26], [0, -33, -13, 0], [-10, 0, 0, -10], [0, -8, 56, 0], [48, 0, 0, 3], [0, -37, 12, 0], [-134, 0, 0, -18], [0, -108, 12, 0], [0, -59, 2, 0], [116, 0, 0, 22], [0, -15, -29, 0], [34, 0, 0, 10], [150, 0, 0, -24], [-124, 0, 0, 28], [0, 124, -36, 0], [0, -93, -47, 0], [0, -96, -20, 0], [-64, 0, 0, 35], [0, -28, -52, 0], [58, 0, 0, -48], [0, 43, 35, 0], [62, 0, 0, 42], [-148, 0, 0, 22], [-102, 0, 0, 30], [0, -162, 14, 0], [-32, 0, 0, 33], [0, 21, 52, 0], [0, -168, -28, 0], [-140, 0, 0, 18], [0, 186, 14, 0], [0, 153, -48, 0], [0, 60, 72, 0], [0, -113, 23, 0], [-46, 0, 0, 22], [-144, 0, 0, -57], [0, -45, 0, 0], [-216, 0, 0, 24], [0, 229, 13, 0], [-204, 0, 0, -62], [0, -124, 40, 0], [-170, 0, 0, -24], [0, 135, 75, 0], [-124, 0, 0, -2], [-164, 0, 0, 8], [0, 174, 94, 0], [10, 0, 0, 100], [0, -45, 20, 0], [0, 26, -180, 0], [154, 0, 0, -26], [-422, 0, 0, 40], [-176, 0, 0, 106], [0, -120, -140, 0], [0, 85, -121, 0], [-510, 0, 0, -4], [0, 321, -2, 0], [16, 0, 0, -106], [0, 194, -38, 0], [-56, 0, 0, 3], [0, -38, -112, 0], [-186, 0, 0, -56], [-6, 0, 0, 46], [0, -246, 106, 0], [0, -1, 166, 0], [-120, 0, 0, 10], [0, -539, 3, 0], [550, 0, 0, 18], [0, 262, -42, 0], [0, 330, 84, 0], [214, 0, 0, -98], [0, 176, -76, 0], [368, 0, 0, 48], [0, -190, -148, 0], [0, 469, 77, 0], [0, 137, 78, 0], [-64, 0, 0, -74], [424, 0, 0, -29], [148, 0, 0, -72], [0, -367, -85, 0], [0, 486, -6, 0], [0, -331, 46, 0], [-280, 0, 0, -52], [158, 0, 0, 0], [0, -652, 40, 0], [0, 381, -148, 0], [0, -174, -56, 0], [66, 0, 0, 0], [338, 0, 0, 26], [130, 0, 0, 92], [0, 67, -40, 0], [304, 0, 0, 20], [-26, 0, 0, -14], [0, -363, -102, 0], [900, 0, 0, -20], [0, -234, 64, 0], [0, -213, -195, 0], [0, -276, -40, 0], [-26, 0, 0, 64], [226, 0, 0, -168], [0, -121, -139, 0], [0, -366, 66, 0], [-12, 0, 0, 156], [0, 569, 1, 0], [968, 0, 0, -47], [0, 510, -140, 0], [-474, 0, 0, 6], [408, 0, 0, 161], [360, 0, 0, 220], [0, -532, -148, 0], [530, 0, 0, 10], [128, 0, 0, -43], [0, 367, -2, 0], [758, 0, 0, 104], [0, 297, 5, 0], [1112, 0, 0, -30], [0, 663, 17, 0], [0, -117, -394, 0], [432, 0, 0, 82], [0, -449, -225, 0], [-982, 0, 0, -38], [0, -20, -172, 0], [1360, 0, 0, 35], [0, 570, 60, 0], [-298, 0, 0, 8], [0, -837, -78, 0], [4, 0, 0, -152], [0, 76, 164, 0], [-694, 0, 0, 76], [0, -415, 0, 0], [28, 0, 0, -248], [0, -228, -104, 0], [20, 0, 0, 160], [0, 252, 212, 0], [-78, 0, 0, -58], [0, -783, 198, 0], [166, 0, 0, -32], [0, -347, 91, 0], [0, 4, -344, 0], [0, 721, -26, 0], [-674, 0, 0, 82], [0, 170, 346, 0], [0, 471, 226, 0], [0, -28, -72, 0], [-350, 0, 0, 2], [18, 0, 0, 336], [-256, 0, 0, 86], [0, 379, 49, 0], [0, -792, -28, 0], [702, 0, 0, -4], [0, -56, -308, 0], [-184, 0, 0, 88], [238, 0, 0, 74], [0, -549, 104, 0], [48, 0, 0, -52], [0, 569, 91, 0], [170, 0, 0, 314], [-34, 0, 0, -96], [-98, 0, 0, 150], [0, -258, -362, 0], [-1008, 0, 0, 125], [0, 427, 336, 0], [0, -288, -164, 0], [0, -765, -79, 0], [-64, 0, 0, 201], [-856, 0, 0, -28], [52, 0, 0, -274], [0, -596, -104, 0], [-1064, 0, 0, 36], [0, 144, -76, 0], [-1928, 0, 0, -44], [0, 485, -185, 0], [0, -380, 340, 0], [0, 77, 320, 0], [-802, 0, 0, -184], [-632, 0, 0, -299], [0, -301, 304, 0], [0, -696, -24, 0], [0, -313, 109, 0], [-286, 0, 0, -202], [-440, 0, 0, -65], [-332, 0, 0, 296], [0, 306, -146, 0], [0, 771, 159, 0], [-698, 0, 0, -274], [0, 1138, -98, 0], [0, 53, -308, 0], [-1004, 0, 0, -16], [38, 0, 0, -48], [0, 31, 85, 0], [2002, 0, 0, -70], [0, 568, 292, 0], [0, -6, 580, 0], [-1226, 0, 0, 8], [1086, 0, 0, -82], [0, 979, 86, 0], [0, 120, -212, 0], [0, 831, 389, 0], [-1096, 0, 0, -265], [-1254, 0, 0, -126], [0, 21, 150, 0], [462, 0, 0, 106], [0, -338, -210, 0], [-418, 0, 0, -148], [0, 17, -372, 0], [0, 14, -388, 0], [1474, 0, 0, 282], [0, 700, -40, 0], [-1096, 0, 0, 79], [68, 0, 0, -300], [158, 0, 0, 498], [0, 1045, -224, 0], [380, 0, 0, -228], [0, -266, -484, 0], [1592, 0, 0, 14], [0, 1073, -365, 0], [0, 606, 350, 0], [0, 870, 144, 0], [0, 462, 18, 0], [788, 0, 0, 254], [214, 0, 0, -366], [-26, 0, 0, 280], [0, 685, 432, 0], [0, 1294, 52, 0], [-1858, 0, 0, 90], [0, -468, -412, 0], [532, 0, 0, -78], [0, -252, -336, 0], [-672, 0, 0, 263], [0, 733, 372, 0], [0, 382, -112, 0], [2368, 0, 0, -36], [0, -293, 523, 0], [0, -916, 116, 0], [272, 0, 0, 191], [1392, 0, 0, 72], [0, -483, -239, 0], [1038, 0, 0, -184], [590, 0, 0, -106], [0, -1024, 284, 0], [536, 0, 0, 211], [902, 0, 0, -432], [0, 243, -686, 0], [-516, 0, 0, -62], [0, 247, -343, 0], [0, 141, 84, 0], [-2120, 0, 0, 90], [0, -55, -173, 0], [242, 0, 0, -544], [-40, 0, 0, -340], [-704, 0, 0, -120], [482, 0, 0, -574], [-264, 0, 0, -24], [1706, 0, 0, -174], [0, 86, 146, 0], [834, 0, 0, 236], [-354, 0, 0, 440], [0, -960, 240, 0], [0, 470, -92, 0], [-1390, 0, 0, 270], [0, 774, 416, 0], [2098, 0, 0, -132], [136, 0, 0, -114], [0, -992, -264, 0], [916, 0, 0, 326], [0, 801, -169, 0], [-1526, 0, 0, -282], [0, -1805, -36, 0], [0, 595, 261, 0], [0, -636, -464, 0], [0, 1503, -68, 0], [0, -432, 732, 0], [46, 0, 0, 288], [0, -1947, -157, 0], [-1262, 0, 0, -186], [0, -257, 75, 0], [0, -138, -102, 0], [376, 0, 0, 402], [218, 0, 0, 16], [0, -75, 455, 0], [-2754, 0, 0, -166]];
    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_h();".
// 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_h(: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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1152_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![100, 0, 28, 0, 1]>,<7,R![-92, -4, 1]>,<13,R![-152, -16, 1]>],Snew);
    return Vf;
end function;