
// Make newform 1152.3.g.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1152_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1152_g_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_g_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_g_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 := [1, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, -2, 2], [0, 2, 6, 2], [0, 4, 0, -4]];
    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_1152_g();"
function MakeCharacter_1152_g()
    N := 1152;
    order := 2;
    char_gens := [127, 901, 641];
    v := [1, 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_1152_g_Hecke();"
function MakeCharacter_1152_g_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], [-2, 0, 0, 1], [0, -1, -1, 0], [0, 1, 2, 0], [-6, 0, 0, -1], [2, 0, 0, -2], [0, -3, 2, 0], [0, -5, 3, 0], [-34, 0, 0, 1], [0, 12, 4, 0], [10, 0, 0, 7], [-2, 0, 0, 4], [0, 13, 4, 0], [0, 6, -2, 0], [22, 0, 0, 1], [0, 11, 0, 0], [74, 0, 0, 7], [0, 9, -6, 0], [0, 9, 1, 0], [22, 0, 0, -6], [0, 22, -10, 0], [0, 29, 8, 0], [-54, 0, 0, -10], [-82, 0, 0, 10], [6, 0, 0, -7], [0, 3, 11, 0], [0, -11, 14, 0], [-110, 0, 0, 7], [78, 0, 0, -16], [0, -16, 8, 0], [0, -5, -22, 0], [14, 0, 0, -12], [0, -3, 12, 0], [-66, 0, 0, 9], [0, 53, 13, 0], [-6, 0, 0, 23], [0, 19, 12, 0], [0, 5, 37, 0], [22, 0, 0, 1], [0, 17, -12, 0], [-46, 0, 0, 23], [0, -8, -32, 0], [78, 0, 0, 26], [142, 0, 0, 17], [0, -41, 7, 0], [0, -9, -4, 0], [0, 20, -36, 0], [0, 73, -16, 0], [82, 0, 0, -49], [-86, 0, 0, 22], [0, 78, 14, 0], [-98, 0, 0, -30], [0, -21, -16, 0], [-338, 0, 0, 0], [0, 49, -7, 0], [-2, 0, 0, -71], [0, 46, -10, 0], [138, 0, 0, -65], [-166, 0, 0, 14], [0, 23, 42, 0], [238, 0, 0, 1], [0, -99, -22, 0], [0, -145, -49, 0], [-350, 0, 0, -4], [126, 0, 0, 1], [0, 35, 34, 0], [258, 0, 0, 56], [0, 111, 44, 0], [-270, 0, 0, -49], [398, 0, 0, 40], [0, -51, -27, 0], [0, 18, 10, 0], [-262, 0, 0, 15], [0, -47, -36, 0], [0, 128, 0, 0], [470, 0, 0, 9], [242, 0, 0, -57], [98, 0, 0, -18], [130, 0, 0, 44], [0, -17, 70, 0], [2, 0, 0, -33], [0, -90, -10, 0], [-258, 0, 0, 82], [0, -79, -15, 0], [0, -75, 10, 0], [-174, 0, 0, -26], [290, 0, 0, 12], [190, 0, 0, 9], [0, -106, -10, 0], [0, -73, -78, 0], [0, -68, 20, 0], [0, 67, -77, 0], [0, 167, 16, 0], [0, 59, 24, 0], [0, -25, -81, 0], [-378, 0, 0, -23], [46, 0, 0, 164], [0, 155, -22, 0], [394, 0, 0, 23], [0, 49, 58, 0], [550, 0, 0, -31], [0, 3, 54, 0], [-50, 0, 0, 132], [0, 51, 30, 0], [-126, 0, 0, -104], [0, 17, -62, 0], [-482, 0, 0, 80], [0, 147, -93, 0], [598, 0, 0, -22], [0, 116, 68, 0], [834, 0, 0, -1], [-422, 0, 0, -82], [0, -129, 150, 0], [0, 185, -47, 0], [-686, 0, 0, -42], [0, 73, -54, 0], [0, -143, -71, 0], [606, 0, 0, 57], [0, 117, 112, 0], [-110, 0, 0, -25], [750, 0, 0, -102], [534, 0, 0, 57], [0, 103, -96, 0], [0, -49, -20, 0], [-714, 0, 0, 9], [330, 0, 0, 103], [0, -150, 26, 0], [0, -195, 77, 0], [-158, 0, 0, 111], [0, -233, -16, 0], [0, 141, 93, 0], [0, 226, 114, 0], [-350, 0, 0, 39], [-354, 0, 0, -124], [110, 0, 0, -70], [-106, 0, 0, -103], [0, -65, 180, 0], [-634, 0, 0, 57], [-258, 0, 0, 164], [0, 199, -18, 0], [-1082, 0, 0, 49], [0, -95, -31, 0], [0, -87, 14, 0], [570, 0, 0, 119], [0, -231, -135, 0], [-790, 0, 0, -17], [206, 0, 0, 36], [0, 313, 28, 0], [0, 12, -140, 0], [-254, 0, 0, 231], [-258, 0, 0, 72], [0, 273, 158, 0], [0, 247, 7, 0], [0, 257, 96, 0], [0, 226, 42, 0], [0, -139, -131, 0], [-654, 0, 0, 38], [-1066, 0, 0, 10], [462, 0, 0, 217], [0, -53, -2, 0], [-82, 0, 0, -140], [0, 247, -105, 0], [0, 23, -56, 0], [-734, 0, 0, -34], [0, 179, -45, 0], [0, -12, -76, 0], [266, 0, 0, -73], [510, 0, 0, 34], [-50, 0, 0, 89], [0, 269, -78, 0], [-526, 0, 0, -241], [0, 385, 153, 0], [-538, 0, 0, 98], [0, -258, -42, 0], [1626, 0, 0, 46], [0, -403, -112, 0], [1830, 0, 0, -7], [0, -21, 123, 0], [810, 0, 0, -81], [0, 136, -152, 0], [0, -175, 192, 0], [34, 0, 0, 255], [58, 0, 0, 254], [0, 218, 82, 0], [-642, 0, 0, 9], [-518, 0, 0, -73], [0, 267, -236, 0], [162, 0, 0, 300], [0, -384, 32, 0], [-398, 0, 0, 120], [0, -301, 68, 0], [0, -255, 150, 0], [-450, 0, 0, 161], [0, -11, -100, 0], [186, 0, 0, 142], [866, 0, 0, -16], [-1094, 0, 0, 71], [62, 0, 0, 224], [0, -455, 17, 0], [-570, 0, 0, -175], [0, 150, -250, 0], [794, 0, 0, -1], [18, 0, 0, 256], [0, -275, -58, 0], [-754, 0, 0, -111], [0, -240, 144, 0], [0, 189, -20, 0], [1962, 0, 0, -26], [0, -193, -130, 0], [-418, 0, 0, -254], [-1330, 0, 0, -135], [0, 37, 85, 0], [0, 333, 170, 0], [0, -91, 213, 0], [-238, 0, 0, -4], [0, -102, -150, 0], [450, 0, 0, -242], [0, -301, -29, 0], [798, 0, 0, 305], [-1486, 0, 0, -49], [0, -615, -95, 0], [-1454, 0, 0, -10], [0, 110, 174, 0], [0, 3, -34, 0], [186, 0, 0, -129], [1066, 0, 0, 246], [0, 196, -92, 0], [0, -293, -189, 0], [0, 603, 164, 0], [1570, 0, 0, -73], [0, -671, -130, 0], [0, 72, 264, 0], [-326, 0, 0, 62], [0, 265, 216, 0], [0, 186, 122, 0], [798, 0, 0, 82], [1358, 0, 0, 41], [0, -431, 174, 0], [0, -355, -195, 0], [0, -67, -320, 0], [0, 439, -62, 0], [0, -193, 167, 0], [-2198, 0, 0, 79], [1598, 0, 0, -24], [0, -517, -5, 0], [0, -20, 68, 0], [0, 571, 194, 0], [0, -551, -256, 0], [0, 150, -346, 0], [-1102, 0, 0, 319], [718, 0, 0, 72], [0, 185, -319, 0], [-714, 0, 0, 218], [750, 0, 0, 201], [0, -463, -276, 0], [578, 0, 0, 423], [0, 85, 296, 0], [-362, 0, 0, 9], [642, 0, 0, 12], [0, 576, -160, 0], [0, -303, 112, 0], [794, 0, 0, -249], [658, 0, 0, 175], [466, 0, 0, -266], [0, -295, -94, 0], [366, 0, 0, -231], [-502, 0, 0, 390], [0, 373, 160, 0], [-1722, 0, 0, 185], [-1222, 0, 0, 159], [0, -39, -98, 0], [1830, 0, 0, -14], [0, -364, 36, 0], [-462, 0, 0, 152], [0, 441, 33, 0], [0, -55, 190, 0], [410, 0, 0, -153], [54, 0, 0, -198], [0, -77, 110, 0], [0, -140, -116, 0], [0, 363, 67, 0], [0, -33, -57, 0], [-1694, 0, 0, 335], [0, 45, -20, 0], [0, 314, 274, 0], [446, 0, 0, -414], [-74, 0, 0, 337], [0, -131, -283, 0], [1854, 0, 0, -184], [62, 0, 0, 41], [0, 507, 382, 0], [42, 0, 0, -314], [0, -255, 162, 0], [130, 0, 0, 631], [-1322, 0, 0, 89], [0, 396, 100, 0], [1918, 0, 0, 121], [0, 353, 134, 0], [0, -99, -354, 0], [1426, 0, 0, -100], [1510, 0, 0, 369], [0, 118, 414, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1152_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1152_3_g_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_g_a(:prec:=4)
    chi := MakeCharacter_1152_g();
    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_g_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_g_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1152_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![-28, 4, 1]>,<13,R![4, 12, 1]>],Snew);
    return Vf;
end function;