Basic Issue:
I'm trying to understand the proper use of NumericQ's "magical" capabilities. Please consider the examples below. Actual question and some links are at the very end.
Example 1:
Many of you are aware that NumericQ can be used as follows, without unprotecting:
In[1]:=
Remove[x, y];
NumericQ[x] = True;
(*and apparently using TagSet instead of Set makes no difference because \
you can't direct, let alone see, where this type of info is stored \
anyways.*)
The following output is as expected:
In[3]:=
NumericQ[x]
NumericQ[y]
Out[3]= True
Out[4]= False
Go ahead and make the following assignment:
In[5]:= x = y
Out[5]= y
The following behavior is interesting, but quite reasonable. It seems logical that setting x to y would somehow globally overwrite the "magical" numeric property:
In[6]:=
NumericQ[x]
NumericQ[y]
Out[6]= False
Out[7]= False
Hmmm... #1
...Well, at least I thought it would have 'overwritten' the behavior!!
In[8]:=
(*Note: Could also use Clear[x] or ClearAll[x] *)
x =.
NumericQ[x]
Out[9]= True
Example 2:
Now suppose we had made the assignment x = y first (before evaluating NumericQ[x] = True):
In[12]:=
Remove[x, y];
x = y
Out[13]= y
Hmmm... #2
Now Mathematica has pushed the numerical property onto y as well.
In[14]:=
NumericQ[x] = True
NumericQ[y]
Out[14]= True
Out[15]= True
Question:
How can one put NumericQ[x] = True to good/powerful use---and just as importanltly, in light of the above examples, how can it be used safely? (i.e., Can this behavior be localized somehow? Used safely within a package?---intuition makes me wonder if the only way to isolate the behavior would be to store impacted symbols in a junk context or something.)
@Szabolcs 'Mathematica Tricks' page; scroll down about half way or search for NumericQ: http://web.ift.uib.no/~szhorvat/mmatricks.php
MathGroup Discussion: https://groups.google.com/forum/?fromgroups=#!topic/comp.soft-sys.math.mathematica/buxdxzwV4bY
