Ask Your Question
1

A simple hypergeometric function fails.

asked 2014-10-29 16:43:29 +0100

Peter Luschny gravatar image

updated 2023-01-09 23:59:42 +0100

tmonteil gravatar image

There is a nice method to compute the Narayana polynomials. With Maple we can write

P := n -> simplify(hypergeom([-n,-n+1], [2], 1/x));
seq(expand(x^k*P(k)), k=0..5);

and get the answer

1,  x,  x^2+x,  x^3+3*x^2+x,  x^4+6*x^3+6*x^2+x,  x^5+10*x^4+20*x^3+10*x^2+x.

Trying the same with Sage

P = lambda n: simplify(hypergeometric([-n,-n+1],[2], 1/x))
[expand(x^k*P(k)) for k in (0..5)]

gives the answer

[1, x, ..., x^n*hypergeometric((-n, -n-1),(2),1/x)]

This is really disappointing. Is there a workaround?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2014-10-29 17:12:55 +0100

kcrisman gravatar image

Sage's simplify() command is very basic; it just sends to Maxima and back, which does simplify a few things. More generally, Sage has a lot of specific simplification routines from Maxima that you can use. In this case, we have success!

sage: P = lambda n: hypergeometric([-n,-n+1],[2], 1/x).simplify_hypergeometric()
sage: [expand(x^k*P(k)) for k in (0..5)]
[1,
 x,
 x^2 + x,
 x^3 + 3*x^2 + x,
 x^4 + 6*x^3 + 6*x^2 + x,
 x^5 + 10*x^4 + 20*x^3 + 10*x^2 + x]
edit flag offensive delete link more

Comments

This is definitely not the way I expect the nomenclature to work in a object-oriented setup. Regardless of the object the function name should be object.simplify(). Depending on the type of the object simplify() chooses _internally_ the appropriate routine, which in this case is simplify_hypergeometric(), a function the user needs not to be aware of.

Peter Luschny gravatar imagePeter Luschny ( 2014-10-30 11:24:18 +0100 )edit
1

Like most things based on Python, Sage is not "purely" object-oriented, or we wouldn't have functions. In any case, if you look at the documentation, the point is that there are many kinds of simplification, and we don't want to force the user to use ALL of them every time they want to simplify. The routine you would like is `simplify_full()` - except currently it doesn't have the `simplify_hypergeometric` inside of it, possibly for good reasons. In any case, "deciding" which routine should be chosen for a given symbolic expression consisting possibly of dozens of different kinds of functions is arbitrarily difficult in a computation sense. Even deciding whether a given expression is equal to zero is computationally infeasible, or so I'm told - I've never seen a specific reference :)

kcrisman gravatar imagekcrisman ( 2014-10-30 13:13:12 +0100 )edit
1

https://en.wikipedia.org/wiki/Constant_problem ?

Peter Luschny gravatar imagePeter Luschny ( 2014-10-30 13:53:46 +0100 )edit
kcrisman gravatar imagekcrisman ( 2014-10-30 16:12:44 +0100 )edit
3

answered 2014-10-29 17:09:40 +0100

tmonteil gravatar image

You can try with sympy :

sage: import sympy
sage: P = lambda n: sympy.hyper([-n,-n+1],[2], 1/x).simplify()
sage: [expand(x^k*P(k)) for k in (0..5)]
[1,
 x,
 x^2 + x,
 x^3 + 3*x^2 + x,
 x^4 + 6*x^3 + 6*x^2 + x,
 x^5 + 10*x^4 + 20*x^3 + 10*x^2 + x]
edit flag offensive delete link more

Comments

We *really* need to start incorporating more Sympy routines as possible algorithms for Sage things. It has improved so much in the past five years, and I barely know how to use it nowadays... but it would be a lot of work to do :(

kcrisman gravatar imagekcrisman ( 2014-10-29 17:13:52 +0100 )edit

That may be but, as my answer shows, for this problem Sage has all that's needed.

rws gravatar imagerws ( 2014-10-29 17:19:04 +0100 )edit
2

answered 2014-10-29 17:17:15 +0100

rws gravatar image

updated 2014-10-31 11:50:01 +0100

As I have said in your other hypergeometric question, there is no need for sympy nor Maxima:

sage: from sage.functions.hypergeometric import closed_form
sage: P = lambda n: simplify(closed_form(hypergeometric([-n,-n+1],[2], 1/x)))
sage: [expand(x^k*P(k)) for k in (0..5)]
[1,
 x,
 x^2 + x,
 x^3 + 3*x^2 + x,
 x^4 + 6*x^3 + 6*x^2 + x,
 x^5 + 10*x^4 + 20*x^3 + 10*x^2 + x]

Fixed in http://trac.sagemath.org/ticket/17066 which needs review.

edit flag offensive delete link more

Comments

Wow, I really did not realize how much stuff was in that ticket, this is awesome. Followup, then: how could a normal user find this using only tab-completion of globals (where I don't count sage.[tab] for obvious reasons)? Without that availability it's not as helpful. (Also, does `expand` use Maxima or only Pynac?)

kcrisman gravatar imagekcrisman ( 2014-10-29 18:55:21 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-10-29 16:43:29 +0100

Seen: 1,013 times

Last updated: Oct 31 '14