整数型で高次方程式を解く　Manager編

#Manager編
前回の[整数型で高方程式を解く](https://qiita.com/cluster_4b/items/906efb35d83944266c52)まで、並列処理部分はmultiprocessingのpoolを使ってきました。各プロセスが終了毎にランダムな順序でreturnされてきます。単に並列処理する場合はいいのですが、順序の並べ直しが必要で処理時間にロスがありました。そこで今回は、multiprocessingのmanagerを使ってプログラムを書き直しました。2度手間の並べ直しが無くなった分、計算時間は半分以下になりました。

前回の[整数型で高方程式を解く](https://qiita.com/cluster_4b/items/906efb35d83944266c52)の中で、10次方程式と10000次方程式のプログラムを書き直し、以下に示しました。Raspberry Pi 4Bのメモリー２Gの機種で、Raspberry Pi OS with DESKTOP（2020-DEC-02, 32bit版OS）のThonnyを使っています。USBにディスク等は接続していません。SwapはデフォルトのSDカード100MBです。

##10次方程式
```python:eq-10ji-int-manager.py
import time
from multiprocessing import Manager, Process

def f0(list0, r_f, ji_su, y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=0
        for j in range(0, ji_su +1):
            Y += Ksu[j]*(X**j)
        if X == int(X_init):
            Ypre=Y
            list0.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                list0.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))
            else:
                Ypre=Y
                list0.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))

def f1(list1, r_f, ji_su, y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=0
        for j in range(0, ji_su +1):
            Y += Ksu[j]*(X**j)
        if X == int(X_init):
            Ypre=Y
            list1.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                list1.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))
            else:
                Ypre=Y
                list1.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))

def f2(list2, r_f, ji_su, y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=0
        for j in range(0, ji_su +1):
            Y += Ksu[j]*(X**j)
        if X == int(X_init):
            Ypre=Y
            list2.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                list2.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))
            else:
                Ypre=Y
                list2.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))

def f3(list3, r_f, ji_su, y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=0
        for j in range(0, ji_su +1):
            Y += Ksu[j]*(X**j)
        if X == int(X_init):
            Ypre=Y
            list3.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                list3.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))
            else:
                Ypre=Y
                list3.append(( X/r_f, Y/(r_f**(ji_su-y_zoom)) ))



if __name__=="__main__":
    
    with Manager() as manager:
        list0 = manager.list(range(1))
        list1 = manager.list(range(1))
        list2 = manager.list(range(1))
        list3 = manager.list(range(1))


        ####  Input Start  ####
        xx_from = 0
        xx_to   = 12
        aa00= 3628800.0
        aa01=-10628640.0
        aa02= 12753576.0
        aa03=-8409500.0
        aa04= 3416930.0
        aa05=-902055.0
        aa06= 157773.0
        aa07=-18150.0
        aa08= 1320.0
        aa09=-55.0
        aa10= 1.0
        r_f     = 1000000
        ji_su   = 10
        y_zoom  = 0
        ####  Input End  ####

        ksu=[]
        ksu.append( int((r_f**10)*aa00) )
        ksu.append( int((r_f**9) *aa01) )
        ksu.append( int((r_f**8) *aa02) )
        ksu.append( int((r_f**7) *aa03) )
        ksu.append( int((r_f**6) *aa04) )
        ksu.append( int((r_f**5) *aa05) )
        ksu.append( int((r_f**4) *aa06) )
        ksu.append( int((r_f**3) *aa07) )
        ksu.append( int((r_f**2) *aa08) )
        ksu.append( int((r_f**1) *aa09) )
        ksu.append( int((r_f**0) *aa10) )

        initial_time=time.time()
        print(f"Calcilation Start")
        print(f" Please wait for 2 minutes.")
        Xfrom  = int(r_f*xx_from)
        Xto    = int(r_f*xx_to)
        Xrange = Xto - Xfrom

        p0 = Process(target=f0, args=(list0,r_f,ji_su,y_zoom,Xfrom+0*Xrange/4,Xfrom+1*Xrange/4,ksu))
        p0.start()
        p1 = Process(target=f1, args=(list1,r_f,ji_su,y_zoom,Xfrom+1*Xrange/4,Xfrom+2*Xrange/4,ksu))
        p1.start()
        p2 = Process(target=f2, args=(list2,r_f,ji_su,y_zoom,Xfrom+2*Xrange/4,Xfrom+3*Xrange/4,ksu))
        p2.start()
        p3 = Process(target=f3, args=(list3,r_f,ji_su,y_zoom,Xfrom+3*Xrange/4,Xfrom+4*Xrange/4,ksu))
        p3.start()
        p0.join()
        p1.join()
        p2.join()
        p3.join()
        print(f"Calcilation Finished")
        print(f"")
        print(f"Time :")
        print(str(time.time() - initial_time))
        print(f"Answers :")
        for i in range(len(list0)):
            print(list0[i])
        for i in range(len(list1)):
            print(list1[i])
        for i in range(len(list2)):
            print(list2[i])
        for i in range(len(list3)):
            print(list3[i])
    
        time.sleep(10)

```
##10000次方程式
```python:eq-10000ji-int-manager.py
import time
from multiprocessing import Manager, Process

def f0(List0, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=1
        for j in range(   0, 10000):
            Y *= (X-Ksu[j])
        if X == int(X_init):
            Ypre=Y
            List0.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                List0.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))
            else:
                Ypre=Y
                List0.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))

def f1(List1, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=1
        for j in range(   0, 10000):
            Y *= (X-Ksu[j])
        if X == int(X_init):
            Ypre=Y
            List1.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                List1.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))
            else:
                Ypre=Y
                List1.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))

def f2(List2, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=1
        for j in range(   0, 10000):
            Y *= (X-Ksu[j])
        if X == int(X_init):
            Ypre=Y
            List2.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                List2.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))
            else:
                Ypre=Y
                List2.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))

def f3(List3, R_f, Ji_su, Y_zoom, X_init, X_end, Ksu):
    Ypre=0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=1
        for j in range(   0, 10000):
            Y *= (X-Ksu[j])
        if X == int(X_init):
            Ypre=Y
            List3.pop(0)
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                List3.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))
            else:
                Ypre=Y
                List3.append(( X/R_f, Y/(R_f**(Ji_su-Y_zoom)) ))



if __name__=="__main__":
    
    with Manager() as manager:

        list0 = manager.list(range(1))
        list1 = manager.list(range(1))
        list2 = manager.list(range(1))
        list3 = manager.list(range(1))

        ####  Input Start  ####
        xx_from = 0.940
        xx_to   = 1.060
        ksu_init = []
        ksu_temp = 0.94999
        for i in range(10000):
            ksu_temp += 0.00001
            ksu_init.append(ksu_temp)
        r_f     = 200000
        ji_su   = 10000
        y_zoom  = 2500
        ####  Input End  ####

        initial_time=time.time()
        print(f"Calcilation Start")
        print(f" Please wait for 15 minutes.")
        Xfrom  = int(r_f*xx_from)
        Xto    = int(r_f*xx_to)
        Xrange = Xto - Xfrom
        ksu=[]
        for i in range(len(ksu_init)):
            ksu.append( int(r_f*ksu_init[i]) )

        p0 = Process(target=f0, args=(list0,r_f,ji_su,y_zoom,Xfrom+0*Xrange/4,Xfrom+1*Xrange/4,ksu))
        p0.start()
        p1 = Process(target=f1, args=(list1,r_f,ji_su,y_zoom,Xfrom+1*Xrange/4,Xfrom+2*Xrange/4,ksu))
        p1.start()
        p2 = Process(target=f2, args=(list2,r_f,ji_su,y_zoom,Xfrom+2*Xrange/4,Xfrom+3*Xrange/4,ksu))
        p2.start()
        p3 = Process(target=f3, args=(list3,r_f,ji_su,y_zoom,Xfrom+3*Xrange/4,Xfrom+4*Xrange/4,ksu))
        p3.start()
        p0.join()
        p1.join()
        p2.join()
        p3.join()
        print(f"Calcilation Finished")
        print(f"")
        print(f"Time :")
        print(str(time.time() - initial_time))
        print(f"Answers :")
        time.sleep(2)
        for i in range(len(list0)):
            print(list0[i])
        for i in range(len(list1)):
            print(list1[i])
        for i in range(len(list2)):
            print(list2[i])
        for i in range(len(list3)):
            print(list3[i])
    
        time.sleep(10)

```


##1000次方程式16core版
1000次まで解けるプログラムですが、ここで実際に解いているのは10次方程式です。

プログラム上部のCore_suで16に変更すると、プロセスが16個立ち上がり16コアに最適です。10秒間、16コア各100%稼働します。初期値は4コアになっています。

```python:eq-1000ji-16core-int-manager.py
import time
from multiprocessing import Manager, Process

##  Input Start   #
Core_su = 4       # 2 or 4 or 8 or 16
x_from  = 0.5     # only > 0
x_to    = 8.5     # eg.  core1:0.5-2.5, core2:2.5-4.5, core3:4.5-6.5, core4:6.5-8.5

r_f     = 100000  # resolution 1000 - 10000000
y_zoom  =      0

ji_suu  = 10
# y=1481760*x**0 -4512312*x**1 +5699652*x**2 -4003042*x**3 +1752225*x**4 -503860*x**5 +97027*x**6 -12418*x**7 +1015*x**8 -48*x**9 +x**10 
ksu_0 = [1481760,-4512312,5699652,-4003042,1752225,-503860,97027,-12418,1015,-48,1,0.,0.,0.,0.,0.,0.,0.,0.,0.,\
         0.,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re  =0
    YYpre =0
    YYYpre =0
    for X in range( int(X_init), int(X_end)+1 ):
        Y=0
        for j in range(0, Ji_su+1):
            Y += Ksu[j]*(X**j)
        YY=0
        for j in range(0, Ji_su):
            YY += (j+1)*Ksu[j+1]*(X**j)
        YYY=0
        for j in range(0, Ji_su-1):
            YYY += (j+1)*(j+2)*Ksu[j+2]*(X**j)
        if X == int(X_init):
            Ypre   =Y
            YYpre  =YY
            YYYpre =YYY
            List0.pop(0)
            List0b.pop(0)
            List0c.pop(0)

        ####  Y : Simple x axis cross method  ####
        if Ypre * Y > 0:
            Ypre=Y
        else:
            if Y == 0:
                Y=Y
                List0.append(( X/R_f, X, Y/(R_f**(Ji_su-Y_zoom)), Y ,333 ))
            else:
                X_tmp = X-1
                Y_tmp = 0
                for k in range(0, Ji_su+1):
                    Y_tmp += Ksu[k]*(X_tmp**k)
                List0.append(( X_tmp/R_f, X_tmp, Y_tmp/(R_f**(Ji_su-Y_zoom)), Y_tmp, 666 ))
                Ypre=Y

        ####  YY even: Simple x axias cross method  ####
        if YYpre * YY > 0:
            YYpre=YY
        else:
            if YY == 0:
                YY=YY
                List0b.append(( X/R_f, X, YY/(R_f**(Ji_su-Y_zoom)), YY, 333 ))
            else:
                X_tmp = X-1
                YY_tmp = 0
                for k in range(0, Ji_su):
                    YY_tmp += (k+1)*Ksu[k+1]*(X_tmp**k)
                List0b.append(( X_tmp/R_f, X_tmp, YY_tmp/(R_f**(Ji_su-Y_zoom)), YY_tmp, 666 ))
                YYpre=YY

        ####  YYY odd: Simple x axias cross method  ####
        if YYYpre * YYY > 0:
            YYYpre=YYY
        else:
            if YYY == 0:
                YYY=YYY
                List0c.append(( X/R_f, X, YYY/(R_f**(Ji_su-Y_zoom)), YYY, 333 ))
            else:
                X_tmp = X-1
                YYY_tmp = 0
                for k in range(0, Ji_su-1):
                    YYY_tmp += (k+1)*(k+2)*Ksu[k+2]*(X_tmp**k)
                List0c.append(( X_tmp/R_f, X_tmp, YYY_tmp/(R_f**(Ji_su-Y_zoom)), YYY_tmp, 666 ))
                YYYpre=YYY


if __name__=="__main__":

    if Core_su >=16:
        core_su  =  16
    elif Core_su < 16 and Core_su >=8:
        core_su  =   8
    elif Core_su <  8 and Core_su >=4:
        core_su  =   4
    else:
        core_su  =   2

    ji_su =int(ji_suu)
    
    with Manager() as manager:
        if core_su>=2:
            list1   = manager.list(range(1))
            list1b  = manager.list(range(1))
            list1c  = manager.list(range(1))
            list2   = manager.list(range(1))
            list2b  = manager.list(range(1))
            list2c  = manager.list(range(1))
        if core_su>=4:
            list3   = manager.list(range(1))
            list3b  = manager.list(range(1))
            list3c  = manager.list(range(1))
            list4   = manager.list(range(1))
            list4b  = manager.list(range(1))
            list4c  = manager.list(range(1))
        if core_su>=8:
            list5   = manager.list(range(1))
            list5b  = manager.list(range(1))
            list5c  = manager.list(range(1))
            list6   = manager.list(range(1))
            list6b  = manager.list(range(1))
            list6c  = manager.list(range(1))
            list7   = manager.list(range(1))
            list7b  = manager.list(range(1))
            list7c  = manager.list(range(1))
            list8   = manager.list(range(1))
            list8b  = manager.list(range(1))
            list8c  = manager.list(range(1))
        if core_su>=16:
            list9   = manager.list(range(1))
            list9b  = manager.list(range(1))
            list9c  = manager.list(range(1))
            list10  = manager.list(range(1))
            list10b = manager.list(range(1))
            list10c = manager.list(range(1))
            list11  = manager.list(range(1))
            list11b = manager.list(range(1))
            list11c = manager.list(range(1))
            list12  = manager.list(range(1))
            list12b = manager.list(range(1))
            list12c = manager.list(range(1))
            list13  = manager.list(range(1))
            list13b = manager.list(range(1))
            list13c = manager.list(range(1))
            list14  = manager.list(range(1))
            list14b = manager.list(range(1))
            list14c = manager.list(range(1))
            list15  = manager.list(range(1))
            list15b = manager.list(range(1))
            list15c = manager.list(range(1))
            list16  = manager.list(range(1))
            list16b = manager.list(range(1))
            list16c = manager.list(range(1))

        initial_time=time.time()
        print(f"Calcilation Start")
        Xfrom  = int(r_f*x_from)
        Xto    = int(r_f*x_to)
        Xrange = Xto - Xfrom
        ksu=[]
        for i in range(len(ksu_0)):
            ksu.append( int(ksu_0[i]*r_f**(ji_su-i)) )

        if core_su==2:
            p1  = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/2,Xfrom+1*Xrange/2,ksu))
            p1.start()
            p2  = Process(target=f0, args=(list2,list2b,list1c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/2,Xfrom+2*Xrange/2,ksu))
            p2.start()
        elif core_su==4:
            p1  = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/4,Xfrom+1*Xrange/4,ksu))
            p1.start()
            p2  = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/4,Xfrom+2*Xrange/4,ksu))
            p2.start()
            p3  = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom,Xfrom+2*Xrange/4,Xfrom+3*Xrange/4,ksu))
            p3.start()
            p4  = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom,Xfrom+3*Xrange/4,Xfrom+4*Xrange/4,ksu))
            p4.start()
        elif core_su==8:
            p1  = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,Xfrom+0*Xrange/8,Xfrom+1*Xrange/8,ksu))
            p1.start()
            p2  = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom,Xfrom+1*Xrange/8,Xfrom+2*Xrange/8,ksu))
            p2.start()
            p3  = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom,Xfrom+2*Xrange/8,Xfrom+3*Xrange/8,ksu))
            p3.start()
            p4  = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom,Xfrom+3*Xrange/8,Xfrom+4*Xrange/8,ksu))
            p4.start()
            p5  = Process(target=f0, args=(list5,list5b,list5c,r_f,ji_su,y_zoom,Xfrom+4*Xrange/8,Xfrom+5*Xrange/8,ksu))
            p5.start()
            p6  = Process(target=f0, args=(list6,list6b,list6c,r_f,ji_su,y_zoom,Xfrom+5*Xrange/8,Xfrom+6*Xrange/8,ksu))
            p6.start()
            p7  = Process(target=f0, args=(list7,list7b,list7c,r_f,ji_su,y_zoom,Xfrom+6*Xrange/8,Xfrom+7*Xrange/8,ksu))
            p7.start()
            p8  = Process(target=f0, args=(list8,list8b,list8c,r_f,ji_su,y_zoom,Xfrom+7*Xrange/8,Xfrom+8*Xrange/8,ksu))
            p8.start()
        elif core_su==16:
            p1  = Process(target=f0, args=(list1,list1b,list1c,r_f,ji_su,y_zoom,  Xfrom+0*Xrange/16, Xfrom+1*Xrange/16,ksu))
            p1.start()
            p2  = Process(target=f0, args=(list2,list2b,list2c,r_f,ji_su,y_zoom,  Xfrom+1*Xrange/16, Xfrom+2*Xrange/16,ksu))
            p2.start()
            p3  = Process(target=f0, args=(list3,list3b,list3c,r_f,ji_su,y_zoom,  Xfrom+2*Xrange/16, Xfrom+3*Xrange/16,ksu))
            p3.start()
            p4  = Process(target=f0, args=(list4,list4b,list4c,r_f,ji_su,y_zoom,  Xfrom+3*Xrange/16, Xfrom+4*Xrange/16,ksu))
            p4.start()
            p5  = Process(target=f0, args=(list5,list5b,list5c,r_f,ji_su,y_zoom,  Xfrom+4*Xrange/16, Xfrom+5*Xrange/16,ksu))
            p5.start()
            p6  = Process(target=f0, args=(list6,list6b,list6c,r_f,ji_su,y_zoom,  Xfrom+5*Xrange/16, Xfrom+6*Xrange/16,ksu))
            p6.start()
            p7  = Process(target=f0, args=(list7,list7b,list7c,r_f,ji_su,y_zoom,  Xfrom+6*Xrange/16, Xfrom+7*Xrange/16,ksu))
            p7.start()
            p8  = Process(target=f0, args=(list8,list8b,list8c,r_f,ji_su,y_zoom,  Xfrom+7*Xrange/16, Xfrom+8*Xrange/16,ksu))
            p8.start()
            p9  = Process(target=f0, args=(list9,list9b,list9c,r_f,ji_su,y_zoom,  Xfrom+8*Xrange/16, Xfrom+9*Xrange/16,ksu))
            p9.start()
            p10 = Process(target=f0, args=(list10,list10b,list10c,r_f,ji_su,y_zoom, Xfrom+9*Xrange/16,Xfrom+10*Xrange/16,ksu))
            p10.start()
            p11 = Process(target=f0, args=(list11,list11b,list11c,r_f,ji_su,y_zoom,Xfrom+10*Xrange/16,Xfrom+11*Xrange/16,ksu))
            p11.start()
            p12 = Process(target=f0, args=(list12,list12b,list12c,r_f,ji_su,y_zoom,Xfrom+11*Xrange/16,Xfrom+12*Xrange/16,ksu))
            p12.start()
            p13 = Process(target=f0, args=(list13,list13b,list13c,r_f,ji_su,y_zoom,Xfrom+12*Xrange/16,Xfrom+13*Xrange/16,ksu))
            p13.start()
            p14 = Process(target=f0, args=(list14,list14b,list14c,r_f,ji_su,y_zoom,Xfrom+13*Xrange/16,Xfrom+14*Xrange/16,ksu))
            p14.start()
            p15 = Process(target=f0, args=(list15,list15b,list15c,r_f,ji_su,y_zoom,Xfrom+14*Xrange/16,Xfrom+15*Xrange/16,ksu))
            p15.start()
            p16 = Process(target=f0, args=(list16,list16b,list16c,r_f,ji_su,y_zoom,Xfrom+15*Xrange/16,Xfrom+16*Xrange/16,ksu))
            p16.start()

        if core_su>=2:
            p1.join()
            p2.join()
        if core_su>=4:
            p3.join()
            p4.join()
        if core_su>=8:
            p5.join()
            p6.join()
            p7.join()
            p8.join()
        if core_su>=16:
            p9.join()
            p10.join()
            p11.join()
            p12.join()
            p13.join()
            p14.join()
            p15.join()
            p16.join()

        print(f"Calcilation Finished")

        print(f"Time :")
        print(str(time.time() - initial_time))
        print(f"Answers Y:")
        kai_su=0
        if core_su>=2:
            for i in range(len(list1)):
                print(list1[i])
            for i in range(len(list2)):
                print(list2[i])
            kai_su += len(list1) + len(list2)
        if core_su>=4:
            for i in range(len(list3)):
                print(list3[i])
            for i in range(len(list4)):
                print(list4[i])
            kai_su += len(list3) + len(list4)
        if core_su>=8:
            for i in range(len(list5)):
                print(list5[i])
            for i in range(len(list6)):
                print(list6[i])
            for i in range(len(list7)):
                print(list7[i])
            for i in range(len(list8)):
                print(list8[i])
            kai_su += len(list5) + len(list6) + len(list7) + len(list8)
        if core_su>=16:
            for i in range(len(list9)):
                print(list9[i])
            for i in range(len(list10)):
                print(list10[i])
            for i in range(len(list11)):
                print(list11[i])
            for i in range(len(list12)):
                print(list12[i])
            for i in range(len(list13)):
                print(list13[i])
            for i in range(len(list14)):
                print(list14[i])
            for i in range(len(list15)):
                print(list15[i])
            for i in range(len(list16)):
                print(list16[i])
            kai_su += len(list9) + len(list10) + len(list11) + len(list12) + len(list13) + len(list14) + len(list15) + len(list16)

        print(f"Answers YY even:")
        if core_su>=2:
            for i in range(len(list1b)):
                print(list1b[i])
            for i in range(len(list2b)):
                print(list2b[i])
        if core_su>=4:
            for i in range(len(list3b)):
                print(list3b[i])
            for i in range(len(list4b)):
                print(list4b[i])
        if core_su>=8:
            for i in range(len(list5b)):
                print(list5b[i])
            for i in range(len(list6b)):
                print(list6b[i])
            for i in range(len(list7b)):
                print(list7b[i])
            for i in range(len(list8b)):
                print(list8b[i])
        if core_su>=16:
            for i in range(len(list9b)):
                print(list9b[i])
            for i in range(len(list10b)):
                print(list10b[i])
            for i in range(len(list11b)):
                print(list11b[i])
            for i in range(len(list12b)):
                print(list12b[i])
            for i in range(len(list13b)):
                print(list13b[i])
            for i in range(len(list14b)):
                print(list14b[i])
            for i in range(len(list15b)):
                print(list15b[i])
            for i in range(len(list16b)):
                print(list16b[i])

        print(f"Answers YYY odd:")
        if core_su>=2:
            for i in range(len(list1c)):
                print(list1c[i])
            for i in range(len(list2c)):
                print(list2c[i])
        if core_su>=4:
            for i in range(len(list3c)):
                print(list3c[i])
            for i in range(len(list4c)):
                print(list4c[i])
        if core_su>=8:
            for i in range(len(list5c)):
                print(list5c[i])
            for i in range(len(list6c)):
                print(list6c[i])
            for i in range(len(list7c)):
                print(list7c[i])
            for i in range(len(list8c)):
                print(list8c[i])
        if core_su>=16:
            for i in range(len(list9c)):
                print(list9c[i])
            for i in range(len(list10c)):
                print(list10c[i])
            for i in range(len(list11c)):
                print(list11c[i])
            for i in range(len(list12c)):
                print(list12c[i])
            for i in range(len(list13c)):
                print(list13c[i])
            for i in range(len(list14c)):
                print(list14c[i])
            for i in range(len(list15c)):
                print(list15c[i])
            for i in range(len(list16c)):
                print(list16c[i])

        time.sleep(10)

#Calcilation Start
#Calcilation Finished
#Time :
#10......
#Answers Y:
#(1.0, 100000, 0.0, 0, 333)
#(1.0, 100000, 0.0, 0, 666)
#(2.0, 200000, 0.0, 0, 333)
#(2.0, 200000, 0.0, 0, 666)
#(3.0, 300000, 0.0, 0, 333)
#(3.0, 300000, 0.0, 0, 666)
#(4.0, 400000, 0.0, 0, 333)
#(4.0, 400000, 0.0, 0, 666)
#(5.0, 500000, 0.0, 0, 333)
#(5.0, 500000, 0.0, 0, 666)
#(6.0, 600000, 0.0, 0, 333)
#(7.0, 700000, 0.0, 0, 333)
#(7.0, 700000, 0.0, 0, 666)
#Answers YY even:
#(1.28107, 128107, -5.0430906065052035e-06, -504309060650520383598306522927248034166134930, 666)
#(2.3403, 234030, 5.895172117815607e-07, 58951721178156071200540809805342830000000000, 666)
#(3.37589, 337589, -3.8314118844822066e-07, -38314118844822066863365014957865170863972910, 666)
#(4.38698, 438698, 2.0096322108705502e-08, 2009632210870550169854766202814042133242880, 666)
#(5.32751, 532751, -3.8765760701232836e-08, -3876576070123283353238523090266069772752490, 666)
#(6.0, 600000, 0.0, 0, 333)
#(6.0, 600000, 0.0, 0, 666)
#(6.48822, 648822, -1.5305210210566334e-08, -1530521021056633320916001320946154929710080, 666)
#(7.0, 700000, 0.0, 0, 333)
#Answers YYY odd:
#(1.58379, 158379, 2.8252114286971364e-10, 28252114286971366198659094366787618174490, 666)
#(2.69998, 269998, -3.5165403524180634e-11, -3516540352418063406780002628844646376960, 666)
#(3.76443, 376443, 2.4550892683310132e-12, 245508926833101309842334511517512440090, 666)
#(4.76517, 476517, -6.500608871808993e-13, -65006088718089930325956498402607790310, 666)
#(5.61901, 561901, 1.3726941815060848e-12, 137269418150608485975317329750596168090, 666)
#(6.23869, 623869, -4.247385971364261e-13, -42473859713642607811448890915553918310, 666)
#(6.72889, 672889, 1.0720108151986837e-12, 107201081519868371207991692168551651290, 666)
#(7.0, 700000, 0.0, 0, 333)
#(7.0, 700000, 0.0, 0, 666)

```
x=1, 2, 3, 4, 5, 6, 7に解があります。x=6は2重解(even)です。x=7は3重解(add)です。プログラムを実行すると1次微分YYよりx=6にevenの重解(2重解)があることがわかります。2次微分YYYよりx=7にoddの重解(3重解)があることがわかります。シンプルに解の位置がわかるプログラムです。また因数分解型を展開した方程式ですから、Y値がきれいに0.0になります。

matplotlibで描画すると次図のようになります。x=1, 2, 3, 4, 5, 6, 7に解を持ちます。x=6,7付近のY軸をズームアップした右側の図より、x=6でX軸上に接点を持ち、x=7でX軸上に変曲点を持つことがわかります。
![a.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/960318/605e92c1-0a36-a2df-3869-4f8d2fb5a81f.png)


最後までご覧いただき、ありがとうございました。

今回はQiitaの主旨に同意して投稿していますので、公開したプログラムはコピー、改変などでのご使用は自由です。著作権に関する問題も発生しません。

ただし、Raspberry Pi 4Bを使う場合にはCPUに特に大きめのヒートシンクが必須です。LAN通信の頻度の少ない今回のプログラムのような場合、LANチップは熱くなりません。しかし計算時間が継続するとCPUの激しい発熱で分かるように相当電力を使っています。電源UCB Cタイプの後ろにある黒い小さなチップも熱くなりますので、ファンでの風流も必要です。

次回、「整数型で高方程式を解く＝分散並列処理＝」では、Raspberry Pi 4台のsocket通信を使った分散処理により、計算時間を短縮する試行を予定しています。