Giải phương trình hàm cho các hàm chưa biết trong phép tính lambda


14

Có kỹ thuật nào để giải phương trình hàm cho các hàm chưa biết trong phép tính lambda không?

Giả sử tôi có chức năng nhận dạng được định nghĩa mở rộng như sau:

Ix=x

(nghĩa là, bằng cách viết ra một phương trình cho hành vi dự kiến ​​của hàm đó) và bây giờ tôi muốn giải nó cho bằng cách thực hiện một số phép biến đổi đại số để có được công thức tính toán cho hàm đó:I

I=λx.x

that tells how exactly does the function do what was expected (that is, how to implement it in lambda calculus).

Of course the identity function is used just as an example. I'm interested in more general methods of solving such equations. In particular, I would like to find a function B that satisfies the following requirement:

Bf(λx.M)=(λx.fM)

that is, "injects" the given function f into the given lambda function (λx.M) before its "body" M (which is some arbitrary lambda expression), possibly by taking it apart and constructing a new one, so that it became a parameter the function f is applied to.

Câu trả lời:


13

This is a known problem, known as Higher Order Unification.

Unfortunately, this problem is undecidable in general. There is a decidable fragment, known as Miller's Pattern Fragment. It's used extensively in, among other things, typechecking of dependently-typed programs with metavariables or pattern matching. This fragment is where unification variables are applied only to distinct bound program variables.

This paper provides a great tutorial of how higher order unification works, and walks through a (relatively) simple implementation of it.

Unfortunately, it doesn't look like your function falls into this pattern fragment. That said, what I'm looking seeing is pretty similar to function composition. Does the following function satisfy your property?

B=λf g x .f (g x)

We have:

  • B f (λx.M)
  • =B f (λy.[y/x]M) by α-equivalence
  • =λx.f ((λy.[y/x]M)x)
  • =λx.f ([x/y][y/x]M)
  • =λx.f M

1
Yup, seems like it :) The funny thing is, I almost got that solution, but from some reason I thought that calling (λx.M) on something would "execute it", messing up the expression :q What I missed is that we can substitute the variable with another variable bound outside.
BarbaraKwarc

1
Thanks for the link to the paper too, I'll check it out, and I'll accept your answer in a couple of days to give other people a chance too.
BarbaraKwarc

3
Is this higher order unification? The question seems to be about the untyped lambda calculus rather than the simply typed lambda calculus.
Peter Taylor

2

I think I have a partial answer, regarding the equation with the identity function:

Ix=x

We want to solve it by finding the formula for I, which will be of the form (λp.M) with some yet unknown expression M as its body. Let's substitute it for I in the original equation:

(λp.M)x=x

then apply the function to x on the left hand side:

M[p/x]=x

But what do we have here? :> This equation is the formula for the expression M we're looking for, after substituting every occurrence of p in it with x, and it says that it should look like the right hand side afterwards :) In other words, the function we were looking for is:

I=(λx.x)

which of course is the right answer :)


Let's try the same approach to find the formula for the ω combinator. We want it to work in such a way that, when applied to itself, will produce itself applied to itself:

ωω=ωω

Now let's find the formula for ω which is of the form (λx.M) for some yet unknown expression M. Substituting this into the equation we get:

(λx.M)ω=ωω

Applying it to the parameter on the left hand side gives the formula for M:

M[x/ω]=ωω

This says that after substituting every occurrence of x in M with ω it produced ωω, so we can deduce that the original expression M before substitution should have been xx, so the function we were looking for should look like this:

ω=(λx.xx)

which is indeed the case :)


I have a feeling, though, that it might get so easy just because the right hand side was already in the form we're looking for.


Is there an algorithmic way of going from M[x/ω]=ωω to ω=(λx.xx) though?
Zhengqun Koo

In these two simple cases – yes, there is: simply reverse the substitution. But as I said, these cases might work by pure "luck": that the right hand side is already in the required form. When I tried it with some more complex examples, it didn't work. That's what I'm looking for, though: for an algorithmic way.
BarbaraKwarc

1
Note that ωω=ωω is satisfied by any choice of ω, in a trivial way. An algorithm to solve that equation for ω can output any term.
chi
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.