binary relations -...

165
Binary Relations Part One

Upload: others

Post on 04-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Binary RelationsPart One

Page 2: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Outline for Today

● Binary Relations● Reasoning about connections between

objects.● Properties of Relations

● Certain relations are Interesting and Noteworthy – why?

● Equivalence Relations● Reasoning about clusters.

Page 3: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Relationships

● In CS103, you've seen examples of relationships● between sets:

A ⊆ B● between numbers:

x < y x ≡ₖ y x ≤ y● between people:

p loves q

● Since these relations focus on connections between two objects, they are called binary relations.● The “binary” here means “pertaining to two things,”

not “made of zeros and ones.”

Page 4: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

What exactly is a binary relation?

Page 5: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 6: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 7: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 8: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 9: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 10: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 11: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

<

Page 12: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

10 12

<

Page 13: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

10 12

<

10 < 12

Page 14: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

<

Page 15: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

<

5 -2

Page 16: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

<

5 -2

5 <� -2

Page 17: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

≡₃

Page 18: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

≡₃

7 10

Page 19: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

7 10

≡₃

7 ≡₃ 10

Page 20: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

≡₃

6 11

Page 21: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

≡₃

6 11

6 ≡�₃ 11

Page 22: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 23: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

R

Page 24: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

R

Page 25: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

aRb

R

Page 26: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

R

Page 27: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

aR̸b

R

Page 28: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Binary Relations

● A binary relation over a set A is a predicate R that can be applied to ordered pairs of elements drawn from A.

● If R is a binary relation over A and it holds for the pair (a, b), we write aRb.

3 = 3 5 < 7 Ø ⊆ ℕ● If R is a binary relation over A and it does not

hold for the pair (a, b), we write aR̸b.

4 ≠ 3 4 << 3 ℕ ⊆< Ø

Page 29: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Properties of Relations

● Generally speaking, if R is a binary relation over a set A, the order of the operands is significant.● For example, 3 < 5, but 5 << 3.● In some relations order is irrelevant; more on that

later.● Relations are always defined relative to some

underlying set.● It's not meaningful to ask whether ☺ ⊆ 15, for

example, since ⊆ is defined over sets, not arbitrary objects.

Page 30: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Visualizing Relations

● We can visualize a binary relation R over a set A by drawing the elements of A and drawing an arrow between an element a and an element b if aRb is true.

● Example: the relation a | b (meaning “a divides b”) over the set {1, 2, 3, 4} looks like this:

1

2

4

3

Page 31: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Visualizing Relations

● We can visualize a binary relation R over a set A by drawing the elements of A and drawing an arrow between an element a and an element b if aRb is true.

● Example: the relation a ≠ b over the set {1, 2, 3, 4} looks like this:

1

2

4

3

Page 32: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Visualizing Relations

● We can visualize a binary relation R over a set A by drawing the elements of A and drawing an arrow between an element a and an element b if aRb is true.

● Example: the relation a = b over the set {1, 2, 3, 4} looks like this:

1

2

4

3

Page 33: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Visualizing Relations

● We can visualize a binary relation R over a set A by drawing the elements of A and drawing an arrow between an element a and an element b if aRb is true.

● Example: below is some relation over {1, 2, 3, 4} that's a totally valid relation even though there doesn't appear to be a simple unifying rule.

1

2

4

3 This element does not relate to anything, and nothing relates to it.

It’s called an isolated element.

This element does not relate to anything, and nothing relates to it.

It’s called an isolated element.

Page 34: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Capturing Structure

Page 35: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Capturing Structure

● Binary relations are an excellent way for capturing certain structures that appear in computer science.

● Today, we'll look at one of them (partitions), and next time we'll see another (prerequisites).

● Along the way, we'll explore how to write proofs about definitions given in first-order logic.

Page 36: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Partitions

Page 37: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 38: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 39: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 40: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 41: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 42: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 43: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 44: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 45: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 46: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 47: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Partitions

● A partition of a set is a way of splitting the set into disjoint, nonempty subsets so that every element belongs to exactly one subset.● Two sets are disjoint if their intersection is the

empty set; formally, sets S and T are disjoint if S ∩ T = Ø.

● Intuitively, a partition of a set breaks the set apart into smaller pieces.

● There doesn't have to be any rhyme or reason to what those pieces are, though often there is one.

Page 48: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Partitions and Clustering

● If you have a set of data, you can often learn something from the data by finding a “good” partition of that data and inspecting the partitions.● Usually, the term clustering is used in data

analysis rather than partitioning.● Interested to learn more? Take CS161 or

CS246!

Page 49: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

What's the connection between partitions and binary relations?

Page 50: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 51: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a a

Page 52: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a a

Page 53: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 54: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

Page 55: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

Page 56: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

Page 57: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

ab

Page 58: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between
Page 59: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

Page 60: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a b

Page 61: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a bc

Page 62: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

b c

Page 63: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

ab c

Page 64: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

ca

Page 65: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

ba cb ca

ba ab

aa

∧ →

Page 66: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

→∧

aRa

aRb bRa

aRb bRc aRc

Page 67: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa

∀a ∈ A. ∀b ∈ A. (aRb → bRa)

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)

Page 68: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa

∀a ∈ A. ∀b ∈ A. (aRb → bRa)

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)

Page 69: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Reflexivity

● Some relations always hold from any element to itself.

● Examples:● x = x for any x.● A ⊆ A for any set A.● x ≡ₖ x for any x.

● Relations of this sort are called reflexive.● Formally speaking, a binary relation R over a set A is

reflexive if the following first-order statement is true:

∀a ∈ A. aRa

(“Every element is related to itself.”)

Page 70: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Reflexivity Visualized

∀a ∈ A. aRa(“Every element is related to itself.”)

Page 71: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa(“Every element is related to itself.”)

Let R be the relation drawn to the left. Is R

reflexive?

Let R be the relation drawn to the left. Is R

reflexive?

Page 72: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa(“Every element is related to itself.”)

Page 73: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa(“Every element is related to itself.”)

a

Page 74: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa(“Every element is related to itself.”)

a

Page 75: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa(“Every element is related to itself.”)

a

This means that R is not reflexive, since the first-order logic

statement given below is not true.

This means that R is not reflexive, since the first-order logic

statement given below is not true.

Page 76: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is reflexive?Is reflexive?

∀a ∈ A. aRa(“Every element is related to itself.”)

Page 77: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is reflexive?Is reflexive?

∀a ∈ ??. a a

Page 78: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is reflexive?Is reflexive?

∀a ∈ ??. a a

Reflexivity is a property of relations, not

individual objects.

Reflexivity is a property of relations, not

individual objects.

Page 79: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa

∀a ∈ A. ∀b ∈ A. (aRb → bRa)

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)

Page 80: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa

∀a ∈ A. ∀b ∈ A. (aRb → bRa)

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)

Page 81: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Symmetry

● In some relations, the relative order of the objects doesn't matter.

● Examples:● If x = y, then y = x.● If x ≡ₖ y, then y ≡ₖ x.

● These relations are called symmetric.● Formally: a binary relation R over a set A is called

symmetric if the following first-order statement is true about R:

∀a ∈ A. ∀b ∈ A. (aRb → bRa)

(“If a is related to b, then b is related to a.”)

Page 82: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Symmetry Visualized

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

Page 83: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is This Relation Symmetric?

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

Page 84: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is This Relation Symmetric?

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

a

b

Page 85: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is This Relation Symmetric?

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

a

b

Page 86: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

Is This Relation Symmetric?

Page 87: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

Is This Relation Symmetric?

Pro tip: to see if this statement is true, see if

its negation is false.

Pro tip: to see if this statement is true, see if

its negation is false.

Page 88: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

Page 89: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

¬∀a ∈ A. ∀b ∈ A. (aRb → bRa)

Page 90: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∃a ∈ A. ¬∀b ∈ A. (aRb → bRa)

Page 91: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∃a ∈ A. ∃b ∈ A. ¬(aRb → bRa)

Page 92: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∃a ∈ A. ∃b ∈ A. (aRb ∧ bR̸a)

Page 93: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∃a ∈ A. ∃b ∈ A. (aRb ∧ bR̸a)(“Some a relates to some b, but not vice-versa”)

Page 94: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∃a ∈ A. ∃b ∈ A. (aRb ∧ bR̸a)(“Some a relates to some b, but not vice-versa”)

This element is isolated, so it can’t be

a counterexample.

This element is isolated, so it can’t be

a counterexample.

Page 95: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∃a ∈ A. ∃b ∈ A. (aRb ∧ bR̸a)(“Some a relates to some b, but not vice-versa”)

This self-loop doesn’t pose

any problems.

This self-loop doesn’t pose

any problems.

I me.❤ me.

Page 96: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. ∀b ∈ A. (aRb → bRa)(“If a is related to b, then b is related to a.”)

Is This Relation Symmetric?

Page 97: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa

∀a ∈ A. ∀b ∈ A. (aRb → bRa)

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)

Page 98: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

∀a ∈ A. aRa

∀a ∈ A. ∀b ∈ A. (aRb → bRa)

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)

