Brzozowski derivative

From testwiki
Jump to navigation Jump to search

Template:Short description

Brzozowski derivative (on red background) of a dictionary string set with respect to the string "con"

In theoretical computer science, particularly in formal language theory, the Brzozowski derivative u−1S of a set S of strings and a string u is the set of all strings obtainable from a string in S by cutting off the prefix u. Formally:

u−1S={v∈Σ∗∣uv∈S}.

For example,

c−1{cat,cow,dog}={at,ow}.

The Brzozowski derivative was introduced under various different names since the late 1950s.[1][2][3] Today it is named after the computer scientist Janusz Brzozowski who investigated its properties and gave an algorithm to compute the derivative of a generalized regular expression.[4]

Definition

Even though originally studied for regular expressions, the definition applies to arbitrary formal languages. Given any formal language S over an alphabet Σ and any string u∈Σ∗, the derivative of S with respect to u is defined as:[4]

u−1S={v∈Σ∗∣uv∈S}

The Brzozowski derivative is a special case of left quotient by a singleton set containing only u:  u−1S={u}∖S.

Equivalently, for all u,v∈Σ∗:

v∈u−1S⇔uv∈S.

From the definition, for all u,v∈Σ∗:

(uv)−1S=v−1(u−1S)

since for all w∈Σ∗, we have Template:Nowrap

The derivative with respect to an arbitrary string reduces to successive derivatives over the symbols of that string, since for all a∈Σ,u∈Σ∗: (ua)−1S=a−1(u−1S)ε−1S=S

A language S⊆Σ∗ is called nullable if it contains the empty string ε. Each language S is uniquely determined by nullability of its derivatives:

w∈S ⇔ ε∈w−1S

A language can be viewed as a (potentially infinite) boolean-labelled tree (see also tree (set theory) and infinite-tree automaton). Each possible string w∈Σ∗ denotes a node in the tree, with label true when w∈S and false otherwise. In this interpretation, the derivative with respect to a symbol a corresponds to the subtree obtained by following the edge a from the root. Decomposing a tree into the root and the subtrees a−1S corresponds to the following equality, which holds for every language S⊆Σ∗:

S=({ε}∩S)∪⋃a∈Σa(a−1S).

Derivatives of generalized regular expressions

When a language is given by a regular expression, the concept of derivatives leads to an algorithm for deciding whether a given word belongs to the regular expression.

Given a finite alphabet A of symbols,[5] a generalized regular expression R denotes a possibly infinite set of finite-length strings over the alphabet A, called the language of R, denoted L(R).

A generalized regular expression can be one of the following (where a is a symbol of the alphabet A, and R and S are generalized regular expressions):

  • "∅" denotes the empty set: L(∅) = {},
  • "ε" denotes the singleton set containing the empty string: L(ε) = {ε},
  • "a" denotes the singleton set containing the single-symbol string a: L(a) = {a},
  • "R∨S" denotes the union of R and S: L(R∨S) = L(R) ∪ L(S),
  • "R∧S" denotes the intersection of R and S: L(R∧S) = L(R) ∩ L(S),
  • "¬R" denotes the complement of R (with respect to A*, the set of all strings over A): L(¬R) = A* \ L(R),
  • "RS" denotes the concatenation of R and S: L(RS) = L(R) · L(S),
  • "R*" denotes the Kleene closure of R: L(R*) = L(R)*.

In an ordinary regular expression, neither ∧ nor ¬ is allowed.

Computation

For any given generalized regular expression R and any string u, the derivative u−1R is again a generalized regular expression (denoting the language u−1L(R)).[6] It may be computed recursively as follows.[7]

(ua)−1R = a−1(u−1R)       for a symbol a and a string u
ε−1R = R

Using the previous two rules, the derivative with respect to an arbitrary string is explained by the derivative with respect to a single-symbol string a. The latter can be computed as follows:[8]

a−1a = ε
a−1b = ∅ for each symbol b≠a
a−1ε = ∅
a−1∅ = ∅
a−1(R*) = (a−1R)R*
a−1(RS) = (a−1R)S ∨ ν(R)a−1S
a−1(R∧S) = (a−1R) ∧ (a−1S)
a−1(R∨S) = (a−1R) ∨ (a−1S)
a−1(¬R) = ¬(a−1R)

Here, Template:Math is an auxiliary function yielding a generalized regular expression that evaluates to the empty string ε if RTemplate:'s language contains ε, and otherwise evaluates to ∅. This function can be computed by the following rules:[9]

ν(a) = ∅ for any symbol a
ν(ε) = ε
ν(∅) = ∅
ν(R*) = ε
ν(RS) = ν(R) ∧ ν(S)
ν(R ∧ S) = ν(R) ∧ ν(S)
ν(R ∨ S) = ν(R) ∨ ν(S)
ν(¬R) = ε if ν(R) = ∅
ν(¬R) = ∅ if ν(R) = ε

Properties

A string u is a member of the string set denoted by a generalized regular expression R if and only if ε is a member of the string set denoted by the derivative u−1R.[10]

Considering all the derivatives of a fixed generalized regular expression R results in only finitely many different languages. If their number is denoted by dR, all these languages can be obtained as derivatives of R with respect to strings of length less than dR.[11] Furthermore, there is a complete deterministic finite automaton with dR states that recognises the regular language given by R, as stated by the Myhill–Nerode theorem.

Derivatives of context-free languages

Derivatives are also effectively computable for recursively defined equations with regular expression operators, which are equivalent to context-free grammars. This insight was used to derive parsing algorithms for context-free languages.[12] Implementation of such algorithms have shown to have cubic time complexity,[13] corresponding to the complexity of the Earley parser on general context-free grammars.

See also

References

Template:Reflist

  1. ↑ Template:Cite journal
  2. ↑ Template:Cite journal
  3. ↑ Template:Cite book
  4. ↑ 4.0 4.1 Template:Cite journal
  5. ↑ Brzozowski (1964), p.481, required A to consist of the 2n combinations of n bits, for some n.
  6. ↑ Brzozowski (1964), p.483, Theorem 4.1
  7. ↑ Brzozowski (1964), p.483, Theorem 3.2
  8. ↑ Brzozowski (1964), p.483, Theorem 3.1
  9. ↑ Brzozowski (1964), p.482, Definition 3.2
  10. ↑ Brzozowski (1964), p.483, Theorem 4.2
  11. ↑ Brzozowski (1964), p.484, Theorem 4.3
  12. ↑ Template:Cite conference
  13. ↑ Template:Cite conference