Numerical Representation of Strings

Slides:



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

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.
1 Introduction to Computability Theory Lecture11: Variants of Turing Machines Prof. Amos Israeli.
CS5371 Theory of Computation
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-
Balanced Parentheses G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\}
Parsing — Part II (Ambiguity, Top-down parsing, Left-recursion Removal)
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.
September 24, 2009Theory of Computation Lecture 6: Primitive Recursive Functions II 1 Homework Questions Question 1: Write a program P that computes 
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, …,
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
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.
PPL Applicative and Normal Form Verification, Type Checking and Inference.
Theory of Computation Lecture 5: Primitive Recursive Functions I
Lecture 3: Count Programs, While Programs and Recursively Defined Functions 虞台文 大同大學資工所 智慧型多媒體研究室.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
Lecture 16b Turing Machines Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE 355 Foundations.
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.
Compiler Construction Lecture Five: Parsing - Part Two CSC 2103: Compiler Construction Lecture Five: Parsing - Part Two Joyce Nakatumba-Nabende 1.
Sorting by placement and Shift Sergi Elizalde Peter Winkler By 資工四 B 周于荃.
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
Section 14.2 Computing Partial Derivatives Algebraically
Another Word on PRC Classes
Context-Free Grammars: an overview
CS510 Compiler Lecture 4.
Theory of Computation Lecture 12: A Universal Program III
Theory Of Computer Science
Modeling Arithmetic, Computation, and Languages
Simplifications of Context-Free Grammars
Diagonalization and Reducibility
Fall Compiler Principles Lecture 4: Parsing part 3
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
Intro to Data Structures
CHAPTER 2 Context-Free Languages
Theory Of Computer Science
The Programming Language L
Derivations and Languages
Theory of Computation Lecture #
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 21: Turing Machines II
12 Further mathematics Recurrence relations.
Numerical Representation of Strings
Diagonalization and Reducibility
Primitive Recursive Predicates
Theory of Computation Lecture 5: Programs and Computable Functions III
The Programming Language L
Numerical Representation of Strings
Theory of Computation Lecture 4: Programs and Computable Functions II
Numerical Representation of Strings
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 6: Primitive Recursive Functions I
Some Primitive Recursive Functions
Theory of Computation Lecture 22: Turing Machines II
Theory of Computation Lecture 13: A Universal Program V
Numerical Representation of Strings
Theory of Computation Lecture 17: Calculations on Strings II
Theory of Computation Lecture 11: A Universal Program III
Theory of Computation Lecture 23: Turing Machines III
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Numerical Representation of Strings 2.) g(u, v) = CONCATn(u, v) This function is primitive recursive because it is defined by the following equation: CONCATn(u, v) = un|v| + v Example: Alphabet A = {1, 2, 3, 4, 5, 6, 7, 8, 9, X}: CONCAT10(13, 478) = 131000 + 478 = 13478 April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings 3.) CONCATn(m)(u1, …, um) This function is primitive recursive for each m, n  1. It follows at once from the previous example using composition. Example: Alphabet A = {1, 2, 3, 4, 5, 6, 7, 8, 9, X}, m = 3: CONCATn(u, v, w) = un|v| + |w| + vn|w| + w CONCAT10(13, 478, 9) = 1310000 + 478 10 + 9 = 134789 April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings 4.) RTENDn(w) = h(0, n, w) Remember: im = h(m, n, x), m = 0, …, k. RTENDn gives the rightmost symbol of a given word. We know that h is primitive recursive, so RTENDn is also primitive recursive. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings 5.) LTENDn(w) = h(|w| - 1, n, w) Corresponding to RTENDn, LTENDn gives the leftmost symbol of a given word. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings 6.) RTRUNCn(w) = g(1, n, w) Remember: g(m, n, x) = um u0 = iknk + ik-1nk-1 + … + i1n1 + i0 u1 = iknk-1 + ik-1nk-2 + … + i1 RTRUNCn gives the result of removing the rightmost symbol from a given nonempty string. When we can omit the reference to the base n, we often write w- for RTRUNCn(w). Note that 0- = 0. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings 7.) LTRUNCn(w) = w - (LTENDn(w) n|w| -1) LTRUNCn gives the result of removing the leftmost symbol from a given nonempty string. Example: Alphabet A = {1, 2, 3, 4, 5, 6, 7, 8, 9, X}: LTRUNC10(3478) = 3478 - 31000 = 478. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings We will use these newly introduced primitive recursive functions to prove the computability of a pair of functions that can be used in changing base. Let 1  n < l. Let A  Ã, where A is an alphabet of n symbols and à is an alphabet of l symbols. So whenever a string belongs to A*, it also belongs to Ã*. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings For any x  N, let w be the word in A* that represents x in base n. Then we write UPCHANGEn,l(x) for the number which w represents in base l. Examples: UPCHANGE2,6(5) = 13 The representation of 5 in base 2 is s2s1. In base 6, s2s1 represents the number 13. UPCHANGE1,5(3) = 31 The representation of 3 in base 1 is s1s1s1. In base 5, s1s1s1 represents the number 31. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

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 DOWNCHANGEn,l(x) for the number which w’ represents in base n. Example: DOWNCHANGE2,6(109) = 5 The representation of 109 in base 6 is s2s6s1. We cross out the s6 and get s2s1. In base 2, s2s1 represents the number 5. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings UPCHANGEn,l and DOWNCHANGEn,l are actually primitive recursive functions, but now we will just show that they are computable. This program computes UPCHANGEn,l: [A] IF X = 0 GOTO E Z ← LTENDn(X) // Z receives leftmost symbol X ← LTRUNCn(X) // removes this symbol from x Y ← l  Y + Z // add to output GOTO A April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings Let us look at the computation of UPCHANGE2,10(12) iteration by iteration (string s2s1s2): [A] IF X = 0 GOTO E Z ← LTENDn(X) X ← LTRUNCn(X) Y ← l  Y + Z GOTO A 0. Z = 0, Y = 0, X = 12 Z = 2, Y = 2, X = 4 Z = 1, Y = 21, X = 2 Z = 2, Y = 212, X = 0 Result: 212 April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

Numerical Representation of Strings This program computes DOWNCHANGEn,l: [A] IF X = 0 GOTO E Z ← LTENDl(X) // Z receives leftmost symbol X ← LTRUNCl(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 April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

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? April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

A Progr. Language for String Computations To improve this situation, we will now introduce specific programming languages Ln 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 Ln is said to be partially computable in Ln. If the function is total and partially computable in Ln, it is called computable in Ln. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

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 L If the value of V ends in the symbol , continue with the first instruction labeled L; otherwise proceed to the next instruction. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

A Progr. Language for String Computations Although the instructions of Ln 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  siV 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 Ln have complex numerical counterparts. April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

A Progr. Language for String Computations Now let us look at some useful macros for use in Ln and their expansions: 1. The macro IF V0 GOTO L has the expansion IF V ENDS s1 GOTO L IF V ENDS s2 GOTO L : IF V ENDS sn GOTO L April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V

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  s1Z IF Z ENDS s1 GOTO L April 25, 2019 Theory of Computation Lecture 20: Calculations on Strings V