Computer Science 202 Lecture Summaries, Fall 2018


[Home]
8/30

Discussion of the syllabus, the role of the class in the Computer Science major, comparison with Math 244. The first problem set is available.

Two problems from Smullyan's "Island of Knights and Knaves". In the first, A says "We are both knights." and B says "No, we're not!". Because these two statements contradict each other, they cannot both be true, so it is not the case that both A and B are knights. Then because what A says is false, A must be a knave, making what B says true. Therefore, B is a knight. In the second problem, A says "Exactly one of us is a knave.", B says "At least one of us is a knight.' and C says "None of us is a knave." We found exactly three assignments of types (knight or knave) to A, B, and C in which these three statements would be possible.

Egyptian unit fractions. From "the world's oldest extant algorithms textbook" (the Rhind or Ahmose papyrus) comes a representation of fractions using a finite sum of distinct unit fractions, where a unit fraction is 1 divided by a positive integer. For example, 3/4 = 1/2 + 1/4. To express 2/7 in this form, we find the largest unit fraction less than 2/7, namely 1/4, and subtract it from 2/7 to get 1/28. Thus, 2/7 = 1/4 + 1/28. We get a "greedy" algorithm: subtract the largest unit fraction less than the target, repeating as necessary. For example, for 3/7, the largest unit fraction less than 3/7 is 1/3, and 3/7 - 1/3 = 9/21 - 7/21 = 2/21. Repeating, the largest unit fraction less than 2/21 is 1/11 (why?) and subtracting 1/11 from 2/21 gives 1/231, so 3/7 = 1/3 + 1/11 + 1/231.

Question: will this greedy algorithm eventually terminate for any input fraction p/q (in lowest terms) strictly between 0 and 1? Why or why not?

9/4

Mathematical Logic I. Some uses of logic in computer science: specifying, designing and verifying the correctness of computer hardware and software, representing knowledge and reasoning in artificial intelligence, and formalizing mathematical arguments. We'll consider two main divisions: Propositional Logic and Predicate Logic.

Propositional Logic. Inductive definition of propositional formulas using logical operations of not, and, or, exclusive or, implication and biconditional (including their order of operations.) Construction of truth tables for propositional formulas. Tautologies, contradictions and contingencies, logical equivalence of propositional formulas.

9/6

Mathematical Logic II. Propositional Logic, continued. Examples of logical equivalences verified using a truth table. (See Tables 2.2 and 2.3 in the text for many examples.) Example of using logical equivalences to show that (((not q) and (p implies q)) implies (not p)) is a tautology. Definitions of conjunctive and disjunctive normal forms (CNF and DNF) and an example of putting the formula ((not (p and q)) implies (not (p or r))) into CNF. One place that CNF used is in resolution theorem proving.

Predicate Logic. Example of translating the argument: 1. All humans are mortal, 2. Socrates is human, 3. Socrates is mortal, into formulas in the predicate logic, using the "for all" quantifier (upside-down A), a variable x standing for a member of the domain, predicate symbols H and M, where H(x) is the assertion "x is human" and M(x) is the assertion "x is mortal", and the constant s (for the individual member Socrates of the domain.) Translations: 1. (for all x)(H(x) implies M(x)), 2. H(s), 3. M(s).

We can argue from the premises (1 and 2) to the conclusion (3) using rules of inference as follows. From (1) by Universal Instantiation we get (H(s) implies M(s)) (removing the universal (for all) quantifier and substituting s for x everywhere). Then using (2) and (H(s) implies M(s)) we get M(s) by "Modus Ponens" (the rule that if we have p and (p implies q) then we can conclude q.)

It's important to note that this argument is valid simply because of its form. This doesn't depend at all on the semantics of humanity, mortality or Socrates. See the text for more rules of logical inference.

9/11

Mathematical Logic III. Predicate Logic, continued. The signature of a predicate logic language specifies the symbols used for constants, functions, and predicates, together with how many arguments the function and predicate symbols take (their "arity"). Given a signature and a set of variables, we define the set of terms and the set of predicate logic formulas (PLFs) inductively as follows.

