
// Make newform 1296.3.o.be in Magma, downloaded from the LMFDB on 17 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1296_o();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1296_o_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_1296_3_o_be();".
// 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_1296_3_o_be();".
// 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, -1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 1], [0, 2, 0, -1]];
    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_1296_o();"
function MakeCharacter_1296_o()
    N := 1296;
    order := 6;
    char_gens := [1135, 325, 1217];
    v := [3, 6, 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_1296_o_Hecke();"
function MakeCharacter_1296_o_Hecke(Kf)
    N := 1296;
    order := 6;
    char_gens := [1135, 325, 1217];
    char_values := [[-1, 0, 0, 0], [1, 0, 0, 0], [-1, 1, 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], [6, -6, -1, 1], [-4, 2, 2, -4], [12, -6, -2, 4], [-7, 7, 6, -6], [-12, 0, 0, -5], [-2, 4, 20, -10], [-6, -6, 6, 6], [0, -6, -1, 0], [12, 12, 4, 4], [5, 0, 0, -18], [0, 0, 24, -24], [-36, 18, 2, -4], [0, 0, -8, 16], [36, 0, 0, -12], [0, 0, 32, 32], [0, -17, 30, 0], [34, 34, -6, -6], [54, -108, 28, -14], [49, 0, 0, 48], [-92, 46, -10, 20], [-120, 60, -4, 8], [-24, 0, 0, -31], [0, 2, 24, 0], [0, -108, -36, 0], [44, 44, -12, -12], [-12, 24, 88, -44], [91, 0, 0, -6], [120, -120, 55, -55], [30, -60, 52, -26], [18, 18, 62, 62], [0, -84, 43, 0], [20, 20, -4, -4], [-42, 42, 13, -13], [-104, 52, 36, -72], [-149, 149, 78, -78], [56, -112, 80, -40], [-150, -150, 14, 14], [0, 174, -37, 0], [96, -192, -16, 8], [118, 0, 0, -48], [-156, 78, 10, -20], [61, -61, 60, -60], [-66, 0, 0, -47], [-64, 128, 112, -56], [38, 38, 22, 22], [36, -18, 22, -44], [84, -42, 10, -20], [-67, 67, -150, 150], [192, 0, 0, 65], [132, 132, 4, 4], [0, 107, 108, 0], [-54, 108, -28, 14], [-264, 264, 113, -113], [-240, 120, 48, -96], [-114, 0, 0, -61], [70, -140, -156, 78], [0, -166, -144, 0], [0, -312, 41, 0], [48, 48, 8, 8], [-30, 30, -229, 229], [-204, 408, -120, 60], [180, 180, -68, -68], [0, 253, -108, 0], [0, -30, -299, 0], [260, -130, 22, -44], [-94, 94, 312, -312], [138, 138, -90, -90], [0, -218, 24, 0], [0, -288, 144, 0], [78, -156, -292, 146], [440, -220, 36, -72], [-122, 122, -192, 192], [-20, 40, 184, -92], [-30, -30, -138, -138], [0, 180, -156, 0], [17, 0, 0, 42], [348, -348, -139, 139], [659, -659, -36, 36], [-132, -132, -188, -188], [0, -55, -198, 0], [-132, 264, -120, 60], [-109, 0, 0, -156], [240, -120, 144, -288], [-96, 48, 72, -144], [-144, 0, 0, 312], [0, 227, -156, 0], [0, 468, -252, 0], [-232, -232, 136, 136], [-156, 312, 40, -20], [84, -42, 2, -4], [20, -40, 232, -116], [186, 186, -50, -50], [126, 126, -66, -66], [12, -24, -232, 116], [-36, 36, -156, 156], [720, 0, 0, 168], [-314, 628, -12, 6], [319, 0, 0, 54], [752, -376, -96, 192], [-30, 0, 0, -347], [96, 96, -24, -24], [0, -132, 101, 0], [-272, -272, 16, 16], [23, 0, 0, 528], [-372, 186, 94, -188], [-312, 0, 0, 233], [444, 444, 60, 60], [0, 529, -96, 0], [-70, -70, -310, -310], [458, 0, 0, -144], [-120, 120, 329, -329], [-1064, 532, -12, 24], [-380, 760, 88, -44], [0, -84, 259, 0], [-84, -84, -348, -348], [306, -612, 308, -154], [-396, 396, 12, -12], [-1356, 678, 10, -20], [-821, 821, 222, -222], [0, -395, 204, 0], [0, 36, -12, 0], [480, -960, -80, 40], [228, -114, 22, -44], [822, 0, 0, -205], [0, -379, 30, 0], [-342, 684, 52, -26], [-780, 390, 6, -12], [314, -314, 0, 0], [24, -48, -128, 64], [120, 120, 240, 240], [334, 334, -50, -50], [406, 0, 0, -432], [204, -204, 389, -389], [-875, 875, -348, 348], [510, 0, 0, 361], [-134, -134, 282, 282], [174, -174, 445, -445], [300, 0, 0, -187], [552, -1104, 272, -136], [0, 330, 373, 0], [688, 688, 56, 56], [126, -252, 588, -294], [262, 0, 0, -384], [420, -210, -222, 444], [0, -218, -144, 0], [0, 780, -173, 0], [392, 392, -112, -112], [-246, 492, 308, -154], [367, -367, -198, 198], [-1080, 0, 0, 48], [140, -280, 760, -380], [-54, -54, 454, 454], [424, -212, 140, -280], [-900, 450, -50, 100], [798, -1596, 180, -90], [0, -924, 317, 0], [-193, 0, 0, 432], [-42, 42, 349, -349], [732, -366, 126, -252], [660, 0, 0, -355], [106, 106, 282, 282], [210, -420, -28, 14], [720, -720, -216, 216], [-648, 324, -52, 104], [134, -268, 276, -138], [0, -929, 30, 0], [13, 0, 0, -852], [1332, -1332, 12, -12], [-384, 192, -104, 208], [247, -247, -462, 462], [468, 468, 164, 164], [0, 215, 288, 0], [806, 806, 46, 46], [648, -648, -144, 144], [-420, 210, -430, 860], [-1014, 0, 0, 359], [-140, 280, -712, 356], [0, 1015, -402, 0], [904, -452, -20, 40], [444, -222, -194, 388], [-103, 103, 30, -30], [360, 0, 0, -672], [-120, -120, -200, -200], [0, 294, 745, 0], [-1589, 0, 0, 138], [476, -238, -238, 476], [-526, 526, 480, -480], [870, -1740, -484, 242], [409, 0, 0, 528], [-2328, 1164, 52, -104], [38, -76, -1132, 566], [0, 534, 539, 0], [30, -60, 828, -414], [-432, 432, -96, 96], [-1415, 1415, -24, 24], [0, -358, -480, 0], [0, -816, -319, 0], [-834, 1668, -388, 194], [150, -150, -49, 49], [724, -362, 206, -412], [842, -842, -744, 744], [0, -145, 528, 0], [-702, 1404, -668, 334], [-540, 0, 0, -876], [-818, 1636, 260, -130], [900, 900, -132, -132], [0, 1080, -240, 0], [-350, -350, -134, -134], [674, 0, 0, -888], [606, -606, 157, -157], [244, -122, 198, -396], [1092, -546, 74, -148], [564, 564, -404, -404], [0, 718, 504, 0], [-690, -690, 422, 422], [0, 516, -187, 0], [-252, 504, 856, -428], [150, -150, 47, -47], [-295, 295, 654, -654], [-210, -210, -354, -354], [12, -12, -1181, 1181], [204, -408, 8, -4], [-312, -312, -152, -152], [0, -1385, 78, 0], [0, 72, -624, 0], [-114, 228, -1332, 666], [2288, -1144, 248, -496], [1752, -876, 132, -264], [965, -965, 162, -162], [426, -852, 796, -398], [54, 54, 718, 718], [-696, 696, -583, 583], [-1144, 572, 260, -520], [-1008, 504, 632, -1264], [443, -443, -444, 444], [-828, 0, 0, 924], [732, 732, -284, -284], [-66, 132, -852, 426], [2172, -1086, 22, -44], [-662, 1324, -84, 42], [-164, -164, 444, 444], [-1702, 0, 0, -144], [504, -504, -912, 912], [516, -258, -750, 1500], [-338, 676, -1276, 638], [-486, -486, -610, -610], [852, 852, 196, 196], [468, -936, -1016, 508], [905, -905, 678, -678], [312, 0, 0, 919], [960, 960, -112, -112], [0, -289, 960, 0], [0, -1086, -217, 0], [-534, 1068, -844, 422], [1291, 0, 0, 642], [1524, -762, -370, 740], [1038, 0, 0, 803], [-1294, 0, 0, 72], [320, -160, -560, 1120], [-744, 372, 300, -600], [-367, 367, 606, -606], [26, 0, 0, -24], [-504, 504, -840, 840], [-24, 12, -44, 88], [42, 0, 0, 397], [0, 1968, -401, 0], [228, 228, 724, 724], [-570, 570, -889, 889], [979, -979, 1206, -1206], [314, -628, -1300, 650], [0, 770, 648, 0], [664, 664, -144, -144], [239, -239, -384, 384], [308, -616, -792, 396], [-816, -816, 0, 0], [0, 187, 642, 0], [-1153, 0, 0, 672], [-2424, 1212, -428, 856], [168, 168, -152, -152], [540, 540, -196, -196], [1680, -840, 304, -608], [0, -557, -6, 0], [-940, -940, 516, 516], [-1452, 2904, 760, -380], [2965, 0, 0, -84], [-540, 540, 1596, -1596], [596, -298, -954, 1908], [816, 0, 0, 1303], [0, -540, -396, 0], [426, -852, 1332, -666], [1056, -1056, -65, 65], [468, 468, 436, 436], [0, 1519, -402, 0], [3126, -3126, 13, -13], [224, -112, -32, 64], [0, -1518, 1127, 0], [210, -420, -1452, 726], [1528, -764, -412, 824], [565, -565, -1284, 1284], [1044, 0, 0, -1092], [126, -252, 2084, -1042]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1296_o_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1296_3_o_be();".
// 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_1296_3_o_be(:prec:=4)
    chi := MakeCharacter_1296_o();
    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_1296_3_o_be();".
// 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_1296_3_o_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1296_o();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![1089, -396, 111, -12, 1]>,<7,R![576, -288, 24, 12, 1]>,<11,R![5184, -2592, 504, -36, 1]>],Snew);
    return Vf;
end function;