# Wrong result using “numeric” symbols

Recently I stumbled upon a weird bug when I used a package that sets the NumericQ result of symbols you are feeding into a certain function to true.

Here is a minimal working example of what I mean:

NumericQ[a] ^= True;
NumericQ[b] ^= True;
a + a (-1.) - 2 b + 2. 0 b + 2 b


The output of the above expression should be 0 but it gives

0. - 2 b


Exchanging any of the floats with integers gives the correct result. Could someone explain to me what is happening here? Is this a bug I should report?

Another hint could be that when I decrease the factor in front of the first b by one, the result is decreased by 2:

a + a (-1.) - 3 b + 2. 0 b + 2 b


yields

0. - 4 b


Any ideas are welcome.

• On the one hand, this is probably unexpected behavior. On the other hand: What is the point of setting NumericQ[a] to True if a is a symbol? This breaks the whole purpose of NumericQ. – Henrik Schumacher Mar 15 at 10:49
• It's used in this package: nrgljubljana.ijs.si/sneg. You can define real constants using snegrealconstants, so that for example functions like scalarproduct can distinguish between operators and scalars. – tantum quod Mar 15 at 11:06
• Well, that does not convince me that what they do were good practice. – Henrik Schumacher Mar 15 at 11:12
• If N[x] does not return a number then NumericQ[x] should not be True. This is simply a misuse of NumericQ. – Szabolcs Mar 15 at 12:57
• Here is a reasonable use for adding definitions to NumericQ: mathematica.stackexchange.com/q/128444/12 Using it to indicate what is a scalar and what is an operator is plainly wrong, and will lead to lots of broken things down the road. – Szabolcs Mar 15 at 13:00