Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:multiply [2019/06/27 15:50]
pl:prolog:pllib:multiply [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Multiply ======
 +{{tag>​math arithmetic}}
 +===== Description =====
 +Multiplication as repeated addition.
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{multiply.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 + times(X,​Y,​Z) :-
 + X, Y and Z are natural numbers
 + such that Z is the product of X and Y
 +*/
 +
 + times(0,​X,​0).
 + times(s(X),​Y,​Z) :- times(X,​Y,​XY),​ plus(XY,​Y,​Z).
 +
 + plus(0,​X,​X) :- natural_number(X).
 + plus(s(X),​Y,​s(Z)):​- plus(X,​Y,​Z).
 +
 + natural_number(0).
 + natural_number(s(X)) :- natural_number(X).
 +
 +% Program 3.4: Multiplication as repeated addition
 +% ?- times(s(0),​s(0),​X).
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/multiply.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0