First time here? Check out the FAQ!

Ask Your Question
1

A simple hypergeometric function fails.

asked 10 years ago

Peter Luschny gravatar image

updated 2 years ago

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?

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
2

answered 10 years ago

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]
Preview: (hide)
link

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 ( 10 years ago )
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 ( 10 years ago )
1

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

Peter Luschny gravatar imagePeter Luschny ( 10 years ago )
3

answered 10 years ago

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]
Preview: (hide)
link

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 ( 10 years ago )

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

rws gravatar imagerws ( 10 years ago )
2

answered 10 years ago

rws gravatar image

updated 10 years ago

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.

Preview: (hide)
link

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 ( 10 years ago )

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: 10 years ago

Seen: 1,120 times

Last updated: Oct 31 '14