Skip to content

Commit ef1925c

Browse files
committed
Eigenvariables
1 parent 6d08c22 commit ef1925c

6 files changed

Lines changed: 293 additions & 79 deletions

text/curry_howard_correspondence.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ \section{Curry-Howard correspondence}\label{sec:curry_howard_correspondence}
1313

1414
Haskell Curry is credited for the realization that, in modern terms, the \hyperref[def:arrow_type]{arrow type} \( \tau \synimplies \rho \) can be regarded as a \hyperref[def:propositional_alphabet/connectives/conditional]{conditional formula}. In this section will extend this to \hyperref[def:simple_algebraic_types]{simple algebraic types}.
1515

16-
William Howard is credited for extending this analogy to \hyperref[sec:first_order_logic]{first-order logic} via what are now called \enquote{dependent types}. We discuss these extensions in \cref{rem:mltt_hol}.
16+
William Howard is credited for extending this analogy to \hyperref[sec:first_order_logic]{first-order logic} via what are now called \enquote{dependent types}. We discuss these extensions in \fullref{sec:predicate_logic}.
1717

1818
Honoring Curry and Howard, we will refer to the overall identification of types and formulas as the \term[en=Curry-Howard correspondence (\cite[def. 4.1.7]{Mimram2020ProgramEqualsProof})]{Curry-Howard correspondence}.
1919

text/dependent_types.tex

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ \section{Dependent types}\label{sec:dependent_types}
101101
\end{equation*}
102102
as an \( n \)-ary function whose arguments are inhabitants of \( \tau_1, \ldots, \tau_n \), correspondingly. In accordance with the terminology for functions from \cref{con:variable_dependence}, we may state that \( M \) depends on variables of types \( \tau_1, \ldots, \tau_n \).
103103