Page 99: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Transitivity

● Many relations can be chained together.● Examples:

● If x = y and y = z, then x = z.● If R ⊆ S and S ⊆ T, then R ⊆ T.● If x ≡ₖ y and y ≡ₖ z, then x ≡ₖ z.

● These relations are called transitive.● A binary relation R over a set A is called transitive if the

following first-order statement is true about R:

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)

(“Whenever a is related to b and b isrelated to c, we know a is related to c.)

Page 100: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Transitivity Visualized

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)(“Whenever a is related to b and b is

related to c, we know a is related to c.)

Page 101: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is This Relation Transitive?

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)(“Whenever a is related to b and b is

related to c, we know a is related to c.)

Page 102: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is This Relation Transitive?

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)(“Whenever a is related to b and b is

related to c, we know a is related to c.)

a

c

b

Page 103: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is This Relation Transitive?

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)(“Whenever a is related to b and b is

related to c, we know a is related to c.)

a

c

b

Page 104: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Is This Relation Transitive?

∀a ∈ A. ∀b ∈ A. ∀c ∈ A. (aRb ∧ bRc → aRc)(“Whenever a is related to b and b is

related to c, we know a is related to c.)

a

c

b

Page 105: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Equivalence Relations

● An equivalence relation is a relation that is reflexive, symmetric and transitive.

● Some examples:● x = y● x ≡ₖ y● x has the same color as y● x has the same shape as y.

Page 106: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Binary relations give us a common language to describe common

structures.

Page 107: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Equivalence Relations

● Most modern programming languages include some sort of hash table data structure.● Java: HashMap● C++: std::unordered_map● Python: dict

● If you insert a key/value pair and then try to look up a key, the implementation has to be able to tell whether two keys are equal.

● Although each language has a different mechanism for specifying this, many languages describe them in similar ways...

Page 108: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Equivalence Relations

“The equals method implements an equivalence relation on non-null object references:● It is reflexive: for any non-null reference value x, x.equals(x) should return true.

● It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.

● It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.”

Java 8 Documentation

Page 109: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Equivalence Relations

“The equals method implements an equivalence relation on non-null object references:● It is reflexive: for any non-null reference value x, x.equals(x) should return true.

● It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.

● It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.”

Java 8 Documentation

Page 110: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Equivalence Relations

“Each unordered associative container is parameterized by Key, by a function object type Hash that meets the Hash requirements (17.6.3.4) and acts as a hash function for argument values of type Key, and by a binary predicate Pred that induces an equivalence relation on values of type Key. Additionally, unordered_map and unordered_multimap associate an arbitrary mapped type T with the Key.”

C++14 ISO Spec, §23.2.5/3

Page 111: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Equivalence Relations

“Each unordered associative container is parameterized by Key, by a function object type Hash that meets the Hash requirements (17.6.3.4) and acts as a hash function for argument values of type Key, and by a binary predicate Pred that induces an equivalence relation on values of type Key. Additionally, unordered_map and unordered_multimap associate an arbitrary mapped type T with the Key.”

C++14 ISO Spec, §23.2.5/3

Page 112: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Time-Out for Announcements!

Page 113: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Problem Set One Solutions

● We’ve just released solutions to Problem Set One on the course website (sorry – our printer broke!)

● You need to read over these solutions as soon as possible.

● Why?● Each question is there for a reason. We’ve described

what it is that we hoped you would have learned when solving those problems.

● There are lots of different ways of solving these problems. Comparing what you did against our solutions, which are just one possible set of solutions, can help introduce new techniques.

Page 114: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Problem Set Two

● The Problem Set Two checkpoint was due today at 2:30PM.● Solutions are available online. You need to read these

solutions to make sure you understand why each question was there and what the main points were.

● The remaining problems are due Friday at 2:30PM.● Have questions?

● Stop by office hours!● Ask on Piazza!

Page 115: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Your Questions

Page 116: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

“What’s the most important thing for us to leave Stanford knowing?”

I don’t think there’s a single, most important piece of knowledge you should make sure to gain before leaving here. If there were, we’d shout it off of rooftops at all hours of the day. There are a few things that I think are 😃 There are a few things that I think are

worth learning while you’re here:

1. A basic understanding of what makes you happy, what your core values are,and what you’re willing to invest your energy doing.

2. That the world is far more exciting and nuanced than it appears to be, andthat it is absolutely worth your time to go learn more about it.

3. How to respectfully disagree with someone and question deeply-held beliefs.

4. Lots of interesting, exciting people who you’ll stay in touch with for therest of your life.

5. That no discipline has a monopoly on truth and that all simple models arewrong.

