WORK IT, WRAP IT, FIX IT, FOLD IT Graham Hutton and Neil Sculthorpe.

Slides:



Advertisements
Similar presentations
Exponential & Logarithmic Equations
Advertisements

Color this Polynomial Simplified A visualization method for simplifying expressions. A GEMS Submission/ALEX Submitted by: E. Thompson, PhD. Summer 2008.
Naïve Bayes. Bayesian Reasoning Bayesian reasoning provides a probabilistic approach to inference. It is based on the assumption that the quantities of.
CALCULATING AN EXCEPTIONAL MACHINE Graham Hutton and Joel Wright University of Nottingham.
THE WORKER / WRAPPER TRANSFORMATION Graham Hutton and Andy Gill.
Functional Design and Programming Lecture 11: Functional reasoning.
CATCH: Case and Termination Checker for Haskell Neil Mitchell (Supervised by Colin Runciman)
What is a Parser? A parser is a program that analyses a piece of text to determine its syntactic structure  3 means 23+4.
Optimization in Engineering Design 1 Lagrange Multipliers.
0 PROGRAMMING IN HASKELL Chapter 7 - Higher-Order Functions.
Comp 205: Comparative Programming Languages Lazy Evaluation and Infinite Lists Lecture notes, exercises, etc., can be found at:
0 PROGRAMMING IN HASKELL Chapter 6 - Recursive Functions Most of this should be review for you.
0 PROGRAMMING IN HASKELL Chapter 6 - Recursive Functions.
Comp 205: Comparative Programming Languages Functional Programming Languages: More Lists Recursive definitions List comprehensions Lecture notes, exercises,
RECURSIVE PATTERNS WRITE A START VALUE… THEN WRITE THE PATTERN USING THE WORDS NOW AND NEXT: NEXT = NOW _________.
HOW TO BE MORE PRODUCTIVE Graham Hutton and Mauro Jaskelioff.
0 PROGRAMMING IN HASKELL Typeclasses and higher order functions Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and.
Series-Parallel Combination Circuits
COMPILING EXCEPTIONS CORRECTLY Graham Hutton and Joel Wright University of Nottingham.
Consider the statement 1000 x 100 = We can rewrite our original statement in power (index) format as 10 3 x 10 2 = 10 5 Remembering (hopefully!)
EMLAB 1 Chapter 5. Additional analysis techniques.
1 Recurrences Algorithms Jay Urbain, PhD Credits: Discrete Mathematics and Its Applications, by Kenneth Rosen The Design and Analysis of.
Basic Statistics Correlation Var Relationships Associations.
6.2 Integration by Substitution & Separable Differential Equations M.L.King Jr. Birthplace, Atlanta, GA.
The Relativistic Quantum Field Calculator for Elementary Particle Interactions Brandon Green, Dr. Edward Deveney (Mentor) Department of Physics, Bridgewater.
Implicit Differentiation
Implicit Differentiation - Used in cases where it is impossible to solve for “y” as an explicit function of “x”
ECE 8443 – Pattern Recognition LECTURE 07: MAXIMUM LIKELIHOOD AND BAYESIAN ESTIMATION Objectives: Class-Conditional Density The Multivariate Case General.
Mathematical Induction I Lecture 4: Sep 16. This Lecture Last time we have discussed different proof techniques. This time we will focus on probably the.
0 PROGRAMMING IN HASKELL Chapter 9 - Higher-Order Functions, Functional Parsers.
5-4-1 Unit 4: Sampling approaches After completing this unit you should be able to: Outline the purpose of sampling Understand key theoretical.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Chinese Remainder Theorem Dec 29 Picture from ………………………
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
Chapter 1 Introduction. Theories and Experiments The goal of physics is to develop theories based on experiments A theory is a “guess,” expressed mathematically,
CS 461 – Nov. 30 Section 7.5 How to show a problem is NP-complete –Show it’s in NP. –Show that it corresponds to another problem already known to be NP-complete.
Advanced Formal Methods Lecture 4: Isabelle – Types and Terms Mads Dam KTH/CSC Course 2D1453, Some material from Paulson.
CS5205Haskell1 CS5205: Foundation in Programming Languages Basics of Functional Programming.
Integers as Exponents Simplify:.
5.1 Exponents. Exponents that are natural numbers are shorthand notation for repeating factors. 3 4 = is the base 4 is the exponent (also called.
0 PROGRAMMING IN HASKELL Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources) Odds and Ends,
Recursion Higher Order Functions CSCE 314 Spring 2016.
Haskell Chapter 4. Recursion  Like other languages  Base case  Recursive call  Author programs a number of built-in functions as examples.
Percentages. What Are Percentages? A percentage is a number expressed as a fraction of 100. We use the percent sign % when representing numbers as a percentage.
Fusion Catherine Hope and Graham Hutton University of Nottingham in Less Space.
Computer Systems Laboratory Stanford University Clark W. Barrett David L. Dill Aaron Stump A Framework for Cooperating Decision Procedures.
Number: Recurring Decimals Definition and Simple Conversion to Fraction Form. By I Porter.
1 PROGRAMMING IN HASKELL Lecture 2 Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Math for CS Fourier Transforms
Review Simplify Expressions Distributing and Combining Like Terms.
5.1 Exponential Functions
Polymorphic Functions
Solving systems of equations
Expanding Brackets and Simplifying
GENERAL SOLUTIONS FOR COUPLED EQUATIONS FOR PIEZOELECTRIC MEDIA
FIRST ORDER DIFFERENTIAL EQUATIONS
MULTIPLICATION OF ALGEBRAIC EXPRESSIONS
Substitution & Separable Differential Equations
Copyright © Cengage Learning. All rights reserved.
PROGRAMMING IN HASKELL
Integration by Substitution & Separable Differential Equations
Fundamental Theorem of Calculus (Part 2)
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
4.5 Integration by Substitution The chain rule allows us to differentiate a wide variety of functions, but we are able to find antiderivatives for.
Verifying a compiler for a simple language with exceptions (MPC 04).
Objectives Simplify expressions with several variables by combining like terms.
Determinant of amatrix:
Information Theoretical Analysis of Digital Watermarking
WARMUP 1).
Presentation transcript:

