Types of data

2020 James B. Wilson

Colorado State University

 

Over-arching objective

 

Minimal requirements to define abstract algebra as the substitution of values, operations, and equations in equational formulas.

Objectives

1. Understand ways to limit substitution to contexts.

2. Define Types of data:

  • Formation,
  • Introduction,
  • Elimination, and
  • Computation.

Unresolved Problems with Substitution

Suppose \(x\mapsto 2x\), then \[[x:=2](x\mapsto 2x)\qquad\rhd \qquad 22\]

(Said in short hand \(2\mapsto 22\).)

 

That cannot be what we mean normally; rather, when \(x:=2\) we expect this means \(2x:=2\times x\).

Suppose \(x\mapsto 2x\), then substituting :-\ for \(x\) yields

2:-\

 

Here it really is the correct use, because this substitution is trying to make a silly emoji into a silly emoji with awesome hair.

The point:

The type of data guides substitution.

 

\(x\) a natural number? then \(2x\) is multiplication.

\(x\) a string of letters? then \(2x\) is a new string beginning with the character 2.

Assumption

all data \(x\) has a (data) type \(X\) to go with it, we annotate \(x\) with this type,

 

Notation. write \(x\in X\) (usually for sets \(X\)) and \(x:X\) (for all other data, but also to include sets).

 

We are documenting how we plan to use \(x\).

  • \(5\in \mathbb{N}\) or \(5:\mathbb{N}\) or uint 5, or 5:Nat,.... 

  • \(-5\in \mathbb{Z}\) or \(-5:\mathbb{Z}\).  Notice \(-5\notin\mathbb{N}\), so \(\mathbb{N}\) is a different type of data then \(\mathbb{Z}\)

  • Even large things have a type, E.g. \(\mathbb{N}:Monoid\) whereas \(\mathbb{Z}:Group\).*

*For technical reasons we don't use \(\in\) but rather `:` for large things like this, see below.

Difference of \(\in\) and \(\colon\)

  • Russell's Paradox taught us that you cannot have single set of all sets that do not contain themselves.
  • Fact. Every set can be made into a monoid.
  • Fact. Every set can be made into a group.
  • Corollary.  There is no set of all monoids, there is no set of all groups.

 

Hence \(G:Group\) instead of set-notation \(G\in Group\).

Formation of \(\to\)

Given types \(X\) and \(Y\) can form a new type of data called functions denoted

\[X\to Y\]

 

First Order Examples

 

  • \(x\mapsto x^2\) can be treated as a function of type \(\mathbb{R}\to [0,\infty)\).  I.e. here \(X=\mathbb{R}\) and \(Y=[0,\infty)\).

  • \(f\mapsto \int_1^x f(t)\mathrm{d}t\) is a function of type \(\mathcal{C}[1,\infty)\to \mathbb{R}\) where \(X=C[1,\infty)\) is the type of all continuous functions \([1,\infty)\to \mathbb{R}\).
  • \(f(n)=n\cdot f(n-1)\) is a (recursive) function \(\mathbb{N}\to \mathbb{N}\), it is usually called the factorial function.

High Order Examples

 

  • \(G\mapsto |G|\) the function that computes the order of a finite group, has type \(Group\to \mathbb{N}\)

  • \(G\mapsto(H\mapsto G\times H)\) is a function of type \[Group\to (Group\to Group)\]
These are functions in our sense of substitutions but these are not between sets so they are not functions in that they are not defined by points (input,output).

Aside: Notation

\[\frac{Premises}{Conclusion}\]

\[\begin{array}{l} P\\ P\Rightarrow Q\\ \hline Q\end{array}\]

\[\begin{array}{l} \neg P\\ P\vee Q\\ \hline Q\end{array}\]

\[\begin{array}{l}  P \vdash Q\\ \hline P\Rightarrow Q\end{array}\]

\(\vdash\) (turnstile) "assertion",i.e. \(\vdash Q\) reads as "assert Q is true"

\(P\vdash Q\) reads "Assume P, assert Q"

Elimination Rule For \(\to\)

Given a function \(f\) of type \(X\to Y\) and \(x\) of type \(X\), then there is a term \(f(x)\) of type \(Y\).

 

\[\frac{x:X\qquad f:X\to Y}{f(x):Y}(E\to)\]

 

