Regular Expressions Equivalence
- Construct NFA-lambdas corresponding to each RE using Kleene's theorem
- Construct DFAs for each using the subset/powerset construction
- (optional) Minimize the DFAs using a standard DFA minimization algorithm.
- Construct DFAs for L(M1) \ L(M2) and L(M2) \ L(M1) using the Cartesian Product Machine construction
- (Optional) Minimize these CPMs.
- Determine whether each one accepts any strings by testing all strings over alphabet E of size no greater than |Q| (works due to the pumping lemma for regular languages)
雖然從理論上已經解決了這個問題,但是從計算的角度甚至手算的角度來看,這個方法的結果並不能讓人滿意。可以說語言本身的計算依賴於自動機由來已久,語言本身的計算卻沒有發展起來。所以不斷有研究從不同的角度,甚至單獨從正則表達式空間上定義的一系列運算出發,來驗證正則表達式的等價性,而不必將運算映射到DFA空間上去。從數學的角度上看,這樣一系列理論的完善是簡潔和優美的,這使得正則表達式空間能夠是自閉和完備的,重要的結論可以通過該空間本身的性質直接推出,而不需要DFA的輔助。這樣的方法也是易於理解,符合人們在學習一個新的代數結構的一般過程。有些時候,這些方法的完善甚至是計算有利的。相關的工作可以參看論文Testing the equivalence of regular expressions [Marco Almeida...etc].
作為拋磚引玉的例子,這里給出幾個著名的正則表達式的等價的例子,這些例子在一般性的正則表達式的化簡上有一定的經驗作用。
\[(a^*b)^* = \varepsilon\ \lvert\ (a\lvert b)^* \tag{1} \]
\[(ab)^* = \varepsilon\ \lvert\ a(ba)^*b\tag{2} \]
\[a^*(a\lvert b)^* = (a\lvert b)^*a^* = b^*(a\lvert b)^* = (a\lvert b)^*b^* = (a\lvert b)^*\tag{3} \]