Terms. The base case: every constant symbol and variable is a term. The inductive case: if t1, t2, ..., tk are terms and f is a function symbol of arity k, then f(t1,t2,...,tk) is a term.

Atomic formulas: If t1,t2,...,tk are terms and P is a predicate symbol of arity k, then P(t1,t2,...,tk) is an atomic formula.

Predicate logic formulas (PLFs). The base case: every atomic formula is a PLF. If F and G are PLFs, then so are not(F), (F or G), (F exclusive-or G), (F and G), (F implies G) and (F if-and-only-if G) (where these logical operations have the same symbols as in the propositional logic) Aslo, forall x : (F) and exists x: (F) are PLFs, where x is any variable (and the symbol for "forall" is an upside-down A and the symbol for "exists" is a backwards E.)

These definitions give the legal syntax (grammar) for predicate logic formulas. There is a corresponding inductive definition of the semantics (meaning) of predicate logic formulas, but we will not cover it formally. Definition and examples of free and bound occurrences of variables in a PLF, and the definition of a closed formula (no free occurrences of variables.)

Definition of a "possible world", or structure for a signature, which involves specifying a set of objects (the universe) and for each constant symbol, which object it denotes, for each function symbol, which function from k-tuples of objects to objects it denotes, and for each predicate symbol, which k-ary relation on objects it denotes. Every closed PLF has a truth value in every structure for the signature.

The examples in lecture gave an extension of the signature and structure used in homework problem #5, and examples of formulas, free and bound occurrences of variables and the truth values of closed PLFs for that signature and structure.

9/13

Mathematical Logic IV: Mathematical Proof. Rules of inference allow us to derive new truths from old. It is important that they be sound: for any possible world in which the premises are true, the conclusion must be true. Otherwise, we could derive a contradiction, from which every other statement would follow, making our "proofs" meaningless. "Sound" means everything provable is true. The converse (everything true is provable) is a property called "complete" -- which is attainable for some (usually limited) theories. An important property of rules of inference is that they should be efficiently checkable, so that, presented with a purported proof of conclusion Q from premises P1, P2, ..., Pk, we can efficiently check that all the rules of inference were correctly applied. By contrast, *finding* a proof is a search problem, with no generally efficient algorithm to solve it. The proof techniques (heuristics to guide your search for a proof) in the text's Table 2.6 are worth studying.

A (tiny) sample proof in the propositional logic: From the premises (A -> B and C) and A we can derive the conclusion B.

	1. A -> (B and C) Premise
	2. A              Premise
	3. B and C        From 1,2 via Modus Ponens (see 2.4)
	4. B              From 3 via Simplification (see 2.4)
      

We can introduce valid statements (true in every possible world, like (A or (not A))) and axioms on any line of a proof. Axioms are statements that we've made up to try to capture a certain kind of mathematical object. As an example, Chapter 4 of the text has a collection of axioms for the real numbers. We hope the axioms are true of what we mean by the real numbers, and that they allow us to prove interesting lemmas and theorems about the real numbers. A sample axiom from Chapter 4 is Axiom 4.2.4: If a is less than or equal to b then (a+c) is less than or equal to (b+c).

We observed the generalization of DeMorgan's laws to quantifiers: (not (forall x (P(x)))) is logically equivalent to (exists x (not (P(x)))), and (not (exists x (P(x)))) is logically equivalent to (forall x (not (P(x)))). We also observed the logical INEQUIVALENCE of the two statements (forall x (exists y (P(x,y)))) and (exists y (forall x (P(x,y)))). To see that they are logically inequivalent, it is sufficient to find one structure in which their truth values differ, for example, let the universe be all real numbers and let P(x,y) mean that x is less than y. The first statement then says for every real number x, there is a greater real number y, which is true. The second statement says that there exists a real number y that is greater than every real number x, which is false.

