Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Finite Automaton equivalents to Regular Expression

N@N
December 13, 2015

Finite Automaton equivalents to Regular Expression

数物セミナー冬の大談話会2015 in 岡山での発表資料

N@N

December 13, 2015
Tweet

More Decks by N@N

Other Decks in Technology

Transcript

  1. $ perl -i -pe 's/foo/bar/g' input foo oaaahhhhhhhh! -> bar

    oaaahhhhhhhh! $ perl -i'*.bak' -pe 's/foo/bar/g' input
  2. • HT 0x09 ¥t LF 0x0a ¥n CR 0x0d ¥r

    LF ¥n CR ¥r CR+LF ¥r¥n
  3. • ≠ Σ • • Σ • • • Σ

    Σ5 ∋ = = 5 • = 0 • Σ = , , , , , , , , ⋯
  4. def = , Σ, , 0 , Σ : ×

    Σ → 0 ∈ ⊂
  5. 1 = {1 , 2 } Σ = 0,1 :

    × Σ → 1 ∈ 2 ⊂ 0 1 1 2 1 2 2 2 1 2
  6. • = , Σ, , 0 , • Σ ∋

    = 1 2 ⋯ ∀ ∈ Σ def ∃ ∈ s. t. 0 = 0 , +1 = +1 ∈
  7. • , • ∪ ≔ ∈ or ∈ • ∘

    ≔ ∈ and ∈ • ∗ ≔ 1 2 ⋯ ∈ ℕ, ∈ •
  8. • Σ ≔ , , ⋯ , • ≔ good,

    bad • ≔ start, end • ∪ = good, bad, start, end • ∘ = goodstart, goodend, badstart, badend • ∗ = , good, bad, goodgood, goodbad, badbad, ⋯
  9. 1 , 2 : Reg. Lang. ⇒ 1 ∪ 2

    : Reg. Lang. 1 , 2 : Reg. Lang. ⇒ 1 ∘ 2 : Reg. Lang. : Reg. Lang. ⇒ ∗: Reg. Lang.
  10. • 1 , 2 1 , 2 • 1 ∪

    2 • 1 , 2 • 1 or 2 • • 1 2 •
  11. • 1 = 1 , Σ, 1 , 1 ,

    1 1 • 2 = 2 , Σ, 2 , 2 , 2 2 1. ≔ 1 , 2 1 ∈ 1 and 2 ∈ 2 2. ∀ 1 , 2 ∈ : ∀ ∈ Σ: 1 , 2 , = 1 1 , , 2 2 , 3. 0 ≔ 1 , 2 4. ≔ 1 , 2 1 ∈ 1 or 2 ∈ 2 = 1 × 2 ∪ 2 × 1 = , Σ, , 0 ,
  12. • = , Σ, , 0 , = 1 ,

    2 , 1 , 1 , 1 , 2 , 1 , 2 , 1 , 1 , 1 , 2 : 1 × 2 × Σ → 1 × 2 0 = 1 , 2 = 1 , 2 , 1 , 1 , 1 , 2 , 1 , 1 1 1 2 1 2 1 2
  13. def = , Σ, , 0 , Σ : ×

    Σ → Σ ≔ Σ ∪ 0 ∈ ⊂
  14. = {1 , 2 , 3 , 4 } Σ

    = 0,1 : × Σ → 1 ∈ 2 ⊂ 0 1 ε 1 1 1 , 2 ∅ 2 3 ∅ 3 3 4 ∅ ∅ 4 ∅ ∅ ∅ 2 1 3 4
  15. • = , Σ, , 0 , • Σ ∋

    = 1 2 ⋯ ∀ ∈ Σ def ∃ ∈ s. t. 0 = 0 ∀ ∈ ℕ, ≤ − 1: +1 ∈ , +1 ∈
  16. iff ∀1 : NFA: ∃2 : DFA s. t. 1

    ≡ 2 ∀1 , 2 : FA 1 ≡ 2 def 1 2
  17. • = , Σ, , 0 , • ′ =

    ′, Σ, ′, 0 ′ , ′ • ′ • • • • card = ⇒ card = 2
  18. • = , Σ, , 0 , • ′ =

    ′, Σ, ′, 0 ′ , ′ 1. ′ ≔ 2. ∀ ∈ ′: ∀ ∈ Σ: ′ , = ∈ ∈ , , ∈ = , ∈ 3. 0 ′ ≔ 0 4. ′ ≔ ∈ ′ ⊂
  19. • ⊂ ′ ∈ ′ ∗ → • ⊂ ≔

    ∗ → ′ , = , = ∈ ∈ , , ∈ 0 ′ = 0 ///
  20. • = , Σ, , 0 , • ′ =

    ′, Σ, ′, 0 ′ , ′ • 0 ′ = 0 = 1 , 2 • ′ = 3 , 1 , 3 , 2 , 3 , 1 , 2 , 3 2 1 3
  21. 0 1 ε 1 1 1 , 2 ∅ 2

    3 ∅ 3 3 ∅ ∅ ∅ ′ 0 1 1 1 , 2 , 3 1 , 2 2 3 ∅ 3 ∅ ∅ 2 1 3
  22. ′ 0 1 1 1 , 2 , 3 1

    , 2 2 3 ∅ 3 ∅ ∅ ′ 0 1 1 1 , 2 , 3 1 , 2 2 3 ∅ 3 ∅ ∅ 1 , 2 1 , 2 , 3 1 , 2 1 , 2 , 3 1 , 2 , 3 1 , 2 2 1 3
  23. ′ = 1 , 2 , 1 , 2 ,

    3 0 ′ = 1 , 2 ′ = 1 , 2 , 3 1 , 2 , 3 1 , 2 ′ 0 1 1 , 2 1 , 2 , 3 1 , 2 1 , 2 , 3 1 , 2 , 3 1 , 2
  24. 1 , 2 : Reg. Lang. ⇒ 1 ∪ 2

    : Reg. Lang. 1 , 2 : Reg. Lang. ⇒ 1 ∘ 2 : Reg. Lang. : Reg. Lang. ⇒ ∗: Reg. Lang.
  25. 1. ≔ 0 ∪ 1 ∪ 2 2. ∀ ∈

    : ∀ ∈ Σ : , = 1 , ∈ 1 2 , ∈ 2 1 , 2 = 0 and = ∅ = 0 and ≠ 3. ≔ 1 ∪ 2 • = 0 and = • 1 ∘ 2 , ∗
  26. • Σ = 0,1 • 0 ∪ 1 ∗ •

    0 ∪ 1 ∗0 0 ∪ 1 ∗ ∘ 0 • 0Σ∗ ∪ 1Σ∗ ΣΣ∗
  27. • ∗, 1 ∘ 2 , 1 ∪ 2 •

    1 ∗ ∪ 2 ∘ 3 ∪ 4 ∗ 1 ∗ ∪ 2 ∘ 3 ∪ 4 ∗
  28. def 1. ∈ Σ 2. 3. ∅ 4. 1 ∪

    2 5. 1 ∘ 2 6. 1 ∗ 1 , 2
  29. • + ≔ ∗ • + = ∪ • ≔

    ⋯ ∈ ℕ • 1∗∅ ≔ ∅ • ∅∗ ≔ • ∗
  30. ⇐ 1. ∈ Σ = = = 1 , 2

    , Σ, , 1 , 2 2. = = = 1 , Σ, , 1 , 1 a 1 2 1
  31. ⇐ 3. = ∅ = ∅ = 1 , Σ,

    , 1 , ∅ 4. = 1 ∪ 2 5. = 1 ∘ 2 6. = 1 ∗ 1
  32. • = , Σ, , 0 , • ′ =

    ′, Σ, ′, , • → ′ 1. 0 → 2. ∈ : → ∅
  33. def = , Σ, , , Σ : − ×

    − → ℛ ℛ ∈ ∈ 1 , 2 = 1 2
  34. • = , Σ, , , • Σ ∋ =

    1 2 ⋯ ∀ ∈ Σ∗ def ∃ ∈ s. t. 0 = = ∀ ∈ ℕ: = −1 , ⇒ ∈
  35. ⇒ CONVERT 7. > 2 , ≠ rip ∈ ′

    = ′, Σ, ′, , ′ = − rip ∀ ∈ ′ − , ∀ ∈ ′ − : ′ , = 1 2 ∗ 3 ∪ 4 1 = , rip , 2 = rip , rip , 3 = rip , , 4 = , 8. CONVERT ′ = 2
  36. ⇒ ⇒ − 1 ′ , 1 , 2 ,

    ⋯ , ≠ rip ∀ ′