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.
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
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.
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, …,
Unary, Binary, and Beyond Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 3Jan 20, 2004Carnegie Mellon University.
November 3, 2009Theory of Computation Lecture 14: A Universal Program VI 1 Recursively Enumerable Sets Definition: We write: W n = {x  N |  (x, n) 
Chapter 4: A Universal Program 1. Coding programs Example : For our programs P we have variables that are arranged in a certain order: Y 1 X 1 Z 1 X 2.
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.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
September 29, 2009Theory of Computation Lecture 7: Primitive Recursive Functions III 1 Some Primitive Recursive Functions Example 3: h(x) = x! Here are.
Theory of Computation Lecture 5: Primitive Recursive Functions I
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
November 2003Computational Morphology III1 CSA405: Advanced Topics in NLP Xerox Notation.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
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.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 4 Inverse, Exponential, and Logarithmic Functions Copyright © 2013, 2009, 2005 Pearson Education,
Chapter 4 Introduction to Set Theory
Another Word on PRC Classes
Theory of Computation Lecture #
Relations, Functions, and Matrices
Theory Of Computer Science
Copyright © Cengage Learning. All rights reserved.
Modeling Arithmetic, Computation, and Languages
Diagonalization and Reducibility
Theory of Computation Lecture 23: Turing Machines IV
Theory of Computation Lecture 14: A Universal Program V
Lecture 9 Theory of AUTOMATA
Recursively Enumerable Sets
Numerical Representation of Strings
Theory of Computation Lecture 22: Turing Machines III
Functions Defined on General Sets
Great Theoretical Ideas in Computer Science
Lecture 14 Grammars – Parse Trees– Normal Forms
Theory of Computation Lecture 16: A Universal Program VII
Theory of Computation Lecture 5: Programs and Computable Functions III
Theory of Computation Lecture 6: Primitive Recursive Functions I
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
Context-Free Grammars
INTRODUCTION TO THE THEORY OF COMPUTATION
Context-Free Grammars 1
Copyright © Cengage Learning. All rights reserved.
Theory Of Computer Science
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
2 Chapter Numeration Systems and Sets
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
Discrete Mathematics and its Applications
Properties of Functions
Copyright © Cengage Learning. All rights reserved.
Theory of Computation Lecture 21: Turing Machines II
Numerical Representation of Strings
Diagonalization and Reducibility
Recursively Enumerable Sets
Primitive Recursive Predicates
Theory of Computation Lecture 5: Programs and Computable Functions III
Cardinality Definition: The cardinality of a set A is equal to the cardinality of a set B, denoted |A| = |B|, if and only if there is a one-to-one correspondence.
Numerical Representation of Strings
Numerical Representation of Strings
Theory of Computation Lecture 4: Programs and Computable Functions II
Formal Languages Context free languages provide a convenient notation for recursive description of languages. The original goal of formalizing the structure.
Theory of Computation Lecture 6: Primitive Recursive Functions I
Some Primitive Recursive Functions
Theory of Computation Lecture 13: A Universal Program V
Numerical Representation of Strings
Programming Languages
Theory of Computation Lecture 17: Calculations on Strings II
Theory of Computation Lecture 23: Turing Machines III
Presentation transcript:

Numerical Representation of Strings So you see that we can easily replace our usual digit range from 0 to n-1 with the range 1 to n. In our representation of strings on the alphabet A, we use the range from 1 to n to have a bijective mapping between strings and numbers. When using a range from 0 to n-1, there is no such mapping, because different strings correspond to the same number, for example: 87 = 087 = 0087 = 00087 = … November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings Now let us return to our general case of associating numbers with strings. For an alphabet A = {s1, …, sn}, the string w = sik sik-1 … si1 , si0 is called the base n notation for the number x as defined by x = iknk + ik-1nk-1 + … + i1n1 + i0 . When n is fixed, we can consider a function of one or more variables on A* as a function of the corresponding numbers. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings So we can speak of an m-ary partial function on A* with values in A* as being partially computable, or when it is total, we can speak of it as being computable. Similarly, we can say that an m-ary function on A* is primitive recursive. But what about predicates? Notice that for an alphabet A = {s1, …, sn} the value s1 denotes 1 in base n notation. Thus an m-ary predicate on A* is simply a total m-ary function on A* whose values are either s1 (“true”) or 0 (“false”). Therefore, it makes sense to speak of an m-ary predicate on A* as being computable. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings For a given alphabet A, any subset of A* (any set of strings on A) is called a language on A. By associating numbers with the elements of A*, we can speak of a language on A as being r.e., recursive, or primitive recursive. Notice that our base n notation even works for n = 1, that is, an alphabet containing only one symbol. For example, if A = {s1} then x = 1 is represented by the string w = s1 x = 7 is represented by the string w = s1s1s1s1s1s1s1 : November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings To avoid confusion, we will not use decimal digits as symbols in our alphabets. Accordingly, a string of decimal digits will always be meant to refer to a number. We will now define some useful functions for string operations. The first function will be CONCAT. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings Let A be some fixed alphabet containing n symbols, A = {s1, …, sn}. For each m  1, we define CONCATn(m) as follows: CONCATn(1)(u) = u CONCATn(m+1)(u1, …, um, um+1) = zum+1, where z = CONCATn(m)(u1, …, um). This means that for given strings u1, …, um  A*, CONCATn(m)(u1, …, um) is obtained by concatenating the strings u1, …, um. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings We will usually omit the superscript, i.e., the number of arguments. For example: CONCAT3 (s3s1s2, s1s3) = s3s1s2s1s3 Translating this equation from strings to numbers: CONCAT3 (32, 6) = 294 It is also true that CONCAT5 (s3s1s2, s1s3) = s3s1s2s1s3 CONCAT5 (82, 8) = 2058 Obviously, the definition of CONCAT depends on the base n. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings We will now look at several primitive recursive functions on strings. These functions will be useful for our further discussion of calculation on strings. It will be helpful to remember the functions g and h: g(0, n, x) = x g(m + 1, n, x) = Q+(g(m, n, x), n), then g(m, n, x) = um. h(m, n, x) = R+(g(m, n, x), n), then im = h(m, n, x), m = 0, …, k. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings 1.) f(u) = |u| This “length” function is defined on A* and yields a natural number. How can we compute f on the number associated with A*? For each t, the number tj=0 nj has the base n representation s1[t+1]. (The expression s[m] stands for the string that consists of m times the symbol s.) November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings For example, given the alphabet A = {s1, s2 ,s3} and t = 2: The string representation of tj=0 3j = s1s1s1. This number is the smallest number whose base 3 representation contains t + 1 symbols. If we subtract 1 from the string s1s1s1, it becomes s3s3. So the length |u| can be defined as follows: |u| = mint≤u (tj=0 nj > u). Obviously, this function is primitive recursive. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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 November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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 November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

Numerical Representation of Strings 5.) LTENDn(w) = h(|w| - 1, n, w) Corresponding to RTENDn, LTENDn gives the leftmost symbol of a given word. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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 Ã*. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III

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. November 21, 2017 Theory of Computation Lecture 19: Calculations on Strings III