• No results found

Efficiency Analysis for the Elimination of Intermediate Results in Functional Programs by Compositions of Attributed Tree Transducers

N/A
N/A
Protected

Academic year: 2021

Share "Efficiency Analysis for the Elimination of Intermediate Results in Functional Programs by Compositions of Attributed Tree Transducers"

Copied!
19
0
0

Loading.... (view fulltext now)

Full text

(1)

Efficiency Analysis for the

Elimination of Intermediate Results in

Functional Programs by Compositions of

Attributed Tree Transducers

Andreas Maletti

Department of Computer Science Dresden University of Technology

(2)

Itinerary

• Motivation and introduction

• Step 1: To Attributed Tree Transducers

• Step 2: Composing Attributed Tree Transducers • Step 3: Back to Macro Tree Transducers

(3)

Motivation

• Intermediate results are ubiquitous in functional programs. • Elimination of such results might therefore

– save memory and

– speed up computation of the final result.

• Major question: How can we compose functions symbolically? • Minor question: Can we guarantee a speed-up?

(4)

Introduction

MACsu ; MACwsu

1st step ? ? ATTsu ; ATT @ @ @ R 2nd step ATT ? 3rd step MAC

(5)

Macro Tree Transducers

• Special (restricted) functional programs

Example: Mpal = {A(1), B(1), N(0)}, {A(1), B(1), N(0)}, {s(1)}, (s x1 N ), R  R = { s (A x1) y1 = A s x1 (A y1)  , s (B x1) y1 = B s x1 (B y1)  , s N y1 = y1 }

• Appends the reversed input list to the input list; constructs a palindrome

(6)

Attributed Tree Transducers

• Special (restricted) attribute grammars

Example:

Mpal0 = {A(1), B(1), N(0)}, {A(1), B(1), N(0)}, {s}, {i},bs,σ, Rb  Depiction of some rules in the rule-set R:

A x i s ? 6 A A B x i s ? 6 B B N i s 6

(7)

MAC

wsu

⊆ ATT

• Synthesized attributes instead of function symbols • Simulate context parameters by inherited attributes

• Associate a set of inherited attributes to every synthesized attribute

(8)

MAC

wsu

⊆ ATT (cont’d)

• Macro Tree Transducer M ,

Attributed Tree Transducer M0 = C[M ] (τM0 = τM)

• Established efficiency relation:

count(M ) = count(M0) − i − 1

• i : number of reduction steps invested to reduce inherited attribute instances

(9)

Macro Tree Transducer: s (ABN ) N ⇒ A (s BN (AN )) ⇒ AB (s N (BAN )) ⇒ ABBAN 3 reduction steps

Attributed Tree Transducer:

A i s ? 6 A A B ? 6 B B N 6

(10)

ATT

su

; ATT ⊆ ATT

• Core idea of construction: pairing of attributes • Efficiency considerations

M1, M2 syntactic single-use atts

F1, F2 attribute sets of M1, M2

M = C[M1, M2] att with τM = τM1; τM2

t1, t2 input tree for M1 and t2 = τM1(t1)

M is more efficient than (M1; M2), iff

(11)

A i s ? 6 A A B ? 6 B B B ? 6 B B A ? 6 A A N 6

Composition result (Mpal0 ; Mpal0 ):

A is si ii ss ? ? 6 6 A A A A ?  B ? ? 6 6 B B B B N 6 6 

(12)

ATT

su

; ATT ⊆ ATT (Example cont’d)

size(t1)|F1| |F2| + 1 < size(t1)|F1| + size(t2)|F2| + 2 • in our example:

3 · 2 · 2 + 1 = 13 < 18 = 3 · 2 + 5 · 2 + 2 • in general for (Mpal0 ; Mpal0 ):

n · 2 · 2 + 1 = 4n + 1 < 6n = n · 2 + (2n − 1) · 2 + 2 n = size(t1) > 0

