Ask Your Question
0

region_plot with "or" expressions

asked 2013-03-29 22:59:49 +0100

DrNick gravatar image

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.

edit retag flag offensive close merge delete

Comments

By 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.<="" p="">

kcrisman gravatar imagekcrisman ( 2013-03-31 00:01:27 +0100 )edit

Sorry, I couldn't get the less than signs to work out right in the comment...

kcrisman gravatar imagekcrisman ( 2013-03-31 00:02:09 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-03-30 05:38:44 +0100

vdelecroix gravatar image

Hello,

It is documented within the function 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))

Vincent

edit flag offensive delete link more

Comments

I 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?

DrNick gravatar imageDrNick ( 2013-03-31 10:41:32 +0100 )edit

It 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.

vdelecroix gravatar imagevdelecroix ( 2013-03-31 11:50:46 +0100 )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

Stats

Asked: 2013-03-29 22:59:49 +0100

Seen: 1,025 times

Last updated: Mar 30 '13