Post on 14-Jul-2020
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
The Fundamentals: Algorithms, the Integers, MatricesDiagonalization & Algorithms
March 31, 2020
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 1 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Outline
1 Diagonalization
2 Algorithms
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 2 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Languages
alphabet A finite set of symbols; e.g. the binary alphabet is {0, 1}.string A sequence of zero or more symbols from an alphabet; e.g. λ
(the empty string), 01011100010, 0, 101Σ is used to represent the alphabet as a whole. λ or ε standfor the empty string.
language A set of strings; e.g. {w|w starts with 1}, {00, 01, 10, 11}.Σ∗ The star (Kleene’s star operator) means zero or more copies
of the symbol before the star. This is short hand for the setof all the strings across the alphabet Σ.Note: that means Σ∗ is a set.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 3 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Cardinality of {0, 1}∗
{0, 1}∗ is infinite. Consider the set of just strings containing only ’1’symbols. The lengths of different strings in this language range acrossnon-negative integers. That is infinite.Is Σ∗ countable?If so, how to prove it.
Find bijection f : Σ∗ → Z+.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 4 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Cardinality of {0, 1}∗
{0, 1}∗ is infinite. Consider the set of just strings containing only ’1’symbols. The lengths of different strings in this language range acrossnon-negative integers. That is infinite.Is Σ∗ countable?If so, how to prove it.Find bijection f : Σ∗ → Z+.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 4 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
Define the length-then-value ordering for binary strings: w1 comes beforew2 if |w1| < |w2| or |w1| = |w2| ∧ the unsigned number represented by w1is less than the number represented by w2.So, Σ∗ can be put in order by the above ordering:
{λ, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111, ...}
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 5 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.
z s z− p f(z)1 0 0 ”” = λ2 1 0 ”0”3 1 1 ”1”4 2 0 ”00”5 2 1 ”01”6 2 2 ”10”7 2 3 ”11”8 3 0 ”000”9 3 1 ”001”
10 3 2 ”010”11 3 3 ”011”
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 6 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.f(23) =
0111f(32) =00000f−1(λ) =0f−1(1000) =24f−1(00010) =34
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 7 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.f(23) =0111f(32) =
00000f−1(λ) =0f−1(1000) =24f−1(00010) =34
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 7 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.f(23) =0111f(32) =00000f−1(λ) =
0f−1(1000) =24f−1(00010) =34
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 7 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.f(23) =0111f(32) =00000f−1(λ) =0f−1(1000) =
24f−1(00010) =34
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 7 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.f(23) =0111f(32) =00000f−1(λ) =0f−1(1000) =24f−1(00010) =
34
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 7 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
f : {0, 1}∗ → Z+
∀z ∈ Z let s = ⌊log2(z)⌋ and p = 2s. Then f(z) = z− p written as a binarynumber s characters long.f(23) =0111f(32) =00000f−1(λ) =0f−1(1000) =24f−1(00010) =34
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 7 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Cardinality of P(Σ∗)Review of Terms
Σ = {0, 1} = the binary alphabetΣ∗ =
{ all binary strings}{λ, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111, ...}P(Σ∗) = Set of all subsets of Σ∗
{ all binary languages}
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 8 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Cardinality of P(Σ∗)Review of Terms
Σ = {0, 1} = the binary alphabetΣ∗ = { all binary strings}{λ, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111, ...}P(Σ∗) = Set of all subsets of Σ∗
{ all binary languages}
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 8 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Cardinality of P(Σ∗)Review of Terms
Σ = {0, 1} = the binary alphabetΣ∗ = { all binary strings}{λ, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111, ...}P(Σ∗) = Set of all subsets of Σ∗
{ all binary languages}
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 8 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Cardinality of P(Σ∗)
P(Σ∗) is uncountable.|P(Σ∗)| > |Z+||P(Σ∗)| > ℵ0
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 9 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
P(Σ∗ is Uncountable
TBP: P(Σ∗) is uncountable.TBP: |P(Σ∗)| ̸= |Z+| Countably Infinite
FSOC: |P(Σ∗)| = |Z+|1. bijection ∃ f : Z+ → P(Σ∗) Same cardinality2. f can be represented as a table
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 10 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Looking at fλ 0 1 00 01 10 11 00
000
1
…1 0 1 0 1 0 1 0 1 0 …2 0 1 0 1 1 1 0 0 0 …3 0 0 1 0 0 0 0 0 0 …4 1 0 1 0 1 0 0 0 1 …...
Each row represents a subset of Σ∗ or an element ofP(Σ∗). A sequence of Boolean values whether thestring atop the column is/is not in the language inthat row.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 11 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Looking at fλ 0 1 00 01 10 11 00
000
1
…1 0 1 0 1 0 1 0 1 0 …2 0 1 0 1 1 1 0 0 0 …3 0 0 1 0 0 0 0 0 0 …4 1 0 1 0 1 0 0 0 1 …...
Let f(i) = bi1bi2bi3bi4bi5 . . .
Let d, the diagonal language, be b11b22b33b44 . . . = 0110…Let d, the anti-diagonal language, be b11b22b33b44 . . . = 1001…d ̸∈ range(f).
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 12 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Looking at fλ 0 1 00 01 10 11 00
000
1
…1 0 1 0 1 0 1 0 1 0 …2 0 1 0 1 1 1 0 0 0 …3 0 0 1 0 0 0 0 0 0 …4 1 0 1 0 1 0 0 0 1 …...
Let f(i) = bi1bi2bi3bi4bi5 . . .Let d, the diagonal language, be b11b22b33b44 . . . = 0110…
Let d, the anti-diagonal language, be b11b22b33b44 . . . = 1001…d ̸∈ range(f).
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 12 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Looking at fλ 0 1 00 01 10 11 00
000
1
…1 0 1 0 1 0 1 0 1 0 …2 0 1 0 1 1 1 0 0 0 …3 0 0 1 0 0 0 0 0 0 …4 1 0 1 0 1 0 0 0 1 …...
Let f(i) = bi1bi2bi3bi4bi5 . . .Let d, the diagonal language, be b11b22b33b44 . . . = 0110…Let d, the anti-diagonal language, be b11b22b33b44 . . . = 1001…
d ̸∈ range(f).
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 12 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Looking at fλ 0 1 00 01 10 11 00
000
1
…1 0 1 0 1 0 1 0 1 0 …2 0 1 0 1 1 1 0 0 0 …3 0 0 1 0 0 0 0 0 0 …4 1 0 1 0 1 0 0 0 1 …...
Let f(i) = bi1bi2bi3bi4bi5 . . .Let d, the diagonal language, be b11b22b33b44 . . . = 0110…Let d, the anti-diagonal language, be b11b22b33b44 . . . = 1001…d ̸∈ range(f).
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 12 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
Looking at f
TBP: d ̸∈ range(f).FSOC: d ∈ range(f).
1. ∃z ∈ Z+ ∋ f(z) = d Definition of range2. f(z)z = b f(z) is a sequence of bits3. dz = b by construction
→← f(z) cannot equal d 2. and 3.∴ d ̸∈ range(f)
f is not an onto function.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 13 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Diagonalization
P(Σ∗ is Uncountable
TBP: P(Σ∗) is uncountable.TBP: |P(Σ∗)| ̸= |Z+| Countably Infinite
FSOC: |P(Σ∗)| = |Z+|1. bijection ∃ f : Z+ → P(Σ∗) Same cardinality2. f can be represented as a table3. The f in the table is not onto.
→← f both is and is not onto 1. and 3.∴ |P(Σ∗)| ̸= |Z+|
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 14 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsDefinition
DefinitionAn algorithm is a finite series of precise instructions for performing acomputation or solving a problem.
Example (Algorithm: Maximum element in finite sequence)
procedure max(a1 , a2 , . . . , an : i n teger )max := a1f o r i := 2 to n
i f (ai > max) then max = ai{ max l a r g e s t on a1 − ai i n c l u s i v e }
{ max l a r g e s t on a1 − an i n c l u s i v e }
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 15 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsDefinition
DefinitionAn algorithm is a finite series of precise instructions for performing acomputation or solving a problem.
Example (Algorithm: Maximum element in finite sequence)
procedure max(a1 , a2 , . . . , an : i n teger )max := a1f o r i := 2 to n
i f (ai > max) then max = ai{ max l a r g e s t on a1 − ai i n c l u s i v e }
{ max l a r g e s t on a1 − an i n c l u s i v e }
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 15 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Properties of Algorithms
Input An algorithm has input values from a specified set
Output From each set of input values, an algorithm produces outputvalues, the solution, from a specified set
Definiteness The steps of the algorithm are defined preciselyCorrectness The algorithm should produce the correct output for each
input valueFiniteness The solution must be produced in a finite number of steps
Effectiveness It must be possible to perform each step in the algorithmprecisely and in a finite amount of time
Generality The procedure should apply to all problems of the givenform, not just a single input value
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 16 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Properties of Algorithms
Input An algorithm has input values from a specified setOutput From each set of input values, an algorithm produces output
values, the solution, from a specified set
Definiteness The steps of the algorithm are defined preciselyCorrectness The algorithm should produce the correct output for each
input valueFiniteness The solution must be produced in a finite number of steps
Effectiveness It must be possible to perform each step in the algorithmprecisely and in a finite amount of time
Generality The procedure should apply to all problems of the givenform, not just a single input value
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 16 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Properties of Algorithms
Input An algorithm has input values from a specified setOutput From each set of input values, an algorithm produces output
values, the solution, from a specified setDefiniteness The steps of the algorithm are defined precisely
Correctness The algorithm should produce the correct output for eachinput value
Finiteness The solution must be produced in a finite number of stepsEffectiveness It must be possible to perform each step in the algorithm
precisely and in a finite amount of timeGenerality The procedure should apply to all problems of the given
form, not just a single input value
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 16 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Properties of Algorithms
Input An algorithm has input values from a specified setOutput From each set of input values, an algorithm produces output
values, the solution, from a specified setDefiniteness The steps of the algorithm are defined preciselyCorrectness The algorithm should produce the correct output for each
input value
Finiteness The solution must be produced in a finite number of stepsEffectiveness It must be possible to perform each step in the algorithm
precisely and in a finite amount of timeGenerality The procedure should apply to all problems of the given
form, not just a single input value
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 16 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Properties of Algorithms
Input An algorithm has input values from a specified setOutput From each set of input values, an algorithm produces output
values, the solution, from a specified setDefiniteness The steps of the algorithm are defined preciselyCorrectness The algorithm should produce the correct output for each
input valueFiniteness The solution must be produced in a finite number of steps
Effectiveness It must be possible to perform each step in the algorithmprecisely and in a finite amount of time
Generality The procedure should apply to all problems of the givenform, not just a single input value
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 16 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Properties of Algorithms
Input An algorithm has input values from a specified setOutput From each set of input values, an algorithm produces output
values, the solution, from a specified setDefiniteness The steps of the algorithm are defined preciselyCorrectness The algorithm should produce the correct output for each
input valueFiniteness The solution must be produced in a finite number of steps
Effectiveness It must be possible to perform each step in the algorithmprecisely and in a finite amount of time
Generality The procedure should apply to all problems of the givenform, not just a single input value
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 16 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Properties of Algorithms
Input An algorithm has input values from a specified setOutput From each set of input values, an algorithm produces output
values, the solution, from a specified setDefiniteness The steps of the algorithm are defined preciselyCorrectness The algorithm should produce the correct output for each
input valueFiniteness The solution must be produced in a finite number of steps
Effectiveness It must be possible to perform each step in the algorithmprecisely and in a finite amount of time
Generality The procedure should apply to all problems of the givenform, not just a single input value
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 16 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsLinear Search
Example (Algorithm: Linear Search of Finite Sequence)
procedure l i n e a r (x : integer , a1 , . . . , an : d i s t i n c t i n teger )i := 1whi le ( i ≤ n ∧ x ̸= ai ) do
i := i + 1{ no x yet and more to search }
i f i ≤ n then location := ie l s e location := 0{ location i s 0 i f not found ;
index of matching va lue otherwi se }
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 17 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsBinary Search
Example (Algorithm: Binary Search of Sorted Finite Sequence)
procedure b inary (x : integer ,a1 , a2 , . . . , an : i n c r e a s i n g i n teger )
low := 1high := n{ search i n t e r v a l [ low , high ] }
whi le ( low < high) domid := ⌊( low + high)/2⌋i f (x > amid ) then low := mid + 1e l s e high := mid
{ low = high ( could not be <; why not ?) and ,i f x i s found , x = alow }
i f (x = alow ) then location := lowe l s e location := 0{location i s 0 i f not found ;
index of matching va lue otherwi se }
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 18 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsBinary Search
Theorembinary always terminates
Proof.The only way it can not terminate is to be stuck in the while loop.In the loop, low ≤ mid ≤ highhigh - low is the size of the range to be searched.
high′ - low′, the value after the loop, is smaller:If x > amid, low′ > lowOtherwise, high′ < high becauselow ̸= high; ⌊ ⌋ of average less than maxRange to be searched is smaller on each iteration of loop; range initiallyfinite so value must cross 0 terminating the while loop.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 19 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsBinary Search
Theorembinary always terminates
Proof.The only way it can not terminate is to be stuck in the while loop.In the loop, low ≤ mid ≤ highhigh - low is the size of the range to be searched.high′ - low′, the value after the loop, is smaller:
If x > amid, low′ > lowOtherwise, high′ < high becauselow ̸= high; ⌊ ⌋ of average less than maxRange to be searched is smaller on each iteration of loop; range initiallyfinite so value must cross 0 terminating the while loop.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 19 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsBinary Search
Theorembinary always terminates
Proof.The only way it can not terminate is to be stuck in the while loop.In the loop, low ≤ mid ≤ highhigh - low is the size of the range to be searched.high′ - low′, the value after the loop, is smaller:If x > amid, low′ > lowOtherwise, high′ < high becauselow ̸= high; ⌊ ⌋ of average less than maxRange to be searched is smaller on each iteration of loop; range initiallyfinite so value must cross 0 terminating the while loop.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 19 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsMaking Change
Example (Problem)Given: Amount of change to make, n ∈ Z+
Sequence of coins: c1 > c2 > ... > cr
Describe an algorithm to solve this problem.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 20 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsMaking Change
Example (Algorithm: Greedy Algorithm for Making Change)
procedure change ( i n teger n ,dec reas ing i n teger c1 , c2 , . . . , cr )
change = {}f o r i = 1 to r
whi le n ≥ ciadd ci to changen = n − ci
// ci > n − no more of t h i s co in f i t// Assuming a l l va lue s can be b u i l t of coins , change i s set// of co in s making change n ( s i n c e n should be 0)
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 21 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsChange Making Correctness
LemmaIf n ∈ Z+, then n cents in change using American coins under a halfdollar, using the fewest coins possible, has at most two dimes, at most onenickel, at most four pennies, and cannot have two dimes and a nickel. Theamount of change excluding quarters cannot exceed 24 cents.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 22 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
AlgorithmsChange Making Correctness
TheoremThe greedy algorithm produces correct change in the fewest number ofcoins using American coins under a half dollar.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 23 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Halting Problem
DefinitionThe Halting Problem is the problem of constructing a program, H, thattakes two parameters: P, another computer program and I, input for P. Hshould report “halts” or “loops forever” depending on whether or not Phalts on input I.
H(P, I) ={
”halts” if P(I) halts”loops forever” if P(I) does not halt
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 24 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Programs as Data
A program is encoded in some way (Fortran, pseudo-code, Java,bytecode). An encoding can be expressed as a sequence of symbols acrosssome alphabet.Any alphabet can be re-encoded using strings of bits.Any program can be expressed as a sequence of bits.A program, encoded as a sequence of bits, can be given as input to aprogram. The receiving program may or may not respect the “right”interpretation.
Any program that takes a single input parameter can be passed itself (orrather, its own encoding) as its input.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 25 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Programs as Data
A program is encoded in some way (Fortran, pseudo-code, Java,bytecode). An encoding can be expressed as a sequence of symbols acrosssome alphabet.Any alphabet can be re-encoded using strings of bits.Any program can be expressed as a sequence of bits.A program, encoded as a sequence of bits, can be given as input to aprogram. The receiving program may or may not respect the “right”interpretation.Any program that takes a single input parameter can be passed itself (orrather, its own encoding) as its input.
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 25 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Halting Problem
Definition
H(P, I) ={
”halt” if P(I) halts”loop” if P(I) does not halt
DefinitionFSOC Assume H exists. Construct D
D(P) ={
loop forever if H(D,P) haltsreturn if H(D,P) does not halt
What does H(D,D) return?
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 26 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Halting Problem
Definition
H(P, I) ={
”halt” if P(I) halts”loop” if P(I) does not halt
DefinitionFSOC Assume H exists. Construct D
D(P) ={
loop forever if H(D,P) haltsreturn if H(D,P) does not halt
What does H(D,D) return?
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 26 / 26
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
Algorithms
Halting Problem
Definition
H(P, I) ={
”halt” if P(I) halts”loop” if P(I) does not halt
DefinitionFSOC Assume H exists. Construct D
D(P) ={
loop forever if H(D,P) haltsreturn if H(D,P) does not halt
What does H(D,D) return?
The Fundamentals: Algorithms, the Integers, Matrices March 31, 2020 26 / 26