Analogy between types and first order logic
posted by Lee
posted 170d 12h ago
Next, we say that
to mean that e has type
within the empty context. Since the empty context
is the bottom element, then if
implies that for all
,
.
Finally, we say an expression
is well typed if there exists some type
such that
. For example, the program
is not well typed since we can't apply 42 to a function expecting (). But the program
is well typed because we can build the derivation/proof tree of its typing:
It also happens that these rules, in conjunction with the natural operational semantics defined for this system of simply typed lambda calculus
, is sound. Soundness (in the case of
this is equivalent to normalization) essentially says that well typed programs do not get stuck.
Finally, we illustrate the analogy between types in
and first order logic.
It was noticed some time ago that the judgements within first order constructive/intuitionistic logic look REALLY REALLY similar to judgements for our typing relation. In first order logic, we say
for some logical context
and some logical atom
, that if all of the logical elements within the context
hold/are true, then we can conclude that
are also true.
Compare this to the type relation case where
to mean that given the inputs
and an expression
(such that we can transform these two into a collection of type judgements), then we can satisfy the relation
.
Under these same interpretations however, we can get an isomorphic set of rules. For example, the rules for the left/right conjunction rules are respectively
these are both quite similar to a derived typing rule from #1, #2 and our
rule
similarly for sum types and function types w.r.t to disjunction and implications
For the disjunction case,
is isomorphic to the typing rules for left and right terms
and the derived case rule
As an exercise to the reader, show the same isomorphism between
and
.
This then suggests that if it's possible to construct a term in
that has a type
, then the derivation tree proving that
can be directly translated into first order logic as a proof of the logic analog of
.
to mean that e has type
within the empty context. Since the empty context
is the bottom element, then if
implies that for all
,
.
Finally, we say an expression
is well typed if there exists some type
such that
. For example, the program
is not well typed since we can't apply 42 to a function expecting (). But the program
is well typed because we can build the derivation/proof tree of its typing:
It also happens that these rules, in conjunction with the natural operational semantics defined for this system of simply typed lambda calculus
, is sound. Soundness (in the case of
this is equivalent to normalization) essentially says that well typed programs do not get stuck.
Finally, we illustrate the analogy between types in
and first order logic.
It was noticed some time ago that the judgements within first order constructive/intuitionistic logic look REALLY REALLY similar to judgements for our typing relation. In first order logic, we say
for some logical context
and some logical atom
, that if all of the logical elements within the context
hold/are true, then we can conclude that
are also true.
Compare this to the type relation case where
to mean that given the inputs
and an expression
(such that we can transform these two into a collection of type judgements), then we can satisfy the relation
.
Under these same interpretations however, we can get an isomorphic set of rules. For example, the rules for the left/right conjunction rules are respectively
these are both quite similar to a derived typing rule from #1, #2 and our
rule
similarly for sum types and function types w.r.t to disjunction and implications
For the disjunction case,
is isomorphic to the typing rules for left and right terms
and the derived case rule
As an exercise to the reader, show the same isomorphism between
and
.
This then suggests that if it's possible to construct a term in
that has a type
, then the derivation tree proving that
can be directly translated into first order logic as a proof of the logic analog of
. 






























 = \mathsf{int}}{x:\mathsf{int} \vdash x : \mathsf{int}}\mbox{\textsc{T-Var}}
}{\vdash \lambda x:\mathsf{int}. x : \mathsf{int} \to \mathsf{int}}\mbox{\textsc{T-Abs}} ~~~~
\dfrac{~}{\vdash 2 : \mathsf{int}}\mbox{\textsc{T-Int}}
}{\vdash (\lambda x:\mathsf{int}. x)~42 : \mathsf{int}}\mbox{\textsc{T-App}}
\dfrac{
\dfrac{
\dfrac{[x:\mathsf{int}](x) = \mathsf{int}}{x:\mathsf{int} \vdash x : \mathsf{int}}\mbox{\textsc{T-Var}}
}{\vdash \lambda x:\mathsf{int}. x : \mathsf{int} \to \mathsf{int}}\mbox{\textsc{T-Abs}} ~~~~
\dfrac{~}{\vdash 2 : \mathsf{int}}\mbox{\textsc{T-Int}}
}{\vdash (\lambda x:\mathsf{int}. x)~42 : \mathsf{int}}\mbox{\textsc{T-App}}](equations/119444_0.png)





















![\dfrac{\Gamma \vdash e_1 : \tau_1 \to \alpha ~~~~ \Gamma \vdash e_2 : \tau_2 \to \alpha ~~~~ \alpha' = \mathcal{T}[\alpha]}
{\mathcal{E}[\mathsf{case}~e_0~\mathsf{of}\{e_1\mid e_2\}] = \mathcal{E}[e_0]_{\alpha'} ~ (\mathcal{E}[e_1], \mathcal{E}[e_2])}
\dfrac{\Gamma \vdash e_1 : \tau_1 \to \alpha ~~~~ \Gamma \vdash e_2 : \tau_2 \to \alpha ~~~~ \alpha' = \mathcal{T}[\alpha]}
{\mathcal{E}[\mathsf{case}~e_0~\mathsf{of}\{e_1\mid e_2\}] = \mathcal{E}[e_0]_{\alpha'} ~ (\mathcal{E}[e_1], \mathcal{E}[e_2])}](equations/119461_4.png)
![\mathcal{E}[\mathsf{left}_{\tau_1 + \tau_2} ~ e] = \forall \alpha.\lambda p: \mathcal{T}[\tau_1] \to \alpha \times \mathcal{T}[\tau_2] \to \alpha. (\#1 p)~\mathcal{E}[e]
\mathcal{E}[\mathsf{left}_{\tau_1 + \tau_2} ~ e] = \forall \alpha.\lambda p: \mathcal{T}[\tau_1] \to \alpha \times \mathcal{T}[\tau_2] \to \alpha. (\#1 p)~\mathcal{E}[e]](equations/119461_5.png)
![\mathcal{E}[\mathsf{right}_{\tau_1 + \tau_2} ~ e] = \forall \alpha.\lambda p: \mathcal{T}[\tau_1] \to \alpha \times \mathcal{T}[\tau_2] \to \alpha. (\#2 p)~\mathcal{E}[e]
\mathcal{E}[\mathsf{right}_{\tau_1 + \tau_2} ~ e] = \forall \alpha.\lambda p: \mathcal{T}[\tau_1] \to \alpha \times \mathcal{T}[\tau_2] \to \alpha. (\#2 p)~\mathcal{E}[e]](equations/119461_6.png)

![\mathcal{T}[\tau_1 + \tau_2] = \forall \alpha . (\mathcal{T}[\tau_1] \to \alpha \times \mathcal{T}[\tau_2] \to \alpha) \to \alpha) \mathcal{T}[\tau_1 + \tau_2] = \forall \alpha . (\mathcal{T}[\tau_1] \to \alpha \times \mathcal{T}[\tau_2] \to \alpha) \to \alpha)](equations/119461_20.png)

