Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to implement `max` efficiently on the untyped lambda calculus?

min is usually defined on the untyped lambda calculus as (using Caramel's syntax):

sub a b   = (b pred a)
<=  a b   = (is_zero (sub b a))
min a b   = (<= a b a b)

This is terribly inefficient. Sub is quadratic, since it applies pred (which is linear) b times. There is a much more efficient implementation of min as:

min a b 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))

This zips through both numbers in a continuation-passing style until the first zero is reached. Now, I'm trying to find a max that is as efficient as min, that has the following properties:

  1. a and b are used at most once on the body of the function.

  2. It has a beta normal form (i.e., doesn't use fixed-point combinators is strongly normalizing).

Does such max definition exist?

like image 334
MaiaVictor Avatar asked Oct 06 '15 12:10

MaiaVictor


People also ask

How do you evaluate lambda in calculus?

Evaluation is done by repeatedly finding a reducible expression (called a redex) and reducing it by a function evaluation until there are no more redexes. Example 1: The lambda expression (λx. x)y in its entirety is a redex that reduces to y.

Why is lambda calculus important?

Lambda calculus has applications in many different areas in mathematics, philosophy, linguistics, and computer science. Lambda calculus has played an important role in the development of the theory of programming languages. Functional programming languages implement lambda calculus.

What is lambda calculus discuss it in details with its syntax?

Lambda calculus is a framework developed by Alonzo Church in 1930s to study computations with functions. Function creation − Church introduced the notation λx. E to denote a function in which 'x' is a formal argument and 'E' is the functional body. These functions can be of without names and single arguments.

Who invented Lambda Calc?

The λ-calculus was invented by Alonzo Church in the 1930s to study the interaction of functional abstraction and function application from an abstract, purely mathematical point of view.


1 Answers

Just for the records, if a and b can be used twice (i.e., it would involve a dup node on interaction nets), there is a simple solution:

true a b  = a
false a b = b
const a b = a

-- less than or equal
lte a b = (go a true (go b false))
    go  = (num result -> (num (pred cont -> (cont pred)) (const result)))

min  = (a b -> (lte a b a b))
max  = (a b -> (lte a b b a))

-- A simple test
main = (max (max 3 14) (max 2 13))

But I demanded no duplication (i.e., lte a b b a isn't allowed) so I still don't know if that is possible.

like image 150
MaiaVictor Avatar answered Oct 19 '22 23:10

MaiaVictor