Download presentation
Presentation is loading. Please wait.
Published byWalter Townsend Modified over 9 years ago
1
Week 15 - Monday
2
What did we talk about last time? Context free grammars
4
Three men in a cafe order food totaling $15 They each contribute $5 to the bill The waiter takes the money to the manager who recognizes the three as friends and asks the waiter to return $5 to the men However, the waiter is dishonest Instead of splitting the $5 evenly (and who would get the last penny, anyway?), he simply gives each man $1 and pockets the remaining $2 Now, each diner effectively paid $4 Thus, the amount paid is $12 Add the $2 in the waiter's pocket and the total comes to $14 Where has the other $1 gone from the original $15?
6
The following is a grammar that produces the language of strings of 1s and 0s that end in a 1 S A1S A1 A 1 | 0 | AA | є This language is regular and is equivalent to (0 | 1)* 1 The following is a grammar that produces the language of a k b k where k ≥ 1 (which is not regular) S AS A A ab | aAb
7
Write a grammar that specifies legal nesting of parentheses and braces in Java Don't worry about the stuff that goes inside Write a grammar for legal mathematical expressions in Java using variables and integers, +, -, *, /, and parentheses Write a grammar that corresponds to the same language defined by the regular expression ab* (a | bb) (ba)*
8
As you know, regular languages can be expressed by regular expressions and finite state automata Thus, regular expressions are equal to FSAs in power Context free languages can be expressed by context free grammars There is also a class of automata called pushdown automata that correspond to context free languages
10
To make the PDA for the language 0 k 1 k, k ≥ 1, we have the following: In this case, the notation X/Y means that if X is on the top of the stack, replace it with Y The top of the stack is Z Notation is not well standardized for PDAs It's awkward keeping track of the stack s1s1 s1s1 s2s2 s2s2 s0s0 s0s0 0: Z/AZ 0: A/AA 1: A/ε 1: A/A 1: Z/Z
12
Noam Chomsky is a brilliant linguist who has recently focused mostly on political activism Remember that a grammar consists of terminals (alphabet symbols), non-terminals, production rules, and a start symbol He noted that grammars can be divided into four levels in terms of expressiveness: Type-0 (Unrestricted grammars) Type-1 (Context sensitive grammars) Type-2 (Context free grammars) Type-3 (Regular grammars)
13
Each grammar has rules for what is a legal production rule Let α, β, and γ be any combinations of terminals and non- terminals, where γ is non-empty Unrestricted grammars α β (anything to anything) Context-sensitive grammars αAβ αγβ (non-terminal in a particular context to anything) Context-free grammars A γ (a single non-terminal to anything) Regular grammars A a and A aB (a single non-terminal to a single terminal or a terminal and a single non-terminal on the right side)
14
Every kind of language has a particular kind of machine associated with it GrammarLanguagesAutomaton Production Rules Examples Type-0 Recursively enumerable Turing machine α βα β All languages, any computable functions Type-1 Context- sensitive Linear-bounded non- deterministic Turing machine αAβ αγβ Most natural human languages Type-2Context-free Non-deterministic pushdown automaton A γ Most programming languages Type-3RegularFinite state automaton A a and A aB Regular expressions
15
Each set of languages in the hierarchy strictly contains the sets beneath it Regular languages Can be accepted by nondeterministic or deterministic finite automata (or a read-0nly Turing machine) Are closed under union, intersection, complement, concatenation, and Kleene star Context-free languages Are defined by those languages accepted by nondeterministic pushdown automata Are closed under union, concatenation, and Kleene star (but not under intersection or complement) Deciding whether a string is in a context-free language can be determined in polynomial time Deciding whether a language is empty is decidable Context-sensitive languages Are very rarely used Are closed under union, intersection, complement, and Kleene star Deciding whether a string is in a context-sensitive language is a PSPACE-complete problem Recursively enumerable Context- sensitive Context-free Regular
16
A Turing machine is a mathematical model for computation It consists of a head, an infinitely long tape, a set of possible states, and an alphabet of characters that can be written on the tape A list of rules saying what it should write and should it move left or right given the current symbol and state 1011110000 A A
17
You can specify a Turing machine with a table giving its behavior for a specific configuration Turing's first example machine printed an infinite sequence of alternating 1s and 0s, separated by spaces: ConfigurationBehavior StateSymbolOperationResult State BBlankWrite 0, Move RightC CBlankMove RightE EBlankWrite 1, Move RightF FBlankMove RightB
18
If an algorithm exists, a Turing machine can perform that algorithm In essence, a Turing machine is the most powerful model we have of computation Power, in this sense, means the ability to compute some function, not the speed associated with its computation Do you own a Turing machine?
19
Given a Turing machine and input x, does it reach the halt state? As you know, there is no algorithm to determine this If you had a Turing machine that could solve the halting problem, it would cause a logical contradiction
20
Are two context-free languages the same? Is the intersection of two context-free languages empty? Is a context-free language equal to Σ * Is a context-free language a subset of another context-free language? Post correspondence problem: You have lists a 1, a 2, … a n and b 1, b 2, … b n, where a i and b j are strings of some alphabet Σ with at least 2 symbols Is there a value k ≥ 1 such that some sequence of k strings from the a list concatenated is equal to some sequence of k strings from the b list concatenated? Is a given statement of first-order logic provable from a starting set of axioms? Given a set of matrices, is there some sequence that they can be multiplied in (perhaps with repetitions) that will yield the zero matrix?
22
Statements AND, OR, NOT, IMPLIES Truth tables Logical equivalence De Morgan's laws Tautologies and contradictions
23
NameLawDual Commutative p q q pp q q pp q q pp q q p Associative (p q) r p (q r)(p q) r p (q r) Distributive p (q r) (p q) (p r)p (q r) (p q) (p r) Identity p t pp c p Negation p ~p tp ~p c Double Negative ~(~p) p Idempotent p p pp p pp p pp p p Universal Bound p t tp t tp c c De Morgan’s ~(p q) ~p ~q~(p q) ~p ~q Absorption p (p q) pp (p q) p Negations of t and c ~t c~t c~c t~c t
24
Can be used to write an if-then statement Contrapositive is logically equivalent Inverse and converse are not (though they are logically equivalent to each other) Biconditional: p q q pp q q p
25
A series of premises and a conclusion Using the premises and rules of inference, an argument is valid if and only if you can show the conclusion Rules of inference: Modus Ponens Modus Tollens Generalization Specialization Conjunction Elimination Transitivity Division into cases Contradiction rule
26
Show that the following is a valid argument ~p ˅ q → r s ˅ ~q ~t~t p → tp → t ~p ˄ r → ~s ∴ ~q
27
The following gates have the same function as the logical operators with the same names: NOT gate: AND gate: OR gate:
28
Make a truth table for: ~(q → r) ˅ (s ˄ p) ↔ (p ˅ r) Make a digital logic circuit for the same expression
30
A predicate is a sentence with a fixed number of variables that becomes a statement when specific values are substituted for to the variables The domain gives all the possible values that can be substituted The truth set of a predicate P(x) are those elements of the domain that make P(x) true when they are substituted
31
We will frequently be referring to various sets of numbers in this class Some typical notation used for these sets: Some authors use Z + to refer to non-negative integers and only N for the natural numbers SymbolSetExamples RReal numbersVirtually everything ZIntegers{…, -2, -1, 0, 1, 2,…} Z-Z- Negative integers{-1, -2, -3, …} Z+Z+ Positive integers{1, 2, 3, …} NNatural numbers{1, 2, 3, …} QRational numbers a/b where a,b Z and b 0
32
The universal quantifier means “for all” The statement “All DJ’s are mad ill” can be written more formally as: x D, M(x) Where D is the set of DJ’s and M(x) denotes that x is mad ill The universal quantifier means “there exists” The statement “Some emcee can bust a rhyme” can be written more formally as: y E, B(y) Where E is the set of emcees and B(y) denotes that y can bust a rhyme
33
When doing a negation, negate the predicate and change the universal quantifier to existential or vice versa Formally: ~( x, P(x)) x, ~P(x) ~( x, P(x)) x, ~P(x) Thus, the negation of "Every dragon breathes fire" is "There is one dragon that does not breathe fire"
34
Any statement with a universal quantifier whose domain is the empty set is vacuously true When we talk about "all things" and there's nothing there, we can say anything we want "All mythological creatures are real." Every single one of the (of which there are none) is real
35
Recall: Statement: p q Contrapositive:~q ~p Converse:q p Inverse:~p ~q These can be extended to universal statements: Statement: x, P(x) Q(x) Contrapositive: x, ~Q(x) ~P(x) Converse: x, Q(x) P(x) Inverse: x, ~P(x) ~Q(x) Similar properties relating a statement equating a statement to its contrapositive (but not to its converse and inverse) apply
36
p is a sufficient condition for q means p q p is a necessary condition for q means q p These come over into universal conditional statements as well: x, P(x) is a sufficient condition for Q(x) means x, P(x) Q(x) x, P(x) is a necessary condition for Q(x) means x, Q(x) P(x)
37
With multiple quantifiers, we imagine that corresponding “actions” happen in the same order as the quantifiers The action for x A is something like, “pick any x from A you want” Since a “for all” must work on everything, it doesn’t matter which you pick The action for y B is something like, “find some y from B” Since a “there exists” only needs one to work, you should try to find the one that matches
38
For negation, Simply switch every to and every to Then negate the predicate Changing the order of quantifiers can change the truth of the whole statement but does not always Furthermore, quantifiers of the same type are commutative: You can reorder a sequence of quantifiers however you want The same goes for Once they start overlapping, however, you can’t be sure anymore
39
Use a statement of predicate logic to write the following statement: "There is a person who can take every sad song and make it better" Now negate the statement and read back the equivalent informal version Rewrite the following without negations outside the predicates: ∼ ( ∀ x ∈ D, ∀ y ∈ E, P(x, y)))
40
Universal instantiation: If a property is true for everything in a domain (universal quantifier), it is true for any specific thing in the domain Universal modus ponens: x, P(x) Q(x) P(a) for some particular a Q(a)Q(a) Universal modus tollens: x, P(x) Q(x) ~Q(a) for some particular a ~P(a)
42
To prove x D P(x) we need to find at least one element of D that makes P(x) true To disprove x D, P(x) Q(x), we need to find an x that makes P(x) true and Q(x) false
43
If the domain is finite, we can use the method of exhaustion, by simply trying every element Otherwise, we can use a direct proof 1. Express the statement to be proved in the form x D, if P(x) then Q(x) 2. Suppose that x is some specific (but arbitrarily chosen) element of D for which P(x) is true 3. Show that the conclusion Q(x) is true by using definitions, other theorems, and the rules for logical inference Direct proofs should start with the word Proof, end with the word QED, and have a justification next to every step in the argument For proofs with cases, number each case clearly and show that you have proved the conclusion for all possible cases
44
If n is an integer, then: n is even k Z n = 2k n is odd k Z n = 2k + 1 If n is an integer where n > 1, then: n is prime r Z +, s Z +, if n = r s, then r = 1 or s = 1 n is composite r Z +, s Z + n = r s and r 1 and s 1 r is rational a, b Z r = a/b and b 0 For n, d Z, n is divisible by d k Z n = dk For any real number x, the floor of x, written x , is defined as follows: x = the unique integer n such that n ≤ x < n + 1 For any real number x, the ceiling of x, written x , is defined as follows: x = the unique integer n such that n – 1 < x ≤ n
45
Unique factorization theorem: For any integer n > 1, there exist a positive integer k, distinct prime numbers p 1, p 2, …, p k, and positive integers e 1, e 2, …, e k such that Quotient remainder theorem: For any integer n and any positive integer d, there exist unique integers q and r such that n = dq + r and 0 ≤ r < d
46
Prove or disprove the following statements: For all integers a, b, and c, if a | b and a | c then a | (2b − 3c) For all integers a, b, and c, if a | (b + c) then a | b or a | c Use the quotient-remainder theorem with d = 3 to prove that the square of any integer has the form 3k or 3k + 1 for some integer k
48
In a proof by contradiction, you begin by assuming the negation of the conclusion Then, you show that doing so leads to a logical impossibility Thus, the assumption must be false and the conclusion true
49
A proof by contradiction is different from a direct proof because you are trying to get to a point where things don't make sense You should always mark such proofs clearly Start your proof with the words Proof by contradiction Write Negation of conclusion as the justification for the negated conclusion Clearly mark the line when you have both p and ~p as a contradiction Finally, state the conclusion with its justification as the contradiction found before
50
Use a proof by contradiction to prove the following: For all integers n, if n 2 is odd then n is odd For all prime numbers a, b, and c, a 2 + b 2 ≠ c 2
52
Mathematical sequences can be represented in expanded form or with explicit formulas Examples: 2, 5, 10, 17, 26, … a i = i 2 + 1, i ≥ 1 Summation notation is used to describe a summation of some part of a series Product notation is used to describe a product of some part of a series
53
To prove a statement of the following form: n Z, where n a, property P(n) is true Use the following steps: 1. Basis Step: Show that the property is true for P(a) 2. Induction Step: ▪ Suppose that the property is true for some n = k, where k Z, k a ▪ Now, show that, with that assumption, the property is also true for k + 1
55
Using recursive definitions to generate sequences Writing a recursive definition based on a sequence Using mathematical induction to show that a recursive definition and an explicit definition are equivalent
56
Expand the recursion repeatedly without combining like terms Find a pattern in the expansions When appropriate, employ formulas to simplify the pattern Geometric series: 1 + r + r 2 + … + r n = (r n+1 – 1)/(r – 1) Arithmetic series: 1 + 2 + 3 + … + n = n(n+ 1)/2
57
Use the method of iteration to find an explicit formula for the following recursively defined sequence: d k = 2d k−1 + 3, for all integers k ≥ 2 d 1 = 2 Use a proof by induction to show that your explicit formula is correct
58
To solve sequence a k = Aa k-1 + Ba k-2 Find its characteristic equation t 2 – At – B = 0 If the equation has two distinct roots r and s Substitute a 0 and a 1 into a n = Cr n + Ds n to find C and D If the equation has a single root r Substitute a 0 and a 1 into a n = Cr n + Dnr n to find C and D
59
Find an explicit formula for the following: r k = 2r k-1 − r k-2, for all integers k ≥ 2 r 0 = 1 r 1 = 4
62
Review second third of the course
63
Review chapters 6 - 9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.