As of May 4 2007 the scripts will autodetect your timezone settings. Nothing here has to be changed, but there are a few things

Please follow this blog

Search this blog

Friday, October 7, 2011

Primitive recursive function

Normally you calculate n factorial with Factorial[n] or short n!. Mathematica handles the details of the function for you and prints the result.

In the course M381 you have to prove that functions like factorial are a primitive recursive function. This basically means that the function can be defined only in terms of itself, add one, or set to zero. A primitive recursive definition of factorial would look as follows in Mathematica.

suc[n1_] := n1 + 1
add[n1_, 0] := n1
add[n1_, n2_] := suc[add[n1, n2 - 1]]
mul[n1_, 0] := 0
mul[n1_, n2_] := add[mul[n1, n2 - 1], n1]
fac[0] := suc[0]
fac[n_] := mul[n, fac[n - 1]]


As you can see no other Mathematica functions than "+ 1" and "= 0" are used. The functions suc, add, mul, fac are defined for the first time.

For example:
In[67]:= Factorial[6]
fac[6]

Out[67]= 720

Out[68]= 720
.

No comments:

Post a Comment

Popular Posts

Welcome to The Bridge

Mathematics: is it the fabric of MEST?
This is my voyage
My continuous mission
To uncover hidden structures
To create new theorems and proofs
To boldly go where no man has gone before




(Raumpatrouille – Die phantastischen Abenteuer des Raumschiffes Orion, colloquially aka Raumpatrouille Orion was the first German science fiction television series. Its seven episodes were broadcast by ARD beginning September 17, 1966. The series has since acquired cult status in Germany. Broadcast six years before Star Trek first aired in West Germany (in 1972), it became a huge success.)