Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Coercion problem while defining piecewise function

In a nutshell: I begin by defining the following function:

def g(x):
return math.exp(-1/(1 - x^2))

which poses no problem. Then, I try to use this function g to define a new function, as follows:

f = Piecewise([ [(-.5,.5), 0.44399*g(x)] ])

which returns the following error:


TypeError Traceback (most recent call last)

/Applications/sage/<ipython console=""> in <module>()

/Applications/sage/<ipython console=""> in g(x)

/Applications/sage/local/lib/python2.6/site-packages/sage/rings/fraction_field_element.so in sage.rings.fraction_field_element.FractionFieldElement.__float__ (sage/rings/fraction_field_element.c:8540)()

/Applications/sage/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.__float__ (sage/rings/polynomial/polynomial_element.c:8243)()

TypeError: cannot coerce nonconstant polynomial to float


I am not sure of what is going wrong here. Any ideas/solutions would be deeply appreciated.

-jl

Coercion problem while defining piecewise function

In a nutshell: I begin by defining the following function:

def g(x):
return math.exp(-1/(1 - x^2))

which poses no problem. Then, I try to use this function g to define a new function, as follows:

f = Piecewise([ [(-.5,.5), 0.44399*g(x)] ])

which returns the following error:


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

last) /Applications/sage/<ipython console> in <module>()

/Applications/sage/<ipython console=""> console> in <module>()

g(x)

/Applications/sage/<ipython console=""> in g(x)

/Applications/sage/local/lib/python2.6/site-packages/sage/rings/fraction_field_element.so in sage.rings.fraction_field_element.FractionFieldElement.__float__ (sage/rings/fraction_field_element.c:8540)()

(sage/rings/fraction_field_element.c:8540)()

/Applications/sage/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.__float__ (sage/rings/polynomial/polynomial_element.c:8243)()

(sage/rings/polynomial/polynomial_element.c:8243)()

TypeError: cannot coerce nonconstant polynomial to float

float
-----------

I am not sure of what is going wrong here. Any ideas/solutions would be deeply appreciated.

-jl