WORK IT, WRAP IT, FIX IT, FOLD IT Graham Hutton and Neil Sculthorpe

1 This Talk zWorker/wrapper is a simple but powerful method for optimizing recursive programs; zPreviously, we developed theories for fix and fold, but with different correctness conditions; zWe combine and extend the two approaches to give a generalised worker/wrapper theory.

2 Worker / Wrapper program wrapper worker A technique for changing the type of a recursive program to improve its performance:

3 Fixed Points ones = 1 : ones ones = fix f f xs = 1 : xs can be rewritten as: fix f = f (fix f) Our original formalisation was based on the use of explicit fixed points. For example:

4 The Problem A Type of the desired worker, fix g. Type of the original program, fix f. B Suppose we wish to change the type of a recursive program that is defined using fix.

5 Assumptions We assume conversion functions A can be faithfully represented by B. such that: abs. rep = id A AB abs rep

6 Let’s Calculate! 6 fix f fix (abs. rep. f) = fix (id A. f) = abs (fix g) = abs (fix (rep. f. abs)) = Rolling rule.

7 Summary fix f We have derived the following factorisation: Wrapper of type B  A. Recursive program of type A. abs = Recursive worker of type B. fix g

8 Final Step We simplify the worker fix (rep. f. abs) rep abs and to eliminate the overhead of repeatedly converting between the two types, by fusing together fix g =

9 The Worker / Wrapper Recipe ① Express the original program using fix; ② Choose the new type for the program; ③ Define appropriate conversion functions; ④ Apply the worker/wrapper transformation; ⑤ Simplify the resulting definitions.

10 Generalising The technique also works for weaker assumptions: From the ‘fix’ paper. abs. rep = id A abs. rep. f = f fix (abs. rep. f) = fix f

11 … and for other conditions relating f and g: g = rep. f. abs rep. f = g. rep abs. g = f. abs From the ‘fold’ paper. fix g = fix (rep. f. abs) fix g = rep (fix f) Necessary and sufficient.

12 Generalised Recipe zIf the worker is already given, we aim to verify that one of the conditions is satisfied; zOtherwise, our aim is to construct the worker, using one of the conditions as a specification; zSimilar assumptions and conditions also give a generalised worker/wrapper theory for fold.

13 Example last [] = ⊥ last [x] = x last (x:xs) = last xs last [] = ⊥ last (x:xs) = work x xs work x [] = x work x (y:ys) = work y ys

14 Example fib 0 = 0 fib 1 = 1 fib (n+2) = fib n + fib (n+1) fib n = fst (work n) work 0 = (0,1) work (n+1) = (y,x+y) where (x,y) = work n

15 Summary zGeneralised technique for changing the type of a program to improve its performance; zCaptures a wide variety of program optimization techniques in a single unified framework; zThe paper also presents a range of new results concerning strictness side conditions.

16 Further Work zOther recursion patterns; zTime and space analysis; zComputational effects; zImplementing the technique.