
// Make newform 363.6.a.g in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_363_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_363_6_a_g();".
// 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_363_6_a_g();".
// 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 := [-78, -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_363_a();"
function MakeCharacter_363_a()
    N := 363;
    order := 1;
    char_gens := [122, 244];
    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_363_a_Hecke(Kf)
    return MakeCharacter_363_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 := 6;
    raw_aps := [[0, -1], [-9, 0], [-24, 10], [10, -2], [0, 0], [-20, 106], [462, -4], [1468, -4], [2610, 26], [6234, 132], [4664, 608], [3158, -320], [-12486, 728], [-9560, -1240], [-2514, -778], [20088, 594], [10944, -3676], [7072, -2746], [32300, 768], [32274, -3102], [-26546, -320], [-9626, 2130], [5388, 3528], [-30582, 3024], [-92074, 1092], [124698, 5932], [41156, -16164], [35028, -10776], [-94388, -5558], [144114, 12600], [-88058, 11826], [135660, -27312], [44142, 14156], [-172964, -12332], [-110106, 26080], [-191858, -22926], [-137998, -2220], [248180, -7888], [-198852, 9948], [122586, 33156], [24120, -69396], [-291046, 32276], [386646, 5918], [-15950, 49252], [-8214, 45452], [60884, -60332], [161608, 78728], [707840, -63184], [388356, -49584], [213674, 45076], [947250, -61200], [713172, 15660], [30970, 55780], [-407136, 64828], [566562, -68816], [-1142880, -103280], [-356304, -173006], [-185942, 119022], [1086040, 55678], [513294, 32268], [1004056, -100856], [853446, -59376], [1275460, 8388], [-929334, -187662], [2334362, 56208], [1191204, -139346], [402164, -188920], [-1218770, 196920], [899628, -109696], [-591284, -284014], [-1420998, 331560], [-383532, 89612], [2998232, 201176], [285172, 34258], [-2141140, -188560], [3195378, -42286], [3916632, -21174], [1898906, 209132], [761022, 34340], [-2441678, 49220], [3026088, -430516], [3416678, 208592], [3991536, -65544], [1645178, 151640], [-162962, -256502], [1370232, -265220], [-3381882, -278524], [-2582390, -142852], [1600566, 60744], [-1335868, -393580], [-3690468, 119784], [-4630344, -56864], [1509932, 465180], [176316, -121216], [-320860, -123576], [-2978772, 212684], [-6560112, -180366], [-3041154, 198492], [-281360, -269856], [541588, -625790], [-1138604, -693828], [-1443570, -682000], [-472188, -427432], [8913750, 156732], [-1553660, -460044], [1492838, 931060], [-2252232, -91748], [5044614, 1171036], [-2160006, -219758], [4670950, -1001472], [-1253978, -325134], [-14584232, -230874], [366594, -264576], [-8452804, 1174560], [4707968, -384400], [2828838, 746580], [-6476932, 54168], [9903666, -144838], [1343316, -631946], [-9044892, 1178888], [-4690150, -1413052], [12986338, -597612], [3599826, 357396], [3305640, 285332], [2633396, -2482848], [-10624314, 108520], [-4963270, 759684], [7635546, 866130], [7610780, 680380], [-1150772, -95062], [-6381416, 1896768], [16679076, -528436], [-5762104, 3003344], [-11791330, -1804392], [2287542, 1485708], [-17526590, 468804], [-21596472, -318366], [18206224, 859240], [-6627816, 673442], [11415114, -1538208], [-8674088, 3332800], [-22474782, 186308], [7962584, 2347360], [9248460, 2323408], [-5159218, -2438560], [-7526538, 251710], [-6083456, 169182], [-12599574, -1832576], [-4847188, 3358768], [8386686, -2629602], [20980300, -2061166], [-3523470, 547640], [25546820, 773480], [-18304740, -508124], [-2832604, -1986488], [10185762, -3379782], [-12597494, 718438], [-8441250, 2319396], [-43885658, 202944], [36177042, 1471692], [10471332, -2970600], [-21310998, 3539936], [-32686202, -1120838], [-10798224, 2297444], [-588666, -3739860], [10488666, -1262190], [-23836792, 63296], [2571916, -939078], [3690178, -5265108], [35638692, 2920350], [19943292, -4527800], [50949938, 256724], [4308948, -6374516], [19655374, 3309360], [-1778968, 1874136], [-20625750, 1577144], [-8435156, 7166604], [14601900, 4989110], [-33377654, 4194798], [20314396, -3325118], [-14654128, 2139336], [-11878980, -3634352], [-9734242, 108520], [492858, 5748816], [-8792094, -3812262], [17953068, -1475082], [-41838992, 2850110], [-36477700, 3640696], [27606754, 1156980], [27168, -4360520], [-13725682, 2261772], [-13229244, -2241496], [-53185492, 3774496], [4313784, -7273374], [38640132, 2414088], [25460754, -6639096], [34133590, 2429976], [29932010, -1892356], [-64404030, -1532448], [53045160, -5210336], [48016902, 93864], [-66425654, -2332714], [32270954, -548060], [66799486, -4454360], [25150944, 771980], [-6615732, -6203258], [15486884, 6091012], [-56089788, 5819064], [-26863842, 2381652], [-8255284, -6946120], [-27775862, 3135068], [-1473636, 7289430], [-31840, -10975856], [60506316, 3875344], [54418116, -1618308], [-225634, -8473260], [-4415138, 95010], [-1789050, 1517340], [51974442, 757002], [-14263356, 2883462], [-34748912, 296230], [91523038, -620398], [-42126762, 6469740], [77349800, 2079288], [-101407236, 4323072], [59513980, -3194886], [-56160006, 7952136], [-3946554, -9044586], [29912950, -11480270], [-42430932, -4085584], [28656686, -1157392], [-55705208, -2780600], [-46779662, 5496094], [68889150, 3164404], [59306516, -1248016], [36876888, -748600], [36040946, 6501904], [72913590, 7538016], [792408, -1312604], [-31416762, 13563598], [-104342148, 4710568], [47356792, 2291880], [19091264, 3271264], [60548714, 1141276], [-112647882, -6790084], [24130572, -13851180], [-33490276, 10566852], [-25504956, -10807048], [-98153348, -5414212], [-123632268, 6248516], [74144680, -11274602], [39923610, -7419248], [-7337730, 10514670], [-1959970, -12420876], [60962550, 8482776], [7314204, 17699336], [41136422, -15299296], [-100597736, 4968224], [-17026308, -6997314], [135621490, -5668148], [72524026, -12487730], [-6704508, 5217336], [-104353028, 4264386], [-84734900, -2987374], [41460846, -8772468], [37244348, 2005712], [71479404, 1202526], [58752210, 12844848], [19284364, 6434820], [-1125294, 7554708], [-99231742, -9743244], [-112674556, -6177296], [-136178074, 8115980], [217126846, -3656574], [11836774, -22142784], [64382204, -12125268], [-377076, -4124760], [-133576280, -1211474], [70441870, 5325256], [22113564, -19061472], [8690352, -12594280], [-91123300, -16462212], [152195340, -4979228], [-155923340, 2408802], [79407556, 1557604], [28596978, 11850930], [91202390, -12058892], [68714922, 1390716], [134214380, 11731100], [-72432186, 24332444], [-5945448, 13730210], [-162387672, 8469380], [-32037234, 10366524], [35765004, -9467448], [82592188, -11265838], [-134207298, 19698784], [-106879204, 6369956], [-143554752, -17927030], [198891324, -12951600], [115728664, -26502840], [132807082, 20684612], [-131150610, -9056592], [-94023878, 7131334], [48205452, 15107176], [-179184124, 4088688], [201989066, 3300536], [268137516, 6978216], [191004206, 16561744], [-34759002, -6089874], [128859436, 21858314], [-87288996, 32551956], [-185966292, -11011682], [-170299470, 2514216], [-23776732, 989448], [-186135480, -6747864], [14893342, 8054352], [61914660, -19335088], [205966968, -13576792], [142075682, -10950160], [206105922, -184736], [-25635140, -3278084], [-116946466, 28608020], [-242911290, 606616], [-27618532, -26133756], [162270846, 2337452], [202705958, -13666716], [23682500, 17778712], [60442700, 24191160], [-245767332, -13771164], [-47089878, -10949716], [164119096, -13289210], [-40698624, 11532426], [-123162638, 292494], [60684660, 3423536], [-65975480, -21953512], [122536404, 14684856], [-11568118, -1879828], [-128057322, 17900780], [-7563814, -23569072], [-232935050, -8140782], [193769402, 16036356], [-220756074, 8877900], [-65572962, -39557256], [-296956840, 23005248], [-166295424, -3175102], [168237516, -6763576], [227874434, -8967412], [-195939940, 18112848], [-141696228, 26454492], [66065256, -41367438], [17070760, 31258920], [-109044190, -22820072], [149221968, -14027022], [5449174, -38488558], [-46090208, 24670942], [299241450, -16855536], [514810122, -4402254], [119587452, 1272208], [-191299662, 408064], [-132172194, 34816814], [291898984, -18127962], [-88381362, 23660172], [-404977446, 4188378], [-307513836, -5161912], [50156, -36845264], [-229989862, -17080528], [122495838, -42617088], [213478846, -10979310], [23082706, -24998980], [-269063736, -21047052], [278903708, -36414128], [-248522664, -34932232], [298232370, -41672428], [344273830, 13611298], [222867734, -37773592], [-182994732, 1392632], [283693740, -18818396], [248676910, -42784704], [-331653438, 23812128], [606582970, 5055260], [-150452136, -29414606], [54666438, -21581892], [-87878018, -32053038], [100654806, -14981372], [352020184, 18431392], [-477656442, 19682406], [-370066912, -22999352], [-230843530, 17562288], [279622960, -6580464], [65627982, 7936886], [-196401154, 53211276], [285007140, -10482194], [-352107816, 8864996], [-114346900, 1484624], [76022598, -66369762], [-411082094, -19480412], [-231153950, -4701762], [-357188802, -31154460], [283391588, 28190840], [-122009238, 15952972], [-551237840, 8524134], [-311547450, -207188], [74666866, -8735362], [-11613162, -53286900], [304350942, -1004680], [108158698, -45216658], [271109270, 54749464], [-206431326, 10567304], [277695548, -58329504], [-213504996, 41840672], [22197310, 56163104], [-14218002, 72557816], [242998548, -9060464], [2457220, -23093652], [200536750, 10557168], [48995100, 27691494], [295627020, 8506468], [315413660, -16627148], [-458042586, -37963036], [413651028, -2806284], [500895204, 22230470], [478229080, 2715142], [480409842, 33594378], [63928212, 6655496], [267257534, -56380348], [-85045872, 1825506], [-264494580, -52204368], [-370437342, -59063824], [208279652, 31255688], [710109216, -10779232]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_363_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_363_6_a_g();".
// 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_363_6_a_g(:prec:=2)
    chi := MakeCharacter_363_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_363_6_a_g();".
// 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_363_6_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_363_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-78, 1, 1]>],Snew);
    return Vf;
end function;