0

I'd like to define the integers and operations on it by using terms. Starting from zero->init[] and nth->succ[n-1th] where succ[] is the successor function. I believe the operations could be implemented as :

add[succ[x],y]=succ[add[x,y]]
product[succ[x],y]=add[product[x,y],y]

But how can I actually define the set or build a successor function?

Thanks

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Chris
  • 3
  • 1
  • Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Dec 19 '14 at 00:12
  • You can format inline code and code blocks by selecting it and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. – Michael E2 Dec 19 '14 at 00:14

2 Answers2

3

It depends on how raw you want to go. Here is an approach that maintains the symbolic character of the formalism:

ClearAll[convertToS, convertFromS, add];

convertToS[0] := 0;
convertToS[n_] := Last[ComposeList[ConstantArray[S, n], 0]];
convertFromS[chain_] := Count[chain, S, Infinity, Heads -> True];

add[a_, 0] := a;
add[0, a_] := a;
add[chain1_, S[chain2_]] := add[S[chain1], chain2];

five = convertToS[5]
sixtyFour = convertToS[64]

add[five, sixtyFour] // convertFromS

S[S[S[S[S[0]]]]]

S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[S[0]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

69

Here the convertToS and convertFromS functions are "outside" the system. Addition just involves commuting all S symbols to the chain on the left. Offhandedly I'm not quite sure how the product could be defined, but it could be done through copying. Philosophically though, in trying to define the numbers you can't escape the usage of them in the first place, implicitly or otherwise.

amr
  • 5,487
  • 1
  • 22
  • 32
1

According to this Wiki article, the successor function is the function with S(1) = 2 and S(2) = 3.. this can be implemented in several ways, perhaps the simplest of which is

s[n_] := n + 1

Hence s[2] returns 3 and s[10] returns 11.

The add function is handled automatically since s[n]+m is 1+n+m. The product is similar since, for instance, s[n] m is automatically simplified to m (1+n). But I'm not sure I understand what you are really trying to do.

bill s
  • 68,936
  • 4
  • 101
  • 191