Ask Your Question

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

edit retag 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="">

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

## 1 answer

Sort by » oldest newest most voted

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

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?

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.

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2013-03-29 16:59:49 -0500

Seen: 290 times

Last updated: Mar 29 '13