Re: ? about Rule (rewritten)
- To: mathgroup at smc.vnet.net
- Subject: [mg67213] Re: ? about Rule (rewritten)
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Sun, 11 Jun 2006 23:08:57 -0400 (EDT)
- References: <e6gddi$nb5$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
jackgoldberg at comcast.net wrote: > Hi, > > My post on this topic was garbled. Here I hope is a clearer version :-). > > 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 > To save space, I choose not to write all my variations of trying this including the obvious one of finding the FullForm of 1 <=x<=2 and using it in (1). I might mention also that every now and then, in isolation from my module, I have managed to make it work, not often but enough to delay my plea for help. I am guessing that there is a pattern matching issue here (sort of obvious comment) but I am at a loss anyway. > > Incidentally I have designed a work around that is so combersome that if there were a prize for the klutzest Mathematica code, this would be a candidate for top prize. > > Jack > The above replacement worked for me using 5.2 under Windows XP: {y\[Equal]z,t\[Equal]7,1\[LessEqual]x\[LessEqual]2, u\[GreaterEqual]-4}/.(a_\[LessEqual]w_\[LessEqual]b_)\[Rule](a+b)/2 {y == z, t == 7, 3/2, u >= -4} David Bailey http://www.dbaileyconsultancy.co.uk