## Swapping arguments and results of recursive functions (2006)

Venue: | In Mathematics of Program Construction, Proceedings, volume 4014 of LNCS |

Citations: | 1 - 0 self |

### BibTeX

@INPROCEEDINGS{Morihata06swappingarguments,

author = {Akimasa Morihata and Kazuhiko Kakehi and Zhenjiang Hu and Masato Takeichi},

title = {Swapping arguments and results of recursive functions},

booktitle = {In Mathematics of Program Construction, Proceedings, volume 4014 of LNCS},

year = {2006},

pages = {379--396},

publisher = {Springer-Verlag}

}

### OpenURL

### Abstract

Abstract. Many useful calculation rules, such as fusion and tupling, rely on well-structured functions, especially in terms of inputs and outputs. For instance, fusion requires that well-produced outputs should be connected to well-consumed inputs, so that unnecessary intermediate data structures can be eliminated. These calculation rules generally fail to work unless functions are well-structured. In this paper, we propose a new calculation rule called IO swapping. IO swapping exchanges call-time computations (occurring in the arguments) and return-time computations (occurring in the results) of a function, while guaranteeing that the original and resulting function compute the same value. IO swapping enables us to rearrange inputs and outputs so that the existing calculation rules can be applied. We present new systematic derivations of efficient programs for detecting palindromes, and a method of higherorder removal that can be applied to defunctionalize function arguments, as two concrete applications. 1

### Citations

447 |
Semantics of Context-Free Languages
- Knuth
- 1968
(Show Context)
Citation Context ...the derived method (Theorem 5) and η-expansion works in a similar fashion to the higher-order removal method proposed by Nishimura [17] on the basis of a composition method [18] of attribute grammars =-=[19]-=-. Attribute grammars give a good abstraction of accumulative programs, and many attribute-grammar-based program transformation methods for accumulative functions have been proposed [20–23]. The reason... |

299 | Definitional interpreters for higher-order programming languages
- Reynolds
- 1972
(Show Context)
Citation Context ...on the other hand, is itself an application of TABA pattern; the TABA pattern is necessary for expressing the IO swapping rule. It is worth mentioning that another method based on defunctionalization =-=[15]-=- was proposed [16] to derive TABA programs. Although this defunctionalization-based method certainly derives pld1, it is not obvious whether it can cope with pld2. While it is well known in the functi... |

