Ask Your Question

Identification polynomial

asked 2010-11-14 04:04:49 +0200

czsan gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2010-11-14 06:44:12 +0200

DSM gravatar image

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)
sage: is_polynomial(3+x+x**7)
sage: is_polynomial(3+x*exp(x))
sage: is_polynomial(3*x*y)
sage: is_polynomial(3*x*y+sin(y))
edit flag offensive delete link more


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 gravatar imageczsan ( 2010-11-15 11:07:53 +0200 )edit

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 gravatar imageDSM ( 2010-11-15 12:29:32 +0200 )edit

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 gravatar imageczsan ( 2010-11-15 13:28:06 +0200 )edit

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 gravatar imageDSM ( 2010-11-15 18:52:19 +0200 )edit

I think it's hard. What do you mean on 'SR suffice'?

czsan gravatar imageczsan ( 2010-11-18 15:08:04 +0200 )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


Asked: 2010-11-14 04:04:49 +0200

Seen: 505 times

Last updated: Nov 14 '10