Karim Belabas on Sun, 12 Apr 2015 10:13:08 +0200

 Re: cos: precision too low in mpsc1

```* Chris De Corte [2015-04-12 04:51]:
> Now he gives me a solution as a Taylor series which I can not use.

[ Please copy-paste explicit reproducible examples, it is hard to guess
what other people input. ]

Something like this ?

(10:00) gp > cos(x)
%1 = 1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 + 1/40320*x^8 - 1/3628800*x^10 + 1/479001600*x^12 - 1/87178291200*x^14 + 1/20922789888000*x^16 + O(x^18)

This is probably an error in your script where you take the value of 'cos'
at an "undefined variable", i.e. a formal variable, and get a t_SER.

Just make sure to assign a numeric value (e.g., x = Pi) first.

> Maybe the cos function should first do something like Mod(x,2*Pi) to bring
> the big number back to a smaller one

Actually, x % (2*Pi). [ Mod() is a constructor for modular types and
quotient rings, it does not apply to t_REALs; % on the other hand is a
generalized Euclidean remainder, which still makes sense ]

(10:02) gp > 10.0 % (2*Pi)
%2 = 3.7168146928204135230747132334409942316

(10:02) gp > Mod(10.0, 2*Pi)
***   at top-level: Mod(10.0,2*Pi)
***                 ^--------------
*** Mod: forbidden division t_REAL % t_REAL.

In fact, cos does something like this (modulo Pi/2).

But this won't help with your precision issues:

(10:02) gp > 1e100 % (2*Pi)
***   at top-level: 1e100%(2*Pi)
***                      ^-------
*** _%_: precision too low in truncr (precision loss in truncation).

Same reason as before: we fail to compute the Euclidean quotient

floor(1e100 / (2*Pi))

because the t_REAL may represent any real number in a huge interval (containing
more than one integer in this case). Solution: increase the accuracy (\p200)
or use exact rational numbers !

Cheers,

K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`

```