
// Make newform 912.3.be.f in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_912_be();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_912_be_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_912_3_be_f();".
// 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_912_3_be_f();".
// 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 := [43, -77, 94, -35, 20, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [5, 0, 1, 0, 0, 0], [-6, 2, -1, 0, 0, 0], [34, -56, 34, -26, 5, -2], [63, 41, 109, -13, 14, -1], [-98, 271, -121, 33, -9, -1]];
    Rf_basisdens := [1, 1, 1, 23, 23, 23];
    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_912_be();"
function MakeCharacter_912_be()
    N := 912;
    order := 6;
    char_gens := [799, 229, 305, 97];
    v := [6, 6, 6, 5];
    // 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_912_be_Hecke();"
function MakeCharacter_912_be_Hecke(Kf)
    N := 912;
    order := 6;
    char_gens := [799, 229, 305, 97];
    char_values := [[1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 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], [1, 0, 0, 1, 0, 0], [2, -1, -1, -2, 0, 1], [4, -1, 0, 0, -1, 1], [5, -1, 2, 0, 1, -1], [0, -3, -1, 0, -3, 1], [11, 4, 4, -11, 3, -1], [-2, 0, 5, 5, 2, 0], [0, -3, 0, -20, 3, 0], [-22, 3, -1, 11, 3, 1], [15, -2, -3, -30, -1, -1], [9, -8, -4, -18, 4, 4], [10, -2, 2, 10, 2, 0], [-37, 3, 3, 37, 2, -1], [0, -2, 2, 16, 2, 2], [-26, 0, 9, 13, 0, -9], [-2, -1, 1, -2, 6, -5], [0, -5, -5, 4, 5, -5], [16, -2, -11, -8, -2, 11], [-5, -4, 4, -5, -13, 17], [-17, -20, -20, 17, -14, 6], [-3, -11, 11, -3, 6, 5], [47, 15, 9, 0, 24, -24], [-14, 12, -3, 7, 12, 3], [-23, 0, 0, -23, -7, 7], [0, 3, 11, -109, -3, 11], [8, 25, 22, -16, -3, -3], [33, 13, 11, -66, -2, -2], [41, 6, -6, 41, -11, 5], [21, 9, 16, -42, 7, 7], [148, 4, -10, -74, 4, 10], [25, -16, -16, -25, -25, -9], [0, 9, -9, 155, -9, -9], [0, -5, -2, 137, 5, -2], [-52, -11, -11, 52, -20, -9], [54, -46, -24, -108, 22, 22], [1, 18, 18, -1, 16, -2], [-68, -3, 8, 0, 5, -5], [-180, 9, 2, 90, 9, -2], [-33, -6, 6, -33, 53, -47], [50, 0, -35, -100, -35, -35], [26, 15, -3, -13, 15, 3], [125, 17, -14, 0, 3, -3], [-68, -6, 6, -68, -17, 23], [-41, -17, -12, 0, -29, 29], [0, -19, 48, 11, 19, 48], [-23, 5, -5, -23, 6, -11], [77, -7, 7, 77, 18, -11], [-7, 9, -22, 14, -31, -31], [32, 7, -17, 0, -10, 10], [-67, 36, 36, 67, -17, -53], [-157, 43, -26, 0, 17, -17], [-14, 0, 16, 7, 0, -16], [0, 26, -20, -170, -26, -20], [-90, -14, -27, 45, -14, 27], [-65, 36, 36, 65, 13, -23], [-115, 7, -7, -115, 49, -56], [-148, 12, 12, 148, 10, -2], [263, -9, 23, 0, 14, -14], [16, 71, 32, -8, 71, -32], [14, 6, 6, -14, 20, 14], [186, 16, 18, -372, 2, 2], [5, 22, -22, 5, 49, -71], [-40, 30, 51, 0, 81, -81], [0, 1, 31, -59, -1, 31], [64, 99, 64, -32, 99, -64], [-47, 82, 69, 94, -13, -13], [-16, -2, 2, -16, -39, 41], [-233, 69, 69, 233, 27, -42], [-346, 11, -19, 0, -8, 8], [244, -2, -25, 0, -27, 27], [232, 22, 22, -232, 40, 18], [0, 65, -16, 23, -65, -16], [93, 21, -37, -186, -58, -58], [237, 6, -3, -474, -9, -9], [139, 3, -3, 139, -35, 32], [0, -24, -33, 95, 24, -33], [-248, 32, 32, 248, 27, -5], [73, 19, -19, 73, -67, 48], [98, -73, -67, -49, -73, 67], [431, 37, -42, 0, -5, 5], [-167, -16, 16, -167, 61, -45], [32, -38, -46, -16, -38, 46], [-112, 23, -65, 56, 23, 65], [-28, 61, -61, -28, -25, -36], [0, -43, 39, 289, 43, 39], [35, -27, 49, -70, 76, 76], [380, -49, 25, 0, -24, 24], [-235, 93, 93, 235, 41, -52], [-182, -89, 2, 0, -87, 87], [-274, -50, 78, 0, 28, -28], [0, 45, 63, 79, -45, 63], [174, 38, -2, -348, -40, -40], [115, -32, -32, -115, -75, -43], [-442, 101, 101, 442, 49, -52], [0, -71, -9, -119, 71, -9], [16, -76, -18, -8, -76, 18], [80, -90, -101, -160, -11, -11], [-116, -36, -51, 58, -36, 51], [0, 116, 52, 91, -116, 52], [-118, 57, -16, 59, 57, 16], [0, 9, 87, 167, -9, 87], [37, -23, 39, -74, 62, 62], [222, -66, -40, -444, 26, 26], [256, -1, 44, 0, 43, -43], [-637, 23, 93, 0, 116, -116], [-422, 113, 113, 422, 40, -73], [0, 22, 29, -13, -22, 29], [314, -110, -45, -157, -110, 45], [236, -151, -81, -472, 70, 70], [-141, 6, 67, 282, 61, 61], [487, -116, -116, -487, -65, 51], [0, -69, -16, -712, 69, -16], [34, 35, 20, 0, 55, -55], [0, -6, 169, 98, 6, 169], [14, 64, -64, 14, -88, 24], [170, -91, -91, -170, -89, 2], [203, -117, 73, 0, -44, 44], [259, -39, 75, 0, 36, -36], [710, -16, -3, -355, -16, 3], [-1020, -70, -30, 510, -70, 30], [-300, 1, 21, 600, 20, 20], [66, -88, -132, -132, -44, -44], [63, -9, 48, -126, 57, 57], [-428, 38, 14, 0, 52, -52], [260, -27, -27, -260, -38, -11], [0, -23, 179, 106, 23, 179], [166, -43, -43, -166, 102, 145], [689, -55, -55, -689, -74, -19], [-253, 91, -9, 0, 82, -82], [-460, -69, -69, 460, 3, 72], [23, 35, -35, 23, -47, 12], [0, 200, 215, 0, 200, -215], [-26, -12, -12, 26, -1, 11], [631, -121, 110, 0, -11, 11], [0, 80, -60, 787, -80, -60], [152, -148, -70, -76, -148, 70], [32, -51, -196, -64, -145, -145], [47, 127, 157, -94, 30, 30], [-38, -36, -165, 0, -201, 201], [112, -158, -172, -56, -158, 172], [0, -233, -41, -451, 233, -41], [0, 118, -84, -622, -118, -84], [38, 119, 37, -19, 119, -37], [168, 65, 139, -336, 74, 74], [85, -107, 107, 85, -75, 182], [-29, 118, 118, 29, 48, -70], [270, 30, -30, 270, -88, 58], [0, -78, -37, -622, 78, -37], [210, 24, -90, -420, -114, -114], [-391, -34, 34, -391, 130, -96], [394, 100, -129, 0, -29, 29], [0, 117, 64, -469, -117, 64], [368, 215, 116, -184, 215, -116], [-532, -86, 86, -532, 68, 18], [50, 242, 198, -100, -44, -44], [-374, 117, 26, 0, 143, -143], [-814, -5, -5, 814, 64, 69], [0, 133, -15, -446, -133, -15], [-440, -116, -164, 220, -116, 164], [-557, 60, 60, 557, 97, 37], [164, 9, -9, 164, -114, 105], [431, -97, -97, -431, -30, 67], [232, 110, -110, 232, -58, -52], [-100, 38, 186, 200, 148, 148], [-341, -59, 59, -341, 45, 14], [-565, 145, -145, -565, -56, -89], [0, 92, -30, 199, -92, -30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_912_be_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_912_3_be_f();".
// 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_912_3_be_f(:prec:=6)
    chi := MakeCharacter_912_be();
    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_912_3_be_f();".
// 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_912_3_be_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_912_be();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![29584, -6880, 2288, -184, 56, -4, 1]>,<7,R![47, -1, -11, 1]>],Snew);
    return Vf;
end function;