I don’t think there’s a single, most important piece of knowledge you should make sure to gain before leaving here. If there were, we’d shout it off of rooftops at all hours of the day. There are a few things that I think are 😃 There are a few things that I think are

worth learning while you’re here:

1. A basic understanding of what makes you happy, what your core values are,and what you’re willing to invest your energy doing.

2. That the world is far more exciting and nuanced than it appears to be, andthat it is absolutely worth your time to go learn more about it.

3. How to respectfully disagree with someone and question deeply-held beliefs.

4. Lots of interesting, exciting people who you’ll stay in touch with for therest of your life.

5. That no discipline has a monopoly on truth and that all simple models arewrong.

Page 117: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

“What’s the best piece of advice you’ve ever received?”

Again, no clear winners here. But here’s a sampler:

“Celebrate your ignorance, then correct it.” Never be afraid to admit that you don’t know something, and take pleasure in learning new things.

“Never underestimate the value of biological care and maintenance.” You are not a brain in a jar. You are a dynamic, living, breathing human being. So take care of yourself – get into a good exercise routine, eat well, sleep well, spend time with friends, and do what you need to do to recharge.

“You’ve never been lost until you’re lost at Mach 3.” There is a time and a place to face adversity by doubling down and pushing harder. But that approach has its limits, and you need to recognize when you’re pushing yourself too hard.

Again, no clear winners here. But here’s a sampler:

“Celebrate your ignorance, then correct it.” Never be afraid to admit that you don’t know something, and take pleasure in learning new things.

“Never underestimate the value of biological care and maintenance.” You are not a brain in a jar. You are a dynamic, living, breathing human being. So take care of yourself – get into a good exercise routine, eat well, sleep well, spend time with friends, and do what you need to do to recharge.

“You’ve never been lost until you’re lost at Mach 3.” There is a time and a place to face adversity by doubling down and pushing harder. But that approach has its limits, and you need to recognize when you’re pushing yourself too hard.

Page 118: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Back to CS103!

Page 119: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Equivalence Relation Proofs

● Let's suppose you've found a binary relation R over a set A and want to prove that it's an equivalence relation.

● How exactly would you go about doing this?

Page 120: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

An Example Relation

● Consider the binary relation ~ defined over the set ℤ:

a~b if a+b is even● Some examples:

0~4 1~9 2~6 5~5● Turns out, this is an equivalence relation! Let's see how to

prove it.

We can binary relations by giving a rule, like this:

a~b if some property of a and b holds

This is the general template for defining a relation. Although we're using “if” rather than “if and only if” here, the above statement means “these two things mean the same thing as one another.” Yes, this is confusing, but it’s a standard convention.

We can binary relations by giving a rule, like this:

a~b if some property of a and b holds

This is the general template for defining a relation. Although we're using “if” rather than “if and only if” here, the above statement means “these two things mean the same thing as one another.” Yes, this is confusing, but it’s a standard convention.

Page 121: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

What properties must ~ have to be an equivalence relation?

ReflexivitySymmetry

Transitivity

Let's prove each property independently.

Page 122: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

A lemma is a smaller result that’s used to prove a larger theorem. Here, just for simplicity, we’re breaking out the proof that ~ is reflexive into its own

separate lemma.

A lemma is a smaller result that’s used to prove a larger theorem. Here, just for simplicity, we’re breaking out the proof that ~ is reflexive into its own

separate lemma.

Page 123: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

Page 124: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

Page 125: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

Page 126: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

Page 127: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

Page 128: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

What is the formal definition of reflexivity?

∀a ∈ ℤ. a ~ a

Therefore, we'll choose an arbitrary integer a, thengo prove that a ~ a.

Page 129: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

Page 130: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

Page 131: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

Page 132: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

Page 133: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

Page 134: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

Page 135: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

Page 136: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

Page 137: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

Page 138: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

Page 139: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

Page 140: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

What is the formal definition of symmetry?

∀a ∈ ℤ. ∀b ∈ ℤ. (a ~ b → b ~ a)

Therefore, we'll choose arbitrary integers a andb where a ~ b, then prove that b ~ a.

Page 141: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

Page 142: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

Page 143: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

Page 144: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

Page 145: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

Page 146: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a~b and b~c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 147: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a~b and b~c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 148: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a~b and b~c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

What is the formal definition of transitivity?

∀a ∈ ℤ. ∀b ∈ ℤ. ∀c ∈ ℤ. (a ~ b ∧ b ~ c → a ~ c)

Therefore, we'll choose arbitrary integers a, b, and cwhere a ~ b and b ~ c, then prove that a ~ c.

