Re: math2.0 rule ordering
- To: mathgroup at yoda.ncsa.uiuc.edu
- Subject: Re: math2.0 rule ordering
- From: Frank Zizza <willamu!pioneer!zizza at uunet.UU.NET>
- Date: Wed, 7 Aug 91 14:05:17 PDT
I have found that the order in which rules are assigned can be important. (I have not worked with version 2.0 yet, my experience is only with version 1.2) Consider the following: Mathematica (sun4) 1.2 (June 13, 1990) [With pre-loaded data] by S. Wolfram, D. Grayson, R. Maeder, H. Cejtin, S. Omohundro, D. Ballman and J. Keiper with I. Rivin and D. Withoff Copyright 1988,1989,1990 Wolfram Research Inc. In[1]:= f[2] := 2 In[2]:= f[x_] := single In[3]:= f[x__] := double In[4]:= f[x___] := triple In[5]:= ?f f f/: f[2] := 2 f/: f[x_] := single f/: f[x__] := double f/: f[x___] := triple In[5]:= g[x___] := triple In[6]:= g[x__] := double In[7]:= g[x_] := single In[8]:= g[2] := 2 In[9]:= ?g g g/: g[2] := 2 g/: g[x___] := triple g/: g[x__] := double g/: g[x_] := single This shows that the most specific rule is positioned first but that the rules that contain pattern blanks are ordered as they were entered. Presumably Mathematica cannot decide how these rules should be ordered. I cannot test your code (for MoreGeneralThan) because it relies on Mathematica 2.0 constructions but I would GUESS that based on the above Mathematica session it would also return False for MoreGeneralThan[f[x_], f[x___]]. (I would be interested to hear the result of such a test.) If Mathematica 2.0 does in general place the rule for f[x_] before f[x___] as your calculations show, then we can argue that if it did not place the rule for f[x_] first, that rule would never be used since f[a] matches the pattern f[x___]. Frank Zizza zizza at willamette.edu