algebraic specialization of generic functions for
play

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.


  1. Algebraic Specialization of Generic Functions for Recursive Types By: Alcino Cunha, Hugo Pacheco Presented by: Joseph Tsun Kiet Man 1

  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 2 5. Summary

  3. Introduction | Problem Given the following data structure: IMDB Movie Actor Name Played Year Title Box Office Director Review Country Value Year Title Role Award 3

  4. Introduction | Problem 4

  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

  6. Introduction | Solutions How to solve the inefficiencies? Restricting the power of traversal combinators. • Offsets run-time checks to compile-time. • Specialization • Transformation Generic function Specialized function 𝑑𝑑𝑑𝑑𝑑 ′ = 𝑡𝑑𝑛 ∘ 𝑛𝑛𝑛 𝑡𝑑𝑛 ∘ 𝑛𝑛𝑛 𝑡𝑓𝑡𝑓 ∘ 𝑓𝑓𝑓𝑓𝑓𝑆𝑡 ∘ 𝑛𝑑𝑓𝑓𝑓𝑡 wher ere 𝑛𝑑𝑓𝑓𝑓𝑡 𝐽𝑛𝐽𝐽 𝑛 𝑛 = 𝑛 6 𝑓𝑓𝑓𝑓𝑓𝑆𝑡 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑓

  7. Specialization: Non-recursive Types Theory Recapitulation SYB: 7

  8. Specialization: Non-recursive Types Theory Recapitulation SYB: 8

  9. Specialization: Non-recursive Types Theory Point-free combinators and functions: 9

  10. Specialization: Non-recursive Types Theory Algebraic Transformation Laws: 10

  11. Specialization: Non-recursive Types Theory Algebraic Query Laws: 11

  12. Specialization: Non-recursive Types Example 𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 ( 𝑛𝑛𝑅 𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓 ) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 12

  13. Specialization: Non-recursive Types Example 𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 ( 𝑛𝑛𝑅 𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓 ) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 13

  14. Specialization: Non-recursive Types Example 𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 ( 𝑛𝑛𝑅 𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓 ) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 14

  15. Specialization: Non-recursive Types Example 𝑑𝑑𝑑𝑑𝑑 = 𝑓𝑓𝑓𝑓𝑓𝑑𝑓𝑓𝑑𝑓 ( 𝑛𝑛𝑅 𝑆𝑆𝑆𝑆𝑆𝑆 𝑡𝑓𝑡𝑓 ) wher ere 𝑡𝑓𝑡𝑓 𝑆𝑓𝑓𝑓𝑓𝑆 𝑓 = 𝑚𝑓𝑑𝑓𝑑𝑓 𝑓 Rewrite: 15

  16. Specialization: Recursive Types Theory Apply same concept to catamorphisms and paramorphisms: 16

  17. Specialization: Recursive Types Theory Catamorphisms: functions defined by iteration. 17

  18. Specialization: Recursive Types Theory Paramorphisms: all functions that can be defined by primitive recursion. 18

  19. Specialization: Recursive Types Theory Idea: Rewrite the everywhere function. • Rewrite the everything function • 19

  20. Specialization: Recursive Types Theory Everywhere function redefined: 20

  21. Specialization: Recursive Types Theory Everywhere function redefined: 21

  22. Specialization: Recursive Types Theory Recap - Algebraic Transformation Laws: 22

  23. Specialization: Recursive Types Theory New additional laws for catamorphisms and paramorphisms. 23

  24. Specialization: Recursive Types Example Function 24

  25. Specialization: Recursive Types Example Function 25

  26. Specialization: Recursive Types Application 26

  27. Specialization: Performance 27

  28. Specialization: Improvements Improvements: Support for non-regular data types (e.g. nested). • Added symbolic evaluation (intermediate structures are • completely removed during optimization). 28

  29. Specialization: Conclusion Specialization comes near handwritten code. • Specialized code can be optimized by compiler • optimization methods. Specialization by rewriting generic function to • specialized functions. 29

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend