Re: ? about Rule (rewritten)
- To: mathgroup at smc.vnet.net
- Subject: [mg67193] Re: ? about Rule (rewritten)
- From: Peter Pein <petsie at dordos.net>
- Date: Sun, 11 Jun 2006 23:07:58 -0400 (EDT)
- References: <e6gddi$nb5$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
jackgoldberg schrieb: > 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 > Hi Jack, It works in Mathematica 5.1 (Windows) without problems: {y == z, t == 7, 1 <= x <= 2, u >= -4, 5 <= s <= 7} /. a_ <= w_ <= b_ -> w == (a + b)/2 yields: {y == z, t == 7, x == 3/2, u >= -4, s == 6} Which version do you use? Maybe it helps to replace Rule ("->") by RuleDelayed (":>")? Peter