Conditions for Efficiency Improvement by Tree Transducer Composition - - PowerPoint PPT Presentation

conditions for efficiency improvement by tree transducer
SMART_READER_LITE
LIVE PREVIEW

Conditions for Efficiency Improvement by Tree Transducer Composition - - PowerPoint PPT Presentation

RTA, July 23, 2002 Conditions for Efficiency Improvement by Tree Transducer Composition Janis Voigtl ander Dresden University of Technology voigt@tcs.inf.tu-dresden.de Supported by the Deutsche Forschungsgemeinschaft under grant KU


slide-1
SLIDE 1

RTA, July 23, 2002

Conditions for Efficiency Improvement by Tree Transducer Composition

Janis Voigtl¨ ander

Dresden University of Technology voigt@tcs.inf.tu-dresden.de

Supported by the “Deutsche Forschungsgemeinschaft” under grant KU 1290/2-1 and by the “European Commission – DG Information Society” with a FLoC’02 travel grant.

slide-2
SLIDE 2

1

Macro Tree Transducers [Eng80]

data Term = Term ⊗ Term | Term ⊕ Term | A | B data Ins = Mul Ins | Add Ins | LoadA Ins | LoadB Ins | Nil data Nat = Succ Nat | Zero pre :: Term → Ins → Ins pre (x1 ⊗ x2) y = Mul (pre x1 (pre x2 y)) pre (x1 ⊕ x2) y = Add (pre x1 (pre x2 y)) pre A y = LoadA y pre B y = LoadB y pre ⊗ A ⊕ B A Nil ⇒ Mul pre A pre ⊕ B A Nil ⇒ Mul LoadA pre ⊕ B A Nil ⇒3 Mul LoadA Add LoadB LoadA Nil

  • ps :: Ins → Nat
  • ps

(Mul x) = Succ (ops x)

  • ps (Add x) = Succ (ops x)
  • ps (LoadA x) = ops x
  • ps (LoadB x) = ops x
  • ps

Nil = Zero

slide-3
SLIDE 3

2

Intermediate Results

  • ps

pre ⊗ A ⊕ B A Nil ⇒5

✁ ✂
  • ps

Mul LoadA Add LoadB LoadA Nil ⇒6

✄ ☎

Succ Succ Zero

Inefficient !

slide-4
SLIDE 4

3

Tree Transducer Composition [EV85]: Example

preops ⊗ x1 x2 yops =

  • ps

Mul pre x1 pre x2 y ⇒ Succ

  • ps

pre x1 pre x2 y ⇒ Succ preops x1

  • ps

pre x2 y ⇒ Succ preops x1 preops x2

  • ps

y ⇒ Succ preops x1 preops x2 yops Replace occurrences of (ops (pre t Nil)) by (preops t (ops Nil)).

slide-5
SLIDE 5

4

Transformed Program:

preops :: Term → Nat → Nat preops (x1 ⊗ x2) yops = Succ (preops x1 (preops x2 yops)) preops (x1 ⊕ x2) yops = Succ (preops x1 (preops x2 yops)) preops A yops = yops preops B yops = yops preops ⊗ A ⊕ B A Zero ⇒ Succ preops A preops ⊕ B A Zero ⇒ Succ preops ⊕ B A Zero ⇒3 Succ Succ Zero

No intermediate result is produced ! Transformed program requires fewer reduction steps !

slide-6
SLIDE 6

5

Formal Efficiency Analysis

should be:

  • with respect to call-by-need reduction steps
  • input-independent
  • based on original program before transformation
slide-7
SLIDE 7

6

Ticking of Producer:

pre

(x1 ⊗ x2) y = ⋄ (Mul (pre x1 (pre x2 y)))

pre

(x1 ⊕ x2) y = ⋄ (Add (pre x1 (pre x2 y)))

pre

  • A

y = ⋄ (LoadA y) pre

  • B

y = ⋄ (LoadB y)

pre

⊗ A ⊕ B A Nil ⇒

Mul pre

A pre

⊕ B A Nil ⇒

Mul

LoadA pre

⊕ B A Nil ⇒3

Mul

LoadA

Add

LoadB

LoadA Nil

slide-8
SLIDE 8

7

Ticking of Consumer:

  • ps
(Mul x)

= • (Succ (ops

x))
  • ps
(Add x)

= • (Succ (ops

x))
  • ps
(LoadA x) = • (ops x)
  • ps
(LoadB x) = • (ops x)
  • ps
Nil

= • Zero

  • ps
(⋄ x1)

= • (ops

x1)
  • ps

Mul

LoadA

Add

LoadB

LoadA Nil ⇒

  • ps
  • Mul

LoadA

Add

LoadB

LoadA Nil ⇒

  • Succ
  • ps

LoadA

Add

LoadB

LoadA Nil ⇒9

  • Succ
  • Succ
  • Zero
slide-9
SLIDE 9

8

Steps of Original Program Reflected in Output (Lemma 2)

The number of •-symbols in the reduction result of:

  • ps
  • pre

A ⊕ B A Nil

is equal to the number of call-by-need reduction steps of:

  • ps

