Ask Your Question
0

unable to convert floor(x) to an integer

asked 2017-06-17 17:19:18 -0500

Tommy Angelo 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-17 17:31:23 -0500

Sébastien gravatar image

updated 2017-06-17 17:34:23 -0500

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
Tommy Angelo gravatar imageTommy Angelo ( 2017-06-17 17:41:05 -0500 )edit

For a Python function, unfortunately, you can not.

Sébastien gravatar imageSébastien ( 2017-06-17 19:42:23 -0500 )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-17 17:19:18 -0500

Seen: 71 times

Last updated: Jun 17