# Why can I define N[MySymbol] := …?

As far as I understand, I cannot define the values of built-in functions: Sin[Cat] := Dog will result in error. This is because all built-in symbols have attribute Protected.

However for the function N[], which is also protected, I can define a custom value:

N[Cat] := Dog

By the way, doing so will not change DownValues[N].

So the question is: why function N[] behaves like that? Is it just some hard-coded rule, which is not described in terms of attributes, downvalues etc.?

• It's actually in the NValues. – b3m2a1 Mar 14 '17 at 7:56
• – xzczd Mar 14 '17 at 7:58
• – Szabolcs Mar 14 '17 at 9:25
• Read the Defining Numerical Values tutorial in the documentation. – Edmund Mar 14 '17 at 10:29

Values of this type are actually stored in an analog to DownValues called NValues. Here's an example:

In:= N[IndianaPi] = 4;
IndianaPi // NValues

Out= {HoldPattern[
N[IndianaPi, {MachinePrecision, MachinePrecision}]] :> 4}


As xzczd points out this is mostly a subset of what's mentioned here

Note that a similar mechanism is used for Format:

In:= Format[IndianaPi] =
Interpretation[I\[Pi], IndianaPi];
IndianaPi // FormatValues


Per bcp's comment, the Protected attribute need not be a problem because no assignment to N is actually ever done. For instance:

In:= A /: HoldPattern@Set[A[q_], v_] := (q -> v);

In:= Protect@A

Out= {"A"}

In:= A = 2

Out= 1 -> 2


That gives us no error. And yet:

In:= Attributes@A

Out= {Protected}

• But the question was why N's Protected attribute does not forbid me to write N[***] = ***? – bcp Mar 14 '17 at 8:56
• I'll address that. We can do the same thing with UpValues. I don't know how it's implemented internally. – b3m2a1 Mar 14 '17 at 8:58
• @bcp realized I didn't tag you so you probably didn't see that. – b3m2a1 Mar 14 '17 at 9:10