298 | Functional programming with bananas, lenses, envelopes and barbed wire
- Meijer, Fokkinga, et al.
- 1991
(Show Context)
Citation Context ...ogy for constructing programs, where we first write down a program that may be terribly inefficient but certainly correct, then we improve its efficiency by applying calculation rules, such as fusion =-=[2, 3]-=- and tupling [4–7]. As an example, consider the problem of checking whether a list is a palindrome or not. A straightforward solution pld0 is given as follows. pld0 x = eqlist(x,reverse x) eqlist([],[... |

215 |
Introduction to Functional Programming using Haskell, 2nd edition
- Bird
- 1998
(Show Context)
Citation Context ... discuss related work in Section 6 and conclude the paper in Section 7. 2 Preliminaries 2.1 Notations Throughout the paper, we have mostly used the notation in functional programming language Haskell =-=[8]-=-. Some syntactic notations we have used in this paper are as follows. The backslash \ is used instead of λ for λ-abstraction, and the identity function is written as (\x −> x). The symbol ⋅ denotes fu... |

96 |
and Oege de Moor. Algebra of Programming
- Bird
- 1997
(Show Context)
Citation Context ...ograms for detecting palindromes, and a method of higherorder removal that can be applied to defunctionalize function arguments, as two concrete applications. 1 Introduction Calculational programming =-=[1]-=- is a methodology for constructing programs, where we first write down a program that may be terribly inefficient but certainly correct, then we improve its efficiency by applying calculation rules, s... |

79 |
Using circular programs to eliminate multiple traversals of data
- Bird
- 1984
(Show Context)
Citation Context ...ammars make manipulations of accumulative functions easy is the symmetric treatments over arguments and results, and this is also what IO swapping aims at. IO swapping is related to circular programs =-=[4]-=-. There have not been many studies on the application and transformation of circular programs in functional area, since circularities are not intuitive and disturb program manipulation. IO swapping of... |

73 | Towards an automated tupling strategy - Chin - 1993 |

72 | Rules and Strategies for Transforming Functional and Logic Programs
- Pettorossi, Proietti
- 1996
(Show Context)
Citation Context ..., Bird [4] derived pldBird x = ��� (r1,r2) = aux x r2 [] �� r1 ����� aux [] [] h = (True, h) aux (a:x) (b:y) h = ��� (r1,r2) = aux x y (a:h) �� (a==b && r1, r2) Alternatively, Pettorossi and Proietti =-=[6]-=- derived pldPettorossi x = ��� (r1,r2) = aux x [] �� r1 r2 ����� aux [] h = (\y−>y==[], h) aux (a:x) h = ��� (r1,r2) = aux x (a:h) �� (\(b:y)−>a==b && r1 y, r2) Both involve a single traversal of x, a... |

58 |
Algebraic identities for program calculation
- Bird
- 1989
(Show Context)
Citation Context ...ogy for constructing programs, where we first write down a program that may be terribly inefficient but certainly correct, then we improve its efficiency by applying calculation rules, such as fusion =-=[2, 3]-=- and tupling [4–7]. As an example, consider the problem of checking whether a list is a palindrome or not. A straightforward solution pld0 is given as follows. pld0 x = eqlist(x,reverse x) eqlist([],[... |

49 |
Attribute coupled grammars
- Ganzinger, Giegerich
- 1984
(Show Context)
Citation Context ...ound that a combination of the derived method (Theorem 5) and η-expansion works in a similar fashion to the higher-order removal method proposed by Nishimura [17] on the basis of a composition method =-=[18]-=- of attribute grammars [19]. Attribute grammars give a good abstraction of accumulative programs, and many attribute-grammar-based program transformation methods for accumulative functions have been p... |

46 | Deriving structural hylomorphisms from recursive definitions
- Hu, Iwasaki, et al.
- 1996
(Show Context)
Citation Context ...d y. ⊓⊔ Theorem 2 (Simple Tupling). (f1 △ f2) = foldr (\a (r1,r2)−>(k1 a r1, k2 a r2)) (z1,z2) where f1 = foldr k1 z1 and f2 = foldr k2 z2. ⊓⊔ Both Theorems 1 and 2 can be generalized to be polytypic =-=[3, 9, 7]-=-. 3 IO Swapping 3.1 IO Swapping for ����� IO swapping is the new transformation that is used to change the view of recursive functions through the swapping of input (arguments) and output (results). T... |

33 | Tupling calculation eliminates multiple data traversals
- Hu, Iwasaki, et al.
- 1997
(Show Context)
Citation Context ...ucture between them. Tupling eliminates multiple traversals of the same data if two functions share the same recursion scheme. We will later make use of the following fusion rule [2] and tupling rule =-=[7]-=-. Theorem 1 (Fold Promotion). f ⋅ foldr (⊕) e = foldr (⊗) e’ provided that ⊗ and e’ are such that f (a ⊕ y) = a ⊗ (f y) and f e = e’ hold for any a and y. ⊓⊔ Theorem 2 (Simple Tupling). (f1 △ f2) = fo... |

31 | Benefits of tree transducers for optimizing functional programs - Kühnemann - 1998 |

18 | Comparison of Deforestation Techniques for Functional Programs and for Tree Transducers - Kühnemann - 1999 |

15 | Declarative Program Transformation: A Deforestation Case-Study - Correnson, Duris, et al. - 1998 |

15 | Using circular programs to deforest in accumulating parameters - Voigtländer - 2002 |

12 |
Improving recursive functions by inverting the order of evaluation
- Boiten
- 1992
(Show Context)
Citation Context ...m its root to its leaves, the IO swapped program constructs it from its leaves to its root, but the resulting tree is the same. Although IO swapping seems related to the inversion of evaluation order =-=[24]-=-, our work bears little relationship to it. IO swapping does not change the order of evaluations, but changes the dependency of computation: IO-swapped functions usually compute arguments after result... |

10 | There and back again
- Danvy, Goldberg
- 2002
(Show Context)
Citation Context ...cussed in [10].s6 Related Work We demonstrated the derivation of two palindrome detecting functions, pld1 and pld2, in Section 4. These palindrome detecting functions were given by Danvy and Goldberg =-=[12]-=- as an application of the There And Back Again (TABA) pattern. What we demonstrated in Section 4 is, therefore, a derivation of TABA programs based on IO swapping. IO swapping derives TABA programs, o... |

9 |
Fully lazy higher-order removal
- Chin
- 1992
(Show Context)
Citation Context ...sent a derivation of a higher-order removal transformation that can be applied to defunctionalize function arguments. 5.1 IO Swapping as a Metatransformation Consider the higher-order removal problem =-=[11]-=-. It is well known that η-expansion effectively defunctionalizes higher-order results. For example, think about the following function, sumTC, whose auxiliary function sum’ returns a function value. s... |

5 |
Fusion with stacks and accumulating parameters
- Nishimura
- 2004
(Show Context)
Citation Context ...ould deal with accumulative programs. We found that a combination of the derived method (Theorem 5) and η-expansion works in a similar fashion to the higher-order removal method proposed by Nishimura =-=[17]-=- on the basis of a composition method [18] of attribute grammars [19]. Attribute grammars give a good abstraction of accumulative programs, and many attribute-grammar-based program transformation meth... |

2 |
Reversing iterations: IO swapping leads you there and back again
- Morihata, Kakehi, et al.
- 2005
(Show Context)
Citation Context ...therefore, a derivation of TABA programs based on IO swapping. IO swapping derives TABA programs, on the one hand, because IO swapping turns an iteration over arguments into an iteration over results =-=[13, 14]-=-. IO swapping, on the other hand, is itself an application of TABA pattern; the TABA pattern is necessary for expressing the IO swapping rule. It is worth mentioning that another method based on defun... |

2 |
There and back again. Fundamenta Informaticae, 66(4):397–413, 2005. A preliminary version was presented at the 2002
- Danvy, Goldberg
- 2002
(Show Context)
Citation Context ... is itself an application of TABA pattern; the TABA pattern is necessary for expressing the IO swapping rule. It is worth mentioning that another method based on defunctionalization [15] was proposed =-=[16]-=- to derive TABA programs. Although this defunctionalization-based method certainly derives pld1, it is not obvious whether it can cope with pld2. While it is well known in the functional community tha... |

1 |
Relationship between arguments and results of recursive functions
- Morihata
- 2006
(Show Context)
Citation Context ... [a] −> r −> ([a],h,r) -} f2’ [] r = (x, g0 r, r) f2’ (_:y) r = ��� (a:z,h,r’) = f2’ y (g3 a r h) �� (z, g2 a r h, r’) Proof Sketch Here we will provide a proof sketch. The full proof can be found in =-=[10]-=-. To prove Theorem 4, we need to assume that all computations terminate with a unique solution. We call the outside (top) of the recursion of the auxiliary function (f1’ or f2’) the 0-th recursive cal... |

1 | M.: IO swapping leads you there and back again
- Morihata, Kakehi, et al.
(Show Context)
Citation Context ...therefore, a derivation of TABA programs based on IO swapping. IO swapping derives TABA programs, on the one hand, because IO swapping turns an iteration over arguments into an iteration over results =-=[13, 14]-=-. IO swapping, on the other hand, is itself an application of TABA pattern; the TABA pattern is necessary for expressing the IO swapping rule. It is worth mentioning that another method based on defun... |