November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 1 Numerical Representation of Strings Correspondingly, we define the following:

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

1 VBScript Session What we learn last session? Regulars Expressions. Methods and properties. How to use the object and his collections. How to create.
Simplifications of Context-Free Grammars
Slide 1 Insert your own content. Slide 2 Insert your own content.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Source of slides: Introduction to Automata Theory, Languages and Computation.
Combining Like Terms. Only combine terms that are exactly the same!! Whats the same mean? –If numbers have a variable, then you can combine only ones.
Introduction to Algorithms
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
CS4026 Formal Models of Computation Running Haskell Programs – power.
9.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 9 – Clipping.
Turing Machines.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Chapter 2 – Combinational.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Addition 1’s to 20.
CS 240 Computer Programming 1
25 seconds left…...
Introduction to Computability Theory
Finite-state Recognizers
Week 1.
Dantzig-Wolfe Decomposition
Section 2.5 Solving Linear Equations in One Variable Using the Multiplication-Division Principle.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
1 Turing Machines and Equivalent Models Section 13.2 The Church-Turing Thesis.
October 13, 2009Theory of Computation Lecture 11: A Universal Program III 1 Coding Programs by Numbers Gödel numbers are usually very large, even for small.
November 17, 2009Theory of Computation Lecture 18: Calculations on Strings III 1 Numerical Representation of Strings We will now look at several primitive.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 1Universality Then we append the following instruction: [C]IF K = Lt(Z) + 1 
November 10, 2009Theory of Computation Lecture 16: Computation on Strings I 1Diagonalization Another example: Let TOT be the set of all numbers p such.
December 8, 2009Theory of Computation Lecture 22: Turing Machines IV 1 Turing Machines Theorem 1.1: Any partial function that can be computed by a Post-
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
October 8, 2009Theory of Computation Lecture 10: A Universal Program II 1 Pairing Functions and Gödel Numbers This way the equation  x, y  = z defines.
Computability and Complexity 10-1 Computability and Complexity Andrei Bulatov Gödel’s Incompleteness Theorem.
September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 1 Macros Now we want to use macros of the form: W  f(V 1, …,
December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.
1 Section 13.2 The Church-Turing Thesis The Church-Turing Thesis: Anything that is intuitively computable can be be computed by a Turing machine. It is.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
December 3, 2009Theory of Computation Lecture 21: Turing Machines III 1 Simulation of T in L Now the MIDDLE section of Q can be generated by replacing.
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CSE202: Introduction to Formal Languages and Automata Theory
Diagonalization and Reducibility
Theory of Computation Lecture 23: Turing Machines IV
Theory of Computation Lecture 14: A Universal Program V
Numerical Representation of Strings
Theory of Computation Lecture 22: Turing Machines III
Theory of Computation Lecture 5: Programs and Computable Functions III
Theory of Computation Lecture 6: Primitive Recursive Functions I
Theory Of Computer Science
The Programming Language L
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 21: Turing Machines II
12 Further mathematics Recurrence relations.
Numerical Representation of Strings
Theory of Computation Lecture 5: Programs and Computable Functions III
The Programming Language L
Numerical Representation of Strings
Numerical Representation of Strings
Numerical Representation of Strings
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 6: Primitive Recursive Functions I
Theory of Computation Lecture 22: Turing Machines II
Numerical Representation of Strings
Theory of Computation Lecture 17: Calculations on Strings II
Theory of Computation Lecture 23: Turing Machines III
Presentation transcript:

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 1 Numerical Representation of Strings Correspondingly, we define the following: For x  N, let w be the string in Ã* which represents x in base l. Let w’ be obtained from w by crossing out all of the symbols that belong to à – A, so w’  A*. We write DOWNCHANGE n,l (x) for the number which w’ represents in base n. Example: DOWNCHANGE 2,6 (109) = 5 The representation of 109 in base 6 is s 2 s 6 s 1. We cross out the s 6 and get s 2 s 1. In base 2, s 2 s 1 represents the number 5.

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 2 Numerical Representation of Strings UPCHANGE n,l and DOWNCHANGE n,l are actually primitive recursive functions, but now we will just show that they are computable. This program computes UPCHANGE n,l : [A]IF X = 0 GOTO E Z ← LTEND n (X) // Z receives leftmost symbol X ← LTRUNC n (X) // removes this symbol from x Y ← l  Y + Z // add to output GOTO A

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 3 Numerical Representation of Strings Let us look at the computation of UPCHANGE 2,10 (12) iteration by iteration (string s 2 s 1 s 2 ): [A]IF X = 0 GOTO E Z ← LTEND n (X) X ← LTRUNC n (X) Y ← l  Y + Z GOTO A 0. Z = 0, Y = 0, X = 12 1.Z = 2, Y = 2, X = 4 2.Z = 1, Y = 21, X = 2 3.Z = 2, Y = 212, X = 0 Result: 212

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 4 Numerical Representation of Strings This program computes DOWNCHANGE n,l : [A]IF X = 0 GOTO E Z ← LTEND l (X) // Z receives leftmost symbol X ← LTRUNC l (X) // removes this symbol from x IF Z > n GOTO A // check if we must cross out Z Y ← n  Y + Z // if not, add digit Z to output GOTO A

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 5 A Progr. Language for String Computations The instructions in our programming language L do not seem well-designed for string computations. Let us consider the instruction type V  V + 1. For example, if we use the alphabet {a, b, c, d}, and the variable V contains the number corresponding to the string cadd, what will this instruction do? It will turn cadd into cbaa. Why would we want to have this as one of our fundamental operations in the programming language?

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 6 A Progr. Language for String Computations To improve this situation, we will now introduce specific programming languages L n for computations on alphabets of size n for all n > 0. All variables will be the same as in L, except that we now consider their values to be from A* with | A | = n. The use of labels, formal rules of syntax, and macro expansions will also be identical to L. An m-ary partial function on A* which is computed by a program in L n is said to be partially computable in L n. If the function is total and partially computable in L n, it is called computable in L n.

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 7 A Progr. Language for String Computations Instruction Interpretation V   V (with  A) Place the symbol  to the left of the string which is the value of V. V  V - Delete the final symbol of the string which is the value of V. If the value of V is 0, leave it unchanged. IF V ENDS  GOTO LIf the value of V ends in the symbol , continue with the first instruction labeled L; otherwise proceed to the next instruction.

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 8 A Progr. Language for String Computations Although the instructions of L n refer to strings, we can still think of them as referring to the numbers associated with the strings. For example, given an alphabet with n symbols, the instruction V  s i V has the effect of replacing the current value of the variable V with the value i  n |V| + V. So you see that the “natural” string operations in L n have complex numerical counterparts.

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 9 A Progr. Language for String Computations Now let us look at some useful macros for use in L n and their expansions: 1. The macro IF V  0 GOTO L has the expansion IF V ENDS s 1 GOTO L IF V ENDS s 2 GOTO L : IF V ENDS s n GOTO L

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 10 A Progr. Language for String Computations 2. The macro V  0 has the expansion [A]V  V - IF V  0 GOTO A 3. The macro GOTO L has the expansion Z  0 Z  s 1 Z IF Z ENDS s 1 GOTO L

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 11 A Progr. Language for String Computations 4. The macro V’  V has a complicated expansion. So let us first introduce the description IF V ENDS s i GOTO B i (1  i  n) to stand for IF V ENDS s 1 GOTO B 1 IF V ENDS s 2 GOTO B 2 : IF V ENDS s n GOTO B n This is also called a filter.

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 12 A Progr. Language for String Computations Z  0 V’  0 [A]IF V ENDS s i GOTO B i (1  i  n) GOTO C [B i ]V  V - (1  i  n) V’  s i V’: Z  s i Z: GOTO A: [C]IF Z ENDS s i GOTO D i (1  i  n) GOTO E [D i ]Z  Z - (1  i  n) V  s i V: GOTO C:

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 13 A Progr. Language for String Computations Finally, let us look at two useful functions, namely f(x) = x + 1 and g(x) = x -  1. We want to show that these functions are computable in L n by writing programs that compute them.

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 14 A Progr. Language for String Computations Example 1: An L n program that computes f(x) = x + 1 [B]IF X ENDS s i GOTO A i (1  i  n) Y  s 1 Y GOTO E [A i ]X  X - (1  i < n) Y  s i+1 Y: GOTO C: [A n ]X  X - Y  s 1 Y GOTO B [C]IF X ENDS s i GOTO D i (1  i  n) GOTO E [D i ]X  X - (1  i  n) Y  s i Y: GOTO C:

November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 15 A Progr. Language for String Computations Example 2: An L n program that computes g(x) = x -  1 [B]IF X ENDS s i GOTO A i (1  i  n) GOTO E [A i ]X  X - (1 < i  n) Y  s i-1 Y: GOTO C: [A 1 ]X  X - IF X  0 GOTO C 2 GOTO E [C 2 ]Y  s n Y GOTO B [C]IF X ENDS s i GOTO D i (1  i  n) GOTO E [D i ]X  X - (1  i  n) Y  s i Y: GOTO C: