CALL-BY-VALUE SOLVABILITY

. The notion of solvability in the call-by-value (cid:21) -calculus is de(cid:12)ned and completely characterized, both from an operational and a logical point of view. The operational characterization is given through a reduction machine, performing the classical (cid:12) -reduction, according to an innermost strategy. In fact, it turns out that the call-by-value reduction rule is too weak for capturing the solvability property of terms. The logical characterization is given through an intersection type assignment system, assigning types of a given shape to all and only the call-by-value solvable terms.


Introduction
The call-by-value λ-calculus (λβ v -calculus) is a paradigmatic language which captures two features present in many real functional programming languages: the call-by-value parameter passing and the lazy evaluation. The parameters are passed in a call-by-value way, when they are evaluated before being passed and a function is evaluated in a lazy way when its body is evaluated only when parameters are supplied. The real programming languages are all lazy, and almost all call-by-value (e.g. ML [9], Scheme [13], while Haskell [14] is one of the few examples of a language using the call-by-name evaluation). Note that the callby-value parameter passing cannot be modelled in the classical λ-calculus, since the β-reduction rule is intrinsecally a call-by-name rule. The λβ v -calculus is a restriction of the classical λ-calculus based on the notion of value. Values are either variables or abstractions and they represent the already evaluated terms. Since the evaluation is lazy, an abstraction is always a value, independently from its body. The call-by-value evaluation mechanism in the λβ v -calculus is realized by defining a suitable reduction rule (the β v -rule), which is a restriction of the classical β-rule, in the sense that (λx.M )N reduces to M [N/x] if and only if N is a value, i.e., it has been already evaluated.
The λβ v -calculus and the machine for its evaluation, that we call secd, has been introduced by Plotkin [11] inspired by the seminal work of Landin [8] on the language ISWIM and the SECD machine.
In this paper we are dealing with the pure (i.e. without constants) version of the λβ v -calculus. So a closed term is said valuable if its evaluation, through the secd machine, stops.
The notion of terminating programs and so of valuable terms is central for studying the operational equivalence between terms induced by the secd machine. This equivalence corresponds to the Liebnitz equality on programs. In fact a context C[ ] can be viewed as a partially specified program, and C[M ] as a program using M as subprogram. So two terms are equivalent if and only if they can be replaced each other in the same program without changing its observational behaviour. In a language (like the λβ v -calculus) without constants, the natural behaviour to be observed is the termination property.
Plotkin proved that the λβ v -calculus enjoys some of the good properties we expected from a calculus, namely the Church-Rosser and the standardization property. But the notion of solvability, in the call-by-value setting, has never been explored. In this paper we want to study such a notion.
The notion of solvability has been introduced in the classical λ-calculus for characterizing terms with good operational behaviour. Using a programming paradigm, M is solvable if and only if, for every output value P , there is a program C P [M ], using effectively M as subprogram, such that C P [M ] evaluates to P . The fact that C P [M ] uses effectively M can be formalized as: not for all Q, C P [Q] evaluates to P .
In the case of classical λ-calculus, it has been proved [15] that, for all term M , if such a context C[ ] exists, then there is also a head context, i.e., a context of the shape: From an operational point of view, solvable terms are the terminating programs, in the head reduction machine [12]. From a semantic point of view, all unsolvable terms (i.e., the non terminating programs) can be all consistently equated [15]. From a logical point of view, a term M is solvable if and only if it can be typed in the intersection type assignment system defined by Coppo and Dezani [3].
Let recall also the notion of solvability in the lazy λ-calculus, introduced by Abramsky and Ong [1] for modelling the call-by-name lazy evaluation. The lazy λ-calculus is the classical one, equipped with the β-reduction rule, but, in the evaluation of terms, no reduction is made under the scope of an abstraction. Abramsky and Ong in [1] noted that the notion of solvability in this setting is the same as in the call-by-name case (a term is solvable if and only if it has a head normal form). But in this case the set of solvable terms does not coincide anymore with the set of terminating terms, with respect to the lazy evaluation. Indeed the term λx.∆∆, where ∆ ≡ λx.xx, is unsolvable, but the lazy evaluation stops on it. In order to clarify the relation between solvable terms and termination in the lazy setting, let us recall the notion of unsolvable of order n (n ≥ 0).
Let P be unsolvable. P is of order 0 if and only if there is no Q such that P = β λx.Q; P is of order n if and only if n is the maximum integer such that P = β λx 1 . . .x n .Q; P is of infinite order if such a n does not exist. So the terminating terms in the lazy λ-calculus are the solvable terms plus the unsolvable ones of order greater than 0.
Semantically the unsolvable terms of order 0 (i.e., the non terminating programs) can be consistently equated, but a model equating all unsolvable terms is not correct with respect to the lazy operational semantics.
As far as the logical characterization of lazy solvability is concerned, it is easy to show that the logical system defined in [1] can give such a characterization. Now let us consider the call-by-value λ-calculus. First of all we must ask ourselves how the general notion of solvability can be specialized in this setting. In [4] (Th. 33) it has been proved that the λβ vcalculus has a functional behaviour, as the classical λ-calculus. More precisely, the operational behaviour of a term M can be studied by considering just the (call-by-value) head-contexts, i.e. contexts of the shape: ., x n }. In this paper we will give a complete characterization, from both an operational and a logical point of view, of v-solvable terms.
A key observation is that, in order to characterize the class of v-solvable terms from an operational point of view, the β v -reduction is too weak. In fact there are β v -normal forms which are v-unsolvable, as for example the term: which is operationally equivalent to λx.∆∆. So, in order to characterize operationally the v-solvability, a more refined tool must be designed. To do so, we extend the notion of valuability (i.e., termination) to open terms, by defining a term M being potentially valuable if and only if there is a substitution s, replacing variables by closed values, such that s(M ) is valuable. It turns out that the class of the v-solvable terms is properly contained in that one of the potentially valuable terms. We will show that the potentially valuable terms are completely characterized through an evaluation machine, that we call inner machine, performing the classical β-reduction according to the innermost-lazy strategy. It is important to notice that the operational equivalence induced by the inner machine coincides with ≈ s . Another evaluation machine, the ahead machine, which is based on the previous one, gives the desired characterization of v-solvable terms. It turns out that a term M is v-solvable if and only if it reduces, using the classical β-reduction with the leftmost-innermost strategy, to a term of the shape: where P i is potentially valuables (1 ≤ i ≤ m). Note that this definition cannot be expressed through the β v -reduction. A preliminary version of these machines has been presented in [10].
Moreover we characterize both the potential valuability and the v-solvability from a logical point of view, defining an intersection type assignment system, which gives type exactly to the potentially valuable terms, and gives a type of a particular shape exactly to the v-solvable terms. Such a type assignment system is inspired to that one defined by [4] for reasoning about canonical denotational semantics of λβ v -calculus.
Let recall that a λβ-theory is called sensible if it equates all unsolvable terms, and semi-sensible if it never equates a solvable term to an unsolvable one. We can extend in an obvious way this definition to a λβ v -theory, calling it v-sensible if it equates all the v-unsolvable terms, and v-semi-sensible if it never equates a v-solvable term to a v-unsolvable one. According to the previous definition of vsolvability, the secd-operational theory, i.e., the theory T secd = {(M, N )|M ≈ s N } is not v-sensible, as expected. Indeed ∆∆ and λx.∆∆ are two different unsolvable terms which are not equated in T secd . This depends on the fact that the secd machine evaluates in a lazy way: indeed also the operational semantics of the lazy λ-calculus is not v-sensible. Moreover, T secd is not v-semi-sensible. In fact it turns out that it equates the identity combinator I to a v-unsolvable term. This equivalence is not surprising, since it is a consequence of the fact that, in the minimal canonical model of λβ v -calculus, showed in [4], which is built by an inverse limit construction, all projections are λ-representable. We will give here a purely syntactic proof of it.
The paper is organized as follows. In Section 2 the λβ v -calculus and its operational semantics are recalled. In Section 3 the notions of potentially valuable and v-solvable term are introduced. The operational characterizations of potentially valuable and v-solvable terms are given in Sections 4 and 5 respectively. Section 6 contains the logical characterization. The two appendices contain the more technical proofs.