What is the formal definition of transitivity?

∀a ∈ ℤ. ∀b ∈ ℤ. ∀c ∈ ℤ. (a ~ b ∧ b ~ c → a ~ c)

Therefore, we'll choose arbitrary integers a, b, and cwhere a ~ b and b ~ c, then prove that a ~ c.

Page 149: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a~b and b~c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

What is the formal definition of transitivity?

∀a ∈ ℤ. ∀b ∈ ℤ. ∀c ∈ ℤ. (a ~ b ∧ b ~ c → a ~ c)

Therefore, we'll choose arbitrary integers a, b, and cwhere a ~ b and b ~ c, then prove that a ~ c.

What is the formal definition of transitivity?

∀a ∈ ℤ. ∀b ∈ ℤ. ∀c ∈ ℤ. (a ~ b ∧ b ~ c → a ~ c)

Therefore, we'll choose arbitrary integers a, b, and cwhere a ~ b and b ~ c, then prove that a ~ c.

Page 150: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a~b and b~c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

What is the formal definition of transitivity?

∀a ∈ ℤ. ∀b ∈ ℤ. ∀c ∈ ℤ. (a ~ b ∧ b ~ c → a ~ c)

Therefore, we'll choose arbitrary integers a, b, and cwhere a ~ b and b ~ c, then prove that a ~ c.

What is the formal definition of transitivity?

∀a ∈ ℤ. ∀b ∈ ℤ. ∀c ∈ ℤ. (a ~ b ∧ b ~ c → a ~ c)

Therefore, we'll choose arbitrary integers a, b, and cwhere a ~ b and b ~ c, then prove that a ~ c.

Page 151: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a~b and b~c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 152: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a~b and b~c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 153: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 154: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 155: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 156: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 157: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 158: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 159: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

Page 160: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

An Observation

Page 161: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 1: The binary relation ~ is reflexive.

Proof: Consider an arbitrary a ∈ ℤ. We need to prove that a~a. From the definition of the ~ relation, this means that we need to prove that a+a is even.

To see this, notice that a+a = 2a, so the sum a+a can be written as 2k for some integer k (namely, a), so a+a is even. Therefore, a~a holds, as required. ■

The formal definition of reflexivityis given in first-order logic, butthis proof does not contain any

first-order logic symbols!

The formal definition of reflexivityis given in first-order logic, butthis proof does not contain any

first-order logic symbols!

Page 162: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 2: The binary relation ~ is symmetric.

Proof: Consider any integers a and b where a~b.We need to show that b~a.

Since a~b, we know that a+b is even. Becausea+b = b+a, this means that b+a is even. Sinceb+a is even, we know that b~a, as required. ■

The formal definition of symmetryis given in first-order logic, butthis proof does not contain any

first-order logic symbols!

The formal definition of symmetryis given in first-order logic, butthis proof does not contain any

first-order logic symbols!

Page 163: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

a~b if a+b is even

Lemma 3: The binary relation ~ is transitive.

Proof: Consider arbitrary integers a, b and c where a~b andb~c. We need to prove that a~c, meaning that we need toshow that a+c is even.

Since a~b and b~c, we know that a+b and b+c are even. This means there are integers k and m where a+b = 2k and b+c = 2m. Notice that

(a+b) + (b+c) = 2k + 2m.

Rearranging, we see that

a+c + 2b = 2k + 2m,

so

a+c = 2k + 2m – 2b = 2(k+m–b).

So there is an integer r, namely k+m–b, such thata+c = 2r. Thus a+c is even, so a~c, as required. ■

The formal definition of transitivityis given in first-order logic, butthis proof does not contain any

first-order logic symbols!

The formal definition of transitivityis given in first-order logic, butthis proof does not contain any

first-order logic symbols!

Page 164: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

First-Order Logic and Proofs

● First-order logic is an excellent tool for giving formal definitions to key terms.

● While first-order logic guides the structure of proofs, it is exceedingly rare to see first-order logic in written proofs.

● Follow the example of these proofs:● Use the FOL definitions to determine what to assume

and what to prove.● Write the proof in plain English using the conventions

we set up in the first week of the class.● Please, please, please, please, please

internalize the contents of this slide!

Page 165: Binary Relations - web.stanford.eduweb.stanford.edu/class/archive/cs/cs103/cs103.1202/lectures/06/Slides06.pdfOutline for Today Binary Relations Reasoning about connections between

Next Time

● Properties of Equivalence Relations● Why are equivalence relations so useful?

● Proofs on Relations● Proving properties of abstract objects.

● Strict Orders● Representing rankings and requirements.