
// Make newform 207.6.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_207_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_207_6_a_a();".
// 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_207_6_a_a();".
// 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 := [-7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 1];
    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_207_a();"
function MakeCharacter_207_a()
    N := 207;
    order := 1;
    char_gens := [47, 28];
    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_207_a_Hecke(Kf)
    return MakeCharacter_207_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, -2], [0, 0], [-47, -1], [-59, -11], [-160, -108], [-144, -74], [905, -13], [365, -311], [-529, 0], [-4104, -266], [886, -1514], [-11556, 206], [-2758, 1372], [5161, -2667], [-21476, 1152], [12675, 4369], [-9172, 508], [18612, -3946], [-3741, 4607], [-63424, -2088], [68830, 2212], [31143, 1479], [-41560, -11124], [-34885, 2317], [-85052, 10274], [-91970, -908], [10035, -1477], [102196, -4696], [-81834, 10136], [112375, 1553], [31470, -31994], [38176, 18356], [-84037, 1933], [308880, -17572], [-258499, 23403], [-135424, 57024], [-59564, -55762], [138234, 58758], [167156, 35780], [-196920, 93766], [-167988, -85588], [-352974, -58316], [-305286, -49774], [-10628, 5910], [127436, 39882], [527727, -104001], [-1030878, -578], [390280, 111400], [186894, -29750], [-161754, 58000], [-680818, -113904], [384292, -45940], [-433416, 27598], [13434, -236746], [-173906, -70344], [116326, 99382], [-69988, -289054], [-66046, 110042], [169750, -12400], [1727307, 12029], [-49417, -188709], [-888073, -180219], [-833474, -242254], [-1164496, -35348], [-159946, -67564], [-741592, -344946], [530554, -289578], [1018352, 21662], [222352, -243208], [715388, -105502], [1436668, -561378], [-1409330, 606430], [208471, -412953], [19660, -251602], [-411551, -451523], [-2651574, -119446], [834811, 758633], [652462, -888480], [-96435, 589703], [-1023236, 100230], [1621792, -582956], [-403666, 773648], [243280, -565560], [2592802, 88160], [-1627960, -443144], [-2698312, -380292], [3005202, -849724], [-1549820, 1206194], [-5250344, 71574], [-326116, -318964], [1142534, 964346], [-4472864, 386696], [-5340792, -622368], [-5509792, 460944], [-3391382, 1232918], [2985940, -341692], [3669636, 707114], [-2030045, 482485], [2284551, 711899], [-5420684, 205442], [9012690, -310514], [-2514065, -1038427], [-11277114, -44670], [4507225, -883141], [-5318353, 1461963], [1335540, 488926], [-5948816, -266804], [2081846, 2108520], [2333244, -740740], [-2551148, -1065706], [-9075876, -626124], [897984, -2021390], [5041575, 1199193], [-5042917, -123561], [-4721009, 2131135], [7644025, -1485533], [-7317135, 1567237], [9919716, 1719432], [-1402354, 2047972], [3421510, 632810], [7872836, 247142], [3085048, -2291766], [-204163, 947131], [-7104292, 1507608], [411534, -1868006], [18834961, -752521], [8963742, -1773192], [-4571716, 1484856], [-7778947, -2120539], [11124442, 2880468], [6384096, -2451468], [14930618, -2702366], [2344305, -1925735], [5919538, -1945804], [-18147308, -1789858], [15859838, -214332], [-9166651, -1026429], [2487857, 1446405], [-17756853, -661327], [-5321148, -3932170], [979910, 2784090], [-16803822, -961144], [-31179558, -660310], [20191262, -1415622], [-22952244, -1965830], [16899314, -3351966], [-10954874, -177408], [3125170, 2383876], [24616400, -2288300], [27276340, -1086696], [5049186, -1625116], [920059, -1268043], [28146246, -1826790], [-2501488, -3281900], [-13411733, -4065777], [-5237260, 4529660], [-23156661, -1940261], [35111546, -1846140], [-24084706, 163140], [24044985, -1776945], [20524324, 2819796], [21516893, -2863825], [-14964150, 5534578], [11681834, -5396258], [1127415, 2206993], [2516524, -4077876], [-2828958, -137062], [24298028, 1733578], [26665084, -212342], [16105474, 6308208], [-56809462, -955962], [-5384558, -2667228], [-12019174, 2817282], [1731844, 3833346], [-11860294, -3104126], [6725425, 3656835], [-17911764, -3940704], [17306146, -2541056], [25594839, 1811415], [33169236, -44858], [7367486, -6648514], [17497034, 8118518], [-14949746, 7700600], [3384936, 4466986], [3348084, -2882676], [9315447, 4484949], [15794302, -2523168], [16906309, -11408375], [48049694, 1631380], [30839368, -10238124], [15194186, 2774264], [-35015180, -8076112], [13713509, 10246873], [-11505626, 8071460], [-9602672, 11948756], [12942401, -10290061], [50705618, 4854824], [-27999826, 863416], [12068077, 5384967], [-37201820, 3252108], [-20153749, 626545], [18205738, 5239386], [-36706874, 2438704], [30219272, 5584054], [22972636, 2434160], [-35383760, 1413846], [-45731403, 4498101], [-54896500, 219972], [19269834, -4674700], [-4626826, 1785882], [-13382174, -2114496], [-5250218, -15890316], [4961177, 5254993], [71829320, -1294636], [1242392, -2109552], [29170358, -8119612], [-36481268, -8762972], [-2976412, 800430], [57644016, -2497928], [-21207530, -13852292], [62408424, 6686550], [-63791791, -8416471], [-14981872, 2936810], [40529111, 6127], [-21114884, -502992], [20090300, -8484878], [22300815, 9397313], [-25302440, 10518572], [-27815815, -16894839], [-78225720, -3789892], [6852988, -12545142], [2544135, -2100637], [-99868755, 1953173], [25936264, -6497134], [-49889541, -12108105], [-79483220, -14996764], [11739424, 25130462], [92832967, -4449899], [-72409024, 8431556], [39801792, -15651060], [-54860486, -21482138], [-27082226, 7272034], [-20918782, -1158558], [-119535716, -2805814], [41603790, 6464168], [42032052, 5743916], [121574058, 13481514], [-122526224, -2023948], [78380383, -14624413], [169705572, 5011044], [-28539786, 12296840], [85249425, 12604731], [69947966, 15685446], [-43141708, -20734526], [46053086, -5210204], [-5886144, -31765076], [-127520674, -12946000], [122996943, -5343877], [-10437740, -10104134], [-91884988, -20113978], [-12592369, -17939161], [-59636612, -6017576], [-85584050, 17011640], [13709576, 29619218], [17985894, -27353520], [-13300189, 6757271], [151924291, -11667191], [-31638003, -31470689], [-137100977, -5847325], [-58355800, 209822], [137413050, 5084444], [1256193, 9582613], [55332804, 21341274], [130187145, -16168167], [83739830, -2653484], [5379128, -19042728], [84496608, 20618288], [214758558, 7012688], [106578094, 6549972], [6508260, 37720704], [5692632, 3682140], [-238504201, -1314769], [-41388174, -11933630], [-193218696, 10441306], [176341242, 22991174], [66010408, 4483892], [-58469880, 42897502], [51988671, 22704621], [18672296, 22265824], [91686864, -1055814], [-31534687, 4292359], [-51433192, -12012700], [-184865784, -7529494], [239484086, -710806], [-28162324, -38773710], [-19185511, 12598415], [-58780875, -481715], [-192179170, 23131716], [180110708, 26218904], [-61953828, 43586152], [-90231510, -5751160], [42109383, -27699491], [265993709, 4686429], [-112214904, -37783944], [-83420815, 11446197], [-31675940, 41705366], [75164992, 899356], [-73133954, -18186208], [-126398710, -20239414], [189509228, -4315758], [26219964, 4948144], [-40804453, 30064873], [105223755, 31552869], [174619472, -109428], [164332572, -37066092], [-204067016, 33661126], [-174308408, 12530636], [68191116, 7493608], [239219524, 12783146], [-131986390, -2314860], [182118477, 31568113], [-117003178, -1852084], [-108720090, 6717540], [-81639696, -25269944], [-161559691, 14714375], [-73510984, -45892362], [-148967563, -30756839], [-152957804, -48510976], [-91385060, -37430140], [-116136413, -18685071], [-330629266, -17088064], [113390522, -48843064], [18563196, -432788], [59412692, -48875552], [306260771, 7349351], [70708872, 29455632], [43265496, 67417762], [43026211, -55091651], [164719036, -25804962], [97653175, 31631831], [231353524, 4410154], [-268681647, -11679501], [52078422, -12338140], [150523369, -22215367], [102505237, 29564843], [-44679072, 50372796], [-160641760, -21824402], [-215278794, -44165038], [-207406988, 36447644], [301945875, 26969121], [77569400, 45607564], [242215100, 41761158], [-370206076, 29527778], [45484299, 33479195], [-185632192, -43304046], [371475560, -22276470], [-211660506, -34477706], [40567430, -94267110], [93933088, -20114414], [164811432, 7734052], [-53286792, 47696242], [129972500, -11876714], [198927420, 22254724], [155263362, 45330558], [-184795380, 5452336], [-98302518, -26327984], [-253310342, -18147008], [16418031, -51668025], [-87699190, 86489928], [280860472, 32402160], [18751814, 70308714], [-409286008, 25549552], [47752853, 10502691], [-394711621, 301579], [-190967154, -58000976], [59401892, -24982472], [364401552, -17541616], [-300767334, 304928], [86270451, -59015539], [252671124, -38805978], [-49852293, 50571617], [-269215553, -10291151], [168389058, 4340514], [-16756418, -6495136], [212762665, 75304365], [-267158112, -80625312], [-250982906, 41227254], [-337486706, 46205912], [-191314093, -63658017], [-316509480, -26855752], [-260324196, -31247070], [290124544, -72044546], [-232606620, 20794748], [-144841194, 110529554], [-5045640, 84912464], [-44840204, 11631474], [237985773, 42069781], [-169764229, -72032035], [-148286887, 48605597], [-19392990, -58427808], [-265194378, -76737736], [-6269468, -12527106], [235830303, -30926577], [509698513, 22761171], [-327676202, 50404220], [-251308368, -41055056], [-412351970, 17767416], [-34189200, 70163106], [-67212013, -9749313], [-85887524, 56490324], [-198287048, 104231514], [-44146190, 20033840], [140010564, -87828976], [123938027, -67981657], [-566756556, 5818690], [-195278768, 76570702], [-452319628, -66930808], [295001098, -50127398], [63633627, 4851813], [-528452346, -3059138], [180991235, 75469129], [-5347660, -101419346], [343619372, -9032324], [-64964340, -71797180], [150631914, -70554800], [-38944786, 88351060], [430529890, -82600282], [-271565482, 56064816], [617612410, -15712554], [319033636, -65134744]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_207_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_207_6_a_a();".
// 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_207_6_a_a(:prec:=2)
    chi := MakeCharacter_207_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_207_6_a_a();".
// 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_207_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_207_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-116, 0, 1]>],Snew);
    return Vf;
end function;