CS2322

Laboratory Problem 22

Union and Intersection using Unrestricted Lambdas

A binary relation on a set S is a subset of the Cartesian product of S with itself. In this problem we wish to write a predicate which will determine whether or not a relation is an equivalence-relation.

A binary relation R on a set S is reflexive if for each x in S, the ordered pair (x,x) is an element of R. A binary relation R on a set S is symmetric if for every ordered pair (x,y) in R, the ordered pair (y,x) is also in R. A binary relation R on a set S is transitive if given (x,y) in R and (y,z) in R, then the ordered pair (x,z) is also in R. A binary relation on a set S is an equivalence-relation if it is reflexive, symmetric and transitive.

Write the definition of the predicate equivalence-relation? that tests whether a given relation is an equivalence relation.

(equivalence-relation?

(make-relation '(0 0) '(1 1) '(2 2) '(3 3))) ==> #t

(equivalence-relation?

(make-relation '(0 0) '(0 1) '(1 1) '(2 2) '(3 3))) ==> #t

Hint: define predicates reflexive?, symmetric? and transitive?. In defining transitive? you may find it useful to define a function relation-compose.

Lab 22 Scheme Code