-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNatural_Number_Peano.pl
More file actions
51 lines (34 loc) · 968 Bytes
/
Natural_Number_Peano.pl
File metadata and controls
51 lines (34 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% Natural Numbers
% X is a natural number
natural_number(0).
natural_number(s(X)) :- natural_number(X).
% X is less or equal than Y
leq(0, X) :- natural_number(X).
leq(s(X), s(Y)) :- leq(X, Y).
% X plus Y
pplus(0, X, X) :- natural_number(X).
pplus(X, 0, X) :- natural_number(X).
pplus(s(X), Y, s(Z)) :- pplus(X, Y, Z).
% X times Y
ttimes(0, X, 0) :- natural_number(X).
ttimes(X, 0, 0) :- natural_number(X).
ttimes(s(X), Y, Z) :- ttimes(X, Y, V), pplus(V, Y, Z).
% X pow Y
ppow(X, 0, s(0)) :- natural_number(X).
ppow(X, s(0), X) :- natural_number(X).
ppow(X, s(Y), Z) :-
natural_number(X),
natural_number(Y),
ppow(X,Y,V),
ttimes(X, V, Z).
% Factorial X
ffact(0, s(0)).
ffact(s(0), s(0)).
ffact(s(X), Z) :-
natural_number(X),
ffact(X, Y),
ttimes(s(X), Y, Z).
% Minumin Between X And Y
mmin(0, X, 0) :- natural_number(X).
mmin(X, 0, 0) :- natural_number(X).
mmin(s(x), Y, s(Z)) :- mmin(X, Y, Z).