An alphabet is a finite nonempty set of symbols. A word over an alphabet is a finite sequence of symbols from , including the empty word ; the set of all words is . A formal language over is any subset .
A regular expression is defined recursively from , , and the individual symbols by the operations of finite union, concatenation, and Kleene star. Its language is defined by
There are only countably many regular expressions: each is a finite word over a finite collection of symbols and punctuation. On the other hand, for every nonempty finite alphabet, is countably infinite, so its power set is uncountable by the Cantor theorem. Thus there are uncountably many languages but only countably many languages denoted by regular expressions. Consequently
A context-free grammar is a quadruple consisting of a finite set of nonterminal symbols, a disjoint finite alphabet of terminal symbols, a start symbol , and a finite set of productions with and . A sentence is a terminal word over an alphabet with , and the generated formal language is .
The first language is context-free. For example, the productions
generate exactly : each recursive production adds two s to the left and two s to the right.
Use the following context-free grammar, with start symbol :
The symbol generates the balanced members of the suffix-nonnegative binary language, while permits extra zeros. To prove the claim and prepare the ambiguity argument, reverse every generated string. The reversed productions are
Here represents the reversals of the strings, and represents the reversals of the strings. A string belongs to the desired formal language precisely when its reversal has no string prefix with more ones than zeros. Associate a path with each reversed string, counting a zero as a step and a one as a step .
The nonterminal generates exactly the paths that stay nonnegative and finish at zero. The production consists of an initial up-step, a balanced path one level higher, a down-step to zero, and another balanced path. Conversely, any nonempty balanced nonnegative path has a first return to zero, and splitting there gives exactly this form. Mathematical induction on length proves the characterization.
The productions for generate nonnegative paths: stays strictly above zero after its first step, while first executes a balanced excursion and then another nonnegative path. Conversely, a nonempty nonnegative path starts with zero. If it never returns to height zero, removing that initial zero leaves a nonnegative path, giving . If it does return, split at its first return to obtain . These shorter components can be generated by mathematical induction. This proves that the original context-free grammar generates exactly the required formal language.
For instance, in the original context-free grammar,
while . The string is excluded since its entire length is a string suffix having two ones and only one zero.
The assertion is true. Every single finite string over is denoted by the regular expression . The empty string is denoted by . Hence if is a finite formal language, the regular expression
denotes precisely , with each read as its concatenation of symbols. This uses the defining union and concatenation operations for regular expressions. For , use the regular expression . Therefore
The assertion is false. Use the pumping lemma for regular languages: if is a regular language, there is such that every with admits a factorization with , , and for every integer .
Suppose the stated formal language were a regular language, and take . This string has twice as many zeros as ones, so it belongs to . In every allowed factorization, the first positions are all zeros, forcing with . Pumping down with produces
It still has ones but fewer than zeros, contradicting the pumping lemma for regular languages. Thus
The assertion is false. Suppose the formal language were a regular language, and let be its constant from the pumping lemma for regular languages. Consider
In every decomposition with and , the pumped factor is with . Pumping down gives
This string has exactly two ones and ends in a one. If it were , each copy of would contain exactly one one, and each copy would end in a one. The first copy would consequently be , while the second would be . They have different lengths because , so they cannot be equal. This contradiction to the pumping lemma for regular languages proves
A Turing machine has a finite control, an unbounded tape divided into cells over a finite tape alphabet including a blank symbol, and a head that reads one cell at a time. For a deterministic Turing machine, the current state and scanned symbol determine the replacement symbol, a head move one cell left or right, and the next state. The input occupies finitely many cells initially; all other cells are blank. Distinguished halting states report acceptance or rejection.
A formal language is a decidable language if some Turing machine halts on every input string, accepting exactly the members and rejecting all nonmembers:
Halting on the nonmembers is part of the requirement; a machine that merely runs forever on some nonmembers need not decide the formal language.
The halting problem asks, given the encoding of a Turing machine and an input string, whether that machine eventually halts on that input. Its formal language is
Suppose a Turing machine decided this formal language. Construct another Turing machine that, on an input encoding , runs on . If answers that halts on its own encoding, enters an infinite loop. If answers that does not halt, halts. Handling malformed encodings by immediate rejection makes well-defined on arbitrary strings.
Now run on its own encoding. If says that halts, the construction makes loop; if says that does not halt, the construction makes halt. Either answer contradicts the assumed correctness of . Therefore
The contradiction concerns a decider that must give a correct terminating answer for every encoded machine and input. Simulating does detect a halt when one occurs, but cannot in general certify that a running computation will continue forever.
A regular language over a finite alphabet is a formal language recognized by a deterministic finite automaton; equivalently it is described by a regular expression. A nondeterministic finite automaton accepts an input string if at least one permitted computation consumes that string and reaches an accepting state. The connection is the equivalence
Every deterministic finite automaton is a special case of a nondeterministic finite automaton. Conversely, the subset construction makes a deterministic finite automaton whose states record the set of all possible current states of a nondeterministic finite automaton. After each input symbol, update that set by taking all permitted transitions, also including any epsilon closure. A new state is accepting exactly when it contains an old accepting state. A finite state set has finitely many subsets, so this really is a deterministic finite automaton recognizing the same formal language.
These strings are the even-length palindromes . Suppose this were a regular language, and let be its length from the pumping lemma for regular languages. The string
belongs to the formal language, with . In any allowed decomposition , where and , the pumped block is with . Pumping it away gives
This is not a palindrome: its initial and final runs of zeros have different lengths. Hence it cannot have the form , contradicting the pumping lemma for regular languages. Therefore
Every finite formal language is a regular language. A single string is described by the regular expression formed by concatenating its symbols; the empty string is described by . A finite union of these regular expressions describes any specified finite collection of strings. The empty collection is described by . Thus
Equivalently, a deterministic finite automaton can remember which prefix of one of the finitely many accepted strings has been read, moving to a rejecting dead state when no such prefix remains possible.
Let , and suppose it were a regular language. The formal language is a regular language. By closure of regular languages under set difference,
would be a regular language. But the pumping lemma for regular languages rules this out: for pumping length , every permitted pumped block in consists of zeros, and deleting it produces , with unequal counts. This contradiction proves
The closure step can also be realized by a product automaton accepting when the automaton for accepts and the automaton for rejects. If the exponents are instead required to be positive, use ; the same argument applies.
A context-free grammar is a quadruple : is a finite set of nonterminal symbols, is a disjoint finite alphabet of terminal symbols, is the start symbol, and is a finite set of productions , with and . Its formal language consists of the terminal strings derivable from .
For the even-length palindromes in (b)(ii), take terminal alphabet and the context-free grammar
Every production adds identical symbols at the two ends, so every generated string is an even-length palindrome. Conversely, remove the matching outer pair of any nonempty even-length palindrome and repeat; this constructs its derivation, ending with .
For the unequal-block formal language in (b)(iv), use
After uses of , and zeros from , the resulting string is , so its zero count is larger. Every such unequal pair with occurs by choosing . Similarly generates exactly with , covering precisely . The start alternatives cover both possibilities and never equal counts. If positive exponents are required, replace the start productions by , which adds one matched pair and ensures both counts are positive.
Give a nonhalting Turing machine computation halting time infinity. The formal language of pairs satisfying the displayed inequality is a co-recursively enumerable language but is not a recursively enumerable language. A violation has a finite witness: has halted on some input after moves while has not halted by that time. For the other direction, reduce non-halting by making simulate a fixed computation on every input and making run forever. The pair satisfies domination exactly when the fixed computation never halts. The convention is essential to this many-one reduction.
The positive closure of a formal language is the language of all concatenations of one or more words from :
Here is -fold concatenation of formal languages, while the Kleene star also permits , whose contribution is the empty word . Thus .
For , positive closure is . If , then as well: positive counts chosen words, not their total character length. For the empty language, but . This operation preserves regular languages and is one of the closure requirements in an abstract family of languages.
Recursive language Created 2026-10-05 Updated 2026-10-06
A formal language is decidable if a Turing machine halts on every input and correctly determines membership. Equivalently its encoded words form a recursive set. A computably enumerable language requires only a machine that eventually accepts every member; it may run forever on nonmembers.
Sentential form 2026-11-05
A sentential form of a formal grammar is any word derivable from the start symbol: . It may contain both terminal symbols and nonterminal symbols. A terminal-only sentential form is a word of the generated formal language.
For productions and , the derivation contains four sentential forms. The intermediate is not a sentence of the terminal language because remains. An arbitrary word over need not be a sentential form: it must actually be reachable by a grammar derivation.
Tracking sentential forms makes it possible to discuss intermediate parsing states and distinguish leftmost derivations from other orders of rewriting. The word need not be a complete output or a prefix of one in an arbitrary grammar.
Seymour Ginsburg 2026-11-05
Seymour Ginsburg coauthored the 1969 studies of the abstract family of languages framework with Sheila Greibach and John Hopcroft. This approach compares formal-language classes through closure properties instead of one particular grammar or machine presentation.[ref]
For example, closure under intersection with regular languages permits restricting an existing language by a finite-state filter. That property is weaker than closure under arbitrary intersections: two context-free languages can have a non-context-free intersection. Stating the allowed operation precisely keeps a shared abstract framework from incorrectly identifying different language classes.
Shuffle of formal languages Created 2026-10-06 Updated 2026-10-31
The shuffle of two formal languages consists of words whose positions can be partitioned into two subsequences, each preserving its order, with the two resulting words belonging to the respective languages. For regular languages, a product-state nondeterministic finite automaton advances exactly one coordinate for each letter. Common letters allow either choice; the powerset construction proves closure.
A Turing machine with one read-write tape. Every multitape Turing machine can be simulated by a single-tape Turing machine, using delimited tape portions and marked head positions. The simulation preserves the accepted formal language and whether a computation halts, while possibly increasing time complexity.