ArticleslgStudy

mathematics

String operations

String operations is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand String operations rather than just read about it. In short: In computer science, in the area of formal language theory, frequent use is made of a variety of string functions; however, the notation used is different from that used for computer programming, and some commonly used functions in the theoretical realm are rarely used when programming. This article defines some of these basic terms.

Key takeaways

  • String operations belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect String operations to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of String operations from memory before moving on to harder problems.

Reference excerpt

In computer science, in the area of formal language theory, frequent use is made of a variety of string functions; however, the notation used is different from that used for computer programming, and some commonly used functions in the theoretical realm are rarely used when programming. This article defines some of these basic terms.

Strings and languages A string is a finite sequence of characters. The empty string is denoted by ε. The concatenation of two strings s and t is denoted by s⋅t, or shorter by st. Concatenating with the empty string makes no difference: s⋅ε=s=ε⋅s. Concatenation of strings is associative: s⋅(t⋅u)=(s⋅t)⋅u. For example, (⟨b⟩⋅⟨l⟩)⋅(ε⋅⟨ah⟩)=⟨bl⟩⋅⟨ah⟩=⟨blah⟩. A language is a finite or infinite set of strings. Besides the usual set operations like union, intersection etc., concatenation can be applied to languages: if both S and T are languages, their concatenation S⋅T is defined as the set of concatenations of any string from S and any string from T, formally S⋅T={s⋅t∣s∈S∧t∈T}. Again, the concatenation dot ⋅ is often omitted for brevity. The language {ε} consisting of just the empty string is to be distinguished from the empty language {}. Concatenating any language with the former doesn't make any change: S⋅{ε}=S={ε}⋅S, while concatenating with the latter always yields the empty language: S⋅{}={}={}⋅S. Concatenation of languages is associative: S⋅(T⋅U)=(S⋅T)⋅U. For example, abbreviating D={⟨0⟩,⟨1⟩,⟨2⟩,⟨3⟩,⟨4⟩,⟨5⟩,⟨6⟩,⟨7⟩,⟨8⟩,⟨9⟩}, the set of all three-digit decimal numbers is obtained as D⋅D⋅D. The set of all decimal numbers of arbitrary length is an example for an infinite language.

Alphabet of a string The alphabet of a string is the set of all of the characters that occur in a particular string. If s is a string, its alphabet is denoted by

Alph⁡(s) The alphabet of a language S is the set of all characters that occur in any string of S, formally: Alph⁡(S)=⋃s∈SAlph⁡(s). For example, the set {⟨a⟩,⟨c⟩,⟨o⟩} is the alphabet of the string ⟨cacao⟩, and the above D is the alphabet of the above language D⋅D⋅D as well as of the language of all decimal numbers.

String substitution Let L be a language, and let Σ be its alphabet. A string substitution or simply a substitution is a mapping f that maps characters in Σ to languages (possibly in a different alphabet). Thus, for example, given a character a ∈ Σ, one has f(a)=La where La ⊆ Δ* is some language whose alphabet is Δ. This mapping may be extended to strings as

f(ε)=ε for the empty string ε, and

f(sa)=f(s)f(a) for string s ∈ L and character a ∈ Σ. String substitutions may be extended to entire languages as

f(L)=⋃s∈Lf(s) Regular languages are closed under string substitution. That is, if each character in the alphabet of a regular language is substituted by another regular language, the result is still a regular language. Similarly, context-free languages are closed under string substitution. A simple example is the conversion fuc(.) to uppercase, which may be defined e.g. as follows:

For the extension of fuc to strings, we have e.g.

fuc(‹Straße›) = {‹S›} ⋅ {‹T›} ⋅ {‹R›} ⋅ {‹A›} ⋅ {‹SS›} ⋅ {‹E›} = {‹STRASSE›}, fuc(‹u2›) = {‹U›} ⋅ {ε} = {‹U›}, and fuc(‹Go!›) = {‹G›} ⋅ {‹O›} ⋅ {} = {}. For the extension of fuc to languages, we have e.g.

