Re: ? about Rule (rewritten)
- To: mathgroup at smc.vnet.net
- Subject: [mg67204] Re: ? about Rule (rewritten)
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Sun, 11 Jun 2006 23:08:31 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 6/11/06 at 2:17 AM, jackgoldberg at comcast.net wrote: >I want to replace an inequality of the type 1 <= x <= 2 which >appears in a list some of whose entries are y==3 or z >= 1 and so >forth. (This arose in using Reduce on a set of linear >inequalities.) My life is simpler if 1 <= x <=2 is replace by an >interior point of the interval, say x ==1.5. It has frustrated me >for about a week since I thought I knew the ins and outs of Rule and >ReplaceAll. So, 2 questions. The first and most important is how >to do it (keep in mind that the list I am speaking of is constructed >by programming and I do not want to examine it and make the >replacement that way). The second question is, why doesn't the >following technique work? >(1) {y==z, t==7, 1 <=x<=2, u>=-4}/. (a_<=w_<=b_)->(a+b)/2 Here, you asked Mathematica to replace 1 <=x<=2 with the average of the end points, i.e. 3/2. Instead of getting just the average of the end points, did you want a replacement rule, i.e., the result to be x->3/2? If so, it seems In[4]:= {y == z, t == 7, 1 <= x <= 2, u >= -4} /. (a_) <= (w_) <= (b_) -> w -> (a + b)/2 Out[4]= {y == z, t == 7, x -> 3/2, u >= -4} does what you want -- To reply via email subtract one hundred and four