ল্যাম্বদা-ক্যালকুলাসে "প্রয়োগিক আদেশ" এবং "সাধারণ আদেশ"


14

প্রযোজ্য ক্রম: ফাংশনটি নিজে মূল্যায়নের আগে কোনও ক্রিয়াকর্মের যুক্তিগুলি সর্বদা সম্পূর্ণ মূল্যায়ন করুন, যেমন -

(λx.x2(λx.(x+1)  2)))(λx.x2(2+1)) (λx.x2(3)) 32  9

সাধারণ ক্রম: এক্সপ্রেশনটি বাইরের থেকে কমিয়ে দেওয়া হবে, যেমন -

(λx.x2(λx.(x+1) 2)) (λx.(x+1)   2)2 (2+1)2 32  9

M=(λx.y (λx.(x  x) λx.(x  x)))

Why is it that under applicative order, M infinite loop,
but under normal order, My?


1
Have you tried evaluating them at all? Is it the first or the second case that's unclear?
Karolis Juodelė

@KarolisJuodelė: 1st
URL87

1
Shouldn't the lambda expressions be written with parentheses to mark the end of the first lambda expression and the beginning of the argument, e.g.: Let M = (λx.y) ((λx.(x x)) λx.(x x))
mattgately

উত্তর:


7

(λx.y (λx.(x  x) λx.(x  x))) is an infinite loop because

λx.(x  x) λx.(x  x)λx.(x  x) λx.(x  x)
Notice that λx.(x  x) just writes it's argument twice.

15

The term you are reducing is (KyΩ) where Ky is the constant function λx.y (it always returns y, ignoring its argument) and Ω=(λx.(xx)λx.(xx)) is a non-terminating term. In some sense Ω is the ultimate non-terminating term: it beta-reduces to itself, i.e. ΩΩ. (Make sure to work it out on paper at least once in your life.)

Applicative order reduction must reduce the argument of the function to a normal form, before it can evaluate the top-level redex. Since the argument Ω has no normal form, applicative order reduction loops infinitely. More generally, for any term M, MΩMΩ, and this is the reduction chosen by the applicative order strategy.

Normal order reduction starts by reducing the top-level redex (because the function Ky is already in normal form). Since Ky ignores its argument, (KyΩ)y in one step. More generally, KyNy for any term N, and this is the reduction chosen by the normal order strategy.

This case illustrates a more general phenomenon: applicative order reduction only ever finds a normal form if the term is strongly normalizing, whereas normal order reduction always finds the normal form if there is one. This happens because applicative order always evaluates fully arguments first, and so misses the opportunity for an argument to turn out to be unused; whereas normal order evaluates arguments as late as possible, and so always wins if the argument turns out to be unused.

(The flip side is that applicative order tends to be faster in practice, because it's relatively rare for an argument to be unused; whereas it's common for an argument to be used multiple times, and under applicative order the argument is only evaluated once. Normal order evaluates the argument as often as it's used, be it 0, 1 or many times.)


I suppose you made a typo in paragraph 3. KyNN should be y, right? Regardless, +1.
Karolis Juodelė
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.