【数理考古学】オイラーの公式を導出したマクローリン級数の限界？

ある意味、円描画関数の基本中の基本ともいうべき***オイラーの公式***（Euler's formula）」_e^Θ=cos(Θ)+sin(Θ)i_…
[【Rで球面幾何学】オイラーの公式とは、そもそも何か？](https://qiita.com/ochimusha01/items/ebb190371d9f268723a6)
[【初心者向け】「円そのもの」の近似から派生した角度概念の起源](https://qiita.com/ochimusha01/items/80b70db93cbf2612bd18)
![20190512232958.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/5e4451eb-9eb8-e8dd-040d-a04a87773795.gif)
#変遷周期を同じくする三角関数と指数・対数関数の「巡回性」の発見
**三角関数**(Trigonometric function)は微分する都度時計回りに90度回転し４回で１周します。そして、**指数関数**（Exponential function）や**対数関数**（Logarithm function）もまた…
[【初心者向け】三角関数と指数・対数関数の「巡回性」について。](https://qiita.com/ochimusha01/items/61d8cfa89dc078cbe472)
![20191014091535.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/ceaf9151-8aef-801f-a771-812bfef7b1d6.gif)
![20191014142817.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/f0b0218a-9773-6903-ed6a-b3c88c7eb448.gif)

```R
#コサイン関数
D01<-expression(cos(x))
D(D01,"x")
-sin(x)
D01<-expression(-sin(x))
D(D01,"x")
-cos(x)
D01<-expression(-cos(x))
D(D01,"x")
sin(x)
D01<-expression(sin(x))
D(D01,"x")
cos(x)

#サイン関数
D01<-expression(sin(x))
D(D01,"x")
cos(x)

D01<-expression(cos(x))
D(D01,"x")
-sin(x)
D01<-expression(-sin(x))
D(D01,"x")
-cos(x)
D01<-expression(-cos(x))
D(D01,"x")
sin(x)
```
<!-- html table generated in R 3.5.2 by xtable 1.8-4 package -->
<!-- Fri Mar  6 14:01:15 2020 -->
<table border=1>
<tr> <th>  </th> <th> Angles </th> <th> Imaginary_solution </th> <th> Cosine </th> <th> Sine </th>  </tr>
  <tr> <td align="right"> 1 </td> <td> 0(2π)radian/0(360)degree </td> <td> 1+0i </td> <td> cos(x) </td> <td> sin(x) </td> </tr>
  <tr> <td align="right"> 2 </td> <td> π/2radian/90degree </td> <td> 0+0i </td> <td> sin(x) </td> <td> -cos(x) </td> </tr>
  <tr> <td align="right"> 3 </td> <td> πradian/180degree  </td> <td> -1+0i </td> <td> -cos(x) </td> <td> -sin(x) </td> </tr>
  <tr> <td align="right"> 4 </td> <td> 3/4πradian/270degree </td> <td> 0-0i </td> <td> -sin(x) </td> <td> cos(x) </td> </tr>
   </table>

```R
#ガウス平面上における遷移図
target_angles<-c("0(2π)radian/0(360)degree","π/2radian/90degree","πradian/180degree ","3/4πradian/270degree")

imaginary_solution<-c("1+0i","0+0i","-1+0i","0-0i")

cosine_function<-c("cos(x)","sin(x)","-cos(x)","-sin(x)")

sine_function<-c("sin(x)","-cos(x)","-sin(x)","cos(x)")

Days_of_Future_Past_F<-data.frame(Angles=target_angles, Imaginary_solution=imaginary_solution, Cosine=cosine_function, Sine=sine_function)
library(xtable) 
print(xtable(Days_of_Future_Past_F), type = "html")
```
そして時はまさに近世文化成熟期に入った18世紀。**指数関数**(Exponential function)と**対数関数**(Logarithmic function)の概念を纏め上げ、**マクローリン級数** (Maclaurin series) の概念を知ったばかりの数学者**レオンハルド・オイラー**（Leonhard Euler, 1707年〜1783年）は、三角関数と指数・対数関数が統合可能なのではないかと考えたのです。
[【Rで球面幾何学】指数・対数関数の発見](https://qiita.com/ochimusha01/items/3e28f4f06abd8cef0af1)
![20190927233136.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/119a783d-c60a-2127-26a6-cc334e3ccc98.png)

#マクローリン展開の概念の導入
[テイラー展開（Taylor expansion）とマクローリン展開（Maclaurin expansion） - Wikipedia](https://ja.wikipedia.org/wiki/%E3%83%86%E3%82%A4%E3%83%A9%E3%83%BC%E5%B1%95%E9%96%8B)
>数学において、**テイラー級数** (Taylor series) は関数のある一点での導関数たちの値から計算される項の無限和として関数を表したものである。そのような級数を得ることをテイラー展開という。
>
>テイラー級数の概念はスコットランドの数学者ジェームズ・グレゴリーにより定式化され、フォーマルにはイギリスの数学者ブルック・テイラーによって1715年に導入された。0 を中心としたテイラー級数は、**マクローリン級数** (Maclaurin series) とも呼ばれる。これはスコットランドの数学者コリン・マクローリンにちなんでおり、彼は18世紀にテイラー級数のこの特別な場合を積極的に活用した。
>
>関数はそのテイラー級数の有限個の項を用いて近似することができる。テイラーの定理はそのような近似による誤差の定量的な評価を与える。テイラー級数の最初のいくつかの項として得られる多項式はテイラー多項式と呼ばれる。関数のテイラー級数は、その関数のテイラー多項式で次数を増やした極限が存在すればその極限である。関数はそのテイラー級数がすべての点で収束するときでさえもテイラー級数に等しいとは限らない。**開区間**（あるいは複素平面の開円板）でテイラー級数に等しい関数はその区間上の解析関数と呼ばれる。

階乗計算については以下。
[【初心者向け】階乗と順列と組み合わせ](https://qiita.com/ochimusha01/items/90d9ef0a224bdd604721)
![https___qiita-image-store.s3.ap-northeast-1.amazonaws.com_0_597772_7c0e924f-7db8-d57c-4d19-8b63ed042399.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/df647c18-893f-c38f-a2a3-d8ed32fdddc7.png)

**ネイピア数を底（root）とする指数関数e^xのマクローリン展開**
![20190617115949.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/0a9d3bb6-1636-86b7-78f8-c03fef2238a2.gif)

```R
Macrolin_expansion_exp<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-6,6)
Graph_scale_y<-c(-1,6)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x/x},
"1"= f0<-function(x) {1+x},
"2"= f0<-function(x) {1+x+x^2/2},
"3"= f0<-function(x) {1+x+x^2/2+x^3/6},
"4"= f0<-function(x) {1+x+x^2/2+x^3/6+x^4/24},
"5"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120},
"6"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120+ x^6/720},
"7"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120+ x^6/720+ x^7/5040},
"8"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120+ x^6/720+ x^7/5040+ x^8/40320},
"9"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24 + x^5/120 + x^6/720 + x^7/5040 + x^8/40320 + x^9/362880 }
)

switch(x,
"0"=text<-c("1"),
"1"=text<-c("1+x"),
"2"=text<-c("1+x+x^2/2!"),
"3"=text<-c("1+x+x^2/2!+x^3/3!"),
"4"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!"),
"5"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!"),
"6"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!"),
"7"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!+x^7/7!"),
"8"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!+x^7/7!+x^8/8!"),
"9"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!+x^7/7!+x^8/8!+x^9/9!")
)

f1=function(x){exp(x)}

plot(f1,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("e^x",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}

library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_exp(i)
}
}, interval = 0.1, movie.name = "TEST01.gif") 
```
**ネイピア数**を**底**（<font color=blue>root</font>）とする**対数関数**<font color=purple>log(x)</font>の求め方はトリッキーです(<font color=blue>というより、不可能なので工夫してテイラー級数/マクローリン級数の限界を誤魔化してる感じ？</font>)。
[テイラー展開](https://eman-physics.net/math/taylor.html)

>指数関数の逆関数である対数関数についてもどうなるのか試してみたくなる.しかしに<font color=green>0</font>を代入することはできないし,を微分したにも<font color=green>0</font>を代入するわけにはいかないので,<font color=green>0</font>の周りにテイラー展開することは出来そうにない.
>
>かと言って,原点以外で展開したようなごちゃごちゃしたものは,それほど見てみたいという気も起きないだろう.そこで原点を少しずらしてやるという工夫をするのである.次のような関数ならば<font color=green>0</font>の周りに展開ができそうだ.
>
><font color=purple>f(x)=log(1+x) </font>
>
>この展開の収束半径は<font color=green>1</font>である.つまりこの展開は<font color=green>-1>x>1</font>の範囲でしか成り立っていない。いや,収束半径ちょうどのところ,<font color=green>x=1</font>と<font color=green>x=-1</font>で収束するかどうかは個別に検証してみないと何とも言えないのだった.

まず<font color=purple>|x|<1</font>の場合における<font color=purple>log(1+x)</font>と<font color=purple>-log(1-x)</font>と両者の和<font color=purple>log((1-x)/(1+x))</font>の**マクローリン展開**の結果を求めます。**指数関数**の「<font color=purple>収束が遅い部分</font>」だけ取り出した形ですが、それ自体は全然**原関数**へと収束して行きません。
[対数関数のTylor展開](http://math-lab.main.jp/taylor7b.html)
![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210204/20210204091231.gif)

```R
Macrolin_expansion_log<-function(x){
#グラフのスケール決定
Graph_scale_x<-c(-2,6)
Graph_scale_y<-c(-1,6)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x},
"1"= f0<-function(x) {x-x^2/2},
"2"= f0<-function(x) {x-x^2/2+x^3/3},
"3"= f0<-function(x) {x-x^2/2+x^3/3-x^4/4},
"4"= f0<-function(x) {x-x^2/2+x^3/3-x^4/4+x^5/5},
"5"= f0<-function(x) {x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6},
"6"= f0<-function(x) {x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7},
"7"= f0<-function(x) {x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7-x^8/8},
"8"= f0<-function(x) {x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7-x^8/8+x^9/9},
"9"= f0<-function(x) {x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7-x^8/8+x^9/9-x^10/10}
)

switch(x,
"0"=text0<-c("x"),
"1"=text0<-c("x-x^2/2"),
"2"=text0<-c("x-x^2/2+x^3/3"),
"3"=text0<-c("x-x^2/2+x^3/3-x^4/4"),
"4"=text0<-c("x-x^2/2+x^3/3-x^4/4+x^5/5"),
"5"=text0<-c("x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6"),
"6"=text0<-c("x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7"),
"7"=text0<-c("x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7-x^8/8"),
"8"=text0<-c("x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7-x^8/8+x^9/9"),
"9"=text0<-c("x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7-x^8/8+x^9/9-x^10/10")
)

switch(x,
"0"= f1<-function(x) {x},
"1"= f1<-function(x) {x+x^2/2},
"2"= f1<-function(x) {x+x^2/2+x^3/3},
"3"= f1<-function(x) {x+x^2/2+x^3/3+x^4/4},
"4"= f1<-function(x) {x+x^2/2+x^3/3+x^4/4+x^5/5},
"5"= f1<-function(x) {x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6},
"6"= f1<-function(x) {x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7},
"7"= f1<-function(x) {x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7+x^8/8},
"8"= f1<-function(x) {x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7+x^8/8+x^9/9},
"9"= f1<-function(x) {x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7+x^8/8+x^9/9+x^10/10}
)

switch(x,
"0"=text1<-c("x"),
"1"=text1<-c("x+x^2/2"),
"2"=text1<-c("x+x^2/2+x^3/3"),
"3"=text1<-c("x+x^2/2+x^3/3+x^4/4"),
"4"=text1<-c("x+x^2/2+x^3/3+x^4/4+x^5/5"),
"5"=text1<-c("x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6"),
"6"=text1<-c("x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7"),
"7"=text1<-c("x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7+x^8/8"),
"8"=text1<-c("x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7+x^8/8+x^9/9"),
"9"=text1<-c("x+x^2/2+x^3/3+x^4/4+x^5/5+x^6/6+x^7/7+x^8/8+x^9/9+x^10/10")
)

switch(x,
"0"= f2<-function(x) {2*(x)},
"1"= f2<-function(x) {2*(x+x^3/3)},
"2"= f2<-function(x) {2*(x+x^3/3+x^5/5)},
"3"= f2<-function(x) {2*(x+x^3/3+x^5/5+x^7/7)},
"4"= f2<-function(x) {2*(x+x^3/3+x^5/5+x^7/7+x^9/9)},
"5"= f2<-function(x) {2*(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11)},
"6"= f2<-function(x) {2*(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13)},
"7"= f2<-function(x) {2*(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13+x^15/15)},
"8"= f2<-function(x) {2*(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13+x^15/15+x^17/17)},
"9"= f2<-function(x) {2*(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13-x^15/15+x^17/17+x^19/19)}
)

switch(x,
"0"=text2<-c("2(x)"),
"1"=text2<-c("2(x+x^3/3)"),
"2"=text2<-c("2(x+x^3/3+x^5/5)"),
"3"=text2<-c("2(x+x^3/3+x^5/5+x^7/7)"),
"4"=text2<-c("2(x+x^3/3+x^5/5+x^7/7+x^9/9)"),
"5"=text2<-c("2(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11)"),
"6"=text2<-c("2(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13)"),
"7"=text2<-c("2(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13+x^15/15)"),
"8"=text2<-c("2(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13+x^15/15+x^17/17)"),
"9"=text2<-c("2(x+x^3/3+x^5/5+x^7/7+x^9/9+x^11/11+x^13/13-x^15/15+x^17/17+x^19/19")
)

f10=function(x){log(x)}

plot(f10,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,1),main="", xlab="", ylab="")
par(new=T)#上書き指定
plot(f1,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")
par(new=T)#上書き指定
plot(f2,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,1,0),main="", xlab="", ylab="")

legend("topleft", legend=c("log(x)",paste("log(1+x)=",text0),paste("-log(1-x)=",text1),paste("log((x+1)/(x-1))=",text2)),lty=c(1,1,1,1),col=c(rgb(0,0,0),rgb(0,0,1),rgb(1,0,0),rgb(0,1,0)))
}

library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_log(i)
}
}, interval = 0.1, movie.name = "TEST03.gif") 
```
ところで古来**数学者達**は、それが<font color=green>x=1</font>の時に<font color=green>π/2</font>で収束して**円周率**に迫るので**アークタンジェント**(<font color=blue>ArcTangent</font>)**近似式**の高速化に血道を上げてきたのです。
[円周率の公式と計算法](http://www.kurims.kyoto-u.ac.jp/~ooura/pi04.pdf)
[【数理考古学】とある円周率への挑戦？](https://qiita.com/ochimusha01/items/5c8a62486ea4d5d1d73a)
![image.gif](https://camo.qiitausercontent.com/b62441814544b01538669b1734189a851cab5952/68747470733a2f2f63646e2d616b2e662e73742d686174656e612e636f6d2f696d616765732f666f746f6c6966652f6f2f6f6368696d7573686130312f32303231303230352f32303231303230353031333830342e676966)

そして実はその過程で発見された**オイラー変換**(<font color=blue>Eulerian Transformation</font>)適用可能な<font color=purple>ArcTangent</font>が、ここでいう<font color=purple>log((x+1)/(x-1))</font>の場合と重なってくるのです。
<font color=purple>グレゴリー級数のみ。</font>
![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210216/20210216002902.gif)

```R
Macrolin_expansion_log<-function(x){
#グラフのスケール決定
Graph_scale_x<-c(-10,10)
Graph_scale_y<-c(-pi/2,pi/2)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x},
"1"= f0<-function(x) {x-x^3/3},
"2"= f0<-function(x) {x-x^3/3+x^5/5},
"3"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7},
"4"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9},
"5"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11},
"6"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13},
"7"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15},
"8"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17},
"9"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17-x^19/19}
)

switch(x,
"0"=text0<-c("x"),
"1"=text0<-c("x-x^3/3"),
"2"=text0<-c("x-x^3/3+x^5/5"),
"3"=text0<-c("x-x^3/3+x^5/5-x^7/7"),
"4"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9"),
"5"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11"),
"6"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13"),
"7"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15"),
"8"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17"),
"9"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17-x^19/19")
)

f10=function(x){atan(x)}

plot(f10,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("Atan(x)",paste("Gregory=",text0)),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}

library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_log(i)
}
}, interval = 0.1, movie.name = "arctan02.gif") 
```

![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210205/20210205102345.gif)
<font color=red>*明らかに途中からEulerian Transformationの様子がおかしいですが、現段階では直し方が分かりません。今後の課題…(2021.2.4)</font>

```R
Macrolin_expansion_log<-function(x){
#グラフのスケール決定
Graph_scale_x<-c(-10,10)
Graph_scale_y<-c(-pi/2,pi/2)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x},
"1"= f0<-function(x) {x-x^3/3},
"2"= f0<-function(x) {x-x^3/3+x^5/5},
"3"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7},
"4"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9},
"5"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11},
"6"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13},
"7"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15},
"8"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17},
"9"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17-x^19/19}
)

switch(x,
"0"=text0<-c("x"),
"1"=text0<-c("x-x^3/3"),
"2"=text0<-c("x-x^3/3+x^5/5"),
"3"=text0<-c("x-x^3/3+x^5/5-x^7/7"),
"4"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9"),
"5"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11"),
"6"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13"),
"7"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15"),
"8"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17"),
"9"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17-x^19/19")
)

switch(x,
"0"= f1<-function(x) {x/(1+x^2)},
"1"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))},
"2"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2},
"3"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2},
"4"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3},
"5"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4},
"6"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5},
"7"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6},
"8"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7},
"9"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7+(2*4*6*8*10*12*14*16)/(3*5*7*9*11*13*15*17)*(x^2/(1+x^2))^8}
)

switch(x,
"0"=text1<-c("x/(1+x^2)"),
"1"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2))"),
"2"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2)"),
"3"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2)"),
"4"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3"),
"5"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4"),
"6"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5"),
"7"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6"),
"8"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7"),
"9"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)+(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7+(2*4*6*8*10*12*14*16)/(3*5*7*9*11*13*15*17)*(x^2/(1+x^2))^8")
)

f10=function(x){atan(x)}

plot(f10,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,1),main="", xlab="", ylab="")
par(new=T)#上書き指定
plot(f1,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("Atan(x)",paste("Gregory=",text0),paste("Euler=",text1)),lty=c(1,1,1),col=c(rgb(0,0,0),rgb(0,0,1),rgb(1,0,0)))
}

library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_log(i)
}
}, interval = 0.1, movie.name = "arctan01.gif") 
```
<font color=red>あれ？　もしかしたらこれが正解？　そんな訳はない？(2021.2.5)</font>
![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210206/20210206045554.gif)

```R
Macrolin_expansion_log<-function(x){
#グラフのスケール決定
Graph_scale_x<-c(-10,10)
Graph_scale_y<-c(-pi/2,pi/2)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x},
"1"= f0<-function(x) {x-x^3/3},
"2"= f0<-function(x) {x-x^3/3+x^5/5},
"3"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7},
"4"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9},
"5"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11},
"6"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13},
"7"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15},
"8"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17},
"9"= f0<-function(x) {x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17-x^19/19}
)

switch(x,
"0"=text0<-c("x"),
"1"=text0<-c("x-x^3/3"),
"2"=text0<-c("x-x^3/3+x^5/5"),
"3"=text0<-c("x-x^3/3+x^5/5-x^7/7"),
"4"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9"),
"5"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11"),
"6"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13"),
"7"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15"),
"8"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17"),
"9"=text0<-c("x-x^3/3+x^5/5-x^7/7+x^9/9-x^11/11+x^13/13-x^15/15+x^17/17-x^19/19")
)

switch(x,
"0"= f1<-function(x) {x/(1+x^2)},
"1"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))},
"2"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2},
"3"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2},
"4"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3},
"5"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4},
"6"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5},
"7"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5-(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6},
"8"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5-(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7},
"9"= f1<-function(x) {x/(1+x^2)*(1+2/3*x^2/(1+x^2))-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5-(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7-(2*4*6*8*10*12*14*16)/(3*5*7*9*11*13*15*17)*(x^2/(1+x^2))^8}
)

switch(x,
"0"=text1<-c("x/(1+x^2)"),
"1"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2))"),
"2"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2)"),
"3"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2)"),
"4"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3"),
"5"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4"),
"6"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5"),
"7"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3-(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6"),
"8"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2-(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5+(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7"),
"9"=text1<-c("x/(1+x^2)*(1+2/3*x^2/(1+x^2)-(2*4)/(3*5)*(x^2/(1+x^2))^2+(2*4*6)/(3*5*7)*(x^2/(1+x^2))^3+(2*4*6*8)/(3*5*7*9)*(x^2/(1+x^2))^4+(2*4*6*8*10)/(3*5*7*9*11)*(x^2/(1+x^2))^5-(2*4*6*8*10*12)/(3*5*7*9*11*13)*(x^2/(1+x^2))^6+(2*4*6*8*10*12*14)/(3*5*7*9*11*13*15)*(x^2/(1+x^2))^7-(2*4*6*8*10*12*14*16)/(3*5*7*9*11*13*15*17)*(x^2/(1+x^2))^8")
)

f10=function(x){atan(x)}

plot(f10,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,1),main="", xlab="", ylab="")
par(new=T)#上書き指定
plot(f1,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("Atan(x)",paste("Gregory=",text0),paste("Euler=",text1)),lty=c(1,1,1),col=c(rgb(0,0,0),rgb(0,0,1),rgb(1,0,0)))
}

library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_log(i)
}
}, interval = 0.1, movie.name = "arctan02.gif") 
```
<font color=red>もしかしたらオイラー変換が有効なのは奇数項、それもX=1の場合のみだったりする？(2021.2.6)</font>
[長田直樹「数値解析 第6回 収束の加速法(中編)](https://www.lab.twcu.ac.jp/~osada/rikei/rikei2008-10.pdf)

```R
> pi/4
[1] 0.7853982

#ライプニッツ級数
> 1-1/3
[1] 0.6666667
> 1-1/3+1/5
[1] 0.8666667
> 1-1/3+1/5-1/7
[1] 0.7238095
> 1-1/3+1/5-1/7+1/9
[1] 0.8349206
> 1-1/3+1/5-1/7+1/9-1/11
[1] 0.7440115
> 1-1/3+1/5-1/7+1/9-1/11+1/13
[1] 0.8209346
> 1-1/3+1/5-1/7+1/9-1/11+1/13-1/15
[1] 0.754268
> 1-1/3+1/5-1/7+1/9-1/11+1/13-1/15+1/17
[1] 0.8130915
> 1-1/3+1/5-1/7+1/9-1/11+1/13-1/15+1/17-1/19
[1] 0.7604599
> 1-1/3+1/5-1/7+1/9-1/11+1/13-1/15+1/17-1/19+1/21
[1] 0.808079
> 1-1/3+1/5-1/7+1/9-1/11+1/13-1/15+1/17-1/19+1/21-1/23
[1] 0.7646007

#ライプニッツ級数へのオイラー変換の適用
> 1/2*(1+1/3)
[1] 0.6666667
> 1/2*(1+1/3+(1*2)/(3*5))
[1] 0.7333333
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7))
[1] 0.7619048
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9))
[1] 0.7746032
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9)+(1*2*3*4*5)/(3*5*7*9*11))
[1] 0.7803752
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9)+(1*2*3*4*5)/(3*5*7*9*11)+(1*2*3*4*5*6)/(3*5*7*9*11*13))
[1] 0.7830392
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9)+(1*2*3*4*5)/(3*5*7*9*11)+(1*2*3*4*5*6)/(3*5*7*9*11*13)+(1*2*3*4*5*6*7)/(3*5*7*9*11*13*15))
[1] 0.7842824
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9)+(1*2*3*4*5)/(3*5*7*9*11)+(1*2*3*4*5*6)/(3*5*7*9*11*13)+(1*2*3*4*5*6*7)/(3*5*7*9*11*13*15)+(1*2*3*4*5*6*7*8)/(3*5*7*9*11*13*15*17))
[1] 0.7848674
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9)+(1*2*3*4*5)/(3*5*7*9*11)+(1*2*3*4*5*6)/(3*5*7*9*11*13)+(1*2*3*4*5*6*7)/(3*5*7*9*11*13*15)+(1*2*3*4*5*6*7*8)/(3*5*7*9*11*13*15*17)+(1*2*3*4*5*6*7*8*9)/(3*5*7*9*11*13*15*17*19))
[1] 0.7851445
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9)+(1*2*3*4*5)/(3*5*7*9*11)+(1*2*3*4*5*6)/(3*5*7*9*11*13)+(1*2*3*4*5*6*7)/(3*5*7*9*11*13*15)+(1*2*3*4*5*6*7*8)/(3*5*7*9*11*13*15*17)+(1*2*3*4*5*6*7*8*9)/(3*5*7*9*11*13*15*17*19)+(1*2*3*4*5*6*7*8*9*10)/(3*5*7*9*11*13*15*17*19*21))
[1] 0.7852765
> 1/2*(1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+(1*2*3*4)/(3*5*7*9)+(1*2*3*4*5)/(3*5*7*9*11)+(1*2*3*4*5*6)/(3*5*7*9*11*13)+(1*2*3*4*5*6*7)/(3*5*7*9*11*13*15)+(1*2*3*4*5*6*7*8)/(3*5*7*9*11*13*15*17)+(1*2*3*4*5*6*7*8*9)/(3*5*7*9*11*13*15*17*19)+(1*2*3*4*5*6*7*8*9*10)/(3*5*7*9*11*13*15*17*19*21)+(1*2*3*4*5*6*7*8*9*10*11)/(3*5*7*9*11*13*15*17*19*21*23))
[1] 0.7853396
#「加速」の意味が良く分かる？
```
グラフ化してみる。
![Rplot24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/a4455bdb-eb86-7a1e-b4a8-d4122458683d.png)

```R
cx<-0:10
cy1<-c(0.6666667,0.8666667,0.7238095,0.8349206,0.7440115,0.8209346,0.754268,0.8130915,0.7604599,0.808079,0.7646007)
cy2<-c(0.6666667,0.7333333,0.7619048,0.7746032,0.7803752,0.7830392,0.7842824,0.7848674,0.7851445,0.7852765,0.7853396)
plot(cx,cy1,xlim=c(0,10),ylim=c(0.65,0.9),type="l",col=rgb(0,0,1),main="Leibniz Series & Eulerian Transformation", xlab="x", ylab="y")
par(new=T)#上書き指定
plot(cx,cy2,xlim=c(0,10),ylim=c(0.65,0.9),type="l",col=rgb(0,1,0),main="", xlab="", ylab="")
abline(h=pi/4,col=rgb(1,0,0))
legend("topright", legend=c("π/4=0.7853982","Leibniz","Euler"),lty=c(1,1,1),col=c(rgb(1,0,0),rgb(0,0,1),rgb(0,1,0)))
```
ところで任意の（<font color=blue>すべての</font>）**正の実数**は<font color=purple>α×２^n</font>(<font color=blue>1≦α<2;nは整数</font>)の形に表せるので,<font color=purple>log(α×2^n)</font>＝<font color=purple>log(α)+n×log(2)</font>と示せます(<font color=blue>ただしここにlog(3,base=2)が混ざり込む</font>)。

```R

> 2^0
[1] 1
> 2^1
[1] 2
> 2^0+2^1
[1] 3

#ところで
> 2^1.5849625
[1] 3
> log(3)/log(2)
[1] 1.584963
> log(3,base=2)
[1] 1.584963

#2^2
> 2^2
[1] 4
> 2^2+2^0
[1] 5
> 2^2+2^1
[1] 6

> 2^2+2^log(3,base=2)
[1] 7

#2^3
> 2^3
[1] 8
```
一覧表(<font color=blue>8まで</font>)

<!-- html table generated in R 3.5.2 by xtable 1.8-4 package -->
<!-- Tue Feb 16 05:08:43 2021 -->
<table border=1>
<tr> <th>  </th> <th> Values </th> <th> Explessions </th>  </tr>
  <tr> <td align="right"> 1 </td> <td> 1 </td> <td> 2^0 </td> </tr>
  <tr> <td align="right"> 2 </td> <td> 2 </td> <td> 2^1 </td> </tr>
  <tr> <td align="right"> 3 </td> <td> 3 </td> <td> 2^0+2^1 / 2^log(3,base=2) </td> </tr>
  <tr> <td align="right"> 4 </td> <td> 4 </td> <td> 2^2 </td> </tr>
  <tr> <td align="right"> 5 </td> <td> 5 </td> <td> 2^2+2^0 </td> </tr>
  <tr> <td align="right"> 6 </td> <td> 6 </td> <td> 2^2+2^1 </td> </tr>
  <tr> <td align="right"> 7 </td> <td> 7 </td> <td> 2^2+2^log(3,base=2) </td> </tr>
  <tr> <td align="right"> 8 </td> <td> 8 </td> <td> 2^3 </td> </tr>
   </table>

```R
target_values<-c("1","2","3","4","5","6","7","8")

target_explession<-c("2^0","2^1","2^0+2^1 / 2^log(3,base=2)","2^2","2^2+2^0","2^2+2^1","2^2+2^log(3,base=2)","2^3")

Regula_falsi04<-data.frame(Values=target_values,Explessions=target_explession)
library(xtable)
print(xtable(Regula_falsi04), type = "html")
```
つまり<font color=green>log(2)</font>の値さえ求めておけば,ここで示した近似式を用いて任意の正の実数<font color=green>x</font>の**自然対数**<font color=green>log(x)</font>の値を計算出来る事になるのです。
[対数関数のTylor展開](http://math-lab.main.jp/taylor7b.html)
[【無限遠点を巡る数理】等差数列と等比数列②基底関数概念の導入](https://qiita.com/ochimusha01/items/df8c006439794da89684)

```R
#オイラー変換に従ったLog(2)の計算
> 2/3+2/3*(1/3)^3+2/5*(1/3)^5+2/7*(1/3)^7
[1] 0.6931348
> log(2)
[1] 0.6931472

#log(2)に基づく計算

#log(1)
> log(1)
[1] 0
> log(2)+log(1/2)
[1] 0
#log(3)
> log(3)
[1] 1.098612
> exp(log(3)-log(2))
[1] 1.5
> log(1.5)+log(2)
[1] 1.098612
#log(4)

> log(4)
[1] 1.386294
> log(2)*2
[1] 1.386294
> log(2^2)
[1] 1.386294

#log(5)

 > log(5)
[1] 1.609438

> exp(log(5)-log(2^2))
[1] 1.25
>log(1.25)+log(2^2)
[1] 1.609438

#log(6)
> log(6)
[1] 1.791759
> exp(log(6)-log(2^2))
[1] 1.5
> log(1.5)+log(2^2)
[1] 1.791759

#log(7)

> log(7)
[1] 1.94591
> exp(log(7)-log(2^2))
[1] 1.75
> log(1.75)+log(2^2)
[1] 1.94591

#log(8)

> log(8)
[1] 2.079442
> log(2)*3
[1] 2.079442
> log(2^3)
[1] 2.079442
```
一覧表(<font color=blue>8まで</font>)

<!-- html table generated in R 3.5.2 by xtable 1.8-4 package -->
<!-- Tue Feb 16 04:54:59 2021 -->
<table border=1>
<tr> <th>  </th> <th> Numbers </th> <th> Explessions </th> <th> Values </th>  </tr>
  <tr> <td align="right"> 1 </td> <td> log(1) </td> <td> log(2^1)+log(1/2) </td> <td> 0 </td> </tr>
  <tr> <td align="right"> 2 </td> <td> log(2) </td> <td> log(2^1) </td> <td> 0.6931472 </td> </tr>
  <tr> <td align="right"> 3 </td> <td> log(3) </td> <td> log(1.5)+log(2^1) </td> <td> 1.098612 </td> </tr>
  <tr> <td align="right"> 4 </td> <td> log(4) </td> <td> log(2^2) </td> <td> 1.386294 </td> </tr>
  <tr> <td align="right"> 5 </td> <td> log(5) </td> <td> log(1.25)+log(2^2) </td> <td> 1.609438 </td> </tr>
  <tr> <td align="right"> 6 </td> <td> log(6) </td> <td> log(1.5)+log(2^2) </td> <td> 1.791759 </td> </tr>
  <tr> <td align="right"> 7 </td> <td> log(7) </td> <td> log(1.75)+log(2^2) </td> <td> 1.94591 </td> </tr>
  <tr> <td align="right"> 8 </td> <td> log(8) </td> <td> log(2^3) </td> <td> 2.079442 </td> </tr>
   </table>

```R
target_number<-c("log(1)","log(2)","log(3)","log(4)","log(5)","log(6)","log(7)","log(8)")

target_explession<-c("log(2^1)+log(1/2)","log(2^1)","log(3/2)+log(2^1)","log(2^2)","log(5/4)+log(2^2)","log(3/2)+log(2^2)","log(7/4)+log(2^2)","log(2^3)")

target_values<-c("0","0.6931472","1.098612","1.386294","1.609438","1.791759","1.94591","2.079442")

Regula_falsi04<-data.frame(Numbers=target_number,Explessions=target_explession,Values=target_values)
library(xtable)
print(xtable(Regula_falsi04), type = "html")
```


ちなみに**アークタンジェント関数**の逆関数たる**タンジェント関数**のマクローリン変換は全く別の形となり、実用性がありません。
[tanxの高階微分とマクローリン展開](https://mathtrain.jp/tanmaclaurin)
[]()

```R
#Arctangent関数とTangent関数の関係
> atan(1)
[1] 0.7853982
> pi/4
[1] 0.7853982
> tan(pi/4)
[1] 1
```
![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210207/20210207062636.gif)

```R
Macrolin_expansion_tan<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-pi/2,pi/2)
Graph_scale_y<-c(-10,10)
#関数と凡例の決定
switch(x,
"1"= f0<-function(x) {x},
"2"= f0<-function(x) {x + x^3/3},
"3"= f0<-function(x) {1 + x^3/3 + 2*x^5/24},
"4"= f0<-function(x) {1 + x^3/3 + 2*x^5/24 + 17*x^7/315}
)

switch(x,
"1"=text<-c("x"),
"2"=text<-c("x + x^3/3"),
"3"=text<-c("1 + x^3/3 + 2*x^5/24"),
"4"=text<-c("1 + x^3/3 + 2*x^5/24 + 17*x^7/315")
)

plot(tan,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("tan",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}

library("animation")
Time_Code=c("1","1","1","2","2","2","3","3","3","4","4","4")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_tan(i)
}
}, interval = 0.1, movie.name = "tan01.gif") 
```
コサイン波の値については、_90度（π/2ラジアン）と270度（3π/2ラジアン）で0となる性質_が、マクローリン変換においては_奇数の冪（べき）数が0になって消える特徴_として現れます。

<!-- Fri Mar  6 15:48:46 2020 -->
<table border=1>
<tr> <th>  </th> <th> Target_names </th> <th> Target_values </th>  </tr>
  <tr> <td align="right"> 1 </td> <td> 0 radian &amp; 0 degree </td> <td> 1 </td> </tr>
  <tr> <td align="right"> 2 </td> <td> π/2 radian &amp; 90 degree </td> <td> 0 </td> </tr>
  <tr> <td align="right"> 3 </td> <td> π radian &amp; 180 degree </td> <td> -1 </td> </tr>
  <tr> <td align="right"> 4 </td> <td> 3/2π&amp; 270 degree </td> <td> 0 </td> </tr>
  <tr> <td align="right"> 5 </td> <td> 2π &amp; 360 degree </td> <td> 1 </td> </tr>
   </table>

```R
target_names<-c("0 radian & 0 degree","π/2 radian & 90 degree","π radian & 180 degree","3/2π& 270 degree","2π & 360 degree")

target_values<-c("1","0","-1","0","1")

Circular_function<-data.frame(Target_names=target_names,Target_values=target_values)
library(xtable)
print(xtable(Circular_function), type = "html")
```

![20190602134935.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/41742bb1-37d7-7c6c-a17e-dddb275a0bed.png)

```R
plot(cos,xlim=c(-4,+4),ylim=c(-1,1),main="Cosine wave", xlab="X", ylab="Y")
```

**コサイン波のマクローリン展開**

![20190602094315.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/59579509-271e-df92-a709-b72857798597.gif)


```R
Macrolin_expansion_cos<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-6,6)
Graph_scale_y<-c(-1,1)
#関数と凡例の決定
switch(x,
"1"= f0<-function(x) {x/x},
"2"= f0<-function(x) {1 - x^2/2},
"3"= f0<-function(x) {1 - x^2/2 + x^4/24},
"4"= f0<-function(x) {1 - x^2/2 + x^4/24 - x^6/720},
"5"= f0<-function(x) {1 - x^2/2 + x^4/24 - x^6/720 + x^8/40320},
"6"= f0<-function(x) {1 - x^2/2 + x^4/24 - x^6/720 + x^8/40320 + 
x^12/479001600},
"7"= f0<-function(x) {1 - x^2/2 + x^4/24 - x^6/720 + x^8/40320 + 
x^12/479001600 - x^14/87178291200}
)

switch(x,
"1"=text<-c("1"),
"2"=text<-c("1-x^2/2!"),
"3"=text<-c("1-x^2/2!+x^4/4!"),
"4"=text<-c("1-x^2/2!+x^4/4!-x^6/6!"),
"5"=text<-c("1-x^2/2!+ x^4/4! - x^6/6! + x^8/8!"),
"6"=text<-c("1-x^2/2!+x^4/4!-x^6/6!+x^8/8!+x^12/12!"),
"7"=text<-c("1-x^2/2!+x^4/4!-x^6/6!+x^8/8!+x^12/12!-x^14/14!"),
)

plot(cos,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("sin",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}

library("animation")
Time_Code=c("1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_cos(i)
}
}, interval = 0.1, movie.name = "TEST01.gif") 
```

サイン波の値については、_0度（0ラジアン）と270度（πラジアン）で0となる性質_が、マクローリン変換においては_偶数の冪（べき）数が0になって消える特徴_として現れます。

<!-- html table generated in R 3.5.2 by xtable 1.8-4 package -->
<!-- Fri Mar  6 15:57:14 2020 -->
<table border=1>
<tr> <th>  </th> <th> Target_names </th> <th> Target_values </th>  </tr>
  <tr> <td align="right"> 1 </td> <td> 0 radian &amp; 0 degree </td> <td> 0 </td> </tr>
  <tr> <td align="right"> 2 </td> <td> π/2 radian &amp; 90 degree </td> <td> 1 </td> </tr>
  <tr> <td align="right"> 3 </td> <td> π radian &amp; 180 degree </td> <td> 0 </td> </tr>
  <tr> <td align="right"> 4 </td> <td> 3/2π&amp; 270 degree </td> <td> -1 </td> </tr>
  <tr> <td align="right"> 5 </td> <td> 2π &amp; 360 degree </td> <td> 0 </td> </tr>
   </table>

```R
target_names<-c("0 radian & 0 degree","π/2 radian & 90 degree","π radian & 180 degree","3/2π& 270 degree","2π & 360 degree")

target_values<-c("0","1","0","-1","0")

Circular_function<-data.frame(Target_names=target_names,Target_values=target_values)
library(xtable)
print(xtable(Circular_function), type = "html")
```
![20190602134519.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/ef3e7370-581d-79c3-dbd8-65643258582a.png)

```R
plot(sin,xlim=c(-4,+4),ylim=c(-1,1),main="Sine wave", xlab="X", ylab="Y")
```

**サイン波のマクローリン展開**
![20190602093127.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/583def61-4422-f319-dbbe-7e66a522a8ae.gif)

```R
Macrolin_expansion_sin<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-6,6)
Graph_scale_y<-c(-1,1)
#関数と凡例の決定
switch(x,
"1"= f0<-function(x) {x},
"2"= f0<-function(x) {x - x^3/6},
"3"= f0<-function(x) {x - x^3/6 + x^5/120},
"4"= f0<-function(x) {x - x^3/6 + x^5/120 - x^7/5040},
"5"= f0<-function(x) {x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880},
"6"= f0<-function(x) {x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880 - x^11/39916800},
"7"= f0<-function(x) {x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880 - x^11/39916800 + 
x^13/6227020800}
)

switch(x,
"1"=text<-c("x"),
"2"=text<-c("x-x^3/3!"),
"3"=text<-c("x-x^3/3!+x^5/5!"),
"4"=text<-c("x-x^3/3!+x^5/5!-x^7/7!"),
"5"=text<-c("x-x^3/3!+x^5/5!-x^7/7!+x^9/9!"),
"6"=text<-c("x-x^3/3!+x^5/5!-x^7/7!+x^9/9!-x^11/11!"),
"7"=text<-c("x-x^3/3!+x^5/5!-x^7/7!+x^9/9!-x^11/11!+x^13/13!")
)

plot(sin,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("sin",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}
library("animation")
Time_Code=c("1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_sin(i)
}
}, interval = 0.1, movie.name = "TEST01.gif")
```
ここに**２乗すると-１になる複素数i**と**実数部をX軸に 、虚数部をY軸に割り当てる複素数­平面**（独Komplexe Zahlenebene, 英complex plane）の概念を導入すると**位相が90度ズレた同じ波を直交させると円を描く数理**と上手く結び付くのです。
[【初心者向け】物理学における「単位円筒(Unit Cylinder)」の概念について。](https://qiita.com/ochimusha01/items/ced1c21b4411e79cdcbe)
**XY軸**（円弧）
![20191029133633.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/0e55e673-d89e-6d33-6e33-9edf6fecdbdd.gif)
**XZ軸**（Cos波）
![20191029193635.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/529cc2b1-3476-4eba-1c07-a79cc8ba16d7.gif)
**YZ軸**（Sin波）
![20191029194000.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/fa66cf1a-291e-8e76-8ea7-c586efcb1e21.gif)
[複素数平面（独Komplexe Zahlenebene, 英complex plane） - Wikipedia](https://ja.wikipedia.org/wiki/%E8%A4%87%E7%B4%A0%E5%B9%B3%E9%9D%A2)
>1811年頃に**ガウス**（Johann Carl Friedrich Gauß、1777年〜1855年）によって導入されたため、**ガウス平面** (Gaussian plane) とも呼ばれる。一方、それに先立つ1806年にJean-Robert Argandも同様の手法を用いたため、**アルガン図**(Argand Diagram)とも呼ばれている。さらに、それ以前の1797年のCaspar Wesselの書簡にも登場している。このように複素数の幾何的表示はガウス以前にも知られていたが、今日用いられているような形式で複素平面を論じたのはガウスである。三者の名前をとってガウス・アルガン平面、ガウス・ウェッセル平面などとも言われる。

**統計言語Rによる「オイラーの公式」の検証例**

```R
#まずは統計言語Rから呼べるYacasライブラリを導入
library(Ryacas)
#Cos(x)=x/1! - x^2/2! + x^4/4! - x^6/6! + x^8/8!...
yacas("Taylor(x, 0, 8) Cos(x)") #マクローリン展開
expression(1 - x^2/2 + x^4/24 - x^6/720 + x^8/40320)

#sin(x)=x/1! - x^3/3! + x^5/5! - x^7/7! + x^9/9!...
yacas("Taylor(x, 0, 11) Sin(x)") #マクローリン展開
expression(x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880)

#Exp(x)=x/1! + x^2/2! + x^3/3! + x^4/4! + x^4/5! + x^6/6! + x^7/7! + x^8/8! + x^9/9!...
yacas("Taylor(x, 0, 9) Exp(x)") #マクローリン展開
expression(x + x^2/2 + x^3/6 + x^4/24 + x^5/120 + x^6/720 + x^7/5040 + 
x^8/40320 + x^9/362880 + 1)

#ただ合算しただけではCos関数とSin関数の合成関数を近似するのみである。
yacas("Taylor(x, 0, 9) Sin(x)+Cos(x)")
expression(x - x^2/2 - x^3/6 + x^4/24 + x^5/120 - x^6/720 - x^7/5040 + 
x^8/40320 + x^9/362880 + 1)

#ここに「２乗すると-１になる複素数i」の概念を導入すると符号違いの問題が解決されてExp(xi)=Cos(x)+Sin(xi)が成立する。
Exp(xi)=xi/1!+xi^2/2!+xi^3/3!+xi^4/4!+xi^4/5!+xi^6/6!+xi^7/7!+xi^8/8!+xi^9/9!…
Exp(xi)=1+xi-x^2/2-xi^3/3!+x^4/4!+xi^5/5!-x^6/6!-xi^7/7!+x^8/8!+xi^9/9!…
Exp(xi)=(1-x^2/2+x^4/4-x^6/6!+x^8/8!…)+(xi-xi^3/3!+xi^5/5!-xi^7/7!+ xi^9/9!…)
Exp(xi)=Cos(x)+Sin(xi)
```
**cos波を主体とする合成波の近似**

![20190602111317.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/9d71ee2f-840d-a1bd-8a06-4d5b3aaf3436.gif)

```R
Macrolin_expansion_circle<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-4,4)
Graph_scale_y<-c(-4,4)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x/x},
"1"= f0<-function(x) {1+x*(0+1i)},
"2"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2},
"3"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6},
"4"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24},
"5"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120},
"6"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120+(x*(0+1i))^6/720},
"7"= f0<-function(x) {1+x*(0+1i)-(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120+(x*(0+1i))^6/720+(x*(0+1i))^7/5040},
"8"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120+(x*(0+1i))^6/720+(x*(0+1i))^7/5040+(x*(0+1i))^8/40320},
"9"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24 +(x*(0+1i))^5/120+(x*(0+1i))^6/720+(x*(0+1i))^7/5040 +(x*(0+1i))^8/40320 + x^9/362880 }
)

switch(x,
"0"=text<-c("1"),
"1"=text<-c("1+xi"),
"2"=text<-c("1+xi+xi^2/2!"),
"3"=text<-c("1+xi+xi^2/2!+x^3/3!"),
"4"=text<-c("1+xi+xi^2/2!+xi^3/3!+x^4/4!"),
"5"=text<-c("1+xi+xi^2/2!+xi^3/3!+x^4/4!+x^5/5!"),
"6"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!"),
"7"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!+xi^7/7!"),
"8"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!+xi^7/7!+xi^8/8!"),
"9"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!+xi^7/7!+xi^8/8!+xi^9/9!")
)
f1<-function(x){cos(x)+sin(x*(0+1i))}
plot(f1,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("e^xi=cos(x)+sin(xi)",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}


library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_circle(i)
}
}, interval = 0.1, movie.name = "TEST01.gif") 
```

**sin波を主体とする合成波の近似**

![20190602114504.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/4bc87b6a-8961-ebcb-bff3-0cce97b45971.gif)

```R
Macrolin_expansion_circle<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-4,4)
Graph_scale_y<-c(-4,4)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x/x},
"1"= f0<-function(x) {1+x},
"2"= f0<-function(x) {1+x-x^2/2},
"3"= f0<-function(x) {1+x-x^2/2-x^3/6},
"4"= f0<-function(x) {1+x-x^2/2-x^3/6+x^4/24},
"5"= f0<-function(x) {1+x-x^2/2-x^3/6+x^4/24+x^5/120},
"6"= f0<-function(x) {1+x-x^2/2-x^3/6+x^4/24+x^5/120-x^6/720},
"7"= f0<-function(x) {1+x-x^2/2-x^3/6+x^4/24+ x^5/120-x^6/720- x^7/5040},
"8"= f0<-function(x) {1+x-x^2/2-x^3/6+x^4/24+x^5/120-x^6/720+ x^7/5040+ x^8/40320},
"9"= f0<-function(x) {1+x-x^2/2-x^3/6+x^4/24+x^5/120-x^6/720- x^7/5040+x^8/40320+x^9/362880 }
)

switch(x,
"0"=text<-c("1"),
"1"=text<-c("1+xi"),
"2"=text<-c("1+xi-xi^2/2!"),
"3"=text<-c("1+xi-xi^2/2!-x^3/3!"),
"4"=text<-c("1+xi-xi^2/2!-xi^3/3!+x^4/4!"),
"5"=text<-c("1+xi-xi^2/2!-xi^3/3!+x^4/4!+x^5/5!"),
"6"=text<-c("1+xi-xi^2/2!-xi^3/3!+xi^4/4!+xi^5/5!-xi^6/6!"),
"7"=text<-c("1+xi-xi^2/2!-xi^3/3!+xi^4/4!+xi^5/5!-xi^6/6!-xi^7/7!"),
"8"=text<-c("1+xi-xi^2/2!-xi^3/3!+xi^4/4!+xi^5/5!-xi^6/6!-xi^7/7!+xi^8/8!"),
"9"=text<-c("1+xi+xi^2/2!-xi^3/3!+xi^4/4!+xi^5/5!-xi^6/6!-xi^7/7!+xi^8/8!+xi^9/9!")
)
f1<-function(x){cos(x)+sin(x)}
plot(f1,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("e^xi=cos(x)+sin(x)",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}

library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_circle(i)
}
}, interval = 0.1, movie.name = "TEST01.gif") 
```
これだけではまだ円を描いたとはいえません。それを実現するには、さらに**実数部をX軸に 、虚数部をY軸に割り当てる複素数­平面**（球面、独Komplexe Zahlenebene, 英complex plane）**の概念**の導入が必須となります。ところが…
#実際のオイラーの公式は、発見された時点で円を描けた訳ではない？
![20190602123436.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/597772/e9449153-a438-7105-7174-eca9ccd74d00.gif)

```R
Macrolin_expansion_circle<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-2,2)
Graph_scale_y<-c(-2,2)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x/x},
"1"= f0<-function(x) {1+x*(0+1i)},
"2"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2},
"3"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6},
"4"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24},
"5"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120},
"6"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120+(x*(0+1i))^6/720},
"7"= f0<-function(x) {1+x*(0+1i)-(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120+(x*(0+1i))^6/720+(x*(0+1i))^7/5040},
"8"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24+(x*(0+1i))^5/120+(x*(0+1i))^6/720+(x*(0+1i))^7/5040+(x*(0+1i))^8/40320},
"9"= f0<-function(x) {1+x*(0+1i)+(x*(0+1i))^2/2+(x*(0+1i))^3/6+(x*(0+1i))^4/24 +(x*(0+1i))^5/120+(x*(0+1i))^6/720+(x*(0+1i))^7/5040 +(x*(0+1i))^8/40320 + x^9/362880 }
)

switch(x,
"0"=text<-c("1"),
"1"=text<-c("1+xi"),
"2"=text<-c("1+xi+xi^2/2!"),
"3"=text<-c("1+xi+xi^2/2!+x^3/3!"),
"4"=text<-c("1+xi+xi^2/2!+xi^3/3!+x^4/4!"),
"5"=text<-c("1+xi+xi^2/2!+xi^3/3!+x^4/4!+x^5/5!"),
"6"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!"),
"7"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!+xi^7/7!"),
"8"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!+xi^7/7!+xi^8/8!"),
"9"=text<-c("1+xi+xi^2/2!+xi^3/3!+xi^4/4!+xi^5/5!+xi^6/6!+xi^7/7!+xi^8/8!+xi^9/9!")
)

theta <- c(seq(0, pi, length=180),seq(-pi, 0, length=180))
plot(cos(theta), sin(theta),xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="Real Expanse", ylab="Imaginaly Expanse")
par(new=T)#上書き指定

Re01=Re(f0(theta))
Im01=Im(f0(theta))
plot(Re01,Im01,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("e^xi=cos(x)+sin(xi)",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}

library("animation")
Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_circle(i)
}
}, interval = 0.1, movie.name = "TEST01.gif") 
```
そのままコーディングするとこうなっちゃうのです。とはいえもちろん、こうした形でのマクローリン級数による近似の限界が暴露されるのは、あくまで**複素数­平面**（球面)の概念が発明された19世紀に入ってからだった訳ですが…
[【無限遠点を巡る数理】オイラーの公式と等比数列①その根本的差異について。](https://qiita.com/ochimusha01/items/acb68f984865c7597ed6)
![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210110/20210110223101.gif)

```R
Macrolin_expansion_exp<-function(x,s0){

#グラフのスケール決定
Graph_scale_x<-c(-6,6)
Graph_scale_y<-c(-1,6)
#関数と凡例の決定
switch(x,
"0"= f0<-function(x) {x/x},
"1"= f0<-function(x) {1+x},
"2"= f0<-function(x) {1+x+x^2/2},
"3"= f0<-function(x) {1+x+x^2/2+x^3/6},
"4"= f0<-function(x) {1+x+x^2/2+x^3/6+x^4/24},
"5"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120},
"6"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120+ x^6/720},
"7"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120+ x^6/720+ x^7/5040},
"8"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24+ x^5/120+ x^6/720+ x^7/5040+ x^8/40320},
"9"= f0<-function(x) {1 + x + x^2/2 + x^3/6+ x^4/24 + x^5/120 + x^6/720 + x^7/5040 + x^8/40320 + x^9/362880 }
)

switch(x,
"0"=text<-c("1"),
"1"=text<-c("1+x"),
"2"=text<-c("1+x+x^2/2!"),
"3"=text<-c("1+x+x^2/2!+x^3/3!"),
"4"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!"),
"5"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!"),
"6"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!"),
"7"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!+x^7/7!"),
"8"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!+x^7/7!+x^8/8!"),
"9"=text<-c("1+x+x^2/2!+x^3/3!+x^4/4!+x^5/5!+x^6/6!+x^7/7!+x^8/8!+x^9/9!")
)

s1<-f0(s0)
plot(s1,type="l",asp=1,xlim=c(-pi,pi),ylim=c(-pi,pi),main="Macrolin Expansion of EXP(1)^πi",xlab="Real",ylab="Imaginal",col=rgb(0,1,0))
par(new=T)
plot(c1,Re(s1),type="l",asp=1,xlim=c(-pi,pi),ylim=c(-pi,pi),main="",xlab="",ylab="",col=rgb(0,0,1))
par(new=T)
plot(c1,Im(s1),type="l",asp=1,xlim=c(-pi,pi),ylim=c(-pi,pi),main="",xlab="",ylab="",col=rgb(1,0,0))

legend("bottomleft", legend=c("e^πi","Cos(θ)","Sin(θ)",text),lty=c(1,1,1,1),col=c(rgb(0,1,0),rgb(0,0,1),rgb(1,0,0),rgb(0,0,0)))
}

#アニメーション描画

library("animation")

c0<-seq(-pi,pi,length=61)
s0<-(0+1i)*c0

Time_Code=c("0","0","0","1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7","8","8","8","9","9","9")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_exp(i,s0)
}
}, interval = 0.1, movie.name = "TEST02.gif")
```
[【無限遠点を巡る数理】オイラーの公式と等比数列④「中学生には難しいが高校生なら気付くレベル」？](https://qiita.com/ochimusha01/items/10f0276f9850bea6c993)
![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210119/20210119041651.gif)

```R
Macrolin_expansion_sin<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-6,6)
Graph_scale_y<-c(-15,15)
#関数と凡例の決定
switch(x,
"1"= f0<-function(x) {x},
"2"= f0<-function(x) {x + x^3/6},
"3"= f0<-function(x) {x + x^3/6 + x^5/120},
"4"= f0<-function(x) {x + x^3/6 + x^5/120 + x^7/5040},
"5"= f0<-function(x) {x + x^3/6 + x^5/120 + x^7/5040 + x^9/362880},
"6"= f0<-function(x) {x + x^3/6 + x^5/120 + x^7/5040 + x^9/362880 + x^11/39916800},
"7"= f0<-function(x) {x + x^3/6 + x^5/120 + x^7/5040 + x^9/362880 + x^11/39916800 + 
x^13/6227020800}
)

switch(x,
"1"=text<-c("x"),
"2"=text<-c("x+x^3/3!"),
"3"=text<-c("x+x^3/3!+x^5/5!"),
"4"=text<-c("x+x^3/3!+x^5/5!+x^7/7!"),
"5"=text<-c("x+x^3/3!+x^5/5!+x^7/7!+x^9/9!"),
"6"=text<-c("x+x^3/3!+x^5/5!+x^7/7!+x^9/9!+x^11/11!"),
"7"=text<-c("x+x^3/3!+x^5/5!+x^7/7!+x^9/9!+x^11/11!+x^13/13!")
)

plot(sinh,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("sinh",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}
library("animation")
Time_Code=c("1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_sin(i)
}
}, interval = 0.1, movie.name = "sinh01.gif")
```
![image.gif](https://cdn-ak.f.st-hatena.com/images/fotolife/o/ochimusha01/20210119/20210119223413.gif)

```R

Macrolin_expansion_cos<-function(x){

#グラフのスケール決定
Graph_scale_x<-c(-6,6)
Graph_scale_y<-c(0,12)
#関数と凡例の決定
switch(x,
"1"= f0<-function(x) {x/x},
"2"= f0<-function(x) {1 + x^2/2},
"3"= f0<-function(x) {1 + x^2/2 + x^4/24},
"4"= f0<-function(x) {1 + x^2/2 + x^4/24 + x^6/720},
"5"= f0<-function(x) {1 + x^2/2 + x^4/24 + x^6/720 + x^8/40320},
"6"= f0<-function(x) {1 + x^2/2 + x^4/24 + x^6/720 + x^8/40320 + 
x^12/479001600},
"7"= f0<-function(x) {1 + x^2/2 + x^4/24 + x^6/720 + x^8/40320 + 
x^12/479001600 + x^14/87178291200}
)

switch(x,
"1"=text<-c("1"),
"2"=text<-c("1+x^2/2!"),
"3"=text<-c("1+x^2/2!+x^4/4!"),
"4"=text<-c("1+x^2/2!+x^4/4!+x^6/6!"),
"5"=text<-c("1+x^2/2!+ x^4/4! + x^6/6! + x^8/8!"),
"6"=text<-c("1+x^2/2!+x^4/4!+x^6/6!+x^8/8!+x^12/12!"),
"7"=text<-c("1+x^2/2!+x^4/4!+x^6/6!+x^8/8!+x^12/12!+x^14/14!"),
)

plot(cosh,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(0,0,0),main="Macrolin expansion", xlab="X", ylab="Y")
par(new=T)#上書き指定
plot(f0,xlim=Graph_scale_x,ylim=Graph_scale_y,type="l",col=rgb(1,0,0),main="", xlab="", ylab="")

legend("bottomleft", legend=c("cosh",text),lty=c(1,1),col=c(rgb(0,0,0),rgb(1,0,0)))
}

library("animation")
Time_Code=c("1","1","1","2","2","2","3","3","3","4","4","4","5","5","5","6","6","6","7","7","7")
saveGIF({
for (i in Time_Code){
　　Macrolin_expansion_cos(i)
}
}, interval = 0.1, movie.name = "Cosh01.gif")

```
そんな感じで以下続報…