For sets \(X\) and \(Y\) and set-functions \(f:X\to Y\), \(f\) really means:

  • \(f\) is a subset \(\{(x,y)\mid x\in X, y\in Y\}\),
  • \((\forall x\in X)(\exists y\in Y)((x,y)\in f)\), and
  • \((x,y),(x,y')\in f\Rightarrow y=y'\).

Theorem (Church). Every Set-function \(f:X\to Y\) is a type-function of type \(X\to Y\).

Proof. Given \(x\in X\) (same as \(x:X\) for sets), and define  \(f(x)\) as the unique \(y\in Y\) where \((x,y)\in f\).  Hence, this model of a function up holds the rule

\[\frac{x:X\qquad f:X\to Y}{f(x):Y}(E\to).\]

\(\Box\)

Result

  • All set-functions are type-functions
  • Not all type-functions are set-functions.

Using elimination in a proof.

Prop. If \(f:X\to Y\) and \(g:Y\to Z\) then \[x:X\Rightarrow g(f(x)):Z.\]

Proof. \[\begin{array}{c}\begin{array}{c}x:X\qquad f:X\to Y\\ \hline f(x):Y \end{array}\qquad g:Y\to Z\\ \hline g(f(x)):Z\end{array}\]

\(\Box\)

Prop. If \(f:X\to Y\) and \(g:Y\to Z\) then

\[x:X\Rightarrow g(f(x)):Z.\]

 

Proof. Given \(x\) of type \(X\) and \(f\) of type \(X\to Y\), then by the elimination rule of \(\to\) we know \(f(x)\) has type \(Y\).  Furthermore, \(g\) has type \(Y\to Z\) so by eliminating \(\to\) again we have that \(g(f(x))\) has type \(Z\).  \(\Box\)

Same proof written in words...

Introduction of \(\to\)

Given a formula \(M\), with the property that \(x:X\) implies \([t:=x](t\mapsto M):Y\), then there is a function \(f:X\to Y\), i.e.

\[\frac{x:X \vdash (M[t:=x]):Y}{f_M:X\to Y}(I\to)\]

E.g. Set \(M=t/2\).  Then

\[\frac{n\in \mathbb{N} \vdash (M[t:=n])\in\mathbb{Q}}{f_M:\mathbb{N}\to \mathbb{Q}}(I\to)\]

Introduction of \(\to\)

\[\frac{x:X \vdash (M[t:=x]):Y}{f_M:X\to Y}(I\to)\]

 

E.g. For sets this is nothing new, e.g. take \(M=t/2\).  Then

\[\frac{n\in \mathbb{N} \vdash (M[t:=n])\in\mathbb{Q}}{f_M:\mathbb{N}\to \mathbb{Q}}(I\to)\]

I.e. \(t\mapsto t/2\) can become a function \(f:\mathbb{N}\to \mathbb{Q}\), because \(n/2\) is always rational. 

But cannot have type \(\mathbb{N}\to \mathbb{N}\) because for example \(n=1\) will produce \(1/2\) which is not of type \(\mathbb{N}\).

Note that we use \(\in\) here because we have sets.

Introduction of \(\to\)

\[\frac{x:X \vdash (M[t:=x]):Y}{f_M:X\to Y}(I\to)\]

 

E.g. For general data just use types, e.g. take \(M\equiv |t|\).  Then

\[\frac{G:Group \vdash |G|:\mathbb{N}\cup\{\infty\}}{f_M:Group\to \mathbb{N}\cup\{\infty\}}(I\to)\]

 

Introduction of \(\to\)

\[\frac{x:X \vdash (M[t:=x]):Y}{f_M:X\to Y}(I\to)\]

The same \(M\) can be a typed function many different ways:

E.g.1 \(M=x\times y\) 

\[\frac{m, n\in \mathbb{N} \vdash m\times n\in \mathbb{N}}{f_M:\mathbb{N}\to (\mathbb{N}\to \mathbb{N})}(I\to)\]

E.g.2 \(M=x\times y\) 

\[\frac{G:Group, H:Group \vdash G\times H:Group}{f_M:Group\to (Group\to Group)}(I\to)\]

 

Prop. If \(f:X\to Y\) and \(g:Y\to Z\) then \[x:X\Rightarrow g(f(x)):Z.\]

 

Corollary: There is a composition 

\[\frac{f:X\to Y, g:Y\to Z, x:X \vdash g(f(x)):Z }{g\circ f:X\to Z}(I\to)\]

Introductions are how you construct new data (in programming we call these "constructors")

I.e we form old data \(f,g\), we made new data \(g\circ f\), provided that data obey some rules.

Consider \(x\mapsto x+2\).

First introduce(construct) a typed function

\[\frac{n:\mathbb{N}\vdash (n+2)\in \mathbb{N}}{f_{x+2}:\mathbb{N}\to \mathbb{N}}(I\to)\]

We can therefore eliminate \(f_{x+2}\)

\[\frac{n:\mathbb{N}\quad f_{x+2}:\mathbb{N}\to \mathbb{N}}{f_{x+2}(n):\mathbb{N}}(E\to)\]

But what makes \(f_{x+2}(5)=5+2\)?  No connection yet.

Missing Cohesion

Computation* rule of \(\to\)

\[\frac{x:X\vdash M[t:=x]:Y}{f_{M}(x)=M[t:=x]}(C\to).\]

*One very small concern, notice the conclusion (bottom) is not data, nor a type, i.e. it is not written like \(a:A\).

To fix lets call \(x=y\) a type, the type of evidence of a claim (i.e. the type of proof we have).

The data of this type is the proof, e.g. The reflexive axiom is the proof that \(x=x\) so write \[refl:x=x\]

Computation* rule of \(\to\)

\[\frac{x:X\vdash M[t:=x]:Y}{refl:f_{M}(x)=M[t:=x]}(C\to).\]

Using "proofs as data" and "propositions as types" will take several more examples to master.

Typed Functions

  • Formation \[\frac{X,Y:type}{X\to Y:type}(F\to)\]
  • Introduction \[\frac{x:X\vdash M[t:=x]:Y}{f_M:X\to Y}(I\to)\]
  • Elimination \[\frac{x:X\quad f:X\to Y}{f(x):Y}(E\to)\]
  • Computation \[\frac{x:X\vdash M[t:=x]:Y}{refl:f_M(x)=M[t:=x]}(C\to)\]

Types of data

By James Wilson

Types of data

  • 510