# unable to convert floor(x) to an integer

Let's say, I want to define the following function:

sage: f(x)=mod(floor(x),5)


Then I get this error:

TypeError: unable to convert floor(x) to an integer


How can I solve this problem?

edit retag close merge delete

Sort by » oldest newest most voted

By using f(x)= syntax, your are defining a Symbolic function of the symbolic variable x. Then floor(x) is a symbolic expression. And mod just don't eat a symbolic expression as first argument.

sage: a = floor(x)
sage: type(a)
<type 'sage.symbolic.expression.Expression'>
sage: mod(a, 5)   # raises type error


Use Python way of defining a function:

sage: def f(x): return mod(floor(x), 5)
sage: f(17.3)
2


See also this post or the section Some Common Issues with Functions in the Sage Guided tour.

more

Thanks! How can I then get an output of the function instruction like in this example:

sage: g(x,y)=x-y
sage: g
(x, y) |--> x - y

( 2017-06-18 00:41:05 +0200 )edit

For a Python function, unfortunately, you can not.

( 2017-06-18 02:42:23 +0200 )edit