110. Strings

110.1 Definition: string

A string is a list of characters in some alphabet.

110.1.1 Example $\langle c,a,t\rangle$ is a string in the English alphabet.

110.1.2 Usage It is customary to denote such a string by writing the characters down next to each other and enclosing them in quotes. We will use single quotes. Thus ‘$cat$’ is another notation for the string $\langle c,a,t\rangle$. We specifically regard ‘$cat$’ and $\langle c,a,t\rangle$ as the same mathematical object written using two different notations.

110.1.3 Remarks

a) Note carefully that ‘$cat$’ is a string, “cat” is an English word, and a cat is a mammal! Similarly, ‘52’ is a string and 52 is a number.

b) The alphabet can be any set of characters. For example ‘0101’ is a string in the alphabet of binary digits.

110.2 Concatenation of strings

In string notation, concatenation is simply juxtaposition: to say that the concatenate of ‘$cat$’ and ‘$ch$’ is ‘$catch$’, we write

$$\text{‘}cat\text{’‘}ch\text{’} = \text{‘}catch\text{’}$$

Strings are often denoted by lowercase letters, particularly those late in the alphabet. For example, let $w=$ ‘$cat$’ and $x=$ ‘$doggie$’. Then $wx=$ ‘$catdoggie$’, $ww=$ ‘$catcat$’ and $xw=$ ‘$doggiecat$’. It is very important to distinguish $w$, which here is the name of a string, from ‘$w$’ which is a string of length one.

110.3 The empty string

The empty string could be denoted ‘’, but this makes it hard to read, so we will follow common practice and use a symbol to denote the empty string. In this text, the symbol will be Λ. Other texts use $\epsilon$ or 0.

110.3.1 Example Λ‘$abba$’ = ‘$abba$’ = ‘$abba$’Λ, and ΛΛ = Λ.

110.3.2 Remark Note carefully that ‘$cat$’ is a string, but that “Λ” is the name of a string.

110.4 Exponential notation for concatenation

To designate a string concatenated with itself several times an exponential notation is used. If $w$ is a string, $w^{n}$ is the concatenate of the string $w$ with itself $n$ times.

110.4.1 Example Let $w=$ ‘0110’. Then it follows that

$$w^{2}= \text{‘01100110’} \quad\text{and}\quad w^{3}= \text{‘011001100110’}$$

Note in particular that ‘0’ $^{3}=$ ‘000’ and ‘1’ $^{2}$‘0’ $^{4}=$ ‘110000’. We always take $w^{1} =w$ and $w^{0}=$ Λ.

110.4.2 Exercise Find the concatenate $wx$ if

a) $w=$ ‘011’, $x=$ ‘1010’

b) $w=\Lambda$, $x=$ ‘011’

c) $w=$ ‘011’, $x=\Lambda$.

d) $w =x=\Lambda$.

e) $w=$ ‘011’, $x =w^{2}$.

f) $x=$ ‘011’, $w =x^{2}$.

(Answer on page 249.)

110.4.3 Exercise Let $A =\{a,b\}$ and let $E$ be the set of strings in $A^{*}$ of even length. Give an inductive definition of $E$. (Answer on page 249.)

110.4.4 Exercise Give an inductive definition of the set of strings in $\{a,b\}$ of odd length.

110.4.5 Exercise Give an inductive definition of the $k$th entry of a string. It should exist for strings of length $k$ or greater but not for strings of length less than $k$. Follow the pattern of the answer to Exercise 109.8.2, using cons.

110.4.6 Exercise Give an inductive definition of $w^{n}$ for an arbitrary string $w$. The induction should be on $n$.

Pages 167–168 of the book (PDF).