Language-Processing Problems Roland Backhouse DIMACS, 8th July, - - PowerPoint PPT Presentation

language processing problems
SMART_READER_LITE
LIVE PREVIEW

Language-Processing Problems Roland Backhouse DIMACS, 8th July, - - PowerPoint PPT Presentation

1 Language-Processing Problems Roland Backhouse DIMACS, 8th July, 2003 2 Introduction Factors and the factor matrix were introduced by Conway (1971). He used them very effectively in, for example, constructing biregulators.


slide-1
SLIDE 1

1

Language-Processing Problems

Roland Backhouse DIMACS, 8th July, 2003

slide-2
SLIDE 2

2

Introduction

“Factors” and the “factor matrix” were introduced by Conway (1971). He used them very effectively in, for example, constructing biregulators. Conway’s discussion is wordy, making it difficult to understand. There are also occasional errors which are difficult to detect and add to the confusion. (“The theorem does prevent E from occurring twice” should read “The theorem does not prevent E from occurring twice.”)

slide-3
SLIDE 3

3

KMP Failure Function (pattern aabaa)

node i 1 2 3 4 5 failure node f(i) 1 1 2

Factor Graph (language Σ∗aabaa)

b ✒✑ ✓✏ ✒✑ ✓✏ ✒✑ ✓✏ ✒✑ ✓✏ ✒✑ ✓✏ ✒✑ ✓✏ ✲ ✲ ✲ ✲ ✲ a a b a a 1 2 3 4 5 ✞ ✝ ✲ ε ✻ ε ❄ ε ✻ ε ❄ ε ✻

slide-4
SLIDE 4

4

Language Problems

S ::= aSS | ε . Is-empty S = φ ≡ ({a} = φ ∨ S = φ ∨ S = φ) ∧ {ε} = φ . Nullable ε ∈S ≡ (ε ∈{a} ∧ ε ∈S ∧ ε ∈S) ∨ ε ∈{ε} . Shortest word length #S = (#a + #S + #S) ↓ #ε .

Non-Example

aa ∈ S ≡ (aa∈{a} ∧ aa ∈S ∧ aa ∈S) ∨ aa ∈ {ε} .

slide-5
SLIDE 5

5

Fusion

Many problems are expressed in the form evaluate

  • generate

where generate generates a (possibly infinite) candidate set of solutions, and evaluate selects a best solution. Examples: shortest

  • path ,

(x∈)

  • L .

Solution method is to fuse the generation and evaluation processes, eliminating the need to generate all candidate solutions.

slide-6
SLIDE 6

6

Conditions for Fusion

Fusion is made possible when

  • evaluate is an adjoint in a Galois connection,
  • generate is expressed as a fixed point.

Algorithms for solving resulting fixed point equation include

  • brute-force iteration,
  • Knuth’s generalisation of Dijkstra’s shortest path algorithm. .

Solution method typically involves generalising the problem.

slide-7
SLIDE 7

7

Galois Connections

Suppose A =(A, ⊑) and B =(B, ) are partially ordered sets and suppose F ∈A←B and G ∈B←A . Then (F, G) is a Galois connection

  • f A and B iff, for all x∈B and y∈A,

F(x) ⊑ y ≡ x G(y) .

Examples

Negation: ¬p⇒q ≡ p⇐¬q . Ceiling function: ⌈x⌉ ≤ n ≡ x ≤n . Maximum: x↑y ≤ z ≡ x ≤z ∧ y≤z . Even (divisible by two): if b→2 ✷ ¬b→1 fi \ m ≡ b⇒even(m) .

slide-8
SLIDE 8

8

Parsing

x∈S ⇒ b ≡ S ⊆ if b → Σ∗ ✷ ¬b → Σ∗ − {x} fi .

Shortest Word (Path)

Let Σ≥k denote the set of all words over alphabet Σ of length at least k. Let #S denote the length of a shortest word in the language S. #S ≥ k ≡ S ⊆ Σ≥k . (Most common application is when S is the set of paths from one node to another in a graph.)

slide-9
SLIDE 9

9

Fusion Theorem

F(µg) = µ⊑h provided that

  • F is a lower adjoint in a Galois connection of ⊑ and (see brief

summary of definition below)

  • F ◦ g = h ◦ F .

Galois Connection F(x) ⊑ y ≡ x G(y) . F is called the lower adjoint and G the upper adjoint.

slide-10
SLIDE 10

10

Language Recognition

Problem: For given word x and grammar G, determine x ∈L(G). That is, implement (x∈)

  • L .

Language L(G) is the least fixed point (with respect to the subset relation) of a monotonic function. (x∈) is the lower adjoint in a Galois connection of languages (ordered by the subset relation) and booleans (ordered by implication). (Recall, x∈S ⇒ b ≡ S ⊆ if b → Σ∗ ✷ ¬b → Σ∗ − {x} fi .)

slide-11
SLIDE 11

11

Nullable Languages

Problem: For given grammar G, determine ε ∈L(G). (ε ∈)

  • L

Solution: Easily expressed as a fixed point computation. Works because:

  • The function (x∈) is a lower adjoint in a Galois connection (for

all x, but in particular for x = ε).

  • For all languages S and T,

ε ∈S·T ≡ ε ∈S ∧ ε ∈T .

slide-12
SLIDE 12

12

Problem Generalisation

Problem: For given grammar G, determine whether all words in L(G) have even length. I.e. implement alleven

  • L .

The function alleven is a lower adjoint in a Galois connection. Specifically, for all languages S and T, alleven(S) ⇐ b ≡ S ⊆ if ¬b → Σ∗ ✷ b→(Σ·Σ)∗ fi . Nevertheless, fusion doesn’t work (directly) because

  • there is no ⊗ such that, for all languages S and T,

alleven(S·T) ≡ alleven(S) ⊗ alleven(T) . Solution: Generalise by tupling: compute simultaneously alleven and allodd.

slide-13
SLIDE 13

13

General Context-Free Parsing

Problem: For given grammar G, determine x ∈L(G). (x ∈)

  • L .

Not (in general) expressible as a fixed point computation. Fusion fails because: for all x, x = ε, there is no ⊗ such that, for all languages S and T, x ∈S·T ≡ (x ∈S) ⊗ (x ∈T) . CYK: Let F(S) denote the relation i, j:: x[i..j)∈S. Works because:

  • The function F is a lower adjoint.
  • For all languages S and T,

F(S·T) = F(S) • F(T) where B•C denotes the composition of relations B and C.

slide-14
SLIDE 14

14

Language Inclusion

Problem: For fixed (regular) language E and varying S, determine S ⊆ E . Example: Emptiness test: S ⊆ φ . Example: Pattern Matching: given pattern P, for each prefix t of text T, evaluate: {t} ⊆ Σ∗ ·{P} . Example: All words are of even length: S ⊆ (Σ·Σ)∗ .

slide-15
SLIDE 15

15

Language Inclusion

Problem: For fixed (regular) language E and varying S, determine S ⊆ E .

  • Function (⊆E) is a lower adjoint. Specifically,

S ⊆E ⇐ b ≡ S ⊆ if b→E ✷ ¬b→Σ∗ fi .

  • But, for E= φ and E= Σ∗, there is no ⊗ such that, for all

languages S and T, S·T ⊆ E ≡ (S ⊆E) ⊗ (T ⊆E) . Solution (Oege de Moor): Use factor theory to derive generalisation.

slide-16
SLIDE 16

16

Factors

For all languages S, T and U, S·T ⊆ U ≡ T ⊆ S\U , S·T ⊆ U ≡ S ⊆ U/T . Note: S\(U/T) = (S\U)/T . Hence, write S\U/T .

slide-17
SLIDE 17

17

Left and Right Factors

Define the functions ⊳ and ⊲ by X⊳ = E/X , X⊲ = X\E . By definition, the range of ⊳ is the set of left factors of E and the range of ⊲ is the set of right factors of E. We also have the Galois connection: X ⊆Y⊳ ≡ Y ⊆X⊲ . Hence, X⊳⊲⊳ = X⊳ , X⊲⊳⊲ = X⊲ , E⊳⊲ = E = E⊲⊳ .

slide-18
SLIDE 18

18

The Factor Matrix

Let L denote the set of left factors of E. Define the factor matrix of E to be the binary operator \ restricted to L×L. Thus entries in the matrix take the form L0\L1 where L0 and L1 are left factors of E. The factor matrix of E is denoted by [ [E] ]. It is a reflexive, transitive matrix. [ [E] ] = [ [E] ]∗ . The row and column containing individual factors, the left factors, the right factors, and E itself, is given by: U\E/V = U⊲⊳\V⊳ , V⊳ = E⊳\V⊳ , U⊲ = U⊲⊳\E⊲⊳ , E = E⊳ \ E⊲⊳ .

slide-19
SLIDE 19

19

Using the Factor Matrix

Problem: For fixed regular language E and varying S, determine S ⊆ E . Generalisation: For fixed regular language E and varying S, determine the relation S ⊆ [ [E] ] . (Formally, the relation L, M:: S ⊆ L\M where L and M range over the left factors of E.) Works because: S·T ⊆ [ [E] ] ≡ (S ⊆[ [E] ]) • (T ⊆[ [E] ]) . where B•C denotes the composition of relations B and C.

slide-20
SLIDE 20

20

Proof

We have to show that S·T ⊆ U⊳ \W⊳ ≡ ∃V :: S ⊆ U⊳ \V⊳ ∧ T ⊆ V⊳ \W⊳ . First, S·T ⊆E = { unit of conjunction } S·T ⊆E ∧ true = { factors, T⊳= E/T; cancellation } S ⊆T⊳ ∧ T⊳ ·T ⊆ E = { factors, T⊳⊲ = T⊳ \E } S ⊆T⊳ ∧ T ⊆ T⊳⊲ . Whence:

slide-21
SLIDE 21

21

S·T ⊆ U⊳ \W⊳ = { factors, definition of W⊳ } U⊳ ·S ·T ·W ⊆ E = { above, with S,T := U⊳ ·S , T·W } U⊳·S ⊆ (T·W)⊳ ∧ T·W ⊆ (T·W)⊳⊲ = { factors } S ⊆ U⊳ \(T·W)⊳ ∧ T ⊆ (T·W)⊳⊲/ W = { U⊲/W = U \W⊳ } S ⊆ U⊳\(T·W)⊳ ∧ T ⊆ (T·W)⊳\W⊳ . ⇒ {

  • ne-point rule

} ∃V :: S ⊆ U⊳ \V⊳ ∧ T ⊆ V⊳\W⊳ ⇒ { Leibniz } ∃V :: S·T ⊆ U⊳ \V⊳ · V⊳ \W⊳ ⇒ { cancellation, } S·T ⊆ U⊳ \W⊳ .

slide-22
SLIDE 22

22

Summary

  • Use of fusion as programming method.
  • Problem generalisation involves generalising the algebra in

the solution domain.

  • Factor theory as basis for language inclusion problems.

Challenges

  • Efficient computation of factor matrices.
  • Extension to non-regular languages.
slide-23
SLIDE 23

23

References

J.H. Conway, “Regular Algebra and Finite Machines”, Chapman and Hall, London, 1971. Backhouse, R.C and Carr´ e, B.A. “Regular algebra applied to path-finding problems”, J. Institute of Mathematics and its Applications, vol. 15, pp. 161–186, 1975. Backhouse, R.C. and Lutz, R.K., “Factor graphs, failure functions and bi-trees”, Automata, Languages and Programming, LNCS 52,

  • pp. 61–75, 1977.

Roland Backhouse, “Fusion on Languages”, 10th European Symposium on Programming, LNCS 2028, pp. 107–121, 2001.

  • O. de Moor, S. Drape, D. Lacey and G. Sittampalam. Incremental

program analysis via language factors. (www.comlab.ox.ac.uk/oucl/work/oege.demoor/pubs.htm) For related publications on fixed points, Galois connections and mathematics of program construction, see www.cs.nott.ac.uk/~rcb/papers