This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
Wolfram Research, Inc.

Defining Numerical ValuesAdvanced Topic: Manipulating Value Lists

2.4.12 Modifying Built-in Functions

Mathematica allows you to define transformation rules for any expression. You can define such rules not only for functions that you add to Mathematica, but also for intrinsic functions that are already built into Mathematica. As a result, you can enhance, or modify, the features of built-in Mathematica functions.

This capability is powerful, but potentially dangerous. Mathematica will always follow the rules you give it. This means that if the rules you give are incorrect, then Mathematica will give you incorrect answers.

To avoid the possibility of changing built-in functions by mistake, Mathematica "protects" all built-in functions from redefinition. If you want to give a definition for a built-in function, you have to remove the protection first. After you give the definition, you should usually restore the protection, to prevent future mistakes.

Protection for functions.

Built-in functions are usually "protected", so you cannot redefine them.

In[1]:= Log[7] = 2


This removes protection for Log.

In[2]:= Unprotect[Log]


Now you can give your own definitions for Log. This particular definition is not mathematically correct, but Mathematica will still allow you to give it.

In[3]:= Log[7] = 2


Mathematica will use your definitions whenever it can, whether they are mathematically correct or not.

In[4]:= Log[7] + Log[3]


This removes the incorrect definition for Log.

In[5]:= Log[7] =.

This restores the protection for Log.

In[6]:= Protect[Log]


Definitions you give can override built-in features of Mathematica. In general, Mathematica tries to use your definitions before it uses built-in definitions.

The rules that are built into Mathematica are intended to be appropriate for the broadest range of calculations. In specific cases, however, you may not like what the built-in rules do. In such cases, you can give your own rules to override the ones that are built in.

There is a built-in rule for simplifying Exp[Log[expr]].

In[7]:= Exp[Log[y]]


You can give your own rule for Exp[Log[expr]], overriding the built-in rule.

In[8]:= (

Unprotect[Exp] ;

Exp[Log[expr_]] := explog[expr] ;

Protect[Exp] ;


Now your rule is used, rather than the built-in one.

In[9]:= Exp[Log[y]]


Defining Numerical ValuesAdvanced Topic: Manipulating Value Lists