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.Sun, 31 Mar 2013 11:50:46 +0200region_plot with "or" expressionshttps://ask.sagemath.org/question/9956/region_plot-with-or-expressions/I'm trying to do a region_plot of a bunch of things that involve an "or" and getting behavior I don't understand.
Here's an example (not so relevant to mine) of the kind of thing I'm encountering:
region_plot([x < y or x < -y], (x,-1,1), (y, -1,1))
If you run this, clearly the output is messed up. It also changes when you switch the order of the two conditions, so it seems to pay attention to just one of them.
I tried carious things like making a function of (x,y) that returns the relevant boolean that works correctly when you just feed it numbers, but exhibits the same odd behavior when you put it in region_plot.
Any idea what's going on here?
Thanks.Fri, 29 Mar 2013 22:59:49 +0100https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/Comment by kcrisman for <p>I'm trying to do a region_plot of a bunch of things that involve an "or" and getting behavior I don't understand.</p>
<p>Here's an example (not so relevant to mine) of the kind of thing I'm encountering:</p>
<p>region_plot([x < y or x < -y], (x,-1,1), (y, -1,1))</p>
<p>If you run this, clearly the output is messed up. It also changes when you switch the order of the two conditions, so it seems to pay attention to just one of them.</p>
<p>I tried carious things like making a function of (x,y) that returns the relevant boolean that works correctly when you just feed it numbers, but exhibits the same odd behavior when you put it in region_plot.</p>
<p>Any idea what's going on here?</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17983#post-id-17983Sorry, I couldn't get the less than signs to work out right in the comment...Sun, 31 Mar 2013 00:02:09 +0100https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17983#post-id-17983Comment by kcrisman for <p>I'm trying to do a region_plot of a bunch of things that involve an "or" and getting behavior I don't understand.</p>
<p>Here's an example (not so relevant to mine) of the kind of thing I'm encountering:</p>
<p>region_plot([x < y or x < -y], (x,-1,1), (y, -1,1))</p>
<p>If you run this, clearly the output is messed up. It also changes when you switch the order of the two conditions, so it seems to pay attention to just one of them.</p>
<p>I tried carious things like making a function of (x,y) that returns the relevant boolean that works correctly when you just feed it numbers, but exhibits the same odd behavior when you put it in region_plot.</p>
<p>Any idea what's going on here?</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17984#post-id-17984By the way, the problem here was that using the `or` meant you were asking Sage/Python to evaluate `x<y` and `x<-y` - try `sage: x<y or x<-y` and see what you get :) Since Sage can't guarantee that the first one is true or false (`bool(x<y)` is `False`, as is `bool(x<-y)`), the outcome of `or` will automatically be the second thing.Sun, 31 Mar 2013 00:01:27 +0100https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17984#post-id-17984Answer by vdelecroix for <p>I'm trying to do a region_plot of a bunch of things that involve an "or" and getting behavior I don't understand.</p>
<p>Here's an example (not so relevant to mine) of the kind of thing I'm encountering:</p>
<p>region_plot([x < y or x < -y], (x,-1,1), (y, -1,1))</p>
<p>If you run this, clearly the output is messed up. It also changes when you switch the order of the two conditions, so it seems to pay attention to just one of them.</p>
<p>I tried carious things like making a function of (x,y) that returns the relevant boolean that works correctly when you just feed it numbers, but exhibits the same odd behavior when you put it in region_plot.</p>
<p>Any idea what's going on here?</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?answer=14709#post-id-14709Hello,
It is documented within the function [region_plot](http://www.sagemath.org/doc/reference/plotting/sage/plot/contour_plot.html#sage.plot.contour_plot.region_plot) (and you can access directly the documentation of a function through question mark). To plot a region with an 'or' statement you must use the following
region_plot([lambda x,y: x < y or x < -y], (x,-1,1), (y, -1,1))
For an 'and' statement you have the choice between
region_plot([lambda x,y: x < y and x < -y], (x,-1,1), (y, -1,1))
and
region_plot([x < y,x < -y], (x,-1,1), (y, -1,1))
VincentSat, 30 Mar 2013 05:38:44 +0100https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?answer=14709#post-id-14709Comment by vdelecroix for <p>Hello,</p>
<p>It is documented within the function <a href="http://www.sagemath.org/doc/reference/plotting/sage/plot/contour_plot.html#sage.plot.contour_plot.region_plot">region_plot</a> (and you can access directly the documentation of a function through question mark). To plot a region with an 'or' statement you must use the following</p>
<pre><code>region_plot([lambda x,y: x < y or x < -y], (x,-1,1), (y, -1,1))
</code></pre>
<p>For an 'and' statement you have the choice between</p>
<pre><code>region_plot([lambda x,y: x < y and x < -y], (x,-1,1), (y, -1,1))
</code></pre>
<p>and</p>
<pre><code>region_plot([x < y,x < -y], (x,-1,1), (y, -1,1))
</code></pre>
<p>Vincent</p>
https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17981#post-id-17981It depends on what you want : a list of graphics ? the intersection for p in P ? What you wrote will plot (A(x,y,p1) or B(x,y,p1)) and (A(x,y,p2) or B(x,y,p2)) and ... The lambda operator is very lazy, it takes the arguments and replace them in the expression you gave it.Sun, 31 Mar 2013 11:50:46 +0200https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17981#post-id-17981Comment by DrNick for <p>Hello,</p>
<p>It is documented within the function <a href="http://www.sagemath.org/doc/reference/plotting/sage/plot/contour_plot.html#sage.plot.contour_plot.region_plot">region_plot</a> (and you can access directly the documentation of a function through question mark). To plot a region with an 'or' statement you must use the following</p>
<pre><code>region_plot([lambda x,y: x < y or x < -y], (x,-1,1), (y, -1,1))
</code></pre>
<p>For an 'and' statement you have the choice between</p>
<pre><code>region_plot([lambda x,y: x < y and x < -y], (x,-1,1), (y, -1,1))
</code></pre>
<p>and</p>
<pre><code>region_plot([x < y,x < -y], (x,-1,1), (y, -1,1))
</code></pre>
<p>Vincent</p>
https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17982#post-id-17982I noticed that in the documentation, and I got the former to work for one function. I have a large family of "or"'s indexed, by say p in P and somehow this broke it. Should region_plot([lambda x,y: A(x,y,p) or B(x,y,p) for p in P], (x,0,1), (y,0,1)] work?Sun, 31 Mar 2013 10:41:32 +0200https://ask.sagemath.org/question/9956/region_plot-with-or-expressions/?comment=17982#post-id-17982