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.
Many of you are aware that
NumericQ can be used as follows, without unprotecting:
In:= 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:= NumericQ[x] NumericQ[y] Out= True Out= False
Go ahead and make the following assignment:
In:= x = y Out= y
The following behavior is interesting, but quite reasonable. It seems logical that setting
y would somehow globally overwrite the "magical" numeric property:
In:= NumericQ[x] NumericQ[y] Out= False Out= False
...Well, at least I thought it would have 'overwritten' the behavior!!
In:= (*Note: Could also use Clear[x] or ClearAll[x] *) x =. NumericQ[x] Out= True
Now suppose we had made the assignment
x = y first (before evaluating
NumericQ[x] = True):
In:= Remove[x, y]; x = y Out= y
Now Mathematica has pushed the numerical property onto
y as well.
In:= NumericQ[x] = True NumericQ[y] Out= True Out= True
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