├── llncs ├── llncs.doc ├── llncs2e.zip ├── sprmindx.sty ├── remreset.sty ├── readme.txt ├── llncsdoc.sty ├── aliascnt.sty ├── history.txt └── llncs.dem ├── diagrams-latex.sty ├── type-matrices.pdf ├── talks ├── mpc-15 │ ├── images │ │ ├── dan.jpg │ │ ├── deriv-DFA.pdf │ │ ├── even-DFA.pdf │ │ ├── deriv-tree.pdf │ │ ├── diff-page1.pdf │ │ ├── dissect-DFA.pdf │ │ ├── example-DFA.pdf │ │ └── dissect-tree.pdf │ ├── diagrams-latex.sty │ ├── DiffTree.hs │ ├── Shake.hs │ ├── notes.org │ ├── Diagrams.hs │ ├── TypeMatricesDiagrams.hs │ └── type-matrices-mpc-15.lhs ├── wesleyan-s15 │ ├── images │ │ ├── dan.jpg │ │ ├── even-DFA.pdf │ │ ├── deriv-DFA.pdf │ │ ├── deriv-tree.pdf │ │ ├── diff-page1.pdf │ │ ├── dissect-DFA.pdf │ │ ├── dissect-tree.pdf │ │ └── example-DFA.pdf │ ├── Shake.hs │ ├── Temp.hs │ ├── notes.org │ ├── Diagrams.hs │ └── type-matrices-wesleyan-s15.tex └── williams-s15 │ ├── images │ ├── dan.jpg │ ├── even-DFA.pdf │ ├── deriv-DFA.pdf │ ├── deriv-tree.pdf │ ├── dissect-DFA.pdf │ ├── dissect-tree.pdf │ └── example-DFA.pdf │ ├── Shake.hs │ ├── Temp.hs │ ├── notes.org │ ├── Diagrams.hs │ └── type-matrices-williams-s15.tex ├── symbols ├── Clowns.hs ├── Dissect.hs └── Jokers.hs ├── .gitignore ├── llncs.tex ├── make.hs ├── agda ├── NSection2.agda └── NSection.agda ├── README.md ├── TypeMatricesDiagrams.hs ├── hs ├── TreeTrisect.hs ├── TypeDFA2.hs └── TypeDFA.hs └── type-matrices.bib /llncs/llncs.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/llncs/llncs.doc -------------------------------------------------------------------------------- /diagrams-latex.sty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/diagrams-latex.sty -------------------------------------------------------------------------------- /llncs/llncs2e.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/llncs/llncs2e.zip -------------------------------------------------------------------------------- /type-matrices.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/type-matrices.pdf -------------------------------------------------------------------------------- /talks/mpc-15/images/dan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/dan.jpg -------------------------------------------------------------------------------- /llncs/sprmindx.sty: -------------------------------------------------------------------------------- 1 | delim_0 "\\idxquad " 2 | delim_1 "\\idxquad " 3 | delim_2 "\\idxquad " 4 | delim_n ",\\," 5 | -------------------------------------------------------------------------------- /talks/mpc-15/diagrams-latex.sty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/diagrams-latex.sty -------------------------------------------------------------------------------- /talks/mpc-15/images/deriv-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/deriv-DFA.pdf -------------------------------------------------------------------------------- /talks/mpc-15/images/even-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/even-DFA.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/dan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/dan.jpg -------------------------------------------------------------------------------- /talks/williams-s15/images/dan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/williams-s15/images/dan.jpg -------------------------------------------------------------------------------- /talks/mpc-15/images/deriv-tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/deriv-tree.pdf -------------------------------------------------------------------------------- /talks/mpc-15/images/diff-page1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/diff-page1.pdf -------------------------------------------------------------------------------- /talks/mpc-15/images/dissect-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/dissect-DFA.pdf -------------------------------------------------------------------------------- /talks/mpc-15/images/example-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/example-DFA.pdf -------------------------------------------------------------------------------- /talks/mpc-15/images/dissect-tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/mpc-15/images/dissect-tree.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/even-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/even-DFA.pdf -------------------------------------------------------------------------------- /talks/williams-s15/images/even-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/williams-s15/images/even-DFA.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/deriv-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/deriv-DFA.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/deriv-tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/deriv-tree.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/diff-page1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/diff-page1.pdf -------------------------------------------------------------------------------- /talks/williams-s15/images/deriv-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/williams-s15/images/deriv-DFA.pdf -------------------------------------------------------------------------------- /talks/williams-s15/images/deriv-tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/williams-s15/images/deriv-tree.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/dissect-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/dissect-DFA.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/dissect-tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/dissect-tree.pdf -------------------------------------------------------------------------------- /talks/wesleyan-s15/images/example-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/wesleyan-s15/images/example-DFA.pdf -------------------------------------------------------------------------------- /talks/williams-s15/images/dissect-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/williams-s15/images/dissect-DFA.pdf -------------------------------------------------------------------------------- /talks/williams-s15/images/dissect-tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/williams-s15/images/dissect-tree.pdf -------------------------------------------------------------------------------- /talks/williams-s15/images/example-DFA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byorgey/type-matrices/HEAD/talks/williams-s15/images/example-DFA.pdf -------------------------------------------------------------------------------- /symbols/Clowns.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoMonomorphismRestriction #-} 2 | 3 | import Diagrams.Backend.Cairo.CmdLine 4 | import Diagrams.Prelude 5 | 6 | ht = 1.2 7 | clowns = strokeTrail $ fromOffsets [0.5 *^ unit_X, 0.5 ^& ht] 8 | 9 | main = defaultMain (clowns # frame 0.05) 10 | -------------------------------------------------------------------------------- /symbols/Dissect.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoMonomorphismRestriction #-} 2 | 3 | import Diagrams.Backend.Cairo.CmdLine 4 | import Diagrams.Prelude 5 | 6 | ht = 1.2 7 | dissect = triangle 1 # scaleToY ht # alignB <> vrule ht # alignB 8 | 9 | main = defaultMain (dissect # frame 0.05) 10 | -------------------------------------------------------------------------------- /symbols/Jokers.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE NoMonomorphismRestriction #-} 2 | 3 | import Diagrams.Backend.Cairo.CmdLine 4 | import Diagrams.Prelude 5 | 6 | ht = 1.2 7 | jokers = strokeTrail $ fromOffsets [0.5 *^ unitX, (-0.5) ^& ht] 8 | 9 | main = defaultMain (jokers # frame 0.05) 10 | -------------------------------------------------------------------------------- /talks/wesleyan-s15/Shake.hs: -------------------------------------------------------------------------------- 1 | import Development.Shake 2 | import Development.Shake.FilePath 3 | 4 | lhs2TeX, pdflatex, mklatex :: String 5 | lhs2TeX = "lhs2TeX" 6 | pdflatex = "pdflatex" 7 | mklatex = "mklatex" 8 | 9 | main :: IO () 10 | main = shake shakeOptions $ do 11 | 12 | want ["type-matrices-wesleyan-s15.pdf"] 13 | 14 | "*.pdf" *> \output -> do 15 | let input = replaceExtension output "tex" 16 | hsFiles <- getDirectoryFiles "" ["*.hs"] 17 | need (input : hsFiles) 18 | cmd pdflatex $ ["--enable-write18", input] 19 | -------------------------------------------------------------------------------- /talks/williams-s15/Shake.hs: -------------------------------------------------------------------------------- 1 | import Development.Shake 2 | import Development.Shake.FilePath 3 | 4 | lhs2TeX, pdflatex, mklatex :: String 5 | lhs2TeX = "lhs2TeX" 6 | pdflatex = "pdflatex" 7 | mklatex = "mklatex" 8 | 9 | main :: IO () 10 | main = shake shakeOptions $ do 11 | 12 | want ["type-matrices-williams-s15.pdf"] 13 | 14 | "*.pdf" *> \output -> do 15 | let input = replaceExtension output "tex" 16 | hsFiles <- getDirectoryFiles "" ["*.hs"] 17 | need (input : hsFiles) 18 | cmd pdflatex $ ["--enable-write18", input] 19 | -------------------------------------------------------------------------------- /talks/mpc-15/DiffTree.hs: -------------------------------------------------------------------------------- 1 | import Data.Tree 2 | import Diagrams.Backend.PGF.CmdLine 3 | import Diagrams.Prelude 4 | import TypeMatricesDiagrams 5 | 6 | t = Nothing ## 7 | [ Nothing ## 8 | [ Nothing ## 9 | leaves [ Just A, Just A ] 10 | , leaf $ Just A 11 | ] 12 | , Nothing ## 13 | [ Nothing ## 14 | [ leaf $ Just A 15 | , Nothing ## leaves [Just H, Just A] 16 | ] 17 | , Nothing ## leaves [Just A, Just A] 18 | ] 19 | ] 20 | where (##) = Node 21 | leaf x = Node x [] 22 | leaves = map leaf 23 | 24 | dia = renderT t # frame 0.5 25 | 26 | main = mainWith dia 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.bbl 3 | *.blg 4 | *-blx.bib 5 | *.dvi 6 | *.fdb_latexmk 7 | *.glg 8 | *.glo 9 | *.gls 10 | *.idx 11 | *.ilg 12 | *.ind 13 | *.ist 14 | *.lof 15 | *.log 16 | *.lot 17 | *.nav 18 | *.nlo 19 | *.out 20 | *.pdfsync 21 | *.ps 22 | *.snm 23 | *.synctex.gz 24 | *.toc 25 | *.vrb 26 | *.maf 27 | *.mtc 28 | *.mtc0 29 | *~ 30 | *.pdf 31 | *.ptb 32 | *.fls 33 | *.exe 34 | 35 | *.o 36 | *.hi 37 | make 38 | .shake.database 39 | .diagrams_cache 40 | diagrams/*.hs 41 | diagrams/*.eps 42 | TAGS 43 | *_flymake.* 44 | *.agdai 45 | 46 | .cabal-sandbox 47 | cabal.sandbox.config 48 | 49 | talks/wesleyan-s15/diagrams 50 | talks/mpc-15/diagrams 51 | 52 | type-matrices.tex 53 | type-matrices-mpc-15.tex -------------------------------------------------------------------------------- /talks/mpc-15/Shake.hs: -------------------------------------------------------------------------------- 1 | import Development.Shake 2 | import Development.Shake.FilePath 3 | 4 | lhs2TeX, pdflatex, mklatex :: String 5 | lhs2TeX = "lhs2TeX" 6 | pdflatex = "pdflatex" 7 | mklatex = "mklatex" 8 | 9 | main :: IO () 10 | main = shake shakeOptions $ do 11 | 12 | want ["type-matrices-mpc-15.pdf"] 13 | 14 | "*.tex" *> \output -> do 15 | let input = output -<.> "lhs" 16 | need [input] 17 | cmd lhs2TeX $ ["--poly", "-o", output, input] 18 | 19 | "*.pdf" *> \output -> do 20 | let input = replaceExtension output "tex" 21 | hsFiles <- getDirectoryFiles "" ["*.hs"] 22 | need (input : hsFiles) 23 | cmd pdflatex $ ["--enable-write18", input] 24 | -------------------------------------------------------------------------------- /talks/williams-s15/Temp.hs: -------------------------------------------------------------------------------- 1 | -- -*- compile-command: "cabal --sandbox-config-file=$HOME/src/diagrams/cabal.sandbox.config exec -- ghc --make Temp && ./Temp -o Temp.pdf -w 400 -h 400" -*- 2 | {-# LANGUAGE ExplicitForAll #-} 3 | {-# LANGUAGE FlexibleContexts #-} 4 | {-# LANGUAGE NoMonomorphismRestriction #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | 7 | import Diagrams.Backend.Cairo.CmdLine 8 | import Diagrams.Prelude 9 | 10 | import Data.List.Split 11 | import Diagrams 12 | 13 | elts = map node "abcd" 14 | eltSet = atop (roundedRect 6 6 0.5) . centerXY . vsep 1 . map (hsep 1) . chunksOf 2 $ elts 15 | 16 | ls = ["aa", "abd", "badcab"] 17 | lsD = vsep 1 (map drawList ls ++ [ellipsis # rotateBy (1/4)]) 18 | 19 | dia = [eltSet, arrowV (5 ^& 0), lsD] # map centerY # hsep 2 20 | main = defaultMain $ dia 21 | -------------------------------------------------------------------------------- /llncs.tex: -------------------------------------------------------------------------------- 1 | \documentclass{llncs} 2 | 3 | %\usepackage{graphicx} 4 | % 5 | \begin{document} 6 | 7 | 8 | \title{LaTeX Template for Your LNCS Paper} 9 | 10 | \author{Author 1, Author 2} 11 | 12 | \institute{Lab, University, Address} 13 | \maketitle 14 | 15 | \begin{abstract} 16 | 17 | Abstract is here. 18 | 19 | \end{abstract} 20 | 21 | \section{Introduction}\label{sec:Introduction} 22 | 23 | Introduction is here. 24 | 25 | \section{Other Sections}\label{sec:Others} 26 | 27 | Other sections are here. 28 | 29 | 30 | \section{Conclusion}\label{sec:Conclusion} 31 | 32 | Conclusions are here. 33 | 34 | \section*{Acknowledgments}\label{sec:Acknowledgments} 35 | 36 | Authors would like to thank YYYYY. 37 | 38 | \begin{thebibliography}{1} 39 | 40 | \bibitem{Einstein} 41 | A. Einstein, On the movement of small particles suspended in stationary liquids required by the molecular-kinetic theory of heat, Annalen der Physik 17, pp. 549-560, 1905. 42 | 43 | \end{thebibliography} 44 | 45 | \end{document} -------------------------------------------------------------------------------- /talks/wesleyan-s15/Temp.hs: -------------------------------------------------------------------------------- 1 | -- -*- compile-command: "cabal --sandbox-config-file=$HOME/src/diagrams-sandbox/cabal.sandbox.config exec -- ghc --make Temp && ./Temp -o Temp.pdf -w 400 -h 400 && open Temp.pdf" -*- 2 | {-# LANGUAGE ExplicitForAll #-} 3 | {-# LANGUAGE FlexibleContexts #-} 4 | {-# LANGUAGE NoMonomorphismRestriction #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | 7 | import Diagrams.Backend.Cairo.CmdLine 8 | import Diagrams.Prelude 9 | 10 | import Data.List.Split 11 | import Diagrams 12 | 13 | -- elts = map node "abcd" 14 | -- eltSet = atop (roundedRect 6 6 0.5) . centerXY . vsep 1 . map (hsep 1) . chunksOf 2 $ elts 15 | 16 | -- ls = ["aa", "abd", "badcab"] 17 | -- lsD = vsep 1 (map drawList ls ++ [ellipsis # rotateBy (1/4)]) 18 | 19 | -- dia = [eltSet, arrowV (5 ^& 0), lsD] # map centerY # hsep 2 20 | 21 | abstractTree label = text label # italic # translateX (-0.1) <> triangle 3 # scaleY 1.2 22 | 23 | dia = hsep 1 24 | [ abstractTree "∂F" 25 | , text "≅" 26 | , abstractTree "F" # withHole 27 | ] 28 | 29 | main = defaultMain $ dia 30 | -------------------------------------------------------------------------------- /make.hs: -------------------------------------------------------------------------------- 1 | import Development.Shake 2 | import Development.Shake.FilePath 3 | 4 | lhs2TeX, pdflatex, latexmk :: String 5 | lhs2TeX = "lhs2TeX" 6 | pdflatex = "pdflatex" 7 | latexmk = "latexmk" 8 | 9 | main :: IO () 10 | main = shake shakeOptions $ do 11 | 12 | want ["type-matrices.pdf"] 13 | 14 | "*.tex" %> \output -> do 15 | let input = replaceExtension output "lhs" 16 | need [input] 17 | cmd lhs2TeX $ ["-o", output] ++ [input] 18 | 19 | "*.pdf" %> \output -> do 20 | let input = replaceExtension output "tex" 21 | need [input, output -<.> "bib"] 22 | 23 | symbols <- getDirectoryFiles "" ["symbols/*.hs"] 24 | need (map (-<.> "pdf") symbols) 25 | 26 | need ["TypeMatricesDiagrams.hs"] 27 | 28 | () <- cmd pdflatex $ ["--enable-write18", input] 29 | cmd latexmk $ ["-pdf", input] 30 | 31 | "symbols/*.pdf" %> \output -> do 32 | let input = output -<.> "hs" 33 | need [input] 34 | () <- cmd "ghc" ["--make", input, "-o", input -<.> "exe"] 35 | cmd (input -<.> "exe") ["-h", "10", "-o", output] 36 | -------------------------------------------------------------------------------- /agda/NSection2.agda: -------------------------------------------------------------------------------- 1 | module NSection2 where 2 | 3 | -- open import Data.Empty 4 | -- open import Data.Unit 5 | -- open import Data.Sum hiding (map) 6 | -- open import Data.Product hiding (map) 7 | -- open import Data.Nat 8 | -- open import Data.Fin 9 | -- open import Data.Vec renaming (map to vecMap ; foldr to vecFoldr) 10 | 11 | -- open import Function 12 | 13 | -- open import Relation.Binary.PropositionalEquality hiding ( [_] ) 14 | 15 | open import Level 16 | open import Data.Unit 17 | open import Data.Product 18 | 19 | data Desc {ℓ : Level} : Set (suc ℓ) where 20 | arg : (A : Set) (d : A → Desc) → Desc 21 | rec : (r : Desc) → Desc 22 | con : (A : Set ℓ) → (r : Desc) → Desc 23 | ret : Desc 24 | 25 | infix 5 ⟦_⟧_ 26 | ⟦_⟧_ : {ℓ : Level} → Desc → Set ℓ → Set ℓ 27 | ⟦ arg A d ⟧ X = Σ[ a ∈ A ] ⟦ d a ⟧ X 28 | ⟦ rec d ⟧ X = X × ⟦ d ⟧ X 29 | ⟦ con A d ⟧ X = A × ⟦ d ⟧ X 30 | ⟦ ret ⟧ X = ⊤ 31 | 32 | data Fix (d : Desc) : Set where 33 | ⟨_⟩ : ⟦ d ⟧ (Fix d) → Fix d 34 | 35 | open import Data.Nat 36 | open import Data.Fin 37 | open import Function 38 | 39 | FD : ℕ → Desc 40 | FD n = arg (Fin 5) λ { zero {- Zero -} → ret 41 | ; (suc zero) {- K -} → con Set ret 42 | ; _ → ret } 43 | -------------------------------------------------------------------------------- /llncs/remreset.sty: -------------------------------------------------------------------------------- 1 | 2 | % remreset package 3 | %%%%%%%%%%%%%%%%%% 4 | 5 | % Copyright 1997 David carlisle 6 | % This file may be distributed under the terms of the LPPL. 7 | % See 00readme.txt for details. 8 | 9 | % 1997/09/28 David Carlisle 10 | 11 | % LaTeX includes a command \@addtoreset that is used to declare that 12 | % a counter should be reset every time a second counter is incremented. 13 | 14 | % For example the book class has a line 15 | % \@addtoreset{footnote}{chapter} 16 | % So that the footnote counter is reset each chapter. 17 | 18 | % If you wish to bas a new class on book, but without this counter 19 | % being reset, then standard LaTeX gives no simple mechanism to do 20 | % this. 21 | 22 | % This package defines |\@removefromreset| which just undoes the effect 23 | % of \@addtorest. So for example a class file may be defined by 24 | 25 | % \LoadClass{book} 26 | % \@removefromreset{footnote}{chapter} 27 | 28 | 29 | \def\@removefromreset#1#2{{% 30 | \expandafter\let\csname c@#1\endcsname\@removefromreset 31 | \def\@elt##1{% 32 | \expandafter\ifx\csname c@##1\endcsname\@removefromreset 33 | \else 34 | \noexpand\@elt{##1}% 35 | \fi}% 36 | \expandafter\xdef\csname cl@#2\endcsname{% 37 | \csname cl@#2\endcsname}}} 38 | 39 | 40 | -------------------------------------------------------------------------------- /llncs/readme.txt: -------------------------------------------------------------------------------- 1 | Dear LLNCS user, 2 | 3 | The files in this directory belong to the LaTeX2e package for 4 | Lecture Notes in Computer Science (LNCS) of Springer-Verlag. 5 | 6 | It consists of the following files: 7 | 8 | readme.txt this file 9 | 10 | history.txt the version history of the package 11 | 12 | llncs.cls the LaTeX2e document class 13 | 14 | llncs.dem the sample input file 15 | 16 | llncs.doc the documentation of the class (LaTeX source) 17 | llncsdoc.pdf the documentation of the class (PDF version) 18 | llncsdoc.sty the modification of the class for the documentation 19 | llncs.ind an external (faked) author index file 20 | subjidx.ind subject index demo from the Springer book package 21 | llncs.dvi the resultig DVI file (remember to use binary transfer!) 22 | 23 | sprmindx.sty supplementary style file for MakeIndex 24 | (usage: makeindex -s sprmindx.sty ) 25 | 26 | splncs03.bst current LNCS BibTeX style with aphabetic sorting 27 | 28 | aliascnt.sty part of the Oberdiek bundle; allows more control over 29 | the counters associated to any numbered item 30 | remreset.sty by David Carlisle 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Polynomial Functors Constrained by Regular Expressions 2 | ====================================================== 3 | 4 | *Dan Piponi and Brent A. Yorgey* 5 | 6 | This work was published in the Conference on the Mathematics of 7 | Program Construction (MPC) 2015. 8 | 9 | Abstract 10 | -------- 11 | 12 | We show that every regular language, via some DFA which accepts it, 13 | gives rise to a homomorphism from the semiring of polynomial functors 14 | to the semiring of $n \times n$ matrices over polynomial functors. 15 | Given some polynomial functor and a regular language, this 16 | homomorphism can be used to automatically derive a functor whose 17 | values have the same shape as those of the original functor, but whose 18 | sequences of leaf types correspond to strings in the language. 19 | 20 | The primary interest of this result lies in the fact that certain 21 | regular languages correspond to previously studied derivative-like 22 | operations on polynomial functors, which have proven useful in program 23 | construction. For example, the regular language $a^*ha^*$ yields the 24 | \emph{derivative} of a polynomial functor, and $b^*ha^*$ its 25 | \emph{dissection}. Using our framework, we are able to unify and lend 26 | new perspective on this previous work. For example, it turns out that 27 | dissection of polynomial functors corresponds to taking \emph{divided 28 | differences} of real or complex functions, and, guided by this 29 | parallel, we show how to generalize binary dissection to $n$-ary 30 | dissection. 31 | -------------------------------------------------------------------------------- /llncs/llncsdoc.sty: -------------------------------------------------------------------------------- 1 | % This is LLNCSDOC.STY the modification of the 2 | % LLNCS class file for the documentation of 3 | % the class itself. 4 | % 5 | \def\AmS{{\protect\usefont{OMS}{cmsy}{m}{n}% 6 | A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}} 7 | \def\AmSTeX{{\protect\AmS-\protect\TeX}} 8 | % 9 | \def\ps@myheadings{\let\@mkboth\@gobbletwo 10 | \def\@oddhead{\hbox{}\hfil\small\rm\rightmark 11 | \qquad\thepage}% 12 | \def\@oddfoot{}\def\@evenhead{\small\rm\thepage\qquad 13 | \leftmark\hfil}% 14 | \def\@evenfoot{}\def\sectionmark##1{}\def\subsectionmark##1{}} 15 | \ps@myheadings 16 | % 17 | \setcounter{tocdepth}{2} 18 | % 19 | \renewcommand{\labelitemi}{--} 20 | \newenvironment{alpherate}% 21 | {\renewcommand{\labelenumi}{\alph{enumi})}\begin{enumerate}}% 22 | {\end{enumerate}\renewcommand{\labelenumi}{enumi}} 23 | % 24 | \def\bibauthoryear{\begingroup 25 | \def\thebibliography##1{\section*{References}% 26 | \small\list{}{\settowidth\labelwidth{}\leftmargin\parindent 27 | \itemindent=-\parindent 28 | \labelsep=\z@ 29 | \usecounter{enumi}}% 30 | \def\newblock{\hskip .11em plus .33em minus -.07em}% 31 | \sloppy 32 | \sfcode`\.=1000\relax}% 33 | \def\@cite##1{##1}% 34 | \def\@lbibitem[##1]##2{\item[]\if@filesw 35 | {\def\protect####1{\string ####1\space}\immediate 36 | \write\@auxout{\string\bibcite{##2}{##1}}}\fi\ignorespaces}% 37 | \begin{thebibliography}{} 38 | \bibitem[1982]{clar:eke3} Clarke, F., Ekeland, I.: Nonlinear 39 | oscillations and boundary-value problems for Hamiltonian systems. 40 | Arch. Rat. Mech. Anal. 78, 315--333 (1982) 41 | \end{thebibliography} 42 | \endgroup} 43 | -------------------------------------------------------------------------------- /talks/mpc-15/notes.org: -------------------------------------------------------------------------------- 1 | Basic idea is to base it on the paper Dan P. and I just submitted. 2 | End goal: get them to understand way of constructing 3 | regular-expression-constrained types? 4 | 5 | Title: Polynomial Functors Constrained by Regular Expressions 6 | 7 | Abstract: Polynomial functors, also known as algebraic data 8 | types, are a well-studied class of combinatorial families that 9 | are foundational in strongly typed functional programming. In 10 | the first half of the talk I will explain polynomial functors, 11 | what it means to constrain them by regular expressions, and why 12 | anyone---particularly programmers---might want to. Along the way, 13 | surprise appearances will be made by semirings and derivatives. 14 | In the second part of the talk I will show how to compute 15 | constrained polynomial functors via an appropriate semiring 16 | homomorphism. No particular background is assumed; my goal is 17 | to convey not a particular result per se, but rather an 18 | appreciation for some of the beautiful overlap between algebra, 19 | combinatorics, calculus, and computer science. 20 | 21 | Outline 22 | 23 | Preface: please ask questions. Part of the interesting 24 | challenge is to translate results & ideas; different terminology 25 | and points of view. 26 | 27 | Part I: algebraic data types 28 | 29 | - algebraic data types, aka combinatorial families 30 | - mention semirings --- algebraic data types form one up to iso 31 | - derivatives of algebraic data types 32 | 33 | Part II: regular expressions and DFAs 34 | 35 | - regular expressions 36 | - DFAs 37 | - transition matrices for DFAs, with semirings 38 | 39 | Part III: mix well 40 | 41 | - idea: constrain an ADT by regular expression 42 | - express derivative via regular expression 43 | - related notions: e.g. dissection (divided difference -- don't 44 | go into detail) 45 | - show homomorphism to semiring of matrices. 46 | -------------------------------------------------------------------------------- /talks/wesleyan-s15/notes.org: -------------------------------------------------------------------------------- 1 | Basic idea is to base it on the paper Dan P. and I just submitted. 2 | End goal: get them to understand way of constructing 3 | regular-expression-constrained types? 4 | 5 | Title: Polynomial Functors Constrained by Regular Expressions 6 | 7 | Abstract: Polynomial functors, also known as algebraic data 8 | types, are a well-studied class of combinatorial families that 9 | are foundational in strongly typed functional programming. In 10 | the first half of the talk I will explain polynomial functors, 11 | what it means to constrain them by regular expressions, and why 12 | anyone---particularly programmers---might want to. Along the way, 13 | surprise appearances will be made by semirings and derivatives. 14 | In the second part of the talk I will show how to compute 15 | constrained polynomial functors via an appropriate semiring 16 | homomorphism. No particular background is assumed; my goal is 17 | to convey not a particular result per se, but rather an 18 | appreciation for some of the beautiful overlap between algebra, 19 | combinatorics, calculus, and computer science. 20 | 21 | Outline 22 | 23 | Preface: please ask questions. Part of the interesting 24 | challenge is to translate results & ideas; different terminology 25 | and points of view. 26 | 27 | Part I: algebraic data types 28 | 29 | - algebraic data types, aka combinatorial families 30 | - mention semirings --- algebraic data types form one up to iso 31 | - derivatives of algebraic data types 32 | 33 | Part II: regular expressions and DFAs 34 | 35 | - regular expressions 36 | - DFAs 37 | - transition matrices for DFAs, with semirings 38 | 39 | Part III: mix well 40 | 41 | - idea: constrain an ADT by regular expression 42 | - express derivative via regular expression 43 | - related notions: e.g. dissection (divided difference -- don't 44 | go into detail) 45 | - show homomorphism to semiring of matrices. 46 | -------------------------------------------------------------------------------- /talks/williams-s15/notes.org: -------------------------------------------------------------------------------- 1 | Basic idea is to base it on the paper Dan P. and I just submitted. 2 | End goal: get them to understand way of constructing 3 | regular-expression-constrained types? 4 | 5 | Title: Polynomial Functors Constrained by Regular Expressions 6 | 7 | Abstract: Polynomial functors, also known as algebraic data 8 | types, are a well-studied class of combinatorial families that 9 | are foundational in strongly typed functional programming. In 10 | the first half of the talk I will explain polynomial functors, 11 | what it means to constrain them by regular expressions, and why 12 | anyone---particularly programmers---might want to. Along the way, 13 | surprise appearances will be made by semirings and derivatives. 14 | In the second part of the talk I will show how to compute 15 | constrained polynomial functors via an appropriate semiring 16 | homomorphism. No particular background is assumed; my goal is 17 | to convey not a particular result per se, but rather an 18 | appreciation for some of the beautiful overlap between algebra, 19 | combinatorics, calculus, and computer science. 20 | 21 | Outline 22 | 23 | Preface: please ask questions. Part of the interesting 24 | challenge is to translate results & ideas; different terminology 25 | and points of view. 26 | 27 | Part I: algebraic data types 28 | 29 | - algebraic data types, aka combinatorial families 30 | - mention semirings --- algebraic data types form one up to iso 31 | - derivatives of algebraic data types 32 | 33 | Part II: regular expressions and DFAs 34 | 35 | - regular expressions 36 | - DFAs 37 | - transition matrices for DFAs, with semirings 38 | 39 | Part III: mix well 40 | 41 | - idea: constrain an ADT by regular expression 42 | - express derivative via regular expression 43 | - related notions: e.g. dissection (divided difference -- don't 44 | go into detail) 45 | - show homomorphism to semiring of matrices. 46 | -------------------------------------------------------------------------------- /talks/mpc-15/Diagrams.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE LambdaCase #-} 4 | {-# LANGUAGE NoMonomorphismRestriction #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | 7 | module Diagrams where 8 | 9 | import Diagrams.Prelude 10 | import Diagrams.TwoD.Layout.Tree 11 | import Diagrams.TwoD.Text 12 | 13 | data NodeType a = Nil | Value a | Hole 14 | 15 | nodeType :: b -> (a -> b) -> b -> NodeType a -> b 16 | nodeType n _ _ Nil = n 17 | nodeType _ f _ (Value a) = f a 18 | nodeType _ _ h Hole = h 19 | 20 | trees :: [BTree Int] 21 | trees = 22 | [ Empty 23 | , leaf 3 24 | , BNode 7 (leaf 2) Empty 25 | , BNode 4 (leaf 17) (BNode 3 (leaf 6) Empty) 26 | ] 27 | 28 | poke :: Eq a => a -> BTree a -> BTree (NodeType a) 29 | poke a = fmap (\case { Value a' | a == a' -> Hole ; n -> n }) . toNTree 30 | 31 | toNTree :: BTree a -> BTree (NodeType a) 32 | toNTree Empty = leaf Nil 33 | toNTree (BNode a l r) = BNode (Value a) (toNTree l) (toNTree r) 34 | 35 | nil = square 0.4 # fc black 36 | node = ((<> circle 1 # fc lightblue) . text . showElt) 37 | hole = circle 1 # dashingG [0.1,0.1] 0 # fc white 38 | renderNode = nodeType nil node hole 39 | 40 | class Elt e where 41 | showElt :: e -> String 42 | 43 | instance Elt Char where 44 | showElt = (:[]) 45 | 46 | instance Elt [Char] where 47 | showElt = id 48 | 49 | instance Elt Int where 50 | showElt = show 51 | 52 | -- drawNTree :: ( V b ~ V2, Ord (N b), TypeableFloat (N b) 53 | -- , Renderable (Path V2 (N b)) b 54 | -- , Renderable (Text (N b)) b 55 | -- , Show a) 56 | -- => BTree (Maybe a) -> Diagram b 57 | drawNTree = 58 | maybe mempty (renderTree renderNode (~~)) 59 | . symmLayoutBin' (with & slVSep .~ 3 & slHSep .~ 3) 60 | 61 | drawTree = drawNTree . toNTree 62 | 63 | ellipsis = hsep 0.5 $ replicate 3 dot 64 | where 65 | dot = circle 0.3 # fc black 66 | 67 | drawNList l = nodes # 68 | (withNames [0 :: Int, length l - 1 :: Int] $ \[s,e] -> 69 | beneath (location s ~~ location e) 70 | ) 71 | where 72 | nodes = 73 | hsep s 74 | (zipWith (\i n -> renderNode n # named i) [0 :: Int ..] l) 75 | s = 1 76 | 77 | drawList l = drawNList (map Value l ++ [Nil]) 78 | 79 | ls = [[1::Int,1], [1,2,4], [2,1,4,3,1,2]] 80 | drawLists ls = vsep 1 (map drawList ls ++ [ellipsis # rotateBy (1/4)]) 81 | lsD = drawLists ls 82 | -------------------------------------------------------------------------------- /talks/williams-s15/Diagrams.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE LambdaCase #-} 4 | {-# LANGUAGE NoMonomorphismRestriction #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | 7 | module Diagrams where 8 | 9 | import Diagrams.Prelude 10 | import Diagrams.TwoD.Layout.Tree 11 | import Diagrams.TwoD.Text 12 | 13 | data NodeType a = Nil | Value a | Hole 14 | 15 | nodeType :: b -> (a -> b) -> b -> NodeType a -> b 16 | nodeType n _ _ Nil = n 17 | nodeType _ f _ (Value a) = f a 18 | nodeType _ _ h Hole = h 19 | 20 | trees :: [BTree Int] 21 | trees = 22 | [ Empty 23 | , leaf 3 24 | , BNode 7 (leaf 2) Empty 25 | , BNode 4 (leaf 17) (BNode 3 (leaf (-6)) Empty) 26 | ] 27 | 28 | poke :: Eq a => a -> BTree a -> BTree (NodeType a) 29 | poke a = fmap (\case { Value a' | a == a' -> Hole ; n -> n }) . toNTree 30 | 31 | toNTree :: BTree a -> BTree (NodeType a) 32 | toNTree Empty = leaf Nil 33 | toNTree (BNode a l r) = BNode (Value a) (toNTree l) (toNTree r) 34 | 35 | nil = square 0.4 # fc black 36 | node = ((<> circle 1 # fc lightblue) . text . showElt) 37 | hole = circle 1 # dashingG [0.1,0.1] 0 # fc white 38 | renderNode = nodeType nil node hole 39 | 40 | class Elt e where 41 | showElt :: e -> String 42 | 43 | instance Elt Char where 44 | showElt = (:[]) 45 | 46 | instance Elt [Char] where 47 | showElt = id 48 | 49 | instance Elt Int where 50 | showElt = show 51 | 52 | -- drawNTree :: ( V b ~ V2, Ord (N b), TypeableFloat (N b) 53 | -- , Renderable (Path V2 (N b)) b 54 | -- , Renderable (Text (N b)) b 55 | -- , Show a) 56 | -- => BTree (Maybe a) -> Diagram b 57 | drawNTree = 58 | maybe mempty (renderTree renderNode (~~)) 59 | . symmLayoutBin' (with & slVSep .~ 3 & slHSep .~ 3) 60 | where 61 | 62 | drawTree = drawNTree . toNTree 63 | 64 | ellipsis = hsep 0.5 $ replicate 3 dot 65 | where 66 | dot = circle 0.3 # fc black 67 | 68 | drawNList l = nodes # 69 | (withNames [0 :: Int, length l - 1 :: Int] $ \[s,e] -> 70 | beneath (location s ~~ location e) 71 | ) 72 | where 73 | nodes = 74 | hsep s 75 | (zipWith (\i n -> renderNode n # named i) [0 :: Int ..] l) 76 | s = 1 77 | 78 | drawList l = drawNList (map Value l ++ [Nil]) 79 | 80 | ls = [[1::Int,1], [1,2,4], [2,1,4,3,1,2]] 81 | drawLists ls = vsep 1 (map drawList ls ++ [ellipsis # rotateBy (1/4)]) 82 | lsD = drawLists ls 83 | -------------------------------------------------------------------------------- /talks/wesleyan-s15/Diagrams.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE LambdaCase #-} 4 | {-# LANGUAGE NoMonomorphismRestriction #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | 7 | module Diagrams where 8 | 9 | import Diagrams.Prelude 10 | import Diagrams.TwoD.Layout.Tree 11 | import Diagrams.TwoD.Text 12 | 13 | data NodeType a = Nil | Value a | Hole 14 | 15 | nodeType :: b -> (a -> b) -> b -> NodeType a -> b 16 | nodeType n _ _ Nil = n 17 | nodeType _ f _ (Value a) = f a 18 | nodeType _ _ h Hole = h 19 | 20 | trees :: [BTree Int] 21 | trees = 22 | [ Empty 23 | , leaf 3 24 | , BNode 7 (leaf 2) Empty 25 | , BNode 4 (leaf 17) (BNode 3 (leaf 6) Empty) 26 | ] 27 | 28 | poke :: Eq a => a -> BTree a -> BTree (NodeType a) 29 | poke a = fmap (\case { Value a' | a == a' -> Hole ; n -> n }) . toNTree 30 | 31 | toNTree :: BTree a -> BTree (NodeType a) 32 | toNTree Empty = leaf Nil 33 | toNTree (BNode a l r) = BNode (Value a) (toNTree l) (toNTree r) 34 | 35 | nil = square 0.4 # fc black 36 | node = ((<> circle 1 # fc lightblue) . text . showElt) 37 | hole = circle 1 # dashingG [0.1,0.1] 0 # fc white 38 | renderNode = nodeType nil node hole 39 | 40 | class Elt e where 41 | showElt :: e -> String 42 | 43 | instance Elt Char where 44 | showElt = (:[]) 45 | 46 | instance Elt [Char] where 47 | showElt = id 48 | 49 | instance Elt Int where 50 | showElt = show 51 | 52 | -- drawNTree :: ( V b ~ V2, Ord (N b), TypeableFloat (N b) 53 | -- , Renderable (Path V2 (N b)) b 54 | -- , Renderable (Text (N b)) b 55 | -- , Show a) 56 | -- => BTree (Maybe a) -> Diagram b 57 | drawNTree = 58 | maybe mempty (renderTree renderNode (~~)) 59 | . symmLayoutBin' (with & slVSep .~ 3 & slHSep .~ 3) 60 | where 61 | 62 | drawTree = drawNTree . toNTree 63 | 64 | ellipsis = hsep 0.5 $ replicate 3 dot 65 | where 66 | dot = circle 0.3 # fc black 67 | 68 | drawNList l = nodes # 69 | (withNames [0 :: Int, length l - 1 :: Int] $ \[s,e] -> 70 | beneath (location s ~~ location e) 71 | ) 72 | where 73 | nodes = 74 | hsep s 75 | (zipWith (\i n -> renderNode n # named i) [0 :: Int ..] l) 76 | s = 1 77 | 78 | drawList l = drawNList (map Value l ++ [Nil]) 79 | 80 | ls = [[], [1::Int,1], [1,2,4], [2,1,4,3,1,2]] 81 | drawLists ls = vsep 1 (map drawList ls ++ [ellipsis # rotateBy (1/4)]) 82 | lsD = drawLists ls 83 | 84 | abstractTree = abstractTree' 1 85 | abstractTree' sz label = text label # scale sz # italic # translateX (-0.1) <> triangle 3 # scaleY 1.2 86 | 87 | withHole = atop (hole # scale 0.3 # translate (0.6 ^& (-0.5))) 88 | -------------------------------------------------------------------------------- /llncs/aliascnt.sty: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `aliascnt.sty', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% aliascnt.dtx (with options: `package') 8 | %% 9 | %% This is a generated file. 10 | %% 11 | %% Project: aliascnt 12 | %% Version: 2009/09/08 v1.3 13 | %% 14 | %% Copyright (C) 2006, 2009 by 15 | %% Heiko Oberdiek 16 | %% 17 | %% This work may be distributed and/or modified under the 18 | %% conditions of the LaTeX Project Public License, either 19 | %% version 1.3c of this license or (at your option) any later 20 | %% version. This version of this license is in 21 | %% http://www.latex-project.org/lppl/lppl-1-3c.txt 22 | %% and the latest version of this license is in 23 | %% http://www.latex-project.org/lppl.txt 24 | %% and version 1.3 or later is part of all distributions of 25 | %% LaTeX version 2005/12/01 or later. 26 | %% 27 | %% This work has the LPPL maintenance status "maintained". 28 | %% 29 | %% This Current Maintainer of this work is Heiko Oberdiek. 30 | %% 31 | %% This work consists of the main source file aliascnt.dtx 32 | %% and the derived files 33 | %% aliascnt.sty, aliascnt.pdf, aliascnt.ins, aliascnt.drv. 34 | %% 35 | \NeedsTeXFormat{LaTeX2e} 36 | \ProvidesPackage{aliascnt}% 37 | [2009/09/08 v1.3 Alias counter (HO)]% 38 | \newcommand*{\newaliascnt}[2]{% 39 | \begingroup 40 | \def\AC@glet##1{% 41 | \global\expandafter\let\csname##1#1\expandafter\endcsname 42 | \csname##1#2\endcsname 43 | }% 44 | \@ifundefined{c@#2}{% 45 | \@nocounterr{#2}% 46 | }{% 47 | \expandafter\@ifdefinable\csname c@#1\endcsname{% 48 | \AC@glet{c@}% 49 | \AC@glet{the}% 50 | \AC@glet{theH}% 51 | \AC@glet{p@}% 52 | \expandafter\gdef\csname AC@cnt@#1\endcsname{#2}% 53 | \expandafter\gdef\csname cl@#1\expandafter\endcsname 54 | \expandafter{\csname cl@#2\endcsname}% 55 | }% 56 | }% 57 | \endgroup 58 | } 59 | \newcommand*{\aliascntresetthe}[1]{% 60 | \@ifundefined{AC@cnt@#1}{% 61 | \PackageError{aliascnt}{% 62 | `#1' is not an alias counter% 63 | }\@ehc 64 | }{% 65 | \expandafter\let\csname the#1\expandafter\endcsname 66 | \csname the\csname AC@cnt@#1\endcsname\endcsname 67 | }% 68 | } 69 | \newcommand*{\AC@findrootcnt}[1]{% 70 | \@ifundefined{AC@cnt@#1}{% 71 | #1% 72 | }{% 73 | \expandafter\AC@findrootcnt\csname AC@cnt@#1\endcsname 74 | }% 75 | } 76 | \def\AC@patch#1{% 77 | \expandafter\let\csname AC@org@#1reset\expandafter\endcsname 78 | \csname @#1reset\endcsname 79 | \expandafter\def\csname @#1reset\endcsname##1##2{% 80 | \csname AC@org@#1reset\endcsname{##1}{\AC@findrootcnt{##2}}% 81 | }% 82 | } 83 | \RequirePackage{remreset} 84 | \AC@patch{addto} 85 | \AC@patch{removefrom} 86 | \endinput 87 | %% 88 | %% End of file `aliascnt.sty'. 89 | -------------------------------------------------------------------------------- /TypeMatricesDiagrams.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE MultiParamTypeClasses #-} 4 | {-# LANGUAGE NoMonomorphismRestriction #-} 5 | {-# LANGUAGE TypeSynonymInstances #-} 6 | 7 | module TypeMatricesDiagrams where 8 | 9 | import qualified Data.Map as M 10 | import Data.Maybe (fromMaybe) 11 | import Data.Tree 12 | import Diagrams.Backend.Cairo 13 | import Diagrams.Core.Envelope 14 | import Diagrams.Prelude 15 | import Diagrams.TwoD.Layout.Tree 16 | import Diagrams.TwoD.Text 17 | import Linear.V2 (perp) 18 | 19 | type Dia = QDiagram Cairo V2 Double Any 20 | 21 | data Type = A | B | H 22 | 23 | drawType A = text "a" # italic # centerX <> square 2 # fc yellow 24 | drawType B = text "b" # italic # centerX <> circle 1 # fc red 25 | drawType H = text "h" # italic # centerX <> circle 1 # fc white # dashingG [0.2,0.2] 0 26 | 27 | renderT :: Tree (Maybe Type) -> Diagram B 28 | renderT 29 | = renderTree 30 | (\x -> case x of 31 | Nothing -> mempty 32 | Just t -> drawType t 33 | ) 34 | (~~) 35 | . symmLayout' (with & slHSep .~ 4 & slVSep .~ 3) 36 | 37 | arcArrow :: P2 Double -> P2 Double -> Double -> Double -> Diagram B -> Diagram B 38 | arcArrow p1 p2 ht offs label 39 | = aDia 40 | <> label 41 | # moveTo (lerp 0.5 p1 p2 .+^ (signum ht *^ ((h + envelopeS ((-signum ht) *^ perp v) label) *^ signorm (perp v)))) 42 | where 43 | h = abs ht 44 | straight = h < 0.00001 45 | v = p2 .-. p1 46 | d = norm (p2 .-. p1) 47 | th = acos ((d*d - 4*h*h)/(d*d + 4*h*h)) 48 | r = d/(2*sin th) 49 | phi | straight = 0 @@ rad 50 | | otherwise = (offs/r) @@ rad 51 | mid | ht >= 0 = (tau/4) @@ rad 52 | | otherwise = (3*tau/4) @@ rad 53 | st = mid ^-^ (th @@ rad) ^+^ phi 54 | end = mid ^+^ (th @@ rad) ^-^ phi 55 | a | straight 56 | = hrule (d - 2*offs) # alignL # translateX offs 57 | | otherwise 58 | = arc (xDir # rotate st) (end ^-^ st) 59 | # scale r 60 | # translateY ((if ht > 0 then negate else id) (r-h)) 61 | # translateX (d/2) 62 | # (if ht > 0 then reversePath else id) 63 | endPt = atEnd . head . pathTrails $ a 64 | hd = triangle 0.4 # rotateBy (-1/4) # alignR # fc black # scaleY 0.7 65 | # rotate (if ht >= 0 then st ^-^ ((tau/4) @@ rad) else ((3*tau/4) @@ rad) ^-^ st) 66 | aDia 67 | = ( hd # moveTo endPt 68 | <> 69 | a # stroke 70 | ) 71 | # rotate (signedAngleBetween v unitX) 72 | # moveTo p1 73 | 74 | data DFA e = DFA (M.Map Int (Bool, P2 Double)) (M.Map (Int,Int) e) 75 | 76 | class DrawableEdge e where 77 | drawEdge :: M.Map Int (Bool, P2 Double) -> (Int,Int) -> e -> Diagram B 78 | 79 | instance DrawableEdge (Dia, Bool) where 80 | drawEdge states (i,j) (label,flp) 81 | | i == j 82 | = arcArrow 83 | (pti # translateY (-1.4) # rotateAround pti (negated theta)) 84 | (pti # translateY (-1.4) # rotateAround pti theta) 85 | (-1.3) 86 | 0 87 | label 88 | | otherwise 89 | = arcArrow pti ptj (if flp then (-1) else 1) 1.4 label 90 | where 91 | theta = 20 @@ deg 92 | stPos ix = fromMaybe (1000 ^& 1000) $ snd <$> M.lookup ix states 93 | pti = stPos i 94 | ptj = stPos j 95 | 96 | instance DrawableEdge Dia where 97 | drawEdge states e label = drawEdge states e (label, False) 98 | 99 | infixr 3 >-- 100 | infixr 3 --> 101 | i >-- (a,j) = ((i,j),a) 102 | (-->) = (,) 103 | 104 | dfa states edges = DFA (M.fromList states) (M.fromList edges) 105 | 106 | drawDFA :: (DrawableEdge e) => DFA e -> Diagram B 107 | drawDFA (DFA states edges) = 108 | drawEdges states (M.assocs edges) <> drawStates (M.assocs states) 109 | 110 | drawStates = mconcat . map drawState 111 | where 112 | drawState (n,(final,pos)) 113 | = (text (show n) <> circle 1 <> (if final then circle 1.2 else mempty)) 114 | # moveTo pos 115 | 116 | drawEdges states = mconcat . map (uncurry (drawEdge states)) 117 | 118 | testDFA = dfa 119 | [ 1 --> (True, origin) 120 | , 2 --> (False, 5 ^& 0) 121 | ] 122 | [ 1 >-- txt "a" --> 2 123 | , 2 >-- txt "b" --> 1 124 | ] 125 | 126 | txt s = text s # italic # scale 0.8 <> square 1 # lw none 127 | 128 | -- main = defaultMain $ drawDFA testDFA 129 | 130 | -------------------------------------------------------------------------------- /hs/TreeTrisect.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveFoldable #-} 2 | {-# LANGUAGE DeriveFunctor #-} 3 | {-# LANGUAGE DeriveTraversable #-} 4 | {-# LANGUAGE GADTs #-} 5 | {-# LANGUAGE TypeFamilies #-} 6 | {-# LANGUAGE TypeOperators #-} 7 | 8 | import Data.Foldable 9 | import Data.Traversable 10 | 11 | data Parens a where 12 | Leaf :: a -> Parens a 13 | Branch :: Parens a -> Parens a -> Parens a 14 | deriving (Show, Functor, Foldable, Traversable) 15 | 16 | p :: Parens Int 17 | p = Branch (Branch (Leaf 1) (Leaf 2)) (Branch (Branch (Leaf 3) (Leaf 4)) (Leaf 5)) 18 | 19 | data Parens2 a b where 20 | Hole :: Parens2 a b 21 | HoleL :: Parens2 a b -> Parens a -> Parens2 a b 22 | HoleR :: Parens b -> Parens2 a b -> Parens2 a b 23 | deriving Show 24 | 25 | -- P[a,b] = (P[b] - P[a])/(b - a) 26 | -- b P[a,b] + P[a] = P[b] + a P[a,b] 27 | 28 | -- Can we write this code more generically, without specific reference to 29 | -- the constructors of Parens or Parens2? I do not look forward to writing 30 | -- similar code for Parens3. How does 'jokers & clowns' write this code? 31 | moveR2 :: Either (Parens a) (b, Parens2 a b) -> Either (a, Parens2 a b) (Parens b) 32 | moveR2 (Left (Leaf a)) = Left (a, Hole) 33 | moveR2 (Left (Branch l r)) = 34 | case moveR2 (Left l) of 35 | Left (a, dl) -> Left (a, HoleL dl r) 36 | Right bs -> undefined -- can this case ever happen?? 37 | moveR2 (Right (b, Hole)) = Right (Leaf b) 38 | moveR2 (Right (b, (HoleL bsas as))) = -- maybe we are not using the right data 39 | case moveR2 (Right (b, bsas)) of -- structures. Need to represent pointed 40 | -- things explicitly so we don't need 41 | -- to pass b around etc. 42 | Left (a, bsas') -> Left (a, HoleL bsas' as) 43 | Right bs -> 44 | case moveR2 (Left as) of 45 | Left (a, as') -> Left (a, HoleR bs as') 46 | Right bs2 -> Right (Branch bs bs2) -- can this case ever happen? 47 | moveR2 (Right (b, (HoleR bs bsas))) = 48 | case moveR2 (Right (b, bsas)) of 49 | Left (a, bsas') -> Left (a, HoleR bs bsas') 50 | Right bs2 -> Right (Branch bs bs2) 51 | 52 | -- Right, of course, Clowns & Jokers does it *generically*. 53 | 54 | -- algebra of 1-ary functors 55 | 56 | data Void1 a 57 | deriving (Functor) 58 | instance Show (Void1 a) where 59 | show _ = undefined 60 | 61 | refute1 :: Void1 a -> r 62 | refute1 _ = undefined 63 | 64 | data K1 b a = K1 b 65 | deriving (Show, Functor) 66 | 67 | type Unit1 = K1 () 68 | 69 | data Id1 a = Id1 a 70 | deriving (Show, Functor) 71 | 72 | data (Plus1 f g) a = Inl1 (f a) | Inr1 (g a) 73 | deriving (Show, Functor) 74 | 75 | data (Times1 f g) a = Pair1 (f a) (g a) 76 | deriving (Show, Functor) 77 | 78 | -- algebra of 2-ary functors 79 | 80 | class Bifunctor h where 81 | bimap :: (a1 -> b1) -> (a2 -> b2) -> h a1 b2 -> h a2 b2 82 | 83 | refute2 :: Void2 c j -> a 84 | refute2 _ = undefined 85 | 86 | data Void2 c j 87 | instance Bifunctor Void2 where 88 | bimap f g v = refute2 v 89 | 90 | instance Show (Void2 c j) where 91 | show v = refute2 v 92 | 93 | data K2 x c j = K2 x 94 | deriving (Show) 95 | instance Bifunctor (K2 x) where 96 | bimap _ _ (K2 x) = K2 x 97 | 98 | type Unit2 = K2 () 99 | 100 | data Plus2 f g c j = Inl2 (f c j) | Inr2 (g c j) 101 | deriving (Show) 102 | instance (Bifunctor f, Bifunctor g) => Bifunctor (Plus2 f g) where 103 | bimap h k (Inl2 f) = Inl2 (bimap h k f) 104 | bimap h k (Inr2 g) = Inr2 (bimap h k g) 105 | 106 | -- Dissection 107 | 108 | class HasD2 (f :: * -> *) where 109 | type D2 f :: * -> * -> * 110 | 111 | right :: Either (f j) (D2 f c j, c) -> Either (j, D2 f c j) (f c) 112 | 113 | instance HasD2 Void1 where 114 | type D2 Void1 = Void2 115 | 116 | right (Left v) = refute1 v 117 | right (Right (v,_)) = refute2 v 118 | 119 | instance HasD2 (K1 b) where 120 | type D2 (K1 b) = Void2 121 | 122 | right (Left (K1 b)) = Right (K1 b) 123 | 124 | instance HasD2 Id1 where 125 | type D2 Id1 = Unit2 126 | 127 | right (Left (Id1 j)) = Left (j, K2 ()) 128 | right (Right (K2 (), c)) = Right (Id1 c) 129 | 130 | instance (HasD2 f, HasD2 g) => HasD2 (Plus1 f g) where 131 | type D2 (Plus1 f g) = Plus2 (D2 f) (D2 g) 132 | 133 | right (Left (Inl1 fj)) = case right (Left fj) of 134 | Left (j, f') -> Left (j, Inl2 f') 135 | Right fc -> Right (Inl1 fc) 136 | right (Left (Inr1 gj)) = case right (Left gj) of 137 | Left (j, g') -> Left (j, Inr2 g') 138 | Right gc -> Right (Inl1 gc) 139 | right (Right (Inl2 f', c)) = case right (Right (f', c)) of 140 | Left (j, f') -> _ 141 | Right fc -> _ 142 | right (Right (Inr2 g', c)) = _ 143 | 144 | main :: IO () 145 | main = print 'x' 146 | -------------------------------------------------------------------------------- /hs/TypeDFA2.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE UndecidableInstances #-} 2 | {-# LANGUAGE FlexibleContexts #-} 3 | {-# LANGUAGE StandaloneDeriving #-} 4 | {-# LANGUAGE RankNTypes #-} 5 | {-# LANGUAGE TypeOperators #-} 6 | {-# LANGUAGE GADTs #-} 7 | {-# LANGUAGE TypeFamilies #-} 8 | {-# LANGUAGE DataKinds #-} 9 | 10 | import Data.Void 11 | import GHC.TypeLits 12 | 13 | ---------------------------------------------------------------------- 14 | -- Initial binary tree type 15 | 16 | data Tree a = Leaf a | Fork (Tree a) (Tree a) 17 | deriving Show 18 | 19 | treeFold :: (a -> r) -> (r -> r -> r) -> Tree a -> r 20 | treeFold f g = go 21 | where 22 | go (Leaf a) = f a 23 | go (Fork l r) = g (go l) (go r) 24 | 25 | ---------------------------------------------------------------------- 26 | -- Derived, restricted type, for the regex (ab)* 27 | 28 | data Tree' :: Nat -> Nat -> * -> * -> * where 29 | Leaf' :: Transition i j a b -> Tree' i j a b 30 | Fork' :: Tree' i k a b -> Tree' k j a b -> Tree' i j a b 31 | 32 | deriving instance (Show a, Show b) => Show (Tree' i j a b) 33 | 34 | tree'Fold :: (forall i j. Transition i j a b -> r) -> (r -> r -> r) -> Tree' i j a b -> r 35 | tree'Fold f _ (Leaf' a) = f a 36 | tree'Fold f g (Fork' l r) = g (tree'Fold f g l) (tree'Fold f g r) 37 | 38 | -- could generalize this more, along the lines of what was in some of 39 | -- the blog posts 40 | data Transition :: Nat -> Nat -> * -> * -> * where 41 | T01 :: a -> Transition 0 1 a b 42 | T10 :: b -> Transition 1 0 a b 43 | 44 | deriving instance (Show a, Show b) => Show (Transition i j a b) 45 | 46 | {- Having Transition be a GADT instead of a type family is important. 47 | Here is what happened when it was a type family: 48 | 49 | >>> :t Fork' (Leaf' 'x') (Leaf' (3 :: Int)) :: Tree' 0 0 Char Int 50 | 51 | :1:14: 52 | Couldn't match type `Transition 0 k0 Char Int' with `Char' 53 | The type variable `k0' is ambiguous 54 | Possible fix: add a type signature that fixes these type variable(s) 55 | Expected type: Transition 0 k0 Char Int 56 | Actual type: Char 57 | In the first argument of Leaf', namely 'x' 58 | In the first argument of Fork', namely `(Leaf' 'x')' 59 | In the expression: 60 | Fork' (Leaf' 'x') (Leaf' (3 :: Int)) :: Tree' 0 0 Char Int 61 | 62 | -} 63 | 64 | ---------------------------------------------------------------------- 65 | -- Existentially wrapping Tree' to hide the DFA state indices 66 | 67 | data ExTree :: * -> * -> * where 68 | ExTreeError :: ExTree a b 69 | ExTree :: Sing (i :: Nat) -> Sing (j :: Nat) -> Tree' i j a b -> ExTree a b 70 | -- The singleton arguments allow us to do case analysis on the 71 | -- type indices i and j at runtime. 72 | 73 | instance (Show a, Show b) => Show (ExTree a b) where 74 | show (ExTreeError) = "ExTreeError" 75 | show (ExTree _ _ t) = show t 76 | 77 | ---------------------------------------------------------------------- 78 | -- Automatically building type-correct trees with dynamic checks 79 | 80 | leafA :: a -> ExTree a b 81 | leafA a = ExTree sing sing (Leaf' (T01 a)) 82 | 83 | leafB :: b -> ExTree a b 84 | leafB b = ExTree sing sing (Leaf' (T10 b)) 85 | 86 | -- fork does runtime case analysis of the existential DFA state 87 | -- indices. Calling eqNat checks whether they are the same, and if 88 | -- so, actually makes that fact known to the type checker. 89 | fork :: ExTree a b -> ExTree a b -> ExTree a b 90 | fork (ExTree i k1 t1) (ExTree k2 j t2) 91 | = case eqNat k1 k2 of 92 | Nothing -> ExTreeError 93 | Just Refl -> ExTree i j (Fork' t1 t2) 94 | fork _ _ = ExTreeError 95 | 96 | ---------------------------------------------------------------------- 97 | -- Converting to and from restricted trees 98 | 99 | toTree :: ExTree a b -> Maybe (Tree (Either a b)) 100 | toTree ExTreeError = Nothing 101 | toTree (ExTree _ _ t) = Just $ tree'Fold leafToEither Fork t 102 | where 103 | leafToEither (T01 a) = Leaf (Left a) 104 | leafToEither (T10 b) = Leaf (Right b) 105 | 106 | fromTree :: Tree (Either a b) -> ExTree a b 107 | fromTree = treeFold (either leafA leafB) fork 108 | 109 | -- Dynamically check whether a tree conforms to (ab)* 110 | checkTree :: Tree (Either a b) -> Maybe (Tree (Either a b)) 111 | checkTree = toTree . fromTree 112 | 113 | ---------------------------------------------------------------------- 114 | -- This stuff is probably already in a library somewhere 115 | 116 | data (:=:) (a :: Nat) (b :: Nat) where 117 | Refl :: a :=: a 118 | 119 | eqNat :: Sing (i :: Nat) -> Sing (j :: Nat) -> Maybe (i :=: j) 120 | eqNat i j = case (isZero i, isZero j) of 121 | (IsZero, IsZero) -> Just Refl 122 | (IsSucc i', IsSucc j') -> case eqNat i' j' of 123 | Nothing -> Nothing 124 | Just Refl -> Just Refl 125 | _ -> Nothing 126 | -------------------------------------------------- 127 | 128 | -------------------------------------------------------------------------------- /hs/TypeDFA.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE PolyKinds #-} 2 | {-# LANGUAGE ConstraintKinds #-} 3 | {-# LANGUAGE UndecidableInstances #-} 4 | {-# LANGUAGE FlexibleContexts #-} 5 | {-# LANGUAGE StandaloneDeriving #-} 6 | {-# LANGUAGE RankNTypes #-} 7 | {-# LANGUAGE TypeOperators #-} 8 | {-# LANGUAGE GADTs #-} 9 | {-# LANGUAGE TypeFamilies #-} 10 | {-# LANGUAGE DataKinds #-} 11 | 12 | import Data.Void 13 | import GHC.Exts 14 | import GHC.TypeLits 15 | 16 | {- 17 | 18 | Still to do: 19 | 20 | + Generalize using a representation of matrices at the type level? 21 | 22 | -} 23 | 24 | ---------------------------------------------------------------------- 25 | -- Initial binary tree type 26 | 27 | data Tree a = Leaf a | Fork (Tree a) (Tree a) 28 | deriving Show 29 | 30 | treeFold :: (a -> r) -> (r -> r -> r) -> Tree a -> r 31 | treeFold f g = go 32 | where 33 | go (Leaf a) = f a 34 | go (Fork l r) = g (go l) (go r) 35 | 36 | ---------------------------------------------------------------------- 37 | -- Derived, restricted type, for the regex (ab)* 38 | 39 | data Tree' :: Nat -> Nat -> [*] -> * where 40 | Leaf' :: Transition i j ts -> Tree' i j ts 41 | Fork' :: Tree' i k ts -> Tree' k j ts -> Tree' i j ts 42 | 43 | type family All (c :: * -> Constraint) (ts :: [*]) :: Constraint 44 | type instance All c '[] = () 45 | type instance All c (t ': ts) = (c t, All c ts) 46 | 47 | deriving instance (All Show ts) => Show (Tree' i j ts) 48 | 49 | tree'Fold :: (forall i j. Transition i j ts -> r) -> (r -> r -> r) -> Tree' i j ts -> r 50 | tree'Fold f _ (Leaf' a) = f a 51 | tree'Fold f g (Fork' l r) = g (tree'Fold f g l) (tree'Fold f g r) 52 | 53 | -- could generalize this more, along the lines of what was in some of 54 | -- the blog posts 55 | data Transition :: Nat -> Nat -> [*] -> * where 56 | T01 :: a -> Transition 0 1 [a,b] 57 | T10 :: b -> Transition 1 0 [a,b] 58 | 59 | deriving instance (All Show ts) => Show (Transition i j ts) 60 | 61 | {- Having Transition be a GADT instead of a type family is important. 62 | Here is what happened when it was a type family: 63 | 64 | >>> :t Fork' (Leaf' 'x') (Leaf' (3 :: Int)) :: Tree' 0 0 Char Int 65 | 66 | :1:14: 67 | Couldn't match type `Transition 0 k0 Char Int' with `Char' 68 | The type variable `k0' is ambiguous 69 | Possible fix: add a type signature that fixes these type variable(s) 70 | Expected type: Transition 0 k0 Char Int 71 | Actual type: Char 72 | In the first argument of Leaf', namely 'x' 73 | In the first argument of Fork', namely `(Leaf' 'x')' 74 | In the expression: 75 | Fork' (Leaf' 'x') (Leaf' (3 :: Int)) :: Tree' 0 0 Char Int 76 | 77 | -} 78 | 79 | ---------------------------------------------------------------------- 80 | -- Existentially wrapping Tree' to hide the DFA state indices 81 | 82 | data Ex :: (Nat -> Nat -> [*] -> *) -> [*] -> * where 83 | ExError :: Ex f ts 84 | Ex :: Sing (i :: Nat) -> Sing (j :: Nat) -> f i j ts -> Ex f ts 85 | -- The singleton arguments allow us to do case analysis on the 86 | -- type indices i and j at runtime. 87 | 88 | instance (Show (f i j ts)) => Show (Ex f ts) where 89 | show (ExError) = "ExError" 90 | show (Ex _ _ t) = show t 91 | 92 | ---------------------------------------------------------------------- 93 | -- Automatically building type-correct trees with dynamic checks 94 | 95 | leafA :: a -> Ex Tree' [a,b] 96 | leafA a = Ex sing sing (Leaf' (T01 a)) 97 | 98 | leafB :: b -> Ex Tree' [a,b] 99 | leafB b = Ex sing sing (Leaf' (T10 b)) 100 | 101 | -- fork does runtime case analysis of the existential DFA state 102 | -- indices. Calling eqNat checks whether they are the same, and if 103 | -- so, actually makes that fact known to the type checker. 104 | fork :: Ex Tree' [a,b] -> Ex Tree' [a,b] -> Ex Tree' [a,b] 105 | fork (Ex i k1 t1) (Ex k2 j t2) 106 | = case eqNat k1 k2 of 107 | Nothing -> ExError 108 | Just Refl -> Ex i j (Fork' t1 t2) 109 | fork _ _ = ExError 110 | 111 | ---------------------------------------------------------------------- 112 | -- Converting to and from restricted trees 113 | 114 | toTree :: Ex Tree' [a,b] -> Maybe (Tree (Either a b)) 115 | toTree ExError = Nothing 116 | toTree (Ex _ _ t) = Just $ tree'Fold leafToEither Fork t 117 | where 118 | leafToEither :: Transition i j [a,b] -> Tree (Either a b) 119 | leafToEither (T01 a) = Leaf (Left a) 120 | leafToEither (T10 b) = Leaf (Right b) 121 | 122 | fromTree :: Tree (Either a b) -> Ex Tree' [a,b] 123 | fromTree = treeFold (either leafA leafB) fork 124 | 125 | -- Dynamically check whether a tree conforms to (ab)* 126 | checkTree :: Tree (Either a b) -> Maybe (Tree (Either a b)) 127 | checkTree = toTree . fromTree 128 | 129 | ---------------------------------------------------------------------- 130 | -- This stuff is probably already in a library somewhere 131 | 132 | data a :=: b where 133 | Refl :: a :=: a 134 | 135 | eqNat :: Sing (i :: Nat) -> Sing (j :: Nat) -> Maybe (i :=: j) 136 | eqNat i j = case (isZero i, isZero j) of 137 | (IsZero, IsZero) -> Just Refl 138 | (IsSucc i', IsSucc j') -> case eqNat i' j' of 139 | Nothing -> Nothing 140 | Just Refl -> Just Refl 141 | _ -> Nothing 142 | -------------------------------------------------- 143 | 144 | -------------------------------------------------------------------------------- /type-matrices.bib: -------------------------------------------------------------------------------- 1 | 2 | @inproceedings{mcbride-dissection, 3 | author = {Conor McBride}, 4 | title = {Clowns to the left of me, jokers to the right (pearl): dissecting 5 | data structures}, 6 | booktitle = {POPL}, 7 | year = {2008}, 8 | pages = {287-295}, 9 | ee = {http://doi.acm.org/10.1145/1328438.1328474}, 10 | } 11 | 12 | @article{DBLP:journals/fuin/AbbottAMG05, 13 | author = {Michael Abbott and 14 | Thorsten Altenkirch and 15 | Conor McBride and 16 | Neil Ghani}, 17 | title = {{$\partial$ for Data: Differentiating Data Structures}}, 18 | journal = {Fundam. Inform.}, 19 | volume = {65}, 20 | number = {1-2}, 21 | year = {2005}, 22 | pages = {1-28}, 23 | ee = {http://iospress.metapress.com/content/jj599ww44r90maa0/}, 24 | bibsource = {DBLP, http://dblp.uni-trier.de} 25 | } 26 | 27 | @article{DBLP:journals/lisp/SiskindP08, 28 | author = {Jeffrey Mark Siskind and 29 | Barak A. Pearlmutter}, 30 | title = {Nesting forward-mode AD in a functional framework}, 31 | journal = {Higher-Order and Symbolic Computation}, 32 | volume = {21}, 33 | number = {4}, 34 | year = {2008}, 35 | pages = {361-376}, 36 | ee = {http://dx.doi.org/10.1007/s10990-008-9037-1}, 37 | bibsource = {DBLP, http://dblp.uni-trier.de} 38 | } 39 | 40 | @ARTICLE{Huet_zipper, 41 | author = {G\'{e}rard Huet}, 42 | title = {Functional Pearl: The Zipper}, 43 | journal = {J. Functional Programming}, 44 | year = {1997}, 45 | volume = {7}, 46 | pages = {7--5} 47 | } 48 | 49 | @article{tarski1955, 50 | ajournal = "Pacific J. Math.", 51 | author = "Tarski, Alfred", 52 | journal = "Pacific Journal of Mathematics", 53 | number = "2", 54 | pages = "285--309", 55 | publisher = "Pacific Journal of Mathematics, A Non-profit Corporation", 56 | title = "A lattice-theoretical fixpoint theorem and its applications.", 57 | url = "http://projecteuclid.org/euclid.pjm/1103044538", 58 | volume = "5", 59 | year = "1955" 60 | } 61 | 62 | @article{mcbride2008applicative, 63 | title={Applicative programming with effects}, 64 | author={McBride, Conor and Paterson, Ross}, 65 | journal={Journal of functional programming}, 66 | volume={18}, 67 | number={01}, 68 | pages={1--13}, 69 | year={2008}, 70 | publisher={Cambridge Univ Press} 71 | } 72 | 73 | @inproceedings{dolan2013fun, 74 | title={Fun with semirings: a functional pearl on the abuse of linear algebra}, 75 | author={Dolan, Stephen}, 76 | booktitle={ACM SIGPLAN Notices}, 77 | volume={48}, 78 | number={9}, 79 | pages={101--110}, 80 | year={2013}, 81 | organization={ACM} 82 | } 83 | 84 | @book{sipser2012introduction, 85 | author={Sipser, Michael}, 86 | title={Introduction to the Theory of Computation}, 87 | year={2012}, 88 | publisher={Cengage Learning} 89 | } 90 | 91 | @article{lehmann1977algebraic, 92 | title={Algebraic structures for transitive closure}, 93 | author={Lehmann, Daniel J}, 94 | journal={Theoretical Computer Science}, 95 | volume={4}, 96 | number={1}, 97 | pages={59--76}, 98 | year={1977}, 99 | publisher={Elsevier} 100 | } 101 | 102 | @misc{oconnor2011shortestpaths, 103 | title={A very general method for computing shortest paths}, 104 | author={Russell O'Connor}, 105 | year={2011}, 106 | howpublished={\url{http://r6.ca/blog/20110808T035622Z.html}} 107 | } 108 | 109 | @Misc{haskell, 110 | author = "Simon Marlow", 111 | editor = "Simon Marlow", 112 | title = "Haskell 2010 {Language} {Report}", 113 | year = "2010", 114 | howpublished = {\url{https://www.haskell.org/onlinereport/haskell2010/}} 115 | } 116 | 117 | @misc{yorgey2010onaproblem, 118 | title={On a problem of sigfpe}, 119 | author={Brent A. Yorgey}, 120 | year={2010}, 121 | howpublished={\url{https://byorgey.wordpress.com/2010/08/12/on-a-problem-of-sigfpe/}} 122 | } 123 | 124 | @misc{piponi2010tomography, 125 | title={{Divided Differences and the Tomography of Types}}, 126 | author={Dan Piponi}, 127 | year={2010}, 128 | howpublished={\url{http://blog.sigfpe.com/2010/08/divided-differences-and-tomography-of.html}} 129 | } 130 | 131 | @misc{piponi2009finite, 132 | title={{Finite Differences of Types}}, 133 | author={Dan Piponi}, 134 | year={2009}, 135 | howpublished={\url{http://blog.sigfpe.com/2009/09/finite-differences-of-types.html}} 136 | } 137 | 138 | @misc{piponi2010regular, 139 | title={{Constraining Types with Regular Expressions}}, 140 | author={Dan Piponi}, 141 | year={2010}, 142 | howpublished={\url{http://blog.sigfpe.com/2010/08/constraining-types-with-regular.html}} 143 | } 144 | 145 | @misc{stay2014q, 146 | title={{Q, Jokers, and Clowns}}, 147 | author={Mike Stay}, 148 | year={2014}, 149 | howpublished={\url{https://reperiendi.wordpress.com/2014/08/05/q-jokers-and-clowns/}} 150 | } 151 | 152 | @article{duchon2004boltzmann, 153 | title={Boltzmann samplers for the random generation of combinatorial structures}, 154 | author={Duchon, Philippe and Flajolet, Philippe and Louchard, Guy and Schaeffer, Gilles}, 155 | journal={Combinatorics, Probability and Computing}, 156 | volume={13}, 157 | number={4-5}, 158 | pages={577--625}, 159 | year={2004}, 160 | publisher={Cambridge Univ Press} 161 | } 162 | 163 | @techreport{kleene1951representation, 164 | title={Representation of events in nerve nets and finite automata}, 165 | author={Kleene, Stephen Cole}, 166 | year={1951}, 167 | institution={DTIC Document} 168 | } 169 | 170 | @book{droste2009handbook, 171 | title={Handbook of weighted automata}, 172 | author={Droste, Manfred and Kuich, Werner and Vogler, Heiko}, 173 | year={2009}, 174 | publisher={Springer Science \& Business Media} 175 | } -------------------------------------------------------------------------------- /talks/mpc-15/TypeMatricesDiagrams.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleContexts #-} 2 | {-# LANGUAGE FlexibleInstances #-} 3 | {-# LANGUAGE MultiParamTypeClasses #-} 4 | {-# LANGUAGE NoMonomorphismRestriction #-} 5 | {-# LANGUAGE TypeSynonymInstances #-} 6 | 7 | module TypeMatricesDiagrams where 8 | 9 | import Data.Colour.SRGB (sRGB24read) 10 | import qualified Data.Map as M 11 | import Data.Maybe (fromMaybe) 12 | import Data.Tree 13 | import Diagrams.Backend.PGF 14 | import Diagrams.Core.Envelope 15 | import Diagrams.Prelude 16 | import Diagrams.TwoD.Layout.Tree 17 | import Diagrams.TwoD.Text 18 | import Linear.V2 (perp) 19 | 20 | type Dia = QDiagram PGF V2 Double Any 21 | 22 | data Type = A | B | C | H | O 23 | 24 | drawType A = text "A" # italic # centerX # translateX (-0.05) <> square 2 # fc lightblue 25 | drawType B = text "B" # italic # centerX # translateX (-0.1) <> circle 1 # fc lightgreen 26 | drawType C = text "C" # italic # centerX # translateX (-0.15) <> triangle 2.3 # fc lavender 27 | drawType H = text "H" # italic # centerX # translateX (-0.1) <> drawType O 28 | drawType O = circle 1 # fc white # dashingG [0.2,0.2] 0 29 | 30 | renderT :: Tree (Maybe Type) -> Diagram B 31 | renderT 32 | = renderTree 33 | (\x -> case x of 34 | Nothing -> mempty 35 | Just t -> drawType t 36 | ) 37 | (~~) 38 | . symmLayout' (with & slHSep .~ 4 & slVSep .~ 3) 39 | 40 | arcArrow :: P2 Double -> P2 Double -> Double -> Double -> Diagram B -> Diagram B 41 | arcArrow p1 p2 ht offs label 42 | = aDia 43 | <> label 44 | # moveTo (lerp 0.5 p1 p2 .+^ (signum ht *^ ((h + envelopeS ((-signum ht) *^ perp v) label) *^ signorm (perp v)))) 45 | where 46 | h = abs ht 47 | straight = h < 0.00001 48 | v = p2 .-. p1 49 | d = norm (p2 .-. p1) 50 | th = acos ((d*d - 4*h*h)/(d*d + 4*h*h)) 51 | r = d/(2*sin th) 52 | phi | straight = 0 @@ rad 53 | | otherwise = (offs/r) @@ rad 54 | mid | ht >= 0 = (tau/4) @@ rad 55 | | otherwise = (3*tau/4) @@ rad 56 | st = mid ^-^ (th @@ rad) ^+^ phi 57 | end = mid ^+^ (th @@ rad) ^-^ phi 58 | a | straight 59 | = hrule (d - 2*offs) # alignL # translateX offs 60 | | otherwise 61 | = arc (xDir # rotate st) (end ^-^ st) 62 | # scale r 63 | # translateY ((if ht > 0 then negate else id) (r-h)) 64 | # translateX (d/2) 65 | # (if ht > 0 then reversePath else id) 66 | endPt = atEnd . head . pathTrails $ a 67 | hd = triangle 0.4 # rotateBy (-1/4) # alignR # fc black # scaleY 0.7 68 | # rotate (if ht >= 0 then st ^-^ ((tau/4) @@ rad) else ((3*tau/4) @@ rad) ^-^ st) 69 | aDia 70 | = ( hd # moveTo endPt 71 | <> 72 | a # stroke 73 | ) 74 | # rotate (signedAngleBetween v unitX) 75 | # moveTo p1 76 | 77 | data DFA e = DFA (M.Map Int (Bool, P2 Double)) (M.Map (Int,Int) e) 78 | 79 | class DrawableEdge e where 80 | drawEdge :: M.Map Int (Bool, P2 Double) -> (Int,Int) -> e -> Diagram B 81 | 82 | instance DrawableEdge (Dia, Bool) where 83 | drawEdge states (i,j) (label,flp) 84 | | i == j 85 | = arcArrow 86 | (pti # translateY (-1.4) # rotateAround pti (negated theta)) 87 | (pti # translateY (-1.4) # rotateAround pti theta) 88 | (-1.3) 89 | 0 90 | label 91 | | otherwise 92 | = arcArrow pti ptj (if flp then (-1) else 1) 1.4 label 93 | where 94 | theta = 20 @@ deg 95 | stPos ix = fromMaybe (1000 ^& 1000) $ snd <$> M.lookup ix states 96 | pti = stPos i 97 | ptj = stPos j 98 | 99 | instance DrawableEdge Dia where 100 | drawEdge states e label = drawEdge states e (label, False) 101 | 102 | infixr 3 >-- 103 | infixr 3 --> 104 | i >-- (a,j) = ((i,j),a) 105 | (-->) = (,) 106 | 107 | dfa states edges = DFA (M.fromList states) (M.fromList edges) 108 | 109 | drawDFA :: (DrawableEdge e) => DFA e -> Diagram B 110 | drawDFA (DFA states edges) = 111 | drawEdges states (M.assocs edges) <> drawStates (M.assocs states) 112 | 113 | drawStates = mconcat . map drawState 114 | where 115 | drawState (n,(final,pos)) 116 | = (text (show n) <> circle 1 <> (if final then circle 1.2 else mempty)) 117 | # moveTo pos 118 | 119 | drawEdges states = mconcat . map (uncurry (drawEdge states)) 120 | 121 | testDFA = dfa 122 | [ 1 --> (True, origin) 123 | , 2 --> (False, 5 ^& 0) 124 | ] 125 | [ 1 >-- txt "a" --> 2 126 | , 2 >-- txt "b" --> 1 127 | ] 128 | 129 | txt s = text s # italic # scale 0.8 <> square 1 # lw none 130 | 131 | -- main = defaultMain $ drawDFA testDFA 132 | 133 | mkNode :: Int -> String -> Diagram B 134 | mkNode i q = (txt q <> circle 1 # fc (nodeColors !! i)) # named q 135 | 136 | connectStates :: IsName n => n -> n -> String -> Double -> Diagram B -> Diagram B 137 | connectStates q0 q1 lab off 138 | = ( withNames [q0, q1] $ \ss -> 139 | let [p0,p1] = map location ss 140 | theLab = txt lab # scale 0.8 141 | labLoc = lerp 0.5 p0 p1 # translate (signorm (perp (p1 .-. p0)) ^* off) 142 | labRot = 0 @@ turn 143 | -- labRot = signedAngleBetweenDirs (dirBetween p1 p0) xDir 144 | in atop (theLab # rotate labRot # moveTo labLoc) 145 | ) 146 | . connectOutside' csOpts q0 q1 147 | 148 | where 149 | csOpts 150 | = with & gaps .~ local 0.5 151 | & headLength .~ local 0.5 152 | & arrowShaft .~ wiggle 153 | 154 | wiggle :: Trail V2 Double 155 | wiggle = mconcat 156 | [ hrule 0.2 157 | , cubicSpline False [ x ^& (0.3 * sin (x*tau)) | x <- [0, 0.1 .. 6] ] 158 | , hrule 0.2 159 | ] 160 | 161 | nodeColors :: [Colour Double] 162 | nodeColors = map sRGB24read ["FFF760", "BA92FF", "FF98B9"] 163 | 164 | -------------------------------------------------------------------------------- /llncs/history.txt: -------------------------------------------------------------------------------- 1 | Version history for the LLNCS LaTeX2e class 2 | 3 | date filename version action/reason/acknowledgements 4 | ---------------------------------------------------------------------------- 5 | 29.5.96 letter.txt beta naming problems (subject index file) 6 | thanks to Dr. Martin Held, Salzburg, AT 7 | 8 | subjindx.ind renamed to subjidx.ind as required 9 | by llncs.dem 10 | 11 | history.txt introducing this file 12 | 13 | 30.5.96 llncs.cls incompatibility with new article.cls of 14 | 1995/12/20 v1.3q Standard LaTeX document class, 15 | \if@openbib is no longer defined, 16 | reported by Ralf Heckmann and Graham Gough 17 | solution by David Carlisle 18 | 19 | 10.6.96 llncs.cls problems with fragile commands in \author field 20 | reported by Michael Gschwind, TU Wien 21 | 22 | 25.7.96 llncs.cls revision a corrects: 23 | wrong size of text area, floats not \small, 24 | some LaTeX generated texts 25 | reported by Michael Sperber, Uni Tuebingen 26 | 27 | 16.4.97 all files 2.1 leaving beta state, 28 | raising version counter to 2.1 29 | 30 | 8.6.97 llncs.cls 2.1a revision a corrects: 31 | unbreakable citation lists, reported by 32 | Sergio Antoy of Portland State University 33 | 34 | 11.12.97 llncs.cls 2.2 "general" headings centered; two new elements 35 | for the article header: \email and \homedir; 36 | complete revision of special environments: 37 | \newtheorem replaced with \spnewtheorem, 38 | introduced the theopargself environment; 39 | two column parts made with multicol package; 40 | add ons to work with the hyperref package 41 | 42 | 07.01.98 llncs.cls 2.2 changed \email to simply switch to \tt 43 | 44 | 25.03.98 llncs.cls 2.3 new class option "oribibl" to suppress 45 | changes to the thebibliograpy environment 46 | and retain pure LaTeX codes - useful 47 | for most BibTeX applications 48 | 49 | 16.04.98 llncs.cls 2.3 if option "oribibl" is given, extend the 50 | thebibliograpy hook with "\small", suggested 51 | by Clemens Ballarin, University of Cambridge 52 | 53 | 20.11.98 llncs.cls 2.4 pagestyle "titlepage" - useful for 54 | compilation of whole LNCS volumes 55 | 56 | 12.01.99 llncs.cls 2.5 counters of orthogonal numbered special 57 | environments are reset each new contribution 58 | 59 | 27.04.99 llncs.cls 2.6 new command \thisbottomragged for the 60 | actual page; indention of the footnote 61 | made variable with \fnindent (default 1em); 62 | new command \url that copys its argument 63 | 64 | 2.03.00 llncs.cls 2.7 \figurename and \tablename made compatible 65 | to babel, suggested by Jo Hereth, TU Darmstadt; 66 | definition of \url moved \AtBeginDocument 67 | (allows for url package of Donald Arseneau), 68 | suggested by Manfred Hauswirth, TU of Vienna; 69 | \large for part entries in the TOC 70 | 71 | 16.04.00 llncs.cls 2.8 new option "orivec" to preserve the original 72 | vector definition, read "arrow" accent 73 | 74 | 17.01.01 llncs.cls 2.9 hardwired texts made polyglot, 75 | available languages: english (default), 76 | french, german - all are "babel-proof" 77 | 78 | 20.06.01 splncs.bst public release of a BibTeX style for LNCS, 79 | nobly provided by Jason Noble 80 | 81 | 14.08.01 llncs.cls 2.10 TOC: authors flushleft, 82 | entries without hyphenation; suggested 83 | by Wiro Niessen, Imaging Center - Utrecht 84 | 85 | 23.01.02 llncs.cls 2.11 fixed footnote number confusion with 86 | \thanks, numbered institutes, and normal 87 | footnote entries; error reported by 88 | Saverio Cittadini, Istituto Tecnico 89 | Industriale "Tito Sarrocchi" - Siena 90 | 91 | 28.01.02 llncs.cls 2.12 fixed footnote fix ; error reported by 92 | Chris Mesterharm, CS Dept. Rutgers - NJ 93 | 94 | 28.01.02 llncs.cls 2.13 fixed the fix (programmer needs vacation) 95 | 96 | 17.08.04 llncs.cls 2.14 TOC: authors indented, smart \and handling 97 | for the TOC suggested by Thomas Gabel 98 | University of Osnabrueck 99 | 100 | 07.03.06 splncs.bst fix for BibTeX entries without year; patch 101 | provided by Jerry James, Utah State University 102 | 103 | 14.06.06 splncs_srt.bst a sorting BibTeX style for LNCS, feature 104 | provided by Tobias Heindel, FMI Uni-Stuttgart 105 | 106 | 16.10.06 llncs.dem 2.3 removed affiliations from \tocauthor demo 107 | 108 | 11.12.07 llncs.doc note on online visibility of given e-mail address 109 | 110 | 15.06.09 splncs03.bst new BibTeX style compliant with the current 111 | requirements, provided by Maurizio "Titto" 112 | Patrignani of Universita' Roma Tre 113 | 114 | 30.03.10 llncs.cls 2.15 fixed broken hyperref interoperability; 115 | patch provided by Sven Koehler, 116 | Hamburg University of Technology 117 | 118 | 15.04.10 llncs.cls 2.16 fixed hyperref warning for informatory TOC entries; 119 | introduced \keywords command - finally; 120 | blank removed from \keywordname, flaw reported 121 | by Armin B. Wagner, IGW TU Vienna 122 | 123 | 15.04.10 llncs.cls 2.17 fixed missing switch "openright" used by \backmatter; 124 | flaw reported by Tobias Pape, University of Potsdam 125 | 126 | 27.09.13 llncs.cls 2.18 fixed "ngerman" incompatibility; solution provided 127 | by Bastian Pfleging, University of Stuttgart 128 | 129 | -------------------------------------------------------------------------------- /agda/NSection.agda: -------------------------------------------------------------------------------- 1 | module NSection where 2 | 3 | open import Data.Empty 4 | open import Data.Unit 5 | open import Data.Sum hiding (map) 6 | open import Data.Product hiding (map) 7 | open import Data.Nat 8 | open import Data.Fin 9 | open import Data.Vec renaming (map to vecMap ; foldr to vecFoldr) 10 | 11 | open import Function 12 | 13 | open import Relation.Binary.PropositionalEquality hiding ( [_] ) 14 | 15 | open import Level using (Level) 16 | 17 | -- Universe/algebra of n-ary functors. 18 | data F : ℕ → Set₁ where 19 | Zero : {n : ℕ} → F n -- void 20 | K : {n : ℕ} → Set → F n -- const 21 | X : {n : ℕ} → Fin n → F n -- projection, i.e. Id 22 | _⊕_ : {n : ℕ} → F n → F n → F n -- sum 23 | _⊗_ : {n : ℕ} → F n → F n → F n -- product 24 | 25 | -- Can't do least fixed point because it makes Agda unhappy, and I don't 26 | -- want to move to full-fledged containers right now 27 | -- μ : {n : ℕ} → Fin (suc n) → F n 28 | 29 | infixl 6 _⊕_ 30 | infixl 7 _⊗_ 31 | 32 | -- One is a synonym for the constantly ⊤ functor 33 | pattern One = K ⊤ 34 | 35 | pattern X₀ = X zero 36 | pattern X₁ = X (suc zero) 37 | pattern X₂ = X (suc (suc zero)) 38 | 39 | sucX : {n : ℕ} → F n → F (suc n) 40 | sucX Zero = Zero 41 | sucX (K A) = K A 42 | sucX (X i) = X (suc i) 43 | sucX (f ⊕ g) = sucX f ⊕ sucX g 44 | sucX (f ⊗ g) = sucX f ⊗ sucX g 45 | 46 | -- Sets n = Set → Set → ... → Set with n arrows 47 | Sets : ℕ → Set₁ 48 | Sets zero = Set 49 | Sets (suc n) = Set → Sets n 50 | 51 | -- Generalized currying: (Set × Set × ... × Set) → Set ≅ Set → Set → ... → Set 52 | Curry : {n : ℕ} → (Vec Set n → Set) → Sets n 53 | Curry {zero} f = f [] 54 | Curry {suc n} f A = Curry (f ∘ _∷_ A) 55 | 56 | -- Interpretation function for elements of the universe F. A code of 57 | -- type F n represents an n-ary functor, here represented as Set^n → Set. 58 | ⟦_⟧ : {n : ℕ} → F n → Vec Set n → Set 59 | ⟦_⟧ Zero _ = ⊥ 60 | ⟦_⟧ (K A) _ = A 61 | ⟦_⟧ (X zero) As = head As 62 | ⟦_⟧ (X (suc i)) As = ⟦ X i ⟧ (tail As) 63 | ⟦_⟧ (f ⊕ g) As = ⟦ f ⟧ As ⊎ ⟦ g ⟧ As 64 | ⟦_⟧ (f ⊗ g) As = ⟦ f ⟧ As × ⟦ g ⟧ As 65 | 66 | -- Interpretation as Set → ... → Set 67 | ⟦_⟧′ : {n : ℕ} → F n → Sets n 68 | ⟦ f ⟧′ = Curry ⟦ f ⟧ 69 | 70 | open import Function.Inverse as Inv using (_↔_; module Inverse) 71 | 72 | _≅_ : {n : ℕ} → F n → F n → Set₁ 73 | _≅_ {n} f g = ∀ (As : Vec Set n) → ⟦ f ⟧ As ↔ ⟦ g ⟧ As 74 | 75 | -- n-ary maps between Set^n 76 | Map : {n : ℕ} → Vec Set n → Vec Set n → Set 77 | Map [] [] = ⊤ 78 | Map (A ∷ As) (B ∷ Bs) = (A → B) × Map As Bs 79 | 80 | -- The identity n-ary map 81 | Id : {n : ℕ} → (As : Vec Set n) → Map As As 82 | Id [] = tt 83 | Id (A ∷ As) = id , Id As 84 | 85 | -- composition of n-ary maps 86 | Comp : {n : ℕ} {As Bs Cs : Vec Set n} → Map Bs Cs → Map As Bs → Map As Cs 87 | Comp {zero} {[]} {[]} {[]} _ _ = tt 88 | Comp {suc n} {A ∷ As} {B ∷ Bs} {C ∷ Cs} (B→C , Bs→Cs) (A→B , As→Bs) 89 | = B→C ∘ A→B , Comp Bs→Cs As→Bs 90 | 91 | -- interpretation of F is functorial 92 | map : ∀ {n : ℕ} {As Bs : Vec Set n} → (f : F n) → Map As Bs → ⟦ f ⟧ As → ⟦ f ⟧ Bs 93 | map Zero _ () 94 | map (K A) _ fAs = fAs 95 | map {As = _ ∷ _} {_ ∷ _} (X zero) (A→B , _) fAs = A→B fAs 96 | map {As = _ ∷ _} {_ ∷ _} (X (suc i)) (_ , m) fAs = map (X i) m fAs 97 | map (f ⊕ g) m fAs = Data.Sum.map (map f m) (map g m) fAs 98 | map (f ⊗ g) m fAs = Data.Product.map (map f m) (map g m) fAs 99 | 100 | -- Functor law: preservation of identity 101 | pres-id : ∀ {n : ℕ} {As : Vec Set n} → (f : F n) → {fAs : ⟦ f ⟧ As} 102 | → (map f (Id As) fAs ≡ fAs) 103 | pres-id Zero {()} 104 | pres-id (K A) = refl 105 | pres-id {As = _ ∷ _} (X zero) = refl 106 | pres-id {As = _ ∷ _} (X (suc i)) = pres-id (X i) 107 | pres-id (f ⊕ g) {inj₁ fAs} = cong inj₁ (pres-id f) 108 | pres-id (f ⊕ g) {inj₂ gAs} = cong inj₂ (pres-id g) 109 | pres-id (f ⊗ g) {fAs , gAs} = cong₂ _,_ (pres-id f) (pres-id g) 110 | 111 | postulate ext : ∀ {A B : Set} {f g : A → B} → ({x : A} → f x ≡ g x) → f ≡ g 112 | 113 | pres-id-ext : ∀ {n : ℕ} {As : Vec Set n} → (f : F n) → map f (Id As) ≡ id 114 | pres-id-ext f = ext (pres-id f) 115 | 116 | -- Functor law: preservation of composition 117 | pres-∘ : ∀ {n : ℕ} {As Bs Cs : Vec Set n} → (f : F n) 118 | → {g : Map As Bs} → {h : Map Bs Cs} → {fAs : ⟦ f ⟧ As} 119 | → (map f h (map f g fAs) ≡ map f (Comp h g) fAs) 120 | pres-∘ Zero {fAs = ()} 121 | pres-∘ (K A) = refl 122 | pres-∘ {As = _ ∷ _} {Bs = _ ∷ _} {Cs = _ ∷ _} (X zero) = refl 123 | pres-∘ {As = _ ∷ _} {Bs = _ ∷ _} {Cs = _ ∷ _} (X (suc i)) = pres-∘ (X i) 124 | pres-∘ (f ⊕ g) {fAs = inj₁ fAs} = cong inj₁ (pres-∘ f) 125 | pres-∘ (f ⊕ g) {fAs = inj₂ gAs} = cong inj₂ (pres-∘ g) 126 | pres-∘ (f ⊗ g) {fAs = fAs , gAs} = cong₂ _,_ (pres-∘ f) (pres-∘ g) 127 | 128 | pres-∘-ext : ∀ {n : ℕ} {As Bs Cs : Vec Set n} → (f : F n) 129 | → {g : Map As Bs} → {h : Map Bs Cs} → {fAs : ⟦ f ⟧ As} 130 | → map f h ∘ map f g ≡ map f (Comp h g) 131 | pres-∘-ext f = ext (pres-∘ f) 132 | 133 | ------------------------------------------------------------ 134 | -- Dissection 135 | ------------------------------------------------------------ 136 | 137 | -- Start with basic 2-dissection, as in Jokers & Clowns paper 138 | 139 | -- D₂ : F 1 → F 2 140 | -- D₂ Zero = Zero 141 | -- D₂ (K _) = Zero 142 | -- D₂ (X _) = One 143 | -- D₂ (f ⊕ g) = D₂ f ⊕ D₂ g 144 | -- D₂ (f ⊗ g) = (D₂ f ⊗ R g) ⊕ (L f ⊗ D₂ g) 145 | -- D₂ (L f) = D₂ f 146 | -- D₂ (R f) = D₂ f 147 | 148 | -- Should try redoing this with pointed things. Also, seems like this is doing a lot of repeated work. 149 | 150 | -- right : (f : F 1) → {j c : Set} → (⟦ f ⟧′ j ⊎ (⟦ D₂ f ⟧′ c j × c)) → ((j × ⟦ D₂ f ⟧′ c j) ⊎ ⟦ f ⟧′ c) 151 | -- right Zero (inj₁ ()) 152 | -- right Zero (inj₂ (() , _)) 153 | -- right (K A) (inj₁ a) = inj₂ a 154 | -- right (K A) (inj₂ (() , _)) 155 | -- right (X zero) (inj₁ j) = inj₁ (j , tt) 156 | -- right (X (suc ())) 157 | -- right (X zero) (inj₂ (tt , c)) = inj₂ c 158 | -- right (f ⊕ g) (inj₁ (inj₁ fj)) with right f (inj₁ fj) 159 | -- ... | inj₁ (j , f'cj) = inj₁ (j , inj₁ f'cj) 160 | -- ... | inj₂ fc = inj₂ (inj₁ fc) 161 | -- right (f ⊕ g) (inj₁ (inj₂ gj)) with right g (inj₁ gj) 162 | -- ... | inj₁ (j , g'cj) = inj₁ (j , inj₂ g'cj) 163 | -- ... | inj₂ gc = inj₂ (inj₂ gc) 164 | -- right (f ⊕ g) (inj₂ (inj₁ f'cj , c)) with right f (inj₂ (f'cj , c)) 165 | -- ... | inj₁ (j , f'cj₂) = inj₁ (j , inj₁ f'cj₂) 166 | -- ... | inj₂ fc = inj₂ (inj₁ fc) 167 | -- right (f ⊕ g) (inj₂ (inj₂ g'cj , c)) with right g (inj₂ (g'cj , c)) 168 | -- ... | inj₁ (j , g'cj₂) = inj₁ (j , inj₂ g'cj₂) 169 | -- ... | inj₂ gc = inj₂ (inj₂ gc) 170 | -- right (f ⊗ g) (inj₁ (fj , gj)) with right f (inj₁ fj) 171 | -- ... | inj₁ (j , f'cj) = inj₁ (j , (inj₁ (f'cj , gj))) 172 | -- ... | inj₂ fc 173 | -- with right g (inj₁ gj) 174 | -- ... | inj₁ (j , g'cj) = inj₁ (j , (inj₂ (fc , g'cj))) 175 | -- ... | inj₂ gc = inj₂ (fc , gc) 176 | -- right (f ⊗ g) (inj₂ (inj₁ (f'cj , gj) , c)) with right f (inj₂ (f'cj , c)) 177 | -- ... | inj₁ (j , f'cj₂) = inj₁ (j , (inj₁ (f'cj₂ , gj))) 178 | -- ... | inj₂ fc 179 | -- with right g (inj₁ gj) 180 | -- ... | inj₁ (j , g'cj) = inj₁ (j , (inj₂ (fc , g'cj))) 181 | -- ... | inj₂ gc = inj₂ (fc , gc) 182 | -- right (f ⊗ g) (inj₂ (inj₂ (fc , g'cj) , c)) with right g (inj₂ (g'cj , c)) 183 | -- ... | inj₁ (j , g'cj₂) = inj₁ (j , (inj₂ (fc , g'cj₂))) 184 | -- ... | inj₂ gc = inj₂ (fc , gc) 185 | -- right (L f) l = right f l 186 | -- right (R f) l = right f l 187 | 188 | 189 | -- The below implementation more closely matches Conor's from "Jokers & Clowns" 190 | 191 | -- ⊕f : (f g : F 1) {j c : Set} → (j × ⟦ D₂ f ⟧′ c j) ⊎ ⟦ f ⟧′ c → (j × ⟦ D₂ (f ⊕ g) ⟧′ c j) ⊎ ⟦ f ⊕ g ⟧′ c 192 | -- ⊕f _ _ (inj₁ (j , f'cj)) = inj₁ (j , inj₁ f'cj) 193 | -- ⊕f _ _ (inj₂ fc) = inj₂ (inj₁ fc) 194 | 195 | -- ⊕g : (f g : F 1) {j c : Set} → (j × ⟦ D₂ g ⟧′ c j) ⊎ ⟦ g ⟧′ c → (j × ⟦ D₂ (f ⊕ g) ⟧′ c j) ⊎ ⟦ f ⊕ g ⟧′ c 196 | -- ⊕g _ _ (inj₁ (j , g'cj)) = inj₁ (j , inj₂ g'cj) 197 | -- ⊕g _ _ (inj₂ gc) = inj₂ (inj₂ gc) 198 | 199 | -- mutual 200 | -- ⊗f : (f g : F 1) {j c : Set} → (j × ⟦ D₂ f ⟧′ c j) ⊎ ⟦ f ⟧′ c → ⟦ g ⟧′ j → (j × ⟦ D₂ (f ⊗ g) ⟧′ c j) ⊎ ⟦ f ⊗ g ⟧′ c 201 | -- ⊗f f g (inj₁ (j , f'cj)) gj = inj₁ (j , (inj₁ (f'cj , gj))) 202 | -- ⊗f f g (inj₂ fc) gj = ⊗g f g fc (right g (inj₁ gj)) 203 | 204 | -- ⊗g : (f g : F 1) {j c : Set} → ⟦ f ⟧′ c → (j × ⟦ D₂ g ⟧′ c j) ⊎ ⟦ g ⟧′ c → (j × ⟦ D₂ (f ⊗ g) ⟧′ c j) ⊎ ⟦ f ⊗ g ⟧′ c 205 | -- ⊗g f g fc (inj₁ (j , g'cj)) = inj₁ (j , (inj₂ (fc , g'cj))) 206 | -- ⊗g f g fc (inj₂ gc) = inj₂ (fc , gc) 207 | 208 | -- right : (f : F 1) → {j c : Set} → (⟦ f ⟧′ j ⊎ (⟦ D₂ f ⟧′ c j × c)) → ((j × ⟦ D₂ f ⟧′ c j) ⊎ ⟦ f ⟧′ c) 209 | -- right Zero (inj₁ ()) 210 | -- right Zero (inj₂ (() , _)) 211 | -- right (K A) (inj₁ a) = inj₂ a 212 | -- right (K A) (inj₂ (() , _)) 213 | -- right (X zero) (inj₁ j) = inj₁ (j , tt) 214 | -- right (X (suc ())) 215 | -- right (X zero) (inj₂ (tt , c)) = inj₂ c 216 | -- right (f ⊕ g) (inj₁ (inj₁ fj)) = ⊕f f g (right f (inj₁ fj)) 217 | -- right (f ⊕ g) (inj₁ (inj₂ gj)) = ⊕g f g (right g (inj₁ gj)) 218 | -- right (f ⊕ g) (inj₂ (inj₁ f'cj , c)) = ⊕f f g (right f (inj₂ (f'cj , c))) 219 | -- right (f ⊕ g) (inj₂ (inj₂ g'cj , c)) = ⊕g f g (right g (inj₂ (g'cj , c))) 220 | -- right (f ⊗ g) (inj₁ (fj , gj)) = ⊗f f g (right f (inj₁ fj)) gj 221 | -- right (f ⊗ g) (inj₂ (inj₁ (f'cj , gj) , c)) = ⊗f f g (right f (inj₂ (f'cj , c))) gj 222 | -- right (f ⊗ g) (inj₂ (inj₂ (fc , g'cj) , c)) = ⊗g f g fc (right g (inj₂ (g'cj , c))) 223 | -- right (L f) x = right f x 224 | -- right (R f) x = right f x 225 | 226 | -- Next: try making types for pointed dissections? Or go ahead and try generalizing to n-section? 227 | 228 | 229 | ------------------------------------------------------------ 230 | -- Generalized n-dissection 231 | ------------------------------------------------------------ 232 | 233 | Mat : {ℓ : Level} → ℕ → ℕ → Set ℓ → Set ℓ 234 | Mat m n A = Fin m → Fin n → A 235 | 236 | mkMat : {ℓ : Level} {A : Set ℓ} {m n : ℕ} → Vec (Vec A n) m → Mat m n A 237 | mkMat v i j = lookup j (lookup i v) 238 | 239 | mapMat : {ℓ : Level} {m n : ℕ} {A B : Set ℓ} → (A → B) → Mat m n A → Mat m n B 240 | mapMat f m = λ i j → f (m i j) 241 | 242 | matSum : {ℓ : Level} {m n : ℕ} {A : Set ℓ} → (A → A → A) → Mat m n A → Mat m n A → Mat m n A 243 | matSum _⊞_ m₁ m₂ = λ i j → m₁ i j ⊞ m₂ i j 244 | 245 | matProd : {ℓ : Level} {m n p : ℕ} {A : Set ℓ} → (A → A → A) → A → (A → A → A) 246 | → Mat m n A → Mat n p A → Mat m p A 247 | matProd {n = n} {A = A} _⊞_ z _⊡_ m₁ m₂ = λ i j → vecFoldr (λ _ → A) _⊞_ z 248 | (vecMap (λ k → m₁ i k ⊡ m₂ k j) (allFin n)) 249 | 250 | ifeq : {ℓ : Level} {n : ℕ} {A : Set ℓ} → Fin n → Fin n → A → A → A 251 | ifeq zero zero x _ = x 252 | ifeq zero (suc j) _ y = y 253 | ifeq (suc i) zero _ y = y 254 | ifeq (suc i) (suc j) x y = ifeq i j x y 255 | 256 | DFA-hom : {n k : ℕ} → Mat n n (F k) → F 1 → Mat n n (F k) 257 | DFA-hom _ Zero _ _ = Zero 258 | DFA-hom _ (K A) i j = ifeq i j (K A) Zero 259 | DFA-hom trans (X _) = trans 260 | DFA-hom trans (f ⊕ g) = matSum _⊕_ (DFA-hom trans f) (DFA-hom trans g) 261 | DFA-hom trans (f ⊗ g) = matProd _⊕_ Zero _⊗_ (DFA-hom trans f) (DFA-hom trans g) 262 | 263 | module 2-deriv where 264 | -- transition matrix for derivative 265 | trans-2-deriv : Mat 2 2 (F 2) 266 | trans-2-deriv = mkMat ( ( X zero ∷ X (suc zero) ∷ [] ) 267 | ∷ ( Zero ∷ X zero ∷ [] ) 268 | ∷ [] 269 | ) 270 | 271 | ∂ : F 1 → F 2 272 | ∂ f = DFA-hom trans-2-deriv f zero (suc zero) 273 | 274 | ∂X² : Set → Set 275 | ∂X² A = ⟦ ∂ (X₀ ⊗ X₀) ⟧′ A ⊤ 276 | 277 | -- ∂X² ℕ = ℕ × ⊤ ⊎ ⊤ × ℕ ⊎ ⊥ 278 | -- It works! 279 | 280 | module 2-dissect where 281 | trans-2-dissect : Mat 2 2 (F 3) 282 | trans-2-dissect = mkMat ( ( X zero ∷ X (suc (suc zero)) ∷ [] ) 283 | ∷ ( Zero ∷ X (suc zero) ∷ [] ) 284 | ∷ [] 285 | ) 286 | 287 | Δ : F 1 → F 3 288 | Δ f = DFA-hom trans-2-dissect f zero (suc zero) 289 | 290 | ΔX² : Set → Set → Set 291 | ΔX² B A = ⟦ Δ (X₀ ⊗ X₀) ⟧′ B A ⊤ 292 | 293 | -- Next step: can we express something like 'right' generically, for 294 | -- n-dissection? 295 | 296 | -- General transition matrix for n-dissection. 297 | -- 298 | -- [ X_0 X_{n+1} 0 0 ... 299 | -- [ 0 X_1 X_{n+1} 0 ... 300 | -- [ 0 0 X_2 X_{n+1} ... 301 | -- [ 0 0 0 X_3 .... 302 | -- 303 | -- etc. 304 | trans-n-dissect : (n : ℕ) → Mat n n (F (suc n)) 305 | trans-n-dissect zero () () 306 | trans-n-dissect (suc _) zero zero = X zero 307 | trans-n-dissect (suc n) zero (suc j) = X (fromℕ (suc n)) 308 | trans-n-dissect (suc _) (suc _) zero = Zero 309 | trans-n-dissect (suc n) (suc i) (suc j) = mapMat sucX (trans-n-dissect n) i j 310 | 311 | D : (n : ℕ) → F 1 → Mat n n (F (suc n)) 312 | D n = DFA-hom (trans-n-dissect n) 313 | 314 | _⋆ : {n : ℕ} → Fin n → Fin (suc n) 315 | _⋆ = raise 1 316 | 317 | right : {n : ℕ} {i j : Fin n} → (f : F 1) 318 | → ((D (suc n) f (i ⋆) (suc j) ⊗ X (suc j ⋆)) ⊕ D (suc n) f (i ⋆) (j ⋆)) 319 | ≅ 320 | (D (suc n) f (suc i) (suc j) ⊕ (X (i ⋆ ⋆) ⊗ D (suc n) f (i ⋆) (suc j))) 321 | right Zero As = {!!} 322 | right (K A) As = {!!} 323 | right (X i) As = {!!} 324 | right (f ⊕ g) As = {!!} 325 | right (f ⊗ g) As = {!!} 326 | -- Oh goodness. The type typechecks. Now what? 327 | 328 | -- ugghhhhh 329 | lemma1 : {ℓ : Level} {A : Set ℓ} → (⊥ × A) ↔ ⊥ 330 | lemma1 = record { to = record { _⟨$⟩_ = proj₁ ; cong = {!!} } ; from = record { _⟨$⟩_ = λ () ; cong = {!!} } ; inverse-of = record { left-inverse-of = λ x → {!!} ; right-inverse-of = {!!} } } 331 | -------------------------------------------------------------------------------- /talks/williams-s15/type-matrices-williams-s15.tex: -------------------------------------------------------------------------------- 1 | %% -*- mode: LaTeX; compile-command: "cabal --sandbox-config-file=$HOME/src/diagrams/cabal.sandbox.config exec runhaskell Shake" -*- 2 | \documentclass[xcolor=svgnames,12pt]{beamer} 3 | 4 | \usepackage[all]{xy} 5 | \usepackage{brent} 6 | \usepackage[backend=cairo,outputdir=diagrams]{diagrams-latex} 7 | \graphicspath{{images/}} 8 | 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | 12 | % Math typesetting 13 | 14 | %% a bit more space for matrices 15 | \setlength{\arraycolsep}{5pt} 16 | 17 | % regular expression alternation/choice operator 18 | \newcommand{\realt}{+} 19 | 20 | \newcommand{\sem}[1]{\ensuremath{\left\llbracket #1 \right\rrbracket}} 21 | 22 | % \newcommand{\m}[1]{\mathbf{#1}} 23 | \newcommand{\m}[1]{\left[ {#1} \right]} 24 | \newcommand{\mD}[1]{\m{#1}_D} 25 | 26 | \newcommand{\dissect}{\includegraphics{Dissect}} 27 | \newcommand{\clowns}{\includegraphics{Clowns}} 28 | \newcommand{\jokers}{\includegraphics{Jokers}} 29 | 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | 33 | \newcommand{\theschool}{Williams College} 34 | \newcommand{\thedate}{March 13, 2015} 35 | 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 38 | 39 | \setbeamertemplate{items}[circle] 40 | 41 | \mode 42 | { 43 | \usetheme{default} % use a default (plain) theme 44 | 45 | \setbeamertemplate{navigation symbols}{} % don't show navigation 46 | % buttons along the 47 | % bottom 48 | \setbeamerfont{normal text}{family=\sffamily} 49 | 50 | % XX remove this before giving actual talk! 51 | % \setbeamertemplate{footline}[frame number] 52 | % {% 53 | % \begin{beamercolorbox}{section in head/foot} 54 | % \vskip2pt 55 | % \hfill \insertframenumber 56 | % \vskip2pt 57 | % \end{beamercolorbox} 58 | % } 59 | 60 | \AtBeginSection[] 61 | { 62 | \begin{frame} 63 | \frametitle{} 64 | 65 | \begin{center} 66 | % \includegraphics[width=2in]{\sectionimg} 67 | % \bigskip 68 | 69 | {\Huge \insertsectionhead} 70 | \end{center} 71 | \end{frame} 72 | } 73 | } 74 | 75 | \defbeamertemplate*{title page}{customized}[1][] 76 | { 77 | \vbox{} 78 | \vfill 79 | \begin{centering} 80 | \begin{beamercolorbox}[sep=8pt,center,#1]{title} 81 | \usebeamerfont{title}\inserttitle\par% 82 | \ifx\insertsubtitle\@@empty% 83 | \else% 84 | \vskip0.25em% 85 | {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 86 | \fi% 87 | \end{beamercolorbox}% 88 | \vskip1em\par 89 | {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par} 90 | \vskip1em\par 91 | \begin{beamercolorbox}[sep=8pt,center,#1]{author} 92 | \usebeamerfont{author}\insertauthor 93 | \end{beamercolorbox} 94 | \begin{beamercolorbox}[sep=8pt,center,#1]{institute} 95 | \usebeamerfont{institute}\insertinstitute 96 | \end{beamercolorbox} 97 | \begin{beamercolorbox}[sep=8pt,center,#1]{date} 98 | \usebeamerfont{date}\insertdate 99 | \end{beamercolorbox} 100 | \end{centering} 101 | \vfill 102 | } 103 | 104 | \newenvironment{xframe}[1][] 105 | {\begin{frame}[fragile,environment=xframe,#1]} 106 | {\end{frame}} 107 | 108 | % uncomment me to get 4 slides per page for printing 109 | % \usepackage{pgfpages} 110 | % \pgfpagesuselayout{4 on 1}[uspaper, border shrink=5mm] 111 | 112 | % \setbeameroption{show only notes} 113 | 114 | \renewcommand{\emph}{\textbf} 115 | 116 | \title{Polynomial Functors Constrained by Regular Expressions} 117 | \date{\theschool \\ \thedate} 118 | \author{Brent Yorgey} 119 | \titlegraphic{\includegraphics[width=1in]{deriv-tree}} 120 | 121 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 122 | 123 | \begin{document} 124 | 125 | \begin{xframe}{} 126 | \titlepage 127 | \end{xframe} 128 | 129 | \begin{xframe} 130 | \begin{center} 131 | Joint work with: \bigskip 132 | 133 | \includegraphics[width=3in]{dan} \\ 134 | Dan Piponi 135 | \end{center} 136 | \end{xframe} 137 | 138 | \begin{xframe} 139 | %%% Fun to be here. Work I do is at the intersection of math & CS. 140 | %%% Please ask questions! Part of my challenge is to translate some 141 | %%% CS things for mathematicians and vice versa. 142 | 143 | \begin{itemize} 144 | \item Please ask questions! 145 | \item Part I: get you to understand the title/problem statement 146 | \item Part II: our solution (sketch) 147 | \end{itemize} 148 | 149 | %%% First two parts: get you to understand title, i.e. problem 150 | %%% statement. Part 3: our solution. Based on joint work with Dan 151 | %%% Piponi. 152 | 153 | \end{xframe} 154 | 155 | %% XXX section image: binary tree 156 | %\def\sectionimg{dan.jpg} 157 | \section{Polynomial functors} 158 | 159 | \begin{xframe}{Polynomial functors} 160 | \begin{center} 161 | \[ F : \Set \to \Set \] 162 | elements $\to$ structures \bigskip 163 | 164 | \begin{diagram}[width=200] 165 | import Data.List.Split 166 | import Diagrams 167 | 168 | elts = map node [1,2,3,4::Int] 169 | eltSet = atop (roundedRect 6 6 0.5) 170 | . centerXY 171 | . vsep 1 . map (hsep 1) 172 | . chunksOf 2 173 | $ elts -- $ 174 | 175 | dia = [eltSet, arrowV (5 ^& 0), lsD] # map centerY # hsep 2 # frame 0.5 176 | \end{diagram} 177 | 178 | think: \emph{(parameterized) combinatorial families} 179 | \end{center} 180 | \end{xframe} 181 | 182 | \begin{xframe}{Building polynomial functors} 183 | Polynomial functors are those $F : \Set \to \Set$ which can be built 184 | up out of: 185 | \begin{align*} 186 | 0(A) &= \varnothing \\ 187 | 1(A) &= \{\star\} \\ 188 | X(A) &= A \\ 189 | (F + G)(A) &= F(A) \uplus G(A) \\ 190 | (F \cdot G)(A) &= F(A) \times G(A) 191 | \end{align*} 192 | \end{xframe} 193 | 194 | \begin{xframe}{Example} 195 | \begin{gather*} 196 | 1 + ((X \cdot X) + X) : \Set \to \Set \\ 197 | (1 + ((X \cdot X) + X))(A) = \{\star\} \uplus ((A \times A) \uplus A) 198 | \end{gather*} 199 | \end{xframe} 200 | 201 | \begin{xframe}{Polynomial functor isomorphisms} 202 | Note that 203 | \begin{gather*} 204 | F + G \cong G + F \\ 205 | F + (G + H) \cong (F + G) + H \\ 206 | 0 + F \cong F \cong F + 0 \\ 207 | F \cdot G \cong G \cdot F \\ 208 | F \cdot (G \cdot H) \cong (F \cdot G) \cdot H \\ 209 | 1 \cdot F \cong F \cong F \cdot 1 \\ 210 | F \cdot (G + H) \cong F \cdot G + F \cdot H 211 | \end{gather*} 212 | \end{xframe} 213 | 214 | \begin{xframe}{Polynomial functor isomorphisms} 215 | \[ 1 \cdot F \cong F \] 216 | 217 | Example proof: 218 | 219 | \begin{align*} 220 | (1 \cdot F)(A) &= 1(A) \times F(A) \\ 221 | &= \{\star\} \times F(A) \\ 222 | &= \{(\star, f) \mid f \in F(A)\} \\ 223 | &\cong F(A). 224 | \end{align*} 225 | \end{xframe} 226 | 227 | \begin{xframe}{Semirings} 228 | Up to isomorphism, polynomial functors form a (commutative) \emph{semiring}: 229 | 230 | \begin{itemize} 231 | \item Associative operations $+$, $\cdot$ with identities $0$, $1$ 232 | \item $+$ is commutative 233 | \item $\cdot$ distributes over $+$ 234 | \item $+$ does \emph{not} necessarily have inverses! 235 | \end{itemize} 236 | 237 | Other examples: $(\N,+,\cdot)$, $(\{\mathit{true},\mathit{false}\}, 238 | \lor, \land)$, $(\R_{\geq 0}, \max, +)$ 239 | \end{xframe} 240 | 241 | \begin{xframe}{Implicit/recursive definition} 242 | We also allow mutually recursive definitions: 243 | \begin{align*} 244 | F_1 &= \Phi_1(F_1, \dots, F_n) \\ 245 | &\vdots \\ 246 | F_n &= \Phi_n(F_1, \dots, F_n) 247 | \end{align*} 248 | \end{xframe} 249 | 250 | \begin{xframe}{Example: lists} 251 | \[ L = 1 + X \cdot L \] 252 | 253 | \onslide<2-> 254 | \[ L(A) = \{\star\} \uplus A \times L(A) \] 255 | \begin{center} 256 | \begin{tabular}{c m{3in}} 257 | $L(\N) =$ & 258 | \begin{diagram}[width=200] 259 | import Diagrams 260 | 261 | dia = lsD # frame 0.5 262 | \end{diagram} 263 | \end{tabular} 264 | \end{center} 265 | \end{xframe} 266 | 267 | \begin{xframe}{Example: binary trees} 268 | \[ T = 1 + X \cdot T \cdot T \] 269 | 270 | \onslide<2-> 271 | \[ T(A) = \{\star\} \uplus A \times T(A) \times T(A) \] 272 | \begin{center} 273 | \begin{tabular}{c m{3in}} 274 | $T(\N) =$ & 275 | \begin{diagram}[width=200] 276 | import Diagrams.TwoD.Layout.Tree 277 | 278 | import Diagrams 279 | 280 | dia = frame 0.5 281 | . hsep 3 282 | . (++ [ellipsis]) 283 | . map (centerY . drawTree) 284 | $ trees -- $ 285 | \end{diagram} 286 | \end{tabular} 287 | \end{center} 288 | \end{xframe} 289 | 290 | \begin{xframe}{Example: binary trees} 291 | Polynomial functors can be \textbf{directly encoded} in programming 292 | languages with \textbf{algebraic data types} (Haskell, OCaml, SML, 293 | Scala, F\#): 294 | \[ T = 1 + X \cdot T \cdot T \] 295 | \[ T(A) = \{\star\} \uplus A \times T(A) \times T(A) \] 296 | \begin{verbatim} 297 | data T a = Empty | Node a (T a) (T a) 298 | \end{verbatim} 299 | \end{xframe} 300 | 301 | \begin{xframe}{Example: even/odd lists} 302 | \begin{align*} 303 | E &= 1 + X \cdot O \\ 304 | O &= X \cdot E 305 | \end{align*} 306 | 307 | \begin{center} 308 | \begin{tabular}{c m{3in}} 309 | $E(\N) =$ & 310 | \begin{diagram}[width=200] 311 | import Diagrams 312 | dia = hsep 2 (map drawList [[], [3 :: Int,7], [3,7,2,8]] ++ [ellipsis]) 313 | # frame 0.5 314 | \end{diagram} 315 | \\ 316 | $O(\N) =$ & 317 | \begin{diagram}[width=150] 318 | import Diagrams 319 | dia = hsep 2 (map drawList [[3 :: Int], [3,7,2]] ++ [ellipsis]) 320 | # frame 0.5 321 | \end{diagram} 322 | \end{tabular} 323 | \end{center} 324 | \end{xframe} 325 | 326 | \begin{xframe}{``Polynomial''?} 327 | All polynomial functors are isomorphic to \[ a_0 + a_1 X + a_2 X^2 + 328 | a_3 X^3 + \dots \] with $a_i \in \N$ ($n = 1 + \dots + 1$) 329 | \vspace{0.75in} 330 | 331 | \begin{center} 332 | {\small (mumble generating functions mumble blah \dots)} 333 | \end{center} 334 | \end{xframe} 335 | 336 | %%% Do I need to say something about arbitrary arities? OR can I just 337 | %%% sweep that under the rug? 338 | 339 | \begin{xframe}{``Functors''?} 340 | These are actually \emph{functors} $\Set \to \Set$: given a function 341 | we can apply it to every element in a structure (``map''). E.g.: 342 | \[ T(x \mapsto x + 1) \] 343 | \begin{center} 344 | \begin{diagram}[width=200] 345 | import Diagrams 346 | dia = 347 | [ drawTree (trees !! 2) 348 | , arrowV (4 ^& 0) 349 | , drawTree (fmap succ (trees !! 2)) 350 | ] 351 | # map centerY 352 | # hsep 2 353 | # frame 0.5 354 | \end{diagram} 355 | \end{center} 356 | \end{xframe} 357 | 358 | \begin{xframe}{Calculus!?} 359 | \begin{center} 360 | Analysis $\leftrightarrow$ Combinatorics \bigskip 361 | 362 | Example: \emph{differentiation} 363 | \end{center} 364 | \end{xframe} 365 | 366 | \begin{xframe} 367 | \begin{center} 368 | \includegraphics[width=3in]{diff-page1} 369 | \end{center} 370 | \end{xframe} 371 | 372 | \begin{xframe} 373 | \begin{center} 374 | \begin{tabular}{c m{2in}} 375 | $T(\N)$ & 376 | \begin{diagram}[width=100] 377 | import Diagrams 378 | dia = drawTree (trees !! 3) # frame 0.5 379 | \end{diagram} 380 | \\ 381 | $\displaystyle \left(\dd T X \right)(\N)$ & 382 | \begin{diagram}[width=100] 383 | import Diagrams 384 | dia = drawNTree (poke 3 (trees !! 3)) # frame 0.5 385 | \end{diagram} 386 | \end{tabular} 387 | \end{center} 388 | \end{xframe} 389 | 390 | \begin{xframe}{Proof!} 391 | \[ \dd 1 X \cong 0 \] 392 | % XXX if time, a picture 393 | \begin{center} 394 | $1$-structures have nowhere for a hole to go (they contain no 395 | data) 396 | \end{center} 397 | \end{xframe} 398 | 399 | \begin{xframe} 400 | \[ \dd{X}{X} \cong 1 \] 401 | % XXX picture 402 | \end{xframe} 403 | 404 | \begin{xframe} 405 | \[ \dd{(F+G)}{X} \cong \dd F X + \dd G X \] 406 | % XXX picture 407 | \end{xframe} 408 | 409 | \begin{xframe} 410 | \[ \dd{(F \cdot G)}{X} \cong \dd F X \cdot G + F \cdot \dd G X \] 411 | % XXX picture 412 | \end{xframe} 413 | 414 | \begin{xframe} 415 | \begin{itemize} 416 | \item Note this proof is also an \emph{algorithm} for computing $\dd 417 | T X$ from the definition of $T$. \bigskip 418 | \item These ``one-hole contexts'' turn out to be quite useful in the 419 | context of functional programming (``zippers''); the theory gives 420 | an automatic way to generate them. 421 | \end{itemize} 422 | 423 | \begin{center} 424 | \begin{diagram}[width=100] 425 | import Diagrams 426 | dia = drawNTree (poke 3 (trees !! 3)) # frame 0.5 427 | \end{diagram} 428 | \end{center} 429 | \end{xframe} 430 | 431 | % XXX if I have time. 432 | % 433 | % \begin{xframe} 434 | % \begin{align*} 435 | % T &= 1 + X \cdot T \cdot T \\ 436 | % \dd T X &= 0 + T^2 + X \dd T X T + X T \dd T X \\ 437 | % \end{align*} 438 | % %% picture: three kinds of trees with a hole 439 | % \end{xframe} 440 | 441 | % \begin{xframe} 442 | % \begin{align*} 443 | % \dd T X &= T^2 + X \dd T X T + X T \dd T X \\ 444 | % &= T^2 + 2XT \dd T X 445 | % &= \mathsf{List}(2XT) \cdot T^2 446 | % \end{align*} 447 | % %% picture: chain of contexts etc. Put this in if I have time. 448 | % \end{xframe} 449 | 450 | %% XXX section image: DFA 451 | %% \def\sectionimg{dan.jpg} 452 | \section{Regular expressions} 453 | 454 | \begin{xframe}{Regular expressions} 455 | Regular expressions are a language of ``patterns'' for strings in 456 | $\Sigma^*$ (finite sequences of elements from ``alphabet'' $\Sigma$) 457 | 458 | \begin{align*} 459 | R &::= \varnothing && \text{never matches} \\ 460 | &\mid \varepsilon && \text{empty string} \\ 461 | &\mid a \in \Sigma && \text{``a''} \\ 462 | &\mid R_1 \realt R_2 && \text{$R_1$ or $R_2$} \\ 463 | &\mid R_1R_2 && \text{$R_1$ followed by $R_2$} \\ 464 | &\mid R^* && \text{sequence of zero or more $R$} 465 | \end{align*} 466 | \end{xframe} 467 | 468 | \begin{xframe}{Examples} 469 | \begin{itemize} 470 | \item $a^*b^*$ \quad matches ``b'', ``aaa'', ``aaaabbb'', \dots 471 | \item $a^* b (c+d)$ \quad matches ``abd'', ``bd'', ``aaaabc'', \dots 472 | \item $((a+b)^*c)^*$ \quad matches ``aababcacaabbabc'', \dots 473 | \end{itemize} 474 | \end{xframe} 475 | 476 | \begin{xframe}{Constraining polynomial functors} 477 | \begin{itemize} 478 | \item Generalize to multivariate polynomial functors \[ F : \Set^n 479 | \to \Set \] i.e. $F(A_1, A_2, \dots, A_n)$ 480 | \item Given a (univariate) $F$ and some regular expression $R$ over 481 | $\Sigma = \{A_1, \dots, A_n\}$ 482 | \item Find a multivariate $F_R$ with the ``same shape'' as $F$ but 483 | whose sequences of elements come from a sequence of sets 484 | corresponding to $R$ 485 | \end{itemize} 486 | \end{xframe} 487 | 488 | \begin{xframe}{Example} 489 | \begin{center} 490 | \[ L(A) = 1 + A \times L(A) \] 491 | \[ R = (AA)^* \] 492 | 493 | \begin{tabular}{c m{3in}} 494 | % $L(\N) =$ & 495 | % \begin{diagram}[width=200] 496 | % import Diagrams 497 | 498 | % dia = lsD # frame 0.5 499 | % \end{diagram} 500 | % \\ 501 | $L_R(\N) =$ & 502 | \begin{diagram}[width=200] 503 | import Diagrams 504 | 505 | ls2 = [[], [3,4 :: Int], [1,4,2,6], [3,9,2,0,8,4]] 506 | 507 | dia = vsep 1 (map drawList ls2) # frame 0.5 508 | \end{diagram} 509 | \end{tabular} 510 | \end{center} 511 | 512 | \end{xframe} 513 | 514 | \begin{xframe}{Example} 515 | \[ P = X + P^2 \] 516 | \[ R = a^*ha^* \] 517 | \begin{center} 518 | \includegraphics[width=2in]{deriv-tree} 519 | 520 | \onslide<2-> \dots this is just differentiation! 521 | \end{center} 522 | \end{xframe} 523 | 524 | \begin{xframe}{Example} 525 | \[ P = X + P^2 \] 526 | \[ R = b^*ha^* \] 527 | \begin{center} 528 | \includegraphics[width=2in]{dissect-tree} 529 | 530 | \onslide<2-> This is called a ``dissection'' and corresponds to 531 | \emph{divided difference}. 532 | \end{center} 533 | \end{xframe} 534 | 535 | \begin{xframe}{The problem} 536 | \begin{center} 537 | \textbf{Given a polynomial functor $F$ and regular expression $R$, compute 538 | a (system of mutually recursive, multivariate) polynomial functor(s) 539 | corresponding to $F$ constrained by $R$.} 540 | \end{center} 541 | \end{xframe} 542 | 543 | \section{The solution} 544 | 545 | \begin{xframe}{DFAs} 546 | \begin{center} 547 | \textbf{D}eterministic \textbf{F}inite \textbf{A}utomata \bigskip 548 | 549 | \includegraphics[width=2in]{example-DFA} 550 | 551 | DFAs = machines for identifying sequences 552 | \end{center} 553 | \end{xframe} 554 | 555 | \begin{xframe}{Punchline \#1} 556 | DFAs and regular expressions are ``about the same thing''! (Kleene, 557 | 1951) \bigskip 558 | 559 | Every regular expression has a corresponding DFA (and vice versa). 560 | \end{xframe} 561 | 562 | \begin{xframe}{Example} 563 | \begin{center} 564 | \includegraphics[width=2in]{even-DFA} 565 | 566 | \[ (aa)^* \] 567 | \end{center} 568 | \end{xframe} 569 | 570 | \begin{xframe}{Example} 571 | \begin{center} 572 | \includegraphics[width=2in]{deriv-DFA} 573 | 574 | \[ a^*ha^* \] 575 | \end{center} 576 | \end{xframe} 577 | 578 | \begin{xframe}{The setup} 579 | Given: 580 | \begin{itemize} 581 | \item Polynomial functor $F$ 582 | \item DFA $D$ 583 | \end{itemize} \medskip 584 | 585 | \onslide<2-> 586 | Let $F_{ij}$ denote the (multivariate) polynomial functor 587 | \begin{itemize} 588 | \item with same shape as $F$ 589 | \item constrained by sequences which take the DFA from state $i$ 590 | to state $j$ 591 | \end{itemize} \medskip 592 | 593 | \onslide<3-> 594 | Ultimately we are interested in $\sum_{q \in \mathrm{final}(D)} F_{1q}$. 595 | \end{xframe} 596 | 597 | % XXX if time 598 | % \begin{xframe}{Example} 599 | % XXX Show derivative DFA and all $T_{ij}$ 600 | % \end{xframe} 601 | 602 | \begin{xframe} 603 | \begin{itemize} 604 | \item<+-> $0_{ij} = 0$ 605 | \item<+-> $ 1_{ij} = \begin{cases} 1 \quad i = j \\ 0 \quad i \neq 606 | j \end{cases}$ 607 | \item<+-> $X_{ij} = \text{(sum of) edge(s) from $i$ to $j$}$ 608 | \item<+-> $(F + G)_{ij} = F_{ij} + G_{ij}$ 609 | \item<+-> $(F \cdot G)_{ij} = \sum_{q \in \mathrm{states}(D)} F_{iq} G_{qj}$ 610 | \end{itemize} \bigskip 611 | 612 | \onslide<6-> These are just the definitions of matrix operations! 613 | \end{xframe} 614 | 615 | \begin{xframe} 616 | %% XXX reword etc. 617 | \begin{center} 618 | This is a \emph{semiring homomorphism} from polynomial functors to 619 | $n \times n$ matrices of (arity-$|\Sigma|$) polynomial functors! 620 | \end{center} 621 | \end{xframe} 622 | 623 | \begin{xframe}{Example} 624 | \[ L = 1 + XL, R = (aa)^* \] 625 | \begin{center} 626 | \includegraphics[width=1in]{even-DFA} \\ 627 | Transition matrix = $\begin{bmatrix} 628 | 0 & a \\ a & 0 629 | \end{bmatrix}$ 630 | 631 | \begin{multline*} 632 | \begin{bmatrix} 633 | L_{11} & L_{12} \\ 634 | L_{21} & L_{22} 635 | \end{bmatrix} 636 | = 637 | \begin{bmatrix} 638 | 1 & 0 \\ 639 | 0 & 1 640 | \end{bmatrix} 641 | + 642 | \begin{bmatrix} 643 | 0 & a \\ 644 | a & 0 645 | \end{bmatrix} 646 | \begin{bmatrix} 647 | L_{11} & L_{12} \\ 648 | L_{21} & L_{22} 649 | \end{bmatrix} 650 | \\ 651 | = 652 | \begin{bmatrix} 653 | 1 + a L_{21} & a L_{22} \\ 654 | a L_{11} & 1+ a L_{12} 655 | \end{bmatrix}. 656 | \end{multline*} 657 | \end{center} 658 | \end{xframe} 659 | 660 | \begin{xframe} 661 | \begin{center} 662 | Thank you! \bigskip 663 | 664 | \includegraphics[width=1in]{deriv-tree} 665 | \end{center} 666 | \end{xframe} 667 | 668 | % \begin{xframe}{Example} 669 | % \includegraphics[width=2in]{deriv-DFA} 670 | 671 | % \[ a^*ha^* \] 672 | % \end{xframe} 673 | 674 | \end{document} -------------------------------------------------------------------------------- /talks/wesleyan-s15/type-matrices-wesleyan-s15.tex: -------------------------------------------------------------------------------- 1 | %% -*- mode: LaTeX; compile-command: "cabal --sandbox-config-file=$HOME/src/diagrams-sandbox/cabal.sandbox.config exec runhaskell Shake.hs && open type-matrices-wesleyan-s15.pdf" -*- 2 | \documentclass[xcolor=svgnames,12pt]{beamer} 3 | 4 | \usepackage[all]{xy} 5 | \usepackage{brent} 6 | \usepackage[backend=cairo,outputdir=diagrams]{diagrams-latex} 7 | \graphicspath{{images/}} 8 | 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | 12 | % Math typesetting 13 | 14 | %% a bit more space for matrices 15 | \setlength{\arraycolsep}{5pt} 16 | 17 | % regular expression alternation/choice operator 18 | \newcommand{\realt}{+} 19 | 20 | \newcommand{\sem}[1]{\ensuremath{\left\llbracket #1 \right\rrbracket}} 21 | 22 | % \newcommand{\m}[1]{\mathbf{#1}} 23 | \newcommand{\m}[1]{\left[ {#1} \right]} 24 | \newcommand{\mD}[1]{\m{#1}_D} 25 | 26 | \newcommand{\dissect}{\includegraphics{Dissect}} 27 | \newcommand{\clowns}{\includegraphics{Clowns}} 28 | \newcommand{\jokers}{\includegraphics{Jokers}} 29 | 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | 33 | \newcommand{\theschool}{Wesleyan University} 34 | \newcommand{\thedate}{May 5, 2015} 35 | 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 38 | 39 | \setbeamertemplate{items}[circle] 40 | 41 | \mode 42 | { 43 | \usetheme{default} % use a default (plain) theme 44 | 45 | \setbeamertemplate{navigation symbols}{} % don't show navigation 46 | % buttons along the 47 | % bottom 48 | \setbeamerfont{normal text}{family=\sffamily} 49 | 50 | % XX remove this before giving actual talk! 51 | % \setbeamertemplate{footline}[frame number] 52 | % {% 53 | % \begin{beamercolorbox}{section in head/foot} 54 | % \vskip2pt 55 | % \hfill \insertframenumber 56 | % \vskip2pt 57 | % \end{beamercolorbox} 58 | % } 59 | 60 | \AtBeginSection[] 61 | { 62 | \begin{frame} 63 | \frametitle{} 64 | 65 | \begin{center} 66 | % \includegraphics[width=2in]{\sectionimg} 67 | % \bigskip 68 | 69 | {\Huge \insertsectionhead} 70 | \end{center} 71 | \end{frame} 72 | } 73 | } 74 | 75 | \defbeamertemplate*{title page}{customized}[1][] 76 | { 77 | \vbox{} 78 | \vfill 79 | \begin{centering} 80 | \begin{beamercolorbox}[sep=8pt,center,#1]{title} 81 | \usebeamerfont{title}\inserttitle\par% 82 | \ifx\insertsubtitle\@@empty% 83 | \else% 84 | \vskip0.25em% 85 | {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 86 | \fi% 87 | \end{beamercolorbox}% 88 | \vskip1em\par 89 | {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par} 90 | \vskip1em\par 91 | \begin{beamercolorbox}[sep=8pt,center,#1]{author} 92 | \usebeamerfont{author}\insertauthor 93 | \end{beamercolorbox} 94 | \begin{beamercolorbox}[sep=8pt,center,#1]{institute} 95 | \usebeamerfont{institute}\insertinstitute 96 | \end{beamercolorbox} 97 | \begin{beamercolorbox}[sep=8pt,center,#1]{date} 98 | \usebeamerfont{date}\insertdate 99 | \end{beamercolorbox} 100 | \end{centering} 101 | \vfill 102 | } 103 | 104 | \newenvironment{xframe}[1][] 105 | {\begin{frame}[fragile,environment=xframe,#1]} 106 | {\end{frame}} 107 | 108 | % uncomment me to get 4 slides per page for printing 109 | % \usepackage{pgfpages} 110 | % \pgfpagesuselayout{4 on 1}[uspaper, border shrink=5mm] 111 | 112 | % \setbeameroption{show only notes} 113 | 114 | \renewcommand{\emph}{\textbf} 115 | 116 | \title{Derivatives of Data Types, via Regular Expressions} 117 | \date{\theschool \\ \thedate} 118 | \author{Brent Yorgey} 119 | \titlegraphic{\includegraphics[width=1in]{deriv-tree}} 120 | 121 | % Abstract 122 | % 123 | % Algebraic data types are central to typed functional programming, 124 | % sitting at a happy intersection of theory and practice. I will 125 | % define and give examples of algebraic data types, and then go on to 126 | % explain what is meant by the derivative of an algebraic data type. 127 | % In the second part of the talk I will show how to constrain 128 | % algebraic data types by a given regular expression, including 129 | % finding derivatives a special case. No particular background is 130 | % assumed; my goal is to convey not a particular result per se, but 131 | % rather an appreciation for some of the beautiful overlap between 132 | % algebra, combinatorics, calculus, and computer science. 133 | 134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 135 | 136 | \begin{document} 137 | 138 | \begin{xframe}{} 139 | \titlepage 140 | \end{xframe} 141 | 142 | \begin{xframe} 143 | \begin{center} 144 | Joint work with: \bigskip 145 | 146 | \includegraphics[width=3in]{dan} \\ 147 | Dan Piponi \medskip 148 | 149 | ``Polynomial Functors Constrained by Regular Expressions'', 150 | Mathematics of Program Construction 2015. 151 | \end{center} 152 | \end{xframe} 153 | 154 | \begin{xframe}{Outline/warnings/encouragements} 155 | %%% Fun to be here. Work I do is at the intersection of math & CS. 156 | %%% Please ask questions! Part of my challenge is to translate some 157 | %%% CS things for mathematicians and vice versa. 158 | 159 | \begin{itemize} 160 | \item Please ask questions! 161 | \item Math! 162 | \item Part I: get you to understand the title/problem statement 163 | \item Part II: our solution (sketch) 164 | \end{itemize} 165 | 166 | %%% First two parts: get you to understand title, i.e. problem 167 | %%% statement. Part 3: our solution. Based on joint work with Dan 168 | %%% Piponi. 169 | 170 | \end{xframe} 171 | 172 | %% XXX section image: binary tree 173 | %\def\sectionimg{dan.jpg} 174 | \section{Polynomial functors} 175 | 176 | \begin{xframe}{Polynomial functors} 177 | 178 | \begin{center} 179 | \[ F : \Set \to \Set \] 180 | elements $\to$ structures \bigskip 181 | 182 | \begin{diagram}[width=200] 183 | import Data.List.Split 184 | import Diagrams 185 | 186 | elts = map node [1,2,3,4::Int] 187 | eltSet = atop (roundedRect 6 6 0.5) 188 | . centerXY 189 | . vsep 1 . map (hsep 1) 190 | . chunksOf 2 191 | $ elts -- $ 192 | 193 | dia = [eltSet, arrowV (5 ^& 0), lsD] # map centerY # hsep 2 # frame 0.5 194 | \end{diagram} 195 | \bigskip 196 | 197 | \onslide<2> aka \emph{algebraic data types}, aka \emph{container 198 | types} \dots 199 | % think: \emph{(parameterized) combinatorial families} 200 | \end{center} 201 | \end{xframe} 202 | 203 | \begin{xframe}{Building polynomial functors} 204 | Polynomial functors are those $F : \Set \to \Set$ which can be built 205 | up out of: 206 | \begin{align*} 207 | 0(A) &= \varnothing \\ 208 | 1(A) &= \{\star\} \\ 209 | X(A) &= A \\ 210 | (F + G)(A) &= F(A) \uplus G(A) \\ 211 | (F \cdot G)(A) &= F(A) \times G(A) 212 | \end{align*} 213 | \end{xframe} 214 | 215 | \begin{xframe}{Example} 216 | \[ 1 + ((X \cdot X) + X) : \Set \to \Set \] 217 | 218 | \onslide<2-> 219 | \[ (1 + ((X \cdot X) + X))(A) = \{\star\} \uplus ((A \times A) 220 | \uplus A) \] 221 | 222 | \begin{center} 223 | \begin{diagram}[width=150] 224 | import Diagrams 225 | 226 | dia = hsep 3 227 | [ square 1 # fc black 228 | , drawNList (map Value [3,5 :: Int]) 229 | , drawNList [Value (2 :: Int)] 230 | ] 231 | # frame 0.5 232 | \end{diagram} 233 | \end{center} 234 | \end{xframe} 235 | 236 | \begin{xframe}{Polynomial functor isomorphisms} 237 | \begin{gather*} 238 | F + G \cong G + F \\ 239 | F + (G + H) \cong (F + G) + H \\ 240 | 0 + F \cong F \cong F + 0 241 | \end{gather*} 242 | \onslide<2-> 243 | \begin{gather*} 244 | F \cdot G \cong G \cdot F \\ 245 | F \cdot (G \cdot H) \cong (F \cdot G) \cdot H \\ 246 | 1 \cdot F \cong F \cong F \cdot 1 247 | \end{gather*} 248 | \onslide<3-> 249 | \[ F \cdot (G + H) \cong F \cdot G + F \cdot H \] 250 | \end{xframe} 251 | 252 | \begin{xframe}{Polynomial functor isomorphisms} 253 | \[ 1 \cdot F \cong F \] 254 | 255 | Example proof: 256 | 257 | \begin{align*} 258 | (1 \cdot F)(A) &= 1(A) \times F(A) \\ 259 | &= \{\star\} \times F(A) \\ 260 | &= \{(\star, f) \mid f \in F(A)\} \\ 261 | &\cong F(A). 262 | \end{align*} 263 | \end{xframe} 264 | 265 | \begin{xframe}{Semirings} 266 | Up to isomorphism, polynomial functors form a (commutative) \emph{semiring}: 267 | 268 | \begin{itemize} 269 | \item Associative operations $+$, $\cdot$ with identities $0$, $1$ 270 | \item $+$ is commutative 271 | \item $\cdot$ distributes over $+$ 272 | \item $+$ and $\cdot$ do \emph{not} necessarily have inverses! 273 | \end{itemize} 274 | 275 | Other examples: 276 | \[ (\N,+,\cdot)\quad (\{\mathit{true},\mathit{false}\}, \lor, \land)\quad 277 | (\R \union \{\infty\}, \max, +) \] 278 | \end{xframe} 279 | 280 | \begin{xframe}{Implicit/recursive definition} 281 | We also allow mutually recursive definitions: 282 | \begin{align*} 283 | F_1 &= \Phi_1(F_1, \dots, F_n) \\ 284 | &\vdots \\ 285 | F_n &= \Phi_n(F_1, \dots, F_n) 286 | \end{align*} 287 | \end{xframe} 288 | 289 | \begin{xframe}{Example: lists} 290 | \[ L = 1 + X \cdot L \] 291 | 292 | \onslide<2-> 293 | \[ L(A) = \{\star\} \uplus (A \times L(A)) \] 294 | \begin{center} 295 | \begin{tabular}{c m{3in}} 296 | $L(\N) =$ & 297 | \begin{diagram}[width=200] 298 | import Diagrams 299 | 300 | dia = lsD # frame 0.5 301 | \end{diagram} 302 | \end{tabular} 303 | \end{center} 304 | \end{xframe} 305 | 306 | \begin{xframe}{Example: binary trees} 307 | \[ T = 1 + X \cdot T \cdot T \] 308 | 309 | \onslide<2-> 310 | \[ T(A) = \{\star\} \uplus (A \times T(A) \times T(A)) \] 311 | \begin{center} 312 | \begin{tabular}{c m{3in}} 313 | $T(\N) =$ & 314 | \begin{diagram}[width=200] 315 | import Diagrams.TwoD.Layout.Tree 316 | 317 | import Diagrams 318 | 319 | dia = frame 0.5 320 | . hsep 3 321 | . (++ [ellipsis]) 322 | . map (centerY . drawTree) 323 | $ trees -- $ 324 | \end{diagram} 325 | \end{tabular} 326 | \end{center} 327 | \end{xframe} 328 | 329 | \begin{xframe}{Algebraic data types} 330 | Polynomial functors model \textbf{algebraic data types} in languages 331 | like Haskell, OCaml, SML, Scala, F\#\dots 332 | \[ T = 1 + X \cdot T \cdot T \] 333 | \[ T(A) = \{\star\} \uplus (A \times T(A) \times T(A)) \] 334 | \begin{verbatim} 335 | data T a = Empty | Node a (T a) (T a) 336 | \end{verbatim} 337 | \end{xframe} 338 | 339 | % \begin{xframe}{Example: even/odd lists} 340 | % \begin{align*} 341 | % E &= 1 + X \cdot O \\ 342 | % O &= X \cdot E 343 | % \end{align*} 344 | 345 | % \begin{center} 346 | % \begin{tabular}{c m{3in}} 347 | % $E(\N) =$ & 348 | % \begin{diagram}[width=200] 349 | % import Diagrams 350 | % dia = hsep 2 (map drawList [[], [3 :: Int,7], [3,7,2,8]] ++ [ellipsis]) 351 | % # frame 0.5 352 | % \end{diagram} 353 | % \\ 354 | % $O(\N) =$ & 355 | % \begin{diagram}[width=150] 356 | % import Diagrams 357 | % dia = hsep 2 (map drawList [[3 :: Int], [3,7,2]] ++ [ellipsis]) 358 | % # frame 0.5 359 | % \end{diagram} 360 | % \end{tabular} 361 | % \end{center} 362 | % \end{xframe} 363 | 364 | \begin{xframe}{``Polynomial''?} 365 | All polynomial functors are isomorphic to \[ a_0 + a_1 X + a_2 X^2 + 366 | a_3 X^3 + \dots \] with $a_i \in \N$ (where $n = 1 + \dots + 1$) \bigskip 367 | 368 | \onslide<2-> 369 | Proof: distribute all products over sums and collect like terms! 370 | 371 | % \begin{center} 372 | % {\small (mumble generating functions mumble blah \dots)} 373 | % \end{center} 374 | \end{xframe} 375 | 376 | %%% Do I need to say something about arbitrary arities? OR can I just 377 | %%% sweep that under the rug? 378 | 379 | \begin{xframe}{``Functors''?} 380 | These are actually \emph{functors} $\Set \to \Set$: given a function 381 | we can apply it to every element in a structure (``map''). E.g.: 382 | \[ T(x \mapsto x + 1) \] 383 | \begin{center} 384 | \begin{diagram}[width=200] 385 | import Diagrams 386 | dia = 387 | [ drawTree (trees !! 2) 388 | , arrowV (4 ^& 0) 389 | , drawTree (fmap succ (trees !! 2)) 390 | ] 391 | # map centerY 392 | # hsep 2 393 | # frame 0.5 394 | \end{diagram} 395 | \end{center} 396 | \end{xframe} 397 | 398 | \begin{xframe}{Polynomials\dots} 399 | Things we can do with polynomials: \bigskip 400 | 401 | \begin{itemize} 402 | \item<2-> Add and multiply 403 | \item<3-> Factor 404 | \item<4-> Find zeros? 405 | \item<5-> Calculus?? 406 | \end{itemize} 407 | \end{xframe} 408 | 409 | \begin{xframe}{Calculus!?} 410 | \begin{center} 411 | Many fruitful connections between analysis \& combinatorics! \bigskip 412 | 413 | Example: \emph{differentiation} 414 | \end{center} 415 | \end{xframe} 416 | 417 | \begin{xframe} 418 | \begin{center} 419 | \includegraphics[width=3in]{diff-page1} 420 | \end{center} 421 | \end{xframe} 422 | 423 | \begin{xframe} 424 | \begin{center} 425 | \begin{tabular}{c m{1in} m{2in}} 426 | $T(\N)$ & trees of natural numbers, e.g. & 427 | \begin{diagram}[width=100] 428 | import Diagrams 429 | dia = drawTree (trees !! 3) # frame 0.5 430 | \end{diagram} 431 | \\ 432 | $\displaystyle \left(\dd T X \right)(\N)$ & 433 | trees of natural numbers \emph{with a hole}, e.g. & 434 | \begin{diagram}[width=100] 435 | import Diagrams 436 | dia = drawNTree (poke 3 (trees !! 3)) # frame 0.5 437 | \end{diagram} 438 | \end{tabular} 439 | \end{center} 440 | \end{xframe} 441 | 442 | \begin{xframe}{Proof!} 443 | \begin{itemize} 444 | \item Let $F$ be a polynomial functor. 445 | \item $\dd{F}{X}$ means what we would expect it to mean from calculus. 446 | \end{itemize} 447 | \bigskip 448 | 449 | \onslide<2-> 450 | \emph{To show}: $\dd{F}{X}$-structures are (isomorphic to) $F$-structures with a 451 | single $X$ replaced by a hole. 452 | 453 | \begin{center} 454 | \begin{diagram}[width=150] 455 | import Diagrams 456 | 457 | dia = hsep 1 458 | [ abstractTree "∂F" 459 | , text "≅" 460 | , abstractTree "F" # withHole 461 | ] 462 | # frame 0.5 463 | \end{diagram} 464 | \end{center} 465 | \end{xframe} 466 | 467 | \begin{xframe}{Proof!} 468 | \[ \dd{1}{X} = 0 \] 469 | 470 | \begin{center} 471 | $1$-structures have nowhere for a hole to go (they contain no 472 | data) 473 | \end{center} 474 | \end{xframe} 475 | 476 | \begin{xframe} 477 | \[ \dd{X}{X} = 1 \] 478 | 479 | \begin{center} 480 | An $X$-structure with a hole is just a hole. \bigskip 481 | 482 | \begin{diagram}[width=100] 483 | import Diagrams 484 | 485 | dia = hsep 1 486 | [ abstractTree "X" # withHole 487 | , text "≅" 488 | , hole # scale 0.5 489 | ] 490 | \end{diagram} 491 | \end{center} 492 | \end{xframe} 493 | 494 | \begin{xframe} 495 | \[ \dd{(F+G)}{X} = \dd F X + \dd G X \] 496 | 497 | \begin{center} 498 | An ($F$ or $G$)-structure with a hole is either an $F$-structure 499 | with a hole, or a $G$-structure with a hole. \bigskip 500 | 501 | \begin{diagram}[width=200] 502 | import Diagrams 503 | 504 | dia = hsep 1 505 | [ abstractTree' 0.5 "F+G" # withHole 506 | , text "≅" 507 | , abstractTree "F" # withHole 508 | , text "+" 509 | , abstractTree "G" # withHole 510 | ] 511 | \end{diagram} 512 | \end{center} 513 | \end{xframe} 514 | 515 | \begin{xframe} 516 | \[ \dd{(F \cdot G)}{X} = \dd F X \cdot G + F \cdot \dd G X \] 517 | 518 | \begin{center} 519 | An $(F \cdot G)$-structure is an $F$-structure paired with a 520 | $G$-structure. If it has a hole, the hole can be either in the 521 | $F$-structure or the $G$-structure. \bigskip 522 | 523 | \begin{diagram}[width=200] 524 | import Diagrams 525 | 526 | dia = hsep 1 527 | [ abstractTree' 0.7 "FG" # withHole 528 | , text "≅" 529 | , abstractTree "F" # withHole ||| abstractTree "G" 530 | , text "+" 531 | , abstractTree "F" ||| abstractTree "G" # withHole 532 | ] 533 | \end{diagram} 534 | \end{center} 535 | \end{xframe} 536 | 537 | \begin{xframe} 538 | \begin{itemize} 539 | \item Note this (inductive) proof is also a (recursive) 540 | \emph{algorithm} for computing $\dd T X$ from the definition of 541 | $T$. \bigskip 542 | \item These ``one-hole contexts'' turn out to be quite useful in the 543 | context of functional programming (``zippers''); the theory gives 544 | an automatic way to generate them. 545 | \end{itemize} 546 | 547 | \begin{center} 548 | \begin{diagram}[width=100] 549 | import Diagrams 550 | dia = drawNTree (poke 3 (trees !! 3)) # frame 0.5 551 | \end{diagram} 552 | \end{center} 553 | \end{xframe} 554 | 555 | % XXX if I have time. 556 | % 557 | % \begin{xframe} 558 | % \begin{align*} 559 | % T &= 1 + X \cdot T \cdot T \\ 560 | % \dd T X &= 0 + T^2 + X \dd T X T + X T \dd T X \\ 561 | % \end{align*} 562 | % %% picture: three kinds of trees with a hole 563 | % \end{xframe} 564 | 565 | % \begin{xframe} 566 | % \begin{align*} 567 | % \dd T X &= T^2 + X \dd T X T + X T \dd T X \\ 568 | % &= T^2 + 2XT \dd T X 569 | % &= \mathsf{List}(2XT) \cdot T^2 570 | % \end{align*} 571 | % %% picture: chain of contexts etc. Put this in if I have time. 572 | % \end{xframe} 573 | 574 | %% XXX section image: DFA 575 | %% \def\sectionimg{dan.jpg} 576 | \section{Regular expressions} 577 | 578 | \begin{xframe}{Regular expressions} 579 | Regular expressions are a language of ``patterns'' for strings in 580 | $\Sigma^*$ (finite sequences of elements from ``alphabet'' $\Sigma$) 581 | 582 | \begin{align*} 583 | R &::= \varnothing && \text{never matches} \\ 584 | &\mid \varepsilon && \text{empty string} \\ 585 | &\mid a \in \Sigma && \text{``a''} \\ 586 | &\mid R_1 \realt R_2 && \text{$R_1$ or $R_2$} \\ 587 | &\mid R_1R_2 && \text{$R_1$ followed by $R_2$} \\ 588 | &\mid R^* && \text{sequence of zero or more $R$} 589 | \end{align*} 590 | \end{xframe} 591 | 592 | \begin{xframe}{Examples} 593 | \begin{itemize} 594 | \item $a^*b^*$ \quad matches ``b'', ``aaa'', ``aaaabbb'', \dots 595 | \item $a^* b (c+d)$ \quad matches ``abd'', ``bd'', ``aaaabc'', \dots 596 | \item $((a+b)^*c)^*$ \quad matches ``aababcacaabbabc'', \dots 597 | \end{itemize} 598 | \end{xframe} 599 | 600 | \begin{xframe}{Constraining polynomial functors} 601 | \begin{itemize} 602 | \item Generalize to multivariate polynomial functors \[ F : \Set^n 603 | \to \Set \] i.e. $F(A_1, A_2, \dots, A_n)$ 604 | \item Given a (univariate) $F$ and some regular expression $R$ over 605 | $\Sigma = \{A_1, \dots, A_n\}$ 606 | \item Find a multivariate $F_R$ with the ``same shape'' as $F$ but 607 | whose sequences of elements come from a sequence of sets 608 | corresponding to $R$ 609 | \end{itemize} 610 | \end{xframe} 611 | 612 | \begin{xframe}{Example} 613 | \begin{center} 614 | \[ L(A) = 1 + A \times L(A) \] 615 | \[ R = (AA)^* \] 616 | 617 | \begin{tabular}{c m{3in}} 618 | % $L(\N) =$ & 619 | % \begin{diagram}[width=200] 620 | % import Diagrams 621 | 622 | % dia = lsD # frame 0.5 623 | % \end{diagram} 624 | % \\ 625 | $L_R(\N) =$ & 626 | \begin{diagram}[width=200] 627 | import Diagrams 628 | 629 | ls2 = [[], [3,4 :: Int], [1,4,2,6], [3,9,2,0,8,4]] 630 | 631 | dia = vsep 1 (map drawList ls2) # frame 0.5 632 | \end{diagram} 633 | \end{tabular} 634 | \end{center} 635 | 636 | \end{xframe} 637 | 638 | \begin{xframe}{Example} 639 | \[ P = X + P^2 \] 640 | \[ R = a^*ha^* \] 641 | \begin{center} 642 | \includegraphics[width=2in]{deriv-tree} 643 | 644 | \onslide<2-> \dots this is just differentiation! 645 | \end{center} 646 | \end{xframe} 647 | 648 | \begin{xframe}{Example} 649 | \[ P = X + P^2 \] 650 | \[ R = b^*ha^* \] 651 | \begin{center} 652 | \includegraphics[width=2in]{dissect-tree} 653 | 654 | \onslide<2-> This is called a ``dissection'' and corresponds to 655 | \emph{divided difference}. 656 | \end{center} 657 | \end{xframe} 658 | 659 | \begin{xframe}{The problem} 660 | \begin{center} 661 | \textbf{Given a polynomial functor $F$ and regular expression $R$, compute 662 | a (system of mutually recursive, multivariate) polynomial functor(s) 663 | corresponding to $F$ constrained by $R$.} 664 | \end{center} 665 | \end{xframe} 666 | 667 | \section{The solution} 668 | 669 | \begin{xframe}{DFAs} 670 | \begin{center} 671 | \textbf{D}eterministic \textbf{F}inite \textbf{A}utomata \bigskip 672 | 673 | \includegraphics[width=2in]{example-DFA} 674 | 675 | DFAs = machines for identifying sequences 676 | \end{center} 677 | \end{xframe} 678 | 679 | \begin{xframe}{Punchline \#1} 680 | DFAs and regular expressions are ``about the same thing''! (Kleene, 681 | 1951) \bigskip 682 | 683 | Every regular expression has a corresponding DFA (and vice versa). 684 | \end{xframe} 685 | 686 | \begin{xframe}{Example} 687 | \begin{center} 688 | \includegraphics[width=2in]{even-DFA} 689 | 690 | \[ (aa)^* \] 691 | \end{center} 692 | \end{xframe} 693 | 694 | \begin{xframe}{Example} 695 | \begin{center} 696 | \includegraphics[width=2in]{deriv-DFA} 697 | 698 | \[ a^*ha^* \] 699 | \end{center} 700 | \end{xframe} 701 | 702 | \begin{xframe}{The setup} 703 | Given: 704 | \begin{itemize} 705 | \item Polynomial functor $F$ 706 | \item DFA $D$ 707 | \end{itemize} \medskip 708 | 709 | \onslide<2-> 710 | Let $F_{ij}$ denote the (multivariate) polynomial functor 711 | \begin{itemize} 712 | \item with same shape as $F$ 713 | \item constrained by sequences which take the DFA from state $i$ 714 | to state $j$ 715 | \end{itemize} \medskip 716 | 717 | \onslide<3-> 718 | Ultimately we are interested in $\sum_{q \in \mathrm{final}(D)} F_{1q}$. 719 | \end{xframe} 720 | 721 | % XXX if time 722 | % \begin{xframe}{Example} 723 | % XXX Show derivative DFA and all $T_{ij}$ 724 | % \end{xframe} 725 | 726 | \begin{xframe} 727 | \begin{itemize} 728 | \item<+-> $0_{ij} = 0$ ($0$ is the only thing with the same shape 729 | (i.e. none) as $0$) 730 | \item<+-> $ 1_{ij} = \begin{cases} 1 \quad i = j \\ 0 \quad i \neq 731 | j \end{cases}$ 732 | \item<+-> $X_{ij} = \text{(sum of) edge(s) from $i$ to $j$}$ 733 | \item<+-> $(F + G)_{ij} = F_{ij} + G_{ij}$ 734 | \item<+-> $(F \cdot G)_{ij} = \sum_{q \in \mathrm{states}(D)} F_{iq} G_{qj}$ 735 | \end{itemize} \bigskip 736 | 737 | \onslide<6-> These are just the definitions of matrix operations! 738 | \end{xframe} 739 | 740 | \begin{xframe} 741 | %% XXX reword etc. 742 | \begin{center} 743 | This is a \emph{semiring homomorphism} from polynomial functors to 744 | $n \times n$ matrices of (arity-$|\Sigma|$) polynomial functors! 745 | \end{center} 746 | \end{xframe} 747 | 748 | \begin{xframe}{Example} 749 | \[ L = 1 + XL, R = (aa)^* \] 750 | \begin{center} 751 | \includegraphics[width=1in]{even-DFA} \\ 752 | Transition matrix = $\begin{bmatrix} 753 | 0 & a \\ a & 0 754 | \end{bmatrix}$ 755 | 756 | \begin{multline*} 757 | \begin{bmatrix} 758 | L_{11} & L_{12} \\ 759 | L_{21} & L_{22} 760 | \end{bmatrix} 761 | = 762 | \begin{bmatrix} 763 | 1 & 0 \\ 764 | 0 & 1 765 | \end{bmatrix} 766 | + 767 | \begin{bmatrix} 768 | 0 & a \\ 769 | a & 0 770 | \end{bmatrix} 771 | \begin{bmatrix} 772 | L_{11} & L_{12} \\ 773 | L_{21} & L_{22} 774 | \end{bmatrix} 775 | \\ 776 | = 777 | \begin{bmatrix} 778 | 1 + a L_{21} & a L_{22} \\ 779 | a L_{11} & 1+ a L_{12} 780 | \end{bmatrix}. 781 | \end{multline*} 782 | \end{center} 783 | \end{xframe} 784 | 785 | \begin{xframe}{Example} 786 | \[ T = 1 + XT^2, R = a^*ha^* \] 787 | \begin{center} 788 | \includegraphics[width=1in]{deriv-DFA} \\ 789 | Transition matrix = $\begin{bmatrix} 790 | a & h \\ 0 & a 791 | \end{bmatrix}$ 792 | 793 | \begin{multline*} 794 | \begin{bmatrix} 795 | T_{11} & T_{12} \\ 796 | 0 & T_{22} 797 | \end{bmatrix} 798 | = 799 | \begin{bmatrix} 800 | 1 & 0 \\ 801 | 0 & 1 802 | \end{bmatrix} 803 | + 804 | \begin{bmatrix} 805 | a & h \\ 806 | 0 & a 807 | \end{bmatrix} 808 | \begin{bmatrix} 809 | T_{11} & T_{12} \\ 810 | 0 & T_{22} 811 | \end{bmatrix}^2 812 | \\ 813 | = 814 | \begin{bmatrix} 815 | a T_{11}^2 & a(T_{11}T_{12} + T_{12}T_{22}) + hT_{22}^2 \\ 816 | 0 & a T_{22}^2 817 | \end{bmatrix}. 818 | \end{multline*} 819 | \end{center} 820 | \end{xframe} 821 | 822 | \begin{xframe} 823 | \begin{center} 824 | Thank you! \bigskip 825 | 826 | \includegraphics[width=1in]{deriv-tree} 827 | 828 | % XXX TODO include picture of publication first page 829 | \end{center} 830 | \end{xframe} 831 | 832 | \end{document} -------------------------------------------------------------------------------- /talks/mpc-15/type-matrices-mpc-15.lhs: -------------------------------------------------------------------------------- 1 | %% -*- mode: LaTeX; compile-command: "cabal exec runhaskell Shake.hs" -*- 2 | \documentclass[xcolor=svgnames,12pt]{beamer} 3 | 4 | %include polycode.fmt 5 | 6 | %format Dissect = "\dissect" 7 | %format <-> = "\cong" 8 | %format * = "\times" 9 | 10 | \usepackage[all]{xy} 11 | \usepackage{brent} 12 | \usepackage{xspace} 13 | \usepackage[backend=pgf,extension=pgf,input,outputdir=diagrams]{diagrams-latex} 14 | \graphicspath{{images/}{../../symbols/}} 15 | 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | 19 | % Math typesetting 20 | 21 | %% a bit more space for matrices 22 | \setlength{\arraycolsep}{5pt} 23 | 24 | % regular expression alternation/choice operator 25 | \newcommand{\realt}{+} 26 | 27 | \newcommand{\sem}[1]{\ensuremath{\left\llbracket #1 \right\rrbracket}} 28 | 29 | % \newcommand{\m}[1]{\mathbf{#1}} 30 | \newcommand{\m}[1]{\left[ {#1} \right]} 31 | \newcommand{\mD}[1]{\m{#1}_D} 32 | 33 | \newcommand{\dissect}{\includegraphics{Dissect}} 34 | \newcommand{\clowns}{\includegraphics{Clowns}} 35 | \newcommand{\jokers}{\includegraphics{Jokers}} 36 | 37 | \newcommand{\Type}{\ensuremath{\mathbf{Type}}} 38 | 39 | \newcommand{\sprod}{\bullet} 40 | 41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 43 | 44 | \newcommand{\etc}{\textit{etc.}} 45 | \renewcommand{\eg}{\textit{e.g.}\xspace} 46 | \renewcommand{\ie}{\textit{i.e.}\xspace} 47 | 48 | \newcommand{\theschool}{Mathematics of Program Construction} 49 | \newcommand{\thelocation}{K\"onigswinter, Germany} 50 | \newcommand{\thedate}{29 June 2015} 51 | 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 53 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 54 | 55 | \setbeamertemplate{items}[circle] 56 | 57 | \mode 58 | { 59 | \usetheme{default} % use a default (plain) theme 60 | 61 | \setbeamertemplate{navigation symbols}{} % don't show navigation 62 | % buttons along the 63 | % bottom 64 | \setbeamerfont{normal text}{family=\sffamily} 65 | 66 | % XX remove this before giving actual talk! 67 | % \setbeamertemplate{footline}[frame number] 68 | % {% 69 | % \begin{beamercolorbox}{section in head/foot} 70 | % \vskip2pt 71 | % \hfill \insertframenumber 72 | % \vskip2pt 73 | % \end{beamercolorbox} 74 | % } 75 | 76 | \AtBeginSection[] 77 | { 78 | \begin{frame} 79 | \frametitle{} 80 | 81 | \begin{center} 82 | % \includegraphics[width=2in]{\sectionimg} 83 | % \bigskip 84 | 85 | {\Huge \insertsectionhead} 86 | \end{center} 87 | \end{frame} 88 | } 89 | } 90 | 91 | \defbeamertemplate*{title page}{customized}[1][] 92 | { 93 | \vbox{} 94 | \vfill 95 | \begin{centering} 96 | \begin{beamercolorbox}[sep=8pt,center,#1]{title} 97 | \usebeamerfont{title}\inserttitle\par% 98 | \ifx\insertsubtitle\@@empty% 99 | \else% 100 | \vskip0.25em% 101 | {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 102 | \fi% 103 | \end{beamercolorbox}% 104 | \vskip1em\par 105 | {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par} 106 | \vskip1em\par 107 | \begin{beamercolorbox}[sep=8pt,center,#1]{author} 108 | \usebeamerfont{author}\insertauthor 109 | \end{beamercolorbox} 110 | \begin{beamercolorbox}[sep=8pt,center,#1]{institute} 111 | \usebeamerfont{institute}\insertinstitute 112 | \end{beamercolorbox} 113 | \begin{beamercolorbox}[sep=8pt,center,#1]{date} 114 | \usebeamerfont{date}\insertdate 115 | \end{beamercolorbox} 116 | \end{centering} 117 | \vfill 118 | } 119 | 120 | \newenvironment{xframe}[1][] 121 | {\begin{frame}[fragile,environment=xframe,#1]} 122 | {\end{frame}} 123 | 124 | % uncomment me to get 4 slides per page for printing 125 | % \usepackage{pgfpages} 126 | % \pgfpagesuselayout{4 on 1}[uspaper, border shrink=5mm] 127 | 128 | % \setbeameroption{show only notes} 129 | 130 | \renewcommand{\emph}{\textbf} 131 | 132 | \title{Polynomial Functors Constrained by Regular Expressions} 133 | \date{\theschool \\ \thelocation \\ \thedate} 134 | \author{Dan Piponi \and \usebeamercolor[fg]{title}{Brent Yorgey}} 135 | \titlegraphic{\includegraphics[width=1in]{deriv-tree}} 136 | 137 | % Abstract 138 | % 139 | % Algebraic data types are central to typed functional programming, 140 | % sitting at a happy intersection of theory and practice. I will 141 | % define and give examples of algebraic data types, and then go on to 142 | % explain what is meant by the derivative of an algebraic data type. 143 | % In the second part of the talk I will show how to constrain 144 | % algebraic data types by a given regular expression, including 145 | % finding derivatives a special case. No particular background is 146 | % assumed; my goal is to convey not a particular result per se, but 147 | % rather an appreciation for some of the beautiful overlap between 148 | % algebra, combinatorics, calculus, and computer science. 149 | 150 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 151 | 152 | \begin{document} 153 | 154 | \begin{xframe}{} 155 | \titlepage 156 | \end{xframe} 157 | 158 | % \begin{xframe} 159 | % \begin{center} 160 | % Joint work with Dan Piponi \bigskip 161 | 162 | % \includegraphics[width=3in]{dan} \\ 163 | % \end{center} 164 | % \end{xframe} 165 | 166 | \section{Introduction \& Motivation} 167 | \label{sec:intro} 168 | 169 | \begin{xframe}{What this talk is about} 170 | \begin{center} 171 | \begin{diagram}[width=150] 172 | dia = mconcat 173 | [ atPoints (triangle 20) 174 | $ map text -- $ 175 | [ "polynomial functors" 176 | , "linear algebra" 177 | , "regular expressions" ] 178 | , triangle 20 179 | # explodePath 180 | # concat 181 | # map (strokeLocTrail . doAdjust) 182 | # mconcat 183 | , text "semirings" 184 | ] 185 | where 186 | doAdjust locTr = adjust locTr opts 187 | where 188 | opts = with & adjMethod .~ ByAbsolute adjLen 189 | & adjSide .~ Both 190 | adjLen || angleBetweenDirs 191 | xDir 192 | (direction (tangentAtStart locTr)) 193 | < (1/20 @@@@ turn) 194 | = -15 195 | || otherwise = -5 196 | \end{diagram} 197 | \end{center} 198 | \end{xframe} 199 | 200 | \begin{xframe}{Motivation} 201 | \begin{center} 202 | Recall that ``the \emph{derivative} of a type is its type of 203 | one-hole contexts'' (Huet, McBride, Joyal, \etc). 204 | \end{center} 205 | 206 | \begin{center} 207 | \begin{diagram}[width=200] 208 | import Diagrams 209 | tree1 = drawTree (trees !! 3) # frame 0.5 210 | tree2 = drawNTree (poke 3 (trees !! 3)) # frame 0.5 211 | dia = hsep 2 $ -- $ 212 | map centerY 213 | [ tree1, strutX 0.5, text "$\\in T(\\N)$" # scale 1.5 214 | , strutX 5 215 | , tree2, strutX 0.5, text "$\\in \\partial T(\\N)$" # scale 1.5 216 | ] 217 | \end{diagram} 218 | \end{center} 219 | \begin{center} 220 | Application: \emph{zippers} 221 | \end{center} 222 | \end{xframe} 223 | 224 | \begin{xframe}{Motivation} 225 | \begin{center} 226 | Recall also \emph{dissection} (McBride, \textit{Clowns \& Jokers}). 227 | \end{center} 228 | 229 | \begin{center} 230 | \begin{diagram}[width=250] 231 | import Diagrams 232 | import Diagrams.TwoD.Layout.Tree 233 | import Data.Char 234 | 235 | tree1 = drawTree (trees !! 3) # frame 0.5 236 | tree2 = drawNCTree (poke 4 (trees !! 3)) # frame 0.5 237 | dia = hsep 2 $ -- $ 238 | map centerY 239 | [ tree1, strutX 0.5, text "$\\in T(\\N)$" # scale 1.5 240 | , strutX 5 241 | , tree2, strutX 0.2, text "$\\in$" # scale 1.5, dissect # scale 1.7 242 | , strutX 0.5, text "$T(\\N,C)$" # scale 1.5 243 | ] 244 | ht = 1.2 245 | dissect = triangle 1 # scaleToY ht # alignB <> vrule ht # alignB 246 | 247 | drawNCTree = 248 | maybe mempty (renderTree (nodeType nil node' hole) (~~)) 249 | . symmLayoutBin' (with & slVSep .~ 3 & slHSep .~ 3) 250 | node' x = ((<> circle 1 # fc lightblue) . text) $ elt' 251 | where elt' || x < 10 = showElt (chr (ord 'a' + x)) 252 | || otherwise = showElt x 253 | \end{diagram} 254 | \end{center} 255 | 256 | % \begin{center} 257 | % \begin{diagram}[width=150] 258 | % import Diagrams.TwoD.Layout.Tree 259 | % import Data.Tree 260 | % import TypeMatricesDiagrams 261 | 262 | % t = nd 263 | % [ nd 264 | % [ nd $ 265 | % leaves [6, 7] 266 | % , lf 4 267 | % ] 268 | % , nd 269 | % [ nd 270 | % [ lf 12 271 | % , nd $ leaves [3, 5] 272 | % ] 273 | % , nd $ leaves [1, 6] 274 | % ] 275 | % ] 276 | % where nd = Node Nothing 277 | % lf x = Node (Just x) [] 278 | % leaves = map lf 279 | 280 | % dia = renderT t # frame 0.5 281 | % \end{diagram} 282 | % %$ 283 | % \end{center} 284 | 285 | \begin{center} 286 | Application: tail-recursive traversals (maps and folds) 287 | \end{center} 288 | \end{xframe} 289 | 290 | \begin{xframe}{Motivation} 291 | 292 | Questions: 293 | 294 | \begin{itemize} 295 | \item How are these related? 296 | \item Where does the definition of dissection come from? 297 | \item Where does |right| come from? 298 | \end{itemize} 299 | 300 | \begin{spec} 301 | right :: F A + (Dissect F B A * B) <-> (A * Dissect F B A) + F B 302 | \end{spec} 303 | 304 | %% XXX if time: make some pictures? 305 | 306 | \end{xframe} 307 | 308 | \section{Preliminaries} 309 | \label{sec:prelim} 310 | 311 | % \begin{xframe}{Polynomial functors} 312 | 313 | % \begin{center} 314 | % \[ F : \Set \to \Set \] 315 | % elements $\to$ structures \bigskip 316 | 317 | % \begin{diagram}[width=200] 318 | % import Data.List.Split 319 | % import Diagrams 320 | 321 | % elts = map node [1,2,3,4::Int] 322 | % eltSet = atop (roundedRect 6 6 0.5) 323 | % . centerXY 324 | % . vsep 1 . map (hsep 1) 325 | % . chunksOf 2 326 | % $ elts -- $ 327 | 328 | % dia = [eltSet, arrowV (5 ^& 0), lsD] # map centerY # hsep 2 # frame 0.5 329 | % \end{diagram} 330 | % \bigskip 331 | 332 | % \onslide<2> aka \emph{algebraic data types} 333 | % % think: \emph{(parameterized) combinatorial families} 334 | % \end{center} 335 | % \end{xframe} 336 | 337 | \begin{xframe}{Polynomial functors} 338 | Polynomial functors are those functors $F : \Set \to \Set$ (or 339 | $\Type \to \Type$) inductively built from: 340 | \begin{align*} 341 | 0(A) &= \varnothing \\ 342 | 1(A) &= \{\star\} \\ 343 | X(A) &= A \\ 344 | (F + G)(A) &= F(A) \uplus G(A) \\ 345 | (F \cdot G)(A) &= F(A) \times G(A) 346 | \end{align*} 347 | 348 | \onslide<2-> Can easily generalize to multivariate polynomial 349 | functors \[ F : \Set^n \to \Set. \] $X$ generalizes to family of 350 | projections $X_j(A_1,\dots,A_n) = A_j$. 351 | \end{xframe} 352 | 353 | \begin{xframe}{Implicit/recursive definition} 354 | We also allow mutually recursive definitions: 355 | \begin{align*} 356 | F_1 &= \Phi_1(F_1, \dots, F_n) \\ 357 | &\vdots \\ 358 | F_n &= \Phi_n(F_1, \dots, F_n) 359 | \end{align*} 360 | interpreted as a least fixed point. 361 | \end{xframe} 362 | 363 | \begin{xframe}{Regular expressions} 364 | Regular expressions are a language of ``patterns'' for strings in 365 | $\Sigma^*$ (finite sequences of elements from ``alphabet'' $\Sigma$) 366 | 367 | \begin{align*} 368 | R &::= \varnothing && \text{never matches} \\ 369 | &\mid \varepsilon && \text{empty string} \\ 370 | &\mid a \in \Sigma && \text{``a''} \\ 371 | &\mid R_1 \realt R_2 && \text{$R_1$ or $R_2$} \\ 372 | &\mid R_1R_2 && \text{$R_1$ followed by $R_2$} \\ 373 | &\mid R^* && \text{sequence of zero or more $R$} 374 | \end{align*} 375 | \end{xframe} 376 | 377 | \begin{xframe}{DFAs} 378 | \begin{center} 379 | \textbf{D}eterministic \textbf{F}inite \textbf{A}utomata \bigskip 380 | 381 | \begin{diagram}[width=150] 382 | import TypeMatricesDiagrams 383 | 384 | exampleDFA :: DFA (Diagram B, Bool) 385 | exampleDFA = dfa 386 | [ 1 --> (False, origin) 387 | , 2 --> (False, 5 ^& 0) 388 | , 3 --> (True, 10 ^& 0) 389 | , 4 --> (False, 5 ^& (-5)) 390 | ] 391 | [ 1 >-- txtN "A" --> 2 392 | , 2 >-- txtN "B" --> 1 393 | 394 | , 2 >-- txtN "A" --> 3 395 | , 3 >-- txtN "B" --> 2 396 | 397 | , 1 >-- (txt "B", True) --> 4 398 | , 3 >-- txtN "A" --> 4 399 | 400 | , 4 >-- txtN "A,B" --> 4 401 | ] 402 | 403 | txtN s = (txt s, False) 404 | 405 | dia = drawDFA exampleDFA # frame 0.5 406 | \end{diagram} 407 | \end{center} 408 | \end{xframe} 409 | 410 | \begin{xframe} 411 | 412 | \begin{center} 413 | \textbf{D}eterministic \textbf{F}inite \textbf{A}utomata \bigskip 414 | 415 | \begin{diagram}[width=150] 416 | import TypeMatricesDiagrams 417 | 418 | exampleDFA :: DFA (Diagram B) 419 | exampleDFA = dfa 420 | [ 1 --> (False, origin) 421 | , 2 --> (False, 5 ^& 0) 422 | , 3 --> (True, 10 ^& 0) 423 | ] 424 | [ 1 >-- txt "a" --> 2 425 | , 2 >-- txt "b" --> 1 426 | 427 | , 2 >-- txt "a" --> 3 428 | , 3 >-- txt "b" --> 2 429 | ] 430 | 431 | dia = drawDFA exampleDFA # frame 0.5 432 | \end{diagram} \bigskip 433 | 434 | Drop sink states; DFA halts and rejects if it can't take a step. 435 | % \medskip 436 | 437 | % \onslide<2-> 438 | % (We can also drop \emph{finiteness}.) 439 | \end{center} 440 | \end{xframe} 441 | 442 | \begin{xframe}{Regular expressions \& DFAs} 443 | Well-known: DFAs and regular expressions are ``about the same 444 | thing'' (Kleene, 1951). Every regular expression has a corresponding 445 | DFA, and vice versa. 446 | \end{xframe} 447 | 448 | \begin{xframe}{Semirings} 449 | Up to isomorphism, both polynomial functors and regular expressions 450 | form commutative \emph{semirings} (aka \emph{rigs}): 451 | 452 | \begin{itemize} 453 | \item Associative operations $+$, $\sprod$ with identities $0$, $1$ 454 | \item $+$ is commutative 455 | \item $\sprod$ distributes over $+$ 456 | \item $+$ does \emph{not} necessarily have inverses (nor $\bullet$) 457 | \end{itemize} 458 | 459 | Other examples: $(\N,+,\times)$, $(\{\mathit{true},\mathit{false}\}, 460 | \lor, \land)$, $(\R \union \{\infty\}, \max, +)$ \medskip 461 | 462 | \onslide<2-> 463 | In fact, polynomial functors and regular expressions are both 464 | \emph{star semirings}, with $x^* = 1 + x \sprod x^*$. 465 | \end{xframe} 466 | 467 | \begin{xframe}{Transition matrices for DFAs} 468 | \begin{center} 469 | \begin{tabular}{m{2in}m{2in}} 470 | \begin{center} 471 | \begin{diagram}[width=130] 472 | import TypeMatricesDiagrams 473 | 474 | exampleDFA :: DFA (Diagram B, Bool) 475 | exampleDFA = dfa 476 | [ 1 --> (False, origin) 477 | , 2 --> (False, 5 ^& 0) 478 | , 3 --> (True, 10 ^& 0) 479 | , 4 --> (False, 5 ^& (-5)) 480 | ] 481 | [ 1 >-- txtN "A" --> 2 482 | , 2 >-- txtN "B" --> 1 483 | 484 | , 2 >-- txtN "A" --> 3 485 | , 3 >-- txtN "B" --> 2 486 | 487 | , 1 >-- (txt "B", True) --> 4 488 | , 3 >-- txtN "A" --> 4 489 | 490 | , 4 >-- txtN "A,B" --> 4 491 | ] 492 | 493 | txtN s = (txt s, False) 494 | 495 | dia = drawDFA exampleDFA # frame 0.5 496 | \end{diagram} 497 | \end{center} 498 | & 499 | \[ 500 | \begin{bmatrix} 501 | \cdot & A & \cdot & B \\ 502 | B & \cdot & A & \cdot \\ 503 | \cdot & B & \cdot & A \\ 504 | \cdot & \cdot & \cdot & A+B 505 | \end{bmatrix} 506 | \] 507 | \end{tabular} 508 | 509 | \onslide<2-> Interpret edge labels in an arbitrary semiring 510 | (weighted automata theory; O'Connor 2011, Dolan 2013) 511 | \end{center} 512 | \end{xframe} 513 | 514 | \section{Constrained polynomial functors} 515 | \label{sec:constrained} 516 | 517 | \begin{xframe}{Constrained polynomial functors} 518 | \begin{itemize} 519 | \item Given a (univariate) $F$ and some regular expression $R$ over 520 | $\Sigma = \{A_1, \dots, A_n\}$ 521 | \item Want to have a restricted version $F_R$ of $F\ (A_1 + \dots + 522 | A_n)$ so the sequences of $A_i$ (obtained from an inorder 523 | traversal) always match $R$. 524 | \end{itemize} 525 | 526 | \begin{center} 527 | \begin{diagram}[width=250] 528 | import Diagrams.TwoD.Layout.Tree 529 | import Data.Tree 530 | import TypeMatricesDiagrams 531 | 532 | t1 = nd 533 | [ nd 534 | [ nd $ 535 | leaves [B, C] 536 | , lf B 537 | ] 538 | , nd 539 | [ nd 540 | [ lf A 541 | , nd $ leaves [C, C] 542 | ] 543 | , nd $ leaves [A, B] 544 | ] 545 | ] 546 | where nd = Node Nothing 547 | lf x = Node (Just x) [] 548 | leaves = map lf 549 | 550 | t2 = nd 551 | [ nd 552 | [ nd $ 553 | leaves [A, A] 554 | , lf A 555 | ] 556 | , nd 557 | [ nd 558 | [ lf B 559 | , nd $ leaves [B, C] 560 | ] 561 | , nd $ leaves [C, C] 562 | ] 563 | ] 564 | where nd = Node Nothing 565 | lf x = Node (Just x) [] 566 | leaves = map lf 567 | 568 | dia = [ vsep 3 [ renderT t1, text "$T(A+B+C)$" # scale 1.5 ] 569 | , vsep 3 [ renderT t2, text "$T_{A^*B^*C^*}(A,B,C)$" # scale 1.5 ] 570 | ] 571 | # hsep 10 # frame 0.5 572 | \end{diagram} 573 | %$ 574 | \end{center} 575 | \end{xframe} 576 | 577 | % \begin{xframe}{ 578 | % \item<2-> That is, find a multivariate $F_R$ with the ``same shape'' as $F$ but 579 | % whose allowed sequences of element types always match $R$. 580 | % \item<3-> (``Same shape'' = natural injection $F_R\ A\ \dots\ A \to F\ A$) 581 | 582 | % \end{itemize} 583 | % \end{xframe} 584 | 585 | \begin{xframe}{Example} 586 | \begin{center} 587 | \[ L = 1 + X \times L \] 588 | \[ R = (AA)^* \] 589 | 590 | \begin{tabular}{c m{3in}} 591 | $L_R(\N) =$ & 592 | \begin{diagram}[width=200] 593 | import Diagrams 594 | 595 | ls2 = [[], [3,4 :: Int], [1,4,2,6], [3,9,2,0,8,4]] 596 | 597 | dia = vsep 1 (map drawList ls2) # frame 0.5 598 | \end{diagram} 599 | \end{tabular} 600 | \end{center} 601 | \end{xframe} 602 | 603 | \begin{xframe}{Example} 604 | \[ P = X + P^2 \] 605 | \[ R = A^*HA^* \] 606 | \begin{center} 607 | \begin{tabular}{c m{3in}} 608 | $P_R(A,H) \ni$ & 609 | \begin{diagram}[width=150] 610 | import TypeMatricesDiagrams 611 | import Data.Tree 612 | 613 | t = Nothing ## 614 | [ Nothing ## 615 | [ Nothing ## 616 | leaves [ Just A, Just A ] 617 | , leaf $ Just A 618 | ] 619 | , Nothing ## 620 | [ Nothing ## 621 | [ leaf $ Just A 622 | , Nothing ## leaves [Just H, Just A] 623 | ] 624 | , Nothing ## leaves [Just A, Just A] 625 | ] 626 | ] 627 | where (##) = Node 628 | leaf x = Node x [] 629 | leaves = map leaf 630 | 631 | dia = renderT t # frame 0.5 632 | \end{diagram} 633 | \end{tabular} 634 | 635 | \onslide<2-> \dots this is differentiation! $P'(A) = P_R(A,1)$. 636 | \end{center} 637 | \end{xframe} 638 | 639 | \begin{xframe}{Example: Dissection} 640 | \[ P = X + P^2 \] 641 | \[ R = B^*HA^* \] 642 | \begin{center} 643 | \begin{diagram}[width=150] 644 | import Diagrams.TwoD.Layout.Tree 645 | import Data.Tree 646 | import TypeMatricesDiagrams 647 | 648 | t = nd 649 | [ nd 650 | [ nd $ 651 | leaves [B, B] 652 | , lf B 653 | ] 654 | , nd 655 | [ nd 656 | [ lf O 657 | , nd $ leaves [A, A] 658 | ] 659 | , nd $ leaves [A, A] 660 | ] 661 | ] 662 | where nd = Node Nothing 663 | lf x = Node (Just x) [] 664 | leaves = map lf 665 | 666 | dia = renderT t # frame 0.5 667 | \end{diagram} 668 | %$ 669 | \end{center} 670 | \end{xframe} 671 | 672 | \begin{xframe}{The problem} 673 | \begin{center} 674 | \textbf{Given a polynomial functor $F$ and regular expression $R$, 675 | compute a (system of mutually recursive, multivariate) 676 | polynomial functor(s) representing $F_R$.} 677 | \end{center} 678 | \end{xframe} 679 | 680 | \begin{xframe}{The setup} 681 | Given: 682 | \begin{itemize} 683 | \item Polynomial functor $F$ 684 | \item DFA $D$ 685 | \end{itemize} \medskip 686 | 687 | \onslide<2-> 688 | Let $F_{ij}$ denote the (multivariate) polynomial functor 689 | \begin{itemize} 690 | \item with same shape as $F$ 691 | \item constrained by sequences which take the DFA from state $i$ 692 | to state $j$ 693 | \end{itemize} \medskip 694 | 695 | \onslide<3-> 696 | Ultimately we are interested in $\sum_{q \in \mathrm{final}(D)} F_{1q}$. 697 | \end{xframe} 698 | 699 | \begin{xframe} 700 | \[ 0_{ij} = 0 \] 701 | 702 | \begin{center} 703 | $0$ is the only thing with the same shape as $0$. 704 | \end{center} 705 | \end{xframe} 706 | 707 | \begin{xframe} 708 | \[ 1_{ij} = \begin{cases} 1 \quad i = j \\ 0 \quad i \neq 709 | j \end{cases} \] 710 | 711 | \begin{center} 712 | $0$ and $1$ are the only things with the same shape as $1$. A 713 | $1$-structure doesn't make the DFA transition at all. 714 | \end{center} 715 | \end{xframe} 716 | 717 | \begin{xframe} 718 | \[ X_{ij} = \sum_{i \stackrel{A}{\to} j} X_A \] 719 | 720 | \begin{center} 721 | \begin{diagram}[width=200] 722 | import TypeMatricesDiagrams 723 | 724 | i2jDFA = 725 | mconcat 726 | [ (txt "i" <> circle 1 # fc (nodeColors !! 0)) 727 | , (txt "j" <> circle 1 # fc (nodeColors !! 1)) # translateX 5 728 | , arcArrow origin (5 ^& 0) 1 1.4 (txt "A") 729 | , arcArrow origin (5 ^& 0) (-1) 1.4 (txt "B") 730 | ] 731 | 732 | aORb = hsep 2 [ drawType A, txt "OR", drawType B ] 733 | 734 | dia = hsep 4 [i2jDFA, aORb] 735 | \end{diagram} 736 | \end{center} 737 | \end{xframe} 738 | 739 | \begin{xframe} 740 | \[ (F + G)_{ij} = F_{ij} + G_{ij} \] 741 | \bigskip 742 | 743 | \begin{center} 744 | \begin{diagram}[width=250] 745 | import TypeMatricesDiagrams 746 | 747 | i2j q0 q1 lab = mconcat 748 | [ mkNode 0 q0 749 | , mkNode 1 q1 # translateX 7 750 | ] 751 | # connectStates q0 q1 lab 1 752 | # centerX 753 | 754 | li2j = i2j "i" "j" 755 | 756 | dia = vsep 1 757 | [ li2j "$(F+G)_{ij}$" 758 | , txt "=" 759 | , hsep 2 [ li2j "$F_{ij}$", txt "OR", li2j "$G_{ij}$" ] 760 | # centerX 761 | ] 762 | \end{diagram} 763 | \end{center} 764 | \end{xframe} 765 | 766 | \begin{xframe} 767 | \[ (F \sprod G)_{ij} = \sum_{q \in \mathrm{states}(D)} F_{iq} 768 | G_{qj} \] 769 | 770 | \begin{center} 771 | \begin{diagram}[width=200] 772 | import TypeMatricesDiagrams 773 | 774 | dia = mconcat 775 | [ mkNode 0 "i" 776 | , mkNode 2 "$q_0$" # translate (7 ^& 4) 777 | , mkNode 2 "$q_1$" # translate (7 ^& 1) 778 | , vellipsis # translate (7 ^& (-1.5)) 779 | , mkNode 2 "$q_k$" # translate (7 ^& (-4)) 780 | , mkNode 1 "j" # translateX 14 781 | ] 782 | # applyAll 783 | [ connectStates "i" ("$q_" ++ x ++ "$") ("$F_{iq_" ++ x ++ "}$") off 784 | . connectStates ("$q_" ++ x ++ "$") "j" ("$G_{q_" ++ x ++ "j}$") off 785 | || (x,off) <- [("0",1), ("1",-1), ("k",-1)] 786 | ] 787 | vellipsis = vsep 0.3 (replicate 3 (circle 0.1 # fc black)) # centerY 788 | \end{diagram} 789 | \end{center} 790 | \end{xframe} 791 | 792 | \begin{xframe} 793 | \begin{align*} 794 | 0_{ij} &= 0 \\ 795 | 1_{ij} &= \begin{cases} 1 \quad i = j \\ 0 \quad i \neq 796 | j \end{cases} \\ 797 | X_{ij} &= \sum_{i \stackrel{A}{\to} j} X_A \\ 798 | (F + G)_{ij} &= F_{ij} + G_{ij} \\ 799 | (F \sprod G)_{ij} &= \sum_{q \in \mathrm{states}(D)} F_{iq} G_{qj} 800 | \end{align*} 801 | 802 | \onslide<2-> 803 | \begin{center} 804 | These are matrix operations! $X_{ij}$ is the transition matrix 805 | for the DFA, interpreted in the semiring of polynomial functors. 806 | \end{center} 807 | \end{xframe} 808 | 809 | \begin{xframe} 810 | Given a DFA $D$, 811 | \[ F \mapsto \begin{bmatrix} F_{11} & \dots & F_{1n} \\ 812 | \vdots & \ddots & \vdots \\ F_{n1} & \dots & 813 | F_{nn} \end{bmatrix} \] 814 | is a \emph{semiring homomorphism} from (unary) polynomial functors 815 | to $n \times n$ matrices of (arity-$||\Sigma||$) polynomial 816 | functors. 817 | \end{xframe} 818 | 819 | \begin{xframe}{Example} 820 | \[ L = 1 + XL \qquad R = (AA)^* \] 821 | \begin{center} 822 | \begin{tabular}{m{1in}m{1in}} 823 | \begin{center} 824 | \begin{diagram}[width=75] 825 | import TypeMatricesDiagrams 826 | 827 | aaStar :: DFA (Diagram B) 828 | aaStar = dfa 829 | [ 1 --> (True, origin) 830 | , 2 --> (False, 5 ^& 0) 831 | ] 832 | [ 1 >-- txt "A" --> 2 833 | , 2 >-- txt "A" --> 1 834 | ] 835 | 836 | dia = drawDFA aaStar # frame 0.5 837 | \end{diagram} 838 | \end{center} 839 | & 840 | \[ \begin{bmatrix} 841 | 0 & X_A \\ X_A & 0 842 | \end{bmatrix} 843 | \] 844 | \end{tabular} 845 | 846 | \begin{multline*} 847 | \begin{bmatrix} 848 | L_{11} & L_{12} \\ 849 | L_{21} & L_{22} 850 | \end{bmatrix} 851 | = 852 | \begin{bmatrix} 853 | 1 & 0 \\ 854 | 0 & 1 855 | \end{bmatrix} 856 | + 857 | \begin{bmatrix} 858 | 0 & X_A \\ 859 | X_A & 0 860 | \end{bmatrix} 861 | \begin{bmatrix} 862 | L_{11} & L_{12} \\ 863 | L_{21} & L_{22} 864 | \end{bmatrix} 865 | \\ 866 | = 867 | \begin{bmatrix} 868 | 1 + X_A L_{21} & X_A L_{22} \\ 869 | X_A L_{11} & 1+ X_A L_{12} 870 | \end{bmatrix}. 871 | \end{multline*} 872 | \end{center} 873 | \end{xframe} 874 | 875 | \begin{xframe}{Example} 876 | \[ T = 1 + XT^2 \qquad R = A^*HA^* \] 877 | \begin{center} 878 | \begin{tabular}{m{1in}m{1in}} 879 | \begin{center} 880 | \begin{center} 881 | \begin{diagram}[width=75] 882 | import TypeMatricesDiagrams 883 | 884 | aaStar :: DFA (Diagram B) 885 | aaStar = dfa 886 | [ 1 --> (False, origin) 887 | , 2 --> (True, 5 ^& 0) 888 | ] 889 | [ 1 >-- txt "H" --> 2 890 | , 1 >-- txt "A" --> 1 891 | , 2 >-- txt "A" --> 2 892 | ] 893 | 894 | dia = drawDFA aaStar # frame 0.5 895 | \end{diagram} 896 | \end{center} 897 | \end{center} 898 | & 899 | \[ \begin{bmatrix} 900 | X_A & X_H \\ 0 & X_A 901 | \end{bmatrix} \] 902 | \end{tabular} 903 | \begin{multline*} 904 | \begin{bmatrix} 905 | T_{11} & T_{12} \\ 906 | 0 & T_{22} 907 | \end{bmatrix} 908 | = 909 | \begin{bmatrix} 910 | 1 & 0 \\ 911 | 0 & 1 912 | \end{bmatrix} 913 | + 914 | \begin{bmatrix} 915 | X_A & X_H \\ 916 | 0 & X_A 917 | \end{bmatrix} 918 | \begin{bmatrix} 919 | T_{11} & T_{12} \\ 920 | 0 & T_{22} 921 | \end{bmatrix}^2 922 | \\ 923 | = 924 | \begin{bmatrix} 925 | X_A T_{11}^2 & X_A(T_{11}T_{12} + T_{12}T_{22}) + X_HT_{22}^2 \\ 926 | 0 & X_A T_{22}^2 927 | \end{bmatrix}. 928 | \end{multline*} 929 | \end{center} 930 | \end{xframe} 931 | 932 | \section{Derivative and dissection} 933 | \label{sec:deriv-dissect} 934 | 935 | \begin{xframe}{Derivative} 936 | \begin{center} 937 | \begin{tabular}{m{1in}m{1in}} 938 | \begin{diagram}[width=75] 939 | import TypeMatricesDiagrams 940 | 941 | deriv :: DFA (Diagram B) 942 | deriv = dfa 943 | [ 1 --> (False, origin) 944 | , 2 --> (True , 5 ^& 0) 945 | ] 946 | [ 1 >-- txt "A" --> 1 947 | , 1 >-- txt "H" --> 2 948 | , 2 >-- txt "A" --> 2 949 | ] 950 | 951 | dia = drawDFA deriv # frame 0.5 952 | \end{diagram} 953 | & 954 | \[ 955 | \begin{bmatrix} 956 | X_A & X_H \\ 0 & X_A 957 | \end{bmatrix} 958 | \] 959 | \end{tabular} 960 | \end{center} 961 | \[ F \mapsto 962 | \begin{bmatrix} 963 | F & F' \\ 0 & F 964 | \end{bmatrix} 965 | \] 966 | 967 | \onslide<2-> 968 | \[ 969 | \begin{bmatrix} 970 | F & F' \\ 0 & F 971 | \end{bmatrix} 972 | \begin{bmatrix} 973 | G & G' \\ 0 & G 974 | \end{bmatrix} 975 | = 976 | \begin{bmatrix} 977 | FG & FG' + F'G \\ 978 | 0 & FG 979 | \end{bmatrix} 980 | \] 981 | \end{xframe} 982 | 983 | \begin{xframe}{Dissection} 984 | \begin{center} 985 | \begin{diagram}[width=100] 986 | import Diagrams.TwoD.Layout.Tree 987 | import Data.Tree 988 | import TypeMatricesDiagrams 989 | 990 | t = nd 991 | [ nd 992 | [ nd $ 993 | leaves [B, B] 994 | , lf B 995 | ] 996 | , nd 997 | [ nd 998 | [ lf H 999 | , nd $ leaves [A, A] 1000 | ] 1001 | , nd $ leaves [A, A] 1002 | ] 1003 | ] 1004 | where nd = Node Nothing 1005 | lf x = Node (Just x) [] 1006 | leaves = map lf 1007 | 1008 | dia = renderT t # frame 0.5 1009 | \end{diagram} 1010 | %$ 1011 | 1012 | \begin{tabular}{m{1.5in}m{1.5in}} 1013 | \begin{diagram}[width=75] 1014 | import TypeMatricesDiagrams 1015 | 1016 | bstarhastar :: DFA (Diagram B) 1017 | bstarhastar = dfa 1018 | [ 1 --> (False, origin) 1019 | , 2 --> (True, 5 ^& 0) 1020 | ] 1021 | [ 1 >-- txt "H" --> 2 1022 | 1023 | , 1 >-- txt "B" --> 1 1024 | , 2 >-- txt "A" --> 2 1025 | ] 1026 | 1027 | dia = drawDFA bstarhastar # frame 0.5 1028 | \end{diagram} 1029 | & 1030 | \[ 1031 | \begin{bmatrix} 1032 | X_B & X_H \\ 1033 | 0 & X_A 1034 | \end{bmatrix} 1035 | \] 1036 | \end{tabular} 1037 | \[ 1038 | F \mapsto 1039 | \begin{bmatrix} 1040 | \clowns F & \dissect F \\ 0 & \jokers F 1041 | \end{bmatrix} 1042 | \qquad 1043 | \left( \begin{array}{c}\clowns F\ B\ A = F\ B \\ \jokers F\ B\ A 1044 | = F\ A\end{array} \right) 1045 | \] 1046 | \end{center} 1047 | \end{xframe} 1048 | 1049 | \begin{xframe}{Dissection} 1050 | \[ \dissect (FG) = \clowns F \dissect G + \dissect F \clowns G \] 1051 | 1052 | \onslide<2-> 1053 | \[ 1054 | \begin{bmatrix} 1055 | \clowns F & \dissect F \\ 1056 | 0 & \jokers F 1057 | \end{bmatrix} 1058 | \begin{bmatrix} 1059 | \clowns G & \dissect G \\ 1060 | 0 & \jokers G 1061 | \end{bmatrix} 1062 | = 1063 | \begin{bmatrix} 1064 | \clowns F \clowns G & \clowns F \dissect G + \dissect F \jokers G 1065 | \\ 1066 | 0 & \jokers F \jokers G 1067 | \end{bmatrix} 1068 | \] 1069 | \end{xframe} 1070 | 1071 | \begin{xframe}{Divided differences} 1072 | \[ f_{b,a} = \frac{f_b - f_a}{b - a} \] 1073 | 1074 | \onslide<2-> 1075 | $f_{b,a}$ is the \emph{average} change in $f$ from $a$ to $b$, \ie 1076 | the secant slope. \medskip 1077 | 1078 | Note $f_{b,a} \to f'(a)$ as $b \to a$. 1079 | \end{xframe} 1080 | 1081 | \begin{xframe}{Divided differences and dissection?} 1082 | \onslide<2-> 1083 | Well-known that 1084 | \[ f \mapsto 1085 | \begin{bmatrix} 1086 | f_b & f_{b,a} \\ 0 & f_a 1087 | \end{bmatrix} 1088 | \] 1089 | is a semiring homomorphism. \medskip 1090 | 1091 | Proof (interesting bit): 1092 | \begin{align*} 1093 | (fg)_{b,a} &= \frac{(fg)_b - (fg)_a}{b - a} \\ 1094 | &= \frac{(fg)_b - f_bg_a + f_bg_a - (fg)_a}{b-a} \\ 1095 | &= \frac{f_b(g_b - g_a) + (f_b - f_a)g_a}{b-a} \\ 1096 | &= f_b g_{b,a} + f_{b,a} g_a. 1097 | \end{align*} 1098 | \end{xframe} 1099 | 1100 | \begin{xframe}{Divided differences and |right|} 1101 | Rearranging $f_{b,a} = \frac{f_b - f_a}{b - a}$ yields 1102 | \[ f_a + f_{b,a} \times b = a \times f_{b,a} + f_b \] 1103 | aka 1104 | \begin{spec} 1105 | right :: F A + (Dissect F B A * B) <-> (A * Dissect F B A) + F B 1106 | \end{spec} 1107 | \end{xframe} 1108 | 1109 | \begin{xframe}{Higher-order divided differences?} 1110 | \begin{equation*} 1111 | f \mapsto 1112 | \begin{bmatrix} 1113 | f_c & f_{c,b} & f_{c,b,a} \\ 1114 | 0 & f_b & f_{b,a} \\ 1115 | 0 & 0 & f_a 1116 | \end{bmatrix} 1117 | \end{equation*} 1118 | 1119 | \onslide<2-> 1120 | \begin{center} 1121 | \begin{tabular}{m{1.5in}m{1.5in}} 1122 | \begin{center} 1123 | \begin{diagram}[width=100] 1124 | import TypeMatricesDiagrams 1125 | 1126 | deriv :: DFA (Diagram B) 1127 | deriv = dfa 1128 | [ 1 --> (False, origin) 1129 | , 2 --> (False, 5 ^& 0) 1130 | , 3 --> (True , 10 ^& 0) 1131 | ] 1132 | [ 1 >-- txt "c" --> 1 1133 | , 1 >-- txt "h" --> 2 1134 | , 2 >-- txt "b" --> 2 1135 | , 2 >-- txt "h" --> 3 1136 | , 3 >-- txt "a" --> 3 1137 | ] 1138 | 1139 | dia = drawDFA deriv # frame 0.5 1140 | \end{diagram} 1141 | \end{center} 1142 | & 1143 | \begin{center} 1144 | \begin{diagram}[width=100] 1145 | import Diagrams.TwoD.Layout.Tree 1146 | import Data.Tree 1147 | import TypeMatricesDiagrams 1148 | 1149 | t = nd 1150 | [ nd 1151 | [ nd $ 1152 | leaves [C, C] 1153 | , lf H 1154 | ] 1155 | , nd 1156 | [ nd 1157 | [ lf B 1158 | , nd $ leaves [B, B] 1159 | ] 1160 | , nd $ leaves [H, A] 1161 | ] 1162 | ] 1163 | where nd = Node Nothing 1164 | lf x = Node (Just x) [] 1165 | leaves = map lf 1166 | 1167 | dia = renderT t # frame 0.5 1168 | \end{diagram} 1169 | %$ 1170 | \end{center} 1171 | 1172 | \end{tabular} 1173 | \end{center} 1174 | 1175 | \end{xframe} 1176 | 1177 | \begin{xframe}{Higher-order divided differences?} 1178 | \begin{equation*} 1179 | f_{x_n \dots x_0} = \frac{f_{x_n 1180 | \dots x_1} - f_{x_{n-1} \dots x_0}}{x_n - x_0}. 1181 | \end{equation*} 1182 | 1183 | Corresponding isomorphism?? 1184 | \end{xframe} 1185 | 1186 | \begin{xframe} 1187 | \begin{center} 1188 | Thank you! \bigskip 1189 | 1190 | \includegraphics[width=1in]{deriv-tree} 1191 | \end{center} 1192 | \end{xframe} 1193 | 1194 | % \begin{xframe}{Derivative} 1195 | % \[ 1196 | % \begin{bmatrix} 1197 | % X_A & X_H \\ 0 & X_A 1198 | % \end{bmatrix} 1199 | % = 1200 | % X_A I + 1201 | % \begin{bmatrix} 1202 | % 0 & X_H \\ 0 & 0 1203 | % \end{bmatrix} 1204 | % = X_A I + d 1205 | % \] 1206 | % \begin{center} 1207 | % Note $d^2 = 0$. \[ (X_A I + d)^n \cong (X_A I)^n + n(X_A I)^{n-1} 1208 | % d \] 1209 | % XXX extend to polynomial??? Maybe I should just leave this part out? 1210 | % \end{center} 1211 | 1212 | % \end{xframe} 1213 | 1214 | \end{document} -------------------------------------------------------------------------------- /llncs/llncs.dem: -------------------------------------------------------------------------------- 1 | % This is LLNCS.DEM the demonstration file of 2 | % the LaTeX macro package from Springer-Verlag 3 | % for Lecture Notes in Computer Science, 4 | % version 2.4 for LaTeX2e as of 16. April 2010 5 | % 6 | \documentclass{llncs} 7 | % 8 | \usepackage{makeidx} % allows for indexgeneration 9 | % 10 | \begin{document} 11 | % 12 | \frontmatter % for the preliminaries 13 | % 14 | \pagestyle{headings} % switches on printing of running heads 15 | \addtocmark{Hamiltonian Mechanics} % additional mark in the TOC 16 | % 17 | \chapter*{Preface} 18 | % 19 | This textbook is intended for use by students of physics, physical 20 | chemistry, and theoretical chemistry. The reader is presumed to have a 21 | basic knowledge of atomic and quantum physics at the level provided, for 22 | example, by the first few chapters in our book {\it The Physics of Atoms 23 | and Quanta}. The student of physics will find here material which should 24 | be included in the basic education of every physicist. This book should 25 | furthermore allow students to acquire an appreciation of the breadth and 26 | variety within the field of molecular physics and its future as a 27 | fascinating area of research. 28 | 29 | For the student of chemistry, the concepts introduced in this book will 30 | provide a theoretical framework for that entire field of study. With the 31 | help of these concepts, it is at least in principle possible to reduce 32 | the enormous body of empirical chemical knowledge to a few basic 33 | principles: those of quantum mechanics. In addition, modern physical 34 | methods whose fundamentals are introduced here are becoming increasingly 35 | important in chemistry and now represent indispensable tools for the 36 | chemist. As examples, we might mention the structural analysis of 37 | complex organic compounds, spectroscopic investigation of very rapid 38 | reaction processes or, as a practical application, the remote detection 39 | of pollutants in the air. 40 | 41 | \vspace{1cm} 42 | \begin{flushright}\noindent 43 | April 1995\hfill Walter Olthoff\\ 44 | Program Chair\\ 45 | ECOOP'95 46 | \end{flushright} 47 | % 48 | \chapter*{Organization} 49 | ECOOP'95 is organized by the department of Computer Science, Univeristy 50 | of \AA rhus and AITO (association Internationa pour les Technologie 51 | Object) in cooperation with ACM/SIGPLAN. 52 | % 53 | \section*{Executive Commitee} 54 | \begin{tabular}{@{}p{5cm}@{}p{7.2cm}@{}} 55 | Conference Chair:&Ole Lehrmann Madsen (\AA rhus University, DK)\\ 56 | Program Chair: &Walter Olthoff (DFKI GmbH, Germany)\\ 57 | Organizing Chair:&J\o rgen Lindskov Knudsen (\AA rhus University, DK)\\ 58 | Tutorials:&Birger M\o ller-Pedersen\hfil\break 59 | (Norwegian Computing Center, Norway)\\ 60 | Workshops:&Eric Jul (University of Kopenhagen, Denmark)\\ 61 | Panels:&Boris Magnusson (Lund University, Sweden)\\ 62 | Exhibition:&Elmer Sandvad (\AA rhus University, DK)\\ 63 | Demonstrations:&Kurt N\o rdmark (\AA rhus University, DK) 64 | \end{tabular} 65 | % 66 | \section*{Program Commitee} 67 | \begin{tabular}{@{}p{5cm}@{}p{7.2cm}@{}} 68 | Conference Chair:&Ole Lehrmann Madsen (\AA rhus University, DK)\\ 69 | Program Chair: &Walter Olthoff (DFKI GmbH, Germany)\\ 70 | Organizing Chair:&J\o rgen Lindskov Knudsen (\AA rhus University, DK)\\ 71 | Tutorials:&Birger M\o ller-Pedersen\hfil\break 72 | (Norwegian Computing Center, Norway)\\ 73 | Workshops:&Eric Jul (University of Kopenhagen, Denmark)\\ 74 | Panels:&Boris Magnusson (Lund University, Sweden)\\ 75 | Exhibition:&Elmer Sandvad (\AA rhus University, DK)\\ 76 | Demonstrations:&Kurt N\o rdmark (\AA rhus University, DK) 77 | \end{tabular} 78 | % 79 | \begin{multicols}{3}[\section*{Referees}] 80 | V.~Andreev\\ 81 | B\"arwolff\\ 82 | E.~Barrelet\\ 83 | H.P.~Beck\\ 84 | G.~Bernardi\\ 85 | E.~Binder\\ 86 | P.C.~Bosetti\\ 87 | Braunschweig\\ 88 | F.W.~B\"usser\\ 89 | T.~Carli\\ 90 | A.B.~Clegg\\ 91 | G.~Cozzika\\ 92 | S.~Dagoret\\ 93 | Del~Buono\\ 94 | P.~Dingus\\ 95 | H.~Duhm\\ 96 | J.~Ebert\\ 97 | S.~Eichenberger\\ 98 | R.J.~Ellison\\ 99 | Feltesse\\ 100 | W.~Flauger\\ 101 | A.~Fomenko\\ 102 | G.~Franke\\ 103 | J.~Garvey\\ 104 | M.~Gennis\\ 105 | L.~Goerlich\\ 106 | P.~Goritchev\\ 107 | H.~Greif\\ 108 | E.M.~Hanlon\\ 109 | R.~Haydar\\ 110 | R.C.W.~Henderso\\ 111 | P.~Hill\\ 112 | H.~Hufnagel\\ 113 | A.~Jacholkowska\\ 114 | Johannsen\\ 115 | S.~Kasarian\\ 116 | I.R.~Kenyon\\ 117 | C.~Kleinwort\\ 118 | T.~K\"ohler\\ 119 | S.D.~Kolya\\ 120 | P.~Kostka\\ 121 | U.~Kr\"uger\\ 122 | J.~Kurzh\"ofer\\ 123 | M.P.J.~Landon\\ 124 | A.~Lebedev\\ 125 | Ch.~Ley\\ 126 | F.~Linsel\\ 127 | H.~Lohmand\\ 128 | Martin\\ 129 | S.~Masson\\ 130 | K.~Meier\\ 131 | C.A.~Meyer\\ 132 | S.~Mikocki\\ 133 | J.V.~Morris\\ 134 | B.~Naroska\\ 135 | Nguyen\\ 136 | U.~Obrock\\ 137 | G.D.~Patel\\ 138 | Ch.~Pichler\\ 139 | S.~Prell\\ 140 | F.~Raupach\\ 141 | V.~Riech\\ 142 | P.~Robmann\\ 143 | N.~Sahlmann\\ 144 | P.~Schleper\\ 145 | Sch\"oning\\ 146 | B.~Schwab\\ 147 | A.~Semenov\\ 148 | G.~Siegmon\\ 149 | J.R.~Smith\\ 150 | M.~Steenbock\\ 151 | U.~Straumann\\ 152 | C.~Thiebaux\\ 153 | P.~Van~Esch\\ 154 | from Yerevan Ph\\ 155 | L.R.~West\\ 156 | G.-G.~Winter\\ 157 | T.P.~Yiou\\ 158 | M.~Zimmer\end{multicols} 159 | % 160 | \section*{Sponsoring Institutions} 161 | % 162 | Bernauer-Budiman Inc., Reading, Mass.\\ 163 | The Hofmann-International Company, San Louis Obispo, Cal.\\ 164 | Kramer Industries, Heidelberg, Germany 165 | % 166 | \tableofcontents 167 | % 168 | \mainmatter % start of the contributions 169 | % 170 | \title{Hamiltonian Mechanics unter besonderer Ber\"ucksichtigung der 171 | h\"ohreren Lehranstalten} 172 | % 173 | \titlerunning{Hamiltonian Mechanics} % abbreviated title (for running head) 174 | % also used for the TOC unless 175 | % \toctitle is used 176 | % 177 | \author{Ivar Ekeland\inst{1} \and Roger Temam\inst{2} 178 | Jeffrey Dean \and David Grove \and Craig Chambers \and Kim~B.~Bruce \and 179 | Elsa Bertino} 180 | % 181 | \authorrunning{Ivar Ekeland et al.} % abbreviated author list (for running head) 182 | % 183 | %%%% list of authors for the TOC (use if author list has to be modified) 184 | \tocauthor{Ivar Ekeland, Roger Temam, Jeffrey Dean, David Grove, 185 | Craig Chambers, Kim B. Bruce, and Elisa Bertino} 186 | % 187 | \institute{Princeton University, Princeton NJ 08544, USA,\\ 188 | \email{I.Ekeland@princeton.edu},\\ WWW home page: 189 | \texttt{http://users/\homedir iekeland/web/welcome.html} 190 | \and 191 | Universit\'{e} de Paris-Sud, 192 | Laboratoire d'Analyse Num\'{e}rique, B\^{a}timent 425,\\ 193 | F-91405 Orsay Cedex, France} 194 | 195 | \maketitle % typeset the title of the contribution 196 | 197 | \begin{abstract} 198 | The abstract should summarize the contents of the paper 199 | using at least 70 and at most 150 words. It will be set in 9-point 200 | font size and be inset 1.0 cm from the right and left margins. 201 | There will be two blank lines before and after the Abstract. \dots 202 | \keywords{computational geometry, graph theory, Hamilton cycles} 203 | \end{abstract} 204 | % 205 | \section{Fixed-Period Problems: The Sublinear Case} 206 | % 207 | With this chapter, the preliminaries are over, and we begin the search 208 | for periodic solutions to Hamiltonian systems. All this will be done in 209 | the convex case; that is, we shall study the boundary-value problem 210 | \begin{eqnarray*} 211 | \dot{x}&=&JH' (t,x)\\ 212 | x(0) &=& x(T) 213 | \end{eqnarray*} 214 | with $H(t,\cdot)$ a convex function of $x$, going to $+\infty$ when 215 | $\left\|x\right\| \to \infty$. 216 | 217 | % 218 | \subsection{Autonomous Systems} 219 | % 220 | In this section, we will consider the case when the Hamiltonian $H(x)$ 221 | is autonomous. For the sake of simplicity, we shall also assume that it 222 | is $C^{1}$. 223 | 224 | We shall first consider the question of nontriviality, within the 225 | general framework of 226 | $\left(A_{\infty},B_{\infty}\right)$-subquadratic Hamiltonians. In 227 | the second subsection, we shall look into the special case when $H$ is 228 | $\left(0,b_{\infty}\right)$-subquadratic, 229 | and we shall try to derive additional information. 230 | % 231 | \subsubsection{The General Case: Nontriviality.} 232 | % 233 | We assume that $H$ is 234 | $\left(A_{\infty},B_{\infty}\right)$-sub\-qua\-dra\-tic at infinity, 235 | for some constant symmetric matrices $A_{\infty}$ and $B_{\infty}$, 236 | with $B_{\infty}-A_{\infty}$ positive definite. Set: 237 | \begin{eqnarray} 238 | \gamma :&=&{\rm smallest\ eigenvalue\ of}\ \ B_{\infty} - A_{\infty} \\ 239 | \lambda : &=& {\rm largest\ negative\ eigenvalue\ of}\ \ 240 | J \frac{d}{dt} +A_{\infty}\ . 241 | \end{eqnarray} 242 | 243 | Theorem~\ref{ghou:pre} tells us that if $\lambda +\gamma < 0$, the 244 | boundary-value problem: 245 | \begin{equation} 246 | \begin{array}{rcl} 247 | \dot{x}&=&JH' (x)\\ 248 | x(0)&=&x (T) 249 | \end{array} 250 | \end{equation} 251 | has at least one solution 252 | $\overline{x}$, which is found by minimizing the dual 253 | action functional: 254 | \begin{equation} 255 | \psi (u) = \int_{o}^{T} \left[\frac{1}{2} 256 | \left(\Lambda_{o}^{-1} u,u\right) + N^{\ast} (-u)\right] dt 257 | \end{equation} 258 | on the range of $\Lambda$, which is a subspace $R (\Lambda)_{L}^{2}$ 259 | with finite codimension. Here 260 | \begin{equation} 261 | N(x) := H(x) - \frac{1}{2} \left(A_{\infty} x,x\right) 262 | \end{equation} 263 | is a convex function, and 264 | \begin{equation} 265 | N(x) \le \frac{1}{2} 266 | \left(\left(B_{\infty} - A_{\infty}\right) x,x\right) 267 | + c\ \ \ \forall x\ . 268 | \end{equation} 269 | 270 | % 271 | \begin{proposition} 272 | Assume $H'(0)=0$ and $ H(0)=0$. Set: 273 | \begin{equation} 274 | \delta := \liminf_{x\to 0} 2 N (x) \left\|x\right\|^{-2}\ . 275 | \label{eq:one} 276 | \end{equation} 277 | 278 | If $\gamma < - \lambda < \delta$, 279 | the solution $\overline{u}$ is non-zero: 280 | \begin{equation} 281 | \overline{x} (t) \ne 0\ \ \ \forall t\ . 282 | \end{equation} 283 | \end{proposition} 284 | % 285 | \begin{proof} 286 | Condition (\ref{eq:one}) means that, for every 287 | $\delta ' > \delta$, there is some $\varepsilon > 0$ such that 288 | \begin{equation} 289 | \left\|x\right\| \le \varepsilon \Rightarrow N (x) \le 290 | \frac{\delta '}{2} \left\|x\right\|^{2}\ . 291 | \end{equation} 292 | 293 | It is an exercise in convex analysis, into which we shall not go, to 294 | show that this implies that there is an $\eta > 0$ such that 295 | \begin{equation} 296 | f\left\|x\right\| \le \eta 297 | \Rightarrow N^{\ast} (y) \le \frac{1}{2\delta '} 298 | \left\|y\right\|^{2}\ . 299 | \label{eq:two} 300 | \end{equation} 301 | 302 | \begin{figure} 303 | \vspace{2.5cm} 304 | \caption{This is the caption of the figure displaying a white eagle and 305 | a white horse on a snow field} 306 | \end{figure} 307 | 308 | Since $u_{1}$ is a smooth function, we will have 309 | $\left\|hu_{1}\right\|_\infty \le \eta$ 310 | for $h$ small enough, and inequality (\ref{eq:two}) will hold, 311 | yielding thereby: 312 | \begin{equation} 313 | \psi (hu_{1}) \le \frac{h^{2}}{2} 314 | \frac{1}{\lambda} \left\|u_{1} \right\|_{2}^{2} + \frac{h^{2}}{2} 315 | \frac{1}{\delta '} \left\|u_{1}\right\|^{2}\ . 316 | \end{equation} 317 | 318 | If we choose $\delta '$ close enough to $\delta$, the quantity 319 | $\left(\frac{1}{\lambda} + \frac{1}{\delta '}\right)$ 320 | will be negative, and we end up with 321 | \begin{equation} 322 | \psi (hu_{1}) < 0\ \ \ \ \ {\rm for}\ \ h\ne 0\ \ {\rm small}\ . 323 | \end{equation} 324 | 325 | On the other hand, we check directly that $\psi (0) = 0$. This shows 326 | that 0 cannot be a minimizer of $\psi$, not even a local one. 327 | So $\overline{u} \ne 0$ and 328 | $\overline{u} \ne \Lambda_{o}^{-1} (0) = 0$. \qed 329 | \end{proof} 330 | % 331 | \begin{corollary} 332 | Assume $H$ is $C^{2}$ and 333 | $\left(a_{\infty},b_{\infty}\right)$-subquadratic at infinity. Let 334 | $\xi_{1},\allowbreak\dots,\allowbreak\xi_{N}$ be the 335 | equilibria, that is, the solutions of $H' (\xi ) = 0$. 336 | Denote by $\omega_{k}$ 337 | the smallest eigenvalue of $H'' \left(\xi_{k}\right)$, and set: 338 | \begin{equation} 339 | \omega : = {\rm Min\,} \left\{\omega_{1},\dots,\omega_{k}\right\}\ . 340 | \end{equation} 341 | If: 342 | \begin{equation} 343 | \frac{T}{2\pi} b_{\infty} < 344 | - E \left[- \frac{T}{2\pi}a_{\infty}\right] < 345 | \frac{T}{2\pi}\omega 346 | \label{eq:three} 347 | \end{equation} 348 | then minimization of $\psi$ yields a non-constant $T$-periodic solution 349 | $\overline{x}$. 350 | \end{corollary} 351 | % 352 | 353 | We recall once more that by the integer part $E [\alpha ]$ of 354 | $\alpha \in \bbbr$, we mean the $a\in \bbbz$ 355 | such that $a< \alpha \le a+1$. For instance, 356 | if we take $a_{\infty} = 0$, Corollary 2 tells 357 | us that $\overline{x}$ exists and is 358 | non-constant provided that: 359 | 360 | \begin{equation} 361 | \frac{T}{2\pi} b_{\infty} < 1 < \frac{T}{2\pi} 362 | \end{equation} 363 | or 364 | \begin{equation} 365 | T\in \left(\frac{2\pi}{\omega},\frac{2\pi}{b_{\infty}}\right)\ . 366 | \label{eq:four} 367 | \end{equation} 368 | 369 | % 370 | \begin{proof} 371 | The spectrum of $\Lambda$ is $\frac{2\pi}{T} \bbbz +a_{\infty}$. The 372 | largest negative eigenvalue $\lambda$ is given by 373 | $\frac{2\pi}{T}k_{o} +a_{\infty}$, 374 | where 375 | \begin{equation} 376 | \frac{2\pi}{T}k_{o} + a_{\infty} < 0 377 | \le \frac{2\pi}{T} (k_{o} +1) + a_{\infty}\ . 378 | \end{equation} 379 | Hence: 380 | \begin{equation} 381 | k_{o} = E \left[- \frac{T}{2\pi} a_{\infty}\right] \ . 382 | \end{equation} 383 | 384 | The condition $\gamma < -\lambda < \delta$ now becomes: 385 | \begin{equation} 386 | b_{\infty} - a_{\infty} < 387 | - \frac{2\pi}{T} k_{o} -a_{\infty} < \omega -a_{\infty} 388 | \end{equation} 389 | which is precisely condition (\ref{eq:three}).\qed 390 | \end{proof} 391 | % 392 | 393 | \begin{lemma} 394 | Assume that $H$ is $C^{2}$ on $\bbbr^{2n} \setminus \{ 0\}$ and 395 | that $H'' (x)$ is non-de\-gen\-er\-ate for any $x\ne 0$. Then any local 396 | minimizer $\widetilde{x}$ of $\psi$ has minimal period $T$. 397 | \end{lemma} 398 | % 399 | \begin{proof} 400 | We know that $\widetilde{x}$, or 401 | $\widetilde{x} + \xi$ for some constant $\xi 402 | \in \bbbr^{2n}$, is a $T$-periodic solution of the Hamiltonian system: 403 | \begin{equation} 404 | \dot{x} = JH' (x)\ . 405 | \end{equation} 406 | 407 | There is no loss of generality in taking $\xi = 0$. So 408 | $\psi (x) \ge \psi (\widetilde{x} )$ 409 | for all $\widetilde{x}$ in some neighbourhood of $x$ in 410 | $W^{1,2} \left(\bbbr / T\bbbz ; \bbbr^{2n}\right)$. 411 | 412 | But this index is precisely the index 413 | $i_{T} (\widetilde{x} )$ of the $T$-periodic 414 | solution $\widetilde{x}$ over the interval 415 | $(0,T)$, as defined in Sect.~2.6. So 416 | \begin{equation} 417 | i_{T} (\widetilde{x} ) = 0\ . 418 | \label{eq:five} 419 | \end{equation} 420 | 421 | Now if $\widetilde{x}$ has a lower period, $T/k$ say, 422 | we would have, by Corollary 31: 423 | \begin{equation} 424 | i_{T} (\widetilde{x} ) = 425 | i_{kT/k}(\widetilde{x} ) \ge 426 | ki_{T/k} (\widetilde{x} ) + k-1 \ge k-1 \ge 1\ . 427 | \end{equation} 428 | 429 | This would contradict (\ref{eq:five}), and thus cannot happen.\qed 430 | \end{proof} 431 | % 432 | \paragraph{Notes and Comments.} 433 | The results in this section are a 434 | refined version of \cite{clar:eke}; 435 | the minimality result of Proposition 436 | 14 was the first of its kind. 437 | 438 | To understand the nontriviality conditions, such as the one in formula 439 | (\ref{eq:four}), one may think of a one-parameter family 440 | $x_{T}$, $T\in \left(2\pi\omega^{-1}, 2\pi b_{\infty}^{-1}\right)$ 441 | of periodic solutions, $x_{T} (0) = x_{T} (T)$, 442 | with $x_{T}$ going away to infinity when $T\to 2\pi \omega^{-1}$, 443 | which is the period of the linearized system at 0. 444 | 445 | \begin{table} 446 | \caption{This is the example table taken out of {\it The 447 | \TeX{}book,} p.\,246} 448 | \begin{center} 449 | \begin{tabular}{r@{\quad}rl} 450 | \hline 451 | \multicolumn{1}{l}{\rule{0pt}{12pt} 452 | Year}&\multicolumn{2}{l}{World population}\\[2pt] 453 | \hline\rule{0pt}{12pt} 454 | 8000 B.C. & 5,000,000& \\ 455 | 50 A.D. & 200,000,000& \\ 456 | 1650 A.D. & 500,000,000& \\ 457 | 1945 A.D. & 2,300,000,000& \\ 458 | 1980 A.D. & 4,400,000,000& \\[2pt] 459 | \hline 460 | \end{tabular} 461 | \end{center} 462 | \end{table} 463 | % 464 | \begin{theorem} [Ghoussoub-Preiss]\label{ghou:pre} 465 | Assume $H(t,x)$ is 466 | $(0,\varepsilon )$-subquadratic at 467 | infinity for all $\varepsilon > 0$, and $T$-periodic in $t$ 468 | \begin{equation} 469 | H (t,\cdot )\ \ \ \ \ {\rm is\ convex}\ \ \forall t 470 | \end{equation} 471 | \begin{equation} 472 | H (\cdot ,x)\ \ \ \ \ {\rm is}\ \ T{\rm -periodic}\ \ \forall x 473 | \end{equation} 474 | \begin{equation} 475 | H (t,x)\ge n\left(\left\|x\right\|\right)\ \ \ \ \ 476 | {\rm with}\ \ n (s)s^{-1}\to \infty\ \ {\rm as}\ \ s\to \infty 477 | \end{equation} 478 | \begin{equation} 479 | \forall \varepsilon > 0\ ,\ \ \ \exists c\ :\ 480 | H(t,x) \le \frac{\varepsilon}{2}\left\|x\right\|^{2} + c\ . 481 | \end{equation} 482 | 483 | Assume also that $H$ is $C^{2}$, and $H'' (t,x)$ is positive definite 484 | everywhere. Then there is a sequence $x_{k}$, $k\in \bbbn$, of 485 | $kT$-periodic solutions of the system 486 | \begin{equation} 487 | \dot{x} = JH' (t,x) 488 | \end{equation} 489 | such that, for every $k\in \bbbn$, there is some $p_{o}\in\bbbn$ with: 490 | \begin{equation} 491 | p\ge p_{o}\Rightarrow x_{pk} \ne x_{k}\ . 492 | \end{equation} 493 | \qed 494 | \end{theorem} 495 | % 496 | \begin{example} [{{\rm External forcing}}] 497 | Consider the system: 498 | \begin{equation} 499 | \dot{x} = JH' (x) + f(t) 500 | \end{equation} 501 | where the Hamiltonian $H$ is 502 | $\left(0,b_{\infty}\right)$-subquadratic, and the 503 | forcing term is a distribution on the circle: 504 | \begin{equation} 505 | f = \frac{d}{dt} F + f_{o}\ \ \ \ \ 506 | {\rm with}\ \ F\in L^{2} \left(\bbbr / T\bbbz; \bbbr^{2n}\right)\ , 507 | \end{equation} 508 | where $f_{o} : = T^{-1}\int_{o}^{T} f (t) dt$. For instance, 509 | \begin{equation} 510 | f (t) = \sum_{k\in \bbbn} \delta_{k} \xi\ , 511 | \end{equation} 512 | where $\delta_{k}$ is the Dirac mass at $t= k$ and 513 | $\xi \in \bbbr^{2n}$ is a 514 | constant, fits the prescription. This means that the system 515 | $\dot{x} = JH' (x)$ is being excited by a 516 | series of identical shocks at interval $T$. 517 | \end{example} 518 | % 519 | \begin{definition} 520 | Let $A_{\infty} (t)$ and $B_{\infty} (t)$ be symmetric 521 | operators in $\bbbr^{2n}$, depending continuously on 522 | $t\in [0,T]$, such that 523 | $A_{\infty} (t) \le B_{\infty} (t)$ for all $t$. 524 | 525 | A Borelian function 526 | $H: [0,T]\times \bbbr^{2n} \to \bbbr$ 527 | is called 528 | $\left(A_{\infty} ,B_{\infty}\right)$-{\it subquadratic at infinity} 529 | if there exists a function $N(t,x)$ such that: 530 | \begin{equation} 531 | H (t,x) = \frac{1}{2} \left(A_{\infty} (t) x,x\right) + N(t,x) 532 | \end{equation} 533 | \begin{equation} 534 | \forall t\ ,\ \ \ N(t,x)\ \ \ \ \ 535 | {\rm is\ convex\ with\ respect\ to}\ \ x 536 | \end{equation} 537 | \begin{equation} 538 | N(t,x) \ge n\left(\left\|x\right\|\right)\ \ \ \ \ 539 | {\rm with}\ \ n(s)s^{-1}\to +\infty\ \ {\rm as}\ \ s\to +\infty 540 | \end{equation} 541 | \begin{equation} 542 | \exists c\in \bbbr\ :\ \ \ H (t,x) \le 543 | \frac{1}{2} \left(B_{\infty} (t) x,x\right) + c\ \ \ \forall x\ . 544 | \end{equation} 545 | 546 | If $A_{\infty} (t) = a_{\infty} I$ and 547 | $B_{\infty} (t) = b_{\infty} I$, with 548 | $a_{\infty} \le b_{\infty} \in \bbbr$, 549 | we shall say that $H$ is 550 | $\left(a_{\infty},b_{\infty}\right)$-subquadratic 551 | at infinity. As an example, the function 552 | $\left\|x\right\|^{\alpha}$, with 553 | $1\le \alpha < 2$, is $(0,\varepsilon )$-subquadratic at infinity 554 | for every $\varepsilon > 0$. Similarly, the Hamiltonian 555 | \begin{equation} 556 | H (t,x) = \frac{1}{2} k \left\|k\right\|^{2} +\left\|x\right\|^{\alpha} 557 | \end{equation} 558 | is $(k,k+\varepsilon )$-subquadratic for every $\varepsilon > 0$. 559 | Note that, if $k<0$, it is not convex. 560 | \end{definition} 561 | % 562 | 563 | \paragraph{Notes and Comments.} 564 | The first results on subharmonics were 565 | obtained by Rabinowitz in \cite{rab}, who showed the existence of 566 | infinitely many subharmonics both in the subquadratic and superquadratic 567 | case, with suitable growth conditions on $H'$. Again the duality 568 | approach enabled Clarke and Ekeland in \cite{clar:eke:2} to treat the 569 | same problem in the convex-subquadratic case, with growth conditions on 570 | $H$ only. 571 | 572 | Recently, Michalek and Tarantello (see \cite{mich:tar} and \cite{tar}) 573 | have obtained lower bound on the number of subharmonics of period $kT$, 574 | based on symmetry considerations and on pinching estimates, as in 575 | Sect.~5.2 of this article. 576 | 577 | % 578 | % ---- Bibliography ---- 579 | % 580 | \begin{thebibliography}{5} 581 | % 582 | \bibitem {clar:eke} 583 | Clarke, F., Ekeland, I.: 584 | Nonlinear oscillations and 585 | boundary-value problems for Hamiltonian systems. 586 | Arch. Rat. Mech. Anal. 78, 315--333 (1982) 587 | 588 | \bibitem {clar:eke:2} 589 | Clarke, F., Ekeland, I.: 590 | Solutions p\'{e}riodiques, du 591 | p\'{e}riode donn\'{e}e, des \'{e}quations hamiltoniennes. 592 | Note CRAS Paris 287, 1013--1015 (1978) 593 | 594 | \bibitem {mich:tar} 595 | Michalek, R., Tarantello, G.: 596 | Subharmonic solutions with prescribed minimal 597 | period for nonautonomous Hamiltonian systems. 598 | J. Diff. Eq. 72, 28--55 (1988) 599 | 600 | \bibitem {tar} 601 | Tarantello, G.: 602 | Subharmonic solutions for Hamiltonian 603 | systems via a $\bbbz_{p}$ pseudoindex theory. 604 | Annali di Matematica Pura (to appear) 605 | 606 | \bibitem {rab} 607 | Rabinowitz, P.: 608 | On subharmonic solutions of a Hamiltonian system. 609 | Comm. Pure Appl. Math. 33, 609--633 (1980) 610 | 611 | \end{thebibliography} 612 | 613 | % 614 | % second contribution with nearly identical text, 615 | % slightly changed contribution head (all entries 616 | % appear as defaults), and modified bibliography 617 | % 618 | \title{Hamiltonian Mechanics2} 619 | 620 | \author{Ivar Ekeland\inst{1} \and Roger Temam\inst{2}} 621 | 622 | \institute{Princeton University, Princeton NJ 08544, USA 623 | \and 624 | Universit\'{e} de Paris-Sud, 625 | Laboratoire d'Analyse Num\'{e}rique, B\^{a}timent 425,\\ 626 | F-91405 Orsay Cedex, France} 627 | 628 | \maketitle 629 | % 630 | % Modify the bibliography environment to call for the author-year 631 | % system. This is done normally with the citeauthoryear option 632 | % for a particular contribution. 633 | \makeatletter 634 | \renewenvironment{thebibliography}[1] 635 | {\section*{\refname} 636 | \small 637 | \list{}% 638 | {\settowidth\labelwidth{}% 639 | \leftmargin\parindent 640 | \itemindent=-\parindent 641 | \labelsep=\z@ 642 | \if@openbib 643 | \advance\leftmargin\bibindent 644 | \itemindent -\bibindent 645 | \listparindent \itemindent 646 | \parsep \z@ 647 | \fi 648 | \usecounter{enumiv}% 649 | \let\p@enumiv\@empty 650 | \renewcommand\theenumiv{}}% 651 | \if@openbib 652 | \renewcommand\newblock{\par}% 653 | \else 654 | \renewcommand\newblock{\hskip .11em \@plus.33em \@minus.07em}% 655 | \fi 656 | \sloppy\clubpenalty4000\widowpenalty4000% 657 | \sfcode`\.=\@m} 658 | {\def\@noitemerr 659 | {\@latex@warning{Empty `thebibliography' environment}}% 660 | \endlist} 661 | \def\@cite#1{#1}% 662 | \def\@lbibitem[#1]#2{\item[]\if@filesw 663 | {\def\protect##1{\string ##1\space}\immediate 664 | \write\@auxout{\string\bibcite{#2}{#1}}}\fi\ignorespaces} 665 | \makeatother 666 | % 667 | \begin{abstract} 668 | The abstract should summarize the contents of the paper 669 | using at least 70 and at most 150 words. It will be set in 9-point 670 | font size and be inset 1.0 cm from the right and left margins. 671 | There will be two blank lines before and after the Abstract. \dots 672 | \keywords{graph transformations, convex geometry, lattice computations, 673 | convex polygons, triangulations, discrete geometry} 674 | \end{abstract} 675 | % 676 | \section{Fixed-Period Problems: The Sublinear Case} 677 | % 678 | With this chapter, the preliminaries are over, and we begin the search 679 | for periodic solutions to Hamiltonian systems. All this will be done in 680 | the convex case; that is, we shall study the boundary-value problem 681 | \begin{eqnarray*} 682 | \dot{x}&=&JH' (t,x)\\ 683 | x(0) &=& x(T) 684 | \end{eqnarray*} 685 | with $H(t,\cdot)$ a convex function of $x$, going to $+\infty$ when 686 | $\left\|x\right\| \to \infty$. 687 | 688 | % 689 | \subsection{Autonomous Systems} 690 | % 691 | In this section, we will consider the case when the Hamiltonian $H(x)$ 692 | is autonomous. For the sake of simplicity, we shall also assume that it 693 | is $C^{1}$. 694 | 695 | We shall first consider the question of nontriviality, within the 696 | general framework of 697 | $\left(A_{\infty},B_{\infty}\right)$-subquadratic Hamiltonians. In 698 | the second subsection, we shall look into the special case when $H$ is 699 | $\left(0,b_{\infty}\right)$-subquadratic, 700 | and we shall try to derive additional information. 701 | % 702 | \subsubsection{The General Case: Nontriviality.} 703 | % 704 | We assume that $H$ is 705 | $\left(A_{\infty},B_{\infty}\right)$-sub\-qua\-dra\-tic at infinity, 706 | for some constant symmetric matrices $A_{\infty}$ and $B_{\infty}$, 707 | with $B_{\infty}-A_{\infty}$ positive definite. Set: 708 | \begin{eqnarray} 709 | \gamma :&=&{\rm smallest\ eigenvalue\ of}\ \ B_{\infty} - A_{\infty} \\ 710 | \lambda : &=& {\rm largest\ negative\ eigenvalue\ of}\ \ 711 | J \frac{d}{dt} +A_{\infty}\ . 712 | \end{eqnarray} 713 | 714 | Theorem 21 tells us that if $\lambda +\gamma < 0$, the boundary-value 715 | problem: 716 | \begin{equation} 717 | \begin{array}{rcl} 718 | \dot{x}&=&JH' (x)\\ 719 | x(0)&=&x (T) 720 | \end{array} 721 | \end{equation} 722 | has at least one solution 723 | $\overline{x}$, which is found by minimizing the dual 724 | action functional: 725 | \begin{equation} 726 | \psi (u) = \int_{o}^{T} \left[\frac{1}{2} 727 | \left(\Lambda_{o}^{-1} u,u\right) + N^{\ast} (-u)\right] dt 728 | \end{equation} 729 | on the range of $\Lambda$, which is a subspace $R (\Lambda)_{L}^{2}$ 730 | with finite codimension. Here 731 | \begin{equation} 732 | N(x) := H(x) - \frac{1}{2} \left(A_{\infty} x,x\right) 733 | \end{equation} 734 | is a convex function, and 735 | \begin{equation} 736 | N(x) \le \frac{1}{2} 737 | \left(\left(B_{\infty} - A_{\infty}\right) x,x\right) 738 | + c\ \ \ \forall x\ . 739 | \end{equation} 740 | 741 | % 742 | \begin{proposition} 743 | Assume $H'(0)=0$ and $ H(0)=0$. Set: 744 | \begin{equation} 745 | \delta := \liminf_{x\to 0} 2 N (x) \left\|x\right\|^{-2}\ . 746 | \label{2eq:one} 747 | \end{equation} 748 | 749 | If $\gamma < - \lambda < \delta$, 750 | the solution $\overline{u}$ is non-zero: 751 | \begin{equation} 752 | \overline{x} (t) \ne 0\ \ \ \forall t\ . 753 | \end{equation} 754 | \end{proposition} 755 | % 756 | \begin{proof} 757 | Condition (\ref{2eq:one}) means that, for every 758 | $\delta ' > \delta$, there is some $\varepsilon > 0$ such that 759 | \begin{equation} 760 | \left\|x\right\| \le \varepsilon \Rightarrow N (x) \le 761 | \frac{\delta '}{2} \left\|x\right\|^{2}\ . 762 | \end{equation} 763 | 764 | It is an exercise in convex analysis, into which we shall not go, to 765 | show that this implies that there is an $\eta > 0$ such that 766 | \begin{equation} 767 | f\left\|x\right\| \le \eta 768 | \Rightarrow N^{\ast} (y) \le \frac{1}{2\delta '} 769 | \left\|y\right\|^{2}\ . 770 | \label{2eq:two} 771 | \end{equation} 772 | 773 | \begin{figure} 774 | \vspace{2.5cm} 775 | \caption{This is the caption of the figure displaying a white eagle and 776 | a white horse on a snow field} 777 | \end{figure} 778 | 779 | Since $u_{1}$ is a smooth function, we will have 780 | $\left\|hu_{1}\right\|_\infty \le \eta$ 781 | for $h$ small enough, and inequality (\ref{2eq:two}) will hold, 782 | yielding thereby: 783 | \begin{equation} 784 | \psi (hu_{1}) \le \frac{h^{2}}{2} 785 | \frac{1}{\lambda} \left\|u_{1} \right\|_{2}^{2} + \frac{h^{2}}{2} 786 | \frac{1}{\delta '} \left\|u_{1}\right\|^{2}\ . 787 | \end{equation} 788 | 789 | If we choose $\delta '$ close enough to $\delta$, the quantity 790 | $\left(\frac{1}{\lambda} + \frac{1}{\delta '}\right)$ 791 | will be negative, and we end up with 792 | \begin{equation} 793 | \psi (hu_{1}) < 0\ \ \ \ \ {\rm for}\ \ h\ne 0\ \ {\rm small}\ . 794 | \end{equation} 795 | 796 | On the other hand, we check directly that $\psi (0) = 0$. This shows 797 | that 0 cannot be a minimizer of $\psi$, not even a local one. 798 | So $\overline{u} \ne 0$ and 799 | $\overline{u} \ne \Lambda_{o}^{-1} (0) = 0$. \qed 800 | \end{proof} 801 | % 802 | \begin{corollary} 803 | Assume $H$ is $C^{2}$ and 804 | $\left(a_{\infty},b_{\infty}\right)$-subquadratic at infinity. Let 805 | $\xi_{1},\allowbreak\dots,\allowbreak\xi_{N}$ be the 806 | equilibria, that is, the solutions of $H' (\xi ) = 0$. 807 | Denote by $\omega_{k}$ 808 | the smallest eigenvalue of $H'' \left(\xi_{k}\right)$, and set: 809 | \begin{equation} 810 | \omega : = {\rm Min\,} \left\{\omega_{1},\dots,\omega_{k}\right\}\ . 811 | \end{equation} 812 | If: 813 | \begin{equation} 814 | \frac{T}{2\pi} b_{\infty} < 815 | - E \left[- \frac{T}{2\pi}a_{\infty}\right] < 816 | \frac{T}{2\pi}\omega 817 | \label{2eq:three} 818 | \end{equation} 819 | then minimization of $\psi$ yields a non-constant $T$-periodic solution 820 | $\overline{x}$. 821 | \end{corollary} 822 | % 823 | 824 | We recall once more that by the integer part $E [\alpha ]$ of 825 | $\alpha \in \bbbr$, we mean the $a\in \bbbz$ 826 | such that $a< \alpha \le a+1$. For instance, 827 | if we take $a_{\infty} = 0$, Corollary 2 tells 828 | us that $\overline{x}$ exists and is 829 | non-constant provided that: 830 | 831 | \begin{equation} 832 | \frac{T}{2\pi} b_{\infty} < 1 < \frac{T}{2\pi} 833 | \end{equation} 834 | or 835 | \begin{equation} 836 | T\in \left(\frac{2\pi}{\omega},\frac{2\pi}{b_{\infty}}\right)\ . 837 | \label{2eq:four} 838 | \end{equation} 839 | 840 | % 841 | \begin{proof} 842 | The spectrum of $\Lambda$ is $\frac{2\pi}{T} \bbbz +a_{\infty}$. The 843 | largest negative eigenvalue $\lambda$ is given by 844 | $\frac{2\pi}{T}k_{o} +a_{\infty}$, 845 | where 846 | \begin{equation} 847 | \frac{2\pi}{T}k_{o} + a_{\infty} < 0 848 | \le \frac{2\pi}{T} (k_{o} +1) + a_{\infty}\ . 849 | \end{equation} 850 | Hence: 851 | \begin{equation} 852 | k_{o} = E \left[- \frac{T}{2\pi} a_{\infty}\right] \ . 853 | \end{equation} 854 | 855 | The condition $\gamma < -\lambda < \delta$ now becomes: 856 | \begin{equation} 857 | b_{\infty} - a_{\infty} < 858 | - \frac{2\pi}{T} k_{o} -a_{\infty} < \omega -a_{\infty} 859 | \end{equation} 860 | which is precisely condition (\ref{2eq:three}).\qed 861 | \end{proof} 862 | % 863 | 864 | \begin{lemma} 865 | Assume that $H$ is $C^{2}$ on $\bbbr^{2n} \setminus \{ 0\}$ and 866 | that $H'' (x)$ is non-de\-gen\-er\-ate for any $x\ne 0$. Then any local 867 | minimizer $\widetilde{x}$ of $\psi$ has minimal period $T$. 868 | \end{lemma} 869 | % 870 | \begin{proof} 871 | We know that $\widetilde{x}$, or 872 | $\widetilde{x} + \xi$ for some constant $\xi 873 | \in \bbbr^{2n}$, is a $T$-periodic solution of the Hamiltonian system: 874 | \begin{equation} 875 | \dot{x} = JH' (x)\ . 876 | \end{equation} 877 | 878 | There is no loss of generality in taking $\xi = 0$. So 879 | $\psi (x) \ge \psi (\widetilde{x} )$ 880 | for all $\widetilde{x}$ in some neighbourhood of $x$ in 881 | $W^{1,2} \left(\bbbr / T\bbbz ; \bbbr^{2n}\right)$. 882 | 883 | But this index is precisely the index 884 | $i_{T} (\widetilde{x} )$ of the $T$-periodic 885 | solution $\widetilde{x}$ over the interval 886 | $(0,T)$, as defined in Sect.~2.6. So 887 | \begin{equation} 888 | i_{T} (\widetilde{x} ) = 0\ . 889 | \label{2eq:five} 890 | \end{equation} 891 | 892 | Now if $\widetilde{x}$ has a lower period, $T/k$ say, 893 | we would have, by Corollary 31: 894 | \begin{equation} 895 | i_{T} (\widetilde{x} ) = 896 | i_{kT/k}(\widetilde{x} ) \ge 897 | ki_{T/k} (\widetilde{x} ) + k-1 \ge k-1 \ge 1\ . 898 | \end{equation} 899 | 900 | This would contradict (\ref{2eq:five}), and thus cannot happen.\qed 901 | \end{proof} 902 | % 903 | \paragraph{Notes and Comments.} 904 | The results in this section are a 905 | refined version of \cite{2clar:eke}; 906 | the minimality result of Proposition 907 | 14 was the first of its kind. 908 | 909 | To understand the nontriviality conditions, such as the one in formula 910 | (\ref{2eq:four}), one may think of a one-parameter family 911 | $x_{T}$, $T\in \left(2\pi\omega^{-1}, 2\pi b_{\infty}^{-1}\right)$ 912 | of periodic solutions, $x_{T} (0) = x_{T} (T)$, 913 | with $x_{T}$ going away to infinity when $T\to 2\pi \omega^{-1}$, 914 | which is the period of the linearized system at 0. 915 | 916 | \begin{table} 917 | \caption{This is the example table taken out of {\it The 918 | \TeX{}book,} p.\,246} 919 | \begin{center} 920 | \begin{tabular}{r@{\quad}rl} 921 | \hline 922 | \multicolumn{1}{l}{\rule{0pt}{12pt} 923 | Year}&\multicolumn{2}{l}{World population}\\[2pt] 924 | \hline\rule{0pt}{12pt} 925 | 8000 B.C. & 5,000,000& \\ 926 | 50 A.D. & 200,000,000& \\ 927 | 1650 A.D. & 500,000,000& \\ 928 | 1945 A.D. & 2,300,000,000& \\ 929 | 1980 A.D. & 4,400,000,000& \\[2pt] 930 | \hline 931 | \end{tabular} 932 | \end{center} 933 | \end{table} 934 | % 935 | \begin{theorem} [Ghoussoub-Preiss] 936 | Assume $H(t,x)$ is 937 | $(0,\varepsilon )$-subquadratic at 938 | infinity for all $\varepsilon > 0$, and $T$-periodic in $t$ 939 | \begin{equation} 940 | H (t,\cdot )\ \ \ \ \ {\rm is\ convex}\ \ \forall t 941 | \end{equation} 942 | \begin{equation} 943 | H (\cdot ,x)\ \ \ \ \ {\rm is}\ \ T{\rm -periodic}\ \ \forall x 944 | \end{equation} 945 | \begin{equation} 946 | H (t,x)\ge n\left(\left\|x\right\|\right)\ \ \ \ \ 947 | {\rm with}\ \ n (s)s^{-1}\to \infty\ \ {\rm as}\ \ s\to \infty 948 | \end{equation} 949 | \begin{equation} 950 | \forall \varepsilon > 0\ ,\ \ \ \exists c\ :\ 951 | H(t,x) \le \frac{\varepsilon}{2}\left\|x\right\|^{2} + c\ . 952 | \end{equation} 953 | 954 | Assume also that $H$ is $C^{2}$, and $H'' (t,x)$ is positive definite 955 | everywhere. Then there is a sequence $x_{k}$, $k\in \bbbn$, of 956 | $kT$-periodic solutions of the system 957 | \begin{equation} 958 | \dot{x} = JH' (t,x) 959 | \end{equation} 960 | such that, for every $k\in \bbbn$, there is some $p_{o}\in\bbbn$ with: 961 | \begin{equation} 962 | p\ge p_{o}\Rightarrow x_{pk} \ne x_{k}\ . 963 | \end{equation} 964 | \qed 965 | \end{theorem} 966 | % 967 | \begin{example} [{{\rm External forcing}}] 968 | Consider the system: 969 | \begin{equation} 970 | \dot{x} = JH' (x) + f(t) 971 | \end{equation} 972 | where the Hamiltonian $H$ is 973 | $\left(0,b_{\infty}\right)$-subquadratic, and the 974 | forcing term is a distribution on the circle: 975 | \begin{equation} 976 | f = \frac{d}{dt} F + f_{o}\ \ \ \ \ 977 | {\rm with}\ \ F\in L^{2} \left(\bbbr / T\bbbz; \bbbr^{2n}\right)\ , 978 | \end{equation} 979 | where $f_{o} : = T^{-1}\int_{o}^{T} f (t) dt$. For instance, 980 | \begin{equation} 981 | f (t) = \sum_{k\in \bbbn} \delta_{k} \xi\ , 982 | \end{equation} 983 | where $\delta_{k}$ is the Dirac mass at $t= k$ and 984 | $\xi \in \bbbr^{2n}$ is a 985 | constant, fits the prescription. This means that the system 986 | $\dot{x} = JH' (x)$ is being excited by a 987 | series of identical shocks at interval $T$. 988 | \end{example} 989 | % 990 | \begin{definition} 991 | Let $A_{\infty} (t)$ and $B_{\infty} (t)$ be symmetric 992 | operators in $\bbbr^{2n}$, depending continuously on 993 | $t\in [0,T]$, such that 994 | $A_{\infty} (t) \le B_{\infty} (t)$ for all $t$. 995 | 996 | A Borelian function 997 | $H: [0,T]\times \bbbr^{2n} \to \bbbr$ 998 | is called 999 | $\left(A_{\infty} ,B_{\infty}\right)$-{\it subquadratic at infinity} 1000 | if there exists a function $N(t,x)$ such that: 1001 | \begin{equation} 1002 | H (t,x) = \frac{1}{2} \left(A_{\infty} (t) x,x\right) + N(t,x) 1003 | \end{equation} 1004 | \begin{equation} 1005 | \forall t\ ,\ \ \ N(t,x)\ \ \ \ \ 1006 | {\rm is\ convex\ with\ respect\ to}\ \ x 1007 | \end{equation} 1008 | \begin{equation} 1009 | N(t,x) \ge n\left(\left\|x\right\|\right)\ \ \ \ \ 1010 | {\rm with}\ \ n(s)s^{-1}\to +\infty\ \ {\rm as}\ \ s\to +\infty 1011 | \end{equation} 1012 | \begin{equation} 1013 | \exists c\in \bbbr\ :\ \ \ H (t,x) \le 1014 | \frac{1}{2} \left(B_{\infty} (t) x,x\right) + c\ \ \ \forall x\ . 1015 | \end{equation} 1016 | 1017 | If $A_{\infty} (t) = a_{\infty} I$ and 1018 | $B_{\infty} (t) = b_{\infty} I$, with 1019 | $a_{\infty} \le b_{\infty} \in \bbbr$, 1020 | we shall say that $H$ is 1021 | $\left(a_{\infty},b_{\infty}\right)$-subquadratic 1022 | at infinity. As an example, the function 1023 | $\left\|x\right\|^{\alpha}$, with 1024 | $1\le \alpha < 2$, is $(0,\varepsilon )$-subquadratic at infinity 1025 | for every $\varepsilon > 0$. Similarly, the Hamiltonian 1026 | \begin{equation} 1027 | H (t,x) = \frac{1}{2} k \left\|k\right\|^{2} +\left\|x\right\|^{\alpha} 1028 | \end{equation} 1029 | is $(k,k+\varepsilon )$-subquadratic for every $\varepsilon > 0$. 1030 | Note that, if $k<0$, it is not convex. 1031 | \end{definition} 1032 | % 1033 | 1034 | \paragraph{Notes and Comments.} 1035 | The first results on subharmonics were 1036 | obtained by Rabinowitz in \cite{2rab}, who showed the existence of 1037 | infinitely many subharmonics both in the subquadratic and superquadratic 1038 | case, with suitable growth conditions on $H'$. Again the duality 1039 | approach enabled Clarke and Ekeland in \cite{2clar:eke:2} to treat the 1040 | same problem in the convex-subquadratic case, with growth conditions on 1041 | $H$ only. 1042 | 1043 | Recently, Michalek and Tarantello (see Michalek, R., Tarantello, G. 1044 | \cite{2mich:tar} and Tarantello, G. \cite{2tar}) have obtained lower 1045 | bound on the number of subharmonics of period $kT$, based on symmetry 1046 | considerations and on pinching estimates, as in Sect.~5.2 of this 1047 | article. 1048 | 1049 | % 1050 | % ---- Bibliography ---- 1051 | % 1052 | \begin{thebibliography}{} 1053 | % 1054 | \bibitem[1980]{2clar:eke} 1055 | Clarke, F., Ekeland, I.: 1056 | Nonlinear oscillations and 1057 | boundary-value problems for Hamiltonian systems. 1058 | Arch. Rat. Mech. Anal. 78, 315--333 (1982) 1059 | 1060 | \bibitem[1981]{2clar:eke:2} 1061 | Clarke, F., Ekeland, I.: 1062 | Solutions p\'{e}riodiques, du 1063 | p\'{e}riode donn\'{e}e, des \'{e}quations hamiltoniennes. 1064 | Note CRAS Paris 287, 1013--1015 (1978) 1065 | 1066 | \bibitem[1982]{2mich:tar} 1067 | Michalek, R., Tarantello, G.: 1068 | Subharmonic solutions with prescribed minimal 1069 | period for nonautonomous Hamiltonian systems. 1070 | J. Diff. Eq. 72, 28--55 (1988) 1071 | 1072 | \bibitem[1983]{2tar} 1073 | Tarantello, G.: 1074 | Subharmonic solutions for Hamiltonian 1075 | systems via a $\bbbz_{p}$ pseudoindex theory. 1076 | Annali di Matematica Pura (to appear) 1077 | 1078 | \bibitem[1985]{2rab} 1079 | Rabinowitz, P.: 1080 | On subharmonic solutions of a Hamiltonian system. 1081 | Comm. Pure Appl. Math. 33, 609--633 (1980) 1082 | 1083 | \end{thebibliography} 1084 | \clearpage 1085 | \addtocmark[2]{Author Index} % additional numbered TOC entry 1086 | \renewcommand{\indexname}{Author Index} 1087 | \printindex 1088 | \clearpage 1089 | \addtocmark[2]{Subject Index} % additional numbered TOC entry 1090 | \markboth{Subject Index}{Subject Index} 1091 | \renewcommand{\indexname}{Subject Index} 1092 | \input{subjidx.ind} 1093 | \end{document} 1094 | --------------------------------------------------------------------------------