···11\import{dt-macros}
22\author{liamoc}
33\taxon{Theorem}
44-\p{#{+ : \mathbf{Cpo} \times \mathbf{Cpo} \rightarrow \mathbf{Cpo}} is a lawful [bifunctor](dm-000M).
44+\p{#{+ : \mathbf{Cpo} \times \mathbf{Cpo} \rightarrow \mathbf{Cpo}} is a lawful [bifunctor](dm-000M), that is:
55+\ol{
66+\li{ #{ (\lambda a. a) \times (\lambda b. b) = (\lambda x.x)} }
77+\li{ #{ (f_1 \circ g_1) \times (f_2 \circ g_2) = (f_1 \times f_2) \circ (g_1 \times g_2)} }
88+}
59}
+1-1
trees/dt/dt-003L.tree
···55\p{With [the lifting operator](dt-003K), we can relate the lazy constructions like [product](dt-0021) and [sum](dt-0031) with [strict](dt-000K) constructions like [smash product](dt-003G) and [sum](dt-003H) via [isomorphism](dt-002E):
66\ul{
77\li{ #{A\contto B \simeq A_\bot \strictto B}}
88-\li{ #{A + B \;\; \simeq A_\bot \oplus B_\bot}}
88+\li{ #{A + B \simeq A_\bot \oplus B_\bot}}
99\li{ #{(A \times B)_\bot \simeq A_\bot \otimes B_\bot } }
1010}
1111}
+27
trees/loc-000K.tree
···11+\author{liamoc}
22+\import{dt-macros}
33+\title{Finite Automata via Matrices}
44+\date{2025-05-08T09:10:02Z}
55+\p{This technique is almost certainly folklore, but I first saw it in [[dfirsov]] and [[tuustalu]]'s [paper](firsov-uustalu-2013), which uses it to formalise and prove correct a regex matcher in Agda.}
66+\subtree{
77+\taxon{Definition}
88+\p{Define a finite state automaton over an alphabet #{\Sigma} as a tuple #{(N, \delta, I, F)} where: }
99+\ul{
1010+ \li{#{N \in \mathbb{N}} is the number of states.}
1111+ \li{#{\delta : \Sigma \rightarrow N \times N} is the transition function. Here #{\delta(a)} gives a boolean matrix #{M} where #{M_{ij} = 1} iff state #{j} is a successor of state #{i} for the symbol #{a}. As #{\Sigma} is finite this could also be viewed as a three-dimensional tensor.}
1212+ \li{#{I : 1 \times N} is a row vector specifying the initial states, where element #{I_{1k}} is #{1} iff state #{k} is an initial state.}
1313+ \li{#{F : N \times 1} is a column vector specifying the final states, where element #{I_{k1}} is #{1} iff state #{k} is a final state.}
1414+ }
1515+}
1616+\p{
1717+ Running an NFA #{(N, \delta, I, F)} on a word #{x_0x_1x_2\dots
1818+ } from a starting set of states #{X} is the same as the product of #{X} (interpreted as a row vector) with each matrix for each symbol in the word:
1919+ ##{ \begin{array}{lcl}
2020+ \delta^\ast(X, x_0x_1x_2\dots) & = & X \cdot \delta(x_0) \cdot \delta (x_1) \cdot \delta(x_2) \cdot \cdots \\
2121+ \end{array}}
2222+ Start from #{I} and multiply #{F} at last and the result will be #{\lsquare\lsquare 1 \rsquare\rsquare} if the word is in the language and #{\lsquare\lsquare 0 \rsquare\rsquare} otherwise:
2323+ ##{
2424+ w \in \mathcal{L} \;\;\Longleftrightarrow\;\; \delta^\ast(I,w) \cdot F = \lsquare\lsquare 1 \rsquare\rsquare
2525+ }
2626+2727+}