Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctest fix for: very slow taylor expansion for composite functions #14878

Closed
fchapoton opened this issue Jul 11, 2013 · 31 comments
Closed

Doctest fix for: very slow taylor expansion for composite functions #14878

fchapoton opened this issue Jul 11, 2013 · 31 comments

Comments

@fchapoton
Copy link
Contributor

Pynac-0.7.0 uses Flint to get univariate series expansions. For comparison,

                                             now     previously
sin(x*sin(x*sin(x*sin(x)))).series(x,8)     50-55µs    13.7s
sin(x*sin(x*sin(x*sin(x)))).series(x,12)      69µs      >1min
sin(x*exp(x)).series(x,100)                  3.7ms     11.3s
sin(x*exp(x)).series(x,500)                  215ms       n/a
(sin(x+x^2)*cos(x+x^2)).series(x,1000)       2.86s       n/a

Extensive tests are added with #21730 under tests/. Pre-Pynac 0.7.0 the tests need 11s vs 0.2s with pynac-0.7.0.

Previous ticket description:

The following

f=sin(x*sin(x*sin(x*sin(x))))
f.series(x,8)

takes something like 30s, which seems a bit too much. Maybe there is some bottleneck somewhere ?
On the other hand,

f.taylor(x,0,8)

is faster, but not lightning fast.

In the same spirit, one could try

sage: x=PowerSeriesRing(QQ,'x').gen()
sage: sin(x)
Traceback (most recent call last):
...
TypeError: cannot coerce arguments: no canonical coercion from Power Series Ring in x over Rational Field to Symbolic Ring

It would be good if one could apply symbolic functions to power series and get power series when possible.

Depends on #21827

Component: symbolics

Keywords: taylor expansion, symbolic function

Author: Ralf Stephan

Branch/Commit: ebaf2c4

Reviewer: Frédéric Chapoton

Issue created by migration from https://trac.sagemath.org/ticket/14878

@fchapoton fchapoton added this to the sage-6.1 milestone Jul 11, 2013
@fchapoton fchapoton changed the title very slow taylor epansion for composite functions very slow taylor expansion for composite functions Jul 11, 2013
@fredrik-johansson
Copy link

comment:2

Being able to apply functions to power series would be useful.

For anyone looking to implement this, note that flint can now natively evaluate elementary functions over Q[[x]] and (Z/nZ)[[x]] (using fmpq_poly_sin_series in this case).

@fchapoton
Copy link
Contributor Author

comment:3

some timings:

sage: %timeit f.taylor(x,0,8)
100 loops, best of 3: 6.46 ms per loop
sage: %timeit f.series(x,8)
1 loops, best of 3: 42.1 s per loop

@fchapoton

This comment has been minimized.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@mezzarobba
Copy link
Member

Replying to @fchapoton:

Maybe there is some bottleneck somewhere ?

GiNaC's series expansion code seems to be designed for very small orders only. It is incredibly inefficient otherwise:

ginsh - GiNaC Interactive Shell (ginac V1.6.2)
  __,  _______  Copyright (C) 1999-2011 Johannes Gutenberg University Mainz,
 (__) *       | Germany.  This is free software with ABSOLUTELY NO WARRANTY.
  ._) i N a C | You are welcome to redistribute it under certain conditions.
<-------------' For details type `warranty;'.

Type ?? for a list of help topics.
> time(series(sin(x*sin(x*sin(x*sin(x)))), x==0, 8));
2.352s                                                                          
> time(series(sin(x*sin(x*sin(x*sin(x)))), x==0, 12));                         
40.104s                                                                         

Judging by the number of calls to gcd/lcm reported by %prun f.series(x==0, k) for successive k, the number of operations in ℚ seems to grow at least exponentially with k, and perhaps like k! (while it should be something like O(k³) in a naive implementation, and essentially linear in a careful one).

I think that's the heart of the problem, and the difference between the timings with sage and with ginsh is pynac overhead (which should of course be minimized, but only costs a constant factor).

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@fchapoton fchapoton modified the milestones: sage-6.4, sage-6.7 Apr 17, 2015
@fchapoton
Copy link
Contributor Author

Branch: u/chapoton/14878

@fchapoton
Copy link
Contributor Author

Commit: 20163eb

@fchapoton
Copy link
Contributor Author

New commits:

20163ebtrac #14878 sin for power series, step1

@fchapoton fchapoton modified the milestones: sage-6.7, sage-6.10 Oct 8, 2015
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 9, 2015

Changed commit from 20163eb to ed55e28

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 9, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

ed55e28trac #14878 step 2, cos for multi-variable power series

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 27, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

0a0921cMerge branch 'u/chapoton/14878' into 7.1.b0
2e093f6trac #14878 now sin and cos for all power series

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 27, 2016

Changed commit from ed55e28 to 2e093f6

@fchapoton
Copy link
Contributor Author

Changed commit from 2e093f6 to none

@fchapoton
Copy link
Contributor Author

Changed branch from u/chapoton/14878 to none

@fchapoton
Copy link
Contributor Author

comment:12

branch transfered to #20017

@rwst
Copy link

rwst commented Feb 15, 2016

comment:13

The relevant Pynac ticket is pynac/pynac#116

@rwst
Copy link

rwst commented Feb 15, 2016

Upstream: Reported upstream. Developers acknowledge bug.

@rwst
Copy link

rwst commented Oct 15, 2016

Changed upstream from Reported upstream. Developers acknowledge bug. to Fixed upstream, in a later stable release.

@rwst
Copy link

rwst commented Oct 15, 2016

Dependencies: pynac-0.7.0

@rwst

This comment has been minimized.

@rwst rwst modified the milestones: sage-6.10, sage-7.5 Oct 15, 2016
@rwst

This comment has been minimized.

@rwst

This comment has been minimized.

@rwst
Copy link

rwst commented Oct 20, 2016

@rwst
Copy link

rwst commented Oct 20, 2016

New commits:

ebaf2c4add doctests

@rwst
Copy link

rwst commented Oct 20, 2016

Commit: ebaf2c4

@rwst rwst changed the title very slow taylor expansion for composite functions Doctest fix for: very slow taylor expansion for composite functions Oct 20, 2016
@rwst
Copy link

rwst commented Nov 10, 2016

Changed dependencies from pynac-0.7.0 to #21827

@fchapoton
Copy link
Contributor Author

Reviewer: Frédéric Chapoton

@fchapoton
Copy link
Contributor Author

comment:20

ok, looks good to me. Thanks for your work. Please add your name as author.

@rwst
Copy link

rwst commented Nov 12, 2016

Author: Ralf Stephan

@rwst
Copy link

rwst commented Nov 12, 2016

Changed upstream from Fixed upstream, in a later stable release. to none

@rwst
Copy link

rwst commented Nov 12, 2016

comment:21

Thanks too.

@vbraun
Copy link
Member

vbraun commented Nov 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants