CSCE 222 Lecture 14

From Notes
Jump to navigation Jump to search

« previous | Friday, February 25, 2011 | next »


MORE RUBY ACTION!!!

class Integer
  def factorial
    (1..self).inject(:*)
  end
end

... running anything in O(n!) time is a BAD idea!!!


Relations

Let A and B be sets.

Binary Relations

R(from A to B) is a subset RA×B

R is a relation on A iff RA×A=A2

Infix notation: aRb means (a,b)R

Example

Less-than Relation: R<

Applied on set of integers S={1,2,3}: R<={(a,b)A×A|a<b}={(1,2),(1,3),(2,3)}

Properties

reflexive (diagonal relation)
aA((a,a)R)
R< is not reflexive. To make reflexive, take union with reflexive sets (union called reflexive closure): R<(a,a)|aA=R
symmetric
(a,b)R(b,a)R
reflexive relations are also symmetric, since (a,a) and (a,a) are symmetric.
transitive
a,b,cA(((a,b)R(b,c)R)(a,c)R)
Absolute value is transitive: If (a,b)R|| and (a,b)R||, then |a|=|b| and |b|=|c|, so |a|=|c| and (a,c)R||
equivalent
Relation is reflexive, symmetric, and transitive