









































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










































































Input and Tape Alphabets
A Simple Turing Machine q 0
qacc
qacc
direction^ symbol The symbol^ y^ D and (which ☐move represents is^ theeither^ tape the L^ head or blank R^ in). symbol.
Each transition x → y (^) , D of the form means direction symbol “upon y (^) D and (^) (whichreading move is x theeither, replacetape L (^) head (^) orit R within). The symbol ☐ symbol represents. the blank
This state (^) machinespecial causes accept to the immediately accept.
This state (^) machinespecial causes accept to the immediately accept.
This state (^) machinespecial causes reject to the immediately reject.
This state (^) machinespecial causes reject to the immediately reject.
Check Check m m ≟≟ 00 Cross off 1
To End Cross off 1
Next Next 00 To End home home^ Back^ Back
home home^ Back^ Back
UnmarkUnmark
◻ → ◻, R
start 0 → 0, R 1 → 1, L 0 → 0, L
☐ → ☐, R 0 → ×, R
× → ×, R0 → 0, R1 → 1, R
◻ → ◻, L × → ×, L0 → 0, L1 → 1, L 1 → ☐, L
☐1 → 1, L → ☐, L × → ×, R
☐ → ☐, R × → 0, L
Accept!
◻ → ◻, R
Composite Numbers ● (^) A natural number the product of two natural numbers n ≥ 2 is composite p (^) andif it is q , ● neither of which isExample:^ n.
bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }
bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }
Back to Languages
Check for ε start
1 → 1, R (^) Check for 1 1 → 1, L bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }
bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }
Reusing our TMs ● (^) What does our TM need to be able to do? – (^) Check if divisor = n
● (^) What TMs did we build last time?^ –^ Check if^ n^ is a multiple of^ divisor.
A Sketch of the TM
if int (n ≤ 1) divisor = 2; return false; while if (divisor ≠ n) {(n is a multiple of divisor) { return true; }^ }^ divisor++; }^ return^ false;
bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }
A Sketch of the TM
if int (n ≤ 1) divisor = 2; return false; while if (divisor ≠ n) {(n is a multiple of divisor) { return true; }^ }^ divisor++; }^ return^ false;
bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }
last is^ Somehow, of time the to^ formrun see^ our 0 ifm 1 n,TMthe where^ fromstring n is a multiple of m.
last is^ Somehow, of time the to^ formrun see^ our 0 ifm 1 n,TMthe where^ fromstring n is a multiple of m.
A Sketch of the TM
if int (n ≤ 1) divisor = 2; return false; while if (divisor ≠ n) {(n is a multiple of divisor) { return true; }^ }^ divisor++; }^ return^ false;
bool if isComposite( (n ≤ 1) returnint n) {false; int while (^) ifdivisor = 2; (divisor ≠ n) {(n is a multiple of divisor) { } divisor++;^ return^ true; } return false; }