MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replacement Rule with Sqrt in denominator

  • To: mathgroup at
  • Subject: [mg114679] Re: Replacement Rule with Sqrt in denominator
  • From: Jack L Goldberg 1 <jackgold at>
  • Date: Sun, 12 Dec 2010 05:47:32 -0500 (EST)

Andrzej you're 100% correct and indeed in the application in which  
this came up I eventually realized the problem and worked around it in  
essentially the same way you suggested.  Getting around it is one  
thing but why it happens is another.  After all, such behavior is  
really poor design. Why should I have to spend hours on this "feature"  
until I discovered that the FullForm of input 2<=x<=4 is not the same  
as the FullForm of the output of Reduce[2<=x<=4]?  The Reduce function  
was imbedded in 50 lines of code and the error did not immediately  
suggest itself because there were many references to other functions  
throughout the code which could have been the culprit. This suggests  
that EVERY functions that returns 2<=x<=4 as output must be examined  
to see its FullForm before it can be used further, especially if one  
wants Part of the expression.  Andrzej keep in mind the surprise  
factor here.  Two functions return 2<=x<=4 but their outputs have  
different FullForms!

Well maybe I'm nuts but this is bad functionality IMO.  I can't help  
wondering whether there are other examples of this kind and when they  
are going to bite me.


Quoting Andrzej Kozlowski <akoz at>:

> On 11 Dec 2010, at 07:52, Jack L Goldberg 1 wrote:
>> a)  Input as typed:  2<=x<=4.  Look at its fullform.  On my Mac
>> running ver. 7 of Mathematica, I get returned,
>>                    LessEqual[2,x,4].
>> b)  Now type in Reduce[2<=x<=4].  You will get
>> Inequality[2,LessEqual,x,LessEqual,4].
>> These are are different expressions!  How can one program replacement
>> rules when one can not be sure of the FullForm?  These structures are
>> entirely different.  Which fullform can one assume is the one  
>> Mathematica sees
>> in some complicated module wherein one step is a replacement rule?
>> Jack Goldberg
>> Mathematics
>> University of Michigan
> O.K. but I don't see anything here that in any way contradicts  
> anything that has been said about the need for
> for looking at FullForm before trying pattern matching. Actually, it  
> is also an argument against using Copy and Paste. To see that,  
> evaluate Reduce[2<=x<=4]. Now, copy the output and paste it into  
> another cell and wrap FullForm around it, then evaluate. You will  
> get  LessEqual[2,x,4].
> I don't see this as a problem, do you? You can certainly match both  
> forms with a single pattern:
>  {2 <= x <= 4, Reduce[2 <= x <= 4]} /.
>    (a_) <= x <= (b_) |  Inequality[a_, LessEqual, x, LessEqual, b_] :> {a, b}
> {{2, 4}, {2, 4}}
> Andrzej Kozlowski

  • Prev by Date: Re: Replacement Rule with Sqrt in denominator. Also Bug in Series; see Semantica / Harris solution
  • Next by Date: Re: Replacement Rule with Sqrt in denominator. Also Bug in Series
  • Previous by thread: Re: Replacement Rule with Sqrt in denominator
  • Next by thread: Re: Replacement Rule with Sqrt in denominator