Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and...

30
Derivatives of Regular Expressions and an Application Haiming Chen 1 and Yu Shen 2 1 State Key Laboratory of Computer Science, ISCAS 2 Department of Computer Science, University of Western Ontario WTCS 2012, Auckland 2012.2.22

Transcript of Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and...

Page 1: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Derivatives of Regular Expressions and an Application

Haiming Chen1 and Yu Shen2

1State Key Laboratory of Computer Science, ISCAS2Department of Computer Science, University of

Western OntarioWTCS 2012, Auckland 2012.2.22

Page 2: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Derivatives w-1(E) Brzozowski, 1964è (left) quotient of language w-1L(E)

Berry and Sethi ‘s Result 1986Derivatives of E classes of similar derivatives

E linearOur workA characterization of the structure of derivatives of linear E implies Berry and Sethi ‘s Result

Why?

2

Page 3: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

DerivativesBerry and Sethi’s resultStructure of derivativesProperties of repeating termsAn applicationConclusion

3

Page 4: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Regular expressionsE ::= φ | ε | a∈Σ | E + E | EE | E*

ACI-similarE1 ∼aci E2

Associativity (E1 + E2) + E3 = E1 + (E2 + E3 )Commutativity E1 + E2 = E2+ E1

Idempotence E + E = E

4

Page 5: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Marked expressions(a+b)*ab(a+b) E (a1+b1)*a2b2 (a3+b3)The same notation used for dropping of subscripts:

NoteMarking is not uniqueFor example (a1+b2)*a3b4 (a5+b6)

E

EE =

5

Page 6: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

(left) quotient set of a language Lw-1(L)={u | wu∈ L}L = wL(w-1(L))

Derivatives (Brzozowski)

6

Page 7: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Derivatives Berry and Sethi’s resultStructure of derivativesProperties of repeating termsAn applicationConclusion

7

Page 8: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Regular expressions with distinct symbols (linear):One symbol occurs only once

Next we consider this kind of expressions

8

Page 9: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Derivatives Berry and Sethi’s resultStructure of derivativesProperties of repeating termsAn applicationConclusion

9

Page 10: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Berry and Sethi proved that

x1

xi

xn

……

Non-null derivatives of E

|ΣE| = n

10

Page 11: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Theorem 1 Let all symbols in E be distinct. Given a fixed x ∈ ΣE, for all words w, each non-null (wx)-1(E) must be of one of the following forms: F or F + … + F, where F is a non-null regular expression called the repeating term of (wx)-1(E) which does not contain + at the top level.

repeating term for (wa1)-1(E): τ1(wa3)-1(E): τ2

Corollary 1 Let all symbols in E be distinct. If (wx)-1(E) is non-null, then (wx)-1(E) ∼aci rtx(E).

a more precise version of Berry and Sethi's result 11

Page 12: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Q: For each x ∈ ΣE, whether there is a non-null (wx)-1(E) containing one rtx(E), that is, rtx(E) is a derivative of E.

A: positive see belowThe first appearance Fx(E)

12

Page 13: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

13

Page 14: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Proposition 1 Let all symbols in E be distinct. Given a fixed x ∈ ΣE, the first appearance Fx(E) consists of only one repeating term.

The choice of the order is not significant.Proposition 2 Let all symbols in E be distinct. Given any words w1, w2 ∈ ΣE*

and x ∈ ΣE, if | w1 |=| w2 | and (w1x)-1(E), (w2x)-1(E) ≠ φ, and there is no w, such that |w|<| w1 | and ), (w x)-1(E) ≠ φ, then (w1 x)-1(E) = (w2x)-1(E).

Proposition 3 Let all symbols in E be distinct. There exists a word w ∈ ΣE* for each x ∈ ΣE, such that (w x)-1(E) = rtx(E).

Thus repeating terms are derivatives of E, and any non-null derivative of Eis built from one of them.

14

Page 15: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Derivatives Berry and Sethi’s resultStructure of derivativesProperties of repeating termsAn applicationConclusion

15

Page 16: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

There cannot be two rtx(E) for (w x)-1(E)

16

Page 17: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

17

Page 18: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Proposition 8 Let all symbols in E be distinct. If there are non-null (w1 x1)-1(E) and (w2 x2)-1(E), such that (w1 x1)-1(E) ∼aci (w2 x2)-1(E), then rtx1(E) = rtx2(E), and vice versa.

Corollary 2 Let all symbols in E be distinct. If rtx1(E) ∼aci rtx2(E), then rtx1(E)=rtx2(E).

Remark rtx(E)'s are `atomic' building blocks(1) Each non-null (w x)-1(E) is uniquely decomposed into a sum of rtx(E), that is, (w x)-1(E) = ∑rtx(E).(2) rtx(E) and rty(E) are either identical, or not equivalent modulo ∼aci, if x≠y.

18

Page 19: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Derivatives Berry and Sethi’s resultStructure of derivativesProperties of repeating termsAn applicationConclusion

19

Page 20: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Solves an issue in using Berry and Sethi's result: find a unique representative for (w x)-1(E)

20

Page 21: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Glushkov automaton

Berry and Sethi showed the class of derivatives {(w x)-1(E)} corresponds to a state x of Mpos(E), x ∈

21

Page 22: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

In many cases, however, one needs a unique representative for the class of {(w x)-1(E)} to correspond to a state x

By the work, the representatives are obtained immediately

22

Page 23: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

An improvement of Ilie and Yu‘s proof presented in (Ilie & Yu 2003)A proof about the quotient relation between Glushkov and partial derivative automata

23

Page 24: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

24

Partial derivatives

Page 25: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Partial derivative automaton

25

Page 26: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Ilie and Yu’s proof– The central issue is to find a unique representative for a

class of derivatives– The proof fails to find the correct representatives

Example. In Example 1, and are distinct

26

It is claimed in the proof that, by using the rules (φε-rules), for a fixed

and for all words w, is either φ or unique.

incorrectRules (φ-rules)

Page 27: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

An improved proofUse as the unique representative.See our paper

27

Page 28: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Derivatives Berry and Sethi’s resultStructure of derivativesProperties of repeating termsAn applicationConclusion

28

Page 29: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

A characterization of the structure of derivativesSeveral propertiesAn applicationA useful technique

29

Page 30: Derivatives of Regular Expressions wtcs2012.ppt [兼容 … · and an Application Haiming Chen1 and Yu ... Partial derivatives. Partial derivative automaton 25. ... Derivatives of

Thanks!

30