Dependent Types \(\Pi\), \(\Sigma\), \(\forall\) & \(\exists\)

2020 James B. Wilson

Colorado State University

 

\(\times\)-type (Pair type)

\[\frac{A,B:type}{A\times B:type}(F_{\times})\]

 

\[\frac{a:A\quad b:B}{(a,b):A\times B}(I_{\times})\]

\[\frac{x:A\times B}{\pi_A(x):A}(E_{\times}A)\]

\[\frac{x:A\times B}{\pi_B(x):B}(E_{\times} B)\]

\[\frac{a:A\quad b:B}{refl_a:\pi_A(a,b)=_A a}(C_{\times}A)\]

 

\[\frac{a:A\quad b:B}{refl_b:\pi_A(a,b)=_B b}(C_{\times}B)\]

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

\(\times\)-type (Pair type)

\[\frac{A,B:type}{A\times B:type}(F_{\times})\]

 

\[\frac{a:A\quad b:B}{(a,b):A\times B}(I_{\times})\]

\[\begin{array}{rl}x & :A\times B\\ f &:T\to A\\ g &:T\to B\\ \hline f\times g & :T\to A\times B\end{array}\]

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

\((E_{\times})\)

\[\begin{array}{rl} t & : T\\ f &:T\to A\\ g &:T\to B\\ \hline refl_{f(t)} & :\pi_A((f\times g)(t))=_A f(t)\end{array}\]

\[\begin{array}{rl}t& : T\\ f &:T\to A\\ g &:T\to B\\ \hline refl_{g(t)} & :\pi_B((f\times g)(t))=_B g(t)\end{array}\]

\[\begin{array}{ccccc} A & \overset{\pi_A}{\leftarrow} & A\times B & \overset{\pi_B}{\rightarrow} & B \\ & f\nwarrow & \uparrow h & \nearrow g\\ & & T & & \end{array}\]

\[\begin{array}{ccccc} P & \leftarrow & P\wedge Q & \rightarrow & Q \\ & \nwarrow & \uparrow & \nearrow \\ & & T & & \end{array}\]

Logic

Sets & Types

(Arrows here are "implies", e.g. T implies P.)

(Arrows here are functions, e.g. T maps to A,

also \(h=f\times g\).)

\(\sqcup\)-type (Disjoint union type)

\[\frac{A,B:type}{A\sqcup B:type}(F_{\sqcup})\]

 

\[\frac{a:A}{\iota_A(a):A\sqcup B}(I_{\sqcup}A)\qquad \frac{b:B}{\iota_B(b):A\sqcup B}(I_{\sqcup}B)\]

\[\frac{x:A\sqcup B, f:A\to C, g:B\to C}{f\sqcup g:A\sqcup B\to C}(E_{\sqcup})\]

\[\frac{a:A}{refl_{f(a)}:(f\sqcup g)(\iota_A(a))=_C f(a)}(C_{\sqcup}A)\]

 

\[\frac{b:B}{refl_{g(b)}:(f\sqcup g)(\iota_B(b))=_C g(b)}(C_{\sqcup}B)\]

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

\[\begin{array}{ccccc} A & \overset{\iota_A}{\rightarrow} & A\sqcup B & \overset{\iota_B}{\leftarrow} & B \\ & f\searrow & \downarrow h & \swarrow g\\ & & R & & \end{array}\]

\[\begin{array}{ccccc} P & \rightarrow & P\vee Q & \leftarrow & Q \\ & \searrow & \downarrow & \swarrow \\ & & R & & \end{array}\]

Logic

Sets & Types

(Arrows here are "implies", e.g. P implies R.)

(Arrows here are functions, e.g. A maps to R,

also \(h=f\sqcup g\).)

Further Important Types

  • \(\Pi\)-types and how it recover \(\forall\)
  • \(\Sigma\)-types and how it recovers \(\exists\)

\(A\times B\times C\) Option 1

Make it from binary products, but which one? \((A\times B)\times C\) or \(A\times (B\times C)\)?

 

\(A\times B\times C\)?

Claim \((A\times B)\times C\) is interchangable with \(A\times (B\times C)\)

Proof. \((x,c)\mapsto (\pi_A(x),(\pi_B(x),c))\)

is a function that can be typed as

\[f:(A\times B)\times C \to A\times (B\times C).\]

Also \((a,y)\mapsto ((a,\pi_B(y)),\pi_C(y))\)

