[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Held Monday, May 3
Summary
Contents
Handouts
Notes
?- pred(pred(succ(succ(succ(zero)))), succ(zero))
equals).
equals(X,Y) :- canonical(X,XC), canonical(Y,YC), equals(XC,YC).
equals.
equals(X,Y) :- canonical(X,XC), canonical(Y,YC), same(XC,YC). same(X,X).
equals(X,Y) :- canonical(X,C), canonical(Y,C).
equals predicate.
equals(pred(X),Y) :- equals(X,succ(Y)). equals(succ(X),Y) :- equals(X,pred(Y)).
equals(zero,Y). We
switch to a separate predicate.
equals(zero,Y) :- balance(zero,Y).
/* 0 == 0 */ balance(zero,zero). /* X-1 == Y-1 iff X = Y */ balance(pred(X),pred(Y)) :- balance(X,Y). /* X+1 == Y+1 iff X = Y */ balance(succ(X),succ(Y)) :- balance(X,Y). /* X+1 == Y-1 iff X+2 = Y */ balance(succ(X),pred(Y)) :- balance(succ(succ(X)), Y). /* X-1 == Y+1 iff X-2 = Y */ balance(pred(X),succ(Y)) :- balance(pred(pred(X)), Y). /* 0 == Y-1 iff Y == - */ balance(zero,pred(Y)) :- balance(succ(zero), Y). /* 0 == Y+1 iff Y == -1 */ balance(zero,succ(Y)) :- balance(pred(zero), Y).
().
(()())
(()(()] should be in both of the first
languages, but some of you didn't accept it.
swap(x,y),
which swaps the values of two variables.
swap(i,A[i]) and
swap(A[i],i)
swap as
function swap(x,y) var tmp; tmp = x; x = y; y = tmp; end
swap(i,A[i]) becomes
var tmp; tmp = i; i = A[i]; A[i] = tmp;
for loops traditionally repeat a statement (or block
of statements) a fixed number of times.
while loops repeat a statement (block of statements)
an arbitrary number of times.
History
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Disclaimer Often, these pages were created ``on the fly'' with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS302/99S/Outlines/outline.37.html
Source text last modified Mon May 3 13:12:02 1999.
This page generated on Mon May 3 13:18:29 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu