Różnice

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

Odnośnik do tego porównania

pl:prolog:pllib:exp [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Exp ======
 +{{tag>​math arithmetic}}
 +===== Description =====
 +Exponentiation as repeated multiplication
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{exp.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 + exp(N,X,Y) :-
 + N, X and Y are natural numbers
 + such that Y equals X raised to the power N.
 +*/
 +
 + exp(s(N),​0,​0).
 + exp(0,​s(X),​s(0)).
 + exp(s(N),​X,​Y) :- exp(N,X,Z), times(Z,​X,​Y).
 +
 + times(0,​Y,​0).
 + times(s(X),​Y,​Z) :- times(X,​Y,​XY),​ plus(XY,​Y,​Z).
 +
 + myplus(0,​X,​X) :- natural_number(X).
 + myplus(s(X),​Y,​s(Z)):​- myplus(X,​Y,​Z).
 +
 + natural_number(0).
 + natural_number(s(X)) :- natural_number(X).
 +
 +% Program 3.5: Exponentiation as repeated multiplication
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/exp.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