is a function that can be typed as

\[g:A\times (B\times C) \to (A\times B)\times C.\]

\(f\circ g\) is \((x,c)\mapsto (x,c)\) and \(g\circ f\) is \((a,y)\mapsto (a,y)\) (identity functions). \(\Box\)

\(A\times B\times C\)?

Claim \((A\times B)\times C\cong A\times (B\times C)\)

\[\frac{S,T:type}{S\cong T:type}(F_{\cong})\]

\((I_{\cong})\)

\[\begin{array}{l} f:S\to T\\ g:T\to S\\ proof_S: g\circ f=1_S\\ proof_T: g\circ g=1_T\\ \hline iso(f,g):S\cong T\end{array}\]

\[\frac{x:S\cong T}{to_x:S\to T}(E_{\cong}to)\]

 

\[\frac{x:S\cong T}{from_x:T\to S}(E_{\cong}from)\]

\((C_{\cong}S)\)\[\frac{f:S\to T,g:T\to S,\ldots}{proof:to_{iso(f,g)} = f}\]

(details later.)

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

\(A\times B\times C\) Option 1

"Equate" \((A\times B)\times C\) with \(A\times (B\times C)\) via an isomorphism.

 

Subtle problem is you now need to define a type to "equate" types, and on and on.  Leads to \(\infty\)-categories and hard stuff. (Also we have some holes in isomorphism above.)

\(A\times B\times C\) Option 2

Make a new type for triples.

 

Of course next we will want a type for quadruples, qunituples,....multiples.

\(n\)-Multiples type

\[\frac{A_1,\ldots,A_n:type}{A_1\times\cdots \times A_n:type}(F_{\times})\]

 

\[\frac{a_1:A_1,\ldots,a_n:A_n}{(a_1,\ldots,a_n):A_1\times\cdots\times A_n}(I_{n\times})\]

\[\frac{x:A_1\times\cdots\times A_n}{\pi_1(x):A_1}(E_{n\times}1)\ldots\]

 

\[\cdots\frac{a_1:A_1,\ldots,a_n:A_n}{refl_{a_i}:\pi_i(a_1,\ldots,a_n)=_{A_i} a_i}(C_{n\times}i)\cdots\]

\[\cdots\frac{x:A_1\times\cdots\times A_n}{\pi_n(x):A_n}(E_{n\times}n)\]

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

\(\prod_{i:I} A_i\)-types

Multiples just need an index set \(I\), perhaps more interesting than \(I=\{1,\ldots,n\}\), but certainly to include those sets.

 

In fact, \(I\) might just be an index type, no sets required.

\(\Pi\)-type

\[\begin{array}{rl}I &:type\\ A&:I\to type\\ \hline \prod_{i:I} A_i&:type\end{array}(F_{\Pi})\]

 

\[\frac{i:I\Rightarrow a_i:A_i}{(i\mapsto a_i):\prod_{i:I} A_i}(I_{\Pi})\]

\[\begin{array}{rl}i&:I\\ a&:\prod_{i:I} A_i\\ \hline \pi_i(a)& :A_i\end{array}(E_{\Pi})\]

\[\begin{array}{l}i:I\\ j:I\Rightarrow a_j:A_j\\ \hline refl_{a_i}: \pi_i(i\mapsto a_i)=_{A_i} a_i\end{array}(C_{\Pi})\]

Terms \(f:\prod_{i:I}A_i\) are called dependent functions, written \(f:(i:I)\mapsto (f(i):A_i)\).

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

The problem of \(proof_S:g\circ f=1_S\)

Hint of an error: Notice here "=" doesn't have the expected \(=_A\) telling us what type of data we are comparing.

 

What counts as a proof that functions are equal?

 

Real problem of function equals...

There are different meanings.

  • Intentional the intensions of the function are the same, i.e. as computer programs they do the same steps: the "intentions" of \(x\mapsto (x+2)-2)\) is not the same as of \(x\mapsto x\).
  • Extensional function equality extended to the results, rather than the process: "extend" equality to observe \(x\mapsto (x+2)-2\) gives the same result as \(x\mapsto x\).

Function Equality Option

Equal inputs give equal outputs.  Given \(f,g:S\to T\) define

\[(f=g) :\equiv (\forall s:S)(f(s)=g(s))\]

 

Turn "=" premise into data...

\[(f=g) :\equiv (\forall s:S)(refl_{f(s)}: f(s)=_T g(s))\]

