Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Replacement Rule with Sqrt in denominator

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114656] Re: Replacement Rule with Sqrt in denominator
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 12 Dec 2010 05:41:00 -0500 (EST)

I agree that the fact that these two different forms:

Inequality[2, LessEqual, x, LessEqual, 3]

and

LessEqual[2, x, 3]

look exactly the same after evaluation while retaining different FullForms is a trap even for experienced users, and that it should be clearly documented, probably in more than one place. In fact Inequality is probably the worst documented function in Mathematica (not counting the undocumented ones). (I believe I myself found out about its existence on this forum several years ago.)

The lack of documentation is clearly indefensible and I am not going to attempt to defend it. I don't think, however, that the existence of these two forms necessarily constitutes bad design. In fact Inequality is a very convenient way to represent, in a compact form, complicated inequalities, like

Inequality[0, Less, x, LessEqual, y, Less, 2, LessEqual, z, Less, 4]

which otherwise have to be written as a clumsy conjunctions of expressions involving Less and LessEqual. Once you get used to Inequality you will find that it is a useful thing to have but of course if nobody tells you about it,  it is worse than useless.

Andrzej Kozlowski


On 11 Dec 2010, at 19:52, Jack L Goldberg 1 wrote:

> 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.
>
> Jack
>
>
>
> Quoting Andrzej Kozlowski <akoz at mimuw.edu.pl>:
>
>>
>> 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: On the foundation of Mathematica, was Re: Foo /: Plus[b_Foo] := b
  • 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