
// Make newform 294.4.a.n in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_294_a();"
// 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_4_a_n();".
// 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_4_a_n();".
// 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 := [-336, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_a();"
function MakeCharacter_294_a()
    N := 294;
    order := 1;
    char_gens := [197, 199];
    v := [1, 1];
    // 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;

function MakeCharacter_294_a_Hecke(Kf)
    return MakeCharacter_294_a();
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 := 4;
    raw_aps := [[2, 0], [3, 0], [3, -1], [0, 0], [33, 1], [20, 1], [-48, 4], [20, 3], [72, 4], [33, 11], [-259, -2], [8, -9], [-216, 6], [-46, -15], [294, -12], [-123, 3], [9, -25], [110, 4], [338, 11], [246, -20], [-478, 35], [-259, -8], [-123, 25], [366, 42], [959, 35], [342, 20], [-1216, -21], [87, 45], [-274, -49], [-840, -82], [-1393, -68], [93, -7], [-1710, 50], [-850, 101], [474, -6], [437, 59], [-628, -18], [1160, -132], [1266, 8], [282, -70], [1380, -114], [-1264, -143], [-336, -78], [-811, 222], [-1410, -170], [-2908, 36], [2834, -102], [-4489, 9], [3135, -57], [500, -211], [1944, -62], [3024, -54], [71, 39], [9, 75], [-2370, 48], [5070, 102], [1845, -55], [2009, 247], [-2728, -255], [2406, -38], [2858, 17], [-2007, -9], [3920, -175], [-1152, 86], [2897, 38], [3345, 63], [1532, -147], [-1039, -44], [-3228, 168], [5594, -232], [-1464, -162], [-1878, 218], [5231, -354], [-9280, -157], [-4864, -307], [-1026, -302], [-11934, 68], [-2788, 319], [7512, 264], [143, 366], [1728, -174], [6530, -53], [2604, -246], [-4114, 201], [8681, -41], [-4635, 91], [-10956, 38], [-3865, 518], [-7482, -274], [80, 797], [6636, -502], [-12342, -218], [1019, 282], [2637, -633], [-2146, 101], [-2916, 606], [285, -423], [-13506, -426], [-4132, -675], [6458, 583], [4664, 364], [17163, -301], [20805, -143], [-8580, 690], [18626, -287], [-7249, -544], [7455, -623], [8016, -510], [5178, -1014], [19115, -348], [-7429, 802], [-3976, 538], [-78, 472], [-526, 1259], [-4213, 645], [30570, 82], [-13654, -591], [-366, 420], [-12405, 399], [12936, 688], [12158, -211], [10397, -798], [-3081, -1131], [-18789, 21], [-3088, -627], [3561, -493], [-9442, -744], [-3486, -264], [-2479, -496], [-10474, 823], [-14146, -191], [8046, -1128], [22307, -356], [-10690, 724], [3204, -80], [17045, -910], [5886, 1616], [-3490, 562], [24975, 813], [6480, -958], [5318, 674], [4437, -1127], [-20272, 608], [20061, -627], [-8308, -703], [-5208, 1876], [-30058, -567], [-10626, -1374], [-12826, -486], [-19734, -196], [-8320, 458], [13626, -1782], [-19384, -963], [13056, -846], [6320, 637], [37674, 450], [16880, 1613], [-46038, -384], [13355, 204], [10431, 977], [-17520, -1822], [12234, -962], [-21475, -804], [-25581, -891], [13386, -444], [-5388, 1788], [-8695, 2394], [-18802, 873], [14687, 1758], [19023, 537], [-4977, -1135], [-9946, 1280], [30444, 600], [-17779, 40], [21683, -2204], [-3972, -340], [11990, -473], [28887, 127], [-54136, -72], [17522, 1401], [-4963, -1646], [25959, 1201], [8366, 2087], [2190, 2306], [-9306, 632], [-56013, -255], [-4066, 544], [-2050, -2565], [8579, 2662], [14340, -846], [45953, -472], [-8073, -1221], [27212, -1852], [28818, -410], [-9627, 3123], [-15726, -2714], [39638, 93], [-39370, 1520], [23742, 2004], [27798, 2514], [5259, -381], [25472, -419], [9998, -3360], [5690, 3520], [-34704, 1650], [24969, -3159], [7064, 4152], [-10209, -1965], [12168, -1596], [-59878, 642], [19826, -3699], [30687, 1961], [-45763, 1735], [-22497, 3305], [12756, 3468], [22130, 405], [-28009, 2969], [-37848, 340], [7686, 3226], [-79962, -32], [-24232, 1985], [12416, 1871], [80538, 1116], [-15319, -817], [52371, -669], [-13024, -2934], [-35910, -2714], [-20124, 2210], [-47191, -260], [-5340, 2070], [-52366, -569], [37160, -1756], [28373, 1064], [29982, 4296], [20042, 4101], [33996, 2766], [30851, 602], [-103665, 183], [62964, 1200], [22272, 1850], [-39180, 994], [-38752, 2991], [61103, -744], [-5398, -980], [-33900, 3268], [-22476, -804], [-28699, 916], [22164, 1438], [84656, 960], [-24480, 5400], [-80446, 599], [1266, 2586], [-47094, -780], [79250, -1837], [-94971, 1267], [-639, -2225], [-14806, -4053], [-50308, 1789], [48669, -4471], [-113371, 393], [5912, 1745], [56733, -2509], [58046, 2579], [-130828, -373], [50466, -2028], [-36274, -3127], [68679, 987], [39372, 626], [26684, 296], [10839, -2265], [32576, -2873], [13202, 6474], [-45475, -776], [65483, 3186], [85589, 1085], [17480, -5396], [120303, -653], [115544, -1445], [43574, 749], [64608, 396], [23142, -4398], [62417, -2708], [15948, -198], [-53380, -345], [77942, 670], [-58536, 2962], [-35089, -4070], [-11337, -701], [-23653, -996], [-46188, -3582], [-26718, -534], [-14145, 213], [-43860, -1242], [-52068, -5416], [-67564, 2739], [90975, 471], [-95320, -1509], [110322, -450], [15180, 2658], [-44458, -3317], [-32458, -3184], [-21369, -3237], [24371, -5479], [-13131, 3543], [-59842, -5931], [-31582, -357], [-13923, 2309], [127838, 759], [-129078, 1054], [13646, -3735], [65634, -2394], [-57690, -208], [-84156, -34], [-67168, 4776], [-95664, 1208], [4742, -6165], [-76743, 3537], [97920, -2140], [7037, -7716], [39960, 5514], [-13264, 3147], [87938, -4219], [-34911, -6291], [86648, -2107], [27144, 5006], [-81973, -1290], [-58438, 7071], [-6250, 8261], [39654, -5306], [-110301, -1697], [-90622, 3555], [-137217, 3019], [32648, -77], [-36696, -434], [22298, 9971], [30876, 5510], [-33676, -3842], [-53538, -178], [-61687, -3252], [41927, 3176], [-102394, -4371], [-15084, 3564], [5841, 3315], [52799, 3112], [-23439, -3855], [-142245, -2289], [92222, 1023], [7958, 1302], [2430, 2820], [47193, 3321], [127556, -3192], [-92125, -3153], [79326, -7476], [-73525, 6253], [-27130, -5995], [22314, -7796], [2118, 656], [-39255, -5337], [-41364, 9016], [-37806, 400], [123314, -3136], [115848, -206], [40374, 7316], [86148, -6734], [6080, -12361], [-20701, 6651], [-141570, 1458], [-8944, 5779], [60449, 4877], [-100569, -3263], [106016, -4381], [-15150, -5760], [46977, -1699], [-193096, -2731], [3272, 7493], [-139704, 6660], [216732, 1600], [-32197, -565], [-216198, 754], [-38482, 675], [223122, 2010], [59190, 7214], [150008, -1480], [-4236, -1596], [180950, 3542], [-67410, 5990], [-17848, 1677], [13676, 2786], [180044, -1279], [-142116, -1286], [-69319, 6720], [9906, 6924], [-221115, 2959], [4922, 7743], [-10518, 10244], [-98017, 5539], [192659, -847], [69186, -7712], [159752, -2327], [-19857, 3091], [250148, -414], [67560, 7584], [-114724, 8372], [35850, -2416], [-56499, -315], [-109369, -2748], [72446, 6968], [-52902, 12066], [2150, -2355], [-100899, -1145], [-67897, -6469], [-118845, 3001], [83379, -2387], [93494, 2062], [-53110, -5457], [46197, -4307], [-73044, 9490], [86624, -1933], [106776, 9060], [-252114, 326], [104955, 7681], [-168994, 93], [-53034, 2482], [-176715, -5691], [-95398, -2028], [-9450, 6536], [169887, 4811], [-35424, -1968], [166874, 2818], [-32916, 11620]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_4_a_n();".
// 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_4_a_n(:prec:=2)
    chi := MakeCharacter_294_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_4_a_n();".
// 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_4_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-330, -5, 1]>,<11,R![786, -67, 1]>],Snew);
    return Vf;
end function;