# Strange behavior when setting NumericQ of a symbol

It happens both in v9&v10. If you try this

a^0
a^0 (1/a)^(3/2)
a^0 (1/a)^(5/2)


Mathematica returns

1
(1/a)^(3/2)
(1/a)^(5/2)

It's trivial. However, check this out

b /: NumericQ[b] = True;
b^0
b^0 (1/b)^(3/2)
b^0 (1/b)^(5/2)


Mathematica gives

b^0
(1/b)^(3/2)
Hold[(1/b)^(5/2) b^0]

If you trace the last two input, you'll get this

{{{1/b,1/b},{{1/2,1/2},3/2,3/2},(1/b)^(3/2)},b^0 (1/b)^(3/2),(1/b)^(3/2) b^0,(1/b)^(3/2)}

{{{1/b,1/b},{{1/2,1/2},5/2,5/2},(1/b)^(5/2)},b^0 (1/b)^(5/2),(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,<<4063>>,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,Sqrt[1/b]/b^2,(1/b)^(5/2) b^0,{Message[$IterationLimit::itlim,4096],{$IterationLimit::itlim,$Off[]},Null},Hold[(1/b)^(5/2) b^0]} You can find that in the first case,$b^0$actually goes to 1, this doesn't happen in the last case (and when evaluating b^0 (1/b)^(1/2)). I guess that since I set b to be a numeric value, b might be 0, then 0^0 is meaningless; Mathematica will keep the input form; but why does b^0 behave different between b^0 (1/b)^(3/2) and b^0 (1/b)^(5/2) or even stranger is why Mathematica vibrate bewteen (1/b)^(5/2) b^0 and Sqrt[1/b]/b^2 in the last case? • Following Knuth, unprotecting Power and adding the rule Power[_,0]=1 dispenses with the behavior. As to why it's doing that... beats me right now. – ciao Feb 28 '15 at 9:41 • Confirmed with Mathematica 10.0.2 on Windows. I suggest you report it as a bug to WRI. – Simon Woods Feb 28 '15 at 12:52 • Id say more a curiosity that a bug. You are essentially lying to the interpreter claiming the symbol is numeric when it is not. So..garbage in -> garbage out. Can you provide a real example where it makes sense to do this? – george2079 Feb 28 '15 at 18:28 • @george2079 Sorry for my late response. I want to do this when some symbol in the calculation should be treated as a number, otherwise, they will be treated as 3-vector (adding subscript etc). I can bypass this by declaring my own type, such as b/:myNumberForm[b]=True or following rasher's suggestion, but still I can't understand this strange behavior. – luyuwuli Mar 1 '15 at 7:43 ## 1 Answer As you note yourself the difference between b^0 (1/b)^(3/2) and b^0 (1/b)^(5/2) is that the second form results in transformation into Sqrt[1/b]/b^2. This in turn is transformed into (1/b)^(5/2) b^0 causing an infinite loop. You can see some more detail of the process with this: b /: NumericQ[b] = True;$IterationLimit = 20;

Trace[Sqrt[1/b]/b^2, TraceInternal -> True][[;; 15]]

{{{1/b, 1/b}, Sqrt[1/b], {Im[-1], 0}, {1/2 Log[1/b], 1/2 Log[1/b]}, Sqrt[1/b]},
{1/b^2, 1/b^2}, Sqrt[1/b]/b^2, {1/Sqrt[1/b], {Im[-1], 0}, {1/2 Log[1/b] (-1),
-(1/2) Log[1/b]}, 1/Sqrt[1/b]}, {Im[-1], 0}, {1/2 Log[1/b] (-1), -(1/2) Log[1/b]},
{(1/b)^(5/2), {Im[-1], 0}, {1/2 Log[1/b] 5, 5/2 Log[1/b]}, (1/b)^(5/2)},
{Im[-1], 0}, {1/2 Log[1/b] 5, 5/2 Log[1/b]}, (1/b)^(5/2) b^0, {Sqrt[1/b],
{Im[-1], 0}, {1/2 Log[1/b], 1/2 Log[1/b]}, Sqrt[1/b]}, {Sqrt[1/b], {Im[-1], 0},
{1/2 Log[1/b], 1/2 Log[1/b]}, Sqrt[1/b]}, {Im[-1], 0}, {1/2 Log[1/b],
1/2 Log[1/b]}, Sqrt[1/b]/b^2}


Note that by the end of this we have Sqrt[1/b]/b^2 again.

The specific internal rules used in these transformations are not disclosed.
The appearance of Log might relate to what Daniel Lichtblau wrote:

A machine double, raised to a machine double power, will in effect compute exp(pow*log(base))

• Did you mean that this behavior is related to internal rules that can't be disclosed? In my opinion, this seems to be a bug. – luyuwuli Mar 2 '15 at 3:43
• @luyuwuli I mean only that the rules are not revealed in the result shown above. I do not know if this is a bug or not, though I would agree that it is undesirable. I agree with george2079 however that this amounts to "lying to the interpreter" and it does not surprise me if something breaks. In that sense it is no different from unprotecting an important system function and changing its behavior. – Mr.Wizard Mar 2 '15 at 4:18