Skip to content

Commit

Permalink
ENHANCED: Use declarative multiplication instead of division.
Browse files Browse the repository at this point in the history
Declarative integer multiplication is more portable.

Raised as issue #6 by @jusski. Thank you!
  • Loading branch information
triska committed May 29, 2018
1 parent 456386a commit 4683bf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions prolog/concepts.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<center><h2>Terms</h2></center>

In Prolog, <i>all data</i>&mdash;including
Prolog <i>programs</i>&mdash;is represented by
Prolog <i>programs</i>&mdash;are represented by
Prolog <a href="data#term"><b>terms</b></a>.

<br><br>
Expand Down Expand Up @@ -279,7 +279,7 @@
hailstone(N, N).
hailstone(N0, N) :-
N0 mod 2 #= 0,
N1 #= N0 // 2,
N0 #= 2*N1,
hailstone(N1, N).
hailstone(N0, N) :-
N0 mod 2 #= 1,
Expand Down Expand Up @@ -323,18 +323,18 @@
<pre>
?- hailstone(X, Y).
X = Y ;
X//2#=Y,
2*Y#=X,
X mod 2#=0 ;
X//2#=_1824,
2*_7770#=X,
X mod 2#=0,
_1824//2#=Y,
_1824 mod 2#=0 ;
X//2#=_2254,
2*Y#=_7770,
_7770 mod 2#=0 ;
2*_8448#=X,
X mod 2#=0,
_2254//2#=_2302,
_2254 mod 2#=0,
_2302//2#=Y,
_2302 mod 2#=0 .
2*_8496#=_8448,
_8448 mod 2#=0,
2*Y#=_8496,
_8496 mod 2#=0 .
</pre>

When studying a Prolog predicate, try the most general query to see
Expand Down
2 changes: 1 addition & 1 deletion prolog/metapredicates.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
hailstone(N0, N) :-
R #= N0 mod 2,
if_(R = 0,
N1 #= N0//2,
N0 #= 2*N1,
N1 #= 3*N0 + 1),
hailstone(N1, N).
</pre>
Expand Down

0 comments on commit 4683bf4

Please sign in to comment.