In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, [1] [2] or reduction systems). In their most basic form, they consist of a set of objects, plus relations on how to transform those objects.
Rewriting can be non-deterministic. One rule to rewrite a term could be applied in many different ways to that term, or more than one rule could be applicable. Rewriting systems then do not provide an algorithm for changing one term to another, but a set of possible rule applications. When combined with an appropriate algorithm, however, rewrite systems can be viewed as computer programs, and several theorem provers [3] and declarative programming languages are based on term rewriting. [4] [5]
In logic, the procedure for obtaining the conjunctive normal form (CNF) of a formula can be implemented as a rewriting system. [6] The rules of an example of such a system would be:
where the symbol () indicates that an expression matching the left hand side of the rule can be rewritten to one formed by the right hand side, and the symbols each denote a subexpression. In such a system, each rule is chosen so that the left side is equivalent to the right side, and consequently when the left side matches a subexpression, performing a rewrite of that subexpression from left to right maintains logical consistency and value of the entire expression.
Term rewriting systems can be employed to compute arithmetic operations on natural numbers. To this end, each such number has to be encoded as a term. The simplest encoding is the one used in the Peano axioms, based on the constant 0 (zero) and the successor function S. For example, the numbers 0, 1, 2, and 3 are represented by the terms 0, S(0), S(S(0)), and S(S(S(0))), respectively. The following term rewriting system can then be used to compute sum and product of given natural numbers. [7]
For example, the computation of 2+2 to result in 4 can be duplicated by term rewriting as follows:
where the rule numbers are given above the rewrites-to arrow.
As another example, the computation of 2⋅2 looks like:
where the last step comprises the previous example computation.
In linguistics, phrase structure rules, also called rewrite rules, are used in some systems of generative grammar, [8] as a means of generating the grammatically correct sentences of a language. Such a rule typically takes the form , where A is a syntactic category label, such as noun phrase or sentence, and X is a sequence of such labels or morphemes, expressing the fact that A can be replaced by X in generating the constituent structure of a sentence. For example, the rule means that a sentence can consist of a noun phrase (NP) followed by a verb phrase (VP); further rules will specify what sub-constituents a noun phrase and a verb phrase can consist of, and so on.
From the above examples, it is clear that we can think of rewriting systems in an abstract manner. We need to specify a set of objects and the rules that can be applied to transform them. The most general (unidimensional) setting of this notion is called an abstract reduction system [9] or abstract rewriting system (abbreviated ARS). [10] An ARS is simply a set A of objects, together with a binary relation → on A called the reduction relation, rewrite relation [11] or just reduction. [9]
Many notions and notations can be defined in the general setting of an ARS. is the reflexive transitive closure of . is the symmetric closure of . is the reflexive transitive symmetric closure of . The word problem for an ARS is determining, given x and y, whether . An object x in A is called reducible if there exists some other y in A such that ; otherwise it is called irreducible or a normal form. An object y is called a "normal form of x" if , and y is irreducible. If the normal form of x is unique, then this is usually denoted with . If every object has at least one normal form, the ARS is called normalizing. or x and y are said to be joinable if there exists some z with the property that . An ARS is said to possess the Church–Rosser property if implies . An ARS is confluent if for all w, x, and y in A, implies . An ARS is locally confluent if and only if for all w, x, and y in A, implies . An ARS is said to be terminating or noetherian if there is no infinite chain . A confluent and terminating ARS is called convergent or canonical.
Important theorems for abstract rewriting systems are that an ARS is confluent iff it has the Church–Rosser property, Newman's lemma (a terminating ARS is confluent if and only if it is locally confluent), and that the word problem for an ARS is undecidable in general.
A string rewriting system (SRS), also known as semi-Thue system, exploits the free monoid structure of the strings (words) over an alphabet to extend a rewriting relation, , to all strings in the alphabet that contain left- and respectively right-hand sides of some rules as substrings. Formally a semi-Thue system is a tuple where is a (usually finite) alphabet, and is a binary relation between some (fixed) strings in the alphabet, called the set of rewrite rules. The one-step rewriting relation induced by on is defined as: if are any strings, then if there exist such that , , and . Since is a relation on , the pair fits the definition of an abstract rewriting system. Since the empty string is in , is a subset of . If the relation is symmetric, then the system is called a Thue system.
In a SRS, the reduction relation is compatible with the monoid operation, meaning that implies for all strings . Similarly, the reflexive transitive symmetric closure of , denoted , is a congruence, meaning it is an equivalence relation (by definition) and it is also compatible with string concatenation. The relation is called the Thue congruence generated by . In a Thue system, i.e. if is symmetric, the rewrite relation coincides with the Thue congruence .
The notion of a semi-Thue system essentially coincides with the presentation of a monoid. Since is a congruence, we can define the factor monoid of the free monoid by the Thue congruence. If a monoid is isomorphic with , then the semi-Thue system is called a monoid presentation of .
We immediately get some very useful connections with other areas of algebra. For example, the alphabet with the rules , where is the empty string, is a presentation of the free group on one generator. If instead the rules are just , then we obtain a presentation of the bicyclic monoid. Thus semi-Thue systems constitute a natural framework for solving the word problem for monoids and groups. In fact, every monoid has a presentation of the form , i.e. it may always be presented by a semi-Thue system, possibly over an infinite alphabet.
The word problem for a semi-Thue system is undecidable in general; this result is sometimes known as the Post–Markov theorem. [12]
A term rewriting system (TRS) is a rewriting system whose objects are terms , which are expressions with nested sub-expressions. For example, the system shown under § Logic above is a term rewriting system. The terms in this system are composed of binary operators and and the unary operator . Also present in the rules are variables, which represent any possible term (though a single variable always represents the same term throughout a single rule).
In contrast to string rewriting systems, whose objects are sequences of symbols, the objects of a term rewriting system form a term algebra. A term can be visualized as a tree of symbols, the set of admitted symbols being fixed by a given signature. As a formalism, term rewriting systems have the full power of Turing machines, that is, every computable function can be defined by a term rewriting system. [13]
Some programming languages are based on term rewriting. One such example is Pure, a functional programming language for mathematical applications. [14] [15]
A rewrite rule is a pair of terms, commonly written as , to indicate that the left-hand side l can be replaced by the right-hand side r. A term rewriting system is a set R of such rules. A rule can be applied to a term s if the left term l matches some subterm of s, that is, if there is some substitution such that the subterm of rooted at some position p is the result of applying the substitution to the term l. The subterm matching the left hand side of the rule is called a redex or reducible expression. [16] The result term t of this rule application is then the result of replacing the subterm at position p in s by the term with the substitution applied, see picture 1. In this case, is said to be rewritten in one step, or rewritten directly, to by the system , formally denoted as , , or as by some authors.
If a term can be rewritten in several steps into a term , that is, if , the term is said to be rewritten to , formally denoted as . In other words, the relation is the transitive closure of the relation ; often, also the notation is used to denote the reflexive-transitive closure of , that is, if or . [17] A term rewriting given by a set of rules can be viewed as an abstract rewriting system as defined above, with terms as its objects and as its rewrite relation.
For example, is a rewrite rule, commonly used to establish a normal form with respect to the associativity of . That rule can be applied at the numerator in the term with the matching substitution , see picture 2. [note 2] Applying that substitution to the rule's right-hand side yields the term , and replacing the numerator by that term yields , which is the result term of applying the rewrite rule. Altogether, applying the rewrite rule has achieved what is called "applying the associativity law for to " in elementary algebra. Alternately, the rule could have been applied to the denominator of the original term, yielding .
Termination issues of rewrite systems in general are handled in Abstract rewriting system#Termination and convergence . For term rewriting systems in particular, the following additional subtleties are to be considered.
Termination even of a system consisting of one rule with a linear left-hand side is undecidable. [18] [19] Termination is also undecidable for systems using only unary function symbols; however, it is decidable for finite ground systems. [20]
The following term rewrite system is normalizing, [note 3] but not terminating, [note 4] and not confluent: [21]
The following two examples of terminating term rewrite systems are due to Toyama: [22]
and
Their union is a non-terminating system, since
This result disproves a conjecture of Dershowitz, [23] who claimed that the union of two terminating term rewrite systems and is again terminating if all left-hand sides of and right-hand sides of are linear, and there are no "overlaps" between left-hand sides of and right-hand sides of . All these properties are satisfied by Toyama's examples.
See Rewrite order and Path ordering (term rewriting) for ordering relations used in termination proofs for term rewriting systems.
Higher-order rewriting systems are a generalization of first-order term rewriting systems to lambda terms, allowing higher order functions and bound variables. [24] Various results about first-order TRSs can be reformulated for HRSs as well. [25]
Graph rewrite systems are another generalization of term rewrite systems, operating on graphs instead of (ground-) terms / their corresponding tree representation.
Trace theory provides a means for discussing multiprocessing in more formal terms, such as via the trace monoid and the history monoid. Rewriting can be performed in trace systems as well.
In probability theory, the central limit theorem (CLT) states that, under appropriate conditions, the distribution of a normalized version of the sample mean converges to a standard normal distribution. This holds even if the original variables themselves are not normally distributed. There are several versions of the CLT, each applying in the context of different conditions.
In probability theory, there exist several different notions of convergence of sequences of random variables, including convergence in probability, convergence in distribution, and almost sure convergence. The different notions of convergence capture different properties about the sequence, with some notions of convergence being stronger than others. For example, convergence in distribution tells us about the limit distribution of a sequence of random variables. This is a weaker notion than convergence in probability, which tells us about the value a random variable will take, rather than just the distribution.
In computer science, an LL parser is a top-down parser for a restricted context-free language. It parses the input from Left to right, performing Leftmost derivation of the sentence.
Homological algebra is the branch of mathematics that studies homology in a general algebraic setting. It is a relatively young discipline, whose origins can be traced to investigations in combinatorial topology and abstract algebra at the end of the 19th century, chiefly by Henri Poincaré and David Hilbert.
In mathematics, the term homology, originally introduced in algebraic topology, has three primary, closely-related usages. The most direct usage of the term is to take the homology of a chain complex, resulting in a sequence of abelian groups called homology groups. This operation, in turn, allows one to associate various named homologies or homology theories to various other types of mathematical objects. Lastly, since there are many homology theories for topological spaces that produce the same answer, one also often speaks of the homology of a topological space. There is also a related notion of the cohomology of a cochain complex, giving rise to various cohomology theories, in addition to the notion of the cohomology of a topological space.
In algebraic topology, singular homology refers to the study of a certain set of algebraic invariants of a topological space X, the so-called homology groups Intuitively, singular homology counts, for each dimension n, the n-dimensional holes of a space. Singular homology is a particular example of a homology theory, which has now grown to be a rather broad collection of theories. Of the various theories, it is perhaps one of the simpler ones to understand, being built on fairly concrete constructions.
In algebraic topology, a branch of mathematics, a spectrum is an object representing a generalized cohomology theory. Every such cohomology theory is representable, as follows from Brown's representability theorem. This means that, given a cohomology theory
,
In mathematics, cellular homology in algebraic topology is a homology theory for the category of CW-complexes. It agrees with singular homology, and can provide an effective means of computing homology modules.
In theoretical computer science and mathematical logic a string rewriting system (SRS), historically called a semi-Thue system, is a rewriting system over strings from a alphabet. Given a binary relation between fixed strings over the alphabet, called rewrite rules, denoted by , an SRS extends the rewriting relation to all strings in which the left- and right-hand side of the rules appear as substrings, that is , where , , , and are strings.
A bond graph is a graphical representation of a physical dynamic system. It allows the conversion of the system into a state-space representation. It is similar to a block diagram or signal-flow graph, with the major difference that the arcs in bond graphs represent bi-directional exchange of physical energy, while those in block diagrams and signal-flow graphs represent uni-directional flow of information. Bond graphs are multi-energy domain and domain neutral. This means a bond graph can incorporate multiple domains seamlessly.
In computational mathematics, a word problem is the problem of deciding whether two given expressions are equivalent with respect to a set of rewriting identities. A prototypical example is the word problem for groups, but there are many other instances as well. A deep result of computational theory is that answering this question is in many important cases undecidable.
String diagrams are a formal graphical language for representing morphisms in monoidal categories, or more generally 2-cells in 2-categories. They are a prominent tool in applied category theory. When interpreted in the monoidal category of vector spaces and linear maps with the tensor product, string diagrams are called tensor networks or Penrose graphical notation. This has led to the development of categorical quantum mechanics where the axioms of quantum theory are expressed in the language of monoidal categories.
In algebraic topology the cap product is a method of adjoining a chain of degree p with a cochain of degree q, such that q ≤ p, to form a composite chain of degree p − q. It was introduced by Eduard Čech in 1936, and independently by Hassler Whitney in 1938.
In algebra, a presentation of a monoid is a description of a monoid in terms of a set Σ of generators and a set of relations on the free monoid Σ∗ generated by Σ. The monoid is then presented as the quotient of the free monoid by these relations. This is an analogue of a group presentation in group theory.
In algebraic topology, the pushforward of a continuous function : between two topological spaces is a homomorphism between the homology groups for .
A formal grammar describes which strings from an alphabet of a formal language are valid according to the language's syntax. A grammar does not describe the meaning of the strings or what can be done with them in whatever context—only their form. A formal grammar is defined as a set of production rules for such strings in a formal language.
Controlled grammars are a class of grammars that extend, usually, the context-free grammars with additional controls on the derivations of a sentence in the language. A number of different kinds of controlled grammars exist, the four main divisions being Indexed grammars, grammars with prescribed derivation sequences, grammars with contextual conditions on rule application, and grammars with parallelism in rule application. Because indexed grammars are so well established in the field, this article will address only the latter three kinds of controlled grammars.
In probability theory, the Doob–Dynkin lemma, named after Joseph L. Doob and Eugene Dynkin, characterizes the situation when one random variable is a function of another by the inclusion of the -algebras generated by the random variables. The usual statement of the lemma is formulated in terms of one random variable being measurable with respect to the -algebra generated by the other.
In mathematics and theoretical computer science, a pattern is an unavoidable pattern if it is unavoidable on any finite alphabet.
In quantum computing, Mølmer–Sørensen gate scheme refers to an implementation procedure for various multi-qubit quantum logic gates used mostly in trapped ion quantum computing. This procedure is based on the original proposition by Klaus Mølmer and Anders Sørensen in 1999-2000.