Int makePoint :: Int → Int → Point makePoint x y = Point x y getX :: Point → Int getX (Point x y) = x getY :: Point → Int getY (Point x y) = y origin :: Point origin = makePoint 0 0 4
= Point Int Int makePoint :: Int → Int → Point makePoint x y = Point x y x : Int y : Int makePoint x y : Point (PointI) getX :: Point → Int getX (Point x y) = x p : Point getX p : Int (PointE1 ) getY :: Point → Int getY (Point x y) = y p : Point getY p : Int (PointE2 ) 5
: Point (PointI) a : A b : B ⟨a, b⟩ : A × B (×I) p : Point getX p : Int (PointE1 ) p : A × B fst p : A (×E1 ) p : Point getY p : Int (PointE2 ) p : A × B snd p : B (×E2 ) 6
: Int λx.x ∗ 3 : Int → Int (funI) [x : A] . . . b : B λx.b : A → B (→I) (abstraction) f : Int → Int 5 : Int f 5 : Int (funE) f : A → B x : A f x : B (→E) (application) 8
then if pigs ﬂy then it is dark outside. A = it is dark outside A ⊃ (B ⊃ A) B = pigs ﬂy Is this proposition true? A B B ⊃ A A ⊃ (B ⊃ A) false false true true false true false true true false true true true true true true This proposition is always true! 11
then if pigs ﬂy then it is dark outside. A = it is dark outside A ⊃ (B ⊃ A) B = pigs ﬂy Is this proposition true? A B B ⊃ A A ⊃ (B ⊃ A) 0 0 1 1 0 1 0 1 1 0 1 1 1 1 1 1 This proposition is always true! 12
{0, 1}, i.e. deﬁne an evaluation e : Atoms → {0, 1}. Given an evaluation, we extend it to propositions using the truth tables: & : {0, 1} × {0, 1} → {0, 1} ⊃: {0, 1} × {0, 1} → {0, 1} A B A&B 0 0 0 0 1 0 1 0 0 1 1 1 A B A ⊃ B 0 0 1 0 1 1 1 0 0 1 1 1 If for all evaluations, a proposition takes the value 1 then we say it is always true (a tautology). 13
Deals with the notion of provability ∙ Gives a method to manipulate the symbols from the logic (i.e, atoms, ⊃, &) in order to establish when a proposition is provable (a theorem) Completeness = syntax and semantics coincide Soundness = syntax implies semantics 14
connectives ∙ Rules for introducing and eliminating connectives ∙ Rules are of the form Assumptions Conclusion A B A&B (&I) A&B A (&E1 ) A&B B (&E2 ) [A] . . . B A ⊃ B (⊃I) A ⊃ B A B (⊃E) Does it look familiar? 15
Natural Deduction System a : A b : B ⟨a, b⟩ : A × B (×I) A B A&B (&I) p : A × B fst p : A (×E1 ) A&B A (&E1 ) p : A × B snd p : B (×E2 ) A&B B (&E2 ) [x : A] . . . b : B λx.n : A → B (→I) [A] . . . B A ⊃ B (⊃I) f : A → B x : A f x : B (→E) A ⊃ B A B (⊃E) Propositions are types! ♡ 16
inhabitation of type A proof of proposition A product type conjunction function type implication sum type disjunction void type (empty type) falsity unit type (singleton type) truth 19
B A ⊃ B (⊃I) A ⊃ B A B (⊃E) A B A&B (&I) A&B A (&E1 ) A&B B (&E2 ) A A ∨ B (∨I1 ) B A ∨ B (∨I2 ) A ∨ B A ⊃ C B ⊃ C C (∨E) ⊥ A (ex falso quodlibet) ¬¬A A (reductio ad absurdum) (¬A is an abbreviation for A ⊃⊥) 20
B A ⊃ B (⊃I) A ⊃ B A B (⊃E) A B A&B (&I) A&B A (&E1 ) A&B B (&E2 ) A A ∨ B (∨I1 ) B A ∨ B (∨I2 ) A ∨ B A ⊃ C B ⊃ C C (∨E) ⊥ A (ex falso quodlibet) (¬A is an abbreviation for A ⊃⊥) 21
of proof ∙ Useful because proofs are executable and produce examples ∙ The following equivalent propositions are unprovable in intuitionistic logic: ∙ double negation law: ¬¬A ⊃ A ∙ excluded middle law: A ∨ ¬A ∙ Pierce’s law: ((A ⊃ B) ⊃ A) ⊃ A ∙ There is no truth-values semantics for intuitionistic logic! It has alternative semantics (e.g., Kripke semantics) The original Curry-Howard correspondence is between Church’s simply typed and Gentzen’s natural deduction λ-calculus for intuitionistic logic. 22
proofs inhabitation of type A proof of proposition A product type conjunction function type implication sum type disjunction void type (empty type) falsity unit type (singleton type) truth dependent types quantiﬁers call/cc operator Peirce’s law monads a modal logic 23
of logic and computing as distinct ﬁelds ∙ Thinking from a different perspective can help you know what is possible/impossible ∙ Type systems should not be ad hoc piles of rules! 24
A, B, C, . . . ∙ Arrows: for any objects A and B, there is a set of arrows C(A, B) ∙ we denote f ∈ C(A, B) with f : A → B or A f −→ B ∙ Composition: for any arrows f : A → B and g : B → C there is an arrow g ◦ f : A → C A B C f g◦f g ∙ Identity: for any object A there is an arrow idA : A → A ∙ Axioms: for any arrows f : A → B, g : B → C, and h : C → D h ◦ (g ◦ f) = (h ◦ g) ◦ f f ◦ idA = f = idB ◦ f 28
∙ Objects: sets ∙ Arrows: functions ∙ Composition: composition of functions ∙ Identity: for each set A, the identity function idA : A → A, idA(a) = a ∙ Axioms: ✓ 29
such that ∙ M is a set ∙ + : M × M → M is associative (aka (a + b) + c = a + (b + c) for any a, b, c ∈ M) ∙ e ∈ M is an identity for + (aka e + a = a + e = a for any a ∈ M) Monoids are an amazingly powerful concept: ∙ They are behind basic arithmetics ∙ both addition and multiplication form a monoid ∙ They are ubiquitous in programming ∙ strings, lists, foldable data structures, . . . 30
∙ Objects: monoids ∙ Arrows: monoid morphisms (aka functions not messing with the monoid operation) ∙ Composition: composition of monoid morphisms ∙ Identity: for each object M, idM : M → M, idM(m) = m ∙ Axioms: ✓ 31
= ⟨M, +, e⟩ is a category with ∙ Objects: just one object □ ∙ Arrows: the elements of the set M (i.e, M(□, □) = M) ∙ Composition: the monoid operation + ∙ Identity: the monoid identity e ∙ Axioms: h ◦ (g ◦ f) = (h ◦ g) ◦ f f ◦ idA = f = idB ◦ f a + (b + c) = (a + b) + c a + e = a = e + a 32
object T is called terminal if for every object A there exists a unique arrow τA : A → T ∙ an object I is called initial if for every object A there exists a unique arrow ιA : I → A 33
example: A B A&B (&I) Γ ⊢ A Γ ⊢ B Γ ⊢ A&B (&I) Deduction from no assumptions Deduction from assumptions Γ Γ = ∅ (Deduction from truth) Let C be a category with a terminal object T. We have the following interpretations: ∙ Propositions as objects of C ∙ Truth as the terminal object T ∙ A proof of A as an arrow f : T → A ∙ A proof of A from assumptions B as an arrow f : B → A 34
C. We say that A π1 ←− A × B π2 −→ B is a product of A and B if for every A f ←− C g −→ B there exists a unique arrow ⟨f, g⟩ : C −→ A × B such that π1 ◦ ⟨f, g⟩ = f π2 ◦ ⟨f, g⟩ = g 35
a terminal object T and products. Let A, B be two objects in C. A A × B B T π1 π2 f g ⟨f,g⟩ f : T → A g : T → B ⟨f, g⟩ : T → A × B ⟨f, g⟩ : T → A × B π1 ◦ ⟨f, g⟩ : T → A ⟨f, g⟩ : T → A × B π2 ◦ ⟨f, g⟩ : T → B Does it look familiar? 37
Natural Ded. Syst. A Category∗ a : A b : B ⟨a, b⟩ : A × B (×I) A B A&B (&I) f : T → A g : T → B ⟨f, g⟩ : T → A × B p : A × B fst p : A (×E1 ) A&B A (&E1 ) ⟨f, g⟩ : T → A × B π1 ◦ ⟨f, g⟩ : T → A p : A × B snd p : B (×E2 ) A&B B (&E2 ) ⟨f, g⟩ : T → A × B π2 ◦ ⟨f, g⟩ : T → B * A category with a terminal object T and products 38
objects terms proofs arrows inhabitation of type A proof of proposition A arrow f : T → A function type implication ? product type conjunction product sum type disjunction coproduct void type (empty type) falsity initial object unit type (singleton type) truth terminal object T 39
A and B, we can form the set of functions A ⇒ B = Set(A, B) which is again a set! How can we axiomatise this situation? What can we do with it operationally? Apply functions to their arguments! That is, there is an arrow ApA,B : (A ⇒ B) × A → B ApA,B(f, a) = f(a) 40
× A → B, there is an unique arrow Λ(g) : C → (A ⇒ B) such that A ⇒ B (A ⇒ B) × A B C C × A ApA,B Λ(g) Λ(g)×idA g In Set, this is deﬁned by Λ(g)(c) = f where f : A → B with f(a) = g(c, a) This process of transforming a function of two arguments into a function with one argument is known as Currying. 41
a terminal object T and products. We say that C has exponentials if for any objects A and B, there are an object A ⇒ B and an arrow ApA,B : (A ⇒ B) × A → B such that for any arrow g : C × A → B, there is a unique arrow Λ(g) : C → (A ⇒ B) such that ApA,B ◦ (Λ(g) × idA) = g A ⇒ B (A ⇒ B) × A B C C × A ApA,B Λ(g) Λ(g)×idA g 42
T. A Typed λ-Calculus A Natural Ded. Syst. A CCC [x : A] . . . b : B λx.n : A → B (→I) [A] . . . B A ⊃ B (⊃I) g : T×A → B Λ(g) : T → (A ⇒ B) f : A → B x : A f x : B (→E) A ⊃ B A B (⊃E) f : T → (A ⇒ B) g : T → A ApA,B ◦ ⟨f, g⟩ : T → B A ⇒ B (A ⇒ B) × A B T T × A ApA,B Λ(g) Λ(g)×idA g B A ⇒ B (A ⇒ B) × A A T π1 π2 ApA,B f g ⟨f,g⟩ 44
Natural Ded. Syst. A CCC a : A b : B ⟨a, b⟩ : A × B (×I) A B A&B (&I) f : T → A g : T → B ⟨f, g⟩ : T → A × B p : A × B fst p : A (×E1 ) A&B A (&E1 ) ⟨f, g⟩ : T → A × B π1 ◦ ⟨f, g⟩ : T → A p : A × B snd p : B (×E2 ) A&B B (&E2 ) ⟨f, g⟩ : T → A × B π2 ◦ ⟨f, g⟩ : T → B [x : A] . . . b : B λx.n : A → B (→I) [A] . . . B A ⊃ B (⊃I) g : T×A → B Λ(g) : T → (A ⇒ B) f : A → B x : A f x : B (→E) A ⊃ B A B (⊃E) f : T → (A ⇒ B) g : T → A ApA,B ◦ ⟨f, g⟩ : T → B 45
objects terms proofs arrows inhabitation of type A proof of proposition A arrow f : T → A function type implication exponential product type conjunction product sum type disjunction coproduct void type (empty type) falsity initial object unit type (singleton type) truth terminal object T 46
secret to understanding the world https://www.ted.com/talks/roger_antonsen_math_is_the_hidden_secret_to_ understanding_the_world ∙ Samson Abramsky, Categories, Proofs and Processed Lecture III - The Curry-Howard-Lambek Correspondence http://www.math.helsinki.fi/logic/sellc-2010/course/LectureIII.pdf ∙ Philip Wadler, Propositions as Types https://homepages.inf.ed.ac.uk/wadler/papers/propositions-as-types/ propositions-as-types.pdf ∙ Dan Grossman, Lecture notes on The Curry-Howard Isomorphism https://courses.cs.washington.edu/courses/cse505/12au/lec12_6up.pdf 47