Identification polynomial

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

I have a function with one parameter. How can I check whether this parameter is a polynomial? (Univariate or multvariate, does'nt count which is the base ring) I want use this information in a multilevel if construction

asked Nov 14 '10

czsan gravatar image czsan
133 1 5 16
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

Will something like this work?

sage: is_polynomial = lambda s: all(s.is_polynomial(v) for v in s.variables())
sage: var("x y z")
(x, y, z)
sage: is_polynomial(x)
True
sage: is_polynomial(3+x+x**7)
True
sage: is_polynomial(3+x*exp(x))
False
sage: is_polynomial(3*x*y)
True
sage: is_polynomial(3*x*y+sin(y))
False
 
link

posted Nov 14 '10

DSM gravatar image DSM flag of Canada
4802 12 61 103
Thank you, but it is a partial solution, becaus I do'nt know, the parameter has varibales() property or not. For example : a=2 is_polynomial(a) generates an AttributeError. I believed, the .parent() will help me, but there are rings without this property. czsan (Nov 15 '10)
Ah, so you don't even know that it's an Expression, then. Maybe casting it would suffice: is_polynomial = lambda s: all(SR(s).is_polynomial(v) for v in SR(s).variables()) but I'm not clear on your use cases (and how much information you want to preserve). DSM (Nov 15 '10)
Yes, I don't know, the parameter is a number or a polynom. After some preparation the algoritm is same (for example, gcd, cra). but the preparation and some little aid-functions depend on the parent ring. czsan (Nov 15 '10)
So does casting your parameter explicitly into an Expression by wrapping it in SR suffice for your case, or do we need to work harder? DSM (Nov 15 '10)
I think it's hard. What do you mean on 'SR suffice'? czsan (Nov 18 '10)
see 1 more comment

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Nov 14 '10

Seen: 89 times

Last updated: Nov 14 '10

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.