(13)

ATT ⊂ MAC

• Function symbols replace synthesized attributes

• Operations on inherited attributes simulated in context parameters

• Every function symbol has as many context parameters as there are inherited attributes

(14)

ATT ⊂ MAC (cont’d)

• single-use Attributed Tree Transducer M0,

Macro Tree Transducer M = C[M0] (τM = τM0)

• Established efficiency relation:

count(M ) = count(M0) − i − 1

• i : number of reduction steps invested to reduce inherited attribute instances

(15)

ATT ⊂ MAC (Example)

• Running example (let Σ = {A(1), B(1), N(0)}):

Mpal;pal = Σ, Σ, {ss(2), ii(2)}, (ss x1 (ii x1 N N ) N ), R R = { ss (A x1) y1 y2 = A ss x1 (A y1) (A y2)  , ss (B x1) y1 y2 = B ss x1 (B y1) (B y2)  , ss N y1 y2 = y1 ii (A x1) y1 y2 = A ii x1 (A y1) (A y2)  , ii (B x1) y1 y2 = B ii x1 (B y1) (B y2)  , ii N y y = y }

(16)

ATT ⊂ MAC (Example cont’d)

• Reduction:

ss (ABN ) (ii (ABN ) N N ) N

⇒ A (ss (BN ) (A [ii (ABN ) N N ]) (AN )) ⇒ AB (ss N (BA [ii (ABN ) N N ]) (BAN )) ⇒ ABBA [ii (ABN ) N N ]

⇒ ABBAA [ii (BN ) (AN ) (AN )] ⇒ ABBAAB [ii N (BAN ) (BAN )] ⇒ ABBAABBAN

(17)

Main theorem

M1, M2 syntactic single-use and preserving macs

F1, F2 set containing the function symbols of M1, M2

M = C[M1, M2] mac with τM = τM1; τM2

t1, t2 input tree for M1 and t2 = τM1(t1)

M is more efficient than (M1; M2), iff

size(t1)  |F1| |F2| + X f ∈F1 rankF1(f ) X f ∈F2 rankF2(f )  < size(t1)|F1| + size(t2)|F2|

(18)

Main theorem (cont’d)

• Running example with n = size(t1):

n · (1 · 1 + 1 · 1) = 2n < 3n − 1 = n · 1 + (2n − 1) · 1 • Some derived results (only additional properties listed):

M1 M2 M = C[M1, M2] more efficient, if

tdtt, |F2| = 1 always

(19)

Conclusions

• Composition result seems to suffer heavily from the explosion in the number of attributes.

• From the theorem several small classes can be derived. • Further studies (especially in connection with further

optimization techniques like copy rules elimination) for other composition techniques are necessary.

References

Related documents

Brian was primarily responsible for the designing the layout of the hardware on the Segway RMP platform, sensor integration, creation of bitmaps used for navigation,

Ramasamy, S, Gardi, A and Sabatini, R 2014, 'Aircraft Noise modelling and trajectory optimisation for reduced environmental impacts at major Australian airports', in Meenakshi

Schulze, “A review of platinum-based catalyst layer degradation in proton exchange membrane fuel cells,” Journal of Power Sources, vol. Hamrock, “Mesoscale Modeling of

2) Refinement phase (active learning). Training examples generation is expensive, as computing the supervised informa- tion involves the evaluation of the objective functions f of

Regime characteristics a¤ect policies related to the blocking of political challengers and the amount of political rent, but they do not a¤ect the choice of social and economic

Furthermore, while symbolic execution systems often avoid reasoning precisely about symbolic memory accesses (e.g., access- ing a symbolic offset in an array), C OMMUTER ’s test

• Leading Representative of the UP before the following international networks of experts: PECC (Pacific Economic Cooperation Council), as PECC Expert and as

With the same view, less perceived stress and work-family conflicts can be expected in countries with extensive traditional family support that sustain higher gendered divisions