# 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. Mar 14, 2017 at 7:56
• Mar 14, 2017 at 7:58
• Mar 14, 2017 at 9:25
• Read the Defining Numerical Values tutorial in the documentation. Mar 14, 2017 at 10:29

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

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

Out[14]= {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[43]:= 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[118]:= A /: HoldPattern@Set[A[q_], v_] := (q -> v);

In[119]:= Protect@A

Out[119]= {"A"}

In[120]:= A[1] = 2

Out[120]= 1 -> 2


That gives us no error. And yet:

In[121]:= Attributes@A

Out[121]= {Protected}

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