Re: Replacement Rule with Sqrt in denominator

*To*: mathgroup at smc.vnet.net*Subject*: [mg114688] Re: Replacement Rule with Sqrt in denominator*From*: Daniel Lichtblau <danl at wolfram.com>*Date*: Mon, 13 Dec 2010 03:51:32 -0500 (EST)

----- Original Message ----- > From: "Jack L Goldberg 1" <jackgold at umich.edu> > To: mathgroup at smc.vnet.net > Sent: Sunday, December 12, 2010 4:47:32 AM > Subject: [mg114679] Re: Replacement Rule with Sqrt in denominator > 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 Andrzej Kozlowski responded to this. Let me add or emphasize a few points. (1) The documentation of Inequality is lacking. I will file a suggestion report that it be improved, and better linked to LessEqual et al. (2) There are good reasons to have both Inequality and chaining of e.g. LessEqual. It is advantageous to have a general form that handles intricacies the special cases do not (e.g. a<b<=c). But there is the drawback that we then have a general form that overlaps with the specialized forms. Of course having results returned (e.g. by Reduce) using that general form makes some sense, but then leads to the confusion you report. I do not know if this extends to many functions beyond Reduce, or whether it might be changed therein. I will ask about that. (3) In the overlap cases of general vs. specialized inequality chains, both have the same StandardForm. I think this is appropriate at least from the point of view that StandardForm should reflect "reasonable" typography. But it subverts the notion that StandardForm should be unambiguous. These competing needs have clashed in other places in StandardForm, and I believe that resolutions have gone in both directions on a case-by-case basis. I'm giving my onw impression here; it's not an area in which I have much knowledge. I will mention that neither InputForm nor FullForm are ambiguous in regards to Inequality vs. the specialized inequalities. So the situation is "What you see is not necessarily what you get, but if you change settings to "squint" mode then it will be." Or something to that effect. > 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