We looked at the inference rules for quantifiers: Universal Instantiation (UI), Universal Generalization (UG), Existential Generalization (EG), and Existential Instantiation (EI) -- see the text for details.

Finally, we saw an informal mathematical proof of the lemma that if s divides m and s divides n, then s divides (m+n). That, and a corresponding "formal" proof will be presented in a separate document.

9/18

Set Theory I. Relevance to computer science: mathematical objects used in computer science, e.g., numbers, functions, relations, graphs, automata, etc. are generally defined in terms of sets. A basic knowledge of set notation and operations is assumed in many Computer Science courses. Sets are a basic data type for constructing mathematical objects. Chapter 3 explains two approaches to formalizing sets: naive set theory (used by most non-logicians) and axiomatic set theory (devised by logicians to avoid certain paradoxes that arise in naive set theory.)

A set (intuitively) is a collection of objects (or elements), in which order and multiplicity are ignored. The elements of sets may themselves be sets. We may use set braces {, } and an explicit list of elements separated by commas to specify a set. The empty set, the unique set with no elements, can be written {}. The set {1, 4, 9} has three elements, the squares of the first three positive integers. The set {{},{1,3},9,15} has four elements: the empty set {}, the set {1,3}, the number 9, and the number 15. The set of natural numbers is {0, 1, 2, 3, ...}.

Set membership. The axiomatic treatment of sets uses just one non-logical symbol, a variety of the Greek letter epsilon, to stand for a binary relation: x is an element of S. A fundamental axiom for sets is the extensionality axiom, which is formalized (in Section 3.4) as (forall x)(forall y)((x = y) iff (forall z)((z in x) iff (z in y))). This says that two sets x and y are the same set if and only if for all z, z is an element of x if and only if z is an element of y.

Examples of set membership. {} is an element of {{}, {1,3}, 9, 15} as are {1,3}, 9 and 15. However, 1 is not an element of {{}, {1,3}, 9, 15}, though it is an element of {1,3}.

Another way to construct sets: set comprehension and set builder notation. Starting with a set S, we can construct the set of all elements that satisfy some property (that is, make some predicate true). Thus, {x | P(x)} is the set of all elements x such that P is true of x. As an example, if N is the set of natural numbers then {x | x is an element of N and x is less than 5} = {0, 1, 2, 3, 4}.

Unrestricted use of set comprehension leads to Russell's paradox. Define T to be the set of all sets S such that S is not an element of S. Then we ask whether T is an element of T? If so, the T does not satisfy the criterion to be in T, so T is not an element of T. If not, then T does satisfy the criterion to be in T, so T is an element of T. Thus we get the contradiction that T is an element of T if and only if T is not an element of T. The axiomatic treatment of set theory is designed to avoid this contradiction by carefully prescribing the kinds of things we can do to construct sets (see Section 3.4).

Set operations: the union, intersection, and set difference of two sets with their symbols and Venn diagrams illustrating them.

A relation between sets: A is a subset of B if and only if for all x, if x is an element of A then x is an element of B. Symbol and Venn diagrams for this. Note that A = B iff A is a subset of B and B is a subset of A. Also note that for all sets A, the empty set is a subset of A, and A is a subset of itself. Extended example illustrating the difference between "is an element of" and "is a subset of".

Lemma: A = (A intersection B) union (A set difference B). (Please see the proof by cases in Chapter 3 for an example of how we prove things about sets.)

The power set of a set A, denoted P(A), is the set of all subsets of A. As an example, if A = {1, 4, 9} then P(A) = {{}, {1}, {4}, {9}, {1,4}, {4,9}, {1,9}, {1,4,9}}. Note that if A has n elements, P(A) has 2^n elements, so in this case, P(P(A)) would have 2^8 = 256 elements.

