# Formal language

In mathematics, logic and computer science, a formal language is a set of finite-length words (i.e. character strings) drawn from some finite alphabet, and the scientific theory that deals with these entities is known as formal language theory. Note that we can talk about formal language in many contexts (scientific, legal, linguistic and so on), meaning a mode of expression more careful and accurate, or more mannered than everyday speech. The sense of formal language dealt with in this article is the precise sense studied in formal language theory.

An alphabet might be [itex]\left \{ a , b \right \}[itex], and a string over that alphabet might be [itex]ababba[itex].

A typical language over that alphabet, containing that string, would be the set of all strings which contain the same number of symbols [itex]a[itex] and [itex]b[itex].

The empty word (that is, length-zero string) is allowed and is often denoted by [itex]e[itex], [itex]\epsilon[itex] or [itex]\Lambda[itex]. While the alphabet is a finite set and every string has finite length, a language may very well have infinitely many member strings (because the length of words in it may be unbounded).

Some examples of formal languages:

• the set of all words over [itex]{a, b}[itex]
• the set [itex]\left \{ a^{n}\right\}[itex], n is a prime number and [itex]a^{n}[itex] means [itex]a[itex] repeated [itex]n[itex] times
• the set of syntactically correct programs in a given programming language; or
• the set of inputs upon which a certain Turing machine halts.

A formal language can be specified in a great variety of ways, such as:

Several operations can be used to produce new languages from given ones. Suppose [itex]L_{1}[itex] and [itex]L_{2}[itex] are languages over some common alphabet.

• The concatenation [itex]L_{1}L_{2}[itex] consists of all strings of the form [itex]vw[itex] where [itex]v[itex] is a string from [itex]L_{1}[itex] and [itex]w[itex] is a string from [itex]L_{2}[itex].
• The intersection [itex]L_1 \cap L_2[itex] of [itex]L_{1}[itex] and [itex]L_{2}[itex] consists of all strings which are contained in [itex]L_1[itex] and also in [itex]L_{2}[itex].
• The union [itex]L_1 \cup L_2[itex] of [itex]L_{1}[itex] and [itex]L_{2}[itex] consists of all strings which are contained in [itex]L_{1}[itex] or in [itex]L_{2}[itex].
• The complement of the language [itex]L_{1}[itex] consists of all strings over the alphabet which are not contained in [itex]L_{1}[itex].
• The right quotient [itex]L_{1}/L_{2}[itex] of [itex]L_{1}[itex] by [itex]L_{2}[itex] consists of all strings [itex]v[itex] for which there exists a string [itex]w[itex] in [itex]L_{2}[itex] such that [itex]vw[itex] is in [itex]L_{1}[itex].
• The Kleene star [itex]L_{1}^{*}[itex] consists of all strings which can be written in the form [itex]w_{1}w_{2}...w_{n}[itex] with strings [itex]w_{i}[itex] in [itex]L_{1}[itex] and [itex]n \ge 0[itex]. Note that this includes the empty string [itex]\epsilon[itex] because [itex]n = 0[itex] is allowed.
• The reverse [itex]L_{1}^{R}[itex] contains the reversed versions of all the strings in [itex]L_{1}[itex].
• The shuffle of [itex]L_{1}[itex] and [itex]L_{2}[itex] consists of all strings which can be written in the form [itex]v_{1}w_{1}v_{2}w_{2}...v_{n}w_{n}[itex] where [itex]n \ge 1[itex] and [itex]v_{1},...,v_{n}[itex] are strings such that the concatenation [itex]v_{1}...v_{n}[itex] is in [itex]L_{1}[itex] and [itex]w_{1},...,w_{n}[itex] are strings such that [itex]w_{1}...w_{n}[itex] is in [itex]L_{2}[itex].

A question often asked about formal languages is "how difficult is it to decide whether a given word belongs to the language?" This is the domain of computability theory and complexity theory.

• Art and Cultures
• Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
• Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
• Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
• Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
• Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
• United States (http://www.academickids.com/encyclopedia/index.php/United_States)
• World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
• Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
• Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
• Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
• Space and Astronomy
• Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)