min usually defined on an untyped lambda calculus as (using caramel syntax ):
sub ab = (b pred a) <= ab = (is_zero (sub ba)) min ab = (<= abab)
This is terribly inefficient. Sub is quadratic because pred (which is linear) is applied b times. There is a much more efficient min implementation like:
min ab succ zero = (a a_succ (const zero) (b b_succ (const zero)))) a_succ pred cont = (cont pred) b_succ pred cont = (succ (cont pred))
It fastens on both numbers in a continuation style until the first zero is reached. Now I am trying to find max , which is as efficient as min , which has the following properties:
a and b are used no more than once in the function body.
It has a beta-normal form (i.e., it does not use fixed-point combinators, is very normal).
Is there such a definition for max ?
functional-programming lambda-calculus caramel
Maiavictor
source share