
// Make newform 363.6.a.j in Magma, downloaded from the LMFDB on 24 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_j();".
// 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_j();".
// 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 := [-44, -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 := [[3, -1], [-9, 0], [34, -10], [148, -10], [0, 0], [102, -38], [430, -60], [732, 12], [-1868, 366], [-3094, -412], [-3936, 344], [-14890, -136], [2534, 712], [7580, 1496], [5188, -2526], [5986, 2206], [9388, -1476], [2638, -2330], [14068, 3200], [-15356, -3098], [-26554, -7536], [-5676, 9482], [30444, -2592], [38666, 15056], [14210, -21300], [24578, -8556], [-36192, 11380], [-5156, 4648], [36070, -310], [206722, -5336], [108036, 31994], [-140564, 31384], [-293918, 13620], [74660, -47244], [-3942, 47728], [-98132, 35754], [-16058, 2996], [-257300, -34368], [113888, 65804], [100602, -6300], [-222828, 61236], [385646, 41452], [140356, -32166], [-126922, -74124], [-611278, -15260], [-220560, 50532], [-168604, 39224], [-274240, -88448], [1176692, 25232], [-68514, -38652], [557398, 87280], [836472, -15780], [517910, -127548], [192668, 182628], [-250430, -36592], [838872, -138872], [1302490, 135422], [1032764, -187034], [454278, 60142], [-1288026, -103788], [-1444740, 16936], [1196794, 183112], [-1173444, 42260], [460500, 111894], [-237894, 78976], [229490, -167646], [1186900, 122472], [-721586, 501288], [-487020, 393896], [1784038, -382142], [-681902, -192104], [2110656, -138652], [2034960, 288920], [2328718, 170114], [3179972, 7408], [-1251124, -345722], [-1516414, 70934], [-1087418, 100740], [2987802, -248452], [242062, -77852], [4865876, 157156], [-3304858, 14920], [5194976, 6992], [779650, 652488], [-440436, 954178], [2592252, -45980], [-569302, 646012], [850750, 590956], [2840546, 135824], [263752, 802620], [-2288500, -141256], [-778272, -711800], [-2543472, 492796], [-1775844, -582784], [-145316, 942728], [-38304, 1062188], [3113450, 218942], [5494866, -690300], [-5178548, 182400], [8555462, -437022], [361948, 68700], [-1732078, 90328], [91412, -859544], [1872902, -826060], [1441844, -285116], [3261666, 115692], [-335524, 265284], [8628046, 34772], [-8708108, 214838], [9862518, -708400], [-4229996, 1778538], [5202278, -1639466], [4580618, 1040384], [13736940, -37520], [-13887176, 424536], [1867562, -1563316], [3143348, 1458696], [-12317772, 63614], [1365810, 1524202], [-10136124, 772664], [-11035106, 78900], [11516486, -865100], [2718466, -625748], [-12031988, -305508], [-16560412, -1044336], [-2593262, 1067552], [3837758, 2082948], [8815260, 144486], [1407328, -2667380], [-1778762, 2665930], [9866900, -644048], [1301152, -938076], [-7291168, -1078904], [17250550, -1621312], [-5908570, -1841068], [-25347146, 697908], [5796466, -2109698], [2333332, -2125768], [15403402, -919410], [-10814442, 1422528], [-13023460, -4704], [4937842, -4900692], [16477496, 427184], [-15581980, 1222536], [2707870, 648384], [-7283748, -4407782], [19421094, -1152226], [21259718, 256272], [-15306908, 344656], [-17034268, -1789222], [20886582, 2466066], [-4933806, -3672856], [9488436, -2848360], [-27104000, -2290276], [1120108, -1417592], [890044, -1060994], [-1521260, 1636574], [9560618, -350212], [-5688602, 567984], [10906010, 2300852], [38670796, 581944], [4625318, -4570208], [36060092, -557358], [30517516, 2620332], [-30309062, 2470996], [-14940236, 3001030], [33372288, -1465672], [-9795250, 3919834], [11971446, 2914460], [11014762, 5564722], [-21622908, 673072], [-20598106, -2675780], [-9052528, -2140284], [23406454, -6808080], [-26083248, 554632], [5603418, -5631352], [9424308, 1555964], [19223018, 3236986], [-6908572, 9223030], [-14079498, 3570034], [6472832, -317040], [-4089716, 8968376], [-26524426, 6300752], [18704470, 7121104], [-1746068, 3326014], [17250202, -5217494], [55047614, -2052514], [-15920076, 2397000], [-41978146, 5516884], [-67279712, -2544880], [8680450, 8158772], [-7993452, -4445872], [-2747588, -1324640], [-26350262, 25870], [-19589948, -3137576], [11329258, -5361608], [-49020962, -6374568], [-41527146, 686612], [65116926, -5393232], [5585448, -1224032], [22063202, -9042808], [10400444, 2479694], [7924334, -1829956], [-34582658, -6365224], [-38740004, -4200780], [32321250, -6432758], [6412312, -11356868], [73762380, 3168528], [-56698058, 164188], [-61689012, -821416], [-75878890, 1135244], [16547066, -9490198], [-36562584, -4621320], [-42274780, 4704624], [-11997456, -10076748], [20154474, -10410740], [25473492, -14781046], [80819102, -7505740], [-4057612, 17066366], [2050626, -419670], [-66214522, -7232538], [23567980, 4733770], [28985834, -3284812], [-47161120, 10836456], [-6828748, -6897808], [22780894, 2665146], [46976298, 9050328], [44260212, 9232434], [-74509316, -4651318], [75131900, 6688768], [56923566, -13766464], [7198308, -1866920], [-105925988, -7428922], [-6649162, 8375436], [-73703372, 4667328], [101124144, -6972904], [83915954, -12286048], [159408410, -837928], [107219068, 133916], [-12585588, 10555354], [38274124, -18647080], [14743308, 3842216], [-24357096, 2745960], [17196998, -14094820], [-51239314, -9312044], [88281456, -8419812], [91897528, -5357356], [-6557492, -17668872], [-36211916, 7206220], [75257272, 10022124], [-98143090, 12673494], [79790814, 14681536], [164781676, -464054], [134925610, 2734556], [-77072318, 20700808], [135274524, 2747360], [57626646, 3176000], [-155854324, 6750128], [95269242, 2032386], [67173358, -14093476], [95319068, 6866934], [-10583172, 14297232], [104929470, 7087778], [124223590, 686578], [-23959814, -2595500], [-213854812, 3808240], [122386242, -3307902], [-143367030, 12185520], [-5325484, 22161316], [15397906, 5858404], [-229600570, 181692], [-30405148, 21529472], [136824666, -15826060], [86910292, -1089990], [-58967090, 11199936], [29581936, -2378740], [-99821932, 10539656], [228124862, -925218], [194394374, 9331368], [-188189900, -1735184], [20519440, -32569680], [22746304, 736940], [133343488, -10154212], [-13864962, 25311458], [-53560764, 21617860], [60701228, -26294218], [-50299886, -18096740], [-126922654, 25608044], [-149212048, 14827948], [205564158, 10090772], [68261402, -31054370], [-27796588, 3239308], [-63665818, 3436964], [-52001012, -11733704], [131026390, -23105918], [78737218, -4379920], [8944760, 21357268], [160024018, 16860326], [47235364, -21927416], [180013140, 9991688], [11343566, -11370700], [69360114, 5329224], [-76578420, 4072078], [-38032996, 22366680], [100605532, 21449888], [-67734830, 6529752], [-22866668, -6427208], [-45870402, 18041256], [102614396, 15652442], [202486414, 22061146], [-146008, -33235900], [-184661846, 7149218], [-245704242, 8679144], [69923628, 346264], [-135712904, -18929360], [-167037786, 8455136], [171470412, -24687520], [90511072, 27889128], [-58872062, -20083440], [97001966, 41794416], [-242886868, -23887716], [-92811798, 23142620], [-60735150, -45379544], [-22471544, 6178196], [-166788730, 7603396], [132720418, 2789468], [4496436, -11341896], [328669636, -2567560], [273606424, 17961700], [-129633326, -3450372], [107890462, 11830742], [-183430214, -19591370], [123058380, -16981498], [-176875164, 8284592], [-165271716, 20687592], [84469796, -56310136], [-20616538, -21752636], [98268350, -11420300], [79499786, 54115504], [98050740, -48481846], [-174518338, -11892228], [249134034, 822420], [-5575414, 10325888], [-164250184, 48297744], [-70096630, 19585630], [125947836, 13866656], [199729502, -45111980], [-155489372, -23462320], [-80842264, -12303244], [337943330, -13377346], [-217166364, -12038536], [136360442, 34085960], [111525754, -41771234], [-184789276, -8539222], [258538086, -41653730], [-63928826, 3513040], [8505628, -41163818], [-103048212, -59183984], [201689966, 44516352], [-185107348, -32665958], [-211682714, -5684250], [-105415018, 30850052], [-294321636, -7261074], [156777180, -19092184], [146001108, 32110368], [101564106, -38116336], [48211938, 3267744], [517930876, -11105430], [-268199058, -45557652], [63158980, 30722332], [-122566220, 10989088], [230307120, -24900280], [25472978, -59998820], [-173243348, 23517482], [200043006, 28983248], [-77246020, -77067848], [10558568, -24351900], [59004830, 754144], [-430990706, 34128880], [-444152290, 5177180], [-139445654, 50919326], [-170801326, -15024028], [257215628, 28483114], [197597726, -48573012], [373953620, 21785184], [197731228, 44771794], [12408880, -51578768], [144200998, -63166816], [63282044, -62092496], [146103044, -448718], [-467395902, 40002052], [348808506, -4935326], [-146023764, -3986548], [130729564, -30495120], [291073612, 50087386], [-185378114, -34214668], [-410667716, -17928474], [194846978, -21439396], [-280761308, -6706776], [-299201710, -15963012], [158170510, 61961334], [-184524886, 57797364], [536053324, -1441658], [-209156366, 1658740], [-80591862, 69399536], [-70468764, 47027334], [255235918, 12077032], [-71062818, 98656952], [30090196, -102487264], [357668108, 42072208], [-522430226, 24652096], [-649429494, 18879368], [-42723420, 70095376], [189842668, -20049396], [-199514282, -42653712], [-519141806, -30737702], [190861592, -21377820], [-179922272, -83832068], [-100800918, -41483140], [-52565952, -31416300], [162228354, -11695078], [-664240218, 9561142], [-708276372, 19078782], [141918572, 30937096], [84882314, 94393756], [463663418, 58594526], [526541148, -45960432], [-545313498, -9140032], [58773124, -56032680], [487653912, -28378504]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_363_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-38, -5, 1]>],Snew);
    return Vf;
end function;