Algebraic Specialization of Generic Functions for Recursive Types - - PowerPoint PPT Presentation

algebraic specialization of generic functions for
SMART_READER_LITE
LIVE PREVIEW

Algebraic Specialization of Generic Functions for Recursive Types - - PowerPoint PPT Presentation

Algebraic Specialization of Generic Functions for Recursive Types By: Alcino Cunha, Hugo Pacheco Presented by: Joseph Tsun Kiet Man 1 Index 1. Introduction 1. Problem 2. Solutions 2. Specialization: Non-recursive Types 1. Theory 2.


slide-1
SLIDE 1

Algebraic Specialization of Generic Functions for Recursive Types

By: Alcino Cunha, Hugo Pacheco

1 Presented by: Joseph Tsun Kiet Man

slide-2
SLIDE 2

Index

  • 1. Introduction
  • 1. Problem
  • 2. Solutions
  • 2. Specialization: Non-recursive Types
  • 1. Theory
  • 2. Example
  • 3. Specialization: Recursive Types
  • 1. Theory
  • 2. Example
  • 4. Concluding remarks
  • 5. Summary

2

slide-3
SLIDE 3

Introduction | Problem

IMDB Movie Actor Year Title Director Review Box Office Name Played Year Title Role Award

Given the following data structure:

Country Value 3

slide-4
SLIDE 4

Introduction | Problem

4

slide-5
SLIDE 5

Introduction | Problem

𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 (𝑛𝑛𝑅𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓

Performance loss due to:

  • Run-time checks to determine at each node whether to

apply specific / generic behaviour.

  • Traversal through whole data structure.

5

slide-6
SLIDE 6

Introduction | Solutions

How to solve the inefficiencies?

  • Restricting the power of traversal combinators.
  • Offsets run-time checks to compile-time.
  • Specialization

Generic function Transformation Specialized function 𝑑𝑑𝑑𝑑𝑑′ = 𝑡𝑑𝑛 ∘ 𝑛𝑛𝑛 𝑡𝑑𝑛 ∘ 𝑛𝑛𝑛 𝑡𝑓𝑡𝑓 ∘ 𝑓𝑓𝑓𝑓𝑓𝑆𝑡 ∘ 𝑛𝑑𝑓𝑓𝑓𝑡 wher ere 𝑛𝑑𝑓𝑓𝑓𝑡 𝐽𝑛𝐽𝐽 𝑛 𝑛 = 𝑛 𝑓𝑓𝑓𝑓𝑓𝑆𝑡 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑓 6

slide-7
SLIDE 7

Specialization: Non-recursive Types

Theory

Recapitulation SYB:

7

slide-8
SLIDE 8

Specialization: Non-recursive Types

Theory

Recapitulation SYB:

8

slide-9
SLIDE 9

Specialization: Non-recursive Types

Theory

Point-free combinators and functions:

9

slide-10
SLIDE 10

Specialization: Non-recursive Types

Theory

Algebraic Transformation Laws:

10

slide-11
SLIDE 11

Specialization: Non-recursive Types

Theory

Algebraic Query Laws:

11

slide-12
SLIDE 12

Specialization: Non-recursive Types

Example

𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 (𝑛𝑛𝑅𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 12

slide-13
SLIDE 13

Specialization: Non-recursive Types

Example

𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 (𝑛𝑛𝑅𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 13

slide-14
SLIDE 14

Specialization: Non-recursive Types

Example

𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 (𝑛𝑛𝑅𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 14

slide-15
SLIDE 15

Specialization: Non-recursive Types

Example

𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 (𝑛𝑛𝑅𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 15

slide-16
SLIDE 16

Specialization: Recursive Types

Theory

Apply same concept to catamorphisms and paramorphisms:

16

slide-17
SLIDE 17

Specialization: Recursive Types

Theory

Catamorphisms: functions defined by iteration.

17

slide-18
SLIDE 18

Specialization: Recursive Types

Theory

Paramorphisms: all functions that can be defined by primitive recursion.

18

slide-19
SLIDE 19

Specialization: Recursive Types

Theory

Idea:

  • Rewrite the everywhere function.
  • Rewrite the everything function

19

slide-20
SLIDE 20

Specialization: Recursive Types

Theory

Everywhere function redefined:

20

slide-21
SLIDE 21

Specialization: Recursive Types

Theory

Everywhere function redefined:

21

slide-22
SLIDE 22

Specialization: Recursive Types

Theory

Recap - Algebraic Transformation Laws:

22

slide-23
SLIDE 23

Specialization: Recursive Types

Theory

New additional laws for catamorphisms and paramorphisms. 23

slide-24
SLIDE 24

Specialization: Recursive Types

Example

Function 24

slide-25
SLIDE 25

Specialization: Recursive Types

Example

Function 25

slide-26
SLIDE 26

Specialization: Recursive Types

Application

26

slide-27
SLIDE 27

Specialization: Performance

27

slide-28
SLIDE 28

Specialization: Improvements

Improvements:

  • Support for non-regular data types (e.g. nested).
  • Added symbolic evaluation (intermediate structures are

completely removed during optimization).

28

slide-29
SLIDE 29

Specialization: Conclusion

  • Specialization comes near handwritten code.
  • Specialized code can be optimized by compiler
  • ptimization methods.
  • Specialization by rewriting generic function to

specialized functions.

29