The call-by-value λ-calculus
In this section we briefly recall the syntax and the operational semantics of the λβ v -calculus, as stated by Plotkin [11]. The λβ v -calculus is a restriction of the classical λ-calculus, based on the notion of value. In particular, the restriction concerns the evaluation rule, the β-rule, which is replaced by the β v -rule.  The β v reduction satisfies both the Church-Rosser property and the Standardization property (see [11]).
The evaluation of a program (closed term) is formalized through a reduction machine, which we call secd machine for pointing out that it is equivalent (w.r.t. the termination property) to the S.E.C.D. machine defined by Landin for evaluating expressions [8], once its input is restricted to pure λ-calculus terms. We give here a logical presentation of this machine, i.e., the machine is defined as a set of logical rules, and the evaluation process is mimicked by a logical derivation.
The operational equivalence between terms is determined by observing the termination of computations carried out by the secd machine.

Definition 2.4.
i) The secd-machine is a set of rules proving statement of the shape: M ⇓ s N where M ∈ Λ 0 and N ∈ V al. The rules are: If M ⇓ s N , we will say that M is the input of the secd machine and N is the corresponding output. Let M ⇓ s be an abbreviation for: It is immediate to verify that the secd-machine is deterministic, i.e., if M ⇓ s then there is exactly one N such that M ⇓ s N and moreover there is exactly one derivation proving M ⇓ s N . So, if M ⇓ s , then we can define the number of steps of the secd-machine when filled with input M (notation: step s (M )) as the number of applications of rules in the derivation proving M ⇓ s N . It can be checked that the secd-machine reduces at the every step the leftmost outermost β v -redex occurring in the input term not inside the scope of an abstraction, until a value is reached. The following proposition holds: By the standardization property of β v -reduction, see [11].