pre ⊗ A ⊕ B A Nil ⇒

Succ Succ Zero

slide-10
SLIDE 10

9

Ticking of Composed Program:

preops

  • (x1 ⊗ x2) yops = ◦ (Succ (preops
  • x1 (preops
  • x2 yops)))

preops

  • (x1 ⊕ x2) yops = ◦ (Succ (preops
  • x1 (preops
  • x2 yops)))

preops

  • A

yops = ◦ yops preops

  • B

yops = ◦ yops preops

A ⊕ B A Zero ⇒

  • Succ

preops

  • A

preops

B A Zero ⇒

  • Succ
  • preops

B A Zero ⇒3

  • Succ
  • Succ
  • Zero
slide-11
SLIDE 11

10

Annotation through Composition (Lemma 4)

pre

  • (x1 ⊗ x2) y = ⋄ (Mul (pre
  • x1 (pre
  • x2 y)))

pre

  • (x1 ⊕ x2) y = ⋄ (Add (pre
  • x1 (pre
  • x2 y)))

pre

  • A

y = ⋄ (LoadA y) pre

  • B

y = ⋄ (LoadB y)

  • ps
  • (Mul x)

= Succ (ops

  • x)
  • ps
  • (Add x) = Succ (ops
  • x)
  • ps
  • (LoadA x) = ops
  • x
  • ps
  • (LoadB x) = ops
  • x
  • ps
  • Nil

= Zero

  • ps
  • (⋄ x1)

= ◦ (ops

  • x1)

composed into: pre

  • ps
  • (x1 ⊗ x2) yops
  • = ◦ (Succ (pre
  • ps
  • x1 (pre
  • ps
  • x2 yops
  • )))

pre

  • ps
  • (x1 ⊕ x2) yops
  • = ◦ (Succ (pre
  • ps
  • x1 (pre
  • ps
  • x2 yops
  • )))

pre

  • ps
  • A

yops

  • = ◦ yops
  • pre
  • ps
  • B

yops

  • = ◦ yops
slide-12
SLIDE 12

11

Steps of Composed Program Reflected in Output (Lemma 5)

The number of ◦-symbols in the reduction result of:

  • ps
  • pre

A ⊕ B A Nil

is greater or equal to the number of call-by-need reduction steps

  • f:

preops ⊗ A ⊕ B A Zero ⇒

Succ Succ Zero

slide-13
SLIDE 13

12

Compare Annotated Programs:

pre

  • (x1 ⊗ x2) y = ⋄ (Mul (pre
  • x1 (pre
  • x2 y)))

pre

  • (x1 ⊕ x2) y = ⋄ (Add (pre
  • x1 (pre
  • x2 y)))

pre

  • A

y = ⋄ (LoadA y) pre

  • B

y = ⋄ (LoadB y)

  • ps
  • (Mul x)

= • (Succ (ops

  • x))
  • ps
  • (Add x) = • (Succ (ops
  • x))
  • ps
  • (LoadA x) = • (ops
  • x)
  • ps
  • (LoadB x) = • (ops
  • x)
  • ps
  • Nil

= • Zero

  • ps
  • (⋄ x1)

= • (ops

  • x1)
  • ps
  • (Mul x) = Succ (ops
  • x)
  • ps
  • (Add x) = Succ (ops
  • x)
  • ps
  • (LoadA x) = ops
  • x
  • ps
  • (LoadB x) = ops
  • x
  • ps
  • Nil

= Zero

  • ps
  • (⋄ x1)

= ◦ (ops

  • x1)

Always more •- than ◦-symbols !

slide-14
SLIDE 14

13

Abstracting from the Example (Theorem 1)

The composed program is at least as efficient as the original program, provided that:

  • 1. the producer is context-linear or basic
  • 2. the consumer is recursion-linear
  • 3. the consumer is context-linear or basic
slide-15
SLIDE 15

14

Further Results:

  • Weaker pre-conditions by counting only steps of the con-

sumer (Lemma 3, Lemma 6, Lemma 7, Theorem 2)

  • Application to special cases of classical deforestation [Wad90]

(Corollary 1)

  • Analysis technique scales for the case that both involved

transducers use context parameters [VK01]; work in progress

slide-16
SLIDE 16

References

[Eng80]

  • J. Engelfriet. Some open questions and recent results on tree transducers and

tree languages. In R.V. Book, editor, Formal language theory; perspectives and

  • pen problems, pages 241–286. New York, Academic Press, 1980.

[EV85]

  • J. Engelfriet and H. Vogler. Macro tree transducers. J. Comput. Syst. Sci.,

31:71–145, 1985. [VK01]

  • J. Voigtl¨

ander and A. K¨

  • uhnemann. Composition of functions with accumulat-

ing parameters. Technical Report TUD-FI01-08, Dresden University of Tech- nology, August 2001. http://wwwtcs.inf.tu-dresden.de/∼voigt/TUD-FI01-08.ps.gz. [Wad90] P. Wadler. Deforestation: Transforming programs to eliminate trees. Theoret.

  • Comput. Sci., 73:231–248, 1990.