
// Make newform 294.3.g.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_294_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_294_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_294_3_g_c();".
// 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_294_3_g_c();".
// 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, 2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    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_294_g();"
function MakeCharacter_294_g()
    N := 294;
    order := 6;
    char_gens := [197, 199];
    v := [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_294_g_Hecke();"
function MakeCharacter_294_g_Hecke(Kf)
    N := 294;
    order := 6;
    char_gens := [197, 199];
    char_values := [[1, 0, 0, 0], [1, 0, 1, 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, 1, 0, 0], [2, 0, 1, 0], [-2, 1, 2, 2], [0, 0, 0, 0], [0, 3, -6, 3], [8, 4, 16, 2], [4, -11, 2, 11], [-2, 8, 2, 16], [-6, -9, -6, 0], [30, 0, 0, 0], [24, -12, 12, 12], [20, 36, 20, 0], [14, 14, 28, 7], [-32, 0, 0, -30], [28, 4, -28, 8], [0, 12, -54, 12], [56, 20, 28, -20], [4, -4, -4, -8], [0, 12, 44, 12], [-30, 0, 0, 57], [-8, 26, -4, -26], [-32, 72, -32, 0], [32, -40, 64, -20], [-54, -21, 54, -42], [44, -20, 88, -10], [-84, 27, -42, -27], [28, -52, -28, -104], [42, 3, 42, 0], [0, -24, -2, -24], [-90, 0, 0, -12], [56, 0, 0, -24], [24, 12, -24, 24], [0, 96, 30, 96], [-116, -16, -232, -8], [-126, -60, -126, 0], [0, -54, 4, -54], [-168, -36, -84, 36], [124, -36, 124, 0], [-68, 64, -136, 32], [18, 3, -18, 6], [0, 63, -102, 63], [-16, 76, -32, 38], [-6, 75, -6, 0], [0, 36, 28, 36], [-150, 0, 0, 24], [-4, -68, -2, 68], [64, 0, 0, 30], [-18, -72, -36, -36], [264, -24, 132, 24], [-72, -6, 72, -12], [-210, 108, -210, 0], [150, 0, 0, -93], [-200, 2, -100, -2], [16, 64, 32, 32], [-138, 21, 138, 42], [0, 111, -246, 111], [-388, 59, -194, -59], [-52, 52, 52, 104], [0, 132, 104, 132], [-66, 0, 0, -60], [396, 24, 198, -24], [74, -334, 148, -167], [54, 48, 108, 24], [112, 76, 56, -76], [-136, -116, 136, -232], [18, 396, 18, 0], [-256, -54, -256, 0], [190, 0, 0, 72], [0, -273, 66, -273], [-164, -40, -328, -20], [364, 139, 182, -139], [102, -3, 102, 0], [20, 124, 10, -124], [118, -216, 118, 0], [-128, 0, 0, 162], [116, -172, -116, -344], [0, 216, -78, 216], [348, -48, -348, -96], [-222, -336, -222, 0], [-56, -22, -28, 22], [28, 280, 56, 140], [32, 0, 0, -228], [0, 189, 318, 189], [96, -456, 192, -228], [-6, 156, 6, 312], [522, 207, 522, 0], [-210, 0, 0, -276], [-382, 72, -382, 0], [38, 278, 76, 139], [152, 0, 0, -216], [-168, 144, 168, 288], [224, -148, 112, 148], [0, 114, -164, 114], [198, 0, 0, 315], [-136, 438, -136, 0], [164, -184, 328, -92], [242, 143, -242, 286], [140, -169, 70, 169], [-100, -272, 100, -544], [376, 468, 376, 0], [-436, 0, 0, -216], [0, -60, 750, -60], [-720, -84, -360, 84], [-690, -12, -690, 0], [0, -36, -316, -36], [496, -16, 248, 16], [-168, -336, -336, -168], [110, -307, -110, -614], [0, -669, -6, -669], [48, 528, 96, 264], [-202, 268, 202, 536], [0, -168, 38, -168], [54, 0, 0, 288], [-184, 88, -92, -88], [-160, 0, 0, -684], [0, 672, 66, 672], [-30, -288, -60, -144], [0, 384, 0, -384], [-138, -420, -138, 0], [654, 0, 0, -177], [-472, 304, -236, -304], [292, 0, 0, -636], [678, -15, -678, -30], [0, -147, -1026, -147], [-84, -24, 84, -48], [-234, 0, 0, -60], [14, -144, 14, 0], [-352, -244, 352, -488], [-156, -120, -312, -60], [480, -186, -480, -372], [0, 216, 1028, 216], [246, 0, 0, 723], [-244, 138, -244, 0], [-974, 0, 0, 216], [-634, 89, 634, 178], [304, -520, 608, -260], [724, 37, 362, -37], [152, 88, 76, -88], [-186, 558, -372, 279], [0, 60, -198, 60], [-228, 432, -456, 216], [-882, 276, -882, 0], [0, -468, -280, -468], [810, 0, 0, -111], [560, 286, 280, -286], [580, 304, 1160, 152], [-316, 304, -632, 152], [340, -95, 170, 95], [14, 88, -14, 176], [66, 303, 66, 0], [658, -144, 658, 0], [138, -78, 276, -39], [-1208, 0, 0, -198], [508, -32, -508, -64], [0, 90, -680, 90], [-150, 0, 0, -207], [-484, -426, -484, 0], [-266, 445, 266, 890], [280, 224, 560, 112], [-124, 29, -62, -29], [-258, 117, -258, 0], [-954, 0, 0, 288], [872, 0, 0, 276], [-100, 512, 100, 1024], [0, -1116, 222, -1116], [-184, -472, -92, 472], [0, 90, 916, 90], [648, -564, 324, 564]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_3_g_c();".
// 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_294_3_g_c(:prec:=4)
    chi := MakeCharacter_294_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(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_294_3_g_c();".
// 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_294_3_g_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![36, 72, 54, 12, 1]>],Snew);
    return Vf;
end function;