Re: Just another Mathematica "Gotcha", and HoldForm bug
- To: mathgroup at smc.vnet.net
- Subject: [mg121095] Re: Just another Mathematica "Gotcha", and HoldForm bug
- From: Richard Fateman <fateman at cs.berkeley.edu>
- Date: Sat, 27 Aug 2011 08:16:46 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j1r5d3$fi4$1@smc.vnet.net> <j1tnpf$pnu$1@smc.vnet.net> <j22qe4$gop$1@smc.vnet.net>
On 8/12/2011 2:06 AM, Oleksandr Rasputinov wrote: >>> >>>(RJF) Did you know that >>> >>> HoldForm[x //@ y] returns x//@y >>> but >>> HoldForm[x // y] returns y[x] >>> >>> ? >>> (version 7.0). >>> >> .. snip.. > > On further consideration it strikes me that I may have misunderstood what > you meant here. Yes. but you got it right, below. HoldForm is simply printing the expressions in InputForm, > so for example we also have > > HoldForm[MapAll[x,y]] > > printing: > > x //@ y > > Conversion between two equivalent syntactic forms (postfix notation, and > InputForm) is not considered to be a form of evaluation; I agree. it is simply the > way in which the expressions are parsed. Not really parsed, but displayed. a[b] , a@b, and b//a are parsed into the same thing. I view Postfix, Prefix, InputForm as output specifiers; hints to the display program on what to do, not actual conversions. I suppose Mathematica could be doing something else, but this is the way I'd do it. That is, I'd store Postfix[a[b]], but write the display program to show it as b//a. I find the specifications defective, anyway. For instance, Postfix[f[a,b]] comes out as Postfix[f[a,b]] instead of the form Sequence[a,b]//f, which is in fact a postfix version of f[a,b]. If you want an expression that > prints in a particular way you can use > > HoldForm@Postfix[x // y] Not really useful. That expression is not x//y. It is HoldForm[Postfix[y[x]]]. ... The point of my posting is that there is an inconsistency in Mathematica that says that x//y is normally displayed as y[x]. x/.y is normally displayed as x/.y not ReplaceAll[x,y] doing FullForm[everything] is probably the only way to consistently reduce the clutter of mystery, and the display program is clearly able to make more or less informed choices on preferred formats for any construct. I think that f[a,b] is much preferable to Sequence[a,b]//f. I think that, especially for novices, ReplaceAll[x,y] has more mnemonic content than x/.y. Someone's note (DanL?) raised the Dot issue. More gotchas, but not nearly as likely to occur, are these puzzles. One might wonder how to parse x . y x .. y x...y x . .. y x.. . y x....y x.....y x......y x.......y All of which are syntactically valid. Of lines 3,4,5, two of them have the same meaning. Can you tell which? Also consider the confusing lines below 3. ..4 3.. .4 3....4 3... .4 3. ...4 which are NOT the same at all when 3, 4 are x, y. Hint. FullForm[x..] is Repeated[x], and FullForm[x...] is RepeatedNull[x]. RJF