1 - Framingham State University
1 - Framingham State University
1 - Framingham State University
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
1. Sets, languages, and models<br />
David M Keil, <strong>Framingham</strong> <strong>State</strong> <strong>University</strong><br />
CSCI 460 Theory of Computing<br />
1. Sets, languages,<br />
and models<br />
1. Countable sets and formal languages<br />
2. Uncountable sets<br />
3. Streams and coinduction<br />
4. Circuit and lookup computation<br />
David Keil Theory of Computing 12/12 1<br />
Inquiry<br />
• Are the sets of natural numbers and<br />
strings of comparable size?<br />
• Are all infinite sets the same size?<br />
• Can we define infinite sets of infinitely<br />
large data streams?<br />
David Keil Theory of Computing 12/12 2<br />
David Keil Theory of computing 6/12
1. Sets, languages, and models<br />
Objectives<br />
1a. Use the notation of formal language<br />
theory*<br />
1b. Describe the logic-circuit model of<br />
computation*<br />
1c. Prove that a set is countable<br />
1d. Prove that a set is uncountable<br />
1e. Explain or write a coinductive definition<br />
David Keil Theory of Computing 12/12 3<br />
How Topic 1 relates to computing<br />
• We show that some problems are<br />
algorithmically unsolvable<br />
• We show a diagonal proof method that is<br />
used again in topic 4<br />
• Computation deals with finite, infinite, and<br />
uncountable objects or sets<br />
• Computations are operations on sets of<br />
strings (languages)<br />
David Keil Theory of Computing 12/12 4<br />
David Keil Theory of computing 6/12
1. Sets, languages, and models<br />
• How big is a set?<br />
• What does countability have to do with<br />
computing?<br />
• How many of the following exist?<br />
– natural numbers<br />
– rational numbers<br />
– real numbers<br />
– functions<br />
– programs<br />
– sets<br />
David Keil Theory of Computing 12/12 5<br />
David Keil Theory of computing 6/12<br />
1. Countable sets and formal languages<br />
Countability<br />
• The natural numbers are countable, i.e.,<br />
they can be arranged in a particular order<br />
• A bijection is a one-to-one correspondence,<br />
i.e., a relation between two sets that is both<br />
surjective and injective<br />
• A set is countable iff there exists a bijection<br />
between it and the natural numbers (ℕ)<br />
• Countable sets tend to be sets of finite<br />
objects, defined inductively<br />
David Keil Theory of Computing 12/12 6
1. Sets, languages, and models<br />
David Keil Theory of computing 6/12<br />
Peano’s axioms: definition by induction<br />
1. 0 is a natural number (0 N)<br />
2. Every natural number n has a unique<br />
successor, n, also a natural number<br />
(n N) n N<br />
3. All natural numbers follow (1) or (2)<br />
(n N) n = 0 (m N) n = m<br />
• Significance: These axioms, or assumptions,<br />
provide a formal logical basis to work with<br />
counting numbers. Note: (2) is recursive<br />
• Computation is a formal way to manipulate<br />
numbers and objects representable by them.<br />
David Keil Theory of Computing 12/12<br />
Theorem: ℕ is infinite<br />
Proof by contradiction:<br />
1. Suppose ℕ is finite<br />
2. Then let n be the largest element of ℕ<br />
3. Consider the number (n + 1). It cannot be in ℕ,<br />
because it is larger than ℕ’s largest element<br />
4. But by definition of ℕ, any successor of an<br />
element of ℕ is in ℕ.<br />
5. Hence by the contradiction of (3) and (4), we<br />
must reject (1).<br />
6. Hence ℕ is infinite.<br />
David Keil Theory of Computing 12/12 8<br />
7
1. Sets, languages, and models<br />
Strings<br />
• Alphabet: a finite set of symbols, e.g.,<br />
{0,1},<br />
{0, 1, …9}, {a, b, c, …, z}<br />
• A string is a sequence of symbols over a<br />
finite alphabet<br />
• Notation:<br />
– x R is the string x reversed<br />
– n 0(x) is the number of zeroes in string x<br />
David Keil Theory of Computing 12/12 9<br />
David Keil Theory of computing 6/12<br />
The set of strings over an alphabet<br />
• * is the set of strings over finite alphabet <br />
• Recursive definition:<br />
– Base: * ( = = null string)<br />
– Recursive: a s * sa *<br />
– Restriction: only objects defined as above<br />
are strings<br />
• In set notation,<br />
* = {} { ax | a , x * }<br />
David Keil Theory of Computing 12/12 10
1. Sets, languages, and models<br />
Str(n) =<br />
A bijection ℕ {0,1}*<br />
if n = 0<br />
Str(n/2) + ‘0’ if Odd(n) n > 0<br />
Str(n/2) + ‘1’ otherwise<br />
Num(s) =<br />
0 if s = <br />
2 Num(s[1 .. |s| - 1]) +<br />
s[|s|] + 1 otherwise<br />
• This bijection is the core of a proof that<br />
{0,1}* is countable<br />
David Keil Theory of Computing 12/12 11<br />
Cardinalities of sets<br />
• Informally, their sizes<br />
• For infinite sets, we say that two sets have<br />
the same cardinality iff there is a bijection<br />
(1-to-1 correspondence) between their<br />
elements<br />
• Example: Card (EVEN) = Card (ℕ)<br />
Proof: EVEN 0 = 0, EVEN 1 = 2, etc.<br />
• Example: Card (ℚ) = Card (ℕ)<br />
Proof: Zig-zag through a table of rationals<br />
David Keil Theory of Computing 12/12 12<br />
David Keil Theory of computing 6/12
1. Sets, languages, and models<br />
David Keil Theory of Computing 12/12 13<br />
David Keil Theory of computing 6/12<br />
Formal languages<br />
• Language: a set of strings over an alphabet<br />
• Languages may be enumerated:<br />
, 0, 1, 00, 01, 10, 11, …<br />
• * is the set of all strings over <br />
• For any language L over , L *<br />
• Inductively, * = {xy | x y * }<br />
Defining languages<br />
• 0 n 1 n is the language of strings with n zeroes<br />
followed by n ones<br />
• Let alphabet be {0,1}, let be the null<br />
string<br />
• Then 0 = {}, 1 = {(0), (1)}<br />
2 = {00, 01, 10, 11}<br />
k = the set of strings of length k<br />
* = U k N k<br />
David Keil Theory of Computing 12/12 14
1. Sets, languages, and models<br />
Operations on languages<br />
• Concatenation (L 1 L 2 ): strings that are a<br />
string in L 1 followed by one in L 2<br />
• L 1 L 2 = {xy | x L 1 y L 2}<br />
• Union (selection, L 1 L 2, L 1 | L 2):<br />
strings either in L 1 or L 2<br />
L 1 L 2 = {x | x L 1 x L 2}<br />
• Intersection (L 1 L 2) strings that are in<br />
both L 1 and L 2<br />
David Keil Theory of Computing 12/12 15<br />
Kleene star languages<br />
• Kleene star (Iteration, L*): strings that are<br />
sequences of strings in L<br />
L * = {xy | x L y L * }<br />
David Keil Theory of computing 6/12<br />
• Alternative definition:<br />
– L 0 = {}, L 1 = L, L 2 = LL, L 3 = LLL, etc.<br />
– LL ={xx | x L}<br />
– L* = U k N L k<br />
– Example: If L = {0, 00} then<br />
LL = {00, 000, 0000}<br />
David Keil Theory of Computing 12/12 16
1. Sets, languages, and models<br />
Countability of strings<br />
• To help prove equivalence of number-based<br />
and string-based models of computation, we<br />
show mappings of any string to a natural<br />
number and any natural number to a string<br />
• Enumeration according to bit representation:<br />
N {0,1}*<br />
0 <br />
1 0<br />
2 1<br />
3 00<br />
4 01<br />
David Keil Theory of Computing 12/12 17<br />
Languages and countability<br />
• Computation operates on strings;<br />
instances of models of computation<br />
accept sets of strings<br />
• A language may be represented as an<br />
infinite bit sequence, with a 1 bit in a<br />
certain bit location denoting a string’s<br />
membership in the language:<br />
{0, 01, 11, 100} = 10101100…<br />
David Keil Theory of Computing 12/12 18<br />
David Keil Theory of computing 6/12
1. Sets, languages, and models<br />
David Keil Theory of computing 6/12<br />
Countable set: the rational numbers<br />
• The rationals may<br />
be enumerated as<br />
at right, where the<br />
numerator is the<br />
row number and<br />
the denominator is<br />
the column number<br />
• Reference: “The set of rational numbers is countable,”<br />
(http://www.homeschoolmath.net/teaching/rationalnumbers-countable.php)<br />
David Keil Theory of Computing 12/12 19<br />
2. Uncountable sets<br />
• Are all infinite sets the same size?<br />
• Does infinity matter in the real<br />
finite world?<br />
David Keil Theory of Computing 12/12 20
1. Sets, languages, and models<br />
Uncountability<br />
• We show that some sets, such as the<br />
real numbers, are not countable<br />
• We prove this by showing that no<br />
bijection between such a set and the set<br />
of natural numbers can exist<br />
• This proof and its method imply limits<br />
on the power of algorithmic<br />
computation<br />
David Keil Theory of Computing 12/12 21<br />
The set of real numbers<br />
• Intuitively, the real numbers express analog or<br />
continuous quantities; they give all the<br />
possible weights or distances.<br />
• We may consider the size of the set ℝ, of reals,<br />
as corresponding to all the points on a line<br />
segment, line, plane, space, or space/time<br />
• Another definition: The reals are all the<br />
numbers that can be expressed using an<br />
infinite sequence of digits after the decimal or<br />
binary point<br />
David Keil Theory of Computing 12/12 22<br />
David Keil Theory of computing 6/12
1. Sets, languages, and models<br />
Theorem: |ℝ| > |ℕ|<br />
Proof (Cantor) :<br />
1.Suppose ℝ were countable<br />
2.Then the interval (0, 1] could be enumerated as:<br />
r 1 = 0 . b 1,1 b 1,2 b 1,3 …<br />
r 2 = 0 . b 2,1 b 2,2 b 2,3 …<br />
… where b m,n {0,1}<br />
3.Now, consider the real number s =<br />
0. b 1,1 b 2,2 b 3,3 …<br />
That is, for all n, bit n is b n,n (bitwise negation<br />
of the diagonal of r)<br />
David Keil Theory of Computing 12/12 23<br />
Cantor’s proof (cont’d)<br />
4. Now, since for every i, the i th bit of s is<br />
different from the i th bit of r i, so s differs<br />
from every element of r, so there is no<br />
element of sequence r that matches s<br />
5. Hence r does not contain s, which is<br />
clearly a real number<br />
6. Hence we have a contradiction and must<br />
reject the supposition<br />
7. Hence ℝ is not countable<br />
David Keil Theory of Computing 12/12 24<br />
David Keil Theory of computing 6/12
1. Sets, languages, and models<br />
Cantor’s proof, illustrated<br />
Supposed enumeration of ℝ:<br />
r 1 = (0, 0, 0, 0, 0, 0, 0, ...)<br />
r 2 = (1, 1, 1, 1, 1, 1, 1, ...)<br />
r 3 = (0, 1, 0, 1, 0, 1, 0, ...)<br />
r 4 = (1, 0, 1, 0, 1, 0, 1, ...)<br />
r 5 = (1, 1, 0, 1, 0, 1, 1, ...)<br />
r 6 = (0, 0, 1, 1, 0, 1, 1, ...)<br />
r 7 = (1, 0, 0, 0, 1, 0, 0, ...)<br />
...<br />
David Keil Theory of Computing 12/12 25<br />
David Keil Theory of computing 6/12<br />
Real number that differs<br />
with every element in<br />
enumeration in at least<br />
one bit:<br />
s = (1, 0, 1, 1, 1, 0, 1, ...)<br />
Summary of Cantor’s proof<br />
• “The proof shows that no matter how a list<br />
of real numbers were arranged, a real<br />
number could still be defined that would not<br />
be in the list”<br />
T. DiRienzo, J. Bartlett, 2/09<br />
• A diagonal proof is both by construction and<br />
by contradiction<br />
David Keil Theory of Computing 12/12 26
1. Sets, languages, and models<br />
The predicates are uncountable<br />
David Keil Theory of computing 6/12<br />
• Start with the set of functions<br />
{ f : {0} {0,1}}<br />
• This is a set of two functions:<br />
{{(0,1)}, {(0,0)}}<br />
• The set { f : {0, 1} {0,1}} has four elements,<br />
{ f : {0, 1, 2} {0,1}} has eight, etc.<br />
• There are 2 |ℕ| predicates f : ℕ {0,1}<br />
• Question: Is this the same as, or more than, the<br />
cardinality of the natural numbers?<br />
• Compare with the cardinality of reals<br />
David Keil Theory of Computing 12/12 27<br />
Can all predicates on ℕ be<br />
computed in Java?<br />
1. Enumerate all Java methods that take an integer<br />
parameter and return 0 or 1, as J 1, J 2, J 3, … in a<br />
bitwise ordering<br />
2. Consider the predicate f : ℕ {0,1} s.t. f (n) = 1<br />
if J n(n) = 0 or J n(n) hangs, f (n) = 0 if J n(n) = 1<br />
3. The predicate f differs in its behavior from each<br />
element of our enumeration of Java methods<br />
4. Hence f is a predicate not computed by any Java<br />
method<br />
David Keil Theory of Computing 12/12 28
1. Sets, languages, and models<br />
Results<br />
• ℕ is countable (cardinality 0, aleph-null)<br />
• ℝ is uncountable (cardinality 1)<br />
• The set of Java methods is countable using<br />
their bit representations<br />
• The predicates f : ℕ {0,1} are uncountable<br />
• There are 2 0 = 1 predicates on ℕ<br />
• The sets of natural numbers are uncountable<br />
(see handout)<br />
David Keil Theory of Computing 12/12 29<br />
3. Streams and coinduction<br />
• Can we define infinite sets of infinitely<br />
large data streams?<br />
• How can infinite I/O be described<br />
mathematically?<br />
• What is induction without a base case?<br />
David Keil Theory of Computing 12/12<br />
David Keil Theory of computing 6/12<br />
30
1. Sets, languages, and models<br />
Environment<br />
Streams<br />
Interaction stream<br />
inputs<br />
outputs<br />
• A reactive system may receive an infinite<br />
stream of inputs and may emit the<br />
corresponding infinite stream of outputs<br />
David Keil Theory of computing 6/12<br />
Program<br />
• Sets of streams express interactive behavior<br />
• Coinduction defines sets of infinite objects<br />
as induction defines sets of finite ones<br />
David Keil Theory of Computing 12/12 31<br />
Inductively defined sets<br />
• (i) 0 is a natural number;<br />
(ii) Every n ℕ has a unique successor, n;<br />
(iii) i and ii are the only ways to obtain a<br />
natural number (Peano)<br />
• Set of expressions using numerals, +, and ( ):<br />
expression <br />
numeral |<br />
numeral + expression |<br />
( expression )<br />
• The definition of such a set may use itself<br />
• But such a set does not contain itself<br />
David Keil Theory of Computing 12/12<br />
32
1. Sets, languages, and models<br />
Inductive and coinductive<br />
definitions of languages<br />
• * = {} U {ax | a , x * }<br />
(note base case )<br />
• “L is a language over alphabet *”<br />
means that L *<br />
• A stream is an infinite string<br />
• A stream language is a set of streams<br />
• Example, defined coinductively:<br />
= {ax | a , x }<br />
(note lack of base case)<br />
David Keil Theory of Computing 12/12 33<br />
Well-founded sets<br />
• (B. Russell) Let the village hair stylist be<br />
the person who cuts the hair of everyone<br />
who doesn’t cut own hair<br />
• Question: Who cuts the hair-stylist’s hair?<br />
• Similar Questions: Is there a set of all sets?<br />
If so, does it contain itself ? Is there a set of<br />
all sets that don't contain themselves?<br />
• In classical (well founded) set theory, it is<br />
meaningless to say a set belongs or doesn't<br />
belong to itself (Foundation Axiom)<br />
David Keil Theory of Computing 12/12<br />
David Keil Theory of computing 6/12<br />
34
1. Sets, languages, and models<br />
Another diagonal proof<br />
• Theorem: The notion “set of all sets” leads<br />
to a contradiction<br />
• Proof: Consider = { A : A A }<br />
(sets not members of themselves)<br />
• ( ) ( ) ,<br />
( ) ( ) , contradictions<br />
• Note role of “Spoiler” instance <br />
• We say that , are not well founded<br />
(NWF)<br />
David Keil Theory of Computing 12/12 35<br />
David Keil Theory of computing 6/12<br />
Streams and non-well-founded sets<br />
• A non-well-founded set may contain itself,<br />
directly or indirectly<br />
• Example: A = { B, C }; B = { A, D }<br />
• Every stream of characters is a character,<br />
followed by a stream of characters<br />
• Streams contain streams, which contain<br />
streams, which contain streams, ...<br />
• Ex.: The set of all bit streams {0,1} consists<br />
of any infinite sequence that consists of 0 or 1<br />
followed by a stream<br />
David Keil Theory of Computing 12/12<br />
36
1. Sets, languages, and models<br />
Streams and coinduction<br />
David Keil Theory of computing 6/12<br />
• Induction defines countable sets of finite<br />
objects: * = {} { ax | a , x * }<br />
• Coinduction<br />
– is a dual of induction (recursion), lacking a<br />
base case<br />
– is used to define sets of infinite objects<br />
• The set of streams over an alphabet, expressing<br />
ongoing processes such as interaction:<br />
= { ax | a , x }<br />
David Keil Theory of Computing 12/12<br />
Least and greatest fixed points<br />
• A fixed point x of function f is a value x<br />
(which may be a set), for which f (x) = x<br />
• Whereas induction is characterized by<br />
minimality conditions (least fixed points),<br />
coinduction has a maximality condition<br />
(greatest fixed point)<br />
• Minimality example: + is the smallest set that<br />
fits the spec {ax | a , x *}<br />
• Maximality example: is the largest set that<br />
fits the spec {ax | a , x }<br />
David Keil Theory of Computing 12/12 38<br />
37
1. Sets, languages, and models<br />
4. Circuit and lookup computation<br />
• What is a function on a finite set?<br />
• What is a property of a finite set?<br />
• How can a function on a finite domain be<br />
defined?<br />
• What’s a way to compute such a function?<br />
• What’s a simple model of simple<br />
computation?<br />
David Keil Theory of Computing 12/12 39<br />
Problems and languages<br />
• A computational problem with a Boolean<br />
(yes/no) solution is called a decision problem<br />
• Computing devices that solve them are called<br />
acceptors or recognizers<br />
• A decision problem corresponds to a<br />
language: all the strings that get a “yes”<br />
decision<br />
• Other problems, with string solutions, are<br />
called transduction problems<br />
David Keil Theory of Computing 12/12 40<br />
David Keil Theory of computing 6/12
1. Sets, languages, and models<br />
Decision and transduction<br />
• A decision problem requires yes/no responses<br />
to input<br />
• Hence it is also known as a languagerecognition<br />
problem<br />
• A transduction computation produces a string<br />
as output<br />
• Hence its solution is the computation of a<br />
function<br />
• We speak of decidable languages (problems)<br />
or computable functions<br />
David Keil Theory of Computing 12/12<br />
David Keil Theory of computing 6/12<br />
Some language-decision problems<br />
• Some languages:<br />
– 1 | 0 {0, 1}<br />
– (1 | 0) 1 {11, 01}<br />
– 1* {, 1, 11, …}<br />
– 1*0 {0, 10, 110, 1110, …}<br />
– 0(1|0)* {0, 00, 01, 000, 001,<br />
010, 011, …}<br />
• Q: How do we build a simple machine to<br />
accept strings in one of these languages?<br />
David Keil Theory of Computing 12/12 42<br />
41
1. Sets, languages, and models<br />
No-loop computation<br />
• The simplest type of computation uses no<br />
loops, but maps from finite domains<br />
• Examples: lookup table; logic circuit<br />
David Keil Theory of computing 6/12<br />
• Other equivalent models:<br />
– Finite computation trees<br />
– Flowcharts with bounded input, no loops<br />
– Formulas in propositional logic<br />
– Finite languages L k for any or k<br />
David Keil Theory of Computing 12/12 43<br />
Logic circuits<br />
• A model for the computation<br />
of functions f : {0,1} m {0,1} n<br />
where m is the arity of f<br />
(number of inputs to circuit)<br />
and n is the number of outputs<br />
• Proposition: for any such function f, a logic<br />
circuit that computes f may be constructed from a<br />
finite number of , , or gates<br />
• A logic circuit computes a function on strings of<br />
bounded size, i.e., functions with a finite domain<br />
David Keil Theory of Computing 12/12 44
1. Sets, languages, and models<br />
Lookup tables<br />
• A function on a finite domain may be<br />
represented and effectively computed<br />
using a lookup table<br />
Square function<br />
David Keil Theory of Computing 12/12 45<br />
David Keil Theory of computing 6/12<br />
a b a xor b<br />
0 0 0<br />
0 1 1<br />
1 0 1<br />
1 1 0<br />
XOR operator<br />
Labeled transition systems<br />
• Definition: a digraph, where vertices denote<br />
state, labeled edges denote transitions<br />
• Example (right): an input string<br />
of bits is read from the<br />
top, following edges<br />
• A loopless transition<br />
system can accept<br />
any finite language of strings that leave the<br />
system in an accepting state<br />
David Keil Theory of Computing 12/12 46
1. Sets, languages, and models<br />
Transducers and accepters<br />
• Theorem:Any computation of a function<br />
f : {0, 1} * {0, 1} n can be done by n accepters<br />
• Proof:<br />
1. for i n, let L i = {x | bit i of f(x) is 1}<br />
2. Construct accepters M 1 .. i for L 1 .. i as follows.<br />
3. M i decides the ith bit of f (x) for any string x.<br />
4. Let P i be the predicate computed by M i<br />
5. So f (x) = Concat i m(P i(x))<br />
6. Hence f (x) is computable by M 1..n<br />
David Keil Theory of Computing 12/12 47<br />
Barwise-Moss. Vicious Circles, 1996<br />
S. Epp. Discrete Mathematics with<br />
Applications. Brooks/Cole, 2011.<br />
Finsler, 1920s (NWF sets)<br />
Goldin-Wegner (at www.engr.uconn.edu/~dqg)<br />
Peano, 1889 (induction)<br />
J. Savage.<br />
References<br />
David Keil Theory of Computing 12/12 48<br />
David Keil Theory of computing 6/12