ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 22 May 2023 23:51:56 +0200Plotting error message regarding numerical type of function argumentshttps://ask.sagemath.org/question/68663/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.toniMon, 22 May 2023 23:51:56 +0200https://ask.sagemath.org/question/68663/Linear Programming: float solving and exact verificationhttps://ask.sagemath.org/question/48034/linear-programming-float-solving-and-exact-verification/Hi there,
the glpsol tool (GLPK) provides an option "--xcheck": the solver compute the optimal solution uses floating points, and then checks the correctness using exact arithmetics (i guess implicitly they re-check the basis variables, so this only requires one matrix inversation on exact arithmetics)
1. the MILP interface of sage provides the possibility to set, however, it appears that there is no option to activate "xcheck"?
[not allowed to post links but here are the references for the sage documentation] doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html#sage.numerical.mip.MixedIntegerLinearProgram.solver_parameter
doc.sagemath.org/html/en/reference/numerical/sage/numerical/backends/glpk_backend.html#sage.numerical.backends.glpk_backend.GLPKBackend.solver_parameter
2. I know that it is easy to extract the basis variables and to recheck the correctness of a floating-point-solution just within sage, however, I really think **this should be added as a basic functionality** for the SAGE MILP interface to ANY solver, not only GLPK (so this verification-code should also verify solutions of cplex,gurobi,etc.) .
So, does anyone have already an implementation for such a verification?
Best,
ManfreddeadalpsSun, 22 Sep 2019 23:33:46 +0200https://ask.sagemath.org/question/48034/