doubledouble icon indicating copy to clipboard operation
doubledouble copied to clipboard

exp(x)

Open clairvoyante opened this issue 3 years ago • 0 comments

exp(x) use Padé approximant. Same order Padé approximant of exp(x)-1 is:

(312x^11+1201200x^9+1176215040x^7+402265543680x^5+46930980096000x^3+1295295050649600x)/(x^12-156x^11+12012x^10-600600x^9+21621600x^8-588107520x^7+12350257920x^6-201132771840x^5+2514159648000x^4-23465490048000x^3+154872234316800x^2-647647525324800*x+1295295050649600) (cf. https://sagecell.sagemath.org/?z=eJwrSExJ1ShJrMzJL9JIrSjQqNDUNdSp0DHQMTLR1DE0AiJNawDbhwo3&lang=maxima&interacts=eJyLjgUAARUAuQ== )

So...

def exp(self):
    n = int(round(self.x))
    x = self - n
    x2 = x*x
    u = (((((312*x2 + 1201200)*x2 +
        1176215040)*x2 + 402265543680)*x2 +
        46930980096000)*x2 + 1295295050649600)*x
    v = (((((((((((x -
        156)*x + 12012)*x -
        600600)*x + 21621600)*x -
        588107520)*x + 12350257920)*x -
        201132771840)*x + 2514159648000)*x -
        23465490048000)*x + 154872234316800)*x -
        647647525324800)*x + 1295295050649600
    return e.power(n)*(u/v+1)

is little bit faster.

clairvoyante avatar Jan 19 '22 10:01 clairvoyante