Programming Languages in String Diagrams [ one ] String Diagrams Paul-André Melliès Oregon Summer School in Programming Languages June 2011
String diagrams A diagrammatic account of logic and programming 2
Semantics in the 1980’s Cartesian-Closed Categories Intuitionistic λ -calculus Logic 3
Semantics in the 1990’s Monoidal-Closed Categories Linear Logic Proof-Nets 4
Where is the flow of logic? o Ideography (Frege) o Sequent calculus (Gentzen) o Natural deduction (Prawitz) o Proof nets (Girard) Looking for a purely mathematical notation for proofs... 5
Guide : the algebra of Feynman diagrams We want to see the flow inside our proofs and programs !
String Diagrams Categorical Algebra Logic and String Diagrams Language An algebraic investigation of logic and programming 7
String Diagrams Categorical Algebra Logic and String Diagrams Language A bridge between algebra, physics and low level languages 8
Compositionality in logic The reason for introducing categories 9
Sequent calculus of linear logic Axiom A ⊢ A Γ ⊢ A Υ 1 , A , Υ 2 ⊢ B Cut Υ 1 , Γ , Υ 2 ⊢ B Υ 1 , A , B , Υ 2 ⊢ C Left ⊗ Υ 1 , A ⊗ B , Υ 2 ⊢ C Γ ⊢ A ∆ ⊢ B Right ⊗ Γ , ∆ ⊢ A ⊗ B Γ ⊢ A Υ 1 , B , Υ 2 ⊢ C Left ⊸ Υ 1 , Γ , A ⊸ B , Υ 2 ⊢ C A , Γ ⊢ B Right ⊸ Γ ⊢ A ⊸ B 10
Modus Ponens If the property A is true and the property A B ⇒ is true, then the property B is true. 11
Modus ponens in the sequent calculus π 1 π 2 . . . . . . ⊢ A A ⊢ B Cut ⊢ B 12
Modus ponens in the type system π 1 π 2 . . . . . . ⊢ P : A x : A ⊢ M : B ⊢ ( λ x . M ) P : B 13
Modus Ponens If the property A B ⇒ is true and the property B C ⇒ is true, then the property A C ⇒ is true. 14
Modus ponens in the sequent calculus π 1 π 2 . . . . . . A ⊢ B B ⊢ C Cut A ⊢ C 15
Modus ponens in the type system π 1 π 2 . . . . . . x : A ⊢ P : B y : B ⊢ M : C x : A ⊢ ( λ y . M ) P : C 16
� The logical graph Its vertices are the logical formulas and its edges π A B are the logical proofs π . . . A ⊢ B 17
� � � Modus ponens in the logical graph Every pair of edges π 1 π 2 A B C induces an edge π 3 A C which may be denoted as π 3 = π 2 π 1 ◦ 18
� � � Associativity Given a path π 1 π 2 π 3 A B C D one would like that the order of composition does not matter: π 3 ◦ ( π 2 ◦ π 1 ) ( π 3 ◦ π 2 ) ◦ π 1 = 19
Associativity in the sequent calculus π 1 π 2 π 2 π 3 . . . . . . . . . . π 3 π 1 . . . . . . . . A ⊢ B B ⊢ C B ⊢ C C ⊢ D = A ⊢ C C ⊢ D A ⊢ B B ⊢ D A ⊢ D A ⊢ D 20
The identity proof Axiom A ⊢ A 21
� � � Identity Given id A id B π A A B B one would like that id A ◦ π π ◦ id B = π = 22
Identity in the sequent calculus π . . . Axiom A ⊢ A A ⊢ B Cut A ⊢ B is equal to π . . . A ⊢ B is equal to π . . . Axiom A ⊢ B B ⊢ B Cut A ⊢ B 23
� The logical graph (bis) Its vertices are the logical formulas and its edges π A B are the logical proofs π . . . A ⊢ B modulo symbolic execution . 24
Definition of a category A graph equipped with a composition operation f g g ◦ f � B � C � C A A �→ and an identity edge for every vertex of the graph id A � A A satisfying the associativity h ◦ ( g ◦ f ) ( h ◦ g ) ◦ f = and identity equations: id A ◦ f f f ◦ id B = = 25
What about the conjunction? Given two proofs π 1 π 2 . . . . . . A 1 ⊢ A 2 B 1 ⊢ B 2 one is able to construct the proof: π 1 π 2 . . . . . . A 1 ⊢ A 2 B 1 ⊢ B 2 Right ⊗ A 1 , B 1 ⊢ A 2 ⊗ B 2 Left ⊗ A 1 ⊗ B 1 ⊢ A 2 ⊗ B 2 26
� Tensor product So, every pair of edges π 1 π 1 � B 1 � B 2 A 1 A 2 induces an edge π 3 A 1 ⊗ A 2 B 1 ⊗ B 2 which may be denoted as π 3 = π 1 π 2 ⊗ 27
Monoidal Categories A monoidal category is a category C equipped with a functor: ⊗ : C × C −→ C an object: I and three natural transformations: α ( A ⊗ B ) ⊗ C A ⊗ ( B ⊗ C ) −→ ρ λ I ⊗ A A A ⊗ I A −→ −→ satisfying a series of coherence properties. 28
String Diagrams A notation by Roger Penrose 29
String Diagrams A morphism is depicted as: f : A ⊗ B ⊗ C −→ D ⊗ E D E f C A B 30
Composition f g The morphism A −→ C is depicted as −→ B C C g g ◦ f = B f A A A Vertical composition 31
Tensor product f g The morphism ( A −→ D ) is depicted as −→ B ) ⊗ ( C D B ⊗ D B f ⊗ g g = f C A ⊗ C A Horizontal tensor product 32
Example D B f D A f ⊗ id D 33
Example D B f g C A ( f ⊗ id D ) ◦ ( id A ⊗ g ) 34
Example D B g f C A ( id B ⊗ g ) ◦ ( f ⊗ id C ) 35
Meaning preserved by deformation D D B B g f = g f C C A A = ( f ⊗ id D ) ◦ ( id A ⊗ g ) ( id B ⊗ g ) ◦ ( f ⊗ id C ) 36
Application to knot theory A tensor algebra of knots 37
Braided categories A monoidal category equipped with braid maps γ − 1 γ A , B A , B A ⊗ B −→ B ⊗ A B ⊗ A −→ A ⊗ B B A A B B A A B 38
� � � � Coherence diagram for braids γ � ( B ⊗ C ) ⊗ A A ⊗ ( B ⊗ C ) α α ( A ⊗ B ) ⊗ C B ⊗ ( C ⊗ A ) B ⊗ γ γ ⊗ C α � B ⊗ ( A ⊗ C ) ( B ⊗ A ) ⊗ C 39
Topological deformation in string diagrams B C B C A A = A B C A B C 40
� � � � Coherence diagram for braids γ � C ⊗ ( A ⊗ B ) ( A ⊗ B ) ⊗ C α − 1 α − 1 A ⊗ ( B ⊗ C ) ( C ⊗ A ) ⊗ B γ ⊗ B A ⊗ γ α − 1 � ( A ⊗ C ) ⊗ B A ⊗ ( C ⊗ B ) 41
Topological deformation in string diagrams C A B C A B = A B C A B C 42
Duality A duality A ⊣ B is a pair of morphisms η ǫ B ⊗ A −→ I I −→ A ⊗ B A A ∗ ǫ A η A A ∗ A 43
Duality satisfying the two “zig-zag” equalities: A B B A = = A B A B In that case, A is called a left dual of B . 44
Ribbon category A braided category in which every object A has a dual A ∗ satisfying: A A A A ∗ A ∗ = = A ∗∗ A ∗∗ A ∗ A ∗ A A A 45
� � Knot invariants Every ribbon category D induces a knot invariant [ [ − ] ] free-ribbon ( C ) � D C The free ribbon category is a category of framed tangles 46
Jones polynomial invariant � x 4 + y 2 2 x 2 − x 4 + x 2 y 2 x 2 + 1 2 x 2 A compositional semantics of knots 47
Can we apply this to proofs and programs? The topic of the next session... 48
Monoidal categories with feedback A definition by Joyal, Street and Verity (1996) 49
Trace operator A trace in a symmetric monoidal category C is an operator A ⊗ U −→ B ⊗ U Tr U A , B A −→ B depicted as feedback in string diagrams: 50
Trace operator B B U ( ) Tr U U = f f A,B U A A 51
Sliding (naturality in U ) B B u V V = f f U U u A A 52
Tightening (naturality in A , B ) b b = f f a a 53
Vanishing (monoidality in U ) U U ⊗ V I V = = f f f f 54
Superposing f g = f g f g = 55
Yanking = = U U U 56
Fixpoint operator Given a map f : A ⊗ U U −→ we want to compute a map Fix [ f ] : A U −→ such that f ( a , Fix [ f ] ( a ) ) Fix [ f ] ( a ) = Enables to compute recursive definitions 57
Fixpoints computed from traces Suppose given a diagonal map U U ⊗ U −→ Then, U U ∆ Fix : �→ f U f A U A defines a well-behaved fixpoint operator. 58
Traces = parametric fixpoints (1) U ∆ U f A 59
Traces = parametric fixpoints (2) U f f U ∆ ∆ A 60
Traces = parametric fixpoints (3) U ∆ f U U f A ∆ A 61
Traces = parametric fixpoints (4) U f U A ∆ U f ∆ A 62
Traces = parametric fixpoints (5) U f ∆ U A f A ∆ A 63
Traces = parametric fixpoints (6) U f U ∆ ∆ U U = f f ∆ A A 64
Recommend
More recommend