is handling of Inf/Infinity/infinity affected by the 1st call to symbolics?

78 views
Skip to first unread message

Dima Pasechnik

unread,
Jan 16, 2017, 12:41:57 PM1/16/17
to sage-devel
Here is an ugly bug I just ran in at https://trac.sagemath.org/ticket/18920#comment:98

it looks as if setting a symbolic taylor expansion like

sage: g(x)=taylor(log(x),x,1,6); g # log can be replaced by sin with the same end result

---a call that takes a lot of time, probably because some big stuff is initialised behind the scenes---
breaks handling of infinities (by updated Maxima, I guess): namely, I get a SIGFPE on

sage: plot(log(x),(x,0,2))

Does this look possible, and where would one look for the cause of this?
 



Ralf Stephan

unread,
Jan 17, 2017, 1:50:25 AM1/17/17
to sage-devel
As you already noticed that the bug depends on the ECL/Maxima
version, let me just add that there is no need for taylor() (Maxima)
if you use series() (Pynac) which is way faster. Also there is


Regards,

Dima Pasechnik

unread,
Jan 17, 2017, 4:46:50 AM1/17/17
to sage-devel
well, taylor() was there as it came from the doctest showing the problem with ECL 16.1.3.
Anything that triggers loading ECL/Maxima library interface readies  the bug to go off, anyway.

Then something like 

     plot(log(x),(x,0.0,2.0))

does trigger the crash itself. And it appears that the latter does not use ECL/Maxima, right?
(invoking this plot() before calling taylor() does not lead to a problem).

Dima Pasechnik

unread,
Jan 17, 2017, 5:45:56 AM1/17/17
to sage-devel
It was triggered by old non-conforming feature of ECL 16.1.2; ECL 16.1.3 is more standard-conforming,
and so for our purposes we need to explicitly disable SIGFPE traps. Took a while to understand, sorry for noise.

Peter Luschny

unread,
Jan 18, 2017, 9:22:20 AM1/18/17
to sage-devel
Hi Ralf!

R> there is no need for taylor() (Maxima)
R> if you use series() (Pynac) which is way faster.

I cannot reproduce your claim, in the contrary.
Please consider this simple example:

def num(m, n, ser):
    z = var('z')
    w = exp(2 * pi * I / m)
    o = sum(exp(z * w^k) for k in range(m)) / m
    f = 1 / o
    if ser:
        t = f.series(z, n + 1)
    else:
        t = taylor(f, z, 0, n + 1)
    return factorial(n) * t.coefficient(z, n) 

ser = lambda m,n: sum(binomial(m*n,m*k)*num(m,m*k,true )*k/n for k in (1..n))
tay = lambda m,n: sum(binomial(m*n,m*k)*num(m,m*k,false)*k/n for k in (1..n))

---

import time
print time.clock()
print [[tay(m,n) for n in (1..6)] for m in (1..5)]
print time.clock()
print [[ser(m,n) for n in (1..6)] for m in (1..5)]
print time.clock()

In fact if I would not have killed the program I think 
the series version would still run. 
If I have misunderstood, please do enlighten me. 

Peter

Ralf Stephan

unread,
Jan 18, 2017, 10:45:27 AM1/18/17
to sage-devel
On Wednesday, January 18, 2017 at 3:22:20 PM UTC+1, Peter Luschny wrote:
I cannot reproduce your claim, in the contrary.

You are quite right. Your example is not accelerated by the recent
improvements. So I should have said way faster in many cases.

Regards,

Ralf Stephan

unread,
Jan 18, 2017, 10:55:03 AM1/18/17
to sage-devel
Actually the example makes it necessary to completely abandon
the original GiNaC series code and use Maxima as fallback in the
cases that cannot be handled by the fast rational Pynac series code.

Thanks!

Ralf Stephan

unread,
Jan 18, 2017, 11:23:20 AM1/18/17
to sage-devel

Peter Luschny

unread,
Jan 18, 2017, 1:36:48 PM1/18/17
to sage-...@googlegroups.com
R> Actually the example makes it necessary to completely abandon
R> the original GiNaC series code and use Maxima as fallback in the
R> cases that cannot be handled by the fast rational Pynac series code.

Unfortunately this will not help much. Maxima/taylor is also
unable to compute these functions even for modest values of m
efficiently as you can see from the next example:

def P(m, n):
    x, z = var('x, z')
    if m == 1: return Integer(1) 
    w = exp(2 * pi * I / m)
    o = sum(exp(z * w^k) for k in range(m)) / m
    f = exp(z*x) * (exp(z) / o - 1)
    t = f.taylor(z, 0, n+1)
    return factorial(n) * t.coefficient(z, n) 

for m in [1,2,3,4,5,6,7,11,13]:
    print [m], [P(m, n).subs(x=0) for n in (0..10)]

AFAIK there is only one CAS which can handle these things 
(which are basic!) efficiently: Mathematica. So if I would
put something on trac it would be an enhancement request:
"Implement the Mittag-Leffler function!".

Peter

Peter Luschny

unread,
Jan 18, 2017, 1:37:37 PM1/18/17
to sage-...@googlegroups.com
Thanks!

P.S. Do you know that there are functions which work correctly
but advertise to use instead functions which are buggy?
Hint: 22069

Reply all
Reply to author
Forward
0 new messages