Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  Front Matter /  Tour of Mathematica /

Transformation Rules and Definitions

The notation "/." tells Mathematica TE to use the rule x 1 + a on the algebraic expression .

In[1]:= 1 + x^2 + 3 x^3 /. x -> 1 + a

Out[1]=

You can give transformation rules for any expression. This uses a rule for f[2].

In[2]:= {f[1], f[2], f[3]} /. f[2] -> b

Out[2]=

This replaces f[anything], where anything is named n, by n^2.

In[3]:= {f[1], f[2], f[3]} /. f[n_] -> n^2

Out[3]=

Here is a Mathematica TE function definition. It specifies that f[n] is always to be transformed to n^2.

In[4]:= f[n_] := n^2

The definition for f is automatically used whenever it applies.

In[5]:= f[3] + f[a + b]

Out[5]=

Here is the recursive rule for the factorial function.

In[6]:= fac[n_] := n fac[n-1]

This gives a rule for the end condition of the factorial function.

In[7]:= fac[1] := 1

Here are the two rules you have defined for fac.

In[8]:= ?fac

Mathematica TE can now apply these rules to find values for factorials.

In[9]:= fac[20]

Out[9]=

Mathematica TE lets you give rules for transforming any expression. This defines ln of a product to be a sum of ln functions.

In[10]:= ln[x_ y_] := ln[x] + ln[y]

Mathematica TE uses the definition you have given to expand out this expression.

In[11]:= ln[a b c d]

Out[11]=

You can add a rule for each property of the function.

In[12]:= ln[x_ ^ a_] := a ln[x]

Now the rules for ln apply to a greater variety of expressions.

In[13]:= ln[a^2 b^3]

Out[13]=