Ask Your Question
0

unable to convert floor(x) to an integer

asked 2017-06-18 00:19:18 +0100

Thrash gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-06-18 00:31:23 +0100

Sébastien gravatar image

updated 2017-06-18 00:34:23 +0100

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.

edit flag offensive delete link more

Comments

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
Thrash gravatar imageThrash ( 2017-06-18 00:41:05 +0100 )edit

For a Python function, unfortunately, you can not.

Sébastien gravatar imageSébastien ( 2017-06-18 02:42:23 +0100 )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

1 follower

Stats

Asked: 2017-06-18 00:19:18 +0100

Seen: 1,449 times

Last updated: Jun 18 '17