Turn "\forall" premise into data...

\[(f=g) :\equiv (s:S)\mapsto (refl_{f(s)}: f(s)=_T g(s))\]

I.e.

\[(f=g) :\equiv \prod_{s:S}(f(s)=_T g(s))\]

Function Equality Option (small(big) gap)

Equal inputs give equal outputs actually should mean:

\[(f=g) :\equiv (\forall s_1,s_2:S)(s_1=_S s_2)\Rightarrow (f(s_1)=_T g(s_2))\]

I.e.

\[(f=g) :\equiv \prod_{s_1,s_2:S}\prod_{pf:(s_1=_S S_2)}f(s_1)=_T g(s_2).\]

It is much harder, but still possible, to work with functions at that level of equality.

 

As evidence of difficulty, even elite programming language like Haskell cannot yet do this.  Though there is a recent prototype called Cubical that can.

\(\forall\) becomes data

When propositions, equations, statements \(P\) are types of data whose data are its proofs, then  \[(\forall x:X)(P(x))\] becomes \[\prod_{x:X}P(x).\]

 

Proof of \((\forall x)(P(x))\) becomes data, a dependent function \[(x:X)\mapsto (evidence_x:P(x)).\]

\(\forall\) becomes data

Surprised?

Recall \(A\times B\) naturally modeled \(P\wedge Q\).

 

\((\forall x:X)(P(x))\) is just a big AND, \(P(x_1)\wedge P(x_2)\wedge\cdots\)

Makes sense that iterating \(\times\) would  be the same as iterating AND, i.e. \(\prod\) and \(\forall\) are linked.

 

\(\Sigma\)-type

  • \(A\sqcup B\) is disjoint union, often written \(A+B\) but we avoid that notation in algebra to avoid confusion.
  • \(A_1\sqcup\cdots\sqcup A_n\) should make sense then, also written \(A_1+\cdots+A_n\).
  • So should \(\bigsqcup_{i:I} A_i\), or what is usually written \(\sum_{i:I} A_i\).
  • In the proposition-as-types mode, \[(\exists x:X)(P(x)) \longrightarrow \bigsqcup_{x:X}P(x)\equiv\sum_{x:X}P(x).\]

\(+\)-type  (use \(\sqcup\) if \(+\) is over used)

\[\frac{A_1,\ldots,A_n:type}{A_1+\cdots+A_n:type}(F_{+})\]

 

\[\frac{a_1:A_1}{\iota_1(a_1):A_1+\cdots+A_n}(I_{+}1)\cdots\]

\[\begin{array}{rl} x&:A_1+\cdots+A_n\\ f_1&:A_1\to B\\ \vdots &\\ f_n&:A_n\to B\\ \hline &(f_1+\cdots+f_n)(x):B\end{array}(E_{+})\]

\[\begin{array}{l}i:\{1,\ldots,n\}\vdash a_i:A_i\\ f_1: A_1\to B,\ldots,f_n:A_n\to B\\ \hline refl_{f(a_i)}: (f_1+\cdots+f_n)(\iota_i(a_i)) =_B f_i(a_i)\end{array}\]

\[\cdots\frac{a_n:A_n}{\iota_n(a_n):A_1+\cdots+A_n}(I_{+}n)\]

\((C_{+})\)

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

\(\Sigma\)-type  (use \(\sqcup\) if \(\Sigma\) is over used)

\[\begin{array}{rl}I &:type\\ A&:I\to type\\ \hline \sum_{i:I} A_i&:type\end{array}(F_{\Sigma})\]

 

\[\frac{i:I\vdash a_i:A_i}{\iota_i(a_i):\sum_{i:I}A_i}(I_{\Sigma})\]

\[\begin{array}{rl} x&:\sum_{i:I}A_i\\ f &: \prod_{i:I} (A_i\to B)\\[2pt] \hline (\Sigma f)(x)&:B\end{array}(E_{\Sigma})\]

\[\begin{array}{l}i:I \vdash a_i:A_i\\ f:\prod_{i:I} (A_i\to B)\\ \hline refl_{f(a_i)}: (\Sigma f)(\iota_i(a_i)) =_B f(a_i)\end{array}\]

\((C_{+})\)

Formation Rule

Introduction Rule

Elimination Rule

Computation Rule

Dependent types

By James Wilson

Dependent types

Dependent types are defined and their implications in propositions-as-types

  • 397