Re: ? about Rule
- To: mathgroup at smc.vnet.net
- Subject: [mg67165] Re: ? about Rule
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sun, 11 Jun 2006 02:17:41 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <e6e2gu$1va$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
jackgoldberg at comcast.net wrote: > Hi Everyone, > > I am totally puzzled by this and I'm not an Mathematica beginner. > > Let b = {x == 1, 1 ≤ y ≤ 2, z == 3} I want to replace 1 ≤ y ≤ 2 by something else, for this question say 12. So b/. (a_ ≤ u_ ≤ b_) -> 12 should return > {x == 1, 12, z == 3} It doesn't. Why? Even this b/. (1≤ y ≤ 2) -> 12 doesn't work. I'm at a loss... > > Jack > Hi Jack, First, I am afraid that your transformation rule is erroneous. In[1]:= b = {x == 1, (1 & )*#8804; (y & )*#8804; 2, z == 3} Out[1]= {x == 1, 2, z == 3} In[2]:= b /. ((a_ & )*#8804; (u_ & )*#8804; 2) -> 12 Out[2]= {x == 1, 12, z == 3} Indeed, this rule is equivalent to the following one In[3]:= b /. 2 -> 12 Out[3]= {x == 1, 12, z == 3} Now, check the value of 'b'. Whatever the compound expression 1 ≤ y ≤ 2 might possibly mean to you, to Mathematica this is the pure function 1 applied to the slot number 8804, followed by the pure function y applied to the slot number 8804, and finally the atomic expression 2 that returns its own value 2 as value of the whole compound expression. In[4]:= {x\[Equal]1,1≤y≤2,z\[Equal]3}//HoldForm//FullForm Out[4]//FullForm= HoldForm[List[Equal[x,1],CompoundExpression[Times[ Function[1],Slot[8804]],Times[Function[y],Slot[8804]],2],Equal[z,3]]] In[5]:= %//ReleaseHold//FullForm Out[5]//FullForm= List[Equal[x,1],2,Equal[z,3]] Best regards, Jean-Marc