Re: Replacement Rule with Sqrt in denominator
- To: mathgroup at smc.vnet.net
- Subject: [mg114603] Re: Replacement Rule with Sqrt in denominator
- From: Richard Fateman <fateman at cs.berkeley.edu>
- Date: Fri, 10 Dec 2010 02:28:42 -0500 (EST)
- References: <idnqpr$q58$1@smc.vnet.net> <idqd1i$j3o$1@smc.vnet.net>
On 12/9/2010 3:03 AM, Sebastian wrote: > I don't want to claim that pattern matching in Mathematica is bugged, > I am certainly not entitled to do so. I was always quite happy to > follow the rules and look at the FullForm in order to create the > correct pattern, until I learned (actually just by following this > thread) that this does not always produce the expected results. So > even though this may not be a bug, pattern matching can be very > confusing sometimes, and, in terms of usability, may seem to be poorly > implemented to some people. > Having said that, could somebody give me a little insight on how > pattern matching "really" works (I'm sure Daniel has done so many > times already, please feel free to refer me to previous posts!): > What set (or class) of expressions does pattern matching exclude from > its "normal" behavior (obviously there is Rational, Complex, > whatnot...)? Apparently these are called "Raw" objects, and there are others, like SparseArray, and some Graphics thing/?/ Why? Are there different such classes? Why does 3/5[[1]] > fail (alternatively: Why does Rational behave differently then List, > say)? While a+b is internally a list of 3 items, Plus, a, b ... I expect that 3/4 is NOT a list of 3 items, Rational, 3, 4, but some primitive encoded object. What FullForm claims is in fact false. An analogy: in other systems you have a floating-point number x=3.145. You do not expect x[[3]] to be "1". Though of course you might allow that if you interpret "parts" of floating point numbers to do a string conversion etc. This happens on some level for EVERYTHING. After all, an integer in FullForm is a character string with decimal digits, but truly internally an integer is some encoding in 32 or 64 or more bits. I think that, given the FullForm appearance of something like 3/4, it would not be much of a stretch to allow part extraction from Rationals, and to do pattern-matching on their parts. It would make FullForm more accurate in some sense. WRI policy is to disagree. RJF