Instantly share code, notes, and snippets.

# jovaneyck/peano.pl

Created November 15, 2018 21:31
Show Gist options
• Save jovaneyck/44a5cdaa13b7f6e646e1aa0f91eb747e to your computer and use it in GitHub Desktop.
Peano arithmetic as an introduction to prolog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 %load a prolog file like [this]. %or just send file to REPL %Peano arithmetic % https://en.wikipedia.org/wiki/Peano_axioms % * 0 is a natural number % * if n is a natural number, s(n) is a natural number % * equality % * 0 = 0 % * a = b -> s(a) = s(b) % * Addition % * a + 0 = a % * a + s(b) = s(a + b) % * Multiplication % * 0 x a = 0 % * s(a) x b = (a x b) + b %Knowledge base %Facts (||) %Queries %Variables %Rules is_number(0). is_number(s(N)) :- is_number(N). eq(0,0). eq(s(M),s(N)) :- eq(M,N). sum(A, 0, A). sum(A, s(B), s(C)) :- sum(A, B, C). mul(0,_,0). mul(s(A),B,C) :- mul(A,B,D), sum(D,B,C).

``````eq(sum(A, o), A).