Strange behaviour of `region_plot`
Basically, the region_plot
primitive behaves strangely if the expression has half-integer exponents. More specifically, here is the setup I'm using:
u = var("u")
v = var("v")
unit_disc = u**2 + v**2 <= 1
uv_range = ((u, -1, 1), (v, -1, 1))
I am first defining a two-variables functions as follows, and trying to plot the associated implicit curve:
f = u + sqrt((1 - u**2 - v**2)**3)
show(f)
region_plot([f == 0, unit_disc], *uv_range)
This works nicely to draw the zero level of the function. (Note: I am using the region_plot
primitive instead of the more suited implicit_plot
one, because I want to restrict the plot to the unit disc.)
However, if I use a half-integer exponent, the primitive will throw the exception ValueError: negative number to a fractional power not real
:
g = u + (1 - u**2 - v**2)**(3/2)
show(g)
region_plot([g == 0, unit_disc], *uv_range)
Did I discover a new bug?
The issue is that the way I define my function makes it so that I end up having those half-integer exponents lying everywhere, despite using only polynomials and substituing with square root terms. Sage automatically 'reduces' everything to half-integer exponents, and there is no way for me to revert this change.
How can I prevent this behaviour?
(P.S.: I wanted to include images and all, but even if I host them outside of this platform, it won't let me because karma... Why? This is not StackOverflow...)
This works on my machine and it also works on sagecell.sagemath.org. What version of Sage are you using, and what platform?
You could also use the method "add_condition" to add the restriction to the unit disc on the full plot (this is for 3d plots).
I am currently running sagemath 9.5 on Ubuntu. What version do you use?
On the unit disc
g
can be replaced byg = u + abs (1 - u**2 - v**2)**(3/2)
and this version should work on older versions of sageI'm using the latest beta release. sagecell.sagemath.org is using version 10.1. Note that 9.5 was released in January 2022, so it's a bit old by now.