
// Make newform 1815.4.a.o in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1815_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_1815_4_a_o();".
// 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_1815_4_a_o();".
// 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 := [-10, -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_1815_a();"
function MakeCharacter_1815_a()
    N := 1815;
    order := 1;
    char_gens := [1211, 727, 1696];
    v := [1, 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_1815_a_Hecke(Kf)
    return MakeCharacter_1815_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 := [[0, 1], [3, 0], [5, 0], [2, -3], [0, 0], [24, -1], [-47, -4], [-42, 9], [-13, -31], [-60, -7], [-81, -21], [-154, 79], [6, 6], [66, 54], [-275, -65], [-463, -1], [-278, 176], [281, -53], [-644, 150], [-74, -125], [204, 32], [521, -69], [90, -165], [-672, 56], [-12, -52], [142, -31], [-118, 319], [611, 295], [238, 86], [-641, -391], [-854, -358], [-278, -452], [1341, -528], [-1109, -276], [-334, -64], [1011, 309], [-146, -3], [182, 420], [-1833, 99], [-662, 140], [312, -466], [722, -800], [-1678, 925], [-2460, -412], [-1062, 898], [-151, 673], [2857, -360], [4332, 203], [-261, 1127], [2241, 133], [5403, -283], [508, 1141], [-123, -462], [-1014, -582], [2173, 866], [-5217, 171], [454, -593], [3105, -1201], [-872, 1646], [-6100, 974], [3318, -2066], [-2839, 1937], [-694, 742], [-600, 872], [1674, 1406], [-2667, -97], [-5511, 320], [5646, -1050], [4335, 1998], [4385, -333], [-9883, 811], [-2264, 1384], [-3078, -2133], [1198, -3145], [1737, -2470], [-1932, 4346], [-9330, -1000], [1996, 77], [-8872, -1120], [-5835, 2535], [-2290, -3380], [3825, 2085], [4336, 2263], [590, -4586], [5371, 333], [-1954, -2617], [2486, 3080], [-7390, 2976], [8420, 2677], [6726, 1090], [-3019, -1336], [-9516, 2793], [-4384, 2997], [-1732, 3896], [-2478, -1981], [-4763, -2189], [1656, 242], [-4290, 3796], [6940, -646], [-16314, 1926], [15814, 1392], [-4441, 5], [-10438, 1181], [8510, 2386], [-123, 201], [3104, 366], [-8993, 2788], [9846, -6252], [5668, -3536], [16294, -3000], [-24854, -457], [2430, -7707], [14248, -533], [11490, -1465], [-14127, 4647], [-13380, 690], [-13998, 3750], [13177, 2873], [-946, -4546], [9216, -6006], [6834, 2414], [-5312, -7080], [19074, -1798], [6290, 4661], [877, -2842], [-4094, 9371], [-3971, -7099], [4894, 6910], [29936, -1293], [286, -2772], [-26549, 4044], [9063, -7939], [23093, -4071], [750, -56], [3966, 3330], [4775, -3210], [12401, -8693], [25696, -1554], [-2154, -5992], [19560, -9420], [-6011, 7740], [-8438, -7268], [12586, 4197], [-9214, 881], [8847, 2661], [-20070, -1541], [-2640, -4329], [20417, 4532], [43404, 784], [2452, -5954], [24060, 681], [-29500, 7772], [-6210, -10558], [-39848, 572], [38550, -3432], [6018, -9825], [25196, 4278], [-11870, 2164], [-17484, 10674], [-14980, -2647], [601, 9038], [-11482, -5060], [6544, 7656], [4658, 4078], [25749, -7553], [-4945, -9553], [5955, -5715], [-46952, -303], [-6471, 4186], [-21045, 3489], [-7968, -11752], [19609, -4777], [-14396, -997], [30336, 6584], [14371, -2793], [8336, 5618], [-2383, 5130], [-35386, -5639], [-38106, -5202], [-16770, 10668], [20290, -16495], [-42936, -5174], [-22400, 2862], [-8568, -11633], [-43843, 5441], [-7584, -10719], [-22982, 1841], [-1134, -7212], [22721, 12871], [30116, -14629], [23262, -678], [12073, -3056], [-44515, 8706], [-22464, -9355], [-16951, 1264], [18632, -823], [-27909, -10944], [9948, 15729], [-45937, 610], [-13836, 6030], [65096, -6118], [1148, 9990], [16424, 13686], [-20316, 13743], [18670, 6478], [12283, 13303], [-2783, 8969], [-26523, -2190], [-8174, -10352], [-8099, -5806], [22686, 10494], [13564, 5066], [-36270, 16354], [44385, -4611], [-38950, -1579], [3665, -16106], [-12134, 9354], [20626, 2318], [-28707, 2103], [-44218, -242], [-55545, 9505], [-38680, 12640], [-60178, -2738], [-6406, 12294], [88958, -5281], [-2362, -552], [-48983, 13570], [-45866, -4195], [61980, 1569], [19760, -13660], [3592, -20595], [-71949, 87], [24087, -31615], [68872, -11786], [17610, -28438], [-45036, -6826], [6761, -22038], [-86242, 818], [-22506, -6632], [-61380, 265], [1173, -29250], [16838, -16893], [-36596, 7212], [8379, 19169], [113409, -218], [41926, -15685], [-14244, 10420], [-35142, 12648], [97850, 3381], [-56532, -6010], [47046, -20764], [-97098, -5146], [20063, 4523], [-39705, 3609], [15910, -11548], [-13920, -12376], [49654, 3816], [-51774, 14882], [41949, -3745], [42124, -2272], [-2882, -9637], [39138, -18771], [-5642, 3876], [54348, 16315], [2428, -34261], [30404, -26504], [-47192, 17345], [-62388, 3718], [-13200, -10526], [-58645, 2873], [30221, -34137], [29070, -19224], [966, 33948], [-27215, -29733], [-14952, -21792], [-29804, -15436], [57267, -9641], [-14019, -29361], [-41477, -16668], [-37702, -8416], [10611, 24365], [-46360, 32460], [14871, 16491], [9715, -19365], [-33248, -30270], [-9964, 6160], [19472, 30966], [-15093, 22587], [-99948, -3804], [-9456, -12002], [60032, 24154], [-16143, 16850], [-84063, -12370], [34212, -30426], [-73780, 16323], [-97160, -15578], [21300, -7722], [-3985, 28703], [-64204, -9016], [-12266, -6528], [78582, -32536], [-12657, -20559], [-1929, 14519], [37593, 13176], [-68906, 22575], [10230, 68], [38511, -24758], [-75675, -17139], [-45110, 763], [20552, -23103], [-65351, 18617], [41178, -27887], [-38102, 9052], [45834, 11078], [157901, 1655], [51553, -14208], [28278, 9290], [83628, -5987], [37946, -15300], [8940, -16884], [-122946, 2615], [96108, 3172], [-8724, 39009], [57972, -34701], [-18484, 42563], [-45821, 6570], [84935, 26646], [-52312, 26112], [-5780, 24466], [22605, 3043], [90935, -15789], [873, 15843], [-47361, 26127], [-53571, 25068], [-3165, -17624], [-134217, -12001], [-38887, 26277], [163529, -86], [39308, -46079], [21188, 2541], [-192576, 1998], [-77236, 27221], [89062, 9208], [57228, 14226], [-47354, -27176], [68866, -11722], [60045, -21411], [147764, 13812], [152376, 2225], [31479, -19553], [31231, -36397], [106870, 2016], [-25824, -6621], [-129148, 4815], [-86386, 33486], [-30183, 33678], [108322, -7382], [-43776, 6416], [-91846, 37748], [169160, 1990], [168828, -8319], [25488, 2224], [38656, 8954], [55746, 29990], [-130682, -10176], [39836, -56592], [-47285, -8255], [161952, 18013], [154423, -13114], [-30542, -34580], [18233, 16422], [56083, 7835], [-11986, -49267], [-17840, 24128], [-166446, 19128], [-60818, 12898], [-91512, 27245], [-177794, -11308], [122348, -36356], [49388, 58620], [-114392, 36071], [169748, 6743], [-54892, 10449], [-86537, 26545], [-27375, -16707], [205632, -16506], [134328, -1480], [106872, -36561], [70284, 17688], [-15499, -42415], [-169523, -5752], [4249, 30859], [121608, 31332], [107004, 13230], [163240, -23240], [-112226, 12426], [104059, 30597], [106096, -30926], [5707, -25390], [-61740, 43718], [45791, -63897], [74881, -22772], [-20938, 28971], [-14589, 13617], [-17136, 41874], [56725, -45093], [-4056, 52727], [-114176, -8480], [31168, 56652], [-33176, 17396], [-187068, -12444], [7486, 42190], [23397, -36334], [189301, 7877], [-182676, -28918], [-187126, 1523], [-92464, 2084], [54524, 25788], [-72342, -21300], [13477, -42937], [111156, -57521], [91704, 26397], [3096, -4988], [-107938, -9340], [-90742, -4248], [11802, -18114], [121011, 5327], [-67972, -52810], [109002, -64191], [167624, 5617]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1815_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1815_4_a_o();".
// 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_1815_4_a_o(:prec:=2)
    chi := MakeCharacter_1815_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_1815_4_a_o();".
// 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_1815_4_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1815_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-10, -1, 1]>,<7,R![-92, -1, 1]>],Snew);
    return Vf;
end function;