0

Suppose we would like to compute $\sin{1}$ with an error of less than $10^{-17}$ specifically using a Taylor polynomial at $\pi/2$ (instead of the easier route of doing the computation at $0$).

If we write

$$f(x)=\sin{x}=P_{n,a}(x)+R_{n,a}(x)$$

where $P_{n,a}(x)$ is the Taylor polynomial of degree $n$ for $f$ at $a$, and $R_{n,a}(x)$ is the remainder term, then by Taylor's Theorem we have

$$\sin{x}=\sum\limits_{i=0}^{2n+1} \left [\sin^{(i)}{(a)}\frac{(x-a)^{2n+1}}{(2n+1)!}\right ]+\frac{\sin^{(2n+2)}{(t)}}{(2n+2)!}(x-a)^{2n+2}, t\in (0,x)$$

$$R_{2n+1,a}(x)=\frac{\sin^{(2n+2)}{(t)}}{(2n+2)!}(x-a)^{2n+2}, t\in (0,x)$$

Then

$$R_{2n+1,\pi/2}(1)=\frac{\sin^{(2n+2)}{(t)}}{(2n+2)!}\left (1-\frac{\pi}{2}\right )^{2n+2}, t\in (0,1)$$

$$\leq \frac{1}{(2n+2)!}\left (1-\frac{\pi}{2}\right )^{2n+2}$$

$$<10^{-17}$$

$$\implies (2n+1)!>10^{17}\cdot \left (1-\frac{\pi}{2}\right )^{2n+1}\tag{1}$$

$$\implies (2n+1)!-10^{17}\cdot \left (1-\frac{\pi}{2}\right )^{2n+1}>0\tag{2}$$

Let's say we now want to use Maple to figure out which $n$ makes $(2)$ true. Why doesn't the following work?

f := n -> 10^(17)*[1 - 1/2*Pi]^(2*n + 2)

g := n -> (2*n + 2)!

h := n -> g(n) - f(n)

is(h(1)>0) // FAIL

Note that individually computing values of $f$, $g$, and $h$ works fine. In particular, h(1) produces a result. Why doesn't the function is work?

xoux
  • 4,913

2 Answers2

2

Your wrote,

10^(17)*[1 - 1/2*Pi]^(2*n + 2)

which is incorrect syntax for what you're trying to accomplish. In Maple group of terms is accomplished by using round-brackets, eg,

10^(17)*(1 - 1/2*Pi)^(2*n + 2)

Square-brackets form a list, not a scalar expression.

Maple allows you to concoct that weird kind of expression on the grounds that you might have some special use for it. But Maple doesn't necessarily see it and manipulate it like the scalar expression you presumably intended.

In other words, you've made a syntax mistake.

acer
  • 5,293
1

Just for your curiosity.

There is an analytical solution to this problem.

Writing $$\sin(x)=\sum_{n=0}^\infty \frac{(-1)^n}{(2 n)!}\left(x-\frac{\pi }{2}\right)^{2 n}=\sum_{n=0}^p \frac{(-1)^n}{(2 n)!}\left(x-\frac{\pi }{2}\right)^{2 n}+\sum_{n=p+1}^\infty \frac{(-1)^n}{(2 n)!}\left(x-\frac{\pi }{2}\right)^{2 n}$$ You are looking for $p$ such that

$$R_p=\frac 1 {(2p+2)!} \left(\frac{\pi }{2}-1\right)^{2 p+2} \leq 10^{-k}$$ that is to say $$(2p+2)! \geq \left(\frac{\pi }{2}-1\right)^{2 p+2}\, 10^k$$

f you look at this question of mine, you will see a superb approximation proposed by @robjohn. Adapted to your problem, it gives (as a real)

$$p \sim \frac{\pi -2}{4} \, e^{1+W(t)}-\frac 54 \qquad \text{where} \qquad t=\frac{k \log (100)-\log ((\pi -2) \pi )}{e (\pi -2)}$$ $W(t)$ being Lambert function (present in Maple).

Trying for $k=100$, this gives as a real $p=29.853719$ while the exact solution is $p=29.853790$. So $\lceil p \rceil=30$.

Checking $$R_{29}=2.94236\times 10^{-97} \qquad \text{while} \qquad R_{30}=2.53476\times 10^{-101}$$