Accepted Manuscript Derivatives and partial derivatives for regular shuffle expressions
Martin Sulzmann, Peter Thiemann
PII: DOI: Reference:
S0022-0000(16)30132-5 http://dx.doi.org/10.1016/j.jcss.2016.11.010 YJCSS 3047
To appear in:
Journal of Computer and System Sciences
Received date: Revised date: Accepted date:
10 June 2015 18 September 2016 27 November 2016
Please cite this article in press as: M. Sulzmann, P. Thiemann, Derivatives and partial derivatives for regular shuffle expressions, J. Comput. Syst. Sci. (2016), http://dx.doi.org/10.1016/j.jcss.2016.11.010
This is a PDF file of an unedited manuscript that has been accepted for publication. As a service to our customers we are providing this early version of the manuscript. The manuscript will undergo copyediting, typesetting, and review of the resulting proof before it is published in its final form. Please note that during the production process errors may be discovered which could affect the content, and all legal disclaimers that apply to the journal pertain.
Derivatives and Partial Derivatives for Regular Shuffle Expressions Martin Sulzmanna , Peter Thiemannb a
Faculty of Computer Science and Business Information Systems, Karlsruhe University of Applied Sciences Moltkestraße 30, 76133 Karlsruhe, Germany b Faculty of Engineering, University of Freiburg, Georges-K¨ ohler-Allee 079, 79110 Freiburg, Germany
Abstract There is a rich variety of shuffling operations ranging from asynchronous interleaving to various forms of synchronizations. We introduce a general shuffling operation which subsumes earlier forms of shuffling. We further extend the notion of a Brzozowski derivative and an Antimirov partial derivative to the general shuffling operation and thus to many earlier forms of shuffling. This extension enables the direct construction of automata from regular expressions involving shuffles that appear in specifications of concurrent systems. Keywords: automata and logic, shuffle expressions, derivatives, partial derivatives 1. Introduction We consider an extension of regular expressions with a binary shuffle operation which bears similarity to shuffling two decks of cards. Like the extension with negation and complement, the language described by an expression extended with shuffling remains regular. That is, any expression making use of shuffling can be expressed in terms of basic operations such as choice, concatenation, and Kleene star. However, the use of shuffling yields a much more succinct representation of problems that occur in modeling of concurrent systems [1, 2]. Email addresses:
[email protected] (Martin Sulzmann),
[email protected] (Peter Thiemann)
Preprint submitted to Lata’15 Special Issue
December 21, 2016
Our goal is to extend Brzozowski’s derivatives [3] and Antimirov’s partial derivatives [4] to regular expressions with shuffle operations. Briefly, the derivative of a regular expression r w.r.t. some symbol x is a regular expression r such that its language L(r ) is x\L(r), the left quotient of L(r) by the symbol x. Brzozowski gave a simple structural definition to compute derivatives and established two important properties: Each expression can be represented as a linear combination of its derivatives (representation) and the set of iterated derivatives is finite when considered modulo idempotence, commutativity, and associativity of alternatives (finiteness). Thus, Brzozowski derivatives yield a direct construction of a deterministic finite automaton (DFA) from a regular expression. Partial derivatives generalize derivatives by extracting them from sets of linear factors. They may be thought of as representing the states of a nondeterministic finite automaton (NFA). Similar to Brzozowski derivatives, partial derivatives also support representation and finiteness results. In summary, thanks to representation and finiteness, derivatives and partial derivatives both support the elegant and efficient construction of automata-based word recognition algorithms and are also useful in the development of related algorithms for equality and containment among regular expressions [5, 6]. Hence, it is desirable to extend the notion of a derivative and a partial derivative to shuffle expressions. Various flavors of shuffle operations exist in the literature that differ in the notion of synchronization that they support [7, 1, 8, 9, 10]. We focus on four common forms of shuffling which we refer to as (plain) shuffling, weak synchronized shuffling, strong synchronized shuffling, and synchronous composition. For each of these forms we develop the notions of a derivative and a partial derivative and establish representation and finiteness results. Studying each form in separation is tedious and leads to repetition of results and proofs. In some cases, it is even difficult to provide a simple structural definition of a (partial) derivative. Therefore, we introduce a general shuffle operation which subsumes the above four variants of shuffling. For this general shuffle operation we define derivatives and partial derivatives and establish the results indicated. Thus, derivatives and partial derivatives for each specific instance of shuffling fall out almost for free. Contributions and outline. After introducing our notation in Section 2 and reviewing existing variants of shuffling in Section 3, we claim the following contributions: 2
• We introduce a general shuffle operation which subsumes previous forms of shuffling (Section 4). • We extend the notion of Brzozowski’s derivatives and Antimirov’s partial derivatives to the general shuffle operation and prove representation and finiteness (Sections 5 and 6). • Based on the general shuffle operation, we provide systematic methods to obtain (partial) derivatives for specific variants of shuffling. We further see that for forms such as weak synchronized shuffling a direct, simple structural (partial) derivative definition is not possible. This observation justifies the need for a general shuffle operation (Section 7). An earlier version of this work appeared in conference proceedings [11]. The present work includes further examples and proof details and adds the complete treatment of partial derivatives. Further related work is discussed in Section 8. We conclude in Section 9. 2. Preliminaries Let Σ be a fixed alphabet (i.e., a finite set of symbols). We usually denote symbols by x, y and z. The set Σ∗ denotes the set of finite words over Σ. We write Γ, Δ to denote subsets (sub-alphabets) of Σ. We write to denote the empty word and v · w to denote the concatenation of two words v and w. We generally use L, L1 , L2 ⊆ Σ∗ for languages over Σ and employ standard notation for operations on languages: L1 ·i L2 = {v · w | v ∈ L1 , w ∈ L2 }, L0 = {}, Li+1 = L · Li , and L∗ = ∞ i=0 L . We write L2 \L1 to denote the left quotient of L1 with L2 where L2 \L1 = {w | ∃v ∈ L2 .v · w ∈ L1 }. We often write just v in place of the singleton language {v} in arguments for operations on languages. For example, x\L and x · L are shorthands for {x}\L and {x} · L, respectively. We write α(w) to denote the set of symbols which appear in a word. The inductive definition is as follows: (1) α() = ∅, (2) α(x · w) = α(w) ∪ {x}. The extension to languages is as follows: α(L) = w∈L α(w). We write ΠΓ (w) to denote the projection of a word w onto a sub-alphabet Γ. The inductive definition is as follows: x · ΠΓ (w) x ∈ Γ; ΠΓ () = ΠΓ (x · w) = ΠΓ (w) x ∈ Γ. 3
If : Σ∗ × Σ∗ → ℘(Σ∗ ) is an operation mapping two words to a set of words, then we lift this operation to an operator : ℘(Σ∗ ) × ℘(Σ∗ ) → ℘(Σ∗ ) on languages as follows: L1 L2 = {v w | v ∈ L1 , w ∈ L2 }. We use this extension to lift shuffling operations from words to languages. 3. Shuffling Operations Definition 1 (Shuffling). The shuffle operator :: Σ∗ × Σ∗ → ℘(Σ∗ ) is defined inductively by w = {w} w = {w} x · v y · w = {x · u | u ∈ v y · w} ∪ {y · u | u ∈ x · v w}. For example, we find that x · y z = {x · y · z, x · z · y, z · x · y}. While the shuffle operator represents the asynchronous interleaving of two words v, w ∈ Σ∗ , there are also shuffle operators that include some synchronization. The strongly synchronized shuffle of two words w.r.t. some sub-alphabet Γ imposes the restriction that the traces must synchronize on all symbols in Γ. All symbols not appearing in Γ are shuffled. In its definition, we write (p) ⇒ X for: if p then X else ∅. Definition 2 (Strongly Synchronized Shuffling). The strongly synchronized shuffling operator w.r.t. Γ ⊆ Σ, |||Γ :: Σ∗ × Σ∗ → ℘(Σ∗ ), is defined inductively by |||Γ w = (Γ ∩ α(w) = ∅) ⇒ {w} w|||Γ = (Γ ∩ α(w) = ∅) ⇒ {w} x · v|||Γ y · w = (x = y ∧ x ∈ Γ) ⇒ {x · u | u ∈ v|||Γ w} ∪(x ∈ Γ) ⇒ {x · u | u ∈ v|||Γ y · w} ∪(y ∈ Γ) ⇒ {y · u | u ∈ x · v|||Γ w}.
(S1) (S2) (S3) (S4) (S5)
The base cases (S1) and (S2) impose the condition (via Γ ∩ α(w) = ∅) that none of the symbols in w shall be synchronized. If the condition is violated we obtain the empty set. For example, |||{x} y · z = {y · z}, but |||{x} x · y · z = ∅. In the inductive step, a symbol in Γ appearing on both sides forces synchronization (S3). If the leading symbol on either side does not appear in 4
Γ, then it can be shuffled arbitrarily. See cases (S4) and (S5). These three cases ensure progress until one side is reduced to the empty string. For example, we find that x · y|||{x} x · z = {x · y · z, x · z · y}. On the other hand, x · y|||{x,y} x · z = ∅. Shuffling and strongly synchronized shuffling correspond to the arbitrary synchronized shuffling and strongly synchronized shuffling operations by Beek and coworkers [8]. Our inductive definitions simplify the proofs. Beek and coworkers [8] also introduce a weak synchronized shuffling operation. In its definition, we write L · x as a shorthand for {w · x | w ∈ L} and x · L as a shorthand for {x · w | w ∈ L} Definition 3 (Weak Synchronized Shuffling). Let v, w ⊆ Σ∗ and Γ ⊆ Σ. Then, we define v| ∼ |Γ w = {u | ∃n ≥ 0, xi ∈ Γ, vi ∈ Σ∗ , wi ∈ Σ∗ . v = v1 · x1 ...xn · vn+1 ∧ w = w1 · x1 ...xn · wn+1 ∧ u ∈ (v1 w1 ) · x1 ...xn · (vn+1 wn+1 )∧ α(vi ) ∩ α(wi ) ∩ Γ = ∅}. The weak synchronized shuffle of two words v and w synchronizes only on those symbols in Γ that occur in both v and w. For example, x · y| ∼ |{x,y} x · z = {x · y · z, x · z · y} because y ∈ α(x · z) whereas x · y|||{x,y} x · z = ∅. Another variant of synchronous shuffling is called synchronous composition [7, 1]. The difference to strongly synchronized shuffling is that synchronization occurs on symbols common to both operands. Thus, synchronous composition can be defined by projecting onto the symbols of the operands. Definition 4 (Synchronous Composition). The synchronous composition operator ||| is defined by: L1 |||L2 = {w ∈ (α(L1 ) ∪ α(L2 ))∗ | Πα(L1 ) (w) ∈ L1 ∧ Πα(L2 ) (w) ∈ L2 }. For example, x · y|||x · z equals {x · y · z, x · z · y}. It turns out that the strong synchronized shuffling operation |||Γ subsumes synchronous composition due to the customizable set Γ. In Section 4, we show an even stronger result: All of the shuffling variants we have seen can be expressed in terms of a general synchronous shuffling operation.
5
4. General Synchronous Shuffling The general synchronous shuffling operation is parameterized by a set of synchronizing symbols, Γ, and two additional sets P1 and P2 that keep track of ’out of sync’ symbols from Γ. Definition 5 (General Synchronous Shuffling). Let Γ, P1 , P2 ⊆ Σ. The general synchronous shuffling operator P1 ||PΓ2 :: Σ∗ × Σ∗ → ℘(Σ∗ ) is defined inductively by = ((α(w) ∩ Γ = ∅) ∨ (P1 ∩ (P2 ∪ α(w)) = ∅)) ⇒ {w} P1 ||PΓ2 w = ((α(w) ∩ Γ = ∅) ∨ (P1 ∪ α(w)) ∩ P2 = ∅)) ⇒ {w} wP1 ||PΓ2 P1 P2 x · v ||Γ y · w = (x ∈ Γ) ⇒ {x · u | u ∈ v P1 ||PΓ2 y · w} ∪(y ∈ Γ) ⇒ {y · u | u ∈ x · v P1 ||PΓ2 w} ∪(x = y ∧ x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ {x · u | u ∈ v ∅ ||∅Γ w} ∪(x = y ∧ x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ {x · u | u ∈ v P1 ||PΓ2 w} ∪(x ∈ Γ ∧ (P1 ∪ x) ∩ P2 = ∅) ⇒ {x · u | u ∈ v P1 ∪x ||PΓ2 y · w} ∪(y ∈ Γ ∧ P1 ∩ (P2 ∪ y) = ∅) ⇒ {y · u | u ∈ x · v P1 ||PΓ2 ∪y w}.
(G1) (G2) (G3) (G4) (G5) (G6) (G7) (G8)
The definition of general synchronous shuffling is significantly more involved compared to the earlier definitions. Cases (G1-8) are necessary to encode the earlier shuffle operations from Section 3. The exact purpose of the individual cases will become clear shortly. In our first result we observe that Σ ||Σ Γ exactly corresponds to strongly synchronized shuffling (|||Γ ). Theorem 1. For any L1 , L2 ⊆ Σ∗ and Γ ⊆ Σ:
L1 |||Γ L2 = L1 Σ ||Σ Γ L2 .
Proof. We choose a ’maximal’ assignment for P1 and P2 by setting both to Σ. 1 Then, definition of P1 ||PΓ2 reduces to |||Γ . In more detail, we observe that property P1 = Σ ∧ P2 = Σ (SP) is an invariant. For cases (G3-4) and (G6) the invariant property clearly holds. 1
Alternatively, we could set P1 and P2 to ∅ which yields the same result.
6
For cases (G5), (G7-8) the preconditions are violated. Hence, for Σ ||Σ Γ only cases (G1-4) and (G6) will ever apply. Under the given assumptions, we can relate the cases in Definition 2 and Definition 5 as follows. Cases (G1-2) correspond to cases (S1-2). Cases (G3-4) correspond to cases (S4-5). Case (G6) corresponds to case (S3). Due to the invariant property (SP) cases (G5) and (G7-8) never apply. Hence, Σ ||Σ Γ and |||Γ yield the same result. Via similar reasoning we can show that for Γ = ∅ ∧ P1 = ∅ ∧ P2 = ∅ general synchronized shuffling boils down to (arbitrary) shuffling. Theorem 2. For any L1 , L2 ⊆ Σ∗ :
L1 L2 = L1 ∅ ||∅∅ L2 .
An immediate consequence of Theorem 1 (consider ∅ instead of Σ and Γ) and Theorem 2 is that shuffling can also be expressed in terms of strong synchronized shuffling where we consider ∅ instead of Γ. Corollary 1. For any L1 , L2 ⊆ Σ∗ :
L1 L2 = L1 |||∅ L2 .
Our next result establishes a connection to weak synchronized shuffling [8]. Theorem 3. For any L1 , L2 ⊆ Σ∗ ,Γ ⊆ Σ:
L1 | ∼ |Γ L2 = L1 ∅ ||∅Γ L2 .
Proof. Property P1 , P2 ⊆ Γ ∧ P1 ∩ P2 = ∅ (WP) is an invariant of P1 ||PΓ2 . For cases (G3-4) the invariant property clearly holds. More interesting are cases (G7-8) where P1 , resp., P2 is extended. Under the precondition property (WP) remains invariant. Case (G6) never applies. Case (G5) clearly maintains the invariant. Recall that for strong synchronized shuffling the roles of (G5) and (G6) are switched. See proof of Theorem 1. This shows that while cases (G5) and (G6) look rather similar both are indeed necessary. As we can see, under the invariant condition (WP), the purpose of P1 , P2 is to keep track of “out of sync” symbols from Γ. See cases (G7-8). Case (G5) synchronizes on x ∈ Γ. Hence, P1 and P2 are (re)set to ∅. Thus, we can show (via some inductive argument on the length of the words shuffled) that ∅ ||∅Γ under the (WP) invariant corresponds to weak synchronized shuffling as defined in Definition 3.
7
It remains to show that synchronous composition is subsumed (i.e. can be expressed) by general synchronized shuffling. First, we verify that synchronous composition is subsumed by strongly synchronous shuffling via the following identity L1 |||L2 = L1 |||α(L1 )∩α(L2 ) L2 . To establish the direction L1 |||L2 ⊇ L1 |||α(L1 )∩α(L2 ) L2 we verify that the projection of a strongly synchronizable word w.r.t. α(L1 )∩α(L2 ) yields words in the respective languages L1 and L2 as stated by the following lemma. Lemma 1. Let u, v, w ∈ Σ∗ , L1 , L2 ⊆ Σ∗ , Γ ⊆ Σ such that u ∈ v|||Γ w where v ∈ L1 , w ∈ L2 and Γ ⊆ α(L1 ) ∩ α(L2 ). Then, we find that (1) Πα(L1 ) (u) = v and (2) Πα(L2 ) (u) = w. Proof. The proof proceeds by induction over u. Case u = : By definition of |||Γ we must have ∈ L1 , L2 . Thus, (1) and (2) follow immediately. Case u = x · u : We distinguish among the following subcases. Subcase x ∈ Γ: From the assumptions and definition of |||Γ , v = x · v , w = x · w , and xu ∈ x(v |||Γ w ), where x · v ∈ L1 and x · w ∈ L2 . Hence, u ∈ v |||Γ w where v ∈ x\L1 and w ∈ x\L2 . By induction we find that Πα(x\L1 ) (u ) = v and Πα(x\L2 ) (u ) = w . Thus, Πα(L1 ) (x · u ) = x · Πα(L1 ) (u ) by definition. Clearly, Πα(L1 ) (u ) = Πα(x\L1 ) (u ). Hence, Πα(L1 ) (x · u ) = x · v and thus we have established (1). Via a similar reasoning we can establish (2). Subcase x ∈ Γ: There are two further subcases to consider. Either (a) x ∈ α(L1 ) and x ∈ α(L2 ), or (b) x ∈ α(L1 ) and x ∈ α(L2 ). We start with subcase (a). From the assumption we conclude that v = x · v where x · u ∈ x · v |||Γ w. Hence, u ∈ v |||Γ w where v ∈ x\L1 . By induction we find that Πα(x\L1 ) (u ) = v and Πα(L2 ) (u ) = w. Because x ∈ α(L2 ), we have Πα(L1 ) (x · u ) = x · v and Πα(L2 ) (x · u ) = w. Hence, we have established (1) and (2). Subcase (b) can be verified similarly. The other inclusion L1 |||L2 ⊇ L1 |||α(L1 )∩α(L2 ) L2 can be verified similarly. We show that if the projection of a word onto α(L1 ) and α(L2 ) yields words in the respective language, then the word must be strongly synchronizable w.r.t. α(L1 ) ∩ α(L2 ). Lemma 2. Let u, v, w ∈ Σ∗ , L1 , L2 ⊆ Σ∗ such that w ∈ (α(L1 ) ∪ α(L2 ))∗ , Πα(L1 ) (w) = u ∈ L1 and Πα(L1 ) (w) = v ∈ L2 . Then, we find that w ∈ u|||α(L1 )∩α(L2 ) v. 8
Proof. The proof proceeds by induction over w. Case w = : Straightforward. Case w = x · w : From x · w ∈ (α(L1 ) ∪ α(L2 ))∗ we conclude that w ∈ (α(x\L1 ) ∪ α(x\L2 ))∗ . We continue by distinguishing among the following subcases. Subcase x ∈ α(L1 ) ∩ α(L2 ): In this case, we have by definition Πα(L1 ) (x · w ) = x · Πα(L1 ) (w ) = x · Πα(x\L1 ) (w ) by w ∈ (α(x\L1 ) ∪ α(x\L2 ))∗ = x · u where u ∈ x\L1 . Similarly, Πα(x\L2 ) (w ) = v for some v ∈ x\L2 . By induction, we find w ∈ u |||α(x\L1 )∩α(x\L2 ) v . It follows that w ∈ u |||α(L1 )∩α(L2 ) v . If x ∈ α(x\L1 ) ∩ α(x\L2 ) then there is no harm adding x. Otherwise, there is no harm either as u ∈ x\L1 and v ∈ x\L2 . By definition of |||α(L1 )∩α(L2 ) we find that x · w ∈ x · u |||α(L1 )∩α(L2 ) x · v and we are done. Subcase x ∈ α(L1 ), x ∈ α(L2 ): Using the same reasoning as in the first subcase we find that Πα(x\L1 ) (w ) = u ∈ x\L1 . Because of x ∈ α(L2 ), we find that Πα(L2 ) (x · w ) = Πα(L2 ) (w ) = v ∈ L2 and w ∈ (α(x\L1 ) ∪ α(L2 ))∗ . By induction w ∈ u |||α(x\L1 )∪α(L2 ) v. It follows that w ∈ u |||α(L1 )∪α(L2 ) v because x ∈ α(L2 ). By definition of |||α(L1 )∩α(L2 ) we find that x·w ∈ x·u |||α(L1 )∩α(L2 ) v and we are done. Subcase x ∈ α(L2 ), x ∈ α(L1 ): Similar to the above. Subcase x ∈ α(L1 ), x ∈ α(L2 ): Does not apply. Theorem 4. For any L1 , L2 ⊆ Σ∗ we find that L1 |||L2 = L1 |||α(L1 )∩α(L2 ) L2 . Proof. Result follows immediately from Lemmas 1 and 2. An immediate consequence of Theorem 1 and Theorem 4 is the following result. Synchronous composition is subsumed by general synchronous shuffling. Corollary 2. For any L1 , L2 ⊆ Σ∗ we find that L1 |||L2 = L1 Σ ||Σ α(L1 )∩α(L2 ) L2 . In summary, all four shuffling variants from Section 3 can be expressed in terms of the general shuffle operation via the following identities. For each identity, we highlight the relevant cases from Definition 5 to establish the identity. 9
• L1 L2 = L1 Σ ||Σ ∅ L2
Cases (G1-4)
• L1 |||L2 = L1 Σ ||Σ α(L1 )∩α(L2 ) L2
Cases (G1-2), (G3-4), (G6)
• L1 |||Γ L2 = L1 Σ ||Σ Γ L2
Cases (G1-2), (G3-4), (G6)
• L1 | ∼ |Γ L2 = L1 ∅ ||∅Γ L2
Cases (G1-2), (G3-4), (G5), (G7-8)
5. Derivatives for General Synchronous Shuffling Brzozowski derivatives [3] are a useful tool to translate regular expressions into finite automata and to obtain decision procedures for equivalence and containment for regular expressions. We show that Brzozowski’s results and their applications can be extended to regular expressions that contain shuffle operators. Based on the results of the previous section, we restrict our attention to regular expressions extended with the general synchronous shuffle operator. Definition 6. The set RΣ of regular shuffle expressions is defined inductively by φ ∈ RΣ , ∈ RΣ , Σ ⊆ RΣ , and for all r, s ∈ RΣ and Γ, P1 , P2 ⊆ Σ we have that r + s, r · s, r∗ , rP1 ||PΓ2 s ∈ RΣ . Definition 7. The language L( ) : RΣ → Σ∗ denoted by a regular shuffle expression is defined inductively by L(φ) = ∅; L() = {}; L(x) = {x}; L(r+s) = L(r)∪L(s); L(r·s) = L(r)·L(s); L(r ∗ ) = L(r)∗ ; and L(rP1 ||PΓ2 s) = L(r)P1 ||PΓ2 L(s). An expression r is nullable if ∈ L(r). The following function n( ) detects nullable regular shuffle expressions. Definition 8. We define n( ) : RΣ → Bool inductively by n(φ) = false; n() = true; n(x) = false; n(r + s) = n(r) ∨ n(s); n(r · s) = n(r) ∧ n(s); n(r∗ ) = true; and n(rP1 ||PΓ2 s) = n(r) ∧ n(s). Lemma 3. For all r ∈ RΣ we have that ∈ L(r) iff n(r) = true. Proof. The proof proceeds by induction over r. We only consider the shuffle case as the remaining cases are standard. ∈ L(rP1 ||PΓ2 s) iff (by definition) ∈ v P1 ||PΓ2 w for some v ∈ L(r) and w ∈ L(s). By definition of P1 ||PΓ2 it must be that v = and w = . By induction, this is equivalent to n(r) ∧ n(s). 10
The derivative of an expression r w.r.t. some symbol x, written dx (r) yields a new expression for the left quotient of L(r) by x. In its definition, we write (p) ⇒ r for: if p then r else φ. Definition 9. The derivative of r ∈ RΣ w.r.t. x ∈ Σ, written dx (r), is defined inductively by dx (φ) dx () dy (x) dx (r + s) dx (r · s) dx (r∗ ) dx (rP1 ||PΓ2 s)
= = = = = = =
φ φ (x = y) ⇒ dx (r) + dx (s) (dx (r)) · s + (n(r)) ⇒ dx (s) (dx (r)) · r∗ (x ∈ Γ) ⇒ ((dx (r)P1 ||PΓ2 s) + (rP1 ||PΓ2 dx (s))) +(x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ (dx (r)∅ ||∅Γ dx (s)) +(x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ (dx (r)P1 ||PΓ2 dx (s)) +(x ∈ Γ ∧ (P1 ∪ x) ∩ P2 = ∅) ⇒ (dx (r)P1 ∪x ||PΓ2 s) +(x ∈ Γ ∧ P1 ∩ (P2 ∪ x) = ∅) ⇒ (rP1 ||PΓ2 ∪x dx (s)).
(D1) (D2) (D3) (D4) (D5) (D6) (D7) (D8) (D9) (D10) (D11)
The definition extends to words and sets of words. We define d (r) = r and dxw (r) = dw (dx (r)). For L ⊆ Σ∗ we define dL (r) = {dw (r) | w ∈ L}. We refer to the special case dΣ∗ (r) as the set of descendants of r. A descendant is either the expression itself, a derivative of the expression, or the derivative of a descendant. The first six cases (D1-6) correspond to Brzozowski’s original definition [3]. As a minor difference we build the sum with φ when building the derivative of a concatenated expression whose first component is not nullable. The new subcases (D7-11) for the general shuffle closely correspond to the subcases of Definition 5. For example, compare (D7) and (G3-4), (D8) and (G5), (D9) and (G6), (D10) and (G7), and lastly (D11) and (G8). An easy induction shows that the derivative of a shuffle expression is again a shuffle expression. Theorem 5 (Closure). For r ∈ RΣ and x ∈ Σ we have that dx (r) ∈ RΣ . Brzozowski proved that the derivative of a regular expression denotes a left quotient. This result extends to shuffle expressions. In our proof we will make use of the following helper statements which correspond to the cases (D7-D11) in the definition of derivatives. See Definition 9. 11
Lemma 4 (Left Quotient Case D7a). Let r , r, s ∈ RΣ , Γ, P1 , P2 ⊆ Σ and x ∈ Γ such that L(r ) ⊆ x\L(r). Then, L(rP1 ||PΓ2 s) ⊆ x\L(rP1 ||PΓ2 s). Proof. Suppose w ∈ L(rP1 ||PΓ2 s). By definition w ∈ uP1 ||PΓ2 v for some u ∈ L(r ) and v ∈ L(s). If x ∈ Γ we find x · w ∈ x · uP1 ||PΓ2 v. See case (G3) in Definition 5. If u ∈ L(r ) then by assumption x · u ∈ L(r). Hence, x · w ∈ L(rP1 ||PΓ2 s) and we are done. Lemma 5 (Left Quotient Case D7b). Let s , r, s ∈ RΣ , Γ, P1 , P2 ⊆ Σ and x ∈ Γ such that L(s ) ⊆ x\L(s). Then, L(rP1 ||PΓ2 s ) ⊆ x\L(rP1 ||PΓ2 s). Proof. Similar to the proof of Lemma 4. Lemma 6 (Left Quotient Case D8). Let r , s , r, s ∈ RΣ , Γ, P1 , P2 ⊆ Σ and x ∈ Γ such that P1 ∩ P2 = ∅, L(r ) ⊆ x\L(r) and L(s ) ⊆ x\L(s). Then, L(rP1 ||PΓ2 s ) ⊆ x\L(rP1 ||PΓ2 s). Proof. Suppose w ∈ L(rP1 ||PΓ2 s ). By definition w ∈ uP1 ||PΓ2 v for some u ∈ L(r ) and v ∈ L(s ). If P1 ∩ P2 = ∅ we find that x · w ∈ x · u∅ ||∅Γ x · v. See case (G5) in Definition 5. If u ∈ L(r ) and v ∈ L(s ) then by assumption x · u ∈ L(r) and x · v ∈ L(s). Hence, x · w ∈ L(r∅ ||∅Γ s). By inspection of the definition of general synchronous shuffling we find that L(r∅ ||∅Γ s) = L(rP1 ||PΓ2 s) for P1 ∩ P2 = ∅ and thus we are done. Lemma 7 (Left Quotient Case D9). Let r , s , r, s ∈ RΣ , Γ, P1 , P2 ⊆ Σ and x ∈ Γ such that P1 ∩ P2 = ∅, L(r ) ⊆ x\L(r) and L(s ) ⊆ x\L(s). Then, L(rP1 ||PΓ2 s ) ⊆ x\L(rP1 ||PΓ2 s). Proof. Similar to the proof of Lemma 6. Lemma 8 (Left Quotient Case D10). Let r , r, s ∈ RΣ , Γ, P1 , P2 ⊆ Σ and x ∈ Γ. If (P1 ∪ x) ∩ P2 = ∅ and L(r ) ⊆ x\L(r), then L(rP1 ∪x ||PΓ2 s) ⊆ x\L(rP1 ||PΓ2 s). Proof. Suppose w ∈ L(rP1 ∪x ||PΓ2 s). By definition w ∈ uP1 ∪x ||PΓ2 v for some u ∈ L(r ) and v ∈ L(s). If x ∈ Γ, (P1 ∪ x) ∩ P2 = ∅ we find x · w ∈ x · uP1 ||PΓ2 v. See case (G7) in Definition 5. If u ∈ L(r ) then by assumption x · u ∈ L(r). Hence, x · w ∈ L(rP1 ||PΓ2 s) and we are done. 12
Lemma 9 (Left Quotient Case D11). Let s , r, s ∈ RΣ , Γ, P1 , P2 ⊆ Σ and x ∈ Γ. If P1 ∩ (P2 ∪ x) = ∅ and L(s ) ⊆ x\L(s), then L(rP1 ||PΓ2 ∪x s ) ⊆ x\L(rP1 ||PΓ2 s). Proof. Similar to the proof of Lemma 8. Theorem 6 (Left Quotients). For any r ∈ RΣ and x ∈ Σ we have that L(dx (r)) = x\L(r). Proof. It suffices to consider the new case of general synchronous shuffling. We consider the direction L(dx (rP1 ||PΓ2 s)) ⊆ x\L(rP1 ||PΓ2 s) = {w | x · w ∈ L(rP1 ||PΓ2 s)}. Suppose u ∈ L(dx (rP1 ||PΓ2 s)). We will verify that x · u ∈ L(rP1 ||PΓ2 s). We proceed by distinguishing among the following cases. Case x ∈ Γ: By definition of the derivative, we find that either (D7a) u ∈ L(dx (r)P1 ||PΓ2 s) or (D7b) u ∈ L(rP1 ||PΓ2 dx (s)). By induction L(dx (r)) ⊆ x\L(r) and L(dx (s)) ⊆ x\L(s). Via Lemmas 4 and 5 we find that x · u ∈ L(rP1 ||PΓ2 s) and we are done. Case x ∈ Γ: By definition of the derivative (D8) u ∈ L(dx (r)∅ ||∅Γ dx (s)) where P1 ∩P2 = ∅, or (D9) u ∈ L(dx (r)P1 ||PΓ2 dx (s)) where P1 ∩P2 = ∅, or (D10) u ∈ L(dx (r)P1 ∪x ||PΓ2 s) where (P1 ∪ x) ∩ P2 = ∅, or (D11) u ∈ L(rP1 ||PΓ2 ∪x dx (s)) where P1 ∩ (P2 ∪ x) = ∅. Via similar reasoning as above and application of the appropriate Lemmas 6, 7, 8 and 9 we find that x · u ∈ L(rP1 ||PΓ2 s) which concludes the proof. The other direction L(dx (rP1 ||PΓ2 s)) ⊇ {x · w | w ∈ L(rP1 ||PΓ2 s)} follows via similar reasoning. Based on the above result, we obtain a simple algorithm for membership testing. Given a word w and expression r, we exhaustively apply the derivative operation and on the final expression we apply the nullable test. Lemma 10. For all r ∈ RΣ and w ∈ Σ∗ , w ∈ L(r) iff n(dw (r)). For example, consider x · y ∅ ||∅{x,y} x · z for which x · y · z ∈ L(x · y ∅ ||∅{x,y} x · z). We build the derivative w.r.t symbols x, y and z and then test if the resulting expression is nullable. In a first step, we find that {x}
dx (x · y ∅ ||∅{x,y} x · z) = y ∅ ||∅{x,y} z + y {x} ||∅{x,y} x · z + x · y ∅ ||{x,y} z , (D8)
(D10)
13
(D11)
where subterms are connected to the cases in Definition 9. For brevity, some simplifications such as · y = y are applied. The second and third subterm both lead to φ. Hence, we continue with y ∅ ||∅{x,y} z and find that {x}
dx (x · y ∅ ||∅{x,y} x · z) = y ∅ ||∅{x,y} z + y {x} ||∅{x,y} x · z + x · y ∅ ||{x,y} z . (D8)
(D10)
(D11)
We strike through subterms which lead to φ. The next steps are as follows {y}
dy (y ∅ ||∅{x,y} z) = ∅ ||∅{x,y} φ + {y} ||∅{x,y} z + y ∅ ||{x,y} φ (D10)
(D8)
(D11)
{z}
dz ({y} ||∅{x,y} z) = φ{y} ||∅{x,y} φ + φ{y,z} ||∅{x,y} z + {y} ||{x,y} . (D8)
(D10)
(D11)
{z}
In conclusion, we find that dz (dy (dx (x · y ∅ ||∅{x,y} x · z))) = · · · + {y} ||{x,y} {z}
where expression {y} ||{x,y} is nullable. Hence, x · y · z ∈ L(x · y| ∼ |{x,y} x · z). In general, it seems wasteful to repeatedly generate derivatives just for the sake of testing a specific word. It is more efficient to construct a DFA which we can then be used to test many words. Brzozowski recognized that there is an elegant DFA construction method based on derivatives. Expressions are treated as states. For each expression r and symbol x, there is a transition to its derivative dx (r). For this construction to work we must establish that (1) the transitions implied by the derivatives represent all cases, and (2) the set of states remains finite. This is what we will consider next. First, we establish (1) by verifying that each shuffle expression can be represented as a sum of its derivatives, extending another result of Brzozowski. Theorem 7 (Representation). For allr ∈ RΣ , L(r) = L((n(r)) ⇒ ) ∪ x∈Σ x · L(dx (r)). Proof. Follows immediately from Lemma 3 and Theorem 6. The states of the automaton are the descendants of expression r. Hence, we must ensure that the set dΣ∗ (r) is finite. The following example shows that
14
our definitions need to be refined as it exhibits an expression with infinitely many descendants. dx (x∗ ) = · x∗ dx ( · x∗ ) = φ · x ∗ + · x∗ ∗ ∗ dx (φ · x + · x ) = (φ · x∗ + · x∗ ) + (φ · x∗ + · x∗ ) ... To guarantee finiteness, we consider expressions modulo similarity. Definition 10 (Similarity). Two expressions r, s ∈ RΣ are similar, written r ≈ s, if one can be transformed into the other by applying the following identities: (I1) r + s = s + r
(I2) r + (s + t) = (r + s) + t
(I3) r + r = r.
For S ⊆ RΣ we write S/≈ to denote the set of equivalence classes of all similar expressions in S. To verify (dis)similarity among descendants we normalize expressions via identities (I1-3) as follows. (1) Alternatives are kept in a list, see (I2) and (I1), and sorted according to an arbitrary fixed linear order on expressions as done elsewhere [12] to obtain finiteness of descendants for standard regular expressions. (2) Any duplicates in the list are removed, see (I3). This normalization process will eventually terminate as the size of expressions becomes smaller and we can also guarantee that the normal form obtained is unique as the normalization (rewrite) steps (1) and (2) are confluent. For example, consider the above regular expression (φ·x∗ +·x∗ )+(φ·x∗ + · x∗ ). In an intermediate step, we find the form φ · x∗ + φ · x∗ + · x∗ + · x∗ . Parentheses are omitted due to normalization via identities (I1) and (I2). Finally, duplicates are removed via (I3) which leads to φ · x∗ + · x∗ . This normalization step must be applied to all subexpressions. For example, consider expression x∗ · x where repeated application of the derivative operation yields expressions of the form (· · · + · x∗ + · · · + · x∗ ) · x + · · · . It is easy to see that via this normalization step we reach a canonical normal form for each expression. Hence, to verify that two expressions are (dis)similar we build their canonical normal forms and then check if both forms are syntactically equivalent. Thus, the set dΣ∗ (r)/≈ is obtained by generating dissimilar descendants, starting with {r}, where descendants are normalized. The following result shows that this generation procedure reaches a fixpoint. 15
Theorem 8 (Finiteness). For r ∈ RΣ the set dΣ∗ (r)/≈ is finite. Proof. It suffices to consider the new case of shuffle expressions of the form rP1 ||PΓ2 s which we abbreviate by t. Our argumentation is similar to the case of concatenation in Brzozowski’s work [3], in particular the proofs of Theorems 4.3(a) and 5.2. By inspection of the definition of dx ( ) on P1 ||PΓ2 and application of identity (I2) (associativity) we find that all descendants of t can be represented as a P sum of expressions which are either of the shape φ or rP1 ||Γ2 s where r is a descendant of r and s is a descendant of s, but P1 and P2 are arbitrary subsets of Σ. Thus, we can apply a similar argument as in Brzozowski’s original proof to approximate the number of descendants of rP1 ||PΓ2 s by the number of descendants of r and s. Suppose Dr denotes the number of all descendants of r and n = |Σ| is the size of the alphabet. Then, we can approximate Dt as follows: Dt ≤ 2Dr ∗Ds ∗2
n ∗2n
.
The exponent counts the number of different expressions of the form rP1 ||PΓ2 s and a sum corresponds to a subset of these expressions. The factor 2n ∗ 2n arises because P1 , P2 range over subsets of Σ where n = |Σ|. The factor Ds ∗ Dr arises from the variation of r and s over the descendants of r and s, respectively. As Dr and Ds are finite, by the inductive hypothesis, we obtain a very large, but finite bound on Dt . In summary, we can state the following definition and theorem. Definition 11 (Derivative-based DFA Construction). For r ∈ RΣ we define D(r) = (Q, Σ, q0 , δ, F ) where Q = dΣ∗ (r)/≈ , q0 = r, for each q ∈ Q and x ∈ Σ we define δ(q, x) = dx (q), and F = {q ∈ Q | n(q)}. Theorem 9. For any r ∈ RΣ we have that L(r) = L(D(r)). Proof. Let D(r) = (Q, Σ, q0 , δ, F ). We show by induction on w that ∀w ∈ Σ∗ , ∀q ∈ Q, w ∈ L(q) iff w ∈ L(D(r), q), the language recognized from state q. The proof is a straightforward calculation using Theorem 6 in the inductive step. 16
We illustrate the results of the automaton construction by applying various shuffle operators to the expressions (x + y)∗ and (x · y ∗ ). A first group of experiments applies a Kleene star to the result of the shuffle. See Figure 1. The appendix contains the details how numerical state names are connected to descendants. To obtain automata of practically useful size, we extend simplification with the rewriting rules used by Rosu and Viswanathan [13]: φ · r ≈ φ, φ + r ≈ r, · r ≈ r, and distributivity (r · t) + (s · t) ≈ (r + s) · t. These rules are also equivalences on regular expressions and our implementation applies them from left to right, only. For interleaving (upper left), our construction yields the minimal deterministic automaton with three states. For strongly synchronized shuffling (upper right), we also obtain the minimal automaton for with three states. Finally, for weakly synchronizing shuffling, we obtain an automaton with 11 states and 10 of them final. This automaton is not minimal because the implementation does not contain simplification rules targeted at the weakly synchronizing shuffle operator. 6. Partial Derivatives for General Synchronous Shuffling In this section, we define partial derivatives for regular shuffle expressions and establish their basic properties in analogy to Antimirov’s work [4]. Essentially, we prove the representation theorem and finiteness of the set of iterated partial derivatives of regular shuffle expressions. Thus, it is possible to construct nondeterministic finite automata directly from regular shuffle expressions. In this section, the guard expression (b) ⇒ X, where b is a Boolean and X is a set, is defined by (true) ⇒ X = X and (false) ⇒ X = {}. Definition 12. The smart concatenation constructor : RΣ × RΣ → RΣ is defined as follows for r1 , r2 ∈ RΣ . ⎧ φ r1 = φ ∨ r2 = φ; ⎪ ⎪ ⎪ ⎨r r1 = ; 2 r1 r2 = ⎪ r2 = ; r1 ⎪ ⎪ ⎩ r1 · r2 otherwise.
17
y x y x 2 x
1
2
y
y
x
x
y x
1
3
y 3
D(((x + y)∗ (x · y ∗ ))∗ )
D(((x + y)∗ |||{x,y} (x · y ∗ ))∗ ) y
10
y y
y
3
x
x x
6
x
9
y y
1
x 2
x y
y 5 x
x
y x
x y
7 y
4
D(((x + y)∗ | ∼ |{x,y} (x · y ∗ ))∗ ) Figure 1: Derivative-Based DFA Examples
18
x
8
11
pdx (φ) pdx () pdx (x) pdx (y) pdx (r + s) pdx (r · s) pdx (r∗ ) pdx (rP1 ||PΓ2 s)
= = = = = = = =
{} {} {} {} pdx (r) ∪ pdx (s) pdx (r) s ∪ (n(r)) ⇒ pdx (s) pdx (r) r∗ (x ∈ Γ) ⇒ ({rP1 ||PΓ2 s | r ∈ pdx (r)}∪ {rP1 ||PΓ2 s | s ∈ pdx (s)}) ∪(x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ {r∅ ||∅Γ s | r ∈ pdx (r), s ∈ pdx (s)} ∪(x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ {rP1 ||PΓ2 s | r ∈ pdx (r), s ∈ pdx (s)} ∪(x ∈ Γ ∧ (P1 ∪ x) ∩ P2 = ∅) ⇒ {rP1 ∪x ||PΓ2 s | r ∈ pdx (r)} ∪(x ∈ Γ ∧ P1 ∩ (P2 ∪ x) = ∅) ⇒ {rP1 ||PΓ2 ∪x s | s ∈ pdx (s)}
(PD1) (PD2) (PD3a) (PD3b) (PD4) (PD5) (PD6) (PD7) (PD8) (PD9) (PD10) (PD11)
Figure 2: Partial derivatives of regular shuffle expressions. We assume y ∈ Σ with x = y.
It is lifted to sets of expressions by omitting empty expressions, that is, for R ⊆ RΣ and r2 ∈ RΣ define R r2 = {r | r = r1 r2 , r1 ∈ R, r = φ}. Definition 13. The set of partial derivatives of r ∈ RΣ w.r.t. x ∈ Σ, written pdx (r) ⊆ RΣ , are defined inductively in Figure 2. extends to words inductively by pd (r) = {r} and pdwx (r) = The definition ∗ (r ) | r ∈ pd {pd w (r)}. It further extends to languages L ⊆ Σ by pdL (r) = x {pdw (r) | w ∈ L}. We refer to the special case pdΣ∗ (r) as the set of descendants of r. A descendant is either the expression itself, a partial derivative of the expression, or the derivative of a descendant. For a set of regular expressions R ⊆ RΣ , we define L(R) = r∈R L(r). Theorem 10 (Left Quotients). For all r ∈ RΣ and x ∈ Σ, L(pdx (r)) = x\L(r). 19
Proof. Consider L(pdx (r)) = r ∈pdx (r) L(r ). Let r ∈ pdx (r) and show that L(r ) ⊆ x\L(r) by induction on r. Thus, we obtain L(pdx (r)) ⊆ x\L(r). The cases for φ, , x, and y = x are immediate. Case r + s. Immediate by inductive hypothesis. Case r · s. If r ∈ pdx (r) s, then r = r s, for some r ∈ pdx (r). Induction yields L(r ) ⊆ x\L(r) so that L(r s) = L(r ) · L(s) ⊆ x\L(r) · L(s) = x\L(r · s). If n(r) and r ∈ pdx (s), then induction yields L(r ) ⊆ x\L(s) ⊆ x\L(r · s) because n(r). Case r∗ . If r ∈ pdx (r) r∗ , then r = r r∗ , for some r ∈ pdx (r). Induction yields L(r ) ⊆ x\L(r) so that L(r r∗ ) = L(r )·L(r∗ ) ⊆ x\L(r)· L(r∗ ) = x\L(r · r∗ ). Case rP1 ||PΓ2 s. We distinguish among the following subcases. Subcase x ∈ Γ: Assume r = rP1 ||PΓ2 s where r ∈ pdx (r). By induction L(r ) ⊆ x\L(r). Via Lemma 4 we obtain L(rP1 ||PΓ2 s) ⊆ x\L(rP1 ||PΓ2 s) and we are done. Otherwise r = rP1 ||PΓ2 s where s ∈ pdx (s). Via a similar argument we can show that L(rP1 ||PΓ2 s ) ⊆ x\L(rP1 ||PΓ2 s) which concludes this subcase. Subcase x ∈ Γ and P1 ∩ P2 = ∅: We find r = r∅ ||∅Γ s where r ∈ pdx (r). By induction L(r ) ⊆ x\L(r). Via Lemma 6 we obtain L(r∅ ||∅Γ s) ⊆ x\L(r∅ ||∅Γ s). As observed earlier, for P1 ∩ P2 = ∅ we have that L(r∅ ||∅Γ s) = L(rP1 ||PΓ2 s) and we are done. Subcase x ∈ Γ and P1 ∩ P2 = ∅: Can be verified similarly to the above. Subcase x ∈ Γ and (P1 ∪ x) ∩ P2 = ∅: We find r = rP1 ∪x ||PΓ2 s where r ∈ pdx (r). By induction L(r ) ⊆ x\L(r) and Lemma 8 we can establish the desired result. Subcase x ∈ Γ and P1 ∩ (P2 ∪ x) = ∅: Can be verified similarly to the above. The proof for the other direction x\L(r) ⊆ L(pdx (r)) is similar. A noteworthy point is that for this direction we require distributivity of alternatives over concatenation and shuffling: L((r1 + r2 ) · r3 ) = L(r1 · r3 + r2 · r3 ) L((r1 + r2 )P1 ||PΓ2 r3 ) = L(r1 P1 ||PΓ2 r3 + r2 P1 ||PΓ2 r3 ) The first equivalence obviously holds. The second equivalence holds by easy inspection of the definition of general synchronous shuffling.
20
The proof of x\L(r) ⊆ L(pdx (r)) proceeds by induction where we encounter intermediate forms such as “pdx (r)P1 ||PΓ2 s”. Recall L(pdx (r)) = r ∈pdx (r) L(r ). Thanks to the above distributivity laws such forms can be
P1 P2 ||Γ s on transformed into a sequence of alternatives written r ∈pdx (r) r which we can then apply similar reasoning steps as above. Lemma 11. For all r ∈ RΣ and w ∈ Σ∗ , L(pdw (r)) = w\L(r). Proof. The proof is by induction on w. Case . Immediate. Case x · w. L(pdx·w (r)) = {L(pdx (r )) | r ∈ pdw (r)} {by Lemma 10} = {x\L(r ) | r ∈ pdw (r)} = x\L( {r | r ∈ pdw (r)}) = x\L(pdw (r)) {by induction} = x\(w\L(r)) = x · w\L(r).
Theorem 11 (Representation). For r ∈ RΣ , L(r) = ((n(r)) ⇒ {}) ∪ x · L(pd x (r)). x∈Σ Proof. Straightforward using Theorem 10. We prove finiteness following the method suggested by Broda and coworkers [14]. We first define a function that computes a finite superset of pdΣ+ (r). Then we show that the image of this function is closed under taking the partial derivative, which proves the claim.
21
Definition 14. The iterated partial derivatives of r ∈ RΣ , written pd+ (r), are defined inductively by pd+ (φ) pd+ () pd+ (x) pd+ (r + s) pd+ (r · s) pd+ (r∗ ) pd+ (rP1 ||PΓ2 s)
= = = = = = =
{} {} {} pd+ (r) ∪ pd+ (s) pd+ (r) s ∪ pd+ (s) pd+ (r) r∗ {rR ||SΓ s | r ∈ {r} ∪ pd+ (r), s ∈ {s} ∪ pd+ (s), R, S ⊆ Γ}.
Lemma 12. For each r, pd+ (r) is finite. Proof. Straightforward induction on r. Lemma 13. For all r, s, and x ∈ Σ, pdx (r s) = pdx (r · s). Proof. Consider the cases in the definition of r s. Case r = φ or s = φ, then pdx (r s) = pdx (φ) = {}. pdx (φ · s) = pdx (φ) s ∪ (n(φ)) ⇒ pdx (s) = {}. pdx (r · φ) = pdx (r) φ ∪ (n(r)) ⇒ pdx (φ) = {}. Case r = , then pdx (r s) = pdx (s). pdx ( · s) = pdx () s ∪ (n()) ⇒ pdx (s) = pdx (s) Case s = , then pdx (r s) = pdx (r). pdx (r · ) = pdx (r) ∪ (n(r)) ⇒ pdx () = pdx (r). Case {s, r} ∩ {φ, } = ∅ is obvious. The next two lemmas are analogous to lemmas from Broda and coworkers [14]. The main novelty is the treatment of the cases for the general shuffle operator. Lemma 14. For all r and x ∈ Σ, pdx (r) ⊆ pd+ (r). Proof. By induction on r. Case φ, , y. Immediate. Case r + s. Immediate by induction.
22
Case r · s. pdx (r · s) = pdx (r) s ∪ (n(r)) ⇒ pdx (s) ⊆ pdx (r) s ∪ pdx (s) {inductive hypothesis for r and s} ⊆ pd+ (r) s ∪ pd+ (s) = pd+ (r · s) Case r∗ . pdx (r∗ ) = pdx (r) r∗ {by induction} ⊆ pd+ (r) r∗ = pd+ (r∗ ) Case rP1 ||PΓ2 s. Show that P = pdx (rP1 ||PΓ2 s) ⊆ pd+ (rP1 ||PΓ2 s). Subcase (PD7): Let P7 = (x ∈ / Γ) ⇒ {rP1 ||PΓ2 s | r ∈ pdx (r)} ∪ P {rP1 ||Γ2 s | s ∈ pdx (s)}. By induction, pdx (r) ⊆ pd+ (r) and pdx (s) ⊆ pd+ (s). Furthermore, P1 , P2 ⊆ Γ, so that P7 ⊆ pd+ (rP1 ||PΓ2 s). Subcase (PD8): Let P8 = (x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ {r∅ ||∅Γ s | r ∈ pdx (r), s ∈ pdx (s)}. By induction pdx (r) ⊆ pd+ (r) and pdx (s) ⊆ pd+ (s). Furthermore, ∅ ⊆ Γ, so that P8 ⊆ pd+ (rP1 ||PΓ2 s). Subcase (PD9): Let P9 = (x ∈ Γ ∧ P1 ∩ P2 = ∅) ⇒ {rP1 ||PΓ2 s | r ∈ pdx (r), s ∈ pdx (s)}. By induction, pdx (r) ⊆ pd+ (r) and pdx (s) ⊆ pd+ (s). Furthermore, P1 , P2 ⊆ Γ, so that P9 ⊆ pd+ (rP1 ||PΓ2 s). Subcase (PD10): Let P10 = (x ∈ Γ ∧ (P1 ∪ x) ∩ P2 = ∅) ⇒ {rP1 ∪x ||PΓ2 s | r ∈ pdx (r)}. By induction pdx (r) ⊆ pd+ (r). Furthermore, P1 ∪ x ⊆ Γ and P2 ⊆ Γ, so that P10 ⊆ pd+ (rP1 ||PΓ2 s). Subcase (PD11): Let P11 = (x ∈ Γ ∧ P1 ∩ (P2 ∪ x) = ∅) ⇒ {rP1 ||PΓ2 ∪x s | s ∈ pdx (s)}. By induction pdx (s) ⊆ pd+ (s). Furthermore, P1 ⊆ Γ and P2 ∪ x ⊆ Γ, so that P11 ⊆ pd+ (rP1 ||PΓ2 s). Concluding: By definition, P = P7 ∪ P8 ∪ P9 ∪ P10 ∪ P11 and from the subcases, we can conclude that P ⊆ pd+ (rP1 ||PΓ2 s). Lemma 15. For all r ∈ {r} ∪ pd+ (r) and x ∈ Σ, pdx (r ) ⊆ pd+ (r). Proof. By induction on r. 23
Case φ, , y. Immediate. Case r + s. Immediate by induction. Case r · s. Consider some r ∈ pd+ (r · s) = pd+ (r) s ∪ pd+ (s). If r ∈ pd+ (s), then pdx (r ) ⊆ pd+ (s) ⊆ pd+ (r·s) by induction. If r ∈ pd+ (r)s, then ∃r ∈ pd+ (r) such that r = r s. Then pdx (r ) = pdx (r s) {by Lemma 13} = pdx (r · s) = pdx (r ) s ∪ (n(r )) ⇒ pdx (s) {by induction} ⊆ pd+ (r) s ∪ pd+ (s) = pd+ (r · s) Case r∗ . Consider some r ∈ pd+ (r∗ ) = pd+ (r) r∗ . Thus, there exists r ∈ pd+ (r) such that r = r r∗ .
pdx (r ) = pdx (r r∗ ) {by Lemma 13} = pdx (r · r∗ ) = pdx (r ) r∗ {by induction} ⊆ pd+ (r) r∗ = pd+ (r∗ ) Case rP1 ||PΓ2 s. Consider some r0 ∈ pd+ (rP1 ||PΓ2 s) and show that pdx (r0 ) ⊆ pd+ (rP1 ||PΓ2 s). That is, there exists r ∈ {r} ∪ pd+ (r), s ∈ {s} ∪ pd+ (s), and R, S ⊆ Γ such that r0 = rR ||SΓ s . Now consider pdx (rR ||SΓ s ). Subcase (PD7): Let P7 = (x ∈ / Γ) ⇒ {rR ||SΓ s | r ∈ pdx (r )} ∪ {rR ||SΓ s | s ∈ pdx (s )}. By Lemma 14 or by induction pdx (r ) ⊆ pd+ (r) and pdx (s ) ⊆ pd+ (s). Furthermore R, S ⊆ Γ. Hence, P7 ⊆ pd+ (rP1 ||PΓ2 s). The remaining subcases are analogous to the subcases treated in Lemma 14. As above, we conclude that pdx (r0 ) ⊆ pd+ (rP1 ||PΓ2 s). Lemma 16. For all r, pdΣ+ (r) ⊆ pd+ (r).
24
Proof. Show that for each w ∈ Σ+ , pdw (r) ⊆ pd+ (r), by induction on w. If w = x, a singleton word, then pdx (r) ⊆ pd+ (r) by Lemma 14. If w = vx, forsome v ∈ Σ+ , then induction that pdv (r) ⊆ pd+ (r). Now yields pdvx (r) = {pdx (r ) | r ∈ pdv (r)} ⊆ {pdx (r ) | r ∈ pd+ (r)} ⊆ pd+ (r) by Lemma 15. Corollary 3. For all r, pdΣ+ (r) is finite. Proof. Immediate by finiteness of pd+ (r) (Lemma 12) and Lemma 16. Definition 15 (Derivative-based NFA Construction). For r ∈ RΣ we define the nondeterministic finite automaton N (r) = (Q, Σ, q0 , δ, F ) where Q = pdΣ∗ (r), q0 = r, for each q ∈ Q and x ∈ Σ we define δ(q, x) = pdx (q), and F = {q ∈ Q | n(q)}. Theorem 12. For all r ∈ RΣ , we have that L(r) = L(N (r)). Proof. Similar to the proof of Theorem 9. For comparison with the deterministic automata from the previous section, we apply the NFA construction to the same regular expressions with shuffle. In Figure 3, we give the NFAs for interleaving (left) and strongly synchronized shuffling (right). The appendix contains the details how numerical state names are connected to descendants. For the example with the interleave operator, we obtain a nondeterministic automaton with three states, the same size as the minimal deterministic automaton in Figure 1. For the example with the strongly synchronized shuffle, the nondeterministic automaton has just two states. However, it is essentially the same (deterministic) automaton as in Figure 1 except that the non-accepting sink state and its transitions are removed. For the example with the weakly synchronized shuffle, we obtain a nondeterministic automaton in Figure 4 with 13 states, of which 10 are final. This result may be surprising because the corresponding deterministic automaton in Figure 1 has fewer states. The higher number of states may be attributed to our use of distributivity in the construction of the deterministic automaton. Distributivity leads to states of the form (r + s) · t in the automaton in Figure 1, which can never arise from the construction of partial derivatives. 25
y x
1
x y
2
x
y x
x y
3
y x 1
x
2
x
N (((x + y)∗ (x · y ∗ ))∗ )
N (((x + y)∗ |||{x,y} (x · y ∗ ))∗ )
Figure 3: NFA Examples for Interleaving and Strongly Synchronized Shuffling
7. Discussion (Partial) Derivatives for free via Transformation. Based on the results from Sections 3, 5 and 6, we obtain for free derivatives and partial derivatives for interleaving, weakly and strongly synchronized shuffling as well as synchronous composition. Our method is as follows: 1. Transform each shuffle expression into its general synchronous shuffle representation as specified in Section 4. 2. Apply the (partial) derivative constructions from Sections 5 and 6 to the resulting expression. For interleaving ( ), weakly (| ∼ |Γ ) and strongly synchronized shuffling (|||Γ ) the transformation step is purely syntactic. The results from Section 4 imply the following identities: r s = rΣ ||Σ ∅s
r|||Γ s = rΣ ||Σ Γs
r| ∼ |Γ s = r∅ ||∅Γ s.
These identities are exhaustively applied from left to right. It is easy to see that this process eventually terminates and we thus obtain an expression only composed of the general synchronous shuffling operation. For synchronous composition (|||) the identity r|||s = rΣ ||Σ α(r)∩α(s) s applies. For this case the transformation step is more involved as we must compute the alphabet of expressions (resp. the alphabet of the underlying languages). We define α(r) = α(L(r)). For plain regular expressions, we can easily compute the alphabet inductively by α(φ) = {}; α() = {}; α(r + s) = α(r) ∪ α(s); α(r∗ ) = α(r). α(x) = {x}; and α(r · s) = α(r) ∪ α(s) if L(r), L(s) = {}. Otherwise, α(r · s) = {}. The test L(r) = {} can again be defined by observing the expression structure. We omit the details. 26
x x
x x x y y y
x
8
x
y
x
x y x
y x
y x
x y y
y x
12 x y x
y
3
x
x
y x
y x x
6 y
x
2 y y x y x
x
y
y
x y
5 7
y
x y
x x
x
x
y
x 10
y x
y 1
4
y x
x
x y
x x
y x
x
13
y
y
x 11
x
x y y
Figure 4: N (((x + y)∗ | ∼ |{x,y} (x · y ∗ ))∗ )
27
y
9
In the presence of shuffle expressions such as synchronous composition, it is not obvious how to appropriately extend the above structural definition. For example, consider x · x · y|||x · y. We find that α(x · x · y) = {x, y} and α(x · y) but α(x · x · y|||x · y) = {} due to the fact that x · x · y|||x · y equals φ. Hence, to compute the alphabet of some r ∈ RΣ we first convert r into a DFA M using the derivative-based automata construction. To compute the alphabet of M we use a variant of the standard emptiness check algorithm for DFAs. First, we compute all reachable paths from any of the final states to the initial state. To avoid infinite loops we are careful not to visit a transition twice on a path. Then, we obtain the alphabet of M by collecting the set of all symbols on all transitions along these paths. Thus, the transformation of expressions composed of synchronous composition proceeds as follows. In the to be transformed expression, we pick any subexpression r1 |||r2 where r1 , r2 ∈ RΣ . If there is none we are done. Otherwise, we must find r1 and r2 which have already been transformed, resp., do not contain any shuffling operator. Alphabets α(r1 ) and α(r2 ) are computed as described and subexpression r1 |||r2 is replaced by r1 Σ ||Σ α(r1 )∩α(r2 ) r2 . This process repeats until all synchronous composition operations have been replaced. Specialization of (partial) derivative method. Instead of first transforming each shuffle variant into its general form and then applying the general (partial) derivative method, we might want to specialize the general (partial) derivative method. The key to obtain specialized (partial) derivative methods is to show that the general (partial) derivative methods are closed for certain classes of expressions. As we will shortly see, this only applies to shuffling and strongly synchronized shuffling but not to weak synchronous shuffling and synchronous composition. |·| We will write RΣ to denote the subset of regular expressions restricted to shuffle expressions composed of | · | where | · | stands for any of the four shuffling forms we have seen so far.
Theorem 13 (Closure for Shuffling). For any r ∈ RΣ and x ∈ Σ we
have that (1) dx (r) ∈ RΣ and (2) for each r ∈ pdx (r) we find that r ∈ RΣ . Proof. Recall that can be expressed as ∅ ||∅∅ . By case analysis of Definitions 9 and 13. The cases that apply are (D7) and (PD7).
28
Theorem 14 (Closure for Strongly Synchronized Shuffling). For any ||| ||| r ∈ RΣ Γ and x ∈ Σ we have that (1) dx (r) ∈ RΣ Γ and (2) for each r ∈ pdx (r) ||| we find that r ∈ RΣ Γ . Proof. Recall that |||Γ can be expressed as Γ ||ΓΓ . Again by case analysis. This time only cases (D7) and (D9) in case of derivatives and cases (PD7) and (PD9) in case of partial derivatives apply. We obtain the following specialized functions for computing derivatives = dx (r) s + r dx (r) dx (r s) dx (r|||Γ s) = (x ∈ Γ) ⇒ dx (r)|||Γ dx (s) +(x ∈ Γ) ⇒ dx (r)|||Γ s + r|||Γ dx (s) and partial derivatives = {r s | r ∈ pdx (r)} ∪ {r s | s ∈ pdx (r)} pdx (r s) pdx (r|||Γ s) = (x ∈ Γ) ⇒ {r |||Γ s | r ∈ pdx (r) s ∈ pdx (s)} ∪(x ∈ Γ) ⇒ {r |||Γ s | r ∈ pdx (r)} ∪ {r|||Γ s | s ∈ pdx (r)} This result does not extend to weak synchronous shuffling and synchronous composition, as they are not closed under derivative. For example, consider weak synchronous shuffling | ∼ |Γ which is expressed by ∅ ||∅Γ . For the expression x · z ∅ ||∅{x} y, we find that {x}
dx (x · z ∅ ||∅{x} y) = z {x} ||∅{x} y + x · z ∅ ||{x} φ |∼|
The expression on the right-hand side is not part of RΣ Γ due to subexpressions of the form z {x} ||∅{x} y. Hence, the closure property does no longer hold. A similar observation applies to synchronous composition. The above implies that simple, direct (partial) derivative methods for weak synchronous shuffling and synchronous composition do not seem to exist. For example, consider the following attempt to define a direct derivative method for synchronous composition dx (r|||s) = (x ∈ α(r) ∩ α(s)) ⇒ dx (r)|||dx (s) +(x ∈ α(r) ∩ α(s)) ⇒ dx (r)|||s + r|||dx (s)
29
The above is similar to the specialized definition for strong synchronized ||| shuffling. Expressions generated are clearly in RΣ . However, the definition is flawed as shown by the following example. Consider (x · y · z)|||(x · y + z) and repeatedly compute the derivative w.r.t. the symbols x, y and z. First, we compute dx ((x · y · z)|||(x · y + z)) = (y · z)|||y where for brevity we apply simplifications such as · r = r etc. Next, we build dy ((y · z)|||y) = z||| followed by dz (z|||) = ||| = . This derivation (wrongly) suggests that x · y · z ∈ L((x · y · z)|||(x · y + z)) because dx·y·z ((x · y · z)|||(x · y + z)) is nullable. The mistake in our calculation lies in the third derivative construction step dz (z|||) = |||. Based on the expression z|||, the symbol z does not need to be synchronized because z only appears in the left sub-expression. However, this is reasoning step is wrong! Symbol z is part of the alphabets of the left and right sub-expressions in (x · y · z)|||(x · y + z). Hence, both sub-expressions (left and right) need to be synchronized. In terms of the derivative operation, we should have calculated dz (z)|||dz () instead. The problem is that this information about symbol z is only apparent in the initial expression and the subsequently computed expressions using the synchronous composition operator have lost this information. Hence, the above direct derivative method for synchronous composition is flawed. A similar observation applies to weak synchronous shuffling. Hence, to appropriately define derivatives for weak synchronous shuffling derivatives it is strictly necessary to enrich the expression language with general synchronous shuffling. 8. Related Work To the best of our knowledge, there is almost no prior work which studies the notion of Brzozowski derivatives and Antimirov’s partial derivatives in connection with shuffling operators. We are only aware of Lodaya and coworkers [15] whose work seems to imply a definition of derivatives for strongly synchronized shuffling [8]. Broda and coworkers [14] define partial derivatives for plain shuffling whereas Caron and coworkers [16] consider extended regular expressions. Further work in the area studies the construction of automata for plain shuffling commonly referred to as asynchronous interleaving [9, 10]. In contrast, we provide detailed definitions how to obtain derivatives and partial derivatives including formal results for various shuffling operations [7, 1, 8]. Our results imply algorithms for constructing automata as shown 30
in this paper. We believe they extend to checking equality and containment of regular expressions with shuffles in analogy to algorithms by Grabmayer [6] and Antimirov [5]. 9. Conclusion Thanks to a general form of synchronous shuffling introduced in this paper we can extend the notion of a Brzozowski derivative and a Antimirov partial derivative to various forms of shuffling operators which appear in the literature [8, 7, 1]. Our construction enables the application of algorithms based on derivatives for shuffle expressions such as automata-based word recognition algorithms [17] and equality/containment checking [5, 6]. Acknowledgments We thank the reviewers for their comments. References [1] V. K. Garg, M. T. Ragunath, Concurrent regular expressions and their relationship to Petri nets, Theoretical Comput. Sci. 96 (2) (1992) 285– 304. [2] P. D. Stotts, W. Pugh, Parallel finite automata for modeling concurrent software systems, J. Syst. Softw. 27 (1) (1994) 27–43. [3] J. A. Brzozowski, Derivatives of regular expressions, J. ACM 11 (4) (1964) 481–494. [4] V. M. Antimirov, Partial derivatives of regular expressions and finite automaton constructions, Theoretical Comput. Sci. 155 (2) (1996) 291– 319. [5] V. M. Antimirov, Rewriting regular inequalities, in: Proc. of FCT’95, Vol. 965 of LNCS, Springer, 1995, pp. 116–125. [6] C. Grabmayer, Using proofs by coinduction to find ”traditional” proofs, in: Proc. of CALCO’05, Vol. 3629 of LNCS, Springer, 2005, pp. 175–193. [7] R. de Simone, Langages infinitaires et produit de mixage, Theoretical Comput. Sci. 31 (1984) 83–100. 31
[8] M. H. ter Beek, C. Mart´ın-Vide, V. Mitrana, Synchronized shuffles, Theoretical Comput. Sci. 341 (1-3) (2005) 263–275. [9] W. Gelade, Succinctness of regular expressions with interleaving, intersection and counting, Theoretical Comput. Sci. 411 (31-33) (2010) 2987–2998. [10] A. Kumar, A. K. Verma, A novel algorithm for the conversion of parallel regular expressions to non-deterministic finite automata, Appl. Math. Inf. Sci. 8 (2014) 95–105. [11] M. Sulzmann, P. Thiemann, Derivatives for regular shuffle expressions, in: Proc. of LATA’15, Vol. 8977 of LNCS, Springer, 2015, pp. 275–286. [12] T. Nipkow, D. Traytel, Unified decision procedures for regular expression equivalence, Archive of Formal Proofs 2014. [13] G. Rosu, M. Viswanathan, Testing extended regular language membership incrementally by rewriting, in: Proc. of RTA’03, Vol. 2706 of LNCS, Springer, 2003, pp. 499–514. [14] S. Broda, A. Machiavelo, N. Moreira, R. Reis, Partial derivative automaton for regular expressions with shuffle, in: Proc. of DCFS, Vol. 9118 of LNCS, Springer, 2015, pp. 21–32. [15] K. Lodaya, M. Mukund, R. Phawade, Kleene theorems for product systems, in: Proc. of DCFS’11, Vol. 6808 of LNCS, Springer, 2011, pp. 235–247. [16] P. Caron, J.-M. Champarnaud, L. Mignot, Partial derivatives of an extended regular expression, in: LATA, Vol. 6638 of LNCS, Springer, 2011, pp. 179–191. [17] S. Owens, J. Reppy, A. Turon, Regular-expression derivatives reexamined, J. Funct. Programming 19 (2) (2009) 173–190. Appendix A. Details of Derivative DFA Examples Appendix A.1. D(((x + y)∗ (x · y ∗ ))∗ ) The DFA has 3 states of which 2 are final states and 6 transitions. The connection among numerical state names and descendants is as follows. 32
1. :((x + y)∗ x · y ∗ )∗ 2. :(((x + y)∗ x · y ∗ ) + ((x + y)∗ y ∗ )) · ((x + y)∗ x · y ∗ )∗ 3. :((x + y)∗ x · y ∗ ) · ((x + y)∗ x · y ∗ )∗ Appendix A.2. D(((x + y)∗ |||{x,y} (x · y ∗ ))∗ ) The DFA has 3 states out of which 2 are final. There are 6 transitions. The connection among numerical state names and descendants is as follows. 1. :((x + y)∗ |||{x,y} x · y ∗ )∗ 2. :((x + y)∗ |||{x,y} y ∗ ) · ((x + y)∗ |||{x,y} x · y ∗ )∗ 3. :φ Appendix A.3. D(((x + y)∗ | ∼ |{x,y} (x · y ∗ ))∗ ) The DFA has 11 states out of which 10 are final. There are 22 transitions. The connection among numerical state names and descendants is as follows. Recall that the derivative operation is not closed for weakly synchronized shuffling. See the discussion regarding specialization of the (partial) derivative method in Section 7. Hence, we give a presentation in terms of the general synchronous shuffling operator. {}
1. :((x + y)∗{} ||{x,y} x · y ∗ )∗ 2. :(((x + y) 3. 4.
5.
6. 7.
8.
9.
10.
11.
∗{}
{}
{x}
{}
{}
||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x} ||{x,y} x · y ∗ )) · ((x + y)∗{} ||{x,y} x · y ∗ )∗
{} {} :((x + y) ||{x,y} x · y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {} {} ∗{} {} ∗ ∗{} {x} :(((x + y) ||{x,y} y ) + ((x + y) ||{x,y} y ∗ ) + ((x + y)∗{x} ||{x,y} x · y ∗ ) + ((x + y)∗{x} ||{x,y} y ∗ )) · ((x + ∗{} {} ∗ ∗ ||{x,y} x · y ) y) {} {x,y} {y} {} :(((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x,y} ||{x,y} x · y ∗ ) + ((x + ∗{y} {} ∗ ∗{y} {} ∗ ∗{y} {x} ∗ ∗{} {} ||{x,y} x · y ) + ((x + y) ||{x,y} y ) + ((x + y) ||{x,y} y )) · ((x + y) ||{x,y} x · y ∗ )∗ y) {} {} {x} {} :(((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x,y} ||{x,y} x · y ∗ ) + ((x + y)∗{y} ||{x,y} y ∗ )) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {} {x,y} {y} {y} :(((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x} ||{x,y} y ∗ ) + ((x + {} {} {} {} y)∗{x,y} ||{x,y} x · y ∗ ) + ((x + y)∗{x,y} ||{x,y} y ∗ ) + ((x + y)∗{y} ||{x,y} x · y ∗ ) + ((x + y)∗{y} ||{x,y} y ∗ ) + ((x + ∗{y} {x} ∗ ∗{} {} ∗ ∗ ||{x,y} y )) · ((x + y) ||{x,y} x · y ) y) {} {x} {} {} :(((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x} ||{x,y} x · y ∗ ) + ((x + y)∗{x} ||{x,y} y ∗ ) + ((x + ∗{x} {y} ∗ ∗{x,y} {} ∗ ∗{x,y} {} ∗ ∗{y} {x} ||{x,y} y ) + ((x + y) ||{x,y} x · y ) + ((x + y) ||{x,y} y ) + ((x + y) ||{x,y} y ∗ )) · ((x + y) ∗{} {} ∗ ∗ ||{x,y} x · y ) y) {} {x} {} {} :(((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x} ||{x,y} x · y ∗ ) + ((x + y)∗{x} ||{x,y} y ∗ ) + ((x + ∗{x,y} {} ∗ ∗{} {} ∗ ∗ ||{x,y} x · y )) · ((x + y) ||{x,y} x · y ) y) {} {y} {} {} :(((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x,y} ||{x,y} x · y ∗ ) + ((x + y)∗{y} ||{x,y} x · y ∗ ) + ∗{y} {} ∗ ∗{y} {x} ∗ ∗{} {} ∗ ∗ ||{x,y} y ) + ((x + y) ||{x,y} y )) · ((x + y) ||{x,y} x · y ) ((x + y) {} {x} {} {} :(((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{} ||{x,y} y ∗ ) + ((x + y)∗{x} ||{x,y} x · y ∗ ) + ((x + y)∗{x} ||{x,y} y ∗ ) + ((x + ∗{x} {y} ∗ ∗{x,y} {} ∗ ∗{x,y} {} ∗ ∗{} {} ||{x,y} y ) + ((x + y) ||{x,y} x · y ) + ((x + y) ||{x,y} y )) · ((x + y) ||{x,y} x · y ∗ )∗ y) ∗{y}
33
Appendix B. Details of Partial Derivative NFA Examples Appendix B.1. N (((x + y)∗ (x · y ∗ ))∗ ) There are 3 states out of which 2 are final. There are 10 transitions. See Figure 3. The connection among numerical state names and descendants is as follows. 1. :((x + y)∗ x · y ∗ )∗ 2. :((x + y)∗ x · y ∗ ) · ((x + y)∗ x · y ∗ )∗ 3. :((x + y)∗ y ∗ ) · ((x + y)∗ x · y ∗ )∗ Appendix B.2. N (((x + y)∗ |||{x,y} (x · y ∗ ))∗ ) There are 2 states, all are also final. There are 3 transitions. See Figure 3. The connection among numerical state names and descendants is as follows. 1. :((x + y)∗ |||{x,y} x · y ∗ )∗ 2. :((x + y)∗ |||{x,y} y ∗ ) · ((x + y)∗ |||{x,y} x · y ∗ )∗ Appendix B.3. N (((x + y)∗ | ∼ |{x,y} (x · y ∗ ))∗ ) There are 13 states out of which 10 are final. There are 77 transitions. See Figure 4. The connection among numerical state names and descendants is as follows. As in case of the DFA example, we give a presentation in terms of the general synchronous shuffling operator for the reason as explained above. {}
1. :((x + y)∗{} ||{x,y} x · y ∗ )∗ {}
{}
2. :((x + y)∗{} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {}
{}
3. :((x + y)∗{x} ||{x,y} x · y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {x}
{}
4. :((x + y)∗{} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {}
{}
5. :((x + y)∗{y} ||{x,y} x · y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {}
{}
{}
{}
6. :((x + y)∗{x} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ 7. :((x + y)∗{y} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {y}
{}
8. :((x + y)∗{} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {}
{}
9. :((x + y)∗{x,y} ||{x,y} x · y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {x}
{}
10. :((x + y)∗{y} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {x,y}
{}
11. :((x + y)∗{} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {}
{}
12. :((x + y)∗{x,y} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ {y}
{}
13. :((x + y)∗{x} ||{x,y} y ∗ ) · ((x + y)∗{} ||{x,y} x · y ∗ )∗ 34