
// Make newform 1152.3.m.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1152_m();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1152_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_1152_3_m_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_m_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 := [8, -8, 6, -6, 3, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [8, -2, 4, -3, 0, -1], [4, -14, 8, -5, 4, 1], [12, 2, 8, -9, 4, -3], [-20, 14, -8, 9, -4, 3], [20, -10, 16, -7, 4, -5]];
    Rf_basisdens := [1, 4, 4, 4, 4, 4];
    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_m();"
function MakeCharacter_1152_m()
    N := 1152;
    order := 4;
    char_gens := [127, 901, 641];
    v := [2, 1, 4];
    // 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_m_Hecke();"
function MakeCharacter_1152_m_Hecke(Kf)
    N := 1152;
    order := 4;
    char_gens := [127, 901, 641];
    char_values := [[-1, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0], [1, 0, 0, 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, 0, 0, 0], [-1, 1, -1, 0, -1, 0], [0, 0, 1, 1, 0, 0], [-4, -4, 0, -2, 0, -1], [1, 1, 0, -1, 0, 3], [-2, 0, -1, -1, -3, -3], [-4, 4, 2, 0, 1, 0], [-8, 0, 1, 1, 2, 2], [-1, -1, 0, -1, 0, 7], [0, -24, 2, -2, 2, -2], [-7, 7, -5, 0, 7, 0], [0, -8, 6, -6, 6, -6], [16, 16, 0, -8, 0, -1], [0, -24, -2, 2, -10, 10], [15, -15, 1, 0, 5, 0], [32, 32, 0, -4, 0, -3], [-7, -7, 0, -5, 0, -1], [44, -44, 14, 0, 5, 0], [56, 0, 1, 1, 18, 18], [0, -24, 11, -11, 13, -13], [0, 64, 4, -4, -20, 20], [56, -56, 0, 0, 9, 0], [0, 8, -5, 5, 13, -13], [2, 0, -11, -11, 15, 15], [23, -23, -15, 0, 13, 0], [-40, 0, 11, 11, 26, 26], [-60, -60, 0, -6, 0, -5], [-71, -71, 0, -15, 0, -15], [-2, 0, 2, 2, 22, 22], [0, -104, 22, -22, 6, -6], [-28, 28, 26, 0, 3, 0], [0, -8, 8, -8, -20, 20], [8, 8, 0, -20, 0, 19], [-57, 57, 19, 0, 19, 0], [24, 0, -21, -21, -22, -22], [-7, -7, 0, -25, 0, -29], [16, -16, 16, 0, 31, 0], [-32, 0, 7, 7, -24, -24], [111, 111, 0, -15, 0, -35], [24, -24, -8, 0, -15, 0], [-119, 119, 5, 0, -27, 0], [0, -104, 22, -22, 6, -6], [2, 0, -7, -7, -5, -5], [-97, 97, -9, 0, -57, 0], [48, 0, 21, 21, -12, -12], [32, -32, -36, 0, -61, 0], [0, 72, -6, 6, -6, 6], [0, 0, -40, 0, 41, 0], [-63, 63, 37, 0, 77, 0], [0, -8, -35, 35, -5, 5], [0, 192, -12, 12, -4, 4], [130, 0, 45, 45, 39, 39], [-40, -40, 0, -24, 0, 25], [30, 0, 26, 26, -2, -2], [-248, 0, 13, 13, -2, -2], [-201, -201, 0, 31, 0, -49], [0, -24, -34, 34, 22, -22], [145, -145, -45, 0, -73, 0], [0, -88, 29, -29, 3, -3], [124, 124, 0, 18, 0, -39], [175, -175, 55, 0, -9, 0], [164, -164, -18, 0, 45, 0], [304, 0, 19, 19, 36, 36], [0, 152, -22, 22, -30, 30], [127, 127, 0, 51, 0, 67], [-220, -220, 0, 18, 0, -111], [34, 0, -32, -32, -96, -96], [32, 32, 0, 68, 0, -75], [65, 65, 0, 49, 0, 9], [-162, 0, 6, 6, -62, -62], [-376, 0, -35, -35, 14, 14], [0, 24, -30, 30, -86, 86], [-207, 207, 47, 0, 11, 0], [128, 128, 0, -12, 0, -77], [0, -336, -36, 36, -36, 36], [-137, 137, 29, 0, 17, 0], [249, 249, 0, -3, 0, 53], [62, 0, -37, -37, -15, -15], [0, 56, 58, -58, -62, 62], [-132, 132, -34, 0, -89, 0], [-159, 159, 13, 0, -155, 0], [0, 96, 28, -28, 100, -100], [-62, 0, 37, 37, -17, -17], [96, 0, 25, 25, -56, -56], [116, 116, 0, -82, 0, -137], [-66, 0, 11, 11, -79, -79], [0, -152, 58, -58, 74, -74], [-281, -281, 0, -21, 0, 35], [0, 16, 8, -8, 112, -112], [140, -140, -30, 0, 147, 0], [0, -264, -10, 10, 54, -54], [-288, 0, -39, -39, -40, -40], [-72, -72, 0, 108, 0, 85], [16, -16, -36, 0, -109, 0], [280, 0, -7, -7, 26, 26], [135, 135, 0, -27, 0, 97], [0, -72, -64, 64, 52, -52], [44, 44, 0, -26, 0, 117], [9, 9, 0, 27, 0, 15], [28, -28, -18, 0, 181, 0], [223, 223, 0, -35, 0, -111], [420, -420, 22, 0, -57, 0], [0, -312, 0, 0, -52, 52], [-68, -68, 0, -86, 0, 1], [66, 0, 28, 28, 52, 52], [-236, -236, 0, 90, 0, 203], [-418, 0, -60, -60, -116, -116], [128, 0, 95, 95, -16, -16], [0, -200, 17, -17, 183, -183], [0, -480, 16, -16, -32, 32], [-95, 95, -59, 0, 13, 0], [0, -552, 67, -67, -35, 35], [100, 100, 0, 138, 0, 89], [632, 0, -13, -13, 18, 18], [62, 0, -33, -33, 109, 109], [252, -252, -26, 0, -35, 0], [-296, 0, -151, -151, 26, 26], [-169, -169, 0, -41, 0, -105], [488, -488, 40, 0, -79, 0], [249, -249, 117, 0, 197, 0], [-510, 0, -47, -47, 35, 35], [-57, 57, -59, 0, -135, 0], [-720, -720, 0, -104, 0, -15], [208, -208, 188, 0, 51, 0], [87, 87, 0, -31, 0, -283], [89, -89, 87, 0, 91, 0], [0, -192, 140, -140, 132, -132], [656, 0, 13, 13, -4, -4], [-175, -175, 0, -91, 0, -11], [40, -40, -4, 0, -101, 0], [-304, 0, 43, 43, -148, -148], [0, 544, 84, -84, 44, -44], [-55, 55, -91, 0, 69, 0], [0, 424, 2, -2, -126, 126], [-62, 0, -55, -55, 11, 11], [-121, 121, -199, 0, 117, 0], [248, -248, 88, 0, 47, 0], [-265, -265, 0, -227, 0, 25], [0, 632, -30, 30, -102, 102], [-324, -324, 0, -122, 0, 69], [-369, 369, 105, 0, -195, 0], [144, 0, -35, -35, 140, 140], [356, 356, 0, -74, 0, 63], [89, 89, 0, -37, 0, 127], [80, 0, 155, 155, 220, 220], [-191, 191, -177, 0, 27, 0], [0, 40, 52, -52, 184, -184], [112, 112, 0, -28, 0, 147], [0, -968, 86, -86, 54, -54], [361, 361, 0, 109, 0, 21], [-482, 0, 36, 36, -148, -148], [-140, 140, -74, 0, 85, 0], [464, 0, 91, 91, -52, -52], [-288, -288, 0, -56, 0, -33], [0, 280, -174, 174, -6, 6], [168, 0, 103, 103, 70, 70], [574, 0, -109, -109, -23, -23], [0, -696, 11, -11, 29, -29], [39, 39, 0, 223, 0, 415], [156, -156, 210, 0, 211, 0], [0, -632, -124, 124, 56, -56], [-448, 0, -15, -15, -208, -208], [-56, -56, 0, -260, 0, -267], [-578, 0, 63, 63, 93, 93], [1232, 0, -53, -53, 124, 124], [0, -416, 112, -112, -32, 32], [489, -489, 103, 0, -5, 0], [706, 0, 165, 165, 47, 47], [-697, 697, 79, 0, 167, 0], [116, 116, 0, -34, 0, -57], [33, 33, 0, -251, 0, -59], [-392, 0, 17, 17, 162, 162], [0, 456, 9, -9, -73, 73], [0, 120, -158, 158, -198, 198], [0, -472, 89, -89, -73, 73], [568, 568, 0, 8, 0, 167], [-393, 393, -207, 0, -19, 0], [880, 0, 37, 37, 228, 228], [737, 737, 0, -21, 0, 263], [0, 288, -40, 40, 56, -56], [64, -64, -144, 0, -175, 0], [-383, 383, -87, 0, -199, 0], [0, 312, -21, 21, 229, -229], [0, 1064, 70, -70, -82, 82], [935, -935, 83, 0, 115, 0], [-359, -359, 0, 39, 0, -125], [-344, 344, -116, 0, -53, 0], [0, 1288, -2, 2, -186, 186], [0, -496, -172, 172, -44, 44], [-414, 0, -30, -30, -202, -202], [-320, -320, 0, 56, 0, 193], [924, -924, -126, 0, -95, 0], [-193, -193, 0, -17, 0, 151], [288, -288, 232, 0, 441, 0], [0, 600, 111, -111, -31, 31], [-414, 0, -36, -36, 84, 84], [585, 585, 0, 447, 0, 27], [-130, 0, 36, 36, 172, 172], [-1592, 0, -83, -83, -2, -2], [399, 399, 0, -187, 0, 153], [0, 288, 44, -44, 180, -180], [-479, 479, -81, 0, -485, 0], [1186, 0, -74, -74, -14, -14], [-36, -36, 0, -154, 0, 183], [319, 319, 0, 99, 0, -45], [0, 640, -128, 128, 192, -192], [-440, 440, -108, 0, -219, 0], [0, -424, -79, 79, -313, 313], [-996, -996, 0, -18, 0, -323], [-958, 0, 81, 81, 19, 19], [1159, -1159, 107, 0, -37, 0], [-656, 0, -43, -43, -60, -60], [-244, -244, 0, 2, 0, -245], [-608, 0, 167, 167, 40, 40], [0, -792, -132, 132, -208, 208], [0, 720, -64, 64, -200, 200], [-770, 0, -33, -33, -35, -35], [-16, 0, -205, -205, -124, -124], [-337, -337, 0, 123, 0, -277], [353, -353, -131, 0, -139, 0], [312, 0, 51, 51, -334, -334], [318, 0, 27, 27, -31, -31], [0, -880, -104, 104, 352, -352], [44, -44, 18, 0, 259, 0], [193, -193, 399, 0, 411, 0], [0, -760, -61, 61, -27, 27], [0, 0, -8, 8, 360, -360], [-440, 0, 31, 31, -82, -82], [448, 448, 0, 16, 0, 169], [729, 729, 0, -119, 0, -231], [460, -460, -14, 0, -383, 0], [0, -1168, -68, 68, 28, -28], [0, 312, -161, 161, -255, 255], [864, 864, 0, -104, 0, 527], [0, 432, -88, 88, -320, 320], [1218, 0, 157, 157, 55, 55], [919, -919, -193, 0, -89, 0], [540, 540, 0, 42, 0, 659], [832, 0, -177, -177, -16, -16], [928, -928, -100, 0, 69, 0], [500, 500, 0, -90, 0, 205], [456, 0, -193, -193, -18, -18], [-1087, -1087, 0, -217, 0, -69], [1374, 0, -32, -32, 32, 32], [-192, 0, 159, 159, -304, -304], [0, -488, -2, 2, -2, 2], [604, -604, 190, 0, -89, 0], [600, 600, 0, 140, 0, 291], [0, -144, -16, 16, 440, -440], [625, 625, 0, 25, 0, 145], [670, 0, 166, 166, 34, 34], [1256, 0, 53, 53, -154, -154], [0, -600, 79, -79, -71, 71], [279, 279, 0, 135, 0, 423], [-128, 128, -108, 0, -723, 0], [-23, 23, -135, 0, -255, 0], [-248, -248, 0, -480, 0, -193], [-329, 329, 145, 0, -243, 0], [0, -1384, -42, 42, 230, -230], [0, -176, 164, -164, 164, -164], [-584, 584, -324, 0, 205, 0], [-279, 279, -237, 0, -417, 0], [-575, -575, 0, -135, 0, -479], [1278, 0, 31, 31, 173, 173], [132, -132, -126, 0, -647, 0], [-25, -25, 0, -49, 0, 47], [0, -1368, 67, -67, 85, -85], [-1768, -1768, 0, -32, 0, 175], [-265, 265, -131, 0, -143, 0], [-191, -191, 0, 295, 0, 507], [108, -108, 442, 0, 153, 0], [0, -488, -241, 241, -159, 159], [0, -240, -132, 132, -308, 308], [194, 0, -270, -270, 294, 294], [-840, 0, 115, 115, 306, 306], [-292, -292, 0, 2, 0, -197], [9, 9, 0, -201, 0, 3], [0, 1128, -81, 81, -263, 263], [28, -28, 394, 0, 667, 0], [0, -840, -106, 106, -202, 202], [-2136, 0, -73, -73, -154, -154], [-1880, 0, -315, -315, -90, -90], [305, -305, 93, 0, 901, 0], [472, 472, 0, 100, 0, 75], [0, -1768, 146, -146, -70, 70], [514, 0, -99, -99, 215, 215], [639, -639, -383, 0, -491, 0], [152, 0, 219, 219, 570, 570], [-898, 0, -320, -320, 32, 32], [615, 615, 0, 143, 0, -465], [-972, 972, 110, 0, -417, 0], [0, 1704, 27, -27, -35, 35], [444, 444, 0, -162, 0, 351], [-327, -327, 0, -27, 0, -211], [-921, -921, 0, 185, 0, 477], [0, -920, -126, 126, -62, 62], [-969, 969, -269, 0, 323, 0], [-148, -148, 0, 90, 0, -173], [820, -820, 354, 0, -87, 0], [0, 648, -288, 288, 12, -12], [-1137, -1137, 0, 85, 0, 201], [0, 136, 214, -214, -402, 402]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1152_m_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1152_3_m_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_m_a(:prec:=6)
    chi := MakeCharacter_1152_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_1152_3_m_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_m_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1152_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![8, 136, 1156, -64, 2, 2, 1]>,<7,R![136, -60, 2, 1]>],Snew);
    return Vf;
end function;