Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Plotting error message regarding numerical type of function arguments

I am trying to plot the following function:

x = var('x')
def y(x): return RR(len(prime_range(floor(0.95 * x), floor(1.25 * x))) / round(1.25 * x - 0.95 * x))

I am not sure whether it is well-constructed mathematically, but it's trying to check the density of prime numbers around a given value x I am using the floor() function because I'm not sure that prime_range() accepts non-integers.

If I test the function with random real values of x I get a plausible output without errors.

However, when I try to plot the function as in:

plot(y(x), (x, 5, 20))

I get the following error message:

TypeError: unable to convert floor(0.950000000000000*x) to an integer
and argument is also not real: unable to simplify to float approximation

I don't understand why this input cannot be understood as real by sagemath, or why the floor is not an integer.