Constructing the natural numbers. We can define the natural numbers as certain sets, as follows. We take 0 to be the empty set {}, with 0 elements. We take 1 to be the set {0}, that is, {{}}, with 1 element -- the empty set {} is the one and only element of the set {{}}. We take 2 to be the set {0,1}, that is, {{}, {{}}}, with 2 elements. We take 3 to be the set {0, 1, 2}, that is, {{}, {{}}, {{}, {{}}}}, with 3 elements. In general, if n is the set {0, 1, ..., n-1} then n+1 is just the set (n union {n}), which has the elements {0, 1, ..., n}. Note that n is always a set of n elements, and that the operation (X union {X}) is the way we can go from n to n+1 -- the "successor" operation. We normally don't think about the natural numbers this way, but the axioms of set theory let us construct the natural numbers literally from "nothing" (well, {}).

Ordered pairs. Sets are indifferent to order, so {1,2} = {2,1}, because all that matters is they have the same elements. For ordered pairs, we care about order: the key property of the ordered pair (a,b) is that (a,b) = (c,d) if and only if a=c and b=d. We can use sets (surprise!) to construct ordered pairs. Kuratowski's definition of (1,2) is {{1},{1,2}}, and the definition of (2,1) is {{2}, {1,2}}. Note that these are different sets, because {1} is an element of the first one, but not an element of the second one. Thus, we get (1,2) is not equal to (2,1), as desired. Note that (3,3) comes out to be {{3}}. (Why?)

Once we have ordered pairs, we can define the Cartesian product of two sets A and B as AxB = {(a,b) | a is an element of A and b is an element of B}, that is, the set of all ordered pairs such that the first element of the pair is an element of A and the second element of the pair is an element of B. As an example of Cartesian product, we have {1, 4, 9} x {1, 5} = {(1,1), (1,5), (4,1), (4,5), (9,1), (9,5)}.

9/20

Set Theory II. The proof from the text of (3.3.4): the set A is equal to the union of (A set-difference B) and (A intersect B). Review of ordered pair (a,b) and Cartesian product AxB. The number of elements (ordered pairs) in AxB is the product of the number of elements of A and the number of elements of B. Notation |A| for the cardinality (the number of elements) of the set A.

Definition and example of a binary relation R on sets A and B. The number of binary relations R on sets A and B. The definition of a function with domain A and co-domain B as a binary relation f on A and B that satisfies the condition that for every element a of A, there is exactly one element b in B such that the pair (a,b) is an element of f. Notation: f(a) = the unique b such that (a,b) is an element of f. Notation: f:A -> B denotes a function f with domain A and co-domain B. Examples and non-examples of functions. The number of functions with domain A and co-domain B.

Properties a function f may or may not have: injective (one-to-one), surjective (onto), bijective (a one-to-one correspondence). The function f:A -> B is injective iff for all elements a1 and a2 of A, if a1 is not equal to a2, then f(a1) is not equal to f(a2). f:A -> B is surjective iff for all elements b of B there exists an element a of A such that f(a) = b. f:A->B is bijective iff it is both injective and surjective.

Two (possibly infinite) sets A and B have the same cardinality, that is, |A|=|B|, iff there is a bijection f between A and B. Note that the set of natural numbers and the set of even natural numbers have the same cardinality -- consider the bijection f(n) = 2n mapping the natural numbers to the even naturnal numbers. A set A is finite iff it has the same cardinality as one of the sets representing natural numbers; otherwise, A is infinite. A set is countable iff it is finite or has the same cardinality as the natural numbers. An equivalent definition is that a set is countable iff there is a bijection between it and a subset of the natural numbers. A set that is not countable is uncountable. The set of natural numbers, the set of integers, and the set of rational numbers are all countable; the set of real numbers is uncountable.

9/25

Set Theory III. Some more definitions related to functions: the floor of x (see the text for notation) is the largest integer less than or equal to x; the ceiling of x is the smallest integer greater than or equal to x. (In other words, floor rounds down to an integer and ceiling rounds up to an integer; they both just yield x if x is already an integer.) If f:A -> B and g:B -> C then the composition of g and f (see the text for notation) is the function h:A -> C defined by h(a) = g(f(a)) for all elements a of A. If f:A -> B is a bijection then we define its inverse (see the text for notation) to be the function h:B -> A defined for every element b of B as follows: h(b) is the unique element a of A such that f(a) = b. Note that in this case, the composition of the inverse of f and f is the identity function on A, mapping every element a of A to itself, and the composition of f and the inverse of f is the identity function on B.

The Real Numbers I. In the text, section 3.6 (Constructing the universe), gives a sequence of definitions to build from the natural numbers successively larger sets of numbers: the integers, the rational numbers, and the real numbers. The integers are represented by pairs of natural numbers of the form (n,0) or (0,n), where the first represents the integer n and the second represents the integer -n. The rational numbers are represented by pairs (z,n), where z is an integer and n is a nonzero natural number, and no natural number greater than 1 divides both z and n -- this represents the rational number z/n. The real numbers are represented by sets S of rational numbers such that S is nonempty, S is downward closed, S is not equal to all the rational numbers, and S does not contain an upper bound. A set S is downward closed iff for every element s in S, if x is a rational number such that s > x, then x is also an element of S. A set S contains an upper bound iff there exists an element b in S such that every element of S is less than or equal to b. As an example, the square root of 2 is represented by the set T of all rational numbers x such that x is negative or x^2 is less than 2. (Intuitively, this is all the rational numbers to the left of the square root of 2 on the real line.)

Chapter 4 of the text presents another characterization of the real numbers, by means of axioms. The first 9 axioms characterize an algebraic object called a "field", which contains two different numbers 0 and 1, and operations + and *. The field axioms state commutativity and associativity of both + and *, the fact that 0 is an identity element for + and 1 is an identity element for *, that every number x has an additive inverse -x, that every number except 0 has a multiplicative inverse x^{-1}, and that multiplication distributes over addition. There are many different fields (structures that satisfy these axioms), including the rational numbers, the real numbers, the complex numbers, and the integers modulo a prime p, among others. The real numbers also have a binary relation (less than or equal) that satisfies a second group of axioms. These state the properties of comparability (for all x, y: x is less than or equal to y or y is less than or equal to x), antisymmetry (for all x, y: if x is less than or equal to y and y is less than or equal to x then x = y), transitivity (for all x, y, z: if x is less than or equal to y and y is less than or equal to z then x is less than or equal to z), translation invariance (for all x, y, z: if x is less than or equal to y then (x+z) is less than or equal to (y+z)), and (nonnegative) scaling invariance (for all x, y, z: if 0 is less than or equal to z then (z*x) is less than or equal to (z*y).) (These axioms are useful in reasoning about inequalities.) Both the rational numbers and the real numbers satisfy all these axioms (and are "ordered fields"), but the final axiom, the least upper bound property (every nonempty set S that has an upper bound has a least upper bound) gives the real numbers (a "complete ordered field"). In the construction of the real numbers in Section 3.6, the number x is represented by a set of rational numbers whose least upper bound is x.

A number b is an upper bound for a set S iff every element s of S is less than or equal to b. A number b is a least upper bound for a set S iff b is an upper bound for S and b is less than or equal to any lower bound for S.

We also saw the proof of Lemma 4.1.4 in the text (the additive identity is unique.)

9/27

Proof by Induction I. Explanation of proof by simple induction. Examples of proof by simple induction: (1) for every positive integer n, the sum of the first n positive integers is equal to n(n+1)/2, and (2) for every integer n greater than or equal to 4, n^2 is less than or equal to 2^n. (The latter is proved as Theorem 5.2.1 in the text.)

Explanation of proof by strong induction. Example of proof by strong induction: every integer n greater than 1 is divisible by a prime. (See also the first example in Section 5.5.1 of the text.)

Explanation of proof by structural induction. Example of inductive definition of "complete binary tree expressions" (CBTEs) and formulation of claim that for every CBTE T, the number of L's in T is one more than the number of R's in T. (See also Section 5.6.3 (Structural Induction).)


[Home]
September 30, 2018