104-
We can extend this to \hyperref[rem:pseudoterm_schemas]{Martin-L\"of type theory pseudoterms} by regarding \( \synprod \) and \( \synsum \) as \hyperref[con:variable_binding]{variable binders} in addition to \( \synlambda \).
104+
We can extend this to \hyperref[def:mltt_pseudoterm]{Martin-L\"of type theory pseudoterms} by regarding \( \synprod \) and \( \synsum \) as \hyperref[con:variable_binding]{variable binders} in addition to \( \synlambda \).
105105

106106
Because of the unified syntax of terms and types, this opens different possibilities. Suppose that, in a fixed \hyperref[def:abstract_type_system]{type system}, \( M \) inhabits \( \tau \). Then, in accordance with \cref{rem:well_formed_context}, based on \( \tau \) and \( \tau_k \), we can state that the term/type \( M \) depends on the term/type variable \( x_k \).
107107

@@ -174,9 +174,9 @@ \section{Dependent types}\label{sec:dependent_types}
174174
\hypo{ x: \syn\Bbbzero }
175175
\infer[dashed]1{ \tau: \BbbT }
176176
177-
\hypo{ a: \syn\Bbbzero }
177+
\hypo{ A: \syn\Bbbzero }
178178
179-
\infer2[\ref{inf:def:simple_empty_type/elim}]{ \synE_- (\qabs {x^{\syn\Bbbzero}} \tau) a: \tau[x \mapsto a] }
179+
\infer2[\ref{inf:def:simple_empty_type/elim}]{ \synE_- (\qabs {x^{\syn\Bbbzero}} \tau) A: \tau[x \mapsto A] }
180180
\end{prooftree}
181181
\end{equation*}
182182
\end{definition}
@@ -191,8 +191,8 @@ \section{Dependent types}\label{sec:dependent_types}
191191
\begin{equation*}
192192
\begin{prooftree}
193193
\hypo{ \Gamma, x: \syn\Bbbzero \vdash \tau: \BbbT }
194-
\hypo{ \Gamma \vdash a: \syn\Bbbzero }
195-
\infer2[\ref{inf:def:simple_empty_type/elim}]{ \Gamma \vdash \synE_- (\qabs {x^{\syn\Bbbzero}} \tau) a: \tau[x \mapsto a] }
194+
\hypo{ \Gamma \vdash A: \syn\Bbbzero }
195+
\infer2[\ref{inf:def:simple_empty_type/elim}]{ \Gamma \vdash \synE_- (\qabs {x^{\syn\Bbbzero}} \tau) A: \tau[x \mapsto A] }
196196
\end{prooftree}
197197
\end{equation*}
198198

@@ -651,30 +651,6 @@ \section{Dependent types}\label{sec:dependent_types}
651651
\item The rules are generally based on Martin-L\"of's rules from \cite[35]{MartinLöf1984IntuitionisticTypeTheory}, with computation and equality rules adapted from \cite[\S A.2.4]{UnivalentFoundationsProgram2013HoTT}. Due to \cref{rem:product_type_via_dependent_product}, the latter prefer calling dependent products \enquote{dependent function types}.
652652
\end{comments}
653653

654-
\begin{remark}\label{rem:typing_rule_eigenvariables}
655-
We have stated the rule \ref{inf:def:dependent_product/intro} as
656-
\begin{equation*}
657-
\begin{prooftree}
658-
\hypo{ x: \tau }
659-
\infer[dashed]1{ M: \sigma }
660-
\infer1[\ensuremath{ \Pi_+ }]{ \qabs {x^\tau} M: \qprod {x^\tau} \sigma }
661-
\end{prooftree}
662-
\end{equation*}
663-
664-
Actually, due to the Curry-Howard correspondence, the rule should exactly match \ref{eq:def:first_order_natural_deduction_system/forall/intro}, which we state as
665-
\begin{equation*}
666-
\begin{prooftree}
667-
\hypo{ \varphi[x \mapsto y] }
668-
\infer1[\ensuremath{ \synforall_+ }]{ \qpolytype x \varphi },
669-
\end{prooftree}
670-
\end{equation*}
671-
where the \hyperref[con:eigenvariable]{eigenvariable} \( y \) either equals \( x \) or otherwise \( y \) is not free in \( \varphi \) nor any open assumption.
672-
673-
The difference comes from how we handle \hyperref[def:lambda_term_alpha_equivalence]{\( \alpha \)-equivalence}. In the typing rule, we rely on judgmental equality, and in particular on the rule \ref{rem:type_theory_rule_classification/equality/alpha}. This rule ensures that, due to a generalization of \cref{thm:alpha_conversion}, the types \( \qprod {x^\tau} \sigma \) and \( \qprod {y^\tau} \sigma[x \mapsto y] \) are equal (as long as \( y \) is not an open assumption \( \sigma \)). We do not mention free variables because, as described in \cref{rem:beta_equivalence_and_free_variables}, in the presence of judgmental equality rules, the concept of free variables becomes largely meaningless.
674-
675-
On the other hand, in first-order logic, we do not rely such much on implicit metatheoretic equality, and the formulas \( \qpolytype x \varphi \) and \( \qpolytype y \varphi[x \mapsto y] \) are distinct. In order to be able to derive both from \( \varphi \), we must state the eigenvariable condition and use substitution in the rule premise.
676-
\end{remark}
677-
678654
\begin{remark}\label{rem:arrow_type_via_dependent_product}
679655
The \hyperref[def:arrow_type]{arrow type} \( \tau \synimplies \sigma \) is a special case of the \hyperref[def:dependent_product]{dependent product} \( \qprod {x^\tau} \sigma \), in which \( \sigma \) does not depend on \( x \) (in the sense of \cref{rem:mltt_pseudoterm_dependency}).
680656
\end{remark}
@@ -764,9 +740,9 @@ \section{Dependent types}\label{sec:dependent_types}
764740
\hypo{ z: \qsum {x^\tau} \sigma }
765741
\infer[dashed]1{ \rho: \BbbT }
766742
767-
\hypo{ x: \tau }
768-
\hypo{ y: \sigma }
769-
\infer[dashed]2{ M: \rho[z \mapsto \synS_+ x y] }
743+
\hypo{ a: \tau }
744+
\hypo{ b: \sigma }
745+
\infer[dashed]2{ M: \rho[z \mapsto \synS_+ a b] }
770746
771747
\hypo{ A: \qsum {x^\tau} \sigma }
772748
@@ -780,14 +756,14 @@ \section{Dependent types}\label{sec:dependent_types}
780756
\hypo{ z: \qsum {x^\tau} \sigma }
781757
\infer[dashed]1{ \rho: \BbbT }
782758
783-
\hypo{ x: \tau }
784-
\hypo{ y: \sigma }
785-
\infer[dashed]2{ M: \rho[z \mapsto \synS_+ x y] }
759+
\hypo{ a: \tau }
760+
\hypo{ b: \sigma }
761+
\infer[dashed]2{ M: \rho[z \mapsto \synS_+ a b] }
786762
787763
\hypo{ A: \tau }
788764
\hypo{ B: \sigma[x \mapsto A] }
789765
790-
\infer4[\ref{inf:def:dependent_sum/comp}]{ \synS_- (\qabs {z^{\qsum {x^\tau} \sigma}} \rho) (\qabs {x^\tau} {y^\sigma} M) (\synS_+ A B) \syndefeq M[x \mapsto A, y \mapsto B]: \rho[z \mapsto \synS_+ A B] }
766+
\infer4[\ref{inf:def:dependent_sum/comp}]{ \synS_- (\qabs {z^{\qsum {x^\tau} \sigma}} \rho) (\qabs {a^\tau} {b^\sigma} M) (\synS_+ A B) \syndefeq M[a \mapsto A, b \mapsto B]: \rho[z \mapsto \synS_+ A B] }
791767
\end{prooftree}
792768
\end{equation*}
793769
\end{definition}
@@ -933,6 +909,8 @@ \section{Dependent types}\label{sec:dependent_types}
933909

934910
\thmitem{def:mltt_well_formed_context/derivation} We consider a type derivation tree \( T \) to be well-formed with respect to a well-formed context \( \Gamma \) if all open assumptions of \( T \) are in \( \Gamma \) and if all discharged (closed and implicit) assumptions are \hi{not} in \( \Gamma \) but have well-formed types with respect to \( \Gamma \).
935911

912+
We give several examples in \cref{ex:def:mltt_well_formed_context} of why allowing discharged assumptions in \( \Gamma \) can lead to pathologies.
913+
936914
\thmitem{def:mltt_well_formed_context/type} We consider the pseudoterm expression \( \tau \) a well-formed type with respect to a well-formed context \( \Gamma \) if it either satisfies \cref{def:mltt_well_formed_context/base} (i.e. if it is a type universe) or if there exists a well-formed (with respect to \( \Gamma \)) derivation tree with conclusion \( \tau: \BbbT \), where \( \BbbT \) is a type universe.
937915

938916
\thmitem{def:mltt_well_formed_context/context} Finally, we consider the type context \( \Delta \) to be a well-formed if it either satisfies \cref{def:mltt_well_formed_context/base} (i.e. if it features only type universes; the base case also covers the case where \( \Delta \) is empty) or if \( \Delta = \Gamma, (x: \tau) \), where \( \Gamma \) has already been shown to be a well-formed context, and \( \tau \) has already been shown to be a well-formed type with respect to \( \Gamma \).
@@ -1015,15 +993,39 @@ \section{Dependent types}\label{sec:dependent_types}
1015993
\end{prooftree}
1016994
\end{equation*}
1017995
that is well-formed with respect to \( \Gamma \).
996+
997+
\thmitem{ex:def:mltt_well_formed_context/discharging} The type \( \synx \syneq_{\syn\tau} \syny \) is well-formed in the context \( \syn\tau: \BbbT, \synx: \syn\tau, \syny: \syn\tau \) due to \ref{inf:def:identity_type/form}.
998+
999+
Let \( M \) be some term inhabiting this type and consider the following derivation tree:
1000+
\begin{equation*}
1001+
\begin{prooftree}
1002+
\hypo{ M: \synx \syneq_{\syn\tau} \syny }
1003+
\infer[left label=\( \synx \)]1[\ref{inf:def:dependent_product/intro}]{ \qabs {\synx^{\syn\tau}} M: \qprod {\synx^{\syn\tau}} (\synx \syneq_{\syn\tau} \syny) }
1004+
\end{prooftree}
1005+
\end{equation*}
1006+
1007+
According to \cref{def:mltt_well_formed_context/derivation}, the tree is well-formed in a (well-formed) context \( \Gamma \) if \( \Gamma \) contains the open assumptions \( \syn\tau: \BbbT \) and \( \syny: \syn\tau \), but \hi{not} the discharged assumption \( \synx: \syn\tau \). Without \( \synx: \syn\tau \), the assumption \( M: \synx \syneq_{\syn\tau} \syny \) cannot even be assigned a type. So this derivation tree is ill-formed.
1008+
1009+
See \cref{con:eigenvariable} for how this well-formedness condition justifies the eigenvariable conditions in \hyperref[def:higher_order_logic]{higher-order logic}.
10181010
\end{thmenum}
10191011
\end{example}
10201012

1021-
\begin{remark}\label{rem:mltt_hol}
1013+
\begin{remark}\label{rem:mltt_curry_howard}
10221014
With the \hyperref[def:type_derivation_relation]{type derivation relation} defined in \cref{def:mltt_entailment}, \hyperref[def:martin_lof_type_theory]{Martin-L\"of type theory} can be seen as a form of \hyperref[rem:predicate_logic]{predicate logic} if we extend the \hyperref[con:curry_howard_correspondence]{Curry-Howard correspondence} by matching \hyperref[def:predicate_logic_alphabet/quantifiers/universal]{universal quantifiers} with \hyperref[def:dependent_product]{dependent products} and \hyperref[def:predicate_logic_alphabet/quantifiers/existential]{existential quantifiers} with \hyperref[def:dependent_sum]{dependent sums}.
10231015

1024-
We do not put restrictions on which types are allowed to act as formulas. This makes the theory go beyond what we discuss in \fullref{sec:predicate_logic}.
1016+
\begin{thmenum}
1017+
\thmitem{rem:mltt_curry_howard/no_restriction} Without constraints on which types are allowed to act as formulas, we obtain a very general \hyperref[con:logical_system]{logical system} that is hard to analyze.
1018+
1019+
\thmitem{rem:mltt_curry_howard/mere_propositions} One possibility is to only use allow those types that are \hyperref[def:mere_proposition]{mere propositions}.
10251020

1026-
One reasonable restriction is to only use \hyperref[def:mere_proposition]{mere propositions} rather than arbitrary types. This has the downside that, as mentioned in \cref{rem:mere_propositions}, without additional assumptions we are not able to prove that some useful types are mere propositions.
1021+
A benefit of this is that all terms inhabiting a mere proposition are \hyperref[def:mltt_propositional_equality]{propositionally equal}. This is important in some cases such as our definition of subtypes in \cref{def:dependent_subtype}.
1022+
1023+
\thmitem{rem:mltt_curry_howard/arrow_types} Another possibility is to restrict type annotations of quantifiers to only arrow types without type variables.
1024+
1025+
The resulting types then resemble those allowed by Church in his simply typed higher-order logic. Since Church encoded propositions via terms (and not types), we must discard the terms since they are not relevant. This is discussed in \cref{rem:higher_order_logic_and_type_theory}. The inference rules require adaptation; see \cref{con:eigenvariable}.
1026+
1027+
We use this hybrid approach in \fullref{sec:predicate_logic}.
1028+
\end{thmenum}
10271029
\end{remark}
10281030

10291031
\begin{proposition}\label{thm:propositional_equality_equivalence_relation}
@@ -1226,9 +1228,9 @@ \section{Dependent types}\label{sec:dependent_types}
12261228

12271229
\paragraph{Subtypes}
12281230

1229-
\begin{definition}\label{def:subtype}\mcite[46; 115]{UnivalentFoundationsProgram2013HoTT}
1231+
\begin{definition}\label{def:dependent_subtype}\mcite[46; 115]{UnivalentFoundationsProgram2013HoTT}
12301232
Consider the \hyperref[def:dependent_sum]{dependent sum} \( \qsum {x^\tau} \sigma \), assumed to satisfy
1231-
\begin{equation}\label{eq:def:subtype}
1233+
\begin{equation}\label{eq:def:dependent_subtype}
12321234
\qprod {x^\tau} \ref{abbr:def:mere_proposition}[\sigma].
12331235
\end{equation}
12341236

@@ -1244,31 +1246,31 @@ \section{Dependent types}\label{sec:dependent_types}
12441246
\item Subtypes are ubiquitous in programming, where they are advised, if not enforced, to obey Liskov's substitution principle. We discuss this principle in \cref{con:liskov_substitution_principle}.
12451247
\end{comments}
12461248

1247-
\begin{example}\label{ex:def:subtype}
1248-
We list examples of \hyperref[def:subtype]{subtypes}:
1249+
\begin{example}\label{ex:def:dependent_subtype}
1250+
We list examples of \hyperref[def:dependent_subtype]{subtypes}:
12491251
\begin{thmenum}
1250-
\thmitem{ex:def:subtype/trivial} For any type \( \tau \), the (dependent) \hyperref[def:dependent_empty_type]{empty type} induces the \hyperref[def:propositionally_uninhabited]{propositionally uninhabited} subtype \( \qsum {\synx^\tau} \syn\Bbbzero \).
1252+
\thmitem{ex:def:dependent_subtype/trivial} For any type \( \tau \), the (dependent) \hyperref[def:dependent_empty_type]{empty type} induces the \hyperref[def:propositionally_uninhabited]{propositionally uninhabited} subtype \( \qsum {\synx^\tau} \syn\Bbbzero \).
12511253

1252-
Indeed, by \cref{thm:empty_type_is_proposition}, \( \syn\Bbbzero \) is a mere proposition, so the condition \eqref{eq:def:subtype} for the definition of subtype is satisfied.
1254+
Indeed, by \cref{thm:empty_type_is_proposition}, \( \syn\Bbbzero \) is a mere proposition, so the condition \eqref{eq:def:dependent_subtype} for the definition of subtype is satisfied.
12531255

12541256
Furthermore, the right projection \( \pi_R: \qprod {\syna^{\qsum {x^\tau} \syn\Bbbzero}} \syn\Bbbzero \) itself acts as a witness that the subtype \( \qsum {x^\tau} \syn\Bbbzero \) is (propositionally) uninhabited.
12551257

1256-
\thmitem{ex:def:subtype/improper} Dually, for any type \( \tau \), the (dependent) \hyperref[def:dependent_unit_type]{unit type} induces the subtype \( \qsum {\synx^\tau} \syn\Bbbone \).
1258+
\thmitem{ex:def:dependent_subtype/improper} Dually, for any type \( \tau \), the (dependent) \hyperref[def:dependent_unit_type]{unit type} induces the subtype \( \qsum {\synx^\tau} \syn\Bbbone \).
12571259

12581260
The definition of subtype is satisfied because, due to \cref{thm:unit_type_is_proposition}, \( \syn\Bbbone \) is a mere proposition.
12591261

12601262
Furthermore, \( \syn\Bbbone \) does not depend on \( \synx \) and it is always inhabited. Thus, the inclusion \( \iota \) is a surjective function --- for any term \( M \) of \( \tau \), \( \synS_+ M \synU_+ \) is a term of the subtype \( \qsum {\synx^\tau} \syn\Bbbone \).
12611263

1262-
\thmitem{ex:def:subtype/unit} Consider the subtype \( \qsum {\synx^{\syn\Bbbone}} (\synx \syneq_{\syn\Bbbone} \synU_+) \) of the unit type \( \syn\Bbbone \).
1264+
\thmitem{ex:def:dependent_subtype/unit} Consider the subtype \( \qsum {\synx^{\syn\Bbbone}} (\synx \syneq_{\syn\Bbbone} \synU_+) \) of the unit type \( \syn\Bbbone \).
12631265

12641266
For simplicity, we can assume the \( K \) elimination rule \ref{inf:def:identity_type/k/elim}. By \cref{thm:uniqueness_of_identity_proofs}, that would imply that the identity type \( \synU_+ \syneq_{\syn\Bbbone} \synU_+ \) is \hyperref[def:contractible_type]{contractible} and, by \cref{thm:contractible_type_is_proposition}, a mere proposition.
12651267

1266-
Then \ref{inf:def:dependent_unit_type/elim} can be used to conclude that \( \synx \syneq_{\syn\Bbbone} \synU_+ \) is a mere proposition for any \( \synx \), hence the condition \eqref{eq:def:subtype} for subtype is satisfied.
1268+
Then \ref{inf:def:dependent_unit_type/elim} can be used to conclude that \( \synx \syneq_{\syn\Bbbone} \synU_+ \) is a mere proposition for any \( \synx \), hence the condition \eqref{eq:def:dependent_subtype} for subtype is satisfied.
12671269
\end{thmenum}
12681270
\end{example}
12691271

12701272
\begin{concept}\label{con:liskov_substitution_principle}
1271-
In \cite[25]{Liskov1987DataAbstractionAndHierarchy}, in the context of object-oriented programming, Barbara Liskov formulates the following informal definition for \hyperref[def:subtype]{subtypes}:
1273+
In \cite[25]{Liskov1987DataAbstractionAndHierarchy}, in the context of object-oriented programming, Barbara Liskov formulates the following informal definition for \hyperref[def:dependent_subtype]{subtypes}:
12721274
\begin{displayquote}
12731275
A type hierarchy is composed of subtypes and supertypes. The intuitive idea of a \textit{subtype} is one whose objects provide all the behavior of objects of another type (the \textit{supertype}) plus something extra. What is wanted here is something like the following substitution property [6]: If for each object \( o_1 \) of type \( S \) there is an object \( o_2 \) of type \( T \) such that for all programs \( P \) defined in the terms of \( T \), the behavior of \( P \) is unchanged when \( o_1 \) is substituted for \( o_2 \), then \( S \) is a subtype of \( T \).
12741276
\end{displayquote}

0 commit comments

Comments
 (0)