In the simply-typed lambda calculus, how do you prove that: If two terms are beta-equivalent, then they have the same type?
My guess is that I should use the subject reduction, and maybe the confluence...
Theoretical Computer Science Stack Exchange is a question and answer site for theoretical computer scientists and researchers in related fields. It only takes a minute to sign up.
Sign up to join this communityIn the simply-typed lambda calculus, how do you prove that: If two terms are beta-equivalent, then they have the same type?
My guess is that I should use the subject reduction, and maybe the confluence...
The answer depends on what you mean by "simply-typed $\lambda$-calculus". There are two possibilities:
Church-style: in this formulation, terms explicitly carry their type and reduction/expansion preserve it by definition, that is, if $t\to u$, then $t$ and $u$ necessarily have the same type. Then the result you are mentioning is, as you say, a consequence of confluence: by confluence, $t$ is $\beta$-equivalent to $u$ iff there exists $v$ such that $t\to^\ast v$ and $u\to^\ast v$. By definition, $t$ has the same type as $v$, which has the same type as $u$. (In fact, you don't even need confluence: by definition, $t$ and $u$ are $\beta$-equivalent if there is a finite chain of reductions and "anti-reductions" relating $t$ and $u$, so their types must be the same because in the Church-style system reductions only relate terms with the same type).
Curry-style: if you see simple types as a type system for the $\lambda$-calculus, then the result you mention is false, because such a type system does not enjoy subject expansion. For example, let $t:=(\lambda x.xx)I$ and $u:=II$, where $I$ is the identity. Then $t\to u$, so $t$ and $u$ are $\beta$-equivalent, and yet $u$ is simply-typable and $t$ is not. As proved in Nift's answer below, there are even examples of this phenomenon in which $t$ too is typable (but has strictly less types than $u$).
Actually I have deleted an answer to what I claimed in the comments and would like to provide a counterexample in Curry-style STLC, this is 5.12 in https://www.cse.chalmers.se/research/group/logic/TypesSS05/Extra/geuvers.pdf, which I reproduce here. There are $M$, $M'$ ∈ Λ and $σ$, $σ'$ ∈ T such that $M' \twoheadrightarrow_{\beta} M$ and $\vdash M : σ$, $\vdash M' : σ'$, but $\nvdash M' : σ$. Take $M \equiv \lambda xy.y$, $M' \equiv SK$. Take $\sigma \equiv \alpha \rightarrow (\beta \rightarrow \beta)$ and $\sigma' \equiv (\beta \rightarrow \alpha) \rightarrow (\beta \rightarrow \beta)$.
Take these M' and M, given that $M' \twoheadrightarrow_{\beta} M$, $M' \equiv_{\beta} M$,, but by the above $M$ has a typing $\sigma$, but $M'$ does not. To see why $M$ having a typing $\sigma$ is trivial.
For M' and M being equivalent see as follows,
M' = SK
= (λxyz.xz(yz))(λxy.x)
= λyz.(λxy.x)z(yz)
= λyz.(λy.z)(yz)
= λyz. z
which is we can alpha rename to $M$.
For $M'$ not having typing $\sigma$ see as follows, to type SK we need to know that the second argument of S is a function.
Thus we have 2 $\beta$-equivalent terms, only one of which is typeable at $\sigma$, but both are simply typeable.