
// Make newform 432.3.o.b in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_432_o();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_432_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_432_3_o_b();".
// 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_432_3_o_b();".
// 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, 32, 0, 36, 0, 11, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [2, 10, 0, 7, 0, 1, 0, 0], [0, 14, 0, -1, 0, -1, 0, 0], [-6, -14, 24, 1, 6, 1, 0, 0], [0, 8, 14, -4, 8, -1, 1, 0], [0, -8, 14, 4, 8, 1, 1, 0], [42, 50, 70, 95, 22, 32, 2, 3], [42, -50, 70, -95, 22, -32, 2, -3]];
    Rf_basisdens := [1, 4, 2, 4, 2, 2, 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_432_o();"
function MakeCharacter_432_o()
    N := 432;
    order := 6;
    char_gens := [271, 325, 353];
    v := [3, 6, 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_432_o_Hecke();"
function MakeCharacter_432_o_Hecke(Kf)
    N := 432;
    order := 6;
    char_gens := [271, 325, 353];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, -1, 0, 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, 0, 0, 0, 0], [0, -1, 0, 0, 0, -1, 0, 0], [0, 0, 0, 0, -1, -1, -1, 0], [-1, -1, 0, -1, 1, 1, 1, 0], [0, 2, 1, -1, 0, 0, 0, 0], [-1, 0, 1, 2, 0, 0, 2, 2], [-2, 4, 0, 0, -3, 3, -2, 2], [14, -7, -1, -1, -1, 0, 0, 1], [-20, 20, 6, 3, -2, 0, 0, 0], [10, -5, -3, -3, 5, 2, 0, -1], [-1, 0, -1, -2, -1, -1, 4, 4], [0, -12, 1, -1, 4, -5, 8, -4], [2, 2, 0, -6, 2, 5, -1, 0], [-18, -18, 0, -2, -5, -3, -7, 0], [27, 0, 3, 6, -9, -9, 0, 0], [48, -24, 4, 4, -9, -2, 0, 5], [4, -4, 2, 1, 4, 4, -4, 8], [2, -1, -3, -3, -9, -3, 0, 3], [-33, 66, -5, 0, -1, 1, 4, -4], [7, 0, 1, 2, -4, -4, -2, -2], [1, 1, 0, 9, 2, 5, -1, 0], [-44, -44, 0, -2, 5, -1, 11, 0], [25, 0, -3, -6, 7, 7, 0, 0], [-4, 4, -6, -3, 1, -8, 8, -16], [-75, 75, -12, -6, -3, 0, 0, 0], [-56, 28, 12, 12, -9, -9, 0, -9], [-44, 88, 6, 0, 13, -13, 6, -6], [-23, 0, 1, 2, -7, -7, -8, -8], [0, -23, -4, 4, -10, 9, -20, 10], [-8, 16, -12, 0, 18, -18, 20, -20], [72, -36, 10, 10, -21, -11, 0, -1], [38, -38, -14, -7, -3, -8, 8, -16], [36, -18, 6, 6, 1, 10, 0, 19], [0, -128, 1, -1, -8, 2, -16, 8], [-61, -61, 0, 15, 6, -15, 27, 0], [0, 7, -10, 10, -8, -17, -16, 8], [24, -48, 12, 0, -12, 12, 4, -4], [56, -28, 0, 0, -7, -17, 0, -27], [-53, 53, -16, -8, 21, -4, 4, -8], [-62, 124, 10, 0, -18, 18, -8, 8], [31, 0, 3, 6, -7, -7, -8, -8], [-20, -20, 0, 0, -11, 5, -27, 0], [0, -80, -1, 1, 16, -11, 32, -16], [110, 0, 0, 0, 2, 2, 0, 0], [-1, 2, -9, 0, 9, -9, 8, -8], [-106, 53, -15, -15, -1, 2, 0, 5], [40, 40, 0, 12, -17, -5, -29, 0], [53, 53, 0, -19, 19, 37, 1, 0], [0, 29, 16, -16, -4, 23, -8, 4], [-170, 0, 10, 20, -7, -7, 2, 2], [22, -11, -33, -33, -5, -4, 0, -3], [29, -29, 16, 8, -14, 4, -4, 8], [12, -24, 26, 0, -5, 5, 26, -26], [0, 137, -2, 2, 4, -54, 8, -4], [11, 11, 0, -5, 12, -17, 41, 0], [13, 0, 5, 10, -27, -27, 28, 28], [122, -244, -18, 0, 6, -6, -12, 12], [59, -59, 36, 18, -15, 12, -12, 24], [250, -250, 22, 11, 26, -2, 2, -4], [20, -10, 12, 12, -71, -35, 0, 1], [0, -127, -6, 6, 0, -37, 0, 0], [24, -48, -30, 0, 9, -9, -18, 18], [-174, 87, 29, 29, -9, -10, 0, -11], [-119, 119, 32, 16, 26, 8, -8, 16], [-46, 46, 34, 17, -36, -20, 20, -40], [83, 83, 0, -15, 34, 31, 37, 0], [0, 11, 6, -6, -4, 14, -8, 4], [-334, 167, 29, 29, -43, -27, 0, -11], [19, -19, -12, -6, -53, 28, -28, 56], [198, -198, -14, -7, -5, -8, 8, -16], [46, -92, 22, 0, -12, 12, -32, 32], [-173, -173, 0, -9, 24, 45, 3, 0], [0, 64, -9, 9, 32, -22, 64, -32], [195, -390, -3, 0, 30, -30, 38, -38], [-296, 148, 4, 4, -11, 15, 0, 41], [-219, 219, 28, 14, -41, 4, -4, 8], [149, 0, 5, 10, 61, 61, 8, 8], [0, 218, -9, 9, 12, 41, 24, -12], [0, -139, 4, -4, -32, 58, -64, 32], [-10, 5, -71, -71, 41, -16, 0, -73], [-196, 196, -38, -19, 64, -8, 8, -16], [86, -172, 22, 0, -8, 8, 40, -40], [-157, 0, 17, 34, 46, 46, -22, -22], [135, 135, 0, -9, -24, -63, 15, 0], [-4, -4, 0, 64, 12, -29, 53, 0], [-147, 0, -25, -50, -22, -22, -2, -2], [188, -188, -14, -7, 53, -28, 28, -56], [132, -132, -74, -37, 70, 16, -16, 32], [350, -175, 27, 27, -67, -52, 0, -37], [262, -524, -48, 0, 13, -13, 6, -6], [71, 71, 0, -45, 8, 43, -27, 0], [146, -292, 66, 0, -48, 48, -88, 88], [-200, 100, 12, 12, 79, 20, 0, -39], [168, -84, -12, -12, 69, -18, 0, -105], [101, -202, 9, 0, 101, -101, 108, -108], [0, -12, 21, -21, -24, 0, -48, 24], [-330, 0, -22, -44, 11, 11, -38, -38], [-103, 206, 57, 0, 21, -21, 48, -48], [-422, 0, 16, 32, 34, 34, 8, 8], [145, 145, 0, 57, 69, 99, 39, 0], [-73, 0, 3, 6, 77, 77, 12, 12], [166, -83, -41, -41, 73, 3, 0, -67], [139, -139, 56, 28, -126, 8, -8, 16], [282, -141, 33, 33, -61, -1, 0, 59], [-115, 0, -1, -2, -26, -26, -22, -22], [118, 118, 0, 54, 46, 83, 9, 0], [79, 0, 19, 38, 101, 101, -28, -28], [176, -88, 68, 68, -55, -21, 0, 13], [118, -118, -34, -17, 25, -20, 20, -40], [324, -162, -66, -66, 19, 19, 0, 19], [17, 0, 57, 114, -123, -123, 24, 24], [0, 524, 5, -5, -40, 13, -80, 40], [161, 161, 0, 45, 57, 87, 27, 0], [-18, 36, 90, 0, 42, -42, 44, -44], [-85, 85, 16, 8, 90, -44, 44, -88], [-798, 399, -15, -15, 39, 15, 0, -9], [-78, 156, 74, 0, -44, 44, -16, 16], [0, -225, -48, 48, 0, -99, 0, 0], [-139, -139, 0, -61, -62, 13, -137, 0], [0, 55, 2, -2, -20, 79, -40, 20], [172, -172, 14, 7, 72, 18, -18, 36], [-159, 159, 60, 30, 81, -48, 48, -96], [-220, 440, 38, 0, 57, -57, 38, -38], [-410, -410, 0, -24, -11, 49, -71, 0], [49, 0, 21, 42, -41, -41, 0, 0], [341, -341, 64, 32, -111, 60, -60, 120], [-192, 384, 16, 0, -64, 64, -128, 128], [213, 213, 0, 21, -48, -87, -9, 0], [0, -64, 3, -3, 36, -54, 72, -36], [1, -2, -93, 0, -24, 24, -82, 82], [176, -88, 56, 56, -127, -15, 0, 97], [-792, 396, -12, -12, -13, -31, 0, -49], [-566, 0, 0, 0, -108, -108, 0, 0], [0, 158, -39, 39, 30, -118, 60, -30], [0, 133, 62, -62, -90, 117, -180, 90], [509, 0, 1, 2, 63, 63, 8, 8], [776, -388, -18, -18, -3, -33, 0, -63], [0, 292, 13, -13, 16, 104, 32, -16], [1, 0, 67, 134, -22, -22, 62, 62], [278, -556, 36, 0, -69, 69, -62, 62], [-796, 796, -2, -1, -6, 4, -4, 8], [-86, 43, 81, 81, -71, 46, 0, 163], [78, -156, 6, 0, 90, -90, 24, -24], [421, 0, -87, -174, 19, 19, -4, -4], [-254, -254, 0, -94, 69, 161, -23, 0], [-812, 812, 18, 9, -18, -36, 36, -72], [248, -248, -14, -7, 60, 34, -34, 68], [-666, 333, -21, -21, 91, 49, 0, 7], [-422, 844, 22, 0, -66, 66, -68, 68], [0, -212, 11, -11, 56, -16, 112, -56], [537, 0, -43, -86, -25, -25, -8, -8], [-370, 740, 12, 0, 27, -27, 2, -2], [-318, 159, 41, 41, 63, 20, 0, -23], [-398, -398, 0, -66, -16, -67, 35, 0], [-195, -195, 0, 73, 64, 147, -19, 0], [558, -1116, -18, 0, 60, -60, 120, -120], [-668, 668, 82, 41, -64, -2, 2, -4], [737, 0, 5, 10, -13, -13, -92, -92], [0, 67, -24, 24, -84, -89, -168, 84], [-67, -67, 0, 49, -111, -155, -67, 0], [133, 0, -49, -98, 126, 126, -50, -50], [-1114, 557, -33, -33, -87, -78, 0, -69], [-175, 350, 57, 0, 29, -29, -24, 24], [0, -723, -58, 58, 32, -136, 64, -32], [-447, -447, 0, 185, -52, -81, -23, 0], [-326, 652, 30, 0, 66, -66, 84, -84], [271, -271, -172, -86, 127, -8, 8, -16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_432_o_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_432_3_o_b();".
// 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_432_3_o_b(:prec:=8)
    chi := MakeCharacter_432_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(997) - 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_432_3_o_b();".
// 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_432_3_o_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_432_o();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![1296, 324, 2133, -729, 3186, -189, 66, 3, 1]>,<7,R![2566404, -446958, -161487, 32643, 12366, 351, -114, -3, 1]>],Snew);
    return Vf;
end function;