{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Calcuration of Euler Mascheroni constant using Euler Maclaurin Summation Formula package for Maxima CAS\n", "\n", "Written by Yasuaki dot Honda at gmail dot com\n", "\n", "Copyright 2020 Yasuaki Honda\n", "\n", "GPL2.0\n", "\n", "Application to Euler Mascheroni constant is taken from the following PDF:\n", "\n", "http://people.csail.mit.edu/kuat/courses/euler-maclaurin.pdf" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{1}$}\\left[ \\mbox{ /root/quicklisp/dists/quicklisp/archives/euler-maclaurin-sum-master.gz } , \\mbox{ /root/quicklisp/local-projects/YasuakiHonda-euler-maclaurin-sum-69eb859/ } \\right] \\]" ], "text/plain": [ "(%o1) [/root/quicklisp/dists/quicklisp/archives/euler-maclaurin-sum-master.gz, \n", " /root/quicklisp/local-projects/YasuakiHonda-euler-maclaurin-sum-69eb859/]" ], "text/x-maxima": [ "[\"/root/quicklisp/dists/quicklisp/archives/euler-maclaurin-sum-master.gz\",\n", " \"/root/quicklisp/local-projects/YasuakiHonda-euler-maclaurin-sum-69eb859/\"]" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "install_github(\"YasuakiHonda\",\"euler-maclaurin-sum\",\"master\");" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{2}$}\\#\\]" ], "text/plain": [ "(%o2) #" ], "text/x-maxima": [ "\\#\\" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "asdf_load_source(\"euler-maclaurin-sum\");" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{3}$}\\sum_{n=N}^{M}{f\\left(n\\right)}=\\sum_{k=1}^{K-1}{\\frac{\\left(-1\\right)^{k+1}\\,B_{k+1}\\,\\left(\\left.\\frac{d^{k}}{d\\,x^{k}}\\,f\\left(x\\right)\\right|_{x=M}-\\left.\\frac{d^{k}}{d\\,x^{k}}\\,f\\left(x\\right)\\right|_{x=N}\\right)}{\\left(k+1\\right)!}}+\\frac{\\left(-1\\right)^{K+1}\\,\\int_{N}^{M}{\\overline{B}_{K}\\left(x\\right)\\,\\left(\\frac{d^{K}}{d\\,x^{K}}\\,f\\left(x\\right)\\right)\\;dx}}{K!}+\\int_{N}^{M}{f\\left(x\\right)\\;dx}+\\frac{f\\left(N\\right)}{2}+\\frac{f\\left(M\\right)}{2}\\]" ], "text/plain": [ " M\n", " ====\n", " \\\n", "(%o3) > f(n) = \n", " /\n", " ====\n", " n = N\n", " ! !\n", " k ! k !\n", " k + 1 d ! d !\n", " (- 1) bern(k + 1) (--- (f(x))! - --- (f(x))! )\n", "K - 1 k ! k !\n", "==== dx ! dx !\n", "\\ !x = M !x = N\n", " > ------------------------------------------------------------\n", "/ (k + 1)!\n", "====\n", "k = 1\n", " M\n", " / K\n", " K + 1 [ d\n", " (- 1) I periodic_bernpoly(x, K) (--- (f(x))) dx\n", " ] K M\n", " / dx /\n", " N [ f(N)\n", " + ----------------------------------------------------- + I f(x) dx + ----\n", " K! ] 2\n", " /\n", " N\n", " f(M)\n", " + ----\n", " 2" ], "text/x-maxima": [ "'sum(f(n),n,N,M) = 'sum(((-1)^(k+1)*bern(k+1)\n", " *('at('diff(f(x),x,k),x = M)\n", " -'at('diff(f(x),x,k),x = N)))\n", " /(k+1)!,k,1,K-1)\n", " +((-1)^(K+1)*'integrate(\n", " periodic_bernpoly(x,K)*'diff(f(x),x,K),x,N,M))\n", " /K!+'integrate(f(x),x,N,M)+f(N)/2+f(M)/2" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ems;" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{4}$}\\left[ M>1 \\right] \\]" ], "text/plain": [ "(%o4) [M > 1]" ], "text/x-maxima": [ "[M > 1]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{5}$}\\sum_{n=1}^{M}{\\frac{1}{n}}=\\int_{1}^{M}{\\frac{d}{d\\,x}\\,\\left(\\frac{1}{x}\\right)\\,\\overline{B}_{1}\\left(x\\right)\\;dx}+\\int_{1}^{M}{\\frac{1}{x}\\;dx}+\\frac{1}{2\\,M}+\\frac{1}{2}\\]" ], "text/plain": [ " M M M\n", " ==== / /\n", " \\ 1 [ d 1 [ 1 1 1\n", "(%o5) > - = I (-- (-)) periodic_bernpoly(x, 1) dx + I - dx + --- + -\n", " / n ] dx x ] x 2 M 2\n", " ==== / /\n", " n = 1 1 1" ], "text/x-maxima": [ "'sum(1/n,n,1,M) = 'integrate('diff(1/x,x,1)*periodic_bernpoly(x,1),x,1,M)\n", " +'integrate(1/x,x,1,M)+1/(2*M)+1/2" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "assume(M>1);\n", "ems,f(x):=1/x,N:1,K:1;" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{6}$}\\sum_{n=1}^{M}{\\frac{1}{n}}=-\\int_{1}^{M}{\\frac{\\overline{B}_{1}\\left(x\\right)}{x^2}\\;dx}+\\log M+\\frac{1}{2\\,M}+\\frac{1}{2}\\]" ], "text/plain": [ " M M\n", " ==== /\n", " \\ 1 [ periodic_bernpoly(x, 1) 1 1\n", "(%o6) > - = (- I ----------------------- dx) + log(M) + --- + -\n", " / n ] 2 2 M 2\n", " ==== / x\n", " n = 1 1" ], "text/x-maxima": [ "'sum(1/n,n,1,M) = (-'integrate(periodic_bernpoly(x,1)/x^2,x,1,M))\n", " +log(M)+1/(2*M)+1/2" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%,nouns;" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{7}$}\\sum_{n=1}^{M}{\\frac{1}{n}}-\\log M=-\\int_{1}^{M}{\\frac{\\overline{B}_{1}\\left(x\\right)}{x^2}\\;dx}+\\frac{1}{2\\,M}+\\frac{1}{2}\\]" ], "text/plain": [ " M M\n", " ==== /\n", " \\ 1 [ periodic_bernpoly(x, 1) 1 1\n", "(%o7) > - - log(M) = (- I ----------------------- dx) + --- + -\n", " / n ] 2 2 M 2\n", " ==== / x\n", " n = 1 1" ], "text/x-maxima": [ "'sum(1/n,n,1,M)-log(M) = (-'integrate(periodic_bernpoly(x,1)/x^2,x,1,M))\n", " +1/(2*M)+1/2" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EuGamma:%-log(M);" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "Gnuplot\n", "Produced by GNUPLOT 5.2 patchlevel 8 \n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\t\n", "\t \n", "\t \n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\t\n", "\n", "\t\n", "\t\tx\n", "\t\n", "\n", "\n", "\n", "\t(-floor(x))+x-1/2\n", "\n", "\t\n", "\t\t(-floor(x))+x-1/2\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t((-floor(x))+x-1/2)/x2\n", "\n", "\t\n", "\t\t((-floor(x))+x-1/2)/x2\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t1/x2\n", "\n", "\t\n", "\t\t1/x2\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\n", "\t\t\n", "\t\t-0.6\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-0.4\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t-0.2\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0.2\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0.4\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0.6\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 0.8\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 1\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 1\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 1.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 2\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 2.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 3\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 3.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 4\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 4.5\n", "\t\n", "\n", "\n", "\t\t\n", "\t\t 5\n", "\t\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "/tmp/maxplot.svg" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot2d([bernpoly(x-floor(x),1),bernpoly(x-floor(x),1)/x^2,1/x^2],[x,1,5])$" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{9}$}-\\sum_{k=1}^{M-1}{\\left(\\log \\left(k+1\\right)-\\log k+\\frac{1}{2\\,k+2}+\\frac{k}{k+1}-\\frac{1}{2\\,k}-1\\right)}\\]" ], "text/plain": [ " M - 1\n", " ====\n", " \\ 1 k 1\n", "(%o9) - > (log(k + 1) - log(k) + ------- + ----- - --- - 1)\n", " / 2 k + 2 k + 1 2 k\n", " ====\n", " k = 1" ], "text/x-maxima": [ "-'sum(log(k+1)-log(k)+1/(2*k+2)+k/(k+1)-1/(2*k)-1,k,1,M-1)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "apply1(first(rhs(EuGamma)), emsRemInt);" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{10}$}0.0772073316515306\\]" ], "text/plain": [ "(%o10) 0.0772073316515306" ], "text/x-maxima": [ "0.0772073316515306" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rem:%,M:100,nouns,numer;" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{11}$}0.5772073316515306\\]" ], "text/plain": [ "(%o11) 0.5772073316515306" ], "text/x-maxima": [ "0.5772073316515306" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "limit(rest(rhs(EuGamma)),M,inf)+rem,numer;" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{12}$}0.5772156649015329\\]" ], "text/plain": [ "(%o12) 0.5772156649015329" ], "text/x-maxima": [ "0.5772156649015329" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%gamma,numer;" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{13}$}\\left[ M>10000 \\right] \\]" ], "text/plain": [ "(%o13) [M > 10000]" ], "text/x-maxima": [ "[M > 10000]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{14}$}\\sum_{n=10000}^{M}{\\frac{1}{n}}=-\\int_{10000}^{M}{\\frac{\\overline{B}_{6}\\left(x\\right)}{x^7}\\;dx}+\\log M+\\frac{1}{2\\,M}+\\frac{\\frac{1}{100000000}-\\frac{1}{M^2}}{12}-\\frac{\\frac{3}{5000000000000000}-\\frac{6}{M^4}}{720}+\\frac{\\frac{3}{25000000000000000000000}-\\frac{120}{M^6}}{30240}-\\log 10000+\\frac{1}{20000}\\]" ], "text/plain": [ " M M\n", " ==== /\n", " \\ 1 [ periodic_bernpoly(x, 6) 1\n", "(%o14) > - = (- I ----------------------- dx) + log(M) + ---\n", " / n ] 7 2 M\n", " ==== / x\n", " n = 10000 10000\n", " 1 1 3 6 3 120\n", " --------- - -- ---------------- - -- ----------------------- - ---\n", " 100000000 2 5000000000000000 4 25000000000000000000000 6\n", " M M M\n", " + -------------- - --------------------- + -----------------------------\n", " 12 720 30240\n", " 1\n", " - log(10000) + -----\n", " 20000" ], "text/x-maxima": [ "'sum(1/n,n,10000,M) = (-'integrate(periodic_bernpoly(x,6)/x^7,x,10000,M))\n", " +log(M)+1/(2*M)+(1/100000000-1/M^2)/12\n", " -(3/5000000000000000-6/M^4)/720\n", " +(3/25000000000000000000000-120/M^6)/30240-log(10000)\n", " +1/20000" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "assume(M-10000>0);\n", "ems,f(x):=1/x,N:10000,K:6,nouns;" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{15}$}\\sum_{n=10000}^{M}{\\frac{1}{n}}-\\log M=-\\int_{10000}^{M}{\\frac{\\overline{B}_{6}\\left(x\\right)}{x^7}\\;dx}+\\frac{1}{2\\,M}+\\frac{\\frac{1}{100000000}-\\frac{1}{M^2}}{12}-\\frac{\\frac{3}{5000000000000000}-\\frac{6}{M^4}}{720}+\\frac{\\frac{3}{25000000000000000000000}-\\frac{120}{M^6}}{30240}-\\log 10000+\\frac{1}{20000}\\]" ], "text/plain": [ " M M\n", " ==== /\n", " \\ 1 [ periodic_bernpoly(x, 6) 1\n", "(%o15) > - - log(M) = (- I ----------------------- dx) + ---\n", " / n ] 7 2 M\n", " ==== / x\n", " n = 10000 10000\n", " 1 1 3 6 3 120\n", " --------- - -- ---------------- - -- ----------------------- - ---\n", " 100000000 2 5000000000000000 4 25000000000000000000000 6\n", " M M M\n", " + -------------- - --------------------- + -----------------------------\n", " 12 720 30240\n", " 1\n", " - log(10000) + -----\n", " 20000" ], "text/x-maxima": [ "'sum(1/n,n,10000,M)-log(M) = (-'integrate(periodic_bernpoly(x,6)/x^7,x,10000,\n", " M))\n", " +1/(2*M)+(1/100000000-1/M^2)/12\n", " -(3/5000000000000000-6/M^4)/720\n", " +(3/25000000000000000000000-120/M^6)/30240\n", " -log(10000)+1/20000" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "EuGamma:%-log(M);" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{16}$}\\left(x-1\\right)\\,x\\,\\left(2\\,x-1\\right)\\,\\left(3\\,x^2-3\\,x-1\\right)\\]" ], "text/plain": [ " 2\n", "(%o16) (x - 1) x (2 x - 1) (3 x - 3 x - 1)" ], "text/x-maxima": [ "(x-1)*x*(2*x-1)*(3*x^2-3*x-1)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "diff(bernpoly(x,6),x),factor;" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{17}$}\\left[ \\frac{1}{42} , -\\frac{31}{1344} , \\frac{1}{42} \\right] \\]" ], "text/plain": [ " 1 31 1\n", "(%o17) [--, - ----, --]\n", " 42 1344 42" ], "text/x-maxima": [ "[1/42,-31/1344,1/42]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[bernpoly(0,6),bernpoly(1/2,6),bernpoly(1,6)];" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{18}$}\\left[ \\frac{1}{252000000000000000000000000} , 3.968253968253969 \\times 10^{-27} \\right] \\]" ], "text/plain": [ " 1\n", "(%o18) [---------------------------, 3.968253968253969e-27]\n", " 252000000000000000000000000" ], "text/x-maxima": [ "[1/252000000000000000000000000,3.968253968253969e-27]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[err:integrate(%[1]/x^7,x,10000,inf),ev(err,numer)];" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{19}$}30\\]" ], "text/plain": [ "(%o19) 30" ], "text/x-maxima": [ "30" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fpprec:30;" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{20}$}5.77215664901532860606512090082_B \\times 10^{-1}\\]" ], "text/plain": [ "(%o20) 5.77215664901532860606512090082b-1" ], "text/x-maxima": [ "5.77215664901532860606512090082b-1" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bfloat(sum(1/n,n,1,9999)+limit(rest(rhs(EuGamma)),M,inf));" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "\\[\\tag{${\\it \\%o}_{21}$}5.77215664901532860606512090082_B \\times 10^{-1}\\]" ], "text/plain": [ "(%o21) 5.77215664901532860606512090082b-1" ], "text/x-maxima": [ "5.77215664901532860606512090082b-1" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bfloat(%gamma);" ] } ], "metadata": { "kernelspec": { "display_name": "Maxima", "language": "maxima", "name": "maxima" }, "language_info": { "codemirror_mode": "maxima", "file_extension": ".mac", "mimetype": "text/x-maxima", "name": "maxima", "pygments_lexer": "maxima", "version": "5.43.2" } }, "nbformat": 4, "nbformat_minor": 4 }