Ask Your Question
0

region_plot with "or" expressions

asked 12 years ago

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.

Preview: (hide)

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 ( 12 years ago )

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

kcrisman gravatar imagekcrisman ( 12 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 12 years ago

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

Preview: (hide)
link

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 ( 12 years ago )

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 ( 12 years ago )

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: 12 years ago

Seen: 1,102 times

Last updated: Mar 30 '13