e01.org

Lambda lifting

Lambda lifting is a meta-process that restructures a computer program so that functions are defined independently of each other in a global scope. An individual lift transforms a local function (subroutine) into a global function. It is a two step process, consisting of: * Eliminating free variables in the function by adding parameters. * Moving functions from a restricted scope to broader or global scope. The term "lambda lifting" was first introduced by Thomas Johnsson around 1982 and was historically considered as a mechanism for implementing programming languages based on functional programming. It is used in conjunction with other techniques in some modern compilers. Lambda lifting is not the same as closure conversion. It requires all call sites to be adjusted (adding extra arguments (parameters) to calls) and does not introduce a closure for the lifted lambda expression. In contrast, closure conversion does not require call sites to be adjusted but does introduce a closure...

Lambda lifting is a meta-process that restructures a computer program so that functions are defined independently of each other in a global scope. An individual lift transforms a local function (subroutine) into a global function. It is a two step process, consisting of: Eliminating free variables in the function by adding parameters. Moving functions from a restricted scope to broader or global scope. The term "lambda lifting" was first introduced by Thomas Johnsson around 1982 and was historically considered as a mechanism for implementing programming languages based on functional programming. It is used in conjunction with other techniques in some modern compilers. Lambda lifting is not the same as closure conversion. It requires all call sites to be adjusted (adding extra arguments (parameters) to calls) and does not introduce a closure for the lifted lambda expression. In contrast, closure conversion does not require call sites to be adjusted but does introduce a closure for the lambda expression mapping free variables to values. The technique may be used on individual functions, in code refactoring, to make a function usable outside the scope in which it was written. Lambda lifts may also be repeated, to transform the program. Repeated lifts may be used to convert a program written in lambda calculus into a set of recursive functions, without lambdas. This demonstrates the equivalence of programs written in lambda calculus and programs written as functions. However it does not demonstrate the soundness of lambda calculus for deduction, as the eta reduction used in lambda lifting is the step that introduces cardinality problems into the lambda calculus, because it removes the value from the variable, without first checking that there is only one value that satisfies the conditions on the variable (see Curry's paradox). Lambda lifting can be performed with time complexity linear in the size of the lifted program, which is at most O(n^2) . In the untyped lambda calculus, where the basic types are functions, lifting may change the result of beta reduction of a lambda expression. The resulting functions will have the same meaning, in a mathematical sense, but are not regarded as the same function in the untyped lambda calculus. See also intensional versus extensional equality. The reverse operation to lambda lifting is lambda dropping. Lambda dropping may make the compilation of programs quicker for the compiler, and may also increase the efficiency of the resulting program, by reducing the number of parameters, and reducing the size of stack frames. However it makes a function harder to re-use. A dropped function is tied to its context, and can only be used in a different context if it is first lifted. ==Algorithm== The following algorithm is one way to lambda-lift an arbitrary program in a language which doesn't support closures as first-class objects: Rename the functions so that each function has a unique name. Replace each free variable with an additional argument to the enclosing function, and pass that argument to every use of the function. Replace every local function definition that has no free variables with an identical global function. Repeat steps 2 and 3 until all free variables and local functions are eliminated. If the language has closures as first-class objects that can be passed as arguments or returned from other functions, the closure will need to be represented by a data structure that captures the bindings of the free variables. ==Example== The following OCaml program computes the sum of the integers from 1 to 100: let rec sum n = if n = 1 then 1 else let f x = n + x in f (sum (n - 1)) sum 100 (The let rec declares sum as a function that may call itself.) The function f, which adds sum's argument to the sum of the numbers less than the argument, is a local function. Within the definition of f, n is a free variable. Start by converting the free variable to a parameter: let rec sum n = if n = 1 then 1 else let f w x = w + x in f n (sum (n - 1)) sum 100 Next, lift f into a global function: let rec f w x = w + x and sum n = if n = 1 then 1 else f n (sum (n - 1)) in sum 100 The following is the same example, this time written in JavaScript: // Initial version function sum(n) { function f(x) { return n + x; } if (n == 1) return 1; else return f(sum(n - 1)); } // After converting the free variable n to a formal parameter w function sum(n) { function f(w, x) { return w + x; } if (n == 1) return 1; else return f(n, sum(n - 1)); } // After lifting function f into the global scope function f(w, x) { return w + x; } function sum(n) { if (n == 1) return 1; else return f(n, sum(n - 1)); } The substitution operator is used extensively. The expression L[G := S] means substitute every occurrence of G in L by S and return the expression. The definition used is extended to cover the substitution of expressions, from the definition given on the Lambda calculus page. The matching of expressions should compare expressions for alpha equivalence (renaming of variables). \operatorname{lambda-lift-op}[S, L, P] =P[L := \operatorname{lambda-lift}[S, L The sub expression may be either a lambda abstraction, or a lambda abstraction applied to a parameter. Two types of lift are possible. Anonymous lift Named lift An anonymous lift has a lift expression which is a lambda abstraction only. It is regarded as defining an anonymous function. A name must be created for the function. A named lift expression has a lambda abstraction applied to an expression. This lift is regarded as a named definition of a function. \operatorname{lambda-lift}[S, L] \equiv \operatorname{let} V: \operatorname{de-lambda}[G = S] \operatorname{in} L[S:=G] The new lambda expression has S substituted for G: L[S:=G] means substitution of S for G in L. The function definitions has the function definition G = S added. In the above rule G is the function application that is substituted for the expression S. It is defined by, G = \operatorname{make-call}[V, \operatorname{FV}[S where V is the function name. It must be a new variable, i.e. a name not already used in the lambda expression, V \not \in \operatorname{vars}[\operatorname{let} F \operatorname{in} L] where \operatorname{vars}[E] is a meta function that returns the set of variables used in E. \operatorname{lambda-lift}[(\lambda V.E)\ S, L] \equiv \operatorname{let} V : \operatorname{de-lambda}[G = S] \operatorname{in} L[(\lambda V.E)\ S:=E[V:=G As for the anonymous lift, the expression G is constructed from V by applying the free variables of S. It is defined by, G = \operatorname{make-call}[V, \operatorname{FV}[S \operatorname{lambda-lift-tran}[\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))] \equiv \operatorname{let} p\ f\ x = f\ (x\ x) \land q\ p\ f = (p\ f)\ (p\ f) \operatorname{in} q\ p The de-let meta function may then be used to convert the result back into lambda calculus. \operatorname{de-let}[\operatorname{lambda-lift-tran}[\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x)) \equiv (\lambda p.(\lambda q.q\ p)\ \lambda p.\lambda f.(p\ f)\ (p\ f))\ \lambda f.\lambda x.f\ (x\ x) The processing of transforming the lambda expression is a series of lifts. Each lift has, A sub expression chosen for it by the function lift-choice. The sub expression should be chosen so that it may be converted into an equation with no lambdas. The lift is performed by a call to the lambda-lift meta function, described in the next section, \begin{cases} \operatorname{lambda-lift-tran}[L] = \operatorname{drop-params-tran}[\operatorname{merge-let}[\operatorname{lambda-apply}[L ]\\ \operatorname{lambda-apply}[L] = \operatorname{lambda-process}[\operatorname{lift-choice}[L],L]\\ \operatorname{lambda-process}[\operatorname{none}, L] = L\\ \operatorname{lambda-process}[S, L] = \operatorname{lambda-apply}[\operatorname{lambda-lift}[S, L \end{cases} After the lifts are applied the lets are combined together into a single let. \begin{cases} \operatorname{merge-let}[\operatorname{let} V : E \operatorname{in} \operatorname{let} W : F \operatorname{in} G] = \operatorname{merge-let}[\operatorname{let} V, W : E \land F \operatorname{in} G] \\ \operatorname{merge-let}[E] = E \end{cases} Then Parameter dropping is applied to remove parameters that are not necessary in the "let" expression. The let expression allows the function definitions to refer to each other directly, whereas lambda abstractions are strictly hierarchical, and a function may not directly refer to itself. \operatorname{lambda-free}[\lambda F.X] = \operatorname{false} \\ \operatorname{lambda-free}[V] = \operatorname{true} \\ \operatorname{lambda-free}[M\ N] = \operatorname{lambda-free}[M] \land \operatorname{lambda-free}[N] \end{cases} lambda-anon - An anonymous function. An expression like \lambda x_1.\ ...\ \lambda x_n.X where X is lambda free. \begin{cases} \operatorname{lambda-anon}[\lambda F.X] = \operatorname{lambda-free}[X] \lor \operatorname{lambda-anon}[X] \\ \operatorname{lambda-anon}[V] = \operatorname{false} \\ \operatorname{lambda-anon}[M\ N] = \operatorname{false} \end{cases} \operatorname{lambda-anon}[X] \to \operatorname{lift-choice}[X] = X \operatorname{lift-choice}[\lambda F.X] = \operatorname{lift-choice}[X] \operatorname{lift-choice}[M] \ne \operatorname{none} \to \operatorname{lift-choice}[M\ N] = \operatorname{lift-choice}[M] \operatorname{lift-choice}[M\ N] = \operatorname{lift-choice}[N] \operatorname{lift-choice}[V] = \operatorname{none} For example, \operatorname{lambda-named}[(\lambda F.M)\ N] = \operatorname{lambda-free}[M] \land \operatorname{lambda-anon}[N] \\ \operatorname{lambda-named}[\lambda F.X] = \operatorname{false} \\ \operatorname{lambda-named}[V] = \operatorname{false} \end{array} lift-choice : The first anonymous or named function found in traversing the expression or none if there is no function. \operatorname{lambda-named}[X] \lor \operatorname{lambda-anon}[X] \to \operatorname{lift-choice}[X] = X \operatorname{lift-choice}[\lambda F.X] = \operatorname{lift-choice}[X] \operatorname{lift-choice}[M] \ne \operatorname{none} \to \operatorname{lift-choice}[M\ N] = \operatorname{lift-choice}[M] \operatorname{lift-choice}[M\ N] = \operatorname{lift-choice}[N] \operatorname{lift-choice}[V] = \operatorname{none} For example, \operatorname{let} x\ f\ y = f\ (y\ y) \land q\ x\ f = f\ ((x\ f)\ (x\ f)) \operatorname{in} q\ x and after Parameter dropping, \operatorname{let} x\ f\ y = f\ (y\ y) \land q\ f = f\ ((x\ f)\ (x\ f)) \operatorname{in} q As a lambda expression (see Conversion from let to lambda expressions), (\lambda x.(\lambda q.q)\ \lambda f.f\ (x\ f)\ (x\ f))\ \lambda f.\lambda y.f\ (y\ y) If lifting anonymous functions only, the Y combinator is, \operatorname{let} p\ f\ x = f\ (x\ x) \land q\ p\ f = (p\ f)\ (p\ f) \operatorname{in} q\ p and after Parameter dropping, \operatorname{let} p\ f\ x = f\ (x\ x) \land q\ f = (p\ f)\ (p\ f) \operatorname{in} q As a lambda expression, (\lambda p.(\lambda q.q)\ \lambda f.(p\ f)\ (p\ f))\ \lambda f.\lambda x.f\ (x\ x) The first sub expression to be chosen for lifting is \lambda x.f\ (x\ x) . This transforms the lambda expression into \lambda f.(p\ f)\ (p\ f) and creates the equation p\ f\ x = f (x\ x) . The second sub expression to be chosen for lifting is \lambda f.(p\ f)\ (p\ f) . This transforms the lambda expression into q\ p and creates the equation q\ p\ f = (p\ f)\ (p\ f) . And the result is, \operatorname{let} p\ f\ x = f\ (x\ x) \land q\ p\ f = (p\ f)\ (p\ f) \operatorname{in} q\ p\ Surprisingly this result is simpler than the one obtained from lifting named functions. ===Execution=== Apply function to , \begin{cases} \lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))\ K & \ \operatorname{let}\ p\ f\ x = f\ (x\ x) \land q\ p\ f = (p\ f)\ (p\ f) \ \operatorname{in}\ q\ p\ K \\ (\lambda x.K\ (x\ x))\ (\lambda x.K\ (x\ x)) & \ \operatorname{let}\ p\ f\ x = f\ (x\ x) \land q\ p\ f = (p\ f)\ (p\ f) \ \operatorname{in}\ p\ K\ (p\ K) \\ K\ ((\lambda x.K\ (x\ x))\ (\lambda x.K\ (x\ x))) & \ \operatorname{let}\ p\ f\ x = f\ (x\ x) \land q\ p\ f = p\ f\ (p\ f) \ \operatorname{in}\ K\ (p\ K\ (p\ K)) \\ \end{cases} So, (\lambda x.K\ (x\ x))\ (\lambda x.K\ (x\ x)) = K\ ((\lambda x.K\ (x\ x))\ (\lambda x.K\ (x\ x))))\ or p\ K\ (p\ K) = K\ (p\ K\ (p\ K)) The Y-Combinator calls its parameter (function) repeatedly on itself. The value is defined if the function has a fixed point. But the function will never terminate. \operatorname{lambda-drop-op}[L, P, X] = P[L := \operatorname{drop-params-tran}[\operatorname{sink-test}[L, X ] where, L is the lambda abstraction to be dropped. P is the program X is a set of expressions to be excluded from dropping. \operatorname{lambda-drop-tran}[L, X] = \operatorname{drop-params-tran}[\operatorname{sink-tran}[\operatorname{de-let}[L, X ] where, L is the expression to be transformed. X is a set of sub expressions to be excluded from the dropping. sink-tran sinks each abstraction, starting from the innermost, \begin{cases} \operatorname{sink-tran}[(\lambda N.B)\ Y, X] = \operatorname{sink-test}[(\lambda N.\operatorname{sink-tran}[B])\ \operatorname{sink-tran}[Y], X] \\ \operatorname{sink-tran}[\lambda N.B, X] = \lambda N.\operatorname{sink-tran}[B, X] \\ \operatorname{sink-tran}[M\ N, X] = \operatorname{sink-tran}[M, X]\ \operatorname{sink-tran}[M, X] \\ \operatorname{sink-tran}[V, X] = V \end{cases} E \not \in \operatorname{FV}[G] \land E \not \in \operatorname{FV}[H] \to \operatorname{sink}[(\lambda E.G\ H)\ Y, X] = G\ H \\ E \not \in \operatorname{FV}[G] \land E \in \operatorname{FV}[H] \to \operatorname{sink}[(\lambda E.G\ H)\ Y, X] = \operatorname{sink-test}[G\ \operatorname{sink-test}[(\lambda E.H)\ Y, X \\ E \in \operatorname{FV}[G] \land E \not \in \operatorname{FV}[H] \to \operatorname{sink}[(\lambda E.G\ H)\ Y, X] = (\operatorname{sink-test}[(\lambda E.G)\ Y, X])\ H \\ E \in \operatorname{FV}[G] \land E \in \operatorname{FV}[H] \to \operatorname{sink}[(\lambda E.G\ H)\ Y, X] = (\lambda E.G\ H)\ Y \end{cases} Abstraction. Use renaming to ensure that the variable names are all distinct. V \ne W \to \operatorname{sink}[(\lambda V.\lambda W.E)\ Y, X] = \lambda W.\operatorname{sink-test}[(\lambda V.E)\ Y, X] Variable - 2 cases. E \ne V \to \operatorname{sink}[(\lambda E.V)\ Y, X] = V E = V \to \operatorname{sink}[(\lambda E.V)\ Y, X] = Y Sink test excludes expressions from dropping, L \in X \to \operatorname{sink-test}[L, X] = L L \not \in X \to \operatorname{sink-test}[L, X] = \operatorname{sink}[L, X] D[g] = [[x, \operatorname{false}, \_], [o, \_, p], [y, \_, n build-param-lists builds all the lists for an expression, by traversing the expression. It has four parameters; The lambda expression being analyzed. The table parameter lists for names. The table of values for parameters. The returned parameter list, which is used internally by the Abstraction - A lambda expression of the form (\lambda N.S)\ L is analyzed to extract the names of parameters for the function. \begin{cases} \operatorname{build-param-lists}[(\lambda N.S)\ L, D, V, R] \equiv \operatorname{build-param-lists}[S, D, V, R] \land \operatorname{build-list}[L, D, V, D[N \\ \operatorname{build-param-lists}[\lambda N.S, D, V, R] \equiv \operatorname{build-param-lists}[S, D, V, R] \end{cases} Locate the name and start building the parameter list for the name, filling in the formal parameter names. Also receive any actual parameter list from the body of the expression, and return it as the actual parameter list from this expression \begin{cases} \operatorname{build-list}[\lambda P.B, D, V, [X, \_, \_]::L] \equiv \operatorname{build-list}[B, D, V, L] \\ \operatorname{build-list}[B, D, V, [ \equiv \operatorname{build-param-lists}[B, D, V, \_] \end{cases} Variable - A call to a function. \operatorname{build-param-lists}[N, D, V, D[N For a function name or parameter start populating actual parameter list by outputting the parameter list for this name. Application - An application (function call) is processed to extract actual parameter details. \operatorname{build-param-lists}[E\ P, D, V, R] \equiv \operatorname{build-param-lists}[E, D, V, T] \land \operatorname{build-param-lists}[P, D, V, K] \land T = [F, S, A]::R \land (S \implies (\operatorname{equate}[A, P] \land V[F] = A)) \land D[F] = K Retrieve the parameter lists for the expression, and the parameter. Retrieve a parameter record from the parameter list from the expression, and check that the current parameter value matches this parameter. Record the value for the parameter name for use later in checking. \begin{cases} \operatorname{equate}[A, N] \equiv A = N \lor (\operatorname{def}[V[N \land A = V[N]) & \text{if }N\text{ is a variable.} \\ \operatorname{equate}[A, E] \equiv A = E & \text{otherwise.} \end{cases} The above logic is quite subtle in the way that it works. The same value indicator is never set to true. It is only set to false if all the values cannot be matched. The value is retrieved by using S to build a set of the Boolean values allowed for S. If true is a member then all the values for this parameter are equal, and the parameter may be dropped. \operatorname{ask}[S] \equiv S \in \{ X : X = S \} Similarly, def uses set theory to query if a variable has been given a value; \operatorname{def}[F] \equiv |\{X : X = F\}| Let - Let expression. \operatorname{build-param-list}[\operatorname{let} V: E \operatorname{in} L, D, V, \_] \equiv \operatorname{build-param-list}[E, D, V, \_] \land \operatorname{build-param-list}[L, D, V, \_] And - For use in "let". \operatorname{build-param-lists}[E \land F, D, V, \_] \equiv \operatorname{build-param-lists}[E, D, V, \_] \land \operatorname{build-param-lists}[F, D, V, \_] D[g] = [[x, \operatorname{false}, \_], [o, \operatorname{true}, p], [y, \operatorname{true}, n and the parameter o is dropped to give, \lambda m,p,q.(\lambda g.\lambda n.(n\ (g\ m\ n)\ (g\ q\ n)))\ \lambda x.\lambda y.p\ x\ y Gives, D[n] = [\_, \_, g\ m\ p\ n]::[\_, \_, g\ q\ p\ n]::R As there are no definitions for, V[n], V[p], V[q], V[m] , then equate can be simplified to, \operatorname{equate}[A, N] \equiv A = N \lor (\operatorname{def}[V[N \land A = V[N]) \equiv A = N By removing expressions not needed, D[g] = [x, S_5, A_5]::[o, S_4, A_4]::[y, S_3, A_3]::K_2 \land S_3 \implies A_3 = n \land S_4 \implies A_4 = p \land S_5 \implies A_5 = m D[g] = [x, S_8, A_8]::[o, S_6, A_7]::[y, S_6, A_6]::K_1 \land S_6 \implies A_6 = n \land S_7 \implies A_7 = p \land S_8 \implies A_8 = q By comparing the two expressions for D[g] , get, S_5 = S_8, A_5 = A_8, S_4 = S_7, A_4 = A_7, S_3 = S_6, A_3 = A_6 If S_3 is true; n = A_3 = A_6 = n If S_3 is false there is no implication. So S_3 = \_ which means it may be true or false. If S_4 is true; p = A_4 = A_7 = p If S_5 is true; m = A_5 = A_8 = q So S_5 is false. The result is, D[g] = [x, \operatorname{false}, \_]::[o, \_, p]::[y, \_, n]::\_ By similar arguments as used above get, D[o]= [\_, \_, x]::[\_, \_, y]::\_ and from previously, D[g] = [[x, \operatorname{false}, \_], [o, \operatorname{true}, p], [y, \operatorname{true}, n D[n] = [[\_, \_, (g\ m\ p\ n)], [\_, \_, (g\ q\ p\ n) D[m] = \_ D[p] = \_ D[q] = \_ |} Another example is, \lambda f.((\lambda p.f\ (p\ p\ f))\ (\lambda q.\lambda x.x\ (q\ q\ x)) Here x is equal to f. The parameter list mapping is, D[p] = [[q, \_, p], [x, \_, f and the parameter x is dropped to give, \lambda f.((\lambda q.f\ (q\ q))\ (\lambda q.f\ (q\ q)) After collecting the results together, D[p] = [q, \_, \_]::[x, \_, \_]::L_3 D[p] = [F_4, S_4, A_4]::[F_3, S_3, A_3]::K_2 \land (S_3 \implies (\operatorname{equate}[A_3, f] \land V[F_3] = A_3)) \land D[F_3] = D[f] \land (S_4 \implies (\operatorname{equate}[A_4, p] \land V[F_4] = A_4)) \land D[F_4] = D[p] D[q] = [F_7, S_7, A_7]::[F_6, S_6, A_6]::K_5 (S_6 \implies (\operatorname{equate}[A_6, x] \land V[F_6] = A_6)) \land D[F_6] = D[x] (S_7 \implies (\operatorname{equate}[A_7, q] \land V[F_7] = A_7)) \land D[F_7] = D[q] From the two definitions for D[p] ; F_4 = q F_3 = x so D[p] = [q, S_4, A_4]::[x, S_3, A_3]::K_2 (S_3 \implies (\operatorname{equate}[A_3, f] \land V[x] = A_3)) \land D[x] = D[f] (S_4 \implies (\operatorname{equate}[A_4, p] \land V[q] = A_4)) \land D[q] = D[p] Using D[q] = D[p] and D[p] = [F_7, S_7, A_7]::[F_6, S_6, A_6]::K_5 (S_6 \implies (\operatorname{equate}[A_6, x] \land V[F_6] = A_6)) \land D[F_6] = D[x] (S_7 \implies (\operatorname{equate}[A_7, q] \land V[F_7] = A_7)) \land D[F_7] = D[q] by comparing with the above, F_7 = q, F_6 = x, A_3 = A_6, A_4 = A_7, S_3 = S_6, S_4 = S_7 so, V[x] = A_3 V[q] = A_4 in, S_3 \implies A_3 = f S_3 \implies (A_3 = x \lor A_3 = v[x]) reduces to, S_3 \implies A_3 = f also, S_4 \implies A_4 = p S_4 \implies (A_4 = q \lor A_4 = v[q]) reduces to, S_4 \implies A_4 = p So the parameter list for p is effectively; D[p] = [q, \_, p]::[x, \_, f]::\_ |} F = FV[(\lambda N.S)\ L] \operatorname{drop-params}[\lambda N.S, D, V, R] \equiv (\lambda N.\operatorname{drop-params}[S, D, F, R]) where, F = FV[\lambda N.S] Variable \operatorname{drop-params}[N, D, V, D[N \equiv N For a function name or parameter start populating actual parameter list by outputting the parameter list for this name. Application - An application (function call) is processed to extract (\operatorname{def}[F] \land \operatorname{ask}[S] \land FV[A] \subset V) \to \operatorname{drop-params}[E\ P, D, V, R] \equiv \operatorname{drop-params}[E, D, V, [F, S, A]::R] \neg (\operatorname{def}[F] \land \operatorname{ask}[S] \land FV[A] \subset V) \to \operatorname{drop-params}[E\ P, D, V, R] \equiv \operatorname{drop-params}[E, D, V, [F, S, A]::R]\ \operatorname{drop-params}[P, D, V, \_] Let - Let expression. \operatorname{drop-params}[\operatorname{let} V: E \operatorname{in} L] \equiv \operatorname{let} V: \operatorname{drop-params}[E, D, FV[E], [ \operatorname{in} \operatorname{drop-params}[L, D, FV[L], [ And - For use in "let". \operatorname{drop-params}[E \land F, D, V, \_] \equiv \operatorname{drop-params}[E, D, V, \_] \land \operatorname{drop-params}[F, D, V, \_] From the results of building parameter lists; D[n] = [[\_, \_, (g\ m\ p\ n)], [\_, \_, (g\ q\ p\ n) so, F_1 = \_ F_2 = \_ so, \operatorname{def}[F_1] = \operatorname{false} \operatorname{def}[F_2] = \operatorname{false} |} (\operatorname{ask}[S] \land FV[A] \subset V) \to \operatorname{drop-formal}[[F, S, A]::Z, \lambda F.Y, V] \equiv \operatorname{drop-formal}[[F, S, A]::Z, Y[F:=A], L] \neg (\operatorname{ask}[S] \land FV[A] \subset V) \to \operatorname{drop-formal}[[F, S, A]::Z, \lambda F.Y, V] \equiv \lambda F.\operatorname{drop-formal}[[F, S, A]::Z, Y, V] \operatorname{drop-formal}[Z, Y, V] \equiv Y Which can be explained as, If all the actual parameters have the same value, and all the free variables of that value are available for definition of the function then drop the parameter, and replace the old parameter with its value. else do not drop the parameter. else return the body of the function. \operatorname{let} p\ f\ x = f\ (x\ x) \land q\ p\ f = (p\ f)\ (p\ f) \operatorname{in} q\ p\ Which gives back the Y combinator, \lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x)) ==External links== Explanation on Stack Overflow, with a JavaScript example

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Lambda lifting". 1788163407. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1372345156

JSON record · API collection · citation policy