N[expr, prec]N[Pi, 50]
You can manually assign numerical values to symbols.
When you do not specify a precision, MachinePrecision is taken.
N[a] = 10.9
a
N automatically threads over expressions, except when a symbol has attributes NHoldAll, NHoldFirst, or NHoldRest.
N[a + b]
N[a, 20]
N[a, 20] = 11;
N[a + b, 20]
N[f[a, b]]
SetAttributes[f, NHoldAll]
N[f[a, b]]
The precision can be a pattern:
N[c, p_?(#>10&)] := p
N[c, 3]
N[c, 11]
You can also use UpSet or TagSet to specify values for N:
N[d] ^= 5;
However, the value will not be stored in UpValues, but in NValues (as for Set):
UpValues[d]
NValues[d]
e /: N[e] = 6;
N[e]
Values for N[expr] must be associated with the head of expr:
f /: N[e[f]] = 7;
You can use Condition:
N[g[x_, y_], p_] := x + y * Pi /; x + y > 3
SetAttributes[g, NHoldRest]
N[g[1, 1]]
N[g[2, 2]]