Potentially valuable and v-solvable terms
In this section, both the notions of potentially valuable and v-solvable term are introduced, and their relation is discussed. The notion of potentially valuable term is the extension to open terms of the notion of termination in the secd machine. Note that this extension cannot be defined in the standard way, by defining an open term being potentially valuable if its closure is valuable, since the secd machine evaluates terms in a lazy way, so all abstractions are terminating. It is immediate to verify that a closed term is potentially valuable if and only if it is valuable. Now, let us define the notion of v-solvability, for grasping the functional behaviour of terms.

Lemma 3.3. The class of v-solvable terms is properly included in the class of potentially valuable terms.
Proof. Let first prove the inclusion. Let M be v-solvable, so for some closed values The inclusion is proper, since λx.∆∆ is valuable, and so potentially valuable, but clearly v-unsolvable.

Operational characterization of potentially valuable terms
In this section a new reduction machine, the inner-machine, is introduced, which operationally characterizes the potentially valuable terms, in the sense that it stops if and only if the input term is potentially valuable. The shape of the output results of such a machine, which we call canonical terms, is particularly interesting.

Definition 4.1.
i) A term M is canonical if and only if it is either a value or of the shape: ii) The inner-machine is a set of rules proving statements of the shape: where M ∈ Λ and N ∈ C. The rules are: It is easy to prove that the inner-machine is well-defined, i.e., if M ⇓ i N then N ∈ C, and moreover the machine is deterministic. So the notion of the number of steps (defined for the secd-machine in the previous section) can be extended to the i-machine in a straightforward way: if M ⇓ i , step i (M ) denotes the number of steps performed by the i-machine on input M .
Note that the inner-machine executes the classical β-reduction (call by name) with an innermost-lazy strategy. In fact it performs at every step the lefmost innermost β-redex not inside the scope of a λ-abstraction, until either an abstraction or a head variable is reached, and, in the last case, it performs the same reduction strategy in parallel inside all the arguments.
Let us introduce a new reduction rule: Let → i , → * i and = i denote respectively the closure under application of the → inner , the reflexive and transitive closure of → i and the reflexive, symmetric and transitive closure of → i .
Note that → i , → * i and = i are not contextual closed, but they are just closed under application. Indeed, the reduction relation obtained by the contextual closure of → inner is not Church-Rosser (e.g., the term (λx.(λz.I)(x∆))∆ would reduce both to I and (λz.I)(∆∆), which do not have a common reduct).
→ * i , as have been defined, is Church-Rosser (it can be easily proved), and moreover, being not closed under abstraction, it is intrinsecally lazy. As far as the example before is concerned, note that the term (λx.(λz.I)(x∆))∆ has just one i-redex, and it i-reduces only to (λz.I)(∆∆).
The inner-machine can be alternatively described as performing the → i reduction. More precisely, it performs the lefmost outermost i-redex not inside the scope of a λ-abstraction, until either an abstraction or a head variable is reached, and in this last case it performs the same reduction strategy inside all the arguments. Moreover canonical terms are lazy normal forms with respect to the i-reduction rule, i.e., a canonical term does not contain i-redexes, but inside the scope of a λ-abstraction. The following proposition clarifies the relation between the imachine and the i-reduction. The behaviour of the inner-machine and of the secd-machine coincide on closed terms, as proved by the following proposition.
Proof. (⇒) By induction on step i (M ). In case the last used rule is (lazy) then the proof is obvious. The last used rule cannot be (var), since M is closed. Let the last used rule be (head), and let the derivation be: This implies there is a derivation: We will prove that P The first step is obvious, by the rule (app). For the induction step, looking at the derivation showed before, we can assume (λx.P )QM 1 . . .M m−1 ⇓ s λz.S. So we can build the derivation: (⇐) By induction on step s (M ). If the last used rule is (abs) then the proof is obvious. Otherwise, let the derivation be: (head)). We will prove, by induction on So we can build the following derivation: In order to prove that the inner-machine completely characterizes the potentially valuable terms, we need some lemmas. Moreover, for proving them, we need to introduce a measure to be used for currying out the induction. Informally such a measure, that we call weight, is an upper bound to both the number of lazy β v -reductions and of i-reductions needed for reducing a term to a value, if it is possible.
Definition 4.4. The weight of M (denoted by M ), is the partial function defined as follows: Proof. See Appendix A.
So we will give the proof by induction on step i (M ). If step i (M ) = 1, then m = 0, and the proposition is vacuosly true. Otherwise, the derivation of M ⇓ i N is of the shape: Proof. By induction on step i (M ). The case step i (M ) = 1 is trivial.
In the case the last applied rule is (var) the result is obvious. Let the last applied rule be In particular, since step i (M ) = 1 + q + p, for all ρ ≥ step i (M ), both Now we are able to prove the characterization theorem.  Note that in general the equivalence induced by closing contexts does not coicide with that one induced by all context. For example, let us consider the machine which takes a λ-term as input, performs at every step the leftmost outermost β vredex not inside the scope of a λ-abstraction and stops on the lazy β v -normal form. For closed terms this machine is equivalent to the secd-machine, so it induces the same equivalence.