fuc({ ‹Straße›, ‹u2›, ‹Go!› }) = { ‹STRASSE› } ∪ { ‹U› } ∪ { } = { ‹STRASSE›, ‹U› }.

String homomorphism A string homomorphism (often referred to simply as a homomorphism in formal language theory) is a string substitution such that each character is replaced by a single string. That is, f(a)=s, where s is a string, for each character a. String homomorphisms are monoid morphisms on the free monoid, preserving the empty string and the binary operation of string concatenation. Given a language L, the set f(L) is called the homomorphic image of L. The inverse homomorphic image of a string s is defined as f−1(s)={w∣f(w)=s} while the inverse homomorphic image of a language L is defined as f−1(L)={s∣f(s)∈L} In general, f(f−1(L))≠L, while one does have f(f−1(L))⊆L and L⊆f−1(f(L)) for any language L. The class of regular languages is closed under homomorphisms and inverse homomorphisms. Similarly, the context-free languages are closed under homomorphisms and inverse homomorphisms. A string homomorphism is said to be ε-free (or e-free) if f(a)≠ε for all a in the alphabet Σ. Simple single-letter substitution ciphers are examples of (ε-free) string homomorphisms. An example string homomorphism guc can also be obtained by defining similar to the above substitution: guc(‹a›) = ‹A›, ..., guc(‹0›) = ε, but letting guc be undefined on punctuation chars. Examples for inverse homomorphic images are

guc−1({ ‹SSS› }) = { ‹sss›, ‹sß›, ‹ßs› }, since guc(‹sss›) = guc(‹sß›) = guc(‹ßs›) = ‹SSS›, and guc−1({ ‹A›, ‹bb› }) = { ‹a› }, since guc(‹a›) = ‹A›, while ‹bb› cannot be reached by guc. For the latter language, guc(guc−1({ ‹A›, ‹bb› })) = guc({ ‹a› }) = { ‹A› } ≠ { ‹A›, ‹bb› }. The homomorphism guc is not ε-free, since it maps e.g. ‹0› to ε. A very simple string homomorphism example that maps each character to just a character is the conversion of an EBCDIC-encoded string to ASCII.

String projection If s is a string, and Σ is an alphabet, the string projection of s is the string that results by removing all characters that are not in Σ. It is written as πΣ(s). It is formally defined by removal of characters from the right hand side:

πΣ(s)={εif s=ε the empty stringπΣ(t)if s=ta and a∉ΣπΣ(t)aif s=ta and a∈Σ Here ε denotes the empty string. The projection of a string is essentially the same as a projection in relational algebra. String projection may be promoted to the projection of a language. Given a formal language L, its projection is given by

πΣ(L)={πΣ(s) | s∈L}

Right and left quotient The right quotient of a character a from a string s is the truncation of the character a in the string s, from the right-hand side. It is denoted as s/a. If the string does not have a on the right hand side, the result is the empty string. Thus:

(sa)/b={sif a=bεif a≠b The quotient of the empty string may be taken:

ε/a=ε Similarly, given a subset S⊂M of a monoid M, one may define the quotient subset as

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with String operations

Start with the simplest possible case. Write down what String operations claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to String operations before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about String operations ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of String operations

In research
String operations appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses String operations in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
String operations is common in secondary-school and first-year university syllabi. It links to neighbouring topics Formal languages, Relational algebra, String (computer science), so understanding it makes those chapters shorter.
In everyday life
Look for String operations outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “String operations” →

How to study String operations in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what String operations means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain String operations out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is String operations in simple terms?

In computer science, in the area of formal language theory, frequent use is made of a variety of string functions; however, the notation used is different from that used for computer programming, and some commonly used functions in the theoretical realm are rarely used when programming. This articl…

Why does String operations matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study String operations?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on String operations.

Tags

  • Formal languages
  • Relational algebra
  • String (computer science)

Keep exploring