class: center, middle # CS-3110: Formal Languages and Automata ## Math Review ### Chapter 1 + 2 --- class: center, middle # Example 1: Direct Proof --- # Problem: De Morgan's laws for sets Given: * The definitions of the set operations from last lecture, and the laws of predicate logic * Two sets A and B Show that: $$ \overline{A \cup B} = \overline{A} \cap \overline{B}\\\\ \overline{A \cap B} = \overline{A} \cup \overline{B} $$ --- # Some Notation Remember: Two sets are equal if they have the same elements $$ A = B \equiv x \in A \leftrightarrow x \in B $$ Additionally, our set-builder notation is really just shorthand: $$ y \in \\{x | P(x)\\} \equiv P(y) $$ Also recall De Morgan's laws for logic: $$ \neg (a \wedge b) \leftrightarrow (\neg a) \vee (\neg b)\\\\ \neg (a \vee b) \leftrightarrow (\neg a) \wedge (\neg b) $$ --- # With our new notation What we want to show is: $$ \overline{A \cup B} = \overline{A} \cap \overline{B} $$ Which is exactly the same as: $$ \forall y: y\in \overline{A \cup B} \leftrightarrow y\in (\overline{A} \cap \overline{B}) $$ For a direct proof, we start with the left side and then show that we can get to the right side by applying equivalence transformations (logical equivalences and notational equalities) --- # A direct proof For all y: $$\begin{aligned} y \in \overline{A \cup B}\:\leftrightarrow&\: y \in \\{x | \neg x \in (A \cup B) \\}\\\\ \leftrightarrow&\: \neg y \in (A \cup B) \\\\ \leftrightarrow&\: \neg y \in \\{x | x\in A \vee x \in B\\}\\\\ \leftrightarrow&\: \neg (y \in A \vee y \in B)\\\\ \leftrightarrow&\: (\neg y \in A) \wedge (\neg y \in B)\\\\ \leftrightarrow&\: (y \in \\{x | \neg x\in A\\}) \wedge (y \in \\{x | \neg x \in B\\}\\\\ \leftrightarrow&\: y \in \overline{A} \wedge y \in \overline{B}\\\\ \leftrightarrow&\: y \in \\{x | x \in \overline{A} \wedge \overline{B}\\}\\\\ \leftrightarrow&\: y \in (\overline{A} \cap \overline{B}) \end{aligned} $$ --- # A direct proof We usually skip some of the more tedious rewriting. For all y: $$\begin{aligned} y \in \overline{A \cup B}\:\leftrightarrow&\: \neg y \in (A \cup B) \\\\ \leftrightarrow&\: \neg (y \in A \vee y \in B)\\\\ \leftrightarrow&\: (\neg y \in A) \wedge (\neg y \in B)\\\\ \leftrightarrow&\: y \in \overline{A} \wedge y \in \overline{B}\\\\ \leftrightarrow&\: y \in (\overline{A} \cap \overline{B}) \end{aligned} $$ --- class: center, middle # Example 2: Induction Proof --- # Problem: Generalized DeMorgan's law Given: * Set operations, as before, plus the proof from example 1 * n (but at least 2) sets `\(A_1, A_2, \ldots A_n\)` Show that: $$ \overline{A_1 \cup A_2 \cup \cdots \cup A_n} = \overline{A_1} \cap \overline{A_2} \cap \cdots \cap \overline{A_n}\\\\ \overline{A_1 \cap A_2 \cap \cdots \cap A_n} = \overline{A_1} \cup \overline{A_2} \cup \cdots \cup \overline{A_n} $$ --- # Induction Proof An induction proof needs 2 "ingredients": * A base case: Our statement holds for some small/fixed number * A step: We can show that if our statement holds for (any) n, it also holds for n+1 Once we have shown these two things, we can conclude that our statement holds for any n: For a given n, start at the base case, and then apply the step as often as is necessary to reach that n. --- # Induction Proof Base case: We have two sets $$ \overline{A_1 \cup A_2} = \overline{A_1} \cap \overline{A_2} $$ How do we show this? -- We just did, in example 1. If, say, the homework does not have such an "example 1", you'd insert a proof here, using your favorite technique (and yes, nested induction proofs are a thing). --- # Induction Step Now we need to show that for **any** n we can take $$ \overline{A_1 \cup A_2 \cup \cdots \cup A_n} = \overline{A_1} \cap \overline{A_2} \cap \cdots \cap \overline{A_n} $$ to conclude
This means: We can **use** the case for n **as an additional premise**! --- # Induction Step Now we actually show the step:
--- class: middle
--- class: medium # Induction Proof Application Say we have 37 sets. We can show that DeMorgan's laws hold for these 37 sets: * We know (from example 1) that it works with 2 sets * We apply the induction step proof once: We know it also works with 3 sets * We apply the induction step proof another time: We know it works with 4 sets * ... * We apply the induction step proof another time: We know it works with 37 sets --- # Induction Proof * But what if we have more (or fewer?) than 37 sets? * We could still use the same procedure! * The induction proof **shows** that the step works * And that the base case holds * In other words: The proof itself needs to work for **any** n, and must not be a simple enumeration of steps (which may break!) --- class: mathmedium # Never trust patterns! $$ \int_0^\infty 2\cos(x)dx = \pi\\\\ \int_0^\infty 2\cos(x) \frac{\sin(x)}{x} dx = \pi\\\\ \int_0^\infty 2\cos(x) \frac{\sin(x)}{x}\frac{\sin(x/3)}{x/3} dx = \pi\\\\ \int_0^\infty 2\cos(x) \frac{\sin(x)}{x}\frac{\sin(x/3)}{x/3} \frac{\sin(x/5)}{x/5}dx = \pi\\\\ \vdots $$ --- class: mathmedium # Never trust patterns! $$ \int_0^\infty 2\cos(x)dx = \pi\\\\ \int_0^\infty 2\cos(x) \frac{\sin(x)}{x} dx = \pi\\\\ \int_0^\infty 2\cos(x) \frac{\sin(x)}{x}\frac{\sin(x/3)}{x/3} dx = \pi\\\\ \int_0^\infty 2\cos(x) \frac{\sin(x)}{x}\frac{\sin(x/3)}{x/3} \frac{\sin(x/5)}{x/5}dx = \pi\\\\ \vdots\\\\ \int_0^\infty 2\cos(x) \frac{\sin(x)}{x}\frac{\sin(x/3)}{x/3} \frac{\sin(x/5)}{x/5}\cdots \frac{\sin(x/113)}{x/113} dx < \pi\\ $$ [Borwein Integrals](https://www.youtube.com/watch?v=851U557j6HE) --- class: center, middle # Example 3: Proof By Contradiction --- class: medium # Problem: Infinitely Many Primes Given (premises): * The usual laws for integer arithmetic and sets * A prime number is a number p with exactly two proper divisors: 1 and p * There exists at least one prime number, and the smallest prime number is 2 Show that: * There are infinitely many prime numbers * Use a proof by contradiction --- # Negation of the Conclusion To prove by contradiction, we first start with negating the conclusion: Let us assume that there are only finitely many prime numbers. In fact, let us name and order them all: $$ p_1 \lt p_2 \lt p_3 \lt \ldots \lt p_n $$ Where $$ p_1 = 2 $$ --- class: mmmedium # A new number Let us look at this number: $$ N = p_1 \cdot p_2 \cdot p_3 \cdots p_n + 1 $$ Some things we "know": * N is larger than all of our prime numbers, because the smallest number in our product is 2, and we add 1 to the result * N is not a prime number (because we said we have named **all** prime numbers) * Therefore, N must be divisible by one of our prime numbers (You may have seen this proof before, with some "handwaving" here that obviously N can't be divisible by any of the primes we have) --- # Dividing N First, observe that this product is, by definition, also divisible by each of our prime numbers: $$ p_1 \cdot p_2 \cdot p_3 \cdots p_n $$ With the knowledge that N must be divisible by some `\(p_i\)`: $$ p_i | N \equiv N = k \cdot p_i\\\\ p_i | p_1 \cdot p_2 \cdot p_3 \cdots p_n \equiv p_1 \cdot p_2 \cdot p_3 \cdots p_n = j \cdot p_i $$ $$ N - p_1 \cdot p_2 \cdot p_3 \cdots p_n = k \cdot p_i - j \cdot p_i\\\\ p_1 \cdot p_2 \cdot p_3 \cdots p_n + 1 - p_1 \cdot p_2 \cdot p_3 \cdots p_n = k \cdot p_i - j \cdot p_i\\\\ 1 = (k-j) \cdot p_i \equiv p_i | 1 $$ --- # Dividing 1 * We have concluded that the same prime number that divides N also divides 1 * The smallest prime number is 2 * This means we would have some number greater or equal to 2 that divides 1 * But such a number does not exist .... We have reached a contradiction --- # Evaluating our assumption * We started with assuming that there only finitely many prime numbers * After this assumption we have only used our given premises * But we reached a contradiction * This means that our assumption must be wrong, and there must indeed be **infinitely many** prime numbers QED --- class: center, middle # Example 4: Proof By Contrapositive --- # Proof By Contrapositive Given (premises): * The usual laws for integer arithmetic and sets * We call an integer n **even** iff there is an integer k, such that n=2k * We call an integer n **not even** (or "odd") iff there is an integer k such that n=2k+1 Show that: * If `\(n^2\)` is even, then n is even * Use a proof by contrapositive --- # Proof by Contrapositive * A proof by contrapositive is a weird beast * We can only use it to show something of the form "if p then q" * And we do this by showing "If not q, then not p" * And we (usually) do **that** by using "not q" as an additional premise, and showing "not p" using a direct proof --- # Proof by Contrapositive To show: ### If `\(n^2\)` is even, then n is even The contrapositive is: ### If n is not even, then `\(n^2\)` is not even We show this by starting with an n that is not even and manipulating it. --- # The Proof $$ \begin{aligned} n =&\: 2k+1\\\\ n^2 = n\cdot n =&\: (2k+1)\cdot(2k +1)\\\\ =&\: 4k^2 + 4k + 1\\\\ =&\: 2(2k^2 + 2k) + 1\\\\ =&\: 2k_1 + 1 \end{aligned} $$ This new `\(k_1\)` surely is an integer (we got it from adding and multiplying integers), so there is a "k" such that our `\(n^2 = 2k_1 + 1\)` which means that it is not even. --- class: medium # Proofs and Implications * Note: We started with "n = 2k+1" **as an additional premise** * Anything we proved from there is a **consequence** of this premise * This is how we got the implication we needed ("if n is not even, then `\(n^2\)` is not even") * In fact, *every* proof is an "implication": From the premises follow the conclusions * If we **only** use equivalences and equalities, the "implication" goes in both directions, and becomes another equivalence (see example 1) --- # Proofs * Proofs require practice and patience * You may not always see what the path to the solution may be * Sometimes it helps to re-examine all the givens, and see which ones have yet to be used * The proof method also sometimes gives you a clue what to do (for induction proofs, you have to use the statement for the n-case somewhere)