Operational characterization of v-solvability
In this section the operational characterization of the v-solvability is given, through a reduction machine, the ahead machine.
Such a reduction machine performs the β-reduction and uses the inner-machine as submachine.
h.n.f) if and only if it has the following shape: ii) The ahead-machine is a set of rules proving statements of the shape: where M ∈ Λ and N ∈ VH. The rules define an auxiliary machine too, proving statements of the shape M ⇓ 1 a N . The set of rules is the following, where k ∈ {0, 1}: Let M ⇓ k a be an abbreviation for M ⇓ k a N , for some N .
It is easy to check that the definition is correct, i.e., M ⇓ 0 a N implies N ∈ VH. Furthermore, note that the machine of level 1 is the inner-machine, i.e. M ⇓ 1 a N if and only if M ⇓ i N . The behaviour of the ahead-machine is not completely lazy: it enters under the external abstraction (if any) and then it works exactly as the inner-machine. In order to give a precise characterization, in terms of reductions, of the behaviour of the ahead-machine, we need to introduce a new reduction rule. Let → I , → * I and = I be the not lazy version of → i , → * i and = i respectively; namely → I , → * I and = I denote respectively the contextual closure of → inner , the reflexive and transitive closure of → I and the reflexive, symmetric and transitive closure of → I .
Proof. First of all, observe that P ⇓ i Q and F V (P . head: Let the last used rule be , then by induction, ∀r > max{n, π}, ∃h ≥ 0: by Church-Rosser, and finally Now we are able to prove our result. It can be interesting to compare the notions of β v -normal form, valuable term and v-solvable term. λx.(λy.∆)(xI)∆ and λx.∆∆ are respectively a β v -normal-form and a value, and are both v-unsolvable.
We can classify the v-unsolvable terms as follows.
Definition 5.6. Let P be v-unsolvable. P is of order 0 if and only if there is no Q such that P = i λx.Q. P is of order k + 1 if P = i λx.Q and k is the maximum integer such that Q is v-unsolvable of order k, while it is of infinite order if this integer does not exists.
All the v-unsolvable terms of order 0 can be consistently equated (see [4]). Moreover the relation between potentially valuable and v-solvable terms can be now stated as follows.

Proposition 5.7. A term is not potentially valuable if and only if it is v-unsolvable of order 0.
A λβ v -theory is a conguence relation on terms closed under the β v -equality. Let us recall that the λ-theories can be classified into sensible and semi-sensible, the former being these equating all unsolvable terms, and the latter these never equating a solvable term to an unsolvable one. We will introduce a similar classification for the λβ v -theories. The λβ v -theory induced by the secd operational equivalence is T secd = {(M, N )|M ≈ s N }. It immediate to see that: Proof. Consider the two terms ∆∆ and λx.∆∆. They are both v-unsolvable but the former is not valuable while the latter is a value.
The combinator Y v is a recursion combinator in the call-by-value setting. We will prove that R and I have the same operational behaviour. The next lemma will allow us to consider just contexts of a particular shape. Proof. See [4] (Th. 33).

Logical characterization
In this section we will present a type assignment system which allows a complete characterization of the v-solvable terms. Definition 6.1. Let ν and α be two type constants. Let T be the set of types σ built out from the following grammar: T will be ranged over by σ, τ, π, ρ, µ....
The → type-constructor is associative on the right and the intersection type-constructor ∩ binds stronger than →. The types are considered modulo permutations of types bound by intersection costructor.
All types have the following shape: for some m, n where ρ is either ν or α. In the latter case the type is named proper. Let a proper type be denoted by σ p and the subset of proper type by T p . In the rest of the paper, we will use ≡ for denoting the synctactical identity both on terms and types.

Definition 6.2.
i) Let a basis be a finite set of assignments of the shape x : σ, where x is a variable and σ is a type. If B is a basis, let dom(B) = {x | x : σ ∈ B}. ii) The following type assignment system proves statements of the shape: B M : σ where B is a basis, M ∈ Λ and σ ∈ T . The rules are: We will denote by D : We will prove that the typability in the above type assignment system is preserved by β-reduction and by a particular case of I-expansion. In particular, since → i implies → β , and the i-expansion implies the expansion we considered, it turns out that the system is closed under = i . 1) There is a subderivation S ⊆ D of the shape: the following subderivation S can be built.
The desired D is then obtained by replacing in D the subderivation S by S and finally, by replacing in the rest of derivation (λx.P )Q by P [Q/x].
2) Let the redex be introduced by an application of the rule (→ ν I) followed by an application of the rule (→ E). In this case the proof is similar, but it is possible that B = B since either x does not occur in P or it occurs just in subterms of P typed by ν . Proof. The occurrences of Q considered for the expansion in P can be divided in two groups: let Q 1 ,. . ., Q q (q ≥ 0) be those occurrences of Q such that there is and let Q q+1 ,. . ., Q q+p (p ≥ 0) be those occurrences of Q which are not typed by subderivations of D (i.e. these occurrences are in subterms of P typed by the constant ν). We will consider two cases, according to q = 0 or q > 0. q = 0 Every occurrence of Q in P [Q/x] occurs in a subterm of P typed by a rule (ν).
Since, by hypothesis, Q ∈ C, by Property 6.3, there is B and a derivation S proving B Q : ν. Let replace in D every such occurrence of Q by x (note that x is not typed); the result is a derivation D : Thus,D is the following subderivation: The subderivationD is obtained by adjoining an application of (→ E) and (→ I) rules to S, in the following way:   The type assignment system , presented here, is strongly related to the system presented in [4] for reasoning on the denotational semantics of the λβ v -calculus (let call it * ). Indeed, can be obtained from * by restricting both the syntax of types and the rules of types formation, and by dropping the weakening and subtyping rules. The two systems have the same typability power. We could use directly system * for characterizing the v-solvability, introducing in it a suitable notion of proper type. But the characterization would have been less simple and clear.

Appendix A
In order to prove the proposition we need some additional lemmas.
is a value and so Q = 0. We can assume, without loss of generality, that x ∈ F V (P i ), for all i (1 ≤ i ≤ n); otherwise we can rename the bound variable x with a fresh variable. Let

Proof.
i) By induction on the number of steps of the reduction M → * vM ∈ V al using Lemma 7.1. ii) By i) and by Lemma 7.2. iii) By ii), since the β v -reduction is a special case of the β-reduction.
The proof will be given by a computability argument. Let assume N ∈ C and Comp i (µ j , N) (