Note on this version. This paper is a revised version of [15 ] (arXiv:2309.13798v1), which had a WIP status at that time. Several axioms and proof principles were corrected, the adequacy and satisfiability results were proved, and the case studies were completed. Appendix C lists the changes.
Introduction
It is known that many data types used in programming are defined as initial algebra or final coalgebra for an appropriate functor F : C → C F : \mathcal{C} \to\mathcal{C} F : C → C , where C \mathcal{C} C is a category of data types. In this paper we assume that C \mathcal{C} C is the category of sets (see, e.g., [2 ] ). If F F F is bicontinuous, i.e., it preserves the colimits of ω \omega ω -sequences and the limits of ω o p \omega^{op} ω o p -sequences, then the initial algebra (model) is obtained via colimit of the ω \omega ω -sequence
0 → ! F 0 → F ! F F 0 = F 2 0 → F 2 ! F 3 0 → F 3 ! ⋯ (1) \mathbf{0} \xrightarrow{\ !\ } F\mathbf{0} \xrightarrow{F\,!\ } F F\mathbf{0}=F^2\mathbf{0} \xrightarrow{F^2!\ } F^3\mathbf{0} \xrightarrow{F^3!\ } \cdots \tag*{(1)} 0 ! F 0 F ! F F 0 = F 2 0 F 2 ! F 3 0 F 3 ! ⋯ (1)
where 0 \mathbf{0} 0 is the initial object in C \mathcal{C} C , and 0 → ! X \mathbf{0} \xrightarrow{\ !\ } X 0 ! X is the unique arrow from the initial object [2 ] , and the final coalgebra (model) is the limit of the ω o p \omega^{op} ω o p -sequence
1 ← ! F 1 ← F ! F F 1 = F 2 1 ← F 2 ! F 3 1 ← F 3 ! ⋯ (2) \mathbf{1} \xleftarrow{\ !\ } F\mathbf{1} \xleftarrow{F\,!\ } F F\mathbf{1}=F^2\mathbf{1} \xleftarrow{F^2!\ } F^3\mathbf{1} \xleftarrow{F^3!\ } \cdots \tag*{(2)} 1 ! F 1 F ! F F 1 = F 2 1 F 2 ! F 3 1 F 3 ! ⋯ (2)
where 1 \mathbf{1} 1 is the final object in C \mathcal{C} C , and 1 ← ! X \mathbf{1} \xleftarrow{\ !\ } X 1 ! X is the unique arrow to the final object [2 ] .
This is a nice abstract framework, but, as we know, the evil is hidden in details. How the elements of the initial and final models look like for various concrete functors? How could they be handled in practice?
A possible answer can be obtained by capturing these objects in Matching Logic (ML), the logical foundation of the K Framework, where the program languages and the properties of their programs can be specified in a uniform way (see, e.g., [16 , 10 , 17 , 8 , 14 ] ). First steps are done in [7 ] , where the initial algebra semantics is captured in ML (see [9 ] for the journal version, which also derives induction and iteration principles), and in [8 ] , where it is shown how examples of inductive/coinductive data types are fully specified in ML. Data types are usually parametric: lists depend on a set of elements, and, more generally, the data types considered in this paper depend on a set of shapes and a family of sets of positions (§ 2 ). We write D T ( P ) DT(P) D T ( P ) for a data type with parameter sets P P P , which are represented in ML by parameter sorts. We say that ML captures a (inductive/coinductive) data type D T ( P ) DT(P) D T ( P ) if there is an ML theory T h M L ( D T ) \mathrm{Th}^{\mathrm{ML}}(DT) Th ML ( D T ) such that:
from each T h M L ( D T ) \mathrm{Th}^{\mathrm{ML}}(DT) Th ML ( D T ) -model M M M we may extract a structure α ( M ) \alpha(M) α ( M ) that is isomorphic to D T ( P M ) DT(P_M) D T ( P M ) , where P M P_M P M is the interpretation of the parameter sorts in M M M , and
the deduction principles considered here for D T DT D T , namely induction for initial algebras, coinduction for final coalgebras, and the bisimulation principle for equality, can be expressed as theorems within ML using its proof system.
Other principles, such as iteration and primitive recursion, are outside the scope of this paper (see the Conclusion). In this paper, the first condition is established by the adequacy theorems, which are semantic statements about all models, and the second by derivations in the ML proof system; § 5.1 classifies all the results in this way. If, moreover, the theory captures the parameters themselves, i.e., P M ≅ P P_M \cong P P M ≅ P in every model (e.g., for finite or inductively defined sets), then α ( M ) \alpha(M) α ( M ) is isomorphic to D T ( P ) DT(P) D T ( P ) in every model. Without such axioms, a model may interpret the parameter sorts differently: for a constant functor with one shape and no positions, a model with two shapes yields a two-element initial algebra.
In this paper, we investigate how data types specified as initial F F F -algebras or as final F F F -coalgebras, where F F F is a polynomial functor, can be captured in ML. The term “polynomial functor” is used in the literature for two different classes of functors:
the classical polynomial functors (see, e.g., [18 ] ): the smallest class of functors that includes the constant and the identity functors and is closed under sum, product, and exponentiation by a constant object;
the (unary) container functors (see, e.g., [1 , 3 ] ): the functors of the form X ↦ ∑ a : A X B [ a ] X \mapsto\sum_{a:A} X^{B[a]} X ↦ ∑ a : A X B [ a ] , where a : A → B [ a ] a:A \to B[a] a : A → B [ a ] is an A A A -indexed family.
Every classical polynomial functor is naturally isomorphic to a container functor (§ 2.1 ). In this paper, polynomial functor means polynomial in the container sense , i.e., a unary container functor. In particular, everything we say applies to the classical polynomial functors.
The constant and the identity functors, together with their initial and final models, can be easily captured in ML. Moreover, if we exclude the exponent functor, then the initial algebra can be captured using the approach similar to that from [7 ] . The exponent functor complicates things. A possible approach for the classical definition is as follows: supposing that we have captured F 1 X F_1 X F 1 X and F 2 X F_2 X F 2 X by the ML theories (specifications) SPEC ( F 1 X ) \operatorname{SPEC}(F_1 X) SPEC ( F 1 X ) and resp. SPEC ( F 2 X ) \operatorname{SPEC}(F_2 X) SPEC ( F 2 X ) , then use these specifications to build SPEC ( F 1 X op F 2 X ) \operatorname{SPEC}(F_1 X\mathbin{\operatorname{op}} F_2 X) SPEC ( F 1 X op F 2 X ) , i.e., to obtain something like
SPEC ( F 1 X op F 2 X ) = SPEC ( F 1 X ) op ‾ SPEC ( F 2 X ) \operatorname{SPEC}(F_1 X\mathbin{\operatorname{op}} F_2 X)=\operatorname{SPEC}(F_1 X)\mathbin{\overline{\operatorname{op}}}\operatorname{SPEC}(F_2 X) SPEC ( F 1 X op F 2 X ) = SPEC ( F 1 X ) op SPEC ( F 2 X )
where op ‾ \overline{\operatorname{op}} op reflects o p op o p to the level of ML specifications, and is yet to be defined. In order to accomplish that, we need a “uniform standard” definition for the specifications SPEC ( F X ) \operatorname{SPEC}(F X) SPEC ( F X ) .
The container functors already have a uniform standard definition, and therefore they are more tempting for our investigation. The results of this paper show that:
it is possible to specify unary container functors, together with their initial algebras and final coalgebras, as well-formed ML theories (Definition 4.1), which are satisfiable (Theorem B.2), for arbitrary unary containers, including the boundary cases of empty shape and position sets, empty exponent domains, infinite position sets, and empty initial algebras with non-empty final coalgebras (Section 4.9);
the specification of the initial algebra captures it (a semantic result): for every model M M M , the algebra α μ ( M ) \alpha_\mu(M) α μ ( M ) extracted from M M M is an initial algebra, isomorphic to the W-type of the shapes and positions of M M M (Theorem 4.4); such models exist (Proposition 4.6);
the specification of the final coalgebra, which includes an axiom identifying bisimilar elements and an axiom ensuring that every behaviour is realised, captures it (a semantic result): for every model M M M , the coalgebra α ν ( M ) \alpha_\nu(M) α ν ( M ) extracted from M M M is a final coalgebra, isomorphic to the M-type of the shapes and positions of M M M (Theorem 4.15); such models exist (Proposition 4.18);
these results depend on how a model interprets the sorts of shapes and positions; when these sorts are given by finite sets, products, dependent sums, or (co)inductive sorts built from them, the isomorphisms hold with the intended shapes and positions in every model (Theorem 4.21); for parameter sets that are meant to be arbitrary, the results are relative to their interpretation;
the induction principle, the coinduction principle, and the bisimulation principle are derivable in the ML proof system, from the Knaster–Tarski rule and the axioms;
The approach is instantiated on the lists example, in order to see the relationship with the classical approach of these data types, and on that of Moore machines, in order to see the (constant) exponential functor at work.
The paper is structured as follows. Section 2 recalls the classical polynomial functors and the unary container functors, and shows that the former class is included in the latter. Section 3 briefly recalls the main elements of matching logic, together with the theories of the equality and of the sorts. Section 4 includes the main contribution, showing how the unary container functors and their related concepts can be specified in matching logic. The instantiation of the general approach on the examples of lists and Moore machines are included in Section 5 and Section 6, respectively. The paper ends with some concluding remarks.
Polynomial Functors and Container Functors
This section briefly recalls (co)algebras of functors, the classical polynomial functors, and the container functors, and compares the two classes of functors. We consider only the particular case of the functors defined over the category of sets C \mathsf{C} C .
Definition 2.1. [13 ] Given a functor F : C → C F : \mathsf{C} \to\mathsf{C} F : C → C , an F F F -algebra consists of an object X X X in C \mathsf{C} C and an arrow α : F X → X \alpha: F X \to X α : F X → X . An algebra morphism ( X , α ) → ( X ′ , α ′ ) (X,\alpha) \to(X',\alpha') ( X , α ) → ( X ′ , α ′ ) is an arrow h : X → X ′ h : X \to X' h : X → X ′ in C \mathsf{C} C such that h ∘ α = α ′ ∘ F h h \circ\alpha= \alpha' \circ F h h ∘ α = α ′ ∘ F h . An initial algebra for the functor F F F is an initial object in the category of F F F -algebras and F F F -algebra morphisms.
Example 2.2 (Lists). The lists over a set of elements E E E can be defined as an L s t Lst L s t -algebra α : L s t X → X \alpha: Lst X \to X α : L s tX → X for the functor L s t : C → C Lst : \mathsf{C} \to\mathsf{C} L s t : C → C given by L s t X = 1 + E × X Lst X = 1 + E \times X L s tX = 1 + E × X . Usually, such an algebra is defined by a constant
n i l : 1 → X nil:1 \to X ni l : 1 → X and a binary operation c o n s : E × X → X cons:E \times X \to X co n s : E × X → X . The initial L s t Lst L s t -algebra is isomorphic to the finite lists inductively defined [19 ] by the grammar
L i s t : : = n i l ∣ c o n s ( E , L i s t ) List ::= nil \mid cons(E,List) L i s t ::= ni l ∣ co n s ( E , L i s t )
We use μ X . L s t X \mu X.Lst\ X μ X . L s t X or μ L s t \mu Lst μL s t to denote the initial model of the functor L s t Lst L s t .
Definition 2.3. [13 ] Given a functor F : C → C F:\mathcal{C} \to\mathcal{C} F : C → C , an F F F -coalgebra consists of an object X X X in C \mathcal{C} C and an arrow γ : X → F X \gamma:X \to F\ X γ : X → F X . A coalgebra morphism ( X , γ ) → ( X ′ , γ ′ ) (X,\gamma) \to(X',\gamma') ( X , γ ) → ( X ′ , γ ′ ) is an arrow h : X → X ′ h:X \to X' h : X → X ′ in C \mathcal{C} C such that F h ∘ γ = γ ′ ∘ h Fh \circ\gamma= \gamma' \circ h F h ∘ γ = γ ′ ∘ h . A final coalgebra for the functor F F F is a final object in the category of F F F -coalgebras and F F F -coalgebra morphisms.
Example 2.4 (Colists). The colists over a set of elements E E E can be defined as an L s t Lst L s t -coalgebra γ : X → L s t X \gamma:X \to Lst\ X γ : X → L s t X , where L s t Lst L s t is the functor used for lists (see Example 2.2). Usually, such a coalgebra is defined by
a total operation . ? : X → { 1 , 2 } _.? : X \to\{1,2\} . ? : X → { 1 , 2 } such that x . ? = if γ ( x ) = ι 1 ( ⋆ ) then 1 else 2 fi x.? = \text{if }\gamma(x)=\iota_1(\star)\text{ then }1\text{ else }2\text{ fi} x . ? = if γ ( x ) = ι 1 ( ⋆ ) then 1 else 2 fi , where ⋆ \star ⋆ is the unique element of 1 1 1 , and
two partial operations: . h d : X ⇀ E _.hd:X \rightharpoonup E . h d : X ⇀ E , and . t l : X ⇀ X _.tl:X \rightharpoonup X . tl : X ⇀ X such that x . h d = e x.hd=e x . h d = e and x . t l = x ′ x.tl=x' x . tl = x ′ iff x . ? = 2 x.?=2 x . ? = 2 and γ ( x ) = ι 2 ( ⟨ e , x ′ ⟩ ) \gamma(x)=\iota_2(\langle e,x'\rangle) γ ( x ) = ι 2 (⟨ e , x ′ ⟩) .
The final coalgebra is isomorphic to the possible infinite lists coinductively defined by the grammar (LST) [19 ] . We use ν X . L s t X \nu X.Lst\ X ν X . L s t X or ν L s t \nu Lst ν L s t to denote the final model of the functor L s t Lst L s t .
Example 2.5 (Moore machines). A Moore machine is an M \mathcal{M} M -coalgebra α : X → M X \alpha:X \to\mathcal{M}\ X α : X → M X , where M \mathcal{M} M is the functor M : X ↦ O × X I \mathcal{M}:X \mapsto O \times X^I M : X ↦ O × X I , where I I I is the set of inputs and O O O is the set of outputs. Usually, a Moore machine is defined by an output function o u t : X → O out:X \to O o u t : X → O and a transition function t r : X → X I tr:X \to X^I t r : X → X I [18 ] . The final coalgebra ν X . M X \nu X.\mathcal{M}X ν X . M X is isomorphic to ( o u t ‾ , t r ‾ ) : O I ∗ → O × ( O I ∗ ) I (\overline{out},\overline{tr}):O^{I^*} \to O \times(O^{I^*})^I ( o u t , t r ) : O I ∗ → O × ( O I ∗ ) I , o u t ‾ ( f ) = f ( ϵ ) \overline{out}(f)=f(\epsilon) o u t ( f ) = f ( ϵ ) , t r ‾ ( f ) = g \overline{tr}(f)=g t r ( f ) = g with g ( i ) ( w ) = f ( ⟨ i ⟩ ⋅ w ) g(i)(w)=f(\langle i\rangle\cdot w) g ( i ) ( w ) = f (⟨ i ⟩ ⋅ w ) for i ∈ I i \in I i ∈ I and w ∈ I ∗ w \in I^* w ∈ I ∗ , where f f f is a function f : I ∗ → O f:I^* \to O f : I ∗ → O , g g g a function g : I → O I ∗ g:I \to O^{I^*} g : I → O I ∗ , ϵ \epsilon ϵ the empty sequence, and ⋅ \cdot ⋅ the concatenation of sequences.
Definition 2.6. [18 ] The class of classical polynomial functors is inductively defined as follows:
the constant functor A A A (where A A A is an object in C \mathcal{C} C ) is a classical polynomial functor;
the identity functor I D ID I D is a classical polynomial functor;
the sum F 1 + F 2 F_1+F_2 F 1 + F 2 of two classical polynomial functors F 1 F_1 F 1 and F 2 F_2 F 2 is a classical polynomial functor;
the product F 1 × F 2 F_1 \times F_2 F 1 × F 2 of two classical polynomial functors F 1 F_1 F 1 and F 2 F_2 F 2 is a classical polynomial functor; and
the exponent F C F^C F C of a classical polynomial functor F F F by an object C C C , given by F C X = ( F X ) C F^C X=(F X)^C F C X = ( F X ) C , is a classical polynomial functor.
Remark 2.7. Rutten [18 ] defines the class as all functors that can be built from the constant functors, the identity functor, sum, product, and the function space functor X ↦ X C X \mapsto X^C X ↦ X C ; building here includes composition. Definition 2.6 gives the same class: X ↦ X C X \mapsto X^C X ↦ X C is I D C ID^C I D C , and the class of Definition 2.6 is closed under composition, by induction on the outer functor H H H , since A ∘ F = A A \circ F=A A ∘ F = A , I D ∘ F = F ID \circ F=F I D ∘ F = F , ( H 1 + H 2 ) ∘ F = H 1 ∘ F + H 2 ∘ F (H_1+H_2)\circ F=H_1\circ F+H_2\circ F ( H 1 + H 2 ) ∘ F = H 1 ∘ F + H 2 ∘ F , ( H 1 × H 2 ) ∘ F = H 1 ∘ F × H 2 ∘ F (H_1 \times H_2)\circ F=H_1\circ F \times H_2\circ F ( H 1 × H 2 ) ∘ F = H 1 ∘ F × H 2 ∘ F , and H C ∘ F = ( H ∘ F ) C H^C \circ F=(H\circ F)^C H C ∘ F = ( H ∘ F ) C . Rutten also notes that including the function space functor is somewhat non-standard.
The (unary) container functors [1 , 4 , 3 ] form a second class of functors, which includes the classical polynomial functors.
Definition 2.8. An A A A -indexed family a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] is a family of objects of C \mathcal{C} C indexed by elements of A A A . Categorically, it is an object B B B of C / A \mathcal{C}/A C / A and B [ a ] B[a] B [ a ] denotes the elements of B B B mapped to a a a .
Definition 2.9. Given an A A A -indexed family a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] , the dependent product ∏ a : A B [ a ] \prod_{a:A} B[a] ∏ a : A B [ a ] is the object of the dependent functions , which maps an a : A a:A a : A into a b : B [ a ] b:B[a] b : B [ a ] . Set theoretically, we have
∏ a : A B [ a ] = { f ∈ ( ⋃ a : A B [ a ] ) A ∣ ∀ a : A . f ( a ) ∈ B [ a ] } \prod_{a:A} B[a] = \left\{ f \in\left(\bigcup_{a:A} B[a]\right)^{A} \mathrel{\Big|} \forall a:A.f(a) \in B[a] \right\} a : A ∏ B [ a ] = ⎩ ⎨ ⎧ f ∈ ( a : A ⋃ B [ a ] ) A ∀ a : A . f ( a ) ∈ B [ a ] ⎭ ⎬ ⎫ The dependent sum ∑ a : A B [ a ] \sum_{a:A} B[a] ∑ a : A B [ a ] is the dual of the dependent product and it consists of the pairs ⟨ a , b ⟩ \langle a,b\rangle ⟨ a , b ⟩ with a : A a:A a : A and b : B [ a ] b:B[a] b : B [ a ] .
Definition 2.10. A functor F : C → C F:\mathcal{C}\to\mathcal{C} F : C → C is a (unary) container functor iff it is naturally isomorphic to a functor of the form F X = ∑ a : A X B [ a ] F X = \sum_{a:A} X^{B[a]} F X = ∑ a : A X B [ a ] , for some objects A A A in C \mathcal{C} C and an A A A -indexed family a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] .
Classical Polynomial Functors are Container Functors
Container functors are closed under sum, product, and exponentiation by a constant object [1 ] . We recall these constructions below. Together with the container representations of the constant and the identity functors, they show, by induction on Definition 2.6, that every classical polynomial functor is naturally isomorphic to a container functor.
Constant Functor
The main idea is to identify the constant value with the shapes A A A . Consider B B B as being a : A ⊢ 0 a:A \vdash0 a : A ⊢ 0 (no positions of shape a a a ), where 0 0 0 denotes the initial object of C \mathcal{C} C . We get ∑ a : A X B [ a ] ≅ ∑ a : A X 0 ≅ A \sum_{a:A} X^{B[a]} \cong\sum_{a:A} X^0 \cong A ∑ a : A X B [ a ] ≅ ∑ a : A X 0 ≅ A .
Identity Functor
Consider A A A as being 1 1 1 (just one shape) and B B B as being ⋆ : 1 ⊢ 1 \star:1\vdash1 ⋆ : 1 ⊢ 1 (just one position), where ⋆ \star ⋆ is the unique element in 1 1 1 . It follows that ∑ a : A X B [ a ] ≅ ∑ ⋆ X 1 ≅ X \sum_{a:A} X^{B[a]} \cong\sum_{\star} X^1 \cong X ∑ a : A X B [ a ] ≅ ∑ ⋆ X 1 ≅ X .
Sum
Assume that F X = ∑ a : A X B [ a ] F X = \sum_{a:A} X^{B[a]} F X = ∑ a : A X B [ a ] and F ′ X = ∑ a ′ : A ′ X B ′ [ a ′ ] F' X = \sum_{a':A'} X^{B'[a']} F ′ X = ∑ a ′ : A ′ X B ′ [ a ′ ] . Then ( F + F ′ ) X (F+F')X ( F + F ′ ) X is ∑ a ′ ′ : A + A ′ X [ B , B ′ ] [ a ′ ′ ] \sum_{a'':A+A'} X^{[B,B'][a'']} ∑ a ′′ : A + A ′ X [ B , B ′ ] [ a ′′ ] , where [ B , B ′ ] [ a ′ ′ ] = B [ a ] [B,B'][a''] = B[a] [ B , B ′ ] [ a ′′ ] = B [ a ] if a ′ ′ = ι 1 a a''=\iota_1 a a ′′ = ι 1 a , and [ B , B ′ ] [ a ′ ′ ] = B ′ [ a ′ ] [B,B'][a''] = B'[a'] [ B , B ′ ] [ a ′′ ] = B ′ [ a ′ ] if a ′ ′ = ι 2 a ′ a''=\iota_2 a' a ′′ = ι 2 a ′ .
The arrow B + B ′ → A + A ′ B+B' \to A+A' B + B ′ → A + A ′ is equivalently written as the A + A ′ A+A' A + A ′ -indexed set a ′ ′ : A + A ′ ⊢ [ B , B ′ ] [ a ′ ′ ] a'' : A+A' \vdash[B,B'][a''] a ′′ : A + A ′ ⊢ [ B , B ′ ] [ a ′′ ] . Set theoretically, ∑ a ′ ′ : A + A ′ X [ B , B ′ ] [ a ′ ′ ] \sum_{a'' : A+A'} X^{[B,B'][a'']} ∑ a ′′ : A + A ′ X [ B , B ′ ] [ a ′′ ] is the set of pairs ⟨ a ′ ′ , [ f , f ′ ] : [ B , B ′ ] [ a ′ ′ ] → X ⟩ \langle a'', [f,f'] : [B,B'][a''] \to X\rangle ⟨ a ′′ , [ f , f ′ ] : [ B , B ′ ] [ a ′′ ] → X ⟩ , where
either a ′ ′ = ι 1 a a'' = \iota_1 a a ′′ = ι 1 a , ⟨ a , f : B [ a ] → X ⟩ \langle a,f : B[a] \to X\rangle ⟨ a , f : B [ a ] → X ⟩ in F X F X F X , and ∀ x : B [ a ] . [ f , f ′ ] x = f x \forall x : B[a]. [f,f']x = fx ∀ x : B [ a ] . [ f , f ′ ] x = f x , or
a ′ ′ = ι 2 a ′ a'' = \iota_2 a' a ′′ = ι 2 a ′ , ⟨ a ′ , f ′ : B ′ [ a ′ ] → X ⟩ \langle a',f' : B'[a'] \to X\rangle ⟨ a ′ , f ′ : B ′ [ a ′ ] → X ⟩ in F ′ X F' X F ′ X , and ∀ x ′ : B ′ [ a ′ ] . [ f , f ′ ] x ′ = f ′ x ′ \forall x' : B'[a']. [f,f']x' = f'x' ∀ x ′ : B ′ [ a ′ ] . [ f , f ′ ] x ′ = f ′ x ′ .
In other words, the shapes of the sum are the disjoint union of the component shapes, and a shape selects one component: the positions and the labelling function of an element of the sum are those of the selected component, so [ f , f ′ ] [f,f'] [ f , f ′ ] is f f f or f ′ f' f ′ . The object B + B ′ B+B' B + B ′ in the diagram is the total object of positions over A + A ′ A+A' A + A ′ , not the position set of a single shape; position sets of a single shape are combined by disjoint union only in the product construction below.
Product
With F X F X F X and F ′ X F' X F ′ X as for the sum, we have ( F × F ′ ) X ≅ ∑ ⟨ a , a ′ ⟩ : A × A ′ X ⟨ B , B ′ ⟩ [ ⟨ a , a ′ ⟩ ] (F \times F')X \cong\sum_{\langle a,a'\rangle: A \times A'} X^{\langle B,B'\rangle[\langle a,a'\rangle]} ( F × F ′ ) X ≅ ∑ ⟨ a , a ′ ⟩ : A × A ′ X ⟨ B , B ′ ⟩ [⟨ a , a ′ ⟩] , where ⟨ B , B ′ ⟩ [ ⟨ a , a ′ ⟩ ] = B [ a ] + B ′ [ a ′ ] \langle B,B'\rangle[\langle a,a'\rangle] = B[a] + B'[a'] ⟨ B , B ′ ⟩ [⟨ a , a ′ ⟩] = B [ a ] + B ′ [ a ′ ] (the positions of the product are the disjoint union of the component positions); in contrast with the sum, where a shape selects the position set of one component, a shape ⟨ a , a ′ ⟩ \langle a,a'\rangle ⟨ a , a ′ ⟩ of the product has the disjoint union of the position sets of both components.
Remark 2.15. We write ⟨ B , B ′ ⟩ [ a , a ′ ] \langle B,B'\rangle[a,a'] ⟨ B , B ′ ⟩ [ a , a ′ ] for ⟨ B , B ′ ⟩ [ ⟨ a , a ′ ⟩ ] \langle B,B'\rangle[\langle a,a'\rangle] ⟨ B , B ′ ⟩ [⟨ a , a ′ ⟩] . Set theoretically, ∑ ⟨ a , a ′ ⟩ : A × A ′ X ⟨ B , B ′ ⟩ [ a , a ′ ] \sum_{\langle a,a'\rangle: A \times A'} X^{\langle B,B'\rangle[a,a']} ∑ ⟨ a , a ′ ⟩ : A × A ′ X ⟨ B , B ′ ⟩ [ a , a ′ ] is the set of pairs ⟨ ⟨ a , a ′ ⟩ , [ f , f ′ ] : B [ a ] + B ′ [ a ′ ] → X ⟩ \langle\langle a,a'\rangle,[f,f'] : B[a] + B'[a'] \to X\rangle ⟨⟨ a , a ′ ⟩ , [ f , f ′ ] : B [ a ] + B ′ [ a ′ ] → X ⟩ , where f : B [ a ] → X f : B[a] \to X f : B [ a ] → X and f ′ : B ′ [ a ′ ] → X f' : B'[a'] \to X f ′ : B ′ [ a ′ ] → X . In other words, the shape of the product is the product of the component shapes and a labelling function for the product is the sum of two corresponding component labelling functions.
Exponentiation
Assuming F X = ∑ a : A X B [ a ] F X = \sum_{a : A} X^{B[a]} F X = ∑ a : A X B [ a ] , the (constant) exponent functor ( F X ) C (F X)^C ( F X ) C is ∑ g : C → A X ∑ c : C B [ g c ] \sum_{g : C \to A} X^{\sum_{c : C} B[g c]} ∑ g : C → A X ∑ c : C B [ g c ] .
Remark 2.16. An element of ∑ g : C → A X ∑ c : C B [ g c ] \sum_{g : C \to A} X^{\sum_{c : C} B[g c]} ∑ g : C → A X ∑ c : C B [ g c ] is a pair ⟨ g , f ⟩ \langle g,f\rangle ⟨ g , f ⟩ consisting of a function g : C → A g : C \to A g : C → A assigning shapes to C C C and a C C C -indexed function c : C ⊢ f c : B [ g c ] → X c : C \vdash f_c : B[g c] \to X c : C ⊢ f c : B [ g c ] → X labelling the positions B [ g c ] B[g c] B [ g c ] for each c c c in C C C .
Matching Logic (ML)
Matching logic [16 , 10 , 8 ] provides a unifying framework for defining semantics of programming languages. A programming language is defined in matching logic as a logical theory , i.e., a set of axioms. The key concept in matching logic is that of patterns , which can be matched by certain elements. By building complex patterns, we can match elements that have complex structures or certain properties, or both. The presentation of matching logic in this review section follows [8 ] .
Definition 3.1. Let us fix two sets E V EV E V and S V SV S V . The set E V EV E V includes element variables x , y , … x,y,\ldots x , y , … . The set S V SV S V includes set variables X , Y , … X,Y,\ldots X , Y , … . A matching logic signature Σ \Sigma Σ is a set of (constant) symbols , denoted σ , σ 1 , σ 2 , … \sigma,\sigma_1,\sigma_2,\ldots σ , σ 1 , σ 2 , … . Let us fix a signature Σ \Sigma Σ . The set of ( Σ (\Sigma ( Σ -)patterns is inductively defined as follows:
φ : : = x ∣ X ∣ σ ∣ φ 1 φ 2 ∣ ⊥ ∣ φ 1 → φ 2 ∣ ∃ x . φ ∣ μ X . φ \varphi::= x \mid X \mid\sigma\mid\varphi_1\ \varphi_2 \mid\bot\mid\varphi_1 \to\varphi_2 \mid\exists x.\ \varphi\mid\mu X.\ \varphi φ ::= x ∣ X ∣ σ ∣ φ 1 φ 2 ∣ ⊥ ∣ φ 1 → φ 2 ∣ ∃ x . φ ∣ μ X . φ where in μ X . φ \mu X.\ \varphi μ X . φ , called a least-fixpoint pattern, we require that φ \varphi φ is positive in X X X , i.e., every free occurrence of X X X in φ \varphi φ lies within an even number of left-hand sides of implications φ 1 → φ 2 \varphi_1 \to\varphi_2 φ 1 → φ 2 .
Definition 3.2. A *(matching logic) Σ \Sigma Σ -model M M M consists of
a nonempty carrier set , which we also denote M M M ;
an application function ∙ : M × M → P ( M ) \mathbin{\bullet}:M \times M \to\mathcal{P}(M) ∙ : M × M → P ( M ) , where P ( M ) \mathcal{P}(M) P ( M ) is the powerset of M M M ; and
a symbol interpretation σ M ⊆ M \sigma_M \subseteq M σ M ⊆ M as a subset for σ ∈ Σ \sigma\in\Sigma σ ∈ Σ .
Definition 3.3. Given M M M and a variable valuation ρ : ( E V ∪ S V ) → M ∪ P ( M ) \rho:(EV \cup SV) \to M \cup\mathcal{P}(M) ρ : ( E V ∪ S V ) → M ∪ P ( M ) such that ρ ( x ) ∈ M \rho(x) \in M ρ ( x ) ∈ M for x ∈ E V x \in EV x ∈ E V and ρ ( X ) ⊆ M \rho(X) \subseteq M ρ ( X ) ⊆ M for X ∈ S V X \in SV X ∈ S V , we inductively define pattern valuation ∣ φ ∣ M , ρ \lvert\varphi\rvert_{M,\rho} ∣ φ ∣ M , ρ as follows:
∣ x ∣ M , ρ = { ρ ( x ) } \lvert x\rvert_{M,\rho} = \{\rho(x)\} ∣ x ∣ M , ρ = { ρ ( x )} for x ∈ E V x \in EV x ∈ E V
∣ X ∣ M , ρ = ρ ( X ) \lvert X\rvert_{M,\rho} = \rho(X) ∣ X ∣ M , ρ = ρ ( X ) for X ∈ S V X \in SV X ∈ S V
∣ σ ∣ M , ρ = σ M \lvert\sigma\rvert_{M,\rho} = \sigma_M ∣ σ ∣ M , ρ = σ M for σ ∈ Σ \sigma\in\Sigma σ ∈ Σ
∣ φ 1 φ 2 ∣ M , ρ = ⋃ a i ∈ ∣ φ i ∣ M , ρ , i ∈ { 1 , 2 } a 1 ∙ a 2 \lvert\varphi_1\varphi_2\rvert_{M,\rho} = \bigcup_{a_i \in\lvert\varphi_i\rvert_{M,\rho},\,i \in\{1,2\}} a_1 \mathbin{\bullet} a_2 ∣ φ 1 φ 2 ∣ M , ρ = ⋃ a i ∈ ∣ φ i ∣ M , ρ , i ∈ { 1 , 2 } a 1 ∙ a 2 ; note that a 1 ∙ a 2 a_1 \mathbin{\bullet} a_2 a 1 ∙ a 2 is a subset of M M M .
∣ ⊥ ∣ M , ρ = ∅ \lvert\bot\rvert_{M,\rho} = \varnothing ∣ ⊥ ∣ M , ρ = ∅
∣ φ 1 → φ 2 ∣ M , ρ = M ∖ ( ∣ φ 1 ∣ M , ρ ∖ ∣ φ 2 ∣ M , ρ ) \lvert\varphi_1 \to\varphi_2\rvert_{M,\rho} = M \setminus\left(\lvert\varphi_1\rvert_{M,\rho} \setminus\lvert\varphi_2\rvert_{M,\rho}\right) ∣ φ 1 → φ 2 ∣ M , ρ = M ∖ ( ∣ φ 1 ∣ M , ρ ∖ ∣ φ 2 ∣ M , ρ )
∣ ∃ x . φ ∣ M , ρ = ⋃ a ∈ M ∣ φ ∣ M , ρ [ a / x ] \lvert\exists x.\,\varphi\rvert_{M,\rho} = \bigcup_{a \in M} \lvert\varphi\rvert_{M,\rho[a/x]} ∣ ∃ x . φ ∣ M , ρ = ⋃ a ∈ M ∣ φ ∣ M , ρ [ a / x ]
∣ μ X . φ ∣ M , ρ = lfp ( A ↦ ∣ φ ∣ M , ρ [ A / X ] ) \lvert\mu X.\,\varphi\rvert_{M,\rho} = \operatorname{lfp}\left(A \mapsto\lvert\varphi\rvert_{M,\rho[A/X]}\right) ∣ μ X . φ ∣ M , ρ = lfp ( A ↦ ∣ φ ∣ M , ρ [ A / X ] )
where ρ [ a / x ] \rho[a/x] ρ [ a / x ] (resp. ρ [ A / X ] \rho[A/X] ρ [ A / X ] ) is the valuation ρ ′ \rho' ρ ′ with ρ ′ ( x ) = a \rho'(x) = a ρ ′ ( x ) = a (resp. ρ ′ ( X ) = A \rho'(X) = A ρ ′ ( X ) = A ) and agreeing with ρ \rho ρ on all the other variables, i.e., on E V ∪ S V ∖ { x } EV \cup SV \setminus\{x\} E V ∪ S V ∖ { x } (resp. E V ∪ S V ∖ { X } EV \cup SV \setminus\{X\} E V ∪ S V ∖ { X } ). We use lfp ( A ↦ ∣ φ ∣ M , ρ [ A / X ] ) \operatorname{lfp}\left(A \mapsto\lvert\varphi\rvert_{M,\rho[A/X]}\right) lfp ( A ↦ ∣ φ ∣ M , ρ [ A / X ] ) to denote the smallest set A A A such that A = ∣ φ ∣ M , ρ [ A / X ] A = \lvert\varphi\rvert_{M,\rho[A/X]} A = ∣ φ ∣ M , ρ [ A / X ] . The existence of such an A A A is guaranteed by the requirement that φ \varphi φ is positive in X X X . We abbreviate ∣ φ ∣ M , ρ \lvert\varphi\rvert_{M,\rho} ∣ φ ∣ M , ρ as ∣ φ ∣ ρ \lvert\varphi\rvert_\rho ∣ φ ∣ ρ and further as ∣ φ ∣ \lvert\varphi\rvert ∣ φ ∣ if φ \varphi φ is closed.
Definition 3.4. We say that φ \varphi φ holds in M M M , written M ⊨ φ M \models\varphi M ⊨ φ , if ∣ φ ∣ M , ρ = M \lvert\varphi\rvert_{M,\rho} = M ∣ φ ∣ M , ρ = M for all ρ \rho ρ . For a pattern set Γ \Gamma Γ , we write M ⊨ Γ M \models\Gamma M ⊨ Γ , if M ⊨ ψ M \models\psi M ⊨ ψ for all ψ ∈ Γ \psi\in\Gamma ψ ∈ Γ . We write Γ ⊨ φ \Gamma\models\varphi Γ ⊨ φ , if M ⊨ Γ M \models\Gamma M ⊨ Γ implies M ⊨ φ M \models\varphi M ⊨ φ for all M M M .
The following common constructs can be defined from the basic pattern syntax as syntactic sugar in the usual way:
¬ φ ≡ φ → ⊥ φ 1 ∨ φ 2 ≡ ¬ φ 1 → φ 2 φ 1 ∧ φ 2 ≡ ¬ ( ¬ φ 1 ∨ ¬ φ 2 ) \neg\varphi\equiv\varphi\to\bot\qquad\varphi_1 \lor\varphi_2 \equiv\neg\varphi_1 \to\varphi_2 \qquad\varphi_1 \land\varphi_2 \equiv\neg(\neg\varphi_1 \lor\neg\varphi_2) ¬ φ ≡ φ → ⊥ φ 1 ∨ φ 2 ≡ ¬ φ 1 → φ 2 φ 1 ∧ φ 2 ≡ ¬ ( ¬ φ 1 ∨ ¬ φ 2 )
⊤ ≡ ¬ ⊥ ∀ x . φ ≡ ¬ ∃ x . ¬ φ ν X . φ ≡ ¬ μ X . ¬ φ [ ¬ X / X ] \top\equiv\neg\bot\qquad\forall x.\,\varphi\equiv\neg\exists x.\,\neg\varphi\qquad\nu X.\,\varphi\equiv\neg\mu X.\,\neg\varphi[\neg X/X] ⊤ ≡ ¬⊥ ∀ x . φ ≡ ¬∃ x . ¬ φ ν X . φ ≡ ¬ μ X . ¬ φ [ ¬ X / X ]
We assume the standard precedence between the above constructs.
Equality
The equality can be defined as a derived construct (see [16 , 8 ] ). The pattern φ 1 = φ 2 \varphi_1 = \varphi_2 φ 1 = φ 2 is equivalent to ⊤ \top ⊤ if φ 1 \varphi_1 φ 1 and φ 2 \varphi_2 φ 2 are matched by the same elements, and to ⊥ \bot ⊥ otherwise. To express that in ML, a new symbol d e f ∈ Σ \mathit{def} \in\Sigma def ∈ Σ is introduced, called the definedness symbol, and specify it with the axiom (Definedness). The resulted theory can be described as follows:
spec EQUALITY
Symbols: def
Notations: ⌈ϕ⌉ ≡ def ϕ
Axioms: (Definedness) ∀x. ⌈x⌉
Notations:
⌊ϕ⌋ ≡ ¬⌈¬ϕ⌉ // totality
ϕ₁ = ϕ₂ ≡ ⌊ϕ₁ ↔ ϕ₂⌋ // equality
ϕ₁ ⊆ ϕ₂ ≡ ⌊ϕ₁ → ϕ₂⌋ // set inclusion
x ∈ ϕ ≡ x ⊆ ϕ // membership
endspec
Membership is defined for an element variable x x x . We also write φ ∈ ψ \varphi\in\psi φ ∈ ψ when φ \varphi φ is a functional pattern , i.e., one matched by exactly one element, such as a pair ⟨ b , f b ⟩ \langle b, f\ b\rangle ⟨ b , f b ⟩ of defined components; then φ ∈ ψ \varphi\in\psi φ ∈ ψ abbreviates ∃ z . φ = z ∧ z ∈ ψ \exists z.\ \varphi= z \land z \in\psi ∃ z . φ = z ∧ z ∈ ψ , where z z z is fresh, which is equivalent to φ ⊆ ψ \varphi\subseteq\psi φ ⊆ ψ .
Sorts
Matching logic has no builtin support for sorts. Instead, we define a theory of sorts to support arbitrary sort structures following the “sort-as-predicate” paradigm. A sort has a name and is associated with a set of its inhabitants . In matching logic, we use a symbol s ∈ Σ s \in\Sigma s ∈ Σ to represent the sort name and use ( inh s ) (\operatorname{inh}\ s) ( inh s ) to represent all its inhabitants, where inh ∈ Σ \operatorname{inh} \in\Sigma inh ∈ Σ is an ordinary symbol. For better readability, we define the notation ⊤ s ≡ inh s \top_s \equiv\operatorname{inh}\ s ⊤ s ≡ inh s .
spec SORT Imports: EQUALITY
Symbols: inh, Sort
Notations:
⊤s ≡ inh s // inhabitants of sort s
s1 ≤ s2 ≡ ⊤s1 ⊆ ⊤s2 // subsort relation
¬sφ ≡ (¬φ) ∧ ⊤s // negation within sort s
∀x:s. φ ≡ ∀x. x ∈ ⊤s → φ // ∀ within sort s
∃x:s. φ ≡ ∃x. x ∈ ⊤s ∧ φ // ∃ within sort s
μX:s. φ ≡ μX. ⊤s ∧ φ // μ within sort s
νX:s. φ ≡ νX. ⊤s ∧ φ // ν within sort s
φ:s ≡ ∃z:s. φ = z // “typing”
f:s1 ⊗ ⋯ ⊗ sn → s ≡ ∀x1:s1 ...∀xn:sn. ∃y:s. f x1 ...xn = y
// functional
f:s1 ⊗ ⋯ ⊗ sn ⇀ s ≡ ∀x1:s1 ...∀xn:sn. (f x1 ...xn = ⊥) ∨ ∃y:s. f x1 ...xn = y
// partially functional
Axioms:
∃x. Sort = x
Sort ∈ ⊤Sort
endspec
In μ X : s . φ \mu X:s.\ \varphi μ X : s . φ and ν X : s . φ \nu X:s.\ \varphi ν X : s . φ , we require that φ \varphi φ is positive in X X X and that X X X does not occur free in s s s . Note that X ⊆ ⊤ s X \subseteq\top_s X ⊆ ⊤ s cannot be used as a conjunct of the body, since X X X would occur negatively in it; intersecting the body with ⊤ s \top_s ⊤ s keeps it positive in X X X , and all fixpoints are then included in ⊤ s \top_s ⊤ s . The alternative f x 1 … x n = ⊥ f\ x_1\ldots x_n = \bot f x 1 … x n = ⊥ in the notation for partially functional symbols makes it meaningful also when s s s is empty; requiring ∃ y : s . f x 1 … x n ⊆ y \exists y:s.\ f\ x_1\ldots x_n \subseteq y ∃ y : s . f x 1 … x n ⊆ y instead would be unsatisfiable in that case, e.g., for a partial destructor f : s 1 ⇀ s 2 f:s_1 \rightharpoonup s_2 f : s 1 ⇀ s 2 with s 1 s_1 s 1 non-empty and s 2 s_2 s 2 empty, such as the head of a list over an empty sort of elements (§ 6 ).
The ML specifications for the sum, product, and function sorts are given in [8 ] . For reader convenience, we recall that of the product sorts in Appendix § 9 ; sum sorts and function sorts are not needed (Definition 4.1 ).
Specifying Initial Algebra and Final Coalgebra for Container Functors in ML
In this section we show how to specify a unary container functor in ML and how to extract the structures for their initial algebra and the final coalgebra. The theories used in the adequacy results are fixed by the following definition, which refers to the specifications given in this section and in Appendix § 9 . The remarks after it also refer forward to the parameter specifications of Definition 4.20 (§ 4.9 ) and to the models constructed in Appendix § 10 .
Definition 4.1. Let A A A be a sort symbol, the sort of shapes , and B B B a family symbol, the family of positions , and let X ↦ F X = ∑ a : A X B [ a ] X \mapsto F X = \sum_{a:A} X^{B[a]} X ↦ F X = ∑ a : A X B [ a ] be the intended container functor; in a model M M M , the functor determined by the theories is the container functor F M F_M F M extracted from M M M , defined in § 4.5 (Notation for models). The base theory Γ 0 \Gamma_0 Γ 0 consists of EQUALITY and SORT (§ 3 ), PAIR (Appendix § 9 , with (Pair Total)), the specification of the initial morphism ι \iota ι (Section 4.1), and the axioms (SHAPE SORT) and (POSITION SORT) of the indexed family a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] (§ 4.2 ). Then:
Γ F μ \Gamma_F^\mu Γ F μ is Γ 0 \Gamma_0 Γ 0 together with the axioms (MU SORT), (FUNCTIONAL), (NO CONFUSION), (NO JUNK), (EXT), and (TAB) of § 4.5 ;
Γ F ν \Gamma_F^\nu Γ F ν is Γ 0 \Gamma_0 Γ 0 together with the dependent sum P ≡ ∑ a : A B [ a ] P \equiv\sum_{a:A} B[a] P ≡ ∑ a : A B [ a ] (§ 4.3 ), the axioms of L i s t ( P ) \mathit{List}(P) List ( P ) , and the axioms (NU SORT), (FUNCTIONAL), (NO COJUNK), (NO COCONFUSION.1), (NO COCONFUSION.2), (BISIMILARITY), and (REALISATION) of § 4.6 ;
Γ F = Γ F μ ∪ Γ F ν \Gamma_F = \Gamma_F^\mu\cup\Gamma_F^\nu Γ F = Γ F μ ∪ Γ F ν .
The following remarks make the definition precise.
Signature. The signature of Γ F \Gamma_F Γ F consists of d e f \mathit{def} def , i n h \mathit{inh} inh , and S o r t \mathit{Sort} Sort (of EQUALITY and SORT); P a i r \mathit{Pair} Pair , p a i r \mathit{pair} pair , f s t \mathit{fst} fst , and s n d \mathit{snd} snd (of PAIR); i n i M o r \mathit{iniMor} iniMor ; A A A , B B B , and d e p O f \mathit{depOf} depOf ; D e p S u m \mathit{DepSum} DepSum , L i s t \mathit{List} List , p n i l \mathit{pnil} pnil , and p c o n s \mathit{pcons} pcons ; and c o n s \mathit{cons} cons , μ F \mu_F μ F , ν F \nu_F ν F , o u t \mathit{out} out , and n x t \mathit{nxt} nxt . Despite the notation, μ F \mu_F μ F and ν F \nu_F ν F are constant symbols, the names of two sorts, and not fixpoint patterns; their inhabitants are given by the fixpoint patterns of (NO JUNK) and (NO COJUNK).
Instances. PAIR is one set of axioms, quantified over all sorts; the specification of dependent sums is a scheme, instantiated in Γ F ν \Gamma_F^\nu Γ F ν once, for P P P .
Free set variables. The axioms (TAB) and (REALISATION) contain free set variables, R R R and T T T . Since an axiom holds in a model when it holds for all valuations, they speak about all subsets of the carrier. This is why the adequacy results are semantic (§ 5.1 ).
Parameters. The theories constrain the shapes and positions only by the axioms of the indexed family. For a concrete container, the theory used is Γ F ∪ Γ p a r \Gamma_F \cup\Gamma_{par} Γ F ∪ Γ p a r , where Γ p a r \Gamma_{par} Γ p a r specifies A A A and B B B , e.g., by the standard parameter specifications of Definition 4.20; the results of this section are stated for Γ F \Gamma_F Γ F , so they hold for every such extension. The specifications of 0 0 0 , ⋆ \star ⋆ , 1 1 1 , and ! ! ! in Section 4.1 are not part of Γ F \Gamma_F Γ F : 0 0 0 , ⋆ \star ⋆ , and 1 1 1 occur in parameter specifications, e.g., for lists (§ 6 ), and ! ! ! only in the categorical constructions of § 1 and § 2 .
Sums and functions. The sum sorts and function sorts of [8 ] are not part of these theories, and dependent products (§ 2 ) are used only at the level of sets, not specified as sorts. A finite sum of sorts, such as the shapes 1 ⊕ F 1 \oplus F 1 ⊕ F of lists, is represented as a dependent sum over a finite sort of tags, ∑ i : T a g C [ i ] \sum_{i:\mathit{Tag}} C[i] ∑ i : Tag C [ i ] , by the rules (Fin), (Fam), and (Sum) of Definition 4.20. This representation covers sums with any finite number of summands, the positions are then defined by cases on the tags, and its properties follow from (Pair Inj), which Γ 0 \Gamma_0 Γ 0 already contains (§ 6 ). So the sum sorts s 1 ⊕ s 2 s_1 \oplus s_2 s 1 ⊕ s 2 of [8 ] , with their injections and partial ejections, are not needed, and we do not recall their specification. Functions on positions are represented by the notation X B [ a ] X^{B[a]} X B [ a ] (§ 4.4 ),
whose codomain is a set variable and whose domain may be empty, with the axioms (EXT) and (TAB); so the function sorts of [8 ] are not needed either.
By Theorem B.2 in Appendix § 10 , Γ F \Gamma_F Γ F has a model, so Γ F \Gamma_F Γ F , Γ F μ \Gamma_F^\mu Γ F μ , and Γ F ν \Gamma_F^\nu Γ F ν are consistent.
Typing of the symbols The axioms of these theories give each symbol the following typing; in each case, the application is defined (matched by exactly one element) on the indicated arguments.
Table 1.
The destructors are axiomatized only on ν F \nu F ν F ; the theory Γ F μ \Gamma_F^\mu Γ F μ does not use them.
Capturing Elements from the Category C \mathcal{C} C
Of the specifications below, only that of \mathord{\¡} is part of the theories of Definition 4.1; 0 0 0 , ⋆ \star ⋆ , and 1 1 1 are used in parameter specifications, where they are the instances n = 0 n=0 n = 0 and n = 1 n=1 n = 1 of (Fin) in Definition 4.20, and ! ! ! only in the categorical constructions of Sections 1 and 2.
0 : S o r t ∧ T 0 = ⊥ (CAPTURES 0) 0\mathbin{:}\mathit{Sort} \land\mathsf{T}_0 = \perp\qquad\text{(CAPTURES 0)} 0 : Sort ∧ T 0 =⊥ (CAPTURES 0)
so 0 0 0 is a sort without inhabitants; the symbol 0 0 0 denotes the sort name, not ⊥ \perp ⊥ , which allows equations between sorts such as B [ a ] = 0 B[a] = 0 B [ a ] = 0 (Definition 4.20);
∃ y . ⋆ = y (SINGLETON) \exists y.\ \star= y \qquad\text{(SINGLETON)} ∃ y . ⋆ = y (SINGLETON)
1 : S o r t ∧ T 1 = ⋆ (CAPTURES 1) 1\mathbin{:}\mathit{Sort} \land\mathsf{T}_1 = \star\qquad\text{(CAPTURES 1)} 1 : Sort ∧ T 1 = ⋆ (CAPTURES 1)
Expressing Indexed Families in ML
An A A A -indexed family a : A ⊢ B [ a ] a \colon A \vdash B[a] a : A ⊢ B [ a ] is specified by a constant symbol d e p O f ∈ Σ depOf \in\Sigma d e pO f ∈ Σ , a notation B [ a ] ≡ d e p O f B a B[a] \equiv depOf\ B\ a B [ a ] ≡ d e pO f B a , and two axioms of the same kind:
A : S o r t A \colon Sort A : S or t (SHAPE SORT)
∀ a : A . B [ a ] : S o r t \forall a \colon A.\ B[a] \colon Sort ∀ a : A . B [ a ] : S or t (POSITION SORT)
Both use the typing notation φ : S o r t ≡ ∃ z : S o r t . φ = z \varphi\colon Sort \equiv\exists z \colon Sort.\ \varphi= z φ : S or t ≡ ∃ z : S or t . φ = z of Section 3: the first states that A A A denotes one element, which is a sort, and the second that, for each a : A a \colon A a : A , B [ a ] B[a] B [ a ] denotes one element, which is a sort.
Expressing Dependent Sums in ML
A dependent sum ∑ a : A B [ a ] \sum_{a \colon A} B[a] ∑ a : A B [ a ] is specified by a constant D e p S u m ∈ Σ DepSum \in\Sigma D e pS u m ∈ Σ , a notation ∑ a : A B [ a ] ≡ D e p S u m A B \sum_{a \colon A} B[a] \equiv DepSum\ A\ B ∑ a : A B [ a ] ≡ D e pS u m A B (a a a plays a local role and its name can be changed1 ), and by adding the axioms:
⊤ ∑ a : A B [ a ] = ∃ a : A . ∃ b : B [ a ] . ⟨ a , b ⟩ \top_{\sum_{a \colon A} B[a]} = \exists a \colon A.\ \exists b \colon B[a].\ \langle a,b\rangle ⊤ ∑ a : A B [ a ] = ∃ a : A . ∃ b : B [ a ] . ⟨ a , b ⟩
Expressing Unary Container Functors in ML
Let X ↦ F X = ∑ a : A X B [ a ] X \mapsto F\ X = \sum_{a \colon A} X^{B[a]} X ↦ F X = ∑ a : A X B [ a ] be a container functor. Recall that F X F\ X F X is the set of pairs ⟨ a , f ⟩ \langle a,f\rangle ⟨ a , f ⟩ with a : A a \colon A a : A and f : X B [ a ] f \colon X^{B[a]} f : X B [ a ] (or, equivalently, f : B [ a ] → X f \colon B[a] \to X f : B [ a ] → X ). We specify X B [ a ] X^{B[a]} X B [ a ] explicitly by the notation
X B [ a ] ≡ ∃ f . f ∧ ( ( ( ⊤ B [ a ] ≠ ⊥ ) ∧ ( ∀ b : B [ a ] . ∃ x . f b = x ∧ x ∈ X ) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ ⊤ B [ a ] ) → f b ′ = ⊥ ) ) ∨ ( ( ⊤ B [ a ] = ⊥ ) ∧ f = i ) ) X^{B[a]} \equiv\exists f.\ f \land\left(((\top_{B[a]} \ne\bot) \land(\forall b \colon B[a].\ \exists x.\ f\ b = x \land x \in X) \land(\forall b'.\ \neg(b' \in\top_{B[a]}) \to f\ b' = \bot)) \lor((\top_{B[a]} = \bot) \land f = i)\right) X B [ a ] ≡ ∃ f . f ∧ ( (( ⊤ B [ a ] = ⊥ ) ∧ ( ∀ b : B [ a ] . ∃ x . f b = x ∧ x ∈ X ) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ ⊤ B [ a ] ) → f b ′ = ⊥ )) ∨ (( ⊤ B [ a ] = ⊥ ) ∧ f = i ) )
and use it directly in the specification of ∑ a : A X B [ a ] \sum_{a \colon A} X^{B[a]} ∑ a : A X B [ a ] .
∃ a : A . ∃ f . ⟨ a , f ⟩ ∧ f ∈ X B [ a ] \exists a \colon A.\ \exists f.\ \langle a,f\rangle\land f \in X^{B[a]} ∃ a : A . ∃ f . ⟨ a , f ⟩ ∧ f ∈ X B [ a ]
which is equivalent to
∃ a : A . ∃ f . ⟨ a , f ⟩ ∧ ( ( ( ⊤ B [ a ] ≠ ⊥ ) ∧ ( ∀ b : B [ a ] . ∃ x . f b = x ∧ x ∈ X ) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ ⊤ B [ a ] ) → f b ′ = ⊥ ) ) ∨ ( ( ⊤ B [ a ] = ⊥ ) ∧ f = i ) ) \exists a \colon A.\ \exists f.\ \langle a,f\rangle\land\left(((\top_{B[a]} \ne\bot) \land(\forall b \colon B[a].\ \exists x.\ f\ b = x \land x \in X) \land(\forall b'.\ \neg(b' \in\top_{B[a]}) \to f\ b' = \bot)) \lor((\top_{B[a]} = \bot) \land f = i)\right) ∃ a : A . ∃ f . ⟨ a , f ⟩ ∧ ( (( ⊤ B [ a ] = ⊥ ) ∧ ( ∀ b : B [ a ] . ∃ x . f b = x ∧ x ∈ X ) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ ⊤ B [ a ] ) → f b ′ = ⊥ )) ∨ (( ⊤ B [ a ] = ⊥ ) ∧ f = i ) )
The notation X B [ a ] X^{B[a]} X B [ a ] is a pattern, not a sort: it is matched by the elements that behave as strict functions from T B [ a ] \mathsf{T}_{B[a]} T B [ a ] to X X X , where X X X may be any pattern, in particular a set variable, and T B [ a ] \mathsf{T}_{B[a]} T B [ a ] may be empty. This is what the fixpoint axioms of § 4.5 and § 4.6 require, so we do not use the function sorts of [8 ] , which relate two sorts. Recall that if T B [ a ] = ⊥ \mathsf{T}_{B[a]} = \bot T B [ a ] = ⊥ (B [ a ] ≅ 0 B[a] \cong0 B [ a ] ≅ 0 ) then there is just one function 0 → X 0 \to X 0 → X specified by ı ˙ ≡ i n i M o r \dot{\imath} \equiv\mathit{iniMor} ˙ ≡ iniMor . The last conjunct of the first case makes the representation strict : f f f is undefined outside B [ a ] B[a] B [ a ] . Without it, if B [ a ] ⊈ B [ a ′ ] B[a] \not\subseteq B[a'] B [ a ] ⊆ B [ a ′ ] in some model, an element representing a function on B [ a ′ ] B[a'] B [ a ′ ] would also represent its restriction to B [ a ] B[a] B [ a ] , and the axiom (EXT) of Section 4.5 would identify elements that represent different functions on B [ a ′ ] B[a'] B [ a ′ ] .
Specifying Initial Algebra
Let X ↦ F X = ∑ a : A X B [ a ] X \mapsto F X = \sum_{a:A} X^{B[a]} X ↦ F X = ∑ a : A X B [ a ] be a container functor. Lemma 4.2 below and the description of μ F \mu_F μ F by approximations assume that F F F is finitary , i.e., every position set B [ a ] B[a] B [ a ] is finite; the adequacy result (Theorem 4.4 ) does not. We write T B [ a ] \mathsf{T}^{B[a]} T B [ a ] for the pattern X B [ a ] [ T / X ] X^{B[a]}[\mathsf{T}/X] X B [ a ] [ T / X ] , which is matched by the elements that behave as functions from B [ a ] B[a] B [ a ] to arbitrary elements. The initial F F F -algebra is specified by using the characterization given by the “no junk and no confusion” properties for the constructors [8 ] :
∀ a : A . ∀ f . f ∈ T B [ a ] → ∃ x . c o n s ⟨ a , f ⟩ = x (FUNCTIONAL) \forall a:A.\ \forall f.\ f \in\mathsf{T}^{B[a]} \to\exists x.\ \mathit{cons}\langle a,f\rangle= x \qquad\text{(FUNCTIONAL)} ∀ a : A . ∀ f . f ∈ T B [ a ] → ∃ x . cons ⟨ a , f ⟩ = x (FUNCTIONAL)
∀ a , a ′ : A . ∀ f , f ′ . f ∈ T B [ a ] ∧ f ′ ∈ T B [ a ′ ] ∧ c o n s ⟨ a , f ⟩ = c o n s ⟨ a ′ , f ′ ⟩ → a = a ′ ∧ f = f ′ (NO CONFUSION) \forall a,a':A.\ \forall f,f'.\ f \in\mathsf{T}^{B[a]} \land f' \in\mathsf{T}^{B[a']} \land\mathit{cons}\langle a,f\rangle= \mathit{cons}\langle a',f'\rangle\to a = a' \land f = f' \qquad\text{(NO CONFUSION)} ∀ a , a ′ : A . ∀ f , f ′ . f ∈ T B [ a ] ∧ f ′ ∈ T B [ a ′ ] ∧ cons ⟨ a , f ⟩ = cons ⟨ a ′ , f ′ ⟩ → a = a ′ ∧ f = f ′ (NO CONFUSION)
μ F : S o r t (MU SORT) \mu F:\mathit{Sort} \qquad\text{(MU SORT)} μ F : Sort (MU SORT)
T μ F = μ X . ∃ a : A . c o n s ⟨ a , X B [ a ] ⟩ (NO JUNK) \mathsf{T}_{\mu F} = \mu X.\ \exists a:A.\ \mathit{cons}\langle a,X^{B[a]}\rangle\qquad\text{(NO JUNK)} T μ F = μ X . ∃ a : A . cons ⟨ a , X B [ a ] ⟩ (NO JUNK)
Notation for models. Fix a model M M M of Γ F μ \Gamma_F^\mu Γ F μ (or of Γ F ν \Gamma_F^\nu Γ F ν in Section 4.6) and a valuation ρ \rho ρ ; we write x ∙ y x \mathbin{\bullet} y x ∙ y for application in M M M . Let A M = ∣ T A ∣ M A_M = \lvert\mathsf{T}_A \rvert_M A M = ∣ T A ∣ M and, for a ∈ A M a \in A_M a ∈ A M , let B M [ a ] B_M[a] B M [ a ] be the interpretation of T B [ a ] \mathsf{T}_{B[a]} T B [ a ] when the variable a a a is valued to a a a . The container extracted from M M M is the set-theoretic container a : A M ⊢ B M [ a ] a:A_M \vdash B_M[a] a : A M ⊢ B M [ a ] , i.e., the container given by the interpretation in M M M of the shapes and positions, and the container functor extracted from M M M is its functor
F M X = ∑ a ∈ A M X B M [ a ] . F_M X = \sum_{a \in A_M} X^{B_M[a]}. F M X = a ∈ A M ∑ X B M [ a ] .
It may differ from the intended functor F F F , since the theories do not fix the interpretation of A A A and B B B (Section 4.7). We say that F F F is finitary in M M M if every B M [ a ] B_M[a] B M [ a ] is finite. For S ⊆ M S \subseteq M S ⊆ M and a ∈ A M a \in A_M a ∈ A M , let F u n a ( S ) \mathit{Fun}_a(S) Fun a ( S ) be the interpretation of X B [ a ] X^{B[a]} X B [ a ] when X X X is valued to S S S and a a a to a a a . If B M [ a ] = ∅ B_M[a] = \varnothing B M [ a ] = ∅ , then F u n a ( S ) = { ı ˙ M } \mathit{Fun}_a(S) = \{\dot{\imath}_M\} Fun a ( S ) = { ˙ M } , where ı ˙ M \dot{\imath}_M ˙ M is the unique element matching ı ˙ \dot{\imath} ˙ . Otherwise, f ∈ F u n a ( S ) f \in\mathit{Fun}_a(S) f ∈ Fun a ( S ) iff for every b ∈ B M [ a ] b \in B_M[a] b ∈ B M [ a ] there is s b ∈ S s_b \in S s b ∈ S with f ∙ b = { s b } f \mathbin{\bullet} b = \{s_b\} f ∙ b = { s b } , and f ∙ b = ∅ f \mathbin{\bullet} b = \varnothing f ∙ b = ∅ for every b ∈ M ∖ B M [ a ] b \in M \setminus B_M[a] b ∈ M ∖ B M [ a ] ; we then write ∣ f ∣ \lvert f\rvert ∣ f ∣ for the function B M [ a ] → S B_M[a] \to S B M [ a ] → S , b ↦ s b b \mapsto s_b b ↦ s b , and call f f f a code of ∣ f ∣ \lvert f\rvert ∣ f ∣ . For B M [ a ] = ∅ B_M[a] = \varnothing B M [ a ] = ∅ , the only element of F u n a ( S ) \mathit{Fun}_a(S) Fun a ( S ) is f = ı ˙ M f = \dot{\imath}_M f = ˙ M , and so ∣ f ∣ \lvert f\rvert ∣ f ∣ is the empty function. Note that f ∈ F u n a ( S ) f \in\mathit{Fun}_a(S) f ∈ Fun a ( S ) iff f ∈ F u n a ( M ) f \in\mathit{Fun}_a(M) f ∈ Fun a ( M ) and all values of ∣ f ∣ \lvert f\rvert ∣ f ∣ are in S S S . By (FUNCTIONAL), for a ∈ A M a \in A_M a ∈ A M and f ∈ F u n a ( M ) f \in\mathit{Fun}_a(M) f ∈ Fun a ( M ) the pattern c o n s ⟨ a , f ⟩ \mathit{cons}\langle a,f\rangle cons ⟨ a , f ⟩ is matched by exactly one element, which we denote c ( a , f ) c(a,f) c ( a , f ) ; by (NO CONFUSION), for f ∈ F u n a ( M ) f \in\mathit{Fun}_a(M) f ∈ Fun a ( M ) and f ′ ∈ F u n a ′ ( M ) f' \in\mathit{Fun}_{a'}(M) f ′ ∈ Fun a ′ ( M ) , c ( a , f ) = c ( a ′ , f ′ ) c(a,f) = c(a',f') c ( a , f ) = c ( a ′ , f ′ ) implies a = a ′ a = a' a = a ′ and f = f ′ f = f' f = f ′ .
Table 1 summarizes this notation. Note the difference between T B [ a ] \mathsf{T}_{B[a]} T B [ a ] (subscript), the positions, and T B [ a ] \mathsf{T}^{B[a]} T B [ a ] (superscript), the elements representing functions on the positions.
Table 1 (PDF p. 12).
Table 1 (PDF p. 13). Notation for positions and for elements representing functions.
Computing the least fixpoint Let φ F ( X ) \varphi_F(X) φ F ( X ) denote the pattern ∃ a : A . c o n s ⟨ a , X B [ a ] ⟩ \exists a:A.\, cons\langle a,X^{B[a]}\rangle ∃ a : A . co n s ⟨ a , X B [ a ] ⟩ , and let Φ F : P ( M ) → P ( M ) \Phi_F:\mathcal{P}(M)\to\mathcal{P}(M) Φ F : P ( M ) → P ( M ) be the function S ↦ ∣ φ F ( X ) ∣ M , ρ [ S / X ] S\mapsto\lvert\varphi_F(X)\rvert_{M,\rho[S/X]} S ↦ ∣ φ F ( X ) ∣ M , ρ [ S / X ] . By the definitions above,
Φ F ( S ) = { c ( a , f ) ∣ a ∈ A M , f ∈ F u n a ( S ) } , \Phi_F(S)=\{c(a,f)\mid a\in A_M,\ f\in Fun_a(S)\}, Φ F ( S ) = { c ( a , f ) ∣ a ∈ A M , f ∈ F u n a ( S )} ,
and, by (NO JUNK), ∣ T μ F ∣ M = lfp ( Φ F ) \lvert T_{\mu F}\rvert_M=\operatorname{lfp}(\Phi_F) ∣ T μ F ∣ M = lfp ( Φ F ) .
Lemma 4.2. If F F F is finitary in M M M , then Φ F \Phi_F Φ F preserves unions of increasing chains. Therefore ∣ T μ F ∣ M = lfp ( Φ F ) = ⋃ n ≥ 0 Φ F n ( ∅ ) \lvert T_{\mu F}\rvert_M=\operatorname{lfp}(\Phi_F)=\bigcup_{n\geq0}\Phi_F^n(\varnothing) ∣ T μ F ∣ M = lfp ( Φ F ) = ⋃ n ≥ 0 Φ F n ( ∅ ) .
Proof. Φ F \Phi_F Φ F is monotone, because φ F \varphi_F φ F is positive in X X X . Let S 0 ⊆ S 1 ⊆ ⋯ S_0\subseteq S_1\subseteq\cdots S 0 ⊆ S 1 ⊆ ⋯ and S = ⋃ n S n S=\bigcup_n S_n S = ⋃ n S n . If f ∈ F u n a ( S ) f\in Fun_a(S) f ∈ F u n a ( S ) , then ∣ f ∣ \lvert f\rvert ∣ f ∣ has the finite domain B M [ a ] B_M[a] B M [ a ] , so all its values lie in some S N S_N S N , and f ∈ F u n a ( S N ) f\in Fun_a(S_N) f ∈ F u n a ( S N ) . Hence Φ F ( S ) = ⋃ n Φ F ( S n ) \Phi_F(S)=\bigcup_n\Phi_F(S_n) Φ F ( S ) = ⋃ n Φ F ( S n ) . The second claim is Kleene’s fixpoint theorem.
Since Φ F ( ∅ ) = ∣ φ F ( ⊥ ) ∣ M , ρ \Phi_F(\varnothing)=\lvert\varphi_F(\text{⊥})\rvert_{M,\rho} Φ F ( ∅ ) = ∣ φ F ( ⊥ ) ∣ M , ρ , and writing φ ( ψ ) \varphi(\psi) φ ( ψ ) for φ [ ψ / X ] \varphi[\psi/X] φ [ ψ / X ] , we (informally) obtain that lfp ( Φ F ) \operatorname{lfp}(\Phi_F) lfp ( Φ F ) is the interpretation of the infinite disjunction
⊥ ∨ φ F ( ⊥ ) ∨ φ F 2 ( ⊥ ) ∨ φ F 3 ( ⊥ ) ∨ ⋯ (3) \text{⊥}\lor\varphi_F(\text{⊥})\lor\varphi_F^2(\text{⊥})\lor\varphi_F^3(\text{⊥})\lor\cdots \tag*{(3)} ⊥ ∨ φ F ( ⊥ ) ∨ φ F 2 ( ⊥ ) ∨ φ F 3 ( ⊥ ) ∨ ⋯ (3)
according to M M M and ρ \rho ρ . We have φ F n ( ⊥ ) → φ F n + 1 ( ⊥ ) \varphi_F^n(\text{⊥})\to\varphi_F^{n+1}(\text{⊥}) φ F n ( ⊥ ) → φ F n + 1 ( ⊥ ) , and each φ F n ( ⊥ ) \varphi_F^n(\text{⊥}) φ F n ( ⊥ ) gives an approximation of T μ F T_{\mu F} T μ F . So, in order to understand how the elements of the initial algebra look like, we have to investigate these ML patterns.
φ F ( ⊥ ) \varphi_F(\text{⊥}) φ F ( ⊥ ) . The pattern ⊥ B [ a ] \text{⊥}^{B[a]} ⊥ B [ a ] (i.e., X B [ a ] [ ⊥ / X ] X^{B[a]}[\text{⊥}/X] X B [ a ] [ ⊥ / X ] ) is ¡ \text{¡} ¡ if T B [ a ] = ⊥ T_{B[a]}=\text{⊥} T B [ a ] = ⊥ , and ⊥ \text{⊥} ⊥ otherwise, because ∀ b : B [ a ] . ∃ y . f b = y ∧ y ∈ ⊥ \forall b:B[a].\,\exists y.\, f\,b=y\land y\in\text{⊥} ∀ b : B [ a ] . ∃ y . f b = y ∧ y ∈ ⊥ is ⊥ \text{⊥} ⊥ when B [ a ] B[a] B [ a ] is non-empty. We obtain
φ F ( ⊥ ) = ∃ a 1 : A . c o n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ ) \varphi_F(\text{⊥})=\exists a_1:A.\, cons\langle a_1,\text{¡}\rangle\land(T_{B[a_1]}=\text{⊥}) φ F ( ⊥ ) = ∃ a 1 : A . co n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ )
i.e., each a 1 : A a_1:A a 1 : A , with its corresponding dependent sort B [ a 1 ] B[a_1] B [ a 1 ] empty, defines a constant constructor. If ∀ a : A . T B [ a ] ≠ ⊥ \forall a:A.\,T_{B[a]}\ne\text{⊥} ∀ a : A . T B [ a ] = ⊥ , then φ F ( ⊥ ) = ⊥ \varphi_F(\text{⊥})=\text{⊥} φ F ( ⊥ ) = ⊥ , hence φ F n ( ⊥ ) = ⊥ \varphi_F^n(\text{⊥})=\text{⊥} φ F n ( ⊥ ) = ⊥ for all n n n , and T μ F = ⊥ T_{\mu F}=\text{⊥} T μ F = ⊥ (see also Remark 4.7).
φ F 2 ( ⊥ ) = ∃ a 2 : A . c o n s ⟨ a 2 , φ F ( ⊥ ) B [ a 2 ] ⟩ \varphi_F^2(\text{⊥})=\exists a_2:A.\, cons\langle a_2,\varphi_F(\text{⊥})^{B[a_2]}\rangle φ F 2 ( ⊥ ) = ∃ a 2 : A . co n s ⟨ a 2 , φ F ( ⊥ ) B [ a 2 ] ⟩ . If T B [ a 2 ] = ⊥ T_{B[a_2]}=\text{⊥} T B [ a 2 ] = ⊥ , then φ F ( ⊥ ) B [ a 2 ] = ⊥ B [ a 2 ] = ¡ \varphi_F(\text{⊥})^{B[a_2]}=\text{⊥}^{B[a_2]}=\text{¡} φ F ( ⊥ ) B [ a 2 ] = ⊥ B [ a 2 ] = ¡ , which gives again the constant constructor c o n s ⟨ a 2 , ¡ ⟩ cons\langle a_2,\text{¡}\rangle co n s ⟨ a 2 , ¡ ⟩ . If T B [ a 2 ] ≠ ⊥ T_{B[a_2]}\ne\text{⊥} T B [ a 2 ] = ⊥ , then we have
φ F ( ⊥ ) B [ a 2 ] = ∃ f . f ∧ ( ∀ b : B [ a 2 ] . ∃ a 1 : A . f b = c o n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ ) ) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ T B [ a 2 ] ) → f b ′ = ⊥ ) \varphi_F(\text{⊥})^{B[a_2]}=\exists f.\, f\land(\forall b:B[a_2].\,\exists a_1:A.\, f\,b=cons\langle a_1,\text{¡}\rangle\land(T_{B[a_1]}=\text{⊥}))
\land(\forall b'.\,\neg(b'\in T_{B[a_2]})\to f\,b'=\text{⊥}) φ F ( ⊥ ) B [ a 2 ] = ∃ f . f ∧ ( ∀ b : B [ a 2 ] . ∃ a 1 : A . f b = co n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ )) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ T B [ a 2 ] ) → f b ′ = ⊥ )
@page 13/44 starts_mid=0 ends_mid=1
Table 1 (PDF p. 13, second). Notation for positions and for elements representing functions.
Computing the least fixpoint Let φ F ( X ) \varphi_F(X) φ F ( X ) denote the pattern ∃ a : A . c o n s ⟨ a , X B [ a ] ⟩ \exists a:A.\,cons\langle a,X^{B[a]}\rangle ∃ a : A . co n s ⟨ a , X B [ a ] ⟩ , and let Φ F : P ( M ) → P ( M ) \Phi_F:\mathcal{P}(M)\to\mathcal{P}(M) Φ F : P ( M ) → P ( M ) be the function S ↦ ∣ φ F ( X ) ∣ M , ρ [ S / X ] S\mapsto\lvert\varphi_F(X)\rvert_{M,\rho[S/X]} S ↦ ∣ φ F ( X ) ∣ M , ρ [ S / X ] . By the definitions above,
Φ F ( S ) = { c ( a , f ) ∣ a ∈ A M , f ∈ F u n a ( S ) } , \Phi_F(S)=\{c(a,f)\mid a\in A_M,\ f\in Fun_a(S)\}, Φ F ( S ) = { c ( a , f ) ∣ a ∈ A M , f ∈ F u n a ( S )} ,
and, by (NO JUNK), ∣ T μ F ∣ M = lfp ( Φ F ) \lvert T_{\mu F}\rvert_M=\operatorname{lfp}(\Phi_F) ∣ T μ F ∣ M = lfp ( Φ F ) .
Lemma 4.2. If F F F is finitary in M M M , then Φ F \Phi_F Φ F preserves unions of increasing chains. Therefore ∣ T μ F ∣ M = lfp ( Φ F ) = ⋃ n ≥ 0 Φ F n ( ∅ ) \lvert T_{\mu F}\rvert_M=\operatorname{lfp}(\Phi_F)=\bigcup_{n\geq0}\Phi_F^n(\varnothing) ∣ T μ F ∣ M = lfp ( Φ F ) = ⋃ n ≥ 0 Φ F n ( ∅ ) .
Proof. Φ F \Phi_F Φ F is monotone, because φ F \varphi_F φ F is positive in X X X . Let S 0 ⊆ S 1 ⊆ ⋯ S_0\subseteq S_1\subseteq\cdots S 0 ⊆ S 1 ⊆ ⋯ and S = ⋃ n S n S=\bigcup_n S_n S = ⋃ n S n . If f ∈ F u n a ( S ) f\in Fun_a(S) f ∈ F u n a ( S ) , then ∣ f ∣ \lvert f\rvert ∣ f ∣ has the finite domain B M [ a ] B_M[a] B M [ a ] , so all its values lie in some S N S_N S N , and f ∈ F u n a ( S N ) f\in Fun_a(S_N) f ∈ F u n a ( S N ) . Hence Φ F ( S ) = ⋃ n Φ F ( S n ) \Phi_F(S)=\bigcup_n\Phi_F(S_n) Φ F ( S ) = ⋃ n Φ F ( S n ) . The second claim is Kleene’s fixpoint theorem.
Since Φ F ( ∅ ) = ∣ φ F ( ⊥ ) ∣ M , ρ \Phi_F(\varnothing)=\lvert\varphi_F(\text{⊥})\rvert_{M,\rho} Φ F ( ∅ ) = ∣ φ F ( ⊥ ) ∣ M , ρ , and writing φ ( ψ ) \varphi(\psi) φ ( ψ ) for φ [ ψ / X ] \varphi[\psi/X] φ [ ψ / X ] , we (informally) obtain that lfp ( Φ F ) \operatorname{lfp}(\Phi_F) lfp ( Φ F ) is the interpretation of the infinite disjunction
⊥ ∨ φ F ( ⊥ ) ∨ φ F 2 ( ⊥ ) ∨ φ F 3 ( ⊥ ) ∨ ⋯ (4) \text{⊥}\lor\varphi_F(\text{⊥})\lor\varphi_F^2(\text{⊥})\lor\varphi_F^3(\text{⊥})\lor\cdots \tag*{(4)} ⊥ ∨ φ F ( ⊥ ) ∨ φ F 2 ( ⊥ ) ∨ φ F 3 ( ⊥ ) ∨ ⋯ (4)
according to M M M and ρ \rho ρ . We have φ F n ( ⊥ ) → φ F n + 1 ( ⊥ ) \varphi_F^n(\text{⊥})\to\varphi_F^{n+1}(\text{⊥}) φ F n ( ⊥ ) → φ F n + 1 ( ⊥ ) , and each φ F n ( ⊥ ) \varphi_F^n(\text{⊥}) φ F n ( ⊥ ) gives an approximation of T μ F T_{\mu F} T μ F . So, in order to understand how the elements of the initial algebra look like, we have to investigate these ML patterns.
φ F ( ⊥ ) \varphi_F(\text{⊥}) φ F ( ⊥ ) . The pattern ⊥ B [ a ] \text{⊥}^{B[a]} ⊥ B [ a ] (i.e., X B [ a ] [ ⊥ / X ] X^{B[a]}[\text{⊥}/X] X B [ a ] [ ⊥ / X ] ) is ¡ \text{¡} ¡ if T B [ a ] = ⊥ T_{B[a]}=\text{⊥} T B [ a ] = ⊥ , and ⊥ \text{⊥} ⊥ otherwise, because ∀ b : B [ a ] . ∃ y . f b = y ∧ y ∈ ⊥ \forall b:B[a].\,\exists y.\,f\,b=y\land y\in\text{⊥} ∀ b : B [ a ] . ∃ y . f b = y ∧ y ∈ ⊥ is ⊥ \text{⊥} ⊥ when B [ a ] B[a] B [ a ] is non-empty. We obtain
φ F ( ⊥ ) = ∃ a 1 : A . c o n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ ) \varphi_F(\text{⊥})=\exists a_1:A.\,cons\langle a_1,\text{¡}\rangle\land(T_{B[a_1]}=\text{⊥}) φ F ( ⊥ ) = ∃ a 1 : A . co n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ )
i.e., each a 1 : A a_1:A a 1 : A , with its corresponding dependent sort B [ a 1 ] B[a_1] B [ a 1 ] empty, defines a constant constructor. If ∀ a : A . T B [ a ] ≠ ⊥ \forall a:A.\,T_{B[a]}\ne\text{⊥} ∀ a : A . T B [ a ] = ⊥ , then φ F ( ⊥ ) = ⊥ \varphi_F(\text{⊥})=\text{⊥} φ F ( ⊥ ) = ⊥ , hence φ F n ( ⊥ ) = ⊥ \varphi_F^n(\text{⊥})=\text{⊥} φ F n ( ⊥ ) = ⊥ for all n n n , and T μ F = ⊥ T_{\mu F}=\text{⊥} T μ F = ⊥ (see also Remark 4.7).
φ F 2 ( ⊥ ) = ∃ a 2 : A . c o n s ⟨ a 2 , φ F ( ⊥ ) B [ a 2 ] ⟩ \varphi_F^2(\text{⊥})=\exists a_2:A.\,cons\langle a_2,\varphi_F(\text{⊥})^{B[a_2]}\rangle φ F 2 ( ⊥ ) = ∃ a 2 : A . co n s ⟨ a 2 , φ F ( ⊥ ) B [ a 2 ] ⟩ . If T B [ a 2 ] = ⊥ T_{B[a_2]}=\text{⊥} T B [ a 2 ] = ⊥ , then φ F ( ⊥ ) B [ a 2 ] = ⊥ B [ a 2 ] = ¡ \varphi_F(\text{⊥})^{B[a_2]}=\text{⊥}^{B[a_2]}=\text{¡} φ F ( ⊥ ) B [ a 2 ] = ⊥ B [ a 2 ] = ¡ , which gives again the constant constructor c o n s ⟨ a 2 , ¡ ⟩ cons\langle a_2,\text{¡}\rangle co n s ⟨ a 2 , ¡ ⟩ . If T B [ a 2 ] ≠ ⊥ T_{B[a_2]}\ne\text{⊥} T B [ a 2 ] = ⊥ , then we have
φ F ( ⊥ ) B [ a 2 ] = ∃ f . f ∧ ( ∀ b : B [ a 2 ] . ∃ a 1 : A . f b = c o n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ ) ) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ T B [ a 2 ] ) → f b ′ = ⊥ ) \varphi_F(\text{⊥})^{B[a_2]}=\exists f.\,f\land\left(\forall b:B[a_2].\,\exists a_1:A.\,f\,b=cons\langle a_1,\text{¡}\rangle\land(T_{B[a_1]}=\text{⊥})\right)
\land\left(\forall b'.\,\neg(b'\in T_{B[a_2]})\to f\,b'=\text{⊥}\right) φ F ( ⊥ ) B [ a 2 ] = ∃ f . f ∧ ( ∀ b : B [ a 2 ] . ∃ a 1 : A . f b = co n s ⟨ a 1 , ¡ ⟩ ∧ ( T B [ a 1 ] = ⊥ ) ) ∧ ( ∀ b ′ . ¬ ( b ′ ∈ T B [ a 2 ] ) → f b ′ = ⊥ )
We obtain
Φ F 2 ( ⊥ ) = Φ F ( ⊥ ) ∨ ∃ a 2 : A . cons ⟨ a 2 , Φ F ( ⊥ ) B [ a 2 ] ⟩ ∧ ( ⊤ B [ a 2 ] ≠ ⊥ ) \Phi_F^2(\bot)=\Phi_F(\bot)\vee\exists a_2\colon A.\ \operatorname{cons}\left\langle a_2,\Phi_F(\bot)^{B[a_2]}\right\rangle\wedge\left(\top_{B[a_2]}\ne\bot\right) Φ F 2 ( ⊥ ) = Φ F ( ⊥ ) ∨ ∃ a 2 : A . cons ⟨ a 2 , Φ F ( ⊥ ) B [ a 2 ] ⟩ ∧ ( ⊤ B [ a 2 ] = ⊥ )
…
Axioms for codes The axioms above do not say which elements of M M M represent functions. The theory of the initial algebra also includes the following two axioms, where ( ⊤ μ F ) B [ a ] (\top_{\mu F})^{B[a]} ( ⊤ μ F ) B [ a ] denotes the pattern X B [ a ] [ ⊤ μ F / X ] X^{B[a]}[\top_{\mu F}/X] X B [ a ] [ ⊤ μ F / X ] :
∀ a : A . ∀ f , f ′ . f ∈ ( ⊤ μ F ) B [ a ] ∧ f ′ ∈ ( ⊤ μ F ) B [ a ] ∧ ( ∀ b : B [ a ] . f b = f ′ b ) → f = f ′ \forall a\colon A.\ \forall f,f'.\ f\in(\top_{\mu F})^{B[a]}\wedge f'\in(\top_{\mu F})^{B[a]}\wedge\left(\forall b\colon B[a].\ f\ b=f'\ b\right)\to f=f' ∀ a : A . ∀ f , f ′ . f ∈ ( ⊤ μ F ) B [ a ] ∧ f ′ ∈ ( ⊤ μ F ) B [ a ] ∧ ( ∀ b : B [ a ] . f b = f ′ b ) → f = f ′
(EXT)
∀ a : A . ( ∀ b : B [ a ] . ∃ x : μ F . ⟨ b , x ⟩ ∈ R ∧ ∀ x ′ . ⟨ b , x ′ ⟩ ∈ R → x ′ = x ) → \forall a\colon A.\ \left(\forall b\colon B[a].\ \exists x\colon\mu F.\ \langle b,x\rangle\in R\wedge\forall x'.\ \langle b,x'\rangle\in R\to x'=x\right)\to ∀ a : A . ( ∀ b : B [ a ] . ∃ x : μ F . ⟨ b , x ⟩ ∈ R ∧ ∀ x ′ . ⟨ b , x ′ ⟩ ∈ R → x ′ = x ) →
∃ f . f ∈ ( ⊤ μ F ) B [ a ] ∧ ∀ b : B [ a ] . ⟨ b , f b ⟩ ∈ R \exists f.\ f\in(\top_{\mu F})^{B[a]}\wedge\forall b\colon B[a].\ \langle b,f\ b\rangle\in R ∃ f . f ∈ ( ⊤ μ F ) B [ a ] ∧ ∀ b : B [ a ] . ⟨ b , f b ⟩ ∈ R
(TAB)
In (TAB), R R R is a free set variable. Since an axiom holds in M M M when it holds for all valuations, (TAB) speaks about every subset R R R of M M M , in particular about the graph of every function from B M [ a ] B_M[a] B M [ a ] to ⊤ μ F \top_{\mu F} ⊤ μ F . Let L = ∣ ⊤ μ F ∣ M L=\lvert\top_{\mu F}\rvert_M L = ∣ ⊤ μ F ∣ M .
Lemma 4.3. Let M M M be a model of Γ F μ \Gamma_F^\mu Γ F μ . Then:
for all a ∈ A M a\in A_M a ∈ A M and f , f ′ ∈ F u n a ( L ) f,f'\in Fun_a(L) f , f ′ ∈ F u n a ( L ) , if ∣ f ∣ = ∣ f ′ ∣ \lvert f\rvert=\lvert f'\rvert ∣ f ∣ = ∣ f ′ ∣ then f = f ′ f=f' f = f ′ ;
for all a ∈ A M a\in A_M a ∈ A M and every function g : B M [ a ] → L g\colon B_M[a]\to L g : B M [ a ] → L , there is f ∈ F u n a ( L ) f\in Fun_a(L) f ∈ F u n a ( L ) with ∣ f ∣ = g \lvert f\rvert=g ∣ f ∣ = g .
Proof. (1) is the semantics of (EXT). For (2), value R R R to { ⟨ b , g ( b ) ⟩ ∣ b ∈ B M [ a ] } \{\langle b,g(b)\rangle\mid b\in B_M[a]\} {⟨ b , g ( b )⟩ ∣ b ∈ B M [ a ]} ; these pairs exist, and are pairwise distinct, by the axioms of PAIR for the sorts B [ a ] B[a] B [ a ] and μ F \mu F μ F . The premise of (TAB) holds, so there is f ∈ F u n a ( L ) f\in Fun_a(L) f ∈ F u n a ( L ) with ⟨ b , f ∙ b ⟩ ∈ R \langle b,f\mathbin{\bullet}b\rangle\in R ⟨ b , f ∙ b ⟩ ∈ R , hence f ∙ b = { g ( b ) } f\mathbin{\bullet}b=\{g(b)\} f ∙ b = { g ( b )} , for all b ∈ B M [ a ] b\in B_M[a] b ∈ B M [ a ] .
So every function g : B M [ a ] → L g\colon B_M[a]\to L g : B M [ a ] → L has exactly one code in F u n a ( L ) Fun_a(L) F u n a ( L ) , which we denote ⌜ g ⌝ a \ulcorner g\urcorner_a ┌ g ┐ a .
Adequacy Let F M F_M F M be the container functor extracted from M M M , and let s u p : F M W M → W M sup\colon F_MW_M\to W_M s u p : F M W M → W M be its initial algebra, i.e., the W-type of a : A M ⊢ B M [ a ] a\colon A_M\vdash B_M[a] a : A M ⊢ B M [ a ] [1 ] , whose elements are the well-founded trees with nodes labelled by shapes a a a and branching B M [ a ] B_M[a] B M [ a ] . The algebra extracted from M M M is
α μ ( M ) = ( L , α ) , α : F M L → L , α ( a , g ) = c ( a , ⌜ g ⌝ a ) . \alpha_\mu(M)=(L,\alpha),\qquad\alpha\colon F_ML\to L,\qquad\alpha(a,g)=c(a,\ulcorner g\urcorner_a). α μ ( M ) = ( L , α ) , α : F M L → L , α ( a , g ) = c ( a , ┌ g ┐ a ) .
If F F F is finitary in M M M , every tree w ∈ W M w\in W_M w ∈ W M has a finite height: h t ( s u p ( a , t ) ) = 1 + max b ∈ B M [ a ] h t ( t b ) ht(sup(a,t))=1+\max_{b\in B_M[a]}ht(t\ b) h t ( s u p ( a , t )) = 1 + max b ∈ B M [ a ] h t ( t b ) , with max ∅ = 0 \max\varnothing=0 max ∅ = 0 . Let W n W_n W n be the set of trees of height at most n n n .
Theorem 4.4. For every model M M M of Γ F μ \Gamma_F^\mu Γ F μ , α μ ( M ) \alpha_\mu(M) α μ ( M ) is an initial F M F_M F M -algebra: the unique algebra morphism h : W M → L h\colon W_M\to L h : W M → L is a bijection. If, moreover, F F F is finitary in M M M , then h ( W n ) = Φ F n ( ∅ ) h(W_n)=\Phi_F^n(\varnothing) h ( W n ) = Φ F n ( ∅ ) for all n n n .
Proof. Since L = lfp ( Φ F ) L=\operatorname{lfp}(\Phi_F) L = lfp ( Φ F ) is a fixpoint of Φ F \Phi_F Φ F , we have α ( a , g ) ∈ Φ F ( L ) = L \alpha(a,g)\in\Phi_F(L)=L α ( a , g ) ∈ Φ F ( L ) = L , so ( L , α ) (L,\alpha) ( L , α ) is an F M F_M F M -algebra. Initiality of W M W_M W M gives a unique h h h with h ( s u p ( a , t ) ) = c ( a , ⌜ h ∘ t ⌝ a ) h(sup(a,t))=c(a,\ulcorner h\circ t\urcorner_a) h ( s u p ( a , t )) = c ( a , ┌ h ∘ t ┐ a ) .
h h h is injective. The subtree relation on W M W_M W M is well-founded. We show by well-founded induction on ( w , w ′ ) (w,w') ( w , w ′ ) that h ( w ) = h ( w ′ ) h(w)=h(w') h ( w ) = h ( w ′ ) implies w = w ′ w=w' w = w ′ . Let w = s u p ( a , t ) w=sup(a,t) w = s u p ( a , t ) and w ′ = s u p ( a ′ , t ′ ) w'=sup(a',t') w ′ = s u p ( a ′ , t ′ ) . From c ( a , ⌜ h ∘ t ⌝ a ) = c ( a ′ , ⌜ h ∘ t ′ ⌝ a ′ ) c(a,\ulcorner h\circ t\urcorner_a)=c(a',\ulcorner h\circ t'\urcorner_{a'}) c ( a , ┌ h ∘ t ┐ a ) = c ( a ′ , ┌ h ∘ t ′ ┐ a ′ ) , (NO CONFUSION) gives a = a ′ a=a' a = a ′ and ⌜ h ∘ t ⌝ a = ⌜ h ∘ t ′ ⌝ a \ulcorner h\circ t\urcorner_a=\ulcorner h\circ t'\urcorner_a ┌ h ∘ t ┐ a = ┌ h ∘ t ′ ┐ a , hence h ∘ t = h ∘ t ′ h\circ t=h\circ t' h ∘ t = h ∘ t ′ . By the induction hypothesis, t b = t ′ b t\ b=t'\ b t b = t ′ b for all b b b , and w = w ′ w=w' w = w ′ .
h h h is surjective. The least fixpoint is the union of the transfinite sequence
Φ F 0 ( ∅ ) = ∅ , \Phi_F^0(\varnothing)=\varnothing, Φ F 0 ( ∅ ) = ∅ ,
Φ F ξ + 1 ( ∅ ) = Φ F ( Φ F ξ ( ∅ ) ) , \Phi_F^{\xi+1}(\varnothing)=\Phi_F\left(\Phi_F^\xi(\varnothing)\right), Φ F ξ + 1 ( ∅ ) = Φ F ( Φ F ξ ( ∅ ) ) ,
Φ F λ ( ∅ ) = ⋃ ξ < λ Φ F ξ ( ∅ ) for a limit ordinal λ . \Phi_F^\lambda(\varnothing)=\bigcup_{\xi<\lambda}\Phi_F^\xi(\varnothing)\qquad\text{for a limit ordinal }\lambda. Φ F λ ( ∅ ) = ξ < λ ⋃ Φ F ξ ( ∅ ) for a limit ordinal λ .
We show Φ F ξ ( ∅ ) ⊆ h ( W M ) \Phi_F^{\xi}(\varnothing) \subseteq h(W_M) Φ F ξ ( ∅ ) ⊆ h ( W M ) by induction on ξ \xi ξ ; the limit case is immediate. Let x ∈ Φ F ξ + 1 ( ∅ ) x \in\Phi_F^{\xi+1}(\varnothing) x ∈ Φ F ξ + 1 ( ∅ ) , i.e., x = c ( a , f ) x = c(a,f) x = c ( a , f ) with f ∈ F u n a ( Φ F ξ ( ∅ ) ) ⊆ F u n a ( L ) f \in Fun_a(\Phi_F^{\xi}(\varnothing)) \subseteq Fun_a(L) f ∈ F u n a ( Φ F ξ ( ∅ )) ⊆ F u n a ( L ) . By the induction hypothesis and injectivity, for each b ∈ B M [ a ] b \in B_M[a] b ∈ B M [ a ] there is a unique t b ∈ W M t_b \in W_M t b ∈ W M with h ( t b ) = ∣ f ∣ ( b ) h(t_b) = \lvert f \rvert(b) h ( t b ) = ∣ f ∣ ( b ) . Then ∣ f ∣ = h ∘ t \lvert f \rvert= h \circ t ∣ f ∣ = h ∘ t , so f = ⌜ h ∘ t ⌝ a f = \ulcorner h \circ t \urcorner_a f = ┌ h ∘ t ┐ a by Lemma 4.3, and x = h ( sup ( a , t ) ) x = h(\operatorname{sup}(a,t)) x = h ( sup ( a , t )) . A bijective algebra morphism is an isomorphism of algebras, so ( L , α ) (L,\alpha) ( L , α ) is initial. If F F F is finitary in M M M , then h ( W n ) = Φ F n ( ∅ ) h(W_n) = \Phi_F^n(\varnothing) h ( W n ) = Φ F n ( ∅ ) by induction on n n n : for w = sup ( a , t ) ∈ W n + 1 w = \operatorname{sup}(a,t) \in W_{n+1} w = sup ( a , t ) ∈ W n + 1 , every t b t_b t b is in W n W_n W n , so ⌜ h ∘ t ⌝ a ∈ F u n a ( Φ F n ( ∅ ) ) \ulcorner h \circ t \urcorner_a \in Fun_a(\Phi_F^n(\varnothing)) ┌ h ∘ t ┐ a ∈ F u n a ( Φ F n ( ∅ )) and h ( w ) ∈ Φ F n + 1 ( ∅ ) h(w) \in\Phi_F^{n+1}(\varnothing) h ( w ) ∈ Φ F n + 1 ( ∅ ) ; the converse inclusion is the successor step above, where the trees t b t_b t b are in W n W_n W n .
Corollary 4.5. If, moreover, M M M interprets shapes and positions standardly, i.e., there are a bijection ι : A → A M \iota: A \to A_M ι : A → A M and bijections B [ a ] ≅ B M [ ι ( a ) ] B[a] \cong B_M[\iota(a)] B [ a ] ≅ B M [ ι ( a )] for all a ∈ A a \in A a ∈ A , then α μ ( M ) \alpha_{\mu}(M) α μ ( M ) is isomorphic to the initial F F F -algebra μ F \mu F μ F , the W W W -type of a : A ⊢ B [ a ] a \!:\! A \vdash B[a] a : A ⊢ B [ a ] .
Proposition 4.6. Let X ↦ F X = ∑ a : A X B [ a ] X \mapsto F X = \sum_{a:A} X^{B[a]} X ↦ F X = ∑ a : A X B [ a ] be a container functor, specified as above. There is a model M M M of Γ F \Gamma_F Γ F (hence of Γ F μ \Gamma_F^{\mu} Γ F μ ) with a bijection ι : A → A M \iota: A \to A_M ι : A → A M and bijections B [ a ] ≅ B M [ ι ( a ) ] B[a] \cong B_M[\iota(a)] B [ a ] ≅ B M [ ι ( a )] for all a ∈ A a \in A a ∈ A , in which ⊤ μ F \top_{\mu F} ⊤ μ F with c o n s cons co n s is isomorphic to the W W W -type of a : A ⊢ B [ a ] a \!:\! A \vdash B[a] a : A ⊢ B [ a ] .
Proof. The model is constructed in Appendix B (Theorem B.2). Its carrier is built in transfinite stages, up to a regular cardinal larger than every ∣ B [ a ] ∣ \lvert B[a]\rvert ∣ B [ a ]∣ , by closing under pairs, finite sequences, partial applications, codes of functions on position sets, and fresh terms; there, ⊤ μ F \top_{\mu F} ⊤ μ F is the set of well-founded trees of the M-type, and the only elements that represent functions into it are the codes.
Remark 4.7. The axioms (EXT) and (TAB) are needed for Theorem 4.4; Proposition B.4(1) and (2) gives, for each of them, a structure that satisfies all the other axioms of Γ F μ \Gamma_F^{\mu} Γ F μ and whose extracted algebra is not initial. Without (TAB), ⊤ μ F \top_{\mu F} ⊤ μ F may miss trees: it contains only the trees whose families of subtrees have codes in M M M . Without (EXT), two codes f ≠ f ′ f \ne f' f = f ′ with ∣ f ∣ = ∣ f ′ ∣ \lvert f\rvert= \lvert f'\rvert ∣ f ∣ = ∣ f ′ ∣ give, by (NO CONFUSION), two different elements c ( a , f ) ≠ c ( a , f ′ ) c(a,f) \ne c(a,f') c ( a , f ) = c ( a , f ′ ) for the same tree. Finitarity is needed only for Lemma 4.2 and for the description of ⊤ μ F \top_{\mu F} ⊤ μ F by the approximations φ F n ( ⊥ ) \varphi_F^n(\bot) φ F n ( ⊥ ) . For F X = 1 + X N F X = 1 + X^{\mathbb{N}} F X = 1 + X N , the sets Φ F n ( ∅ ) \Phi_F^n(\varnothing) Φ F n ( ∅ ) contain only trees of finite height, while μ F \mu F μ F also contains, e.g., the tree whose k k k -th subtree has height k k k , which is reached only after ω + 1 \omega+ 1 ω + 1 iterations. If every B [ a ] B[a] B [ a ] is non-empty, then Φ F ( ∅ ) = ∅ \Phi_F(\varnothing) = \varnothing Φ F ( ∅ ) = ∅ , so ∅ \varnothing ∅ is the least fixpoint and ⊤ μ F = ⊥ \top_{\mu F} = \bot ⊤ μ F = ⊥ . This covers the Moore machines of Section 6, for any non-empty set of inputs I I I .
Remark 4.8 (Codes and graphs). By Lemma 4.3, codes and functions are in bijection in every model: (EXT) gives injectivity and (TAB) surjectivity. An alternative representation, used for the function sorts of [6 ] , represents a function by its graph: an element α \alpha α of a power sort P S 1 ⊗ S 2 \mathcal{P}_{S_1 \otimes S_2} P S 1 ⊗ S 2 , whose extension is a subset of ⊤ S 1 ⊗ S 2 \top_{S_1 \otimes S_2} ⊤ S 1 ⊗ S 2 , with application given by f x = ∃ y . y ∧ ⟨ x , y ⟩ ∈ extension f f \, x = \exists y.\, y \land\langle x,y\rangle\in\operatorname{extension} f f x = ∃ y . y ∧ ⟨ x , y ⟩ ∈ extension f . The axioms of power sorts make extension \operatorname{extension} extension injective, and surjective onto the subsets of ⊤ S 1 ⊗ S 2 \top_{S_1 \otimes S_2} ⊤ S 1 ⊗ S 2 . So, if the function sort is defined as the set of all total and single-valued relations (and not only included in it), (EXT) and (TAB) become consequences of the axioms of power sorts, and neither strictness nor the case of ι \iota ι is needed: a graph determines its domain, and the function on an empty domain is the empty relation.
We do not follow this approach here, for two reasons. First, a graph takes its values in a sort, while X B [ a ] X^{B[a]} X B [ a ] in (NO JUNK) and (NO COJUNK) maps positions into a set variable X X X . A graph-based version must use a codomain sort, such as μ F \mu F μ F itself, so that the axiom defining ⊤ μ F \top_{\mu F} ⊤ μ F refers to ⊤ μ F \top_{\mu F} ⊤ μ F on both sides, which complicates the adequacy proofs; a universal codomain sort is excluded by Cantor’s theorem, since it would contain its own power sort. Second, the theory of sorts of [6 ] requires every sort to be non-empty, while containers need empty sorts of positions, e.g., for the leaves of lists, and may have an empty initial algebra, e.g., for streams. The two representations nevertheless carry the same information: in every model of Γ F μ \Gamma_F^{\mu} Γ F μ , the map f ↦ { ( b , ∣ f ∣ ( b ) ) ∣ b ∈ B M [ a ] } f \mapsto\{(b,\lvert f\rvert(b)) \mid b \in B_M[a]\} f ↦ {( b , ∣ f ∣ ( b )) ∣ b ∈ B M [ a ]} is a bijection from F u n a ( L ) Fun_a(L) F u n a ( L ) onto the total single-valued relations from B M [ a ] B_M[a] B M [ a ] to L L L , by Lemma 4.3, and the same holds for ν F \nu F ν F by Proposition 4.24.
Remark 4.9. If F F F is finitary in M M M , then h h h maps W n W_n W n , i.e., the image of F n 0 F^n0 F n 0 in the colimit (INI), onto Φ F n ( ∅ ) \Phi_F^n(\varnothing) Φ F n ( ∅ ) , the interpretation of φ F n ( ⊥ ) \varphi_F^n(\bot) φ F n ( ⊥ ) . In this sense, the ML pattern (LFP) is the counterpart of the colimit (INI).
Deriving Induction Principle The following Induction Principle is derivable:
∀ a : A . c o n s ⟨ a , ψ B [ a ] ⟩ → ψ ⊤ μ F → ψ \frac{\forall a\colon A.\ \mathop{\mathrm{cons}}\langle a,\psi^{B[a]}\rangle\to\psi}{\top_{\mu F}\to\psi} ⊤ μ F → ψ ∀ a : A . cons ⟨ a , ψ B [ a ] ⟩ → ψ
where a a a does not occur free in ψ \psi ψ , and ψ B [ a ] \psi^{B[a]} ψ B [ a ] is the pattern X B [ a ] [ ψ / X ] X^{B[a]}[\psi/X] X B [ a ] [ ψ / X ] , i.e., the notation X B [ a ] X^{B[a]} X B [ a ] from § 4.4 with ψ \psi ψ in place of X X X . Indeed, since a a a is not free in ψ \psi ψ , the premise is equivalent to φ F ( ψ ) → ψ \varphi_F(\psi)\to\psi φ F ( ψ ) → ψ . The Knaster–Tarski rule of matching logic [10 ] , which derives μ X . φ → ψ \mu X.\ \varphi\to\psi μ X . φ → ψ from φ [ ψ / X ] → ψ \varphi[\psi/X]\to\psi φ [ ψ / X ] → ψ , then gives μ X . φ F ( X ) → ψ \mu X.\ \varphi_F(X)\to\psi μ X . φ F ( X ) → ψ , and (NO JUNK) rewrites μ X . φ F ( X ) \mu X.\ \varphi_F(X) μ X . φ F ( X ) as ⊤ μ F \top_{\mu F} ⊤ μ F .
Specifying Final Coalgebra
Let X ↦ F X = ∑ a : A X B [ a ] X\mapsto F X=\sum_{a:A}X^{B[a]} X ↦ F X = ∑ a : A X B [ a ] be a container functor. The final F F F -coalgebra is specified by:
ν F : S o r t \nu F\colon\mathop{\mathrm{Sort}} ν F : Sort
⊤ ν F = ν X . ∃ a : A . c o n s ⟨ a , X B [ a ] ⟩ \top_{\nu F}=\nu X.\ \exists a\colon A.\ \mathop{\mathrm{cons}}\langle a,X^{B[a]}\rangle ⊤ ν F = ν X . ∃ a : A . cons ⟨ a , X B [ a ] ⟩
(NO COJUNK)
two destructors o u t , n x t ∈ Σ \mathop{\mathrm{out}},\mathop{\mathrm{nxt}}\in\Sigma out , nxt ∈ Σ together with the notations:
x . o u t ≡ o u t x x.\mathop{\mathrm{out}}\equiv\mathop{\mathrm{out}}x x . out ≡ out x
x . n x t ≡ n x t x x.\mathop{\mathrm{nxt}}\equiv\mathop{\mathrm{nxt}}x x . nxt ≡ nxt x
and the axioms:
∀ a : A . ∀ f . f ∈ ⊤ B [ a ] → ( c o n s ⟨ a , f ⟩ ) . o u t = a \forall a\colon A.\ \forall f.\ f\in\top^{B[a]}\to(\mathop{\mathrm{cons}}\langle a,f\rangle).\mathop{\mathrm{out}}=a ∀ a : A . ∀ f . f ∈ ⊤ B [ a ] → ( cons ⟨ a , f ⟩) . out = a
(NO COCONFUSION.1)
∀ a : A . ∀ f . f ∈ ⊤ B [ a ] → ( c o n s ⟨ a , f ⟩ ) . n x t = f \forall a\colon A.\ \forall f.\ f\in\top^{B[a]}\to(\mathop{\mathrm{cons}}\langle a,f\rangle).\mathop{\mathrm{nxt}}=f ∀ a : A . ∀ f . f ∈ ⊤ B [ a ] → ( cons ⟨ a , f ⟩) . nxt = f
(NO COCONFUSION.2)
b i s ( R ) ≡ ∃ x , y : ν F . ⟨ x , y ⟩ ∧ x . o u t = y . o u t ∧ \mathop{\mathrm{bis}}(R)\equiv\exists x,y\colon\nu F.\ \langle x,y\rangle\land x.\mathop{\mathrm{out}}=y.\mathop{\mathrm{out}}\land bis ( R ) ≡ ∃ x , y : ν F . ⟨ x , y ⟩ ∧ x . out = y . out ∧
∀ b : B [ x . o u t ] . ∃ u , v . ( x . n x t ) b = u ∧ ( y . n x t ) b = v ∧ ⟨ u , v ⟩ ∈ R \forall b\colon B[x.\mathop{\mathrm{out}}].\ \exists u,v.\ (x.\mathop{\mathrm{nxt}})b=u\land(y.\mathop{\mathrm{nxt}})b=v\land\langle u,v\rangle\in R ∀ b : B [ x . out ] . ∃ u , v . ( x . nxt ) b = u ∧ ( y . nxt ) b = v ∧ ⟨ u , v ⟩ ∈ R
B i s i m = ν R . b i s ( R ) \mathop{\mathrm{Bisim}}=\nu R.\ \mathop{\mathrm{bis}}(R) Bisim = ν R . bis ( R )
(the set variable R R R occurs positively in b i s ( R ) \mathop{\mathrm{bis}}(R) bis ( R ) ), and the axiom
∀ x , y : ν F . ⟨ x , y ⟩ ∈ B i s i m → x = y \forall x,y\colon\nu F.\ \langle x,y\rangle\in\mathop{\mathrm{Bisim}}\to x=y ∀ x , y : ν F . ⟨ x , y ⟩ ∈ Bisim → x = y
(BISIMILARITY)
The axiom (NO CONFUSION) of § 4.5 and the expected inverse property of the destructors are consequences of these axioms.
Lemma 4.10. The following patterns are derivable from (FUNCTIONAL), (NO COJUNK), (NO COCONFUSION.1), and (NO COCONFUSION.2), and hold in every model of these axioms:
(NO CONFUSION);
∀ x : ν F . c o n s ⟨ x . o u t , x . n x t ⟩ = x \forall x\colon\nu F.\ \mathop{\mathrm{cons}}\langle x.\mathop{\mathrm{out}},x.\mathop{\mathrm{nxt}}\rangle=x ∀ x : ν F . cons ⟨ x . out , x . nxt ⟩ = x , which we call (NO COCONFUSION.3).
Proof. (1) Let a , a ′ : A a,a'\colon A a , a ′ : A , f ∈ ⊤ B [ a ] f\in\top^{B[a]} f ∈ ⊤ B [ a ] , and f ′ ∈ ⊤ B [ a ′ ] f'\in\top^{B[a']} f ′ ∈ ⊤ B [ a ′ ] with c o n s ⟨ a , f ⟩ = c o n s ⟨ a ′ , f ′ ⟩ \mathop{\mathrm{cons}}\langle a,f\rangle=\mathop{\mathrm{cons}}\langle a',f'\rangle cons ⟨ a , f ⟩ = cons ⟨ a ′ , f ′ ⟩ . By (FUNCTIONAL), both sides are matched by one element x x x . By (NO COCONFUSION.1), a = x . o u t = a ′ a=x.\mathop{\mathrm{out}}=a' a = x . out = a ′ , and by (NO COCONFUSION.2), f = x . n x t = f ′ f=x.\mathop{\mathrm{nxt}}=f' f = x . nxt = f ′ . (2) Let x : ν F x\colon\nu F x : ν F . By (NO COJUNK), x ∈ ∃ a : A . c o n s ⟨ a , ( ⊤ ν F ) B [ a ] ⟩ x\in\exists a\colon A.\ \mathop{\mathrm{cons}}\langle a,(\top_{\nu F})^{B[a]}\rangle x ∈ ∃ a : A . cons ⟨ a , ( ⊤ ν F ) B [ a ] ⟩ , so x = c o n s ⟨ a , f ⟩ x=\mathop{\mathrm{cons}}\langle a,f\rangle x = cons ⟨ a , f ⟩ for some a : A a\colon A a : A and f ∈ ( ⊤ ν F ) B [ a ] f\in(\top_{\nu F})^{B[a]} f ∈ ( ⊤ ν F ) B [ a ] , hence f ∈ ⊤ B [ a ] f\in\top^{B[a]} f ∈ ⊤ B [ a ] . By (NO COCONFUSION.1–2), x . o u t = a x.\mathop{\mathrm{out}}=a x . out = a and x . n x t = f x.\mathop{\mathrm{nxt}}=f x . nxt = f , so cons ⟨ x . out , x . nxt ⟩ = cons ⟨ a , f ⟩ = x \operatorname{cons}\langle x.\operatorname{out},x.\operatorname{nxt}\rangle=\operatorname{cons}\langle a,f\rangle=x cons ⟨ x . out , x . nxt ⟩ = cons ⟨ a , f ⟩ = x . Both arguments use only the elimination of existential quantifiers and the substitution of equals in application contexts, which are available in the ML proof system [10 , 8 ] ; by soundness, the patterns hold in every model.
Computing the greatest fixpoint
We use the notation of Section 4.5, which does not depend on finitarity, and let U = ∣ ⊤ ν F ∣ M U=\lvert\top_{\nu F}\rvert_M U = ∣ ⊤ ν F ∣ M . By (NO COJUNK), U = gfp ( Φ F ) U=\operatorname{gfp}(\Phi_F) U = gfp ( Φ F ) .
Lemma 4.11. Φ F \Phi_F Φ F preserves intersections of decreasing chains. Therefore U = gfp ( Φ F ) = ⋂ n ≥ 0 Φ F n ( M ) U=\operatorname{gfp}(\Phi_F)=\bigcap_{n\ge0}\Phi_F^n(M) U = gfp ( Φ F ) = ⋂ n ≥ 0 Φ F n ( M ) .
Proof. Let S 0 ⊇ S 1 ⊇ ⋯ S_0\supseteq S_1\supseteq\cdots S 0 ⊇ S 1 ⊇ ⋯ and S = ⋂ n S n S=\bigcap_n S_n S = ⋂ n S n . By monotonicity, Φ F ( S ) ⊆ ⋂ n Φ F ( S n ) \Phi_F(S)\subseteq\bigcap_n\Phi_F(S_n) Φ F ( S ) ⊆ ⋂ n Φ F ( S n ) . Conversely, let x ∈ ⋂ n Φ F ( S n ) x\in\bigcap_n\Phi_F(S_n) x ∈ ⋂ n Φ F ( S n ) . For each n n n , x = c ( a n , f n ) x=c(a_n,f_n) x = c ( a n , f n ) with f n ∈ Fun a n ( S n ) f_n\in\operatorname{Fun}_{a_n}(S_n) f n ∈ Fun a n ( S n ) . By (NO CON FUSION), all pairs ( a n , f n ) (a_n,f_n) ( a n , f n ) are equal to one pair ( a , f ) (a,f) ( a , f ) . Then all values of ∣ f ∣ \lvert f\rvert ∣ f ∣ are in every S n S_n S n , hence in S S S , so f ∈ Fun a ( S ) f\in\operatorname{Fun}_a(S) f ∈ Fun a ( S ) and x ∈ Φ F ( S ) x\in\Phi_F(S) x ∈ Φ F ( S ) . The second claim is the dual of Kleene’s fixpoint theorem.
Hence, informally, ⊤ ν F \top_{\nu F} ⊤ ν F is the interpretation of the infinite conjunction
⊤ ∧ φ F ( ⊤ ) ∧ φ F 2 ( ⊤ ) ∧ φ F 3 ( ⊤ ) ∧ ⋯ \top\wedge\varphi_F(\top)\wedge\varphi_F^2(\top)\wedge\varphi_F^3(\top)\wedge\cdots ⊤ ∧ φ F ( ⊤ ) ∧ φ F 2 ( ⊤ ) ∧ φ F 3 ( ⊤ ) ∧ ⋯
The elements that match φ F ( ⊤ ) \varphi_F(\top) φ F ( ⊤ ) are those of the form x = cons ⟨ a , f ⟩ x=\operatorname{cons}\langle a,f\rangle x = cons ⟨ a , f ⟩ , where a : A a:A a : A and f ∈ ⊤ B [ a ] f\in\top^{B[a]} f ∈ ⊤ B [ a ] . By (NO COCONFUSION.1–2), these elements satisfy x . out ∈ ⊤ A x.\operatorname{out}\in\top_A x . out ∈ ⊤ A and x . nxt ∈ ⊤ B [ x . out ] x.\operatorname{nxt}\in\top_{B[x.\operatorname{out}]} x . nxt ∈ ⊤ B [ x . out ] . The converse does not hold in general, since the destructors are not constrained outside the image of cons \operatorname{cons} cons . Further, φ F n + 1 ( ⊤ ) \varphi_F^{n+1}(\top) φ F n + 1 ( ⊤ ) is matched by those elements of φ F ( ⊤ ) \varphi_F(\top) φ F ( ⊤ ) whose children ( x . nxt ) b (x.\operatorname{nxt})\,b ( x . nxt ) b , for b : B [ x . out ] b:B[x.\operatorname{out}] b : B [ x . out ] , all match φ F n ( ⊤ ) \varphi_F^n(\top) φ F n ( ⊤ ) . So φ F n ( ⊤ ) \varphi_F^n(\top) φ F n ( ⊤ ) is matched by the elements that can be unfolded n n n times by the destructors, and ⊤ ν F \top_{\nu F} ⊤ ν F by those that can be unfolded indefinitely.
Remark 4.12. The ML pattern (GFP) can be seen as an informal ML counterpart of the limit (FIN): Φ F n ( M ) \Phi_F^n(M) Φ F n ( M ) contains the elements that can be unfolded n n n times, and F n 1 F^n1 F n 1 contains the behaviours truncated at depth n n n .
Paths and realisation
(BISIMILARITY) ensures that two elements of ⊤ ν F \top_{\nu F} ⊤ ν F with the same behaviour are equal. The converse requirement, that every behaviour is the behaviour of some element, needs an axiom about the existence of elements. To state it, we describe a behaviour by the shapes found along the finite paths of a tree. Let P ≡ ∑ a : A B [ a ] P\equiv\sum_{a:A}B[a] P ≡ ∑ a : A B [ a ] be the sort of positions tagged with their shapes (a dependent sum, Section 4), and let List ( P ) \operatorname{List}(P) List ( P ) be the sort of finite lists over P P P , specified as a term algebra [9 ] by symbols List , pnil , pcons ∈ Σ \operatorname{List},\operatorname{pnil},\operatorname{pcons}\in\Sigma List , pnil , pcons ∈ Σ , the notation List ( P ) ≡ List P \operatorname{List}(P)\equiv\operatorname{List}\ P List ( P ) ≡ List P , and the axioms
List ( P ) : Sort \operatorname{List}(P):\operatorname{Sort} List ( P ) : Sort
∃ y : List ( P ) . pnil = y ∀ q : P . ∀ p : List ( P ) . ∃ y : List ( P ) . pcons q p = y \exists y:\operatorname{List}(P).\ \operatorname{pnil}=y
\qquad
\forall q:P.\ \forall p:\operatorname{List}(P).\ \exists y:\operatorname{List}(P).\ \operatorname{pcons}\ q\ p=y ∃ y : List ( P ) . pnil = y ∀ q : P . ∀ p : List ( P ) . ∃ y : List ( P ) . pcons q p = y
∀ q : P . ∀ p : List ( P ) . pcons q p ≠ pnil \forall q:P.\ \forall p:\operatorname{List}(P).\ \operatorname{pcons}\ q\ p\ne\operatorname{pnil} ∀ q : P . ∀ p : List ( P ) . pcons q p = pnil
∀ q , q ′ : P . ∀ p , p ′ : List ( P ) . pcons q p = pcons q ′ p ′ ⇒ q = q ′ ∧ p = p ′ \forall q,q':P.\ \forall p,p':\operatorname{List}(P).\ \operatorname{pcons}\ q\ p=\operatorname{pcons}\ q'\ p'\Rightarrow q=q'\land p=p' ∀ q , q ′ : P . ∀ p , p ′ : List ( P ) . pcons q p = pcons q ′ p ′ ⇒ q = q ′ ∧ p = p ′
⊤ List ( P ) = μ Y . pnil ∨ pcons ⊤ P Y \top_{\operatorname{List}(P)}=\mu Y.\ \operatorname{pnil}\vee\operatorname{pcons}\ \top_P\ Y ⊤ List ( P ) = μ Y . pnil ∨ pcons ⊤ P Y
A list pcons ⟨ a n , b n ⟩ ( ⋯ ( pcons ⟨ a 1 , b 1 ⟩ pnil ) ⋯ ) \operatorname{pcons}\ \langle a_n,b_n\rangle\ (\cdots(\operatorname{pcons}\ \langle a_1,b_1\rangle\ \operatorname{pnil})\cdots) pcons ⟨ a n , b n ⟩ ( ⋯ ( pcons ⟨ a 1 , b 1 ⟩ pnil ) ⋯ ) represents the path that starts at the root, whose shape is a 1 a_1 a 1 , goes to its child at position b 1 b_1 b 1 , whose shape is a 2 a_2 a 2 , and so on (the most recent step comes first). A set T T T of pairs ⟨ p , a ⟩ \langle p,a\rangle ⟨ p , a ⟩ , with p : List ( P ) p:\operatorname{List}(P) p : List ( P ) and a : A a:A a : A , describes a tree when it satisfies Tree ( T ) \operatorname{Tree}(T) Tree ( T ) , the conjunction of
∀ p : List ( P ) . ∀ a , a ′ : A . ⟨ p , a ⟩ ∈ T ∧ ⟨ p , a ′ ⟩ ∈ T ⇒ a = a ′ (one shape per path) \forall p:\operatorname{List}(P).\ \forall a,a':A.\ \langle p,a\rangle\in T\land\langle p,a'\rangle\in T\Rightarrow a=a'
\qquad\text{(one shape per path)} ∀ p : List ( P ) . ∀ a , a ′ : A . ⟨ p , a ⟩ ∈ T ∧ ⟨ p , a ′ ⟩ ∈ T ⇒ a = a ′ (one shape per path)
∃ a : A . ⟨ pnil , a ⟩ ∈ T (a root) \exists a:A.\ \langle\operatorname{pnil},a\rangle\in T
\qquad\text{(a root)} ∃ a : A . ⟨ pnil , a ⟩ ∈ T (a root)
∀ p : List ( P ) . ∀ a : A . ⟨ p , a ⟩ ∈ T ⇒ ∀ b : B [ a ] . ∃ a ′ : A . ⟨ pcons ⟨ a , b ⟩ p , a ′ ⟩ ∈ T (all children) \forall p:\operatorname{List}(P).\ \forall a:A.\ \langle p,a\rangle\in T\Rightarrow\forall b:B[a].\ \exists a':A.\ \langle\operatorname{pcons}\langle a,b\rangle\ p,a'\rangle\in T
\qquad\text{(all children)} ∀ p : List ( P ) . ∀ a : A . ⟨ p , a ⟩ ∈ T ⇒ ∀ b : B [ a ] . ∃ a ′ : A . ⟨ pcons ⟨ a , b ⟩ p , a ′ ⟩ ∈ T (all children)
The pairs ⟨ p , y ⟩ \langle p,y\rangle ⟨ p , y ⟩ such that y : ν F y\mathrel{:}\nu F y : ν F is reached from x x x along the path p p p are given by
Sub ( x ) ≡ μ S . ⟨ p n i l , x ⟩ ∨ ∃ p : List ( P ) . ∃ y : ν F . ∃ b : B [ y . o u t ] . ⟨ p , y ⟩ ∈ S ∧ ⟨ p c o n s ⟨ y . o u t , b ⟩ p , ( y . n x t ) b ⟩ \operatorname{Sub}(x) \equiv\mu S.\ \langle pnil,x\rangle\lor
\exists p\mathrel{:}\operatorname{List}(P).\ \exists y\mathrel{:}\nu F.\ \exists b\mathrel{:}B[y.out].\ \langle p,y\rangle\in S \land\langle pcons\ \langle y.out,b\rangle\ p,(y.nxt)\ b\rangle Sub ( x ) ≡ μ S . ⟨ p ni l , x ⟩ ∨ ∃ p : List ( P ) . ∃ y : ν F . ∃ b : B [ y . o u t ] . ⟨ p , y ⟩ ∈ S ∧ ⟨ p co n s ⟨ y . o u t , b ⟩ p , ( y . n x t ) b ⟩
and x x x has the behaviour described by T T T when
Beh ( x , T ) ≡ ∀ p : List ( P ) . ∀ y : ν F . ⟨ p , y ⟩ ∈ Sub ( x ) → ⟨ p , y . o u t ⟩ ∈ T . \operatorname{Beh}(x,T) \equiv\forall p\mathrel{:}\operatorname{List}(P).\ \forall y\mathrel{:}\nu F.\ \langle p,y\rangle\in\operatorname{Sub}(x) \to\langle p,y.out\rangle\in T. Beh ( x , T ) ≡ ∀ p : List ( P ) . ∀ y : ν F . ⟨ p , y ⟩ ∈ Sub ( x ) → ⟨ p , y . o u t ⟩ ∈ T .
The theory of the final coalgebra also includes the axiom
Tree ( T ) → ∃ x : ν F . Beh ( x , T ) \operatorname{Tree}(T) \to\exists x\mathrel{:}\nu F.\ \operatorname{Beh}(x,T) Tree ( T ) → ∃ x : ν F . Beh ( x , T )
(REALISATION)
where T T T is a free set variable; as for (TAB), the axiom speaks about every subset T T T of M M M .
Remark 4.13. A set T T T with Tree ( T ) \operatorname{Tree}(T) Tree ( T ) may contain pairs ⟨ p , a ⟩ \langle p,a\rangle ⟨ p , a ⟩ whose path p p p is not reachable from the root; such pairs are ignored by Beh \operatorname{Beh} Beh and play no role. Although Beh ( x , T ) \operatorname{Beh}(x,T) Beh ( x , T ) is stated as an implication, it means that the behaviour of x x x is exactly the reachable part of T T T (Lemma 4.14 ). The reachable part is itself definable, by a least fixpoint pattern in the style of Sub ( x ) \operatorname{Sub}(x) Sub ( x ) :
Reach ( T ) ≡ μ S . ( ∃ a : A . ⟨ p n i l , a ⟩ ∧ ⟨ p n i l , a ⟩ ∈ T ) ∨ \operatorname{Reach}(T) \equiv\mu S.\ (\exists a\mathrel{:}A.\ \langle pnil,a\rangle\land\langle pnil,a\rangle\in T) \lor Reach ( T ) ≡ μ S . ( ∃ a : A . ⟨ p ni l , a ⟩ ∧ ⟨ p ni l , a ⟩ ∈ T ) ∨
( ∃ p : List ( P ) . ∃ a : A . ∃ b : B [ a ] . ∃ a ′ : A . ⟨ p , a ⟩ ∈ S ∧ ⟨ p c o n s ⟨ a , b ⟩ p , a ′ ⟩ ∧ ⟨ p c o n s ⟨ a , b ⟩ p , a ′ ⟩ ∈ T ) . (\exists p\mathrel{:}\operatorname{List}(P).\ \exists a\mathrel{:}A.\ \exists b\mathrel{:}B[a].\ \exists a'\mathrel{:}A.\ \langle p,a\rangle\in S \land\langle pcons\ \langle a,b\rangle\ p,a'\rangle\land\langle pcons\ \langle a,b\rangle\ p,a'\rangle\in T). ( ∃ p : List ( P ) . ∃ a : A . ∃ b : B [ a ] . ∃ a ′ : A . ⟨ p , a ⟩ ∈ S ∧ ⟨ p co n s ⟨ a , b ⟩ p , a ′ ⟩ ∧ ⟨ p co n s ⟨ a , b ⟩ p , a ′ ⟩ ∈ T ) .
Restricting (REALISATION) to the sets with T ⊆ Reach ( T ) T \subseteq\operatorname{Reach}(T) T ⊆ Reach ( T ) , all of whose paths are reachable from the root, gives an equivalent axiom: if Tree ( T ) \operatorname{Tree}(T) Tree ( T ) holds, then Reach ( T ) \operatorname{Reach}(T) Reach ( T ) satisfies Tree \operatorname{Tree} Tree and all its paths are reachable, and an element with the behaviour described by Reach ( T ) \operatorname{Reach}(T) Reach ( T ) has the behaviour described by T T T , since Reach ( T ) ⊆ T \operatorname{Reach}(T) \subseteq T Reach ( T ) ⊆ T . We keep the unrestricted form, which needs no additional fixpoint pattern. The axiom (REALISATION) is strong: through the free set variable T T T , it requires an element for every subset of the model that describes a tree. It is the ML counterpart of the requirement that the final coalgebra contains all behaviours; without it, ν F \nu_F ν F may miss behaviours (Remark 4.17), and it is sound (Appendix § 10 ).
Adequacy By (NO COCONFUSION.3) and (NO CONFUSION) (Lemma 4.10 ), every x ∈ U x \in U x ∈ U is c ( a , f ) c(a,f) c ( a , f ) for exactly one a ∈ A M a \in A_M a ∈ A M and f ∈ Fun a ( M ) f \in\operatorname{Fun}_a(M) f ∈ Fun a ( M ) , namely a = x . o u t a=x.out a = x . o u t and f = x . n x t f=x.nxt f = x . n x t ; since U = Φ F ( U ) U=\Phi_F(U) U = Φ F ( U ) , we have f ∈ Fun a ( U ) f \in\operatorname{Fun}_a(U) f ∈ Fun a ( U ) . The coalgebra extracted from M M M is
α ν ( M ) = ( U , γ ) , γ : U → F M U , γ ( x ) = ( x . o u t , ∣ x . n x t ∣ ) . \alpha_\nu(M)=(U,\gamma), \qquad\gamma\mathrel{:}U\to F_M U,\quad\gamma(x)=(x.out,\lvert x.nxt\rvert). α ν ( M ) = ( U , γ ) , γ : U → F M U , γ ( x ) = ( x . o u t , ∣ x . n x t ∣) .
Let ζ : Z M → F M Z M \zeta\mathrel{:}Z_M\to F_M Z_M ζ : Z M → F M Z M be the final F M F_M F M -coalgebra, i.e., the M-type of a : A M ⊢ B M [ a ] a\mathrel{:}A_M \vdash B_M[a] a : A M ⊢ B M [ a ] [1 ] , whose elements are the possibly infinite trees with nodes labelled by shapes a a a and branching B M [ a ] B_M[a] B M [ a ] .
Let β : ( U , γ ) → ( Z M , ζ ) \beta\mathrel{:}(U,\gamma)\to(Z_M,\zeta) β : ( U , γ ) → ( Z M , ζ ) be the unique coalgebra morphism. The following lemma shows that finite paths faithfully describe trees, and relates this description to the patterns Tree \operatorname{Tree} Tree , Sub \operatorname{Sub} Sub , and Beh \operatorname{Beh} Beh . Let P M = { ⟨ a , b ⟩ ∣ a ∈ A M , b ∈ B M [ a ] } P_M=\{\langle a,b\rangle\mid a\in A_M,\ b\in B_M[a]\} P M = {⟨ a , b ⟩ ∣ a ∈ A M , b ∈ B M [ a ]} . A path is a finite sequence π = ( ⟨ a 1 , b 1 ⟩ , … , ⟨ a n , b n ⟩ ) \pi=(\langle a_1,b_1\rangle,\ldots,\langle a_n,b_n\rangle) π = (⟨ a 1 , b 1 ⟩ , … , ⟨ a n , b n ⟩) of elements of P M P_M P M . A tree z ∈ Z M z\in Z_M z ∈ Z M has the path π \pi π ending in the shape a a a if, starting at the root, for each i i i the node reached has shape a i a_i a i and one moves to its child at position b i b_i b i , and the node finally reached has shape a a a . The path description of z z z is T z = { ( π , a ) ∣ z has π ending in a } T_z=\{(\pi,a)\mid z\text{ has }\pi\text{ ending in }a\} T z = {( π , a ) ∣ z has π ending in a } . A set T T T of pairs ( π , a ) (\pi,a) ( π , a ) , with π \pi π a path and a ∈ A M a\in A_M a ∈ A M , is admissible if (i) ( π , a ) , ( π , a ′ ) ∈ T (\pi,a),(\pi,a')\in T ( π , a ) , ( π , a ′ ) ∈ T imply a = a ′ a=a' a = a ′ , (ii) ( ε , a ) ∈ T (\varepsilon,a)\in T ( ε , a ) ∈ T for some a a a , and (iii) ( π , a ) ∈ T (\pi,a)\in T ( π , a ) ∈ T and b ∈ B M [ a ] b\in B_M[a] b ∈ B M [ a ] imply ( π ⋅ ⟨ a , b ⟩ , a ′ ) ∈ T (\pi\cdot\langle a,b\rangle,a')\in T ( π ⋅ ⟨ a , b ⟩ , a ′ ) ∈ T for some a ′ a' a ′ . A path is reachable in T T T if it is ε \varepsilon ε , or it is π ⋅ ⟨ a , b ⟩ \pi\cdot\langle a,b\rangle π ⋅ ⟨ a , b ⟩ with π \pi π reachable, ( π , a ) ∈ T (\pi,a)\in T ( π , a ) ∈ T , and b ∈ B M [ a ] b\in B_M[a] b ∈ B M [ a ] ; the reachable part R ( T ) R(T) R ( T ) consists of the pairs ( π , a ) ∈ T (\pi,a)\in T ( π , a ) ∈ T with π \pi π reachable.
Lemma 4.14. Let M M M be a model of the axioms of Γ F ∨ \Gamma^{\vee}_{F} Γ F ∨ other than (BISIMILARITY) and (REALISATION).
For every z ∈ Z M z \in Z_M z ∈ Z M , T z T_z T z is admissible and R ( T z ) = T z R(T_z)=T_z R ( T z ) = T z ; moreover, T z = T z ′ T_z=T_{z'} T z = T z ′ implies z = z ′ z=z' z = z ′ .
For every admissible T T T , there is exactly one tree z T ∈ Z M z_T \in Z_M z T ∈ Z M with T z T = R ( T ) T_{z_T}=R(T) T z T = R ( T ) .
The interpretation of List ( P ) \operatorname{List}(P) List ( P ) , with pnil \operatorname{pnil} pnil and pcons \operatorname{pcons} pcons , is in bijection with the set of paths; we write [ π ] [\pi] [ π ] for the list that represents π \pi π (the most recent step first). For x ∈ U x \in U x ∈ U , the interpretation of Sub ( x ) \operatorname{Sub}(x) Sub ( x ) is the set of pairs ⟨ [ π ] , x π ⟩ \langle[\pi],x_\pi\rangle ⟨[ π ] , x π ⟩ , where π \pi π is a path of β ( x ) \beta(x) β ( x ) and x π ∈ U x_\pi\in U x π ∈ U is the element reached from x x x along π \pi π ; β ( x ) \beta(x) β ( x ) has π \pi π ending in x π . out x_\pi.\operatorname{out} x π . out . Consequently, if a set of pairs ⟨ [ π ] , a ⟩ \langle[\pi],a\rangle ⟨[ π ] , a ⟩ satisfies Tree \operatorname{Tree} Tree , then the corresponding set T T T of pairs ( π , a ) (\pi,a) ( π , a ) is admissible, and it satisfies Beh ( x , ⋅ ) \operatorname{Beh}(x,\mathord{\cdot}) Beh ( x , ⋅ ) iff β ( x ) = z T \beta(x)=z_T β ( x ) = z T .
Proof. (1) Conditions (i)–(iii) hold because every path of z z z ends in exactly one node, z z z has a root, and every node of shape a a a has a child at each b ∈ B M [ a ] b \in B_M[a] b ∈ B M [ a ] ; every path of z z z is reachable in T z T_z T z , by induction on its length. If T z = T z ′ T_z=T_{z'} T z = T z ′ , then the relation { ( u , u ′ ) ∣ T u = T u ′ } \{(u,u') \mid T_u=T_{u'}\} {( u , u ′ ) ∣ T u = T u ′ } on Z M Z_M Z M is a bisimulation: related trees have the same root shape a a a , and, for b ∈ B M [ a ] b \in B_M[a] b ∈ B M [ a ] , the path descriptions of their children at b b b are obtained from T u = T u ′ T_u=T_{u'} T u = T u ′ by removing the first step ⟨ a , b ⟩ \langle a,b\rangle ⟨ a , b ⟩ . Since the final coalgebra is strongly extensional, z = z ′ z=z' z = z ′ .
(2) For a reachable path π \pi π , let a π a_\pi a π be the unique shape with ( π , a π ) ∈ T (\pi,a_\pi) \in T ( π , a π ) ∈ T ; it exists by (ii) and (iii), by induction on π \pi π , and it is unique by (i). The reachable paths form an F M F_M F M -coalgebra, with π ↦ ( a π , b ↦ π ⋅ ⟨ a π , b ⟩ ) \pi\mapsto(a_\pi,b \mapsto\pi\mathbin{\cdot}\langle a_\pi,b\rangle) π ↦ ( a π , b ↦ π ⋅ ⟨ a π , b ⟩) . Let z T ∈ Z M z_T \in Z_M z T ∈ Z M be the image of ε \varepsilon ε under the unique morphism into ( Z M , ζ ) (Z_M,\zeta) ( Z M , ζ ) . By induction on paths, z T z_T z T has exactly the reachable paths π \pi π , ending in a π a_\pi a π , so T z T = R ( T ) T_{z_T}=R(T) T z T = R ( T ) . Uniqueness follows from (1).
(3) The bijection between List ( P ) \operatorname{List}(P) List ( P ) and the paths follows from the no-junk and no-confusion axioms of List ( P ) \operatorname{List}(P) List ( P ) , by the argument of [9 Theorem 44] . The interpretation of Sub ( x ) \operatorname{Sub}(x) Sub ( x ) is the least fixpoint of a map that adds, for each pair ⟨ p , y ⟩ \langle p,y\rangle ⟨ p , y ⟩ already obtained and each b ∈ B M [ y . out ] b \in B_M[y.\operatorname{out}] b ∈ B M [ y . out ] , the pair
⟨ pcons ⟨ y . out , b ⟩ p , ( y . nxt ) b ⟩ ; \langle\operatorname{pcons}\ \langle y.\operatorname{out},b\rangle\ p,\ (y.\operatorname{nxt})\ b\rangle; ⟨ pcons ⟨ y . out , b ⟩ p , ( y . nxt ) b ⟩ ;
so it is the union of the finite iterations, and its elements are the pairs ⟨ [ π ] , x π ⟩ \langle[\pi],x_\pi\rangle ⟨[ π ] , x π ⟩ , by induction on the length of π \pi π . Since β \beta β is a coalgebra morphism, γ ( x π ) = ( x π . out , ∣ x π . nxt ∣ ) \gamma(x_\pi)=(x_\pi.\operatorname{out},|x_\pi.\operatorname{nxt}|) γ ( x π ) = ( x π . out , ∣ x π . nxt ∣ ) shows that β ( x ) \beta(x) β ( x ) has π \pi π ending in x π . out x_\pi.\operatorname{out} x π . out , and that the paths of β ( x ) \beta(x) β ( x ) are exactly these π \pi π . The pattern Tree \operatorname{Tree} Tree states (i)–(iii) for the pairs it constrains, so T T T is admissible, and Beh ( x , T ) \operatorname{Beh}(x,T) Beh ( x , T ) states T β ( x ) ⊆ T T_{\beta(x)} \subseteq T T β ( x ) ⊆ T . If β ( x ) = z T \beta(x)=z_T β ( x ) = z T , then T β ( x ) = R ( T ) ⊆ T T_{\beta(x)}=R(T) \subseteq T T β ( x ) = R ( T ) ⊆ T . Conversely, if T β ( x ) ⊆ T T_{\beta(x)} \subseteq T T β ( x ) ⊆ T , then every path of β ( x ) \beta(x) β ( x ) is reachable in T T T (by induction, using (i)), and every path reachable in T T T is a path of β ( x ) \beta(x) β ( x ) (by induction: if ( π , a ) ∈ T (\pi,a) \in T ( π , a ) ∈ T and β ( x ) \beta(x) β ( x ) has π \pi π ending in a ′ a' a ′ , then ( π , a ′ ) ∈ T (\pi,a') \in T ( π , a ′ ) ∈ T , so a = a ′ a=a' a = a ′ by (i), and the children of that node are at the positions b ∈ B M [ a ] b \in B_M[a] b ∈ B M [ a ] ). So T β ( x ) = R ( T ) T_{\beta(x)}=R(T) T β ( x ) = R ( T ) , and β ( x ) = z T \beta(x)=z_T β ( x ) = z T by (2).
:::
Theorem 4.15. Let M M M be a model of Γ F ∨ \Gamma^{\vee}_{F} Γ F ∨ . Then:
U U U is the largest set S ⊆ M S \subseteq M S ⊆ M with S ⊆ Φ F ( S ) S \subseteq\Phi_F(S) S ⊆ Φ F ( S ) ;
α V ( M ) \alpha_V(M) α V ( M ) is a final F M F_M F M -coalgebra: the unique coalgebra morphism β : ( U , γ ) → ( Z M , ζ ) \beta:(U,\gamma)\to(Z_M,\zeta) β : ( U , γ ) → ( Z M , ζ ) is a bijection.
Proof. (1) is the Knaster–Tarski characterization of gfp ( Φ F ) \operatorname{gfp}(\Phi_F) gfp ( Φ F ) .
β \beta β is injective. Let K = { ( x , y ) ∈ U × U ∣ β ( x ) = β ( y ) } K=\{(x,y)\in U\times U\mid\beta(x)=\beta(y)\} K = {( x , y ) ∈ U × U ∣ β ( x ) = β ( y )} . If ( x , y ) ∈ K (x,y)\in K ( x , y ) ∈ K , with γ ( x ) = ( a , g ) \gamma(x)=(a,g) γ ( x ) = ( a , g ) and γ ( y ) = ( a ′ , g ′ ) \gamma(y)=(a',g') γ ( y ) = ( a ′ , g ′ ) , then F M β ( x ) = ζ ( β ( x ) ) = ζ ( β ( y ) ) = F M β ( y ) F_M\beta(x)=\zeta(\beta(x))=\zeta(\beta(y))=F_M\beta(y) F M β ( x ) = ζ ( β ( x )) = ζ ( β ( y )) = F M β ( y ) , so a = a ′ a=a' a = a ′ and b ∘ g = b ∘ g ′ \operatorname{b} \circ g=\operatorname{b} \circ g' b ∘ g = b ∘ g ′ , i.e., ( g b , g ′ b ) ∈ K (gb,g'b)\in K ( g b , g ′ b ) ∈ K for all b ∈ B M [ a ] b\in B_M[a] b ∈ B M [ a ] . By (No Cofonfusion.1–2), x . out x.\operatorname{out} x . out means that x x x and y y y have the same shape a a a , and ( x . nxt ) b (x.\operatorname{nxt})\ b ( x . nxt ) b is matched by g b g b g b . So, with ⟨ K ⟩ = { ⟨ x , y ⟩ ∣ ( x , y ) ∈ K } \langle K\rangle=\{\langle x,y\rangle\mid(x,y)\in K\} ⟨ K ⟩ = {⟨ x , y ⟩ ∣ ( x , y ) ∈ K } (pairs of elements of the sort ν F \nu F ν F exist and are injective, by the axioms of PAIR), the previous observation says ⟨ K ⟩ ⊆ ∣ bis ( R ) ∣ M , ρ [ ⟨ K ⟩ / R ] \langle K\rangle\subseteq\lvert\operatorname{bis}(R)\rvert_{M,\rho[\langle K\rangle/R]} ⟨ K ⟩ ⊆ ∣ bis ( R ) ∣ M , ρ [⟨ K ⟩ / R ] . By the Knaster–Tarski theorem, ⟨ K ⟩ \langle K\rangle ⟨ K ⟩ is included in the interpretation of Bisim \operatorname{Bisim} Bisim , and (BISIMILARITY) gives x = y x=y x = y for all ( x , y ) ∈ K (x,y)\in K ( x , y ) ∈ K .
::: β \beta β is surjective. Let z ∈ Z M z \in Z_M z ∈ Z M . By Lemma 4.14 (1), T z T_z T z is admissible, so the set of pairs ⟨ [ π ] , a ⟩ \langle[\pi],a\rangle ⟨[ π ] , a ⟩ with ( π , a ) ∈ T z (\pi,a) \in T_z ( π , a ) ∈ T z satisfies T r e e Tree T r ee . By (REALISATION), there is x ∈ U x \in U x ∈ U with B e h ( x , T z ) Beh(x,T_z) B e h ( x , T z ) , so β ( x ) = z T z = z \beta(x) = z_{T_z} = z β ( x ) = z T z = z by Lemma 4.14 (1)–(3).
A bijective coalgebra morphism is an isomorphism, so α ν ( M ) \alpha_{\nu}(M) α ν ( M ) is final.
Corollary 4.16. If, moreover, M M M interprets shapes and positions standardly (a bijection ι : A → A M \iota:A \to A_M ι : A → A M and bijections B [ a ] ≅ B M [ ι ( a ) ] B[a] \cong B_M[\iota(a)] B [ a ] ≅ B M [ ι ( a )] for all a ∈ A a \in A a ∈ A ), then α ν ( M ) \alpha_{\nu}(M) α ν ( M ) is isomorphic to the final F F F -coalgebra ν F \nu F ν F , the M M M -type of a : A ⊢ B [ a ] a\!:\!A \vdash B[a] a : A ⊢ B [ a ] .
Remark 4.17. The axioms (BISIMILARITY) and (REALISATION) are needed for Theorem 4.15 ; Proposition B.4 (3)–(6) gives structures that satisfy all the other axioms of Γ F \Gamma_F Γ F and whose extracted coalgebras are not final. Without (BISIMILARITY), a model of streams over E = { 0 } E = \{0\} E = { 0 } may contain two elements x ≠ y x \ne y x = y with x = c o n s ⟨ 0 , f x ⟩ x = cons\langle0,f_x\rangle x = co n s ⟨ 0 , f x ⟩ , y = c o n s ⟨ 0 , f y ⟩ y = cons\langle0,f_y\rangle y = co n s ⟨ 0 , f y ⟩ , where f x f_x f x and f y f_y f y map the unique position to x x x and y y y , respectively; x x x and y y y are bisimilar but different. Without (REALISATION), T ν F \mathsf{T}_{\nu F} T ν F may even be empty: for the identity functor, there is a model of all the other axioms with T ν F = ⊥ \mathsf{T}_{\nu F} = \bot T ν F = ⊥ (§ 5.2 ). It may also miss behaviours: for the streams over E = { 0 , 1 } E = \{0,1\} E = { 0 , 1 } , there is a model of all the other axioms, including (BISIMILARITY), in which T ν F \mathsf{T}_{\nu F} T ν F consists of the eventually periodic streams; it is constructed in Proposition B.4 (5). Closure of this set under c o n s cons co n s and under taking tails gives only that it is a fixpoint of Φ F \Phi_F Φ F , hence included in the greatest one; the converse inclusion holds because the carrier has no other element that can be unfolded indefinitely, by the argument on construction stages of Lemma B.3 (4). This set is countable, while the final coalgebra E ω E^\omega E ω is not, and (REALISATION) fails for the set T T T describing a stream that is not eventually periodic.
Proposition 4.18. Let X ↦ F X = ∑ a : A X B [ a ] X \mapsto F X = \sum_{a:A} X^{B[a]} X ↦ F X = ∑ a : A X B [ a ] be a container functor, specified as above. There is a model M M M of Γ F \Gamma_F Γ F (hence of Γ F ν \Gamma_F^\nu Γ F ν ) with a bijection ι : A → A M \iota:A \to A_M ι : A → A M and bijections B [ a ] ≅ B M [ ι ( a ) ] B[a] \cong B_M[\iota(a)] B [ a ] ≅ B M [ ι ( a )] for all a ∈ A a \in A a ∈ A , in which T ν F \mathsf{T}_{\nu F} T ν F with γ \gamma γ is isomorphic to the M M M -type of a : A ⊢ B [ a ] a\!:\!A \vdash B[a] a : A ⊢ B [ a ] .
Proof. The model of Appendix B (Theorem B.2 ) is a model of the theories of both the initial algebra and the final coalgebra. There, T ν F \mathsf{T}_{\nu F} T ν F is the set Z Z Z of all trees of the M M M -type, c o n s cons co n s maps a shape and the code of a family of trees to the corresponding tree, fresh terms are excluded from the greatest fixpoint by a well-foundedness argument on construction stages, and (BISIMILARITY) and (REALISATION) hold because Z Z Z is the final coalgebra.
Deriving Coinduction Principle The following Coinduction Principle is derivable:
ψ → ∃ a : A . c o n s ⟨ a , ψ B [ a ] ⟩ ψ → T ν F \frac{\psi\to\exists a\!:\!A.\,cons\langle a,\psi^{B[a]}\rangle}{\psi\to\mathsf{T}_{\nu F}} ψ → T ν F ψ → ∃ a : A . co n s ⟨ a , ψ B [ a ] ⟩
where ψ B [ a ] \psi^{B[a]} ψ B [ a ] is as in the Induction Principle. The premise is ψ → Φ F ( ψ ) \psi\to\Phi_F(\psi) ψ → Φ F ( ψ ) . Since ν X . φ ≡ ¬ μ X . ¬ φ [ − X / X ] \nu X.\,\varphi\equiv\neg\mu X.\,\neg\varphi[-X/X] ν X . φ ≡ ¬ μ X . ¬ φ [ − X / X ] , the Knaster–Tarski rule yields its dual, which derives ψ → ν X . φ \psi\to\nu X.\,\varphi ψ → ν X . φ from ψ → φ [ ψ / X ] \psi\to\varphi[\psi/X] ψ → φ [ ψ / X ] (see [10 , 8 ] ). This gives ψ → ν X . Φ F ( X ) \psi\to\nu X.\,\Phi_F(X) ψ → ν X . Φ F ( X ) , and (NO COJUNK) rewrites ν X . Φ F ( X ) \nu X.\,\Phi_F(X) ν X . Φ F ( X ) as T ν F \mathsf{T}_{\nu F} T ν F . The quantifier on a a a in the premise is existential, not universal: different elements matching ψ \psi ψ may have different shapes.
Deriving Bisimulation Principle The following Bisimulation Principle , the usual coinductive proof principle for equality, is derivable:
ψ → b i s ( ψ ) ∀ x , y : ν F . ⟨ x , y ⟩ ∈ ψ → x = y \frac{\psi\to bis(\psi)}{\forall x,y\!:\!\nu F.\,\langle x,y\rangle\in\psi\to x = y} ∀ x , y : ν F . ⟨ x , y ⟩ ∈ ψ → x = y ψ → bi s ( ψ )
where ψ \psi ψ is a pattern (of pairs) in which R R R does not occur free. Indeed, the dual Knaster–Tarski rule gives ψ → ν R . bis ( R ) \psi\to\nu R.\operatorname{bis}(R) ψ → ν R . bis ( R ) , i.e., ψ → Bisim \psi\to\operatorname{Bisim} ψ → Bisim , and (BISIMILARITY) gives the conclusion. So, to prove that two elements of ν F \nu F ν F are equal, it is enough to exhibit a bisimulation ψ \psi ψ that relates them.
Capturing the Parameters and Comparing the Two Theories
This subsection concerns both theories: it shows when the shapes and positions, and hence μ F \mu F μ F and ν F \nu F ν F themselves, are captured, and compares the axioms of Γ F μ \Gamma_F^\mu Γ F μ and Γ F ν \Gamma_F^\nu Γ F ν .
Capturing the shapes and positions Theorems 4.4 and 4.15 capture μ F \mu F μ F and ν F \nu F ν F relative to the interpretation of the parameter sorts A A A and B [ a ] B[a] B [ a ] . The axioms above do not fix this interpretation: for the constant functor with one shape and no positions, a model with two shapes and no positions satisfies them, and its extracted initial algebra has two elements. The intended data type is obtained in every model when the theory also captures the parameters.
Proposition 4.19. Suppose that the theory also includes axioms such that, in every model M M M , there are a bijection ι : A → A M \iota: A \to A_M ι : A → A M and bijections B [ a ] ≅ B M [ ι ( a ) ] B[a] \cong B_M[\iota(a)] B [ a ] ≅ B M [ ι ( a )] for all a ∈ A a \in A a ∈ A . Then, in every model M M M , α μ ( M ) \alpha_\mu(M) α μ ( M ) is isomorphic to the initial F F F -algebra μ F \mu F μ F and α ν ( M ) \alpha_\nu(M) α ν ( M ) is isomorphic to the final F F F -coalgebra ν F \nu F ν F .
Proof. The bijections form an isomorphism between the containers a : A ⊢ B [ a ] a\!:\!A \vdash B[a] a : A ⊢ B [ a ] and a : A M ⊢ B M [ a ] a\!:\!A_M \vdash B_M[a] a : A M ⊢ B M [ a ] , hence a natural isomorphism F ≅ F M F \cong F_M F ≅ F M , which maps initial algebras to initial algebras and final coalgebras to final coalgebras. The claim follows from Theorems 4.4 and 4.15.
We now give sufficient conditions for the hypothesis of Proposition 4.19.
Definition 4.20. A parameter specification is a sort s s s together with a set Γ s \Gamma_s Γ s of axioms and an intended set S S S . It is captured if, in every model M M M of Γ 0 ∪ Γ s \Gamma_0 \cup\Gamma_s Γ 0 ∪ Γ s , the interpretation ∣ ⊤ s ∣ M \lvert\top_s\rvert_M ∣ ⊤ s ∣ M is in bijection with S S S . A family a : A ⊢ B [ a ] a\!:\!A \vdash B[a] a : A ⊢ B [ a ] over a captured sort A A A , with intended sets B [ a ] B[a] B [ a ] , is captured if, in every model M M M , there are a bijection ι : A → A M \iota: A \to A_M ι : A → A M and bijections B [ a ] ≅ B M [ ι ( a ) ] B[a] \cong B_M[\iota(a)] B [ a ] ≅ B M [ ι ( a )] for all a ∈ A a \in A a ∈ A . The class C \mathcal{C} C of standard parameter specifications is the least class closed under the following rules, where the symbols introduced by different rules are distinct:
(Fin) for n ≥ 0 n \ge0 n ≥ 0 , a sort s s s with constants c 1 , … , c n c_1,\ldots,c_n c 1 , … , c n and the axioms s : Sort s\!:\!\operatorname{Sort} s : Sort , ∃ y . c i = y \exists y.\ c_i = y ∃ y . c i = y , c i ≠ c j c_i \ne c_j c i = c j for i ≠ j i \ne j i = j , and ⊤ s = c 1 ∨ ⋯ ∨ c n \top_s = c_1 \lor\cdots\lor c_n ⊤ s = c 1 ∨ ⋯ ∨ c n (for n = 0 n = 0 n = 0 , ⊤ s = ⊥ \top_s = \bot ⊤ s = ⊥ ), with intended set { c 1 , … , c n } \{c_1,\ldots,c_n\} { c 1 , … , c n } ;
(Prod) for s 1 , s 2 ∈ C s_1,s_2 \in\mathcal{C} s 1 , s 2 ∈ C , the sort s 1 ⊗ s 2 s_1 \otimes s_2 s 1 ⊗ s 2 , with intended set S 1 × S 2 S_1 \times S_2 S 1 × S 2 ;
(Fam) for A ∈ C A \in\mathcal{C} A ∈ C , a family a : A ⊢ B [ a ] a\!:\!A \vdash B[a] a : A ⊢ B [ a ] that is either constant , with the axiom ∀ a : A . B [ a ] = s \forall a\!:\!A.\ B[a] = s ∀ a : A . B [ a ] = s for some s ∈ C s \in\mathcal{C} s ∈ C , or, if A A A is given by (Fin) with constants c 1 , … , c n c_1,\ldots,c_n c 1 , … , c n , defined by cases , with the axioms B [ c i ] = s i B[c_i] = s_i B [ c i ] = s i for some s 1 , … , s n ∈ C s_1,\ldots,s_n \in\mathcal{C} s 1 , … , s n ∈ C , or, if A A A is a dependent sum ∑ i : I C [ i ] \sum_{i:I} C[i] ∑ i : I C [ i ] given by (Sum) with I I I given by (Fin) with constants c 1 , … , c n c_1,\ldots,c_n c 1 , … , c n , defined by cases on the tag , with the axioms ∀ x : C [ c i ] . B [ ⟨ c i , x ⟩ ] = s i \forall x\!:\!C[c_i].\ B[\langle c_i,x\rangle] = s_i ∀ x : C [ c i ] . B [⟨ c i , x ⟩] = s i for some s 1 , … , s n ∈ C s_1,\ldots,s_n \in\mathcal{C} s 1 , … , s n ∈ C . In all cases, B [ a ] = s B[a] = s B [ a ] = s is an equality of sorts, i.e., of elements of Sort \operatorname{Sort} Sort ; it implies ⊤ B [ a ] = ⊤ s \top_{B[a]} = \top_s ⊤ B [ a ] = ⊤ s , but is stronger;
(Sum) for A ∈ C A \in\mathcal{C} A ∈ C and a family as in (Fam), the dependent sum ∑ a : A B [ a ] \sum_{a:A} B[a] ∑ a : A B [ a ] , with intended set ∑ a ∈ A B [ a ] \sum_{a\in A} B[a] ∑ a ∈ A B [ a ] ;
(Ind) for a container a : A ⊢ B [ a ] a\!:\!A \vdash B[a] a : A ⊢ B [ a ] with A ∈ C A \in\mathcal{C} A ∈ C and a family as in (Fam), the sort μ G \mu G μ G with the axioms of Γ G μ \Gamma_G^\mu Γ G μ , and the sort ν G \nu G ν G with the axioms of Γ G ν \Gamma_G^\nu Γ G ν , where G G G is the corresponding container functor, with intended sets the W-type and the M-type of a : A ⊢ B [ a ] a\!:\!A \vdash B[a] a : A ⊢ B [ a ] .
The specifications of 0 0 0 and 1 1 1 (Section 4.1) are the instances n = 0 n = 0 n = 0 and n = 1 n = 1 n = 1 of (Fin), the latter with the constant ⋆ \star ⋆ , so 0 , 1 ∈ C 0,1 \in C 0 , 1 ∈ C ; similarly, a sum of n n n sorts of C C C is given by (Fin) with n n n tags, (Fam) by cases, and (Sum).
The class C p a r C^{\mathrm{par}} C par of parametric specifications is the least class closed under the rules above, read with C p a r C^{\mathrm{par}} C par in place of C C C , and under the rule
(Par) a sort symbol s s s with the only axiom s : S o r t s\colon Sort s : S or t , called a parameter sort ; it has no intended set.
So C ⊆ C p a r C \subseteq C^{\mathrm{par}} C ⊆ C par . A parameter sort is not captured: its interpretation is arbitrary, possibly empty, and the sorts built from it are captured only relative to this interpretation. An instance of a specification in C p a r C^{\mathrm{par}} C par chooses a set S S S for each parameter sort; the intended sets of the other sorts are then determined by the rules.
Theorem 4.21. Every specification in C C C is captured, and so is every family given by (Fam). Consequently, if the shapes A A A and the family B B B of a container functor F F F are given by (Fam) from specifications in C C C , then, in every model M M M of 1 F \mathsf{1}_F 1 F together with these specifications, α μ ( M ) \alpha_\mu(M) α μ ( M ) is isomorphic to μ F \mu F μ F and α ν ( M ) \alpha_\nu(M) α ν ( M ) is isomorphic to ν F \nu F ν F .
Proof. By induction on the rules of Definition 4.20. (Fin): the axioms say that T s T_s T s consists of the n n n pairwise distinct elements denoted by c 1 , … , c n c_1,\ldots,c_n c 1 , … , c n . (Prod): by (Pair Domain) and (Pair Inj), T s 1 ⊗ s 2 T_{s_1\otimes s_2} T s 1 ⊗ s 2 is in bijection with the product of T s 1 T_{s_1} T s 1 and T s 2 T_{s_2} T s 2 , hence, by the induction hypothesis, with S 1 × S 2 S_1 \times S_2 S 1 × S 2 . (Fam): a constant family has B M [ a ] = ∣ T s ∣ M B_M[a] = |T_s|_M B M [ a ] = ∣ T s ∣ M for all a ∈ A M a \in A_M a ∈ A M ; a family defined by cases has B M [ c i ] = ∣ T s i ∣ M B_M[c_i] = |T_{s_i}|_M B M [ c i ] = ∣ T s i ∣ M , and A M A_M A M consists of the elements denoted by c 1 , … , c n c_1,\ldots,c_n c 1 , … , c n ; a family defined by cases on the tag has B M [ ⟨ c i , x ⟩ ] = ∣ T s i ∣ M B_M[\langle c_i,x\rangle] = |T_{s_i}|_M B M [⟨ c i , x ⟩] = ∣ T s i ∣ M , and every element of A M A_M A M is such a pair; in all cases the bijections are given by the induction hypothesis. (Sum): by the axiom of dependent sums and (Pair Inj), which applies to pairs whose second components belong to different sorts B [ a ] B[a] B [ a ] , T ∑ a : A B [ a ] T_{\sum_{a:A}B[a]} T ∑ a : A B [ a ] is in bijection with ∑ a ∈ A M B M [ a ] \sum_{a\in A_M} B_M[a] ∑ a ∈ A M B M [ a ] , hence with ∑ a ∈ A B [ a ] \sum_{a\in A} B[a] ∑ a ∈ A B [ a ] . (Ind): by the induction hypothesis the family is captured, so Proposition 4.19 applies to G G G . By (MU SORT) and (NU SORT), μ G \mu G μ G and ν G \nu G ν G are sorts, so they may occur in (Prod), (Fam), and (Sum), whose axioms quantify over sorts. The last claim is Proposition 4.19, whose hypothesis is the capture of the family.
The combined theory used in Theorem 4.21 is consistent: it has a model in which all sorts have their intended interpretations, up to canonical bijections (Theorem B.6). The same theorem covers the parametric specifications: for every instance of a specification in C p a r C^{\mathrm{par}} C par , there is a model in which each parameter sort is interpreted by a set in bijection with the chosen one. In particular, the theories of lists over an arbitrary set of elements (Section 5) and of Moore machines over arbitrary sets of outputs and inputs (Section 6) are consistent, and the results proved for all their models are not vacuous.
Corollary 4.22. The following are captured in every model of the corresponding theories, with their intended interpretations: the natural numbers (μ \mu μ of the container with shapes { z , s } \{z,s\} { z , s } and positions B [ z ] = 0 B[z] = 0 B [ z ] = 0 , B [ s ] = 1 B[s] = 1 B [ s ] = 1 ); the lists (shapes 1 + E 1 + E 1 + E , i.e., ∑ i : { l , r } C [ i ] \sum_{i:\{l,r\}} C[i] ∑ i : { l , r } C [ i ] with C [ l ] = 1 C[l] = 1 C [ l ] = 1 and C [ r ] = E C[r] = E C [ r ] = E , and positions defined by cases on the tag, 0 0 0 for l l l and 1 1 1 for r r r ) and the streams over a set E E E given by a specification in C C C ; and the final coalgebra of Moore machines with outputs and inputs given by specifications in C C C , e.g., deterministic automata with O = { 0 , 1 } O = \{0,1\} O = { 0 , 1 } and a finite input alphabet I I I .
Remark 4.23. Theorem 4.21 has two limits. First, a parameter that is meant to be arbitrary, such as the set of elements of lists in general, is a parameter sort (rule (Par)): it is not fixed by any specification, and the results for it remain relative to its interpretation; the class C C C also does not contain sets that are not built by its rules, e.g., the real numbers. Second, (Fam) covers only constant families and families defined by cases over a finite set of shapes or of tags. Families such as n : N ⊢ [ n ] n\colon\mathbb{N} \vdash[n] n : N ⊢ [ n ] , with [ n ] = { 0 , … , n − 1 } [n] = \{0,\ldots,n-1\} [ n ] = { 0 , … , n − 1 } , are not covered; capturing them would require the family itself to be defined by a captured relation, which we leave for future work.
Local and global axioms The axioms that make the extracted structures isomorphic to the intended ones come in two kinds. Local axioms speak about one constructor step: (EXT) and (TAB). Global axioms speak about whole trees: (BISIMILARITY) and (REALISATION). The theory of μ F \mu F μ F uses the local ones, and the theory of ν F \nu F ν F the global ones. The following proposition shows that each theory implies the axioms it does not contain, restricted to its own sort.
Proposition 4.24. Each theory implies, on its own sort, the axioms of the other kind:
Let M M M be a model of Γ F μ \Gamma^{\mu}_{F} Γ F μ , and L = ∣ ⊤ μ F ∣ M L = \lvert\top_{\mu F}\rvert_{M} L = ∣ ⊤ μ F ∣ M . If K ⊆ L × L K \subseteq L \times L K ⊆ L × L is such that, for all ( x , y ) ∈ K (x,y) \in K ( x , y ) ∈ K with x = c ( a , f ) x = c(a,f) x = c ( a , f ) and y = c ( a ′ , f ′ ) y = c(a',f') y = c ( a ′ , f ′ ) , we have a = a ′ a = a' a = a ′ and ( ∣ f ∣ ( b ) , ∣ f ′ ∣ ( b ) ) ∈ K (\lvert f\rvert(b),\lvert f'\rvert(b)) \in K (∣ f ∣ ( b ) , ∣ f ′ ∣ ( b )) ∈ K for all b ∈ B M [ a ] b \in B_{M}[a] b ∈ B M [ a ] , then K K K is included in the equality. Moreover, every tree of W M W_{M} W M is represented by an element of L L L .
Let M M M be a model of Γ F ν \Gamma^{\nu}_{F} Γ F ν , and U = ∣ ⊤ ν F ∣ M U = \lvert\top_{\nu F}\rvert_{M} U = ∣ ⊤ ν F ∣ M . Then, for all a ∈ A M a \in A_{M} a ∈ A M , (a) f , f ′ ∈ Fun a ( U ) f,f' \in\operatorname{Fun}_{a}(U) f , f ′ ∈ Fun a ( U ) and ∣ f ∣ = ∣ f ′ ∣ \lvert f\rvert= \lvert f'\rvert ∣ f ∣ = ∣ f ′ ∣ imply f = f ′ f = f' f = f ′ , and (b) every function g : B M [ a ] → U g : B_{M}[a] \to U g : B M [ a ] → U is ∣ f ∣ \lvert f\rvert ∣ f ∣ for some f ∈ Fun a ( U ) f \in\operatorname{Fun}_{a}(U) f ∈ Fun a ( U ) .
Proof. (1) By Theorem 4.4 , every x ∈ L x \in L x ∈ L is h ( w ) h(w) h ( w ) for a unique w ∈ W M w \in W_{M} w ∈ W M , which gives the second claim. For the first, we show by well-founded induction on w w w that ( h ( w ) , y ) ∈ K (h(w),y) \in K ( h ( w ) , y ) ∈ K implies h ( w ) = y h(w) = y h ( w ) = y . Let w = sup ( a , t ) w = \sup(a,t) w = sup ( a , t ) , so h ( w ) = c ( a , ⌜ h ∘ t ⌝ a ) h(w) = c(a,\ulcorner h \mathbin{\circ} t\urcorner_{a}) h ( w ) = c ( a , ┌ h ∘ t ┐ a ) , and let y = h ( w ′ ) y = h(w') y = h ( w ′ ) with w ′ = sup ( a ′ , t ′ ) w' = \sup(a',t') w ′ = sup ( a ′ , t ′ ) . Then a = a ′ a = a' a = a ′ and ( h ( t ( b ) ) , h ( t ′ ( b ) ) ) ∈ K (h(t(b)),h(t'(b))) \in K ( h ( t ( b )) , h ( t ′ ( b ))) ∈ K for all b b b , so h ( t ( b ) ) = h ( t ′ ( b ) ) h(t(b)) = h(t'(b)) h ( t ( b )) = h ( t ′ ( b )) by the induction hypothesis, hence h ∘ t = h ∘ t ′ h \mathbin{\circ} t = h \mathbin{\circ} t' h ∘ t = h ∘ t ′ and h ( w ) = h ( w ′ ) h(w) = h(w') h ( w ) = h ( w ′ ) .
(2a) Since U = Φ F ( U ) U = \Phi_{F}(U) U = Φ F ( U ) , the elements x = c ( a , f ) x = c(a,f) x = c ( a , f ) and y = c ( a , f ′ ) y = c(a,f') y = c ( a , f ′ ) are in U U U . They have the same shape and the same children, so the set of pairs { ⟨ x , y ⟩ } ∪ { ⟨ z , z ⟩ ∣ z ∈ U } \{\langle x,y\rangle\} \cup\{\langle z,z\rangle\mid z \in U\} {⟨ x , y ⟩} ∪ {⟨ z , z ⟩ ∣ z ∈ U } is included in the interpretation of bis ( R ) \operatorname{bis}(R) bis ( R ) when R R R is valued to it. By the Knaster–Tarski theorem it is included in the interpretation of Bisim \operatorname{Bisim} Bisim , so x = y x = y x = y by (BISIMILARITY), and f = f ′ f = f' f = f ′ by (NO CONFUSION).
(2b) Let z ∈ Z M z \in Z_{M} z ∈ Z M with ζ ( z ) = ( a , β ∘ g ) \zeta(z) = (a,\beta\mathbin{\circ} g) ζ ( z ) = ( a , β ∘ g ) . By Theorem 4.15 , z = β ( x ) z = \beta(x) z = β ( x ) for some x ∈ U x \in U x ∈ U . Let f = x . n x t f = x.\mathit{nxt} f = x . nxt , so γ ( x ) = ( x . o u t , ∣ f ∣ ) \gamma(x) = (x.\mathit{out},\lvert f\rvert) γ ( x ) = ( x . out , ∣ f ∣) . Since β \beta β is a coalgebra morphism, x . o u t = a x.\mathit{out} = a x . out = a and β ∘ ∣ f ∣ = β ∘ g \beta\mathbin{\circ} \lvert f\rvert= \beta\mathbin{\circ} g β ∘ ∣ f ∣ = β ∘ g , so ∣ f ∣ = g \lvert f\rvert= g ∣ f ∣ = g because β \beta β is injective. Moreover f ∈ Fun a ( U ) f \in\operatorname{Fun}_{a}(U) f ∈ Fun a ( U ) .
Remark 4.25. The four kinds of axioms and their roles are summarized below.
Table 4.25.
The last two rows are dual in the usual sense: least versus greatest fixpoint, and constructor versus destructors. The first two rows are not dual: in both columns they state the injectivity and the surjectivity of the isomorphism with the intended structure. The difference is in which form is primitive. For μ F \mu F μ F , the elements are well-founded, so the local axioms suffice and induction yields the global properties (Proposition 4.24 (1)). For ν F \nu F ν F , there is no induction to propagate local properties, and they are too weak: (NO CONFUSION) and (EXT) allow two different bisimilar elements, and (TAB) holds in the model of eventually periodic streams of Remark 4.17. So the global axioms are needed, and they imply the local ones (Proposition 4.24 (2)). This is also why the coalgebra γ \gamma γ is well defined without assuming (EXT).
Relating the two sorts
The theories Γ F μ \Gamma^{\mu}_{F} Γ F μ and Γ F ν \Gamma^{\nu}_{F} Γ F ν use the same constructor, so the two sorts can be compared in the models of Γ F \Gamma_{F} Γ F . Fix a model M M M of the axioms of Γ F \Gamma_{F} Γ F other than (REALISATION), with L = ∣ ⊤ μ F ∣ M L = \lvert\top_{\mu F}\rvert_{M} L = ∣ ⊤ μ F ∣ M and U = ∣ ⊤ ν F ∣ M U = \lvert\top_{\nu F}\rvert_{M} U = ∣ ⊤ ν F ∣ M ; the coalgebra ( U , γ ) (U,\gamma) ( U , γ ) and the morphism β : ( U , γ ) → ( Z M , ζ ) \beta: (U,\gamma) \to(Z_{M},\zeta) β : ( U , γ ) → ( Z M , ζ ) are defined as in Section 4.6, and β \beta β is injective, by the proof of Theorem 4.15 . For x , y ∈ U x,y \in U x , y ∈ U and n ≥ 0 n \ge0 n ≥ 0 , we say that x x x and y y y agree to depth n n n , written x ≡ n y x \equiv_{n} y x ≡ n y , if n = 0 n = 0 n = 0 , or n = m + 1 n = m+1 n = m + 1 , x . o u t = y . o u t x.\mathit{out} = y.\mathit{out} x . out = y . out , and ∣ x . n x t ∣ ( b ) ≡ m ∣ y . n x t ∣ ( b ) \lvert x.\mathit{nxt}\rvert(b) \equiv_{m} \lvert y.\mathit{nxt}\rvert(b) ∣ x . nxt ∣ ( b ) ≡ m ∣ y . nxt ∣ ( b ) for all b ∈ B M [ x . o u t ] b \in B_{M}[x.\mathit{out}] b ∈ B M [ x . out ] ; agreement to depth n n n is defined in the same way on Z M Z_{M} Z M , with ζ \zeta ζ . Let d ( x , y ) = 0 d(x,y) = 0 d ( x , y ) = 0 if x ≡ n y x \equiv_{n} y x ≡ n y for all n n n , and d ( x , y ) = 2 − n d(x,y) = 2^{-n} d ( x , y ) = 2 − n otherwise, where n n n is the greatest number with x ≡ n y x \equiv_{n} y x ≡ n y .
Proposition 4.26. Let M M M be a model of the axioms of Γ F \Gamma_F Γ F other than (REALISATION). Then:
Inclusion. L ⊆ U L \subseteq U L ⊆ U . Moreover, ⊤ μ F ⊆ ⊤ ν F \top_{\mu F} \subseteq\top_{\nu F} ⊤ μ F ⊆ ⊤ ν F , i.e., μ F ≤ ν F \mu F \leq\nu F μ F ≤ ν F , is derivable in the ML proof system from (NO JUNK) and (NO COJUNK).
Well-founded part. L L L is closed under the destructors, β ( L ) \beta(L) β ( L ) is the set of the well-founded trees of Z M Z_M Z M , and L = { x ∈ U ∣ β ( x ) is well-founded } L = \{x \in U \mid\beta(x)\text{ is well-founded}\} L = { x ∈ U ∣ β ( x ) is well-founded } .
Density. d d d is an ultrametric on U U U . If L ≠ ∅ L \ne\varnothing L = ∅ , then L L L is dense in U U U : for every x ∈ U x \in U x ∈ U and every n n n , there is w ∈ L w \in L w ∈ L with x ≡ n w x \equiv_n w x ≡ n w .
Completeness. If L ≠ ∅ L \ne\varnothing L = ∅ , then M M M satisfies (REALISATION) iff the metric space ( U , d ) (U,d) ( U , d ) is complete. So, in a model of Γ F \Gamma_F Γ F with ⊤ μ F \top_{\mu F} ⊤ μ F non-empty, U U U is the Cauchy completion of L L L .
Proof. (1) L L L is the least fixpoint of Φ F \Phi_F Φ F and U U U is a fixpoint of Φ F \Phi_F Φ F . In the proof system, the unfolding of the greatest fixpoint gives φ F ( ν X . φ F ( X ) ) → ν X . φ F ( X ) \varphi_F(\nu X.\,\varphi_F(X)) \to\nu X.\,\varphi_F(X) φ F ( ν X . φ F ( X )) → ν X . φ F ( X ) , the Knaster–Tarski rule [10 ] then gives μ X . φ F ( X ) → ν X . φ F ( X ) \mu X.\,\varphi_F(X) \to\nu X.\,\varphi_F(X) μ X . φ F ( X ) → ν X . φ F ( X ) , and (NO JUNK) and (NO COJUNK) rewrite the two sides as ⊤ μ F \top_{\mu F} ⊤ μ F and ⊤ ν F \top_{\nu F} ⊤ ν F .
(2) If x ∈ L = Φ F ( L ) x \in L = \Phi_F(L) x ∈ L = Φ F ( L ) , then x = c ( a , f ) x = c(a,f) x = c ( a , f ) with a ∈ A M a \in A_M a ∈ A M and f ∈ Fun a ( L ) f \in\operatorname{Fun}_a(L) f ∈ Fun a ( L ) , so x . out = a x.\operatorname{out} = a x . out = a and the values of ∣ x . nxt ∣ = ∣ f ∣ \lvert x.\operatorname{nxt}\rvert= \lvert f\rvert ∣ x . nxt ∣ = ∣ f ∣ are in L L L . Let h : W M → L h \colon W_M \to L h : W M → L be the isomorphism of Theorem 4.4 , and let ι : W M → Z M \iota\colon W_M \to Z_M ι : W M → Z M be the unique coalgebra morphism from ( W M , sup − 1 ) (W_M,\operatorname{sup}^{-1}) ( W M , sup − 1 ) , which is injective and whose image is the set of the well-founded trees. Since h ( sup ( a , t ) ) = c ( a , ⌜ h ∘ t ⌝ a ) h(\operatorname{sup}(a,t)) = c(a,\ulcorner h \circ t\urcorner_a) h ( sup ( a , t )) = c ( a , ┌ h ∘ t ┐ a ) , we have γ ( h ( sup ( a , t ) ) ) = ( a , h ∘ t ) \gamma(h(\operatorname{sup}(a,t))) = (a,h \circ t) γ ( h ( sup ( a , t ))) = ( a , h ∘ t ) , so h h h is a coalgebra morphism from ( W M , sup − 1 ) (W_M,\operatorname{sup}^{-1}) ( W M , sup − 1 ) to ( U , γ ) (U,\gamma) ( U , γ ) , and β ∘ h = ι \beta\circ h = \iota β ∘ h = ι by the finality of Z M Z_M Z M . Hence β ( L ) = ι ( W M ) \beta(L) = \iota(W_M) β ( L ) = ι ( W M ) . If β ( x ) \beta(x) β ( x ) is well-founded, then β ( x ) = ι ( w ) = β ( h ( w ) ) \beta(x) = \iota(w) = \beta(h(w)) β ( x ) = ι ( w ) = β ( h ( w )) for some w w w , and x = h ( w ) ∈ L x = h(w) \in L x = h ( w ) ∈ L , since β \beta β is injective.
(3) Since ≡ n + 1 \equiv_{n+1} ≡ n + 1 is included in ≡ n \equiv_n ≡ n , d ( x , z ) ≤ max ( d ( x , y ) , d ( y , z ) ) d(x,z) \leq\max(d(x,y),d(y,z)) d ( x , z ) ≤ max ( d ( x , y ) , d ( y , z )) . If x ≡ n y x \equiv_n y x ≡ n y for all n n n , then the set of all such pairs ( x , y ) (x,y) ( x , y ) is a bisimulation on ( U , γ ) (U,\gamma) ( U , γ ) : the two elements have the same shape, and their children at each position agree to every depth. So x = y x = y x = y , as in the proof of Theorem 4.15 , by (BISIMILARITY); hence d d d is an ultrametric. Let L ≠ ∅ L \ne\varnothing L = ∅ . We show by induction on n n n that every x ∈ U x \in U x ∈ U agrees to depth n n n with some w ∈ L w \in L w ∈ L . For n = 0 n = 0 n = 0 , take any w ∈ L w \in L w ∈ L . For n + 1 n+1 n + 1 , let x = c ( a , f ) x = c(a,f) x = c ( a , f ) and choose, for each b ∈ B M [ a ] b \in B_M[a] b ∈ B M [ a ] , some w b ∈ L w_b \in L w b ∈ L with ∣ f ∣ ( b ) ≡ n w b \lvert f\rvert(b) \equiv_n w_b ∣ f ∣ ( b ) ≡ n w b . By Lemma 4.3 , the function g : b ↦ w b g \colon b \mapsto w_b g : b ↦ w b has a code ⌜ g ⌝ a ∈ Fun a ( L ) \ulcorner g\urcorner_a \in\operatorname{Fun}_a(L) ┌ g ┐ a ∈ Fun a ( L ) , and w = c ( a , ⌜ g ⌝ a ) ∈ Φ F ( L ) = L w = c(a,\ulcorner g\urcorner_a) \in\Phi_F(L) = L w = c ( a , ┌ g ┐ a ) ∈ Φ F ( L ) = L has w . out = a w.\operatorname{out} = a w . out = a and ∣ w . nxt ∣ = g \lvert w.\operatorname{nxt}\rvert= g ∣ w . nxt ∣ = g , so x ≡ n + 1 w x \equiv_{n+1} w x ≡ n + 1 w .
(4) Since β \beta β is a coalgebra morphism, x ≡ n y x \equiv_n y x ≡ n y iff β ( x ) ≡ n β ( y ) \beta(x) \equiv_n \beta(y) β ( x ) ≡ n β ( y ) , by induction on n n n ; so β \beta β is an isometry. On Z M Z_M Z M , agreement to depth n n n is equality of the images in F M n 1 F_M^n 1 F M n 1 , and Z M Z_M Z M is the limit of the terminal sequence 1 ← F M 1 ← F M 2 1 ← ⋯ 1 \leftarrow F_M1 \leftarrow F_M^2 1 \leftarrow\cdots 1 ← F M 1 ← F M 2 1 ← ⋯ (Appendix § 10 ); so Z M Z_M Z M is complete: a Cauchy sequence determines a compatible family of elements of the F M n 1 F_M^n1 F M n 1 , i.e., an element of the limit. If M M M satisfies (REALISATION), then β \beta β is a bijection (Theorem 4.15 ), hence an isometry onto a complete space, and ( U , d ) (U,d) ( U , d ) is complete. Conversely, let ( U , d ) (U,d) ( U , d ) be complete and z ∈ Z M z \in Z_M z ∈ Z M . As in (3), by induction on n n n , there is w n ∈ L w_n \in L w n ∈ L such that β ( w n ) \beta(w_n) β ( w n ) agrees with z z z to depth n n n : for n + 1 n+1 n + 1 , let w n + 1 = c ( a , ⌜ g ⌝ a ) w_{n+1} = c(a,\ulcorner g\urcorner_a) w n + 1 = c ( a , ┌ g ┐ a ) , where g ( b ) ∈ L g(b) \in L g ( b ) ∈ L is such that β ( g ( b ) ) \beta(g(b)) β ( g ( b )) agrees with t ( b ) t(b) t ( b ) to depth n n n . For m ≥ n m \geq n m ≥ n , β ( w m ) ≡ n β ( w n ) \beta(w_m) \equiv_n \beta(w_n) β ( w m ) ≡ n β ( w n ) , so w m ≡ n w n w_m \equiv_n w_n w m ≡ n w n , and the sequence ( w n ) (w_n) ( w n ) is Cauchy. Its limit x ∈ U x \in U x ∈ U satisfies β ( x ) ≡ n z \beta(x) \equiv_n z β ( x ) ≡ n z for all n n n , so β ( x ) = z \beta(x) = z β ( x ) = z . Hence β \beta β is surjective. For T T T with Tree ( T ) \operatorname{Tree}(T) Tree ( T ) , an element x x x with β ( x ) = T z T \beta(x) =_T z_T β ( x ) = T z T satisfies Beh ( x , T ) \operatorname{Beh}(x,T) Beh ( x , T ) , by Lemma 4.14 (2) and Lemma 4.14 (3), so (REALISATION) holds. The last claim follows from (3). ∎
Remark 4.27. Proposition 4.26 makes precise the idea that, when ⊤ μ F \top_{\mu F} ⊤ μ F is non-empty, its elements approximate those of ⊤ ν F \top_{\nu F} ⊤ ν F , as the finite lists approximate the infinite ones: an infinite list e 0 e 1 e 2 ⋯ e_0e_1e_2\cdots e 0 e 1 e 2 ⋯ is the limit of the finite lists e 0 ⋯ e n − 1 e_0\cdots e_{n-1} e 0 ⋯ e n − 1 . Three points should be noted. First, the hypothesis is sharp: L ≠ ∅ L \ne\varnothing L = ∅ iff some shape has no positions, i.e., B M [ a ] = ∅ B_M[a] = \varnothing B M [ a ] = ∅ for some a ∈ A M a \in A_M a ∈ A M , since Φ F ( ∅ ) \Phi_F(\varnothing) Φ F ( ∅ ) consists of the elements c ( a , i ) c(a,i) c ( a , i ) for these shapes. For the streams and for the Moore machines with a non-empty set of inputs, ⊤ μ F \top_{\mu F} ⊤ μ F is empty and nothing approximates the elements of ⊤ ν F \top_{\nu F} ⊤ ν F . Second, the approximation is metric, not an information order: the finite list e 0 e 1 e_0e_1 e 0 e 1 agrees with the infinite list e 0 e 1 e 2 ⋯ e_0e_1e_2\cdots e 0 e 1 e 2 ⋯ to depth 2, but it is not a partial version of it, since the two differ at depth 3, where one ends and the other continues. An order of approximation would need partial elements, e.g., the functor F + 1 F + 1 F + 1 with an undefined leaf, which the theories do not have. Third, density does not imply (REALISATION): that every behaviour is the limit of elements of τ μ F \tau_{\mu F} τ μ F does not give an element of τ ν F \tau_{\nu F} τ ν F with this behaviour, as the rational approximations of 2 \sqrt{2} 2 do not give a rational number. Proposition B.4 (6) constructs a structure that satisfies all the other axioms, in which τ μ F \tau_{\mu F} τ μ F is non-empty, hence dense, and (REALISATION) fails. By Proposition 4.26 (4), when τ μ F \tau_{\mu F} τ μ F is non-empty, (REALISATION) states exactly that these limits exist. This reading does not replace the axiom: it is not available when τ μ F \tau_{\mu F} τ μ F is empty, where (REALISATION) is still needed, and the inclusion of (1) is derivable, while density and completeness are semantic properties.
Summary of the Guarantees
The results of this section, and of Appendix B, are of different kinds. We distinguish the requirements for defining the matching logic theories, for their satisfiability , and for their adequacy with respect to the intended set-theoretic functor, and we separate semantic results from results derivable in the ML proof system.
Defining the theories The theories Γ F μ \Gamma_F^\mu Γ F μ , Γ F ν \Gamma_F^\nu Γ F ν , and Γ F \Gamma_F Γ F are fixed by Definition 4.1 . They are well-formed ML theories: every fixpoint pattern they use, namely those in (NO JUNK), (NO COJUNK), Bisim , Sub , and the no-junk axiom of List ( P ) \operatorname{List}(P) List ( P ) , has a body positive in its bound variable, as required by Definition 3.1 , and so do the notations μ X : s . φ \mu X:s.\ \varphi μ X : s . φ and ν X : s . φ \nu X:s.\ \varphi ν X : s . φ (§ 3 ). The notations X B [ a ] X^{B[a]} X B [ a ] (§ 4.4 ) and for partially functional symbols are meaningful for empty and nested sorts, and the table following Definition 4.1 shows on which arguments each constructor and destructor application is defined. The sorts μ F \mu F μ F and ν F \nu F ν F are declared by (MU SORT) and (NU SORT), and (NO CONFUSION) and (NO COCONFUSION.3) are derived in Γ F ν \Gamma_F^\nu Γ F ν (Lemma 4.10 ).
Satisfiability Theorem B.2 constructs a model of Γ F \Gamma_F Γ F in which all sorts have their intended interpretation, up to canonical bijections, and Theorem B.6 extends it to several containers and the parameter specifications of Definition 4.20 . So these theories are consistent; Propositions 4.6 and 4.18 are consequences. Since Theorem B.6 holds for every instance of a parametric specification, the theories of the case studies have models for arbitrary parameters (Corollary B.7).
Necessity of the axioms Proposition B.4 constructs, for each of (EXT), (TAB), (BISIMILARITY), and (REALISATION), a structure that satisfies all the other axioms and whose extracted algebra or coalgebra is not initial or final. So none of these axioms follows from the others, and each is needed for the adequacy theorems.
Adequacy The adequacy results are semantic : they are statements about all models of a theory, proved in set theory, not derivations in the ML proof system. They are: Theorems 4.4 and 4.15 (α μ ( M ) \alpha_\mu(M) α μ ( M ) is initial and α ν ( M ) \alpha_\nu(M) α ν ( M ) is final for F M F_M F M , in every model), with Lemmas 4.3 , 4.11, and 4.14 ; Proposition 4.24 ; and Theorem 6.1 . Matching logic with fixpoints has no complete proof system, so these semantic consequences of the axioms, e.g., that bisimilar elements of τ μ F \tau_{\mu F} τ μ F are equal (Proposition 4.24 (1)), need not be derivable.
Derivable proof principles The Induction, Coinduction, and Bisimulation Principles of § 4.5 and § 4.6 are derivable in the ML proof system, from the Knaster–Tarski rule or its dual and the axioms (No Junk), (No Cojunk), and (Bisimilarity); by soundness, they also hold in every model. The derivations are given at the level of proof rules, not as formal proof objects.
Additional assumptions Two kinds of results need assumptions beyond the theories. Finitarity is needed only for Lemma 4.2, for the description of μ F \mu F μ F by the approximations φ F n ( ⊥ ) \varphi_F^n(\bot) φ F n ( ⊥ ) , and for the correspondence with the colimit (Ini). A standard interpretation of the shapes and positions is needed to compare α μ ( M ) \alpha_\mu(M) α μ ( M ) and α ν ( M ) \alpha_\nu(M) α ν ( M ) with μ F \mu F μ F and ν F \nu F ν F themselves, rather than with μ F M \mu F_M μ F M and ν F M \nu F_M ν F M (the corollaries of Theorems 4.4 and 4.15 , and Proposition 4.19 ); Theorem 4.21 gives specifications that ensure it.
Table 1 (PDF p. 26).
Boundary Cases
The following cases test the specifications at their boundaries. In each of them, the theories of Definition 4.1 behave as intended, and the table indicates which axioms and results the case depends on.
Table 2.
Case (e) shows the role of (Realisation) most clearly. For the identity functor F X = X FX = X F X = X (one shape with one position), ν F \nu F ν F has exactly one element, a self-referential x = c o n s ⟨ ⋆ , f ⟩ x = cons\langle\star,f\rangle x = co n s ⟨ ⋆ , f ⟩ , where f f f maps the unique position to x x x itself. (Bisimilarity) makes this element unique, but only (Realisation) makes it exist: the construction of Appendix § 10 without the trees of the M-type, in which c o n s cons co n s always yields fresh terms, satisfies all the other axioms of Γ F \Gamma_F Γ F , and, by the argument on construction stages, the greatest fixpoint of Φ F \Phi_F Φ F is empty there, so ⊤ ν F = ⊥ \top_{\nu F} = \bot ⊤ ν F = ⊥ (Proposition B.4 (4)).
Case Study: Lists Using Container Functors
The set E E E of elements is a parameter: it is represented by a parameter sort E E E , given by (Par) in Definition 4.20 , and the results below hold for the lists over its interpretation E M E_M E M (§ 4.9 ); the sorts 0 0 0 and 1 1 1 are captured by the axioms of Section 4.1, the instances n = 0 n = 0 n = 0 and n = 1 n = 1 n = 1 of (Fin) in Definition 4.20 . First, we express L s t X = 1 + E × X Lst\ X = 1 + E \times X L s t X = 1 + E × X as a unary container functor, using 1 ≅ ∑ ⋆ : 1 X 0 [ ⋆ ] 1 \cong\sum_{\star: 1} X^{0[\star]} 1 ≅ ∑ ⋆ : 1 X 0 [ ⋆ ] , E ≅ ∑ e : E X 0 [ e ] E \cong\sum_{e : E} X^{0[e]} E ≅ ∑ e : E X 0 [ e ] , and X ≅ ∑ ⋆ : 1 X 1 [ ⋆ ] X \cong\sum_{\star: 1} X^{1[\star]} X ≅ ∑ ⋆ : 1 X 1 [ ⋆ ] .
L s t X = ∑ ⋆ : 1 X 0 [ ⋆ ] + ∑ e : E X 0 [ e ] × ∑ ⋆ : 1 X 1 [ ⋆ ] = ∑ ⋆ : 1 X 0 [ ⋆ ] + ∑ ⟨ e , ⋆ ⟩ : E × 1 X 0 [ e ] + 1 [ ⋆ ] = ∑ a : 1 + E × 1 X [ 0 , { 0 , 1 } ] [ a ] \begin{aligned}
Lst\ X &= \sum_{\star: 1} X^{0[\star]} + \sum_{e : E} X^{0[e]} \times\sum_{\star: 1} X^{1[\star]} \\
&= \sum_{\star: 1} X^{0[\star]} + \sum_{\langle e,\star\rangle: E \times1} X^{0[e]+1[\star]} \\
&= \sum_{a : 1+E \times1} X^{[0,\{0,1\}][a]}
\end{aligned} L s t X = ⋆ : 1 ∑ X 0 [ ⋆ ] + e : E ∑ X 0 [ e ] × ⋆ : 1 ∑ X 1 [ ⋆ ] = ⋆ : 1 ∑ X 0 [ ⋆ ] + ⟨ e , ⋆ ⟩ : E × 1 ∑ X 0 [ e ] + 1 [ ⋆ ] = a : 1 + E × 1 ∑ X [ 0 , { 0 , 1 }] [ a ]
Using the isomorphisms E × 1 ≅ E E \times1 \cong E E × 1 ≅ E and { 0 , 1 } [ ⟨ e , ⋆ ⟩ ] = 0 [ e ] + 1 [ ⋆ ] = 0 + 1 ≅ 1 \{0,1\}[\langle e,\star\rangle] = 0[e] + 1[\star] = 0 + 1 \cong1 { 0 , 1 } [⟨ e , ⋆ ⟩] = 0 [ e ] + 1 [ ⋆ ] = 0 + 1 ≅ 1 in the category C \mathcal{C} C , we obtain the reduced form L s t c X = ∑ a : 1 + E X [ 0 , 1 ] [ a ] Lst^c\ X = \sum_{a : 1+E} X^{[0,1][a]} L s t c X = ∑ a : 1 + E X [ 0 , 1 ] [ a ] of the container functor L s t Lst L s t . From the definition of the sum of container functors we deduce that the elements of ∑ a : 1 + E X [ 0 , 1 ] [ a ] \sum_{a : 1+E} X^{[0,1][a]} ∑ a : 1 + E X [ 0 , 1 ] [ a ] are pairs { ⟨ ⋆ , f ⟩ ∣ f : 0 → X } ⊎ { ⟨ e , f ′ ⟩ ∣ e : E , f ′ : 1 → X } \{\langle\star,f\rangle\mid f : 0 \to X\} \uplus\{\langle e,f'\rangle\mid e : E, f' : 1 \to X\} {⟨ ⋆ , f ⟩ ∣ f : 0 → X } ⊎ {⟨ e , f ′ ⟩ ∣ e : E , f ′ : 1 → X } . The only function 0 → X 0 \to X 0 → X is ι \iota ι , and f ′ : 1 → X ≅ f ′ ∈ X f' : 1 \to X \cong f' \in X f ′ : 1 → X ≅ f ′ ∈ X .
The ML specification The lists are specified by a literal instance of the theories of Definition 4.1 , with parameter specifications as in Definition 4.20 :
a sort T a g Tag T a g with constants l , r l,r l , r , given by (Fin); and the sorts 0 0 0 and 1 1 1 of Section 4.1, i.e., (Fin) with n = 0 n = 0 n = 0 and with n = 1 n = 1 n = 1 ;
the shapes A ≡ ∑ i : T a g C [ i ] A \equiv\sum_{i : Tag} C[i] A ≡ ∑ i : T a g C [ i ] , with C [ l ] = 1 C[l] = 1 C [ l ] = 1 and C [ r ] = E C[r] = E C [ r ] = E , so that the shapes are ⟨ l , ⋆ ⟩ \langle l,\star\rangle ⟨ l , ⋆ ⟩ and ⟨ r , e ⟩ \langle r,e\rangle ⟨ r , e ⟩ for e : E e : E e : E ;
the positions, defined by cases on the tag: ∀ x : 1. B [ ⟨ l , x ⟩ ] = 0 \forall x : 1.\ B[\langle l,x\rangle] = 0 ∀ x : 1. B [⟨ l , x ⟩] = 0 and ∀ x : E . B [ ⟨ r , x ⟩ ] = 1 \forall x : E.\ B[\langle r,x\rangle] = 1 ∀ x : E . B [⟨ r , x ⟩] = 1 .
The constructor c o n s cons co n s , the sorts μ L s t c \mu Lst^c μL s t c and ν L s t c \nu Lst^c ν L s t c , the destructors, and their axioms are those of Γ L s t c μ \Gamma_{Lst^c}^{\mu} Γ L s t c μ and Γ L s t c ν \Gamma_{Lst^c}^{\nu} Γ L s t c ν , without change: nothing specific to lists is postulated. The sort E E E is a parameter sort, so the specification is in C p a r \mathcal{C}^{par} C p a r and has a model for every set of elements (Theorem B.6 ); if E E E is given by a specification in C \mathcal{C} C , Theorem 4.21 applies.
Transport along the coding map In this instance, the tail of a non-empty list is not the list element ℓ \ell ℓ itself, but a code of the function from the unique position ⋆ \star ⋆ to ℓ \ell ℓ . The set-theoretic isomorphism X 1 ≅ X X^1 \cong X X 1 ≅ X is transported into the theory by the coding map , the instance B [ a ] = 1 B[a] = 1 B [ a ] = 1 of the codes ⌜ g ⌝ a \ulcorner g\urcorner_a ┌ g ┐ a of § 4.5 , which we define by the notation
κ ( ψ ) ≡ ∃ f . f ∧ f ∈ ⊤ 1 ∧ ∃ x . ( f ⋆ = x ∧ x ∈ ψ ) . \kappa(\psi) \equiv\exists f.\ f \land f \in\top^1 \land\exists x.\ (f \star= x \land x \in\psi). κ ( ψ ) ≡ ∃ f . f ∧ f ∈ ⊤ 1 ∧ ∃ x . ( f ⋆ = x ∧ x ∈ ψ ) .
The value f ⋆ f \star f ⋆ is required to be in ψ \psi ψ , not equal to it: the equality f ⋆ = ψ f \star= \psi f ⋆ = ψ would compare ψ \psi ψ with the singleton f ⋆ f \star f ⋆ , so it would fail whenever ψ \psi ψ denotes a set with several elements, and ψ \psi ψ would occur negatively in it. With membership, ψ \psi ψ occurs only positively, and in a model κ ( ψ ) \kappa(\psi) κ ( ψ ) is matched by the codes on 1 \mathbf{1} 1 whose value at ⋆ \star ⋆ belongs to the interpretation of ψ \psi ψ . For an element ℓ \ell ℓ , x ∈ ℓ x \in\ell x ∈ ℓ means x = ℓ x=\ell x = ℓ , so κ ( ℓ ) \kappa(\ell) κ ( ℓ ) is matched by the codes whose value at ⋆ \star ⋆ is ℓ \ell ℓ ; for a set, κ \kappa κ is the union of its values on the elements of the set. In fact, κ ( ψ ) \kappa(\psi) κ ( ψ ) is the instance ψ I \psi^{I} ψ I of the notation X B [ a ] X^{B[a]} X B [ a ] of Section 4.4: since ⊤ 1 = ⋆ \top_{1}=\star ⊤ 1 = ⋆ is non-empty, both are matched, for every interpretation of ψ \psi ψ , by the elements f f f such that f ⋆ f \star f ⋆ is a singleton included in it and f f f is undefined outside ⊤ 1 \top_{1} ⊤ 1 . The usual constructors and destructors of lists are then notations:
n i l ≡ c o n s ⟨ ⟨ l , ⋆ ⟩ , ∅ ⟩ , c o n s E e ℓ ≡ c o n s ⟨ ⟨ r , e ⟩ , κ ( ℓ ) ⟩ , \mathit{nil} \equiv\mathit{cons}\left\langle\left\langle l,\star\right\rangle,\varnothing\right\rangle,\qquad
\mathit{cons}_{E}\ e\ \ell\equiv\mathit{cons}\left\langle\left\langle r,e\right\rangle,\kappa(\ell)\right\rangle, nil ≡ cons ⟨ ⟨ l , ⋆ ⟩ , ∅ ⟩ , cons E e ℓ ≡ cons ⟨ ⟨ r , e ⟩ , κ ( ℓ ) ⟩ ,
h d x ≡ ∃ e : E . e ∧ x . o u t = ⟨ r , e ⟩ , t l x ≡ ( x . n x t ) ⋆ . \mathit{hd}\ x \equiv\exists e\mathbin{:}E.\ e\land x.\mathit{out}=\left\langle r,e\right\rangle,\qquad
\mathit{tl}\ x \equiv(x.\mathit{nxt})\ \star. hd x ≡ ∃ e : E . e ∧ x . out = ⟨ r , e ⟩ , tl x ≡ ( x . nxt ) ⋆ .
Proposition 5.1. The usual list operations are recovered by transport along κ \kappa κ . Here Γ L s t c μ \Gamma^{\mu}_{\mathit{Lstc}} Γ Lstc μ and Γ L s t c ν \Gamma^{\nu}_{\mathit{Lstc}} Γ Lstc ν include the parameter specification above, and E M E_{M} E M is the interpretation of ⊤ E \top_{E} ⊤ E :
Let M M M be a model of Γ L s t c μ \Gamma^{\mu}_{\mathit{Lstc}} Γ Lstc μ and L = ∣ ⊤ μ L s t c ∣ M L=\lvert\top^{\mu\mathit{Lstc}}\rvert_{M} L = ∣ ⊤ μ Lstc ∣ M . If E M ≠ ∅ E_{M}\ne\varnothing E M = ∅ , then, for every ℓ ∈ L \ell\in L ℓ ∈ L , κ ( ℓ ) \kappa(\ell) κ ( ℓ ) is matched by exactly one element, and κ \kappa κ is a bijection between L L L and the codes on 1 \mathbf{1} 1 with values in L L L . Moreover, for every E M E_{M} E M , the following hold in M M M :
∃ y : μ L s t c . n i l = y ∀ e : E . ∀ ℓ : μ L s t c . ∃ y : μ L s t c . c o n s E e ℓ = y \exists y\mathbin{:}\mu\mathit{Lstc}.\ \mathit{nil}=y\qquad
\forall e\mathbin{:}E.\ \forall\ell\mathbin{:}\mu\mathit{Lstc}.\ \exists y\mathbin{:}\mu\mathit{Lstc}.\ \mathit{cons}_{E}\ e\ \ell=y ∃ y : μ Lstc . nil = y ∀ e : E . ∀ ℓ : μ Lstc . ∃ y : μ Lstc . cons E e ℓ = y ∀ e : E . ∀ ℓ : μ L s t c . n i l ≠ c o n s E e ℓ ∀ e , e ′ : E . ∀ ℓ , ℓ ′ : μ L s t c . c o n s E e ℓ = c o n s E e ′ ℓ ′ ⇒ e = e ′ ∧ ℓ = ℓ ′ \forall e\mathbin{:}E.\ \forall\ell\mathbin{:}\mu\mathit{Lstc}.\ \mathit{nil}\ne\mathit{cons}_{E}\ e\ \ell\qquad
\forall e,e'\mathbin{:}E.\ \forall\ell,\ell'\mathbin{:}\mu\mathit{Lstc}.\ \mathit{cons}_{E}\ e\ \ell=\mathit{cons}_{E}\ e'\ \ell' \Rightarrow e=e'\land\ell=\ell' ∀ e : E . ∀ ℓ : μ Lstc . nil = cons E e ℓ ∀ e , e ′ : E . ∀ ℓ , ℓ ′ : μ Lstc . cons E e ℓ = cons E e ′ ℓ ′ ⇒ e = e ′ ∧ ℓ = ℓ ′ ⊤ μ L s t c = μ X . n i l ∨ c o n s E ⊤ E X \top^{\mu\mathit{Lstc}}=\mu X.\ \mathit{nil}\lor\mathit{cons}_{E}\ \top_{E}\ X ⊤ μ Lstc = μ X . nil ∨ cons E ⊤ E X so ( L , n i l , c o n s E ) (L,\mathit{nil},\mathit{cons}_{E}) ( L , nil , cons E ) is isomorphic to the algebra of finite lists over E M E_{M} E M .
Let M M M be a model of Γ L s t c ν \Gamma^{\nu}_{\mathit{Lstc}} Γ Lstc ν and U = ∣ ⊤ ν L s t c ∣ M U=\lvert\top^{\nu\mathit{Lstc}}\rvert_{M} U = ∣ ⊤ ν Lstc ∣ M . If E M ≠ ∅ E_{M}\ne\varnothing E M = ∅ , then κ \kappa κ is a bijection between U U U and the codes on 1 \mathbf{1} 1 with values in U U U . For every E M E_{M} E M , the statements of (1) hold with ν L s t c \nu\mathit{Lstc} ν Lstc and ν X \nu X ν X in place of μ L s t c \mu\mathit{Lstc} μ Lstc and μ X \mu X μ X , and h d ( c o n s E e ℓ ) = e \mathit{hd}(\mathit{cons}_{E}\ e\ \ell)=e hd ( cons E e ℓ ) = e , t l ( c o n s E e ℓ ) = ℓ \mathit{tl}(\mathit{cons}_{E}\ e\ \ell)=\ell tl ( cons E e ℓ ) = ℓ , h d n i l = ⊥ \mathit{hd}\ \mathit{nil}=\bot hd nil = ⊥ , and t l n i l = ⊥ \mathit{tl}\ \mathit{nil}=\bot tl nil = ⊥ . Hence U U U , with n i l \mathit{nil} nil , c o n s E \mathit{cons}_{E} cons E , and the partial destructors h d \mathit{hd} hd and t l \mathit{tl} tl , is isomorphic to the set E M ∗ ∪ E M ω E_{M}^{*}\cup E_{M}^{\omega} E M ∗ ∪ E M ω of finite and infinite lists (colists) over E M E_{M} E M , with its usual structure.
Proof. (1) Let E M ≠ ∅ E_{M}\ne\varnothing E M = ∅ and e ∈ E M e\in E_{M} e ∈ E M . The shape ⟨ r , e ⟩ \langle r,e\rangle ⟨ r , e ⟩ has the position set { ⋆ } \{\star\} { ⋆ } , so, by Lemma 4.3 for this shape, every function from { ⋆ } \{\star\} { ⋆ } to L L L has exactly one code with values in L L L ; a code matching κ ( ℓ ) \kappa(\ell) κ ( ℓ ) has the single value ℓ ∈ L \ell\in L ℓ ∈ L , so κ ( ℓ ) \kappa(\ell) κ ( ℓ ) is matched by exactly one element, and κ \kappa κ is a bijection onto these codes. If E M = ∅ E_{M}=\varnothing E M = ∅ , there is no shape with the position set { ⋆ } \{\star\} { ⋆ } , so (EXT) and (TAB) say nothing about the codes on { ⋆ } \{\star\} { ⋆ } , and κ ( ℓ ) \kappa(\ell) κ ( ℓ ) may be matched by no element or by several; but then c o n s E \mathit{cons}_{E} cons E is never applied: the statements below that quantify over e : E e\mathbin{:}E e : E hold vacuously, c o n s E ⊤ E X \mathit{cons}_{E}\ \top_{E}\ X cons E ⊤ E X is ⊥ \bot ⊥ , and L = { n i l } L=\{\mathit{nil}\} L = { nil } .
We continue with the statements that hold for every E M E_{M} E M ; where κ ( ℓ ) \kappa(\ell) κ ( ℓ ) is used, E M ≠ ∅ E_{M}\ne\varnothing E M = ∅ . The element n i l \mathit{nil} nil is c ( ⟨ l , ⋆ ⟩ , ∅ ) ∈ Φ F ( L ) = L c(\langle l,\star\rangle,\varnothing)\in\Phi_{F}(L)=L c (⟨ l , ⋆ ⟩ , ∅ ) ∈ Φ F ( L ) = L , and c o n s E e ℓ = c ( ⟨ r , e ⟩ , κ ( ℓ ) ) ∈ Φ F ( L ) = L \mathit{cons}_{E}\ e\ \ell=c(\langle r,e\rangle,\kappa(\ell))\in\Phi_{F}(L)=L cons E e ℓ = c (⟨ r , e ⟩ , κ ( ℓ )) ∈ Φ F ( L ) = L for ℓ ∈ L \ell\in L ℓ ∈ L . The two confusion statements follow from (No Confusion), the injectivity of pairs, l ≠ r l\ne r l = r , and the injectivity of κ \kappa κ . For the last statement, the body n i l ∨ c o n s E ⊤ E X \mathit{nil}\lor\mathit{cons}_{E}\ \top_{E}\ X nil ∨ cons E ⊤ E X is positive in X X X , since X X X occurs only in κ ( X ) \kappa(X) κ ( X ) , under x ∈ X x\in X x ∈ X . Let Ψ \Psi Ψ be its interpretation as a function of X X X . For every S ⊆ M S\subseteq M S ⊆ M , Ψ ( S ) = Φ F ( S ) \Psi(S)=\Phi_{F}(S) Ψ ( S ) = Φ F ( S ) : the shapes are ⟨ l , ⋆ ⟩ \langle l,\star\rangle ⟨ l , ⋆ ⟩ , with B [ ⟨ l , ⋆ ⟩ ] = 0 B[\langle l,\star\rangle]=0 B [⟨ l , ⋆ ⟩] = 0 and S 0 = { i } S^{0}=\{i\} S 0 = { i } , which gives n i l \mathit{nil} nil , and ⟨ r , e ⟩ \langle r,e\rangle ⟨ r , e ⟩ for e ∈ E M e\in E_{M} e ∈ E M , with B [ ⟨ r , e ⟩ ] = 1 B[\langle r,e\rangle]=1 B [⟨ r , e ⟩] = 1 and S 1 = κ ( S ) S^{1}=\kappa(S) S 1 = κ ( S ) , which gives the elements c ( ⟨ r , e ⟩ , f ) c(\langle r,e\rangle,f) c (⟨ r , e ⟩ , f ) with f ∈ κ ( S ) f\in\kappa(S) f ∈ κ ( S ) . Hence μ X . n i l ∨ c o n s E ⊤ E X \mu X.\ \mathit{nil}\lor\mathit{cons}_{E}\ \top_{E}\ X μ X . nil ∨ cons E ⊤ E X and μ X . φ F ( X ) \mu X.\ \varphi_{F}(X) μ X . φ F ( X ) have the same interpretation, which is L L L by (No Junk). The isomorphism with finite lists follows from these no-junk and no-confusion properties, as for term algebras [9 Theorem 44] .
(2) If E M ≠ ∅ E_{M}\ne\varnothing E M = ∅ , then, by Proposition 2.4(2) for a shape ⟨ r , e ⟩ \langle r,e\rangle ⟨ r , e ⟩ , every function from { ⋆ } \{\star\} { ⋆ } to U U U has exactly one code with values in U U U , so κ \kappa κ is a bijection as in (1); if E M = ∅ E_{M}=\varnothing E M = ∅ , then U = { n i l } U=\{\mathit{nil}\} U = { nil } as in (1). In both cases, the first statements follow as in (1), with Φ F ( U ) = U \Phi_{F}(U)=U Φ F ( U ) = U . For the fixpoint, Ψ = Φ F \Psi=\Phi_{F} Ψ = Φ F as in (1), so ν X . n i l ∨ c o n s E ⊤ E X \nu X.\ \mathit{nil}\lor\mathit{cons}_{E}\ \top_{E}\ X ν X . nil ∨ cons E ⊤ E X and ν X . φ F ( X ) \nu X.\ \varphi_{F}(X) ν X . φ F ( X ) have the same interpretation, which is U U U by (No CoJunk). Finally, by the confusion axioms, ( c o n s E e ℓ ) . o u t = ⟨ r , e ⟩ (\mathit{cons}_{E}\ e\ \ell).\mathit{out}=\langle r,e\rangle ( cons E e ℓ ) . out = ⟨ r , e ⟩ and ( c o n s E e ℓ ) . n x t = κ ( ℓ ) (\mathit{cons}_{E}\ e\ \ell).\mathit{nxt}=\kappa(\ell) ( cons E e ℓ ) . nxt = κ ( ℓ ) , whose value at ⋆ \star ⋆ is ℓ \ell ℓ ; and n i l . o u t = ⟨ l , ⋆ ⟩ ≠ ⟨ r , e ⟩ nil.out = \langle l,\star\rangle\ne\langle r,e\rangle ni l . o u t = ⟨ l , ⋆ ⟩ = ⟨ r , e ⟩ and n i l . n x t = ι nil.nxt = \mathord{\iota} ni l . n x t = ι , with ι ⋆ = ⊥ \mathord{\iota}\mathbin{\star} = \perp ι ⋆ =⊥ . For the last claim, L s t M c X ≅ 1 + E M × X \mathrm{Lst}_{M}^{c}X \cong1+E_{M}\times X Lst M c X ≅ 1 + E M × X naturally: the shape ⟨ l , ⋆ ⟩ \langle l,\star\rangle ⟨ l , ⋆ ⟩ has no positions, and a shape ⟨ r , e ⟩ \langle r,e\rangle ⟨ r , e ⟩ has one position, whose labels are transported along κ \kappa κ . By Theorem 4.15 , α ν ( M ) \alpha_{\nu}(M) α ν ( M ) is a final L s t M c \mathrm{Lst}_{M}^{c} Lst M c -coalgebra, hence isomorphic to the final coalgebra of X ↦ 1 + E M × X X \mapsto1+E_{M}\times X X ↦ 1 + E M × X , which is E M ω ∪ E M ∗ E_{M}^{\omega}\cup E_{M}^{*} E M ω ∪ E M ∗ with the empty list observed as n i l nil ni l and a non-empty list observed by its head and its tail; under this isomorphism, h d hd h d and t l tl tl are the usual partial head and tail.
Thus the usual specifications of lists and of possibly infinite lists, with n i l nil ni l , c o n s E cons_{E} co n s E , and the partial destructors h d hd h d and t l tl tl , as in [8 ] , are recovered as properties of every model of the generic theories, rather than postulated. More generally, any isomorphism of container functors, such as X 1 ≅ X X^{1}\cong X X 1 ≅ X here, is transported along the coding bijections in the same way; this also justifies working with the simplified container M c \mathcal{M}^{c} M c in Section 6.
Case Study: Moore Machines
Here we consider an example of a (constant) exponent functor. Moore machines (automata) have the signature given by the functor M X = O × X I \mathcal{M}\,X=O\times X^{I} M X = O × X I , where O O O is the set of outputs and I I I the set of inputs (see Example 2.5 ). Both are parameters, represented by parameter sorts given by (Par) in Definition 4.20, and the family of positions is the constant family of (Fam), so the theory below has a model for all sets O O O and I I I (Theorem B.6 ); for deterministic automata, O = { 0 , 1 } O=\{0,1\} O = { 0 , 1 } can be captured by the axioms for finite sets, rule (Fin) of Definition 4.20 (Section 4.7).
We express M \mathcal{M} M as a unary container functor, using O ≅ ∑ o : O X 0 [ o ] O\cong\sum_{o:O}X^{0[o]} O ≅ ∑ o : O X 0 [ o ] , X ≅ ∑ ⋆ : 1 X 1 [ ⋆ ] X\cong\sum_{\star:1}X^{1[\star]} X ≅ ∑ ⋆ : 1 X 1 [ ⋆ ] , and the exponent and product constructions of Section 2.1:
M X = O × X I ≅ ∑ o : O X 0 [ o ] × ( ∑ ⋆ : 1 X 1 [ ⋆ ] ) I ≅ ∑ o : O X 0 [ o ] × ∑ g : I → 1 X ∑ i : I 1 [ g i ] ≅ ∑ ⟨ o , g ⟩ : O × ( I → 1 ) X 0 [ o ] + ∑ i : I 1 [ g i ] ≅ ∑ o : O X I = M c X \begin{aligned}
\mathcal{M}\,X &= O\times X^{I}\\
&\cong\sum_{o:O}X^{0[o]}\times\left(\sum_{\star:1}X^{1[\star]}\right)^{I}\\
&\cong\sum_{o:O}X^{0[o]}\times\sum_{g:I\to1}X^{\sum_{i:I}1[g\,i]}\\
&\cong\sum_{\langle o,g\rangle:O\times(I\to1)}X^{0[o]+\sum_{i:I}1[g\,i]}\\
&\cong\sum_{o:O}X^{I}=\mathcal{M}^{c}\,X
\end{aligned} M X = O × X I ≅ o : O ∑ X 0 [ o ] × ( ⋆ : 1 ∑ X 1 [ ⋆ ] ) I ≅ o : O ∑ X 0 [ o ] × g : I → 1 ∑ X ∑ i : I 1 [ g i ] ≅ ⟨ o , g ⟩ : O × ( I → 1 ) ∑ X 0 [ o ] + ∑ i : I 1 [ g i ] ≅ o : O ∑ X I = M c X
where the last step uses I → 1 ≅ 1 I\to1\cong1 I → 1 ≅ 1 and 0 + ∑ i : I 1 ≅ I 0+\sum_{i:I}1\cong I 0 + ∑ i : I 1 ≅ I . So M c \mathcal{M}^{c} M c is the container with shapes O O O and the constant family of positions o : O ⊢ I o:O\vdash I o : O ⊢ I : the shape of a state is its output, and its children are its successors, one for each input.
Capturing the Final M \mathcal{M} M -Coalgebra in ML
The instantiation of the ML specification of Section 4.6, with A = O A=O A = O and the constant family B [ o ] = I B[o]=I B [ o ] = I , is a literal instance of Definition 4.1, and is as follows, where ⊤ I \top^{I} ⊤ I is the pattern X [ ⊤ / X ] X[\top/X] X [ ⊤/ X ] :
∀ o : O . ∀ f . f ∈ ⊤ I → ∃ x . c o n s ⟨ o , f ⟩ = x \forall o:O.\ \forall f.\ f\in\top^{I}\to\exists x.\ cons\langle o,f\rangle=x ∀ o : O . ∀ f . f ∈ ⊤ I → ∃ x . co n s ⟨ o , f ⟩ = x (FUNCTIONAL)
the sort ν M c \nu\mathcal{M}^{c} ν M c with final semantics:
ν M c : Sort \nu\mathcal{M}^{c}:\operatorname{Sort} ν M c : Sort (NU SORT)
T ν M c = ν X . ∃ o : O . cons ⟨ o , X I ⟩ \mathsf{T}_{\nu\mathcal{M}^{c}}=\nu X.\ \exists o:O.\ \operatorname{cons}\langle o,X^{I}\rangle T ν M c = ν X . ∃ o : O . cons ⟨ o , X I ⟩ (NO COJUNK)
the destructors out , nxt ∈ Σ \operatorname{out},\operatorname{nxt}\in\Sigma out , nxt ∈ Σ , specified by the axioms:
∀ o : O . ∀ f . f ∈ T I ⇒ ( cons ⟨ o , f ⟩ ) . out = o \forall o:O.\ \forall f.\ f\in\mathsf{T}^{I}\Rightarrow(\operatorname{cons}\langle o,f\rangle).\operatorname{out}=o ∀ o : O . ∀ f . f ∈ T I ⇒ ( cons ⟨ o , f ⟩) . out = o (NO COCONFUSION.1)
∀ o : O . ∀ f . f ∈ T I ⇒ ( cons ⟨ o , f ⟩ ) . nxt = f \forall o:O.\ \forall f.\ f\in\mathsf{T}^{I}\Rightarrow(\operatorname{cons}\langle o,f\rangle).\operatorname{nxt}=f ∀ o : O . ∀ f . f ∈ T I ⇒ ( cons ⟨ o , f ⟩) . nxt = f (NO COCONFUSION.2)
the bisimilarity, which is here the usual bisimilarity of Moore machines: two states are related when they have the same output and their successors under each input are related,
bis ( R ) ≡ ∃ x , y : ν M c . ⟨ x , y ⟩ ∈ R ∧ x . out = y . out ∧ ∀ i : I . ∃ u , v . ( x . nxt ) i = u ∧ ( y . nxt ) i = v ∧ ⟨ u , v ⟩ ∈ R \operatorname{bis}(R)\equiv\exists x,y:\nu\mathcal{M}^{c}.\ \langle x,y\rangle\in R\land x.\operatorname{out}=y.\operatorname{out}\land\forall i:I.\ \exists u,v.\ (x.\operatorname{nxt})\,i=u\land(y.\operatorname{nxt})\,i=v\land\langle u,v\rangle\in R bis ( R ) ≡ ∃ x , y : ν M c . ⟨ x , y ⟩ ∈ R ∧ x . out = y . out ∧ ∀ i : I . ∃ u , v . ( x . nxt ) i = u ∧ ( y . nxt ) i = v ∧ ⟨ u , v ⟩ ∈ R
∀ x , y : ν M c . ⟨ x , y ⟩ ∈ ν R . bis ( R ) ⇒ x = y \forall x,y:\nu\mathcal{M}^{c}.\ \langle x,y\rangle\in\nu R.\operatorname{bis}(R)\Rightarrow x=y ∀ x , y : ν M c . ⟨ x , y ⟩ ∈ ν R . bis ( R ) ⇒ x = y (BISIMILARITY)
the axiom (REALISATION) of Section 4.6, with paths given by lists over P = ∑ o : O I P=\sum_{o:O}I P = ∑ o : O I , i.e., over the pairs ⟨ o , i ⟩ \langle o,i\rangle ⟨ o , i ⟩ of an output and an input.
By Lemma 4.10, (NO CONFUSION) and (NO COCONFUSION.3), ∀ x : ν M c . cons ⟨ x . out , x . nxt ⟩ = x \forall x:\nu\mathcal{M}^{c}.\ \operatorname{cons}\langle x.\operatorname{out},x.\operatorname{nxt}\rangle=x ∀ x : ν M c . cons ⟨ x . out , x . nxt ⟩ = x , hold in every model. For each n n n , the pattern φ M n ( T ) \varphi_{\mathcal{M}}^{n}(\mathsf{T}) φ M n ( T ) , where φ M ( X ) ≡ ∃ o : O . cons ⟨ o , X I ⟩ \varphi_{\mathcal{M}}(X)\equiv\exists o:O.\ \operatorname{cons}\langle o,X^{I}\rangle φ M ( X ) ≡ ∃ o : O . cons ⟨ o , X I ⟩ , is matched by the states that can be unfolded n n n times: they have an output, all their successors have an output, and so on, up to input words of length n − 1 n-1 n − 1 . By Lemma 4.11, T ν M c \mathsf{T}_{\nu\mathcal{M}^{c}} T ν M c is matched by the states that can be unfolded indefinitely. If I I I is non-empty, every shape has positions, so μ M c \mu\mathcal{M}^{c} μ M c is empty (Remark 4.7): there are no finite Moore machine behaviours. If I I I is empty, M X ≅ O \mathcal{M}X\cong O M X ≅ O , and both μ M c \mu\mathcal{M}^{c} μ M c and ν M c \nu\mathcal{M}^{c} ν M c are O O O .
The Behaviour of a State
Let M M M be a model of the theory above, U = ∣ T ν M c ∣ M U=\lvert\mathsf{T}_{\nu\mathcal{M}^{c}}\rvert_{M} U = ∣ T ν M c ∣ M , and let O M O_{M} O M and I M I_{M} I M be the interpretations of the sorts O O O and I I I . For x ∈ U x\in U x ∈ U and i ∈ I M i\in I_{M} i ∈ I M , we write δ ( x , i ) \delta(x,i) δ ( x , i ) for the successor ∣ x . nxt ∣ ( i ) ∈ U \lvert x.\operatorname{nxt}\rvert(i)\in U ∣ x . nxt ∣ ( i ) ∈ U . We extend it to input words w ∈ I M ∗ w\in I_{M}^{*} w ∈ I M ∗ by δ ∗ ( x , ε ) = x \delta^{*}(x,\varepsilon)=x δ ∗ ( x , ε ) = x and δ ∗ ( x , i ⋅ w ) = δ ∗ ( δ ( x , i ) , w ) \delta^{*}(x,i\mathbin{\cdot}w)=\delta^{*}(\delta(x,i),w) δ ∗ ( x , i ⋅ w ) = δ ∗ ( δ ( x , i ) , w ) , and define the behaviour of x x x as the function
obs ( x ) : I M ∗ → O M , obs ( x ) ( w ) = δ ∗ ( x , w ) . out . \operatorname{obs}(x):I_{M}^{*}\to O_{M},\qquad\operatorname{obs}(x)(w)=\delta^{*}(x,w).\operatorname{out}. obs ( x ) : I M ∗ → O M , obs ( x ) ( w ) = δ ∗ ( x , w ) . out .
Theorem 6.1. For every model M M M of the theory above, obs : U → O M I M ∗ \operatorname{obs}:U\to O_{M}^{I_{M}^{*}} obs : U → O M I M ∗ is a bijection, and it is an isomorphism between the coalgebra α ν ( M ) = ( U , γ ) \alpha_{\nu}(M)=(U,\gamma) α ν ( M ) = ( U , γ ) and the final M \mathcal{M} M -coalgebra ( out ‾ , tr ‾ ) : O M I M ∗ → O M × ( O M I M ∗ ) I M (\overline{\operatorname{out}},\overline{\operatorname{tr}}):O_{M}^{I_{M}^{*}}\to O_{M}\times(O_{M}^{I_{M}^{*}})^{I_{M}} ( out , tr ) : O M I M ∗ → O M × ( O M I M ∗ ) I M of Example 2.5. In particular, for x ∈ U x\in U x ∈ U and f ∈ O M I M ∗ f\in O_{M}^{I_{M}^{*}} f ∈ O M I M ∗ ,
obs ( x ) = f iff x . out = f ( ε ) and obs ( δ ( x , i ) ) = tr ‾ ( f ) ( i ) for all i ∈ I M . \operatorname{obs}(x)=f\quad\text{iff}\quad x.\operatorname{out}=f(\varepsilon)\text{ and }\operatorname{obs}(\delta(x,i))=\overline{\operatorname{tr}}(f)(i)\text{ for all }i\in I_{M}. obs ( x ) = f iff x . out = f ( ε ) and obs ( δ ( x , i )) = tr ( f ) ( i ) for all i ∈ I M .
Proof. obs \operatorname{obs} obs is a coalgebra morphism: out ‾ ( obs ( x ) ) = obs ( x ) ( ε ) = x . out \overline{\operatorname{out}}(\operatorname{obs}(x))=\operatorname{obs}(x)(\varepsilon)=x.\operatorname{out} out ( obs ( x )) = obs ( x ) ( ε ) = x . out , and, for i ∈ I M i\in I_{M} i ∈ I M and w ∈ I M ∗ w\in I_{M}^{*} w ∈ I M ∗ ,
tr ‾ ( obs ( x ) ) ( i ) ( w ) = obs ( x ) ( i ⋅ w ) = δ ∗ ( δ ( x , i ) , w ) . out = obs ( δ ( x , i ) ) ( w ) . \overline{\operatorname{tr}}(\operatorname{obs}(x))(i)(w)=\operatorname{obs}(x)(i\mathbin{\cdot}w)=\delta^{*}(\delta(x,i),w).\operatorname{out}=\operatorname{obs}(\delta(x,i))(w). tr ( obs ( x )) ( i ) ( w ) = obs ( x ) ( i ⋅ w ) = δ ∗ ( δ ( x , i ) , w ) . out = obs ( δ ( x , i )) ( w ) .
Since γ ( x ) = ( x . out , ∣ x . nxt ∣ ) \gamma(x)=(x.\operatorname{out},\lvert x.\operatorname{nxt}\rvert) γ ( x ) = ( x . out , ∣ x . nxt ∣) , these two equations say exactly that ( out ‾ , tr ‾ ) ∘ obs = M obs ∘ γ (\overline{\operatorname{out}},\overline{\operatorname{tr}})\circ\operatorname{obs}=\mathcal{M}\operatorname{obs}\circ\gamma ( out , tr ) ∘ obs = M obs ∘ γ . By Theorem 4.15, ( U , γ ) (U,\gamma) ( U , γ ) is a final M c \mathcal{M}^{c} M c -coalgebra, hence a final M \mathcal{M} M -coalgebra up to the isomorphism M ≅ M c \mathcal{M}\cong\mathcal{M}^{c} M ≅ M c , and ( out ‾ , tr ‾ ) (\overline{\operatorname{out}},\overline{\operatorname{tr}}) ( out , tr ) is a final M \mathcal{M} M -coalgebra [18 ] . A coalgebra morphism between final coalgebras is the unique isomorphism between them, so obs \operatorname{obs} obs is a bijection. The last claim is the morphism property, read as a characterization: obs ( x ) \operatorname{obs}(x) obs ( x ) is determined by its value at ε \varepsilon ε and by the functions tr ‾ ( obs ( x ) ) ( i ) \overline{\operatorname{tr}}(\operatorname{obs}(x))(i) tr ( obs ( x )) ( i ) . □ \square □
For O = { 0 , 1 } O=\{0,1\} O = { 0 , 1 } , Moore machines are deterministic automata, obs ( x ) \operatorname{obs}(x) obs ( x ) is (the characteristic function of) the language accepted from the state x x x , and Theorem 6.1 says that every model contains exactly one state for each language over I M I_{M} I M . In this case, the Bisimulation Principle of Section 4.6 is the usual coinductive proof method for language equivalence: to show that two states are equal, it is enough to exhibit a relation that relates them, preserves outputs, and is closed under successors.
Conclusion
The results reported in this paper show that both the initial models and the final models of polynomial functors (in the container sense) can be fully captured in matching logic (ML), using their representation as unary container functors, in the precise sense of § 1 , which comprises semantic adequacy for all models and the derivability of the induction, coinduction, and bisimulation principles, and not of other principles such as iteration: for every model M M M of the corresponding theory, the algebra α μ ( M ) \alpha_\mu(M) α μ ( M ) is an initial algebra (Theorem 4.4 ) and the coalgebra α ν ( M ) \alpha_\nu(M) α ν ( M ) is a final coalgebra (Theorem 4.15 ) of the container functor extracted from M M M , i.e., the one given by the interpretation in M M M of the shapes and positions. So the data types are captured relative to the parameter sorts of shapes and positions, and absolutely whenever these sorts are themselves captured (Proposition 4.19 ); Theorem 4.21 shows that this is the case for finite sets, products, dependent sums, and (co)inductive sorts built from them. Moreover, the induction, coinduction, and bisimulation principles are derivable in the ML proof system. § 5.1 separates the requirements for defining these theories, for their satisfiability, and for their adequacy, and distinguishes the semantic results from the derivable ones. Besides the axioms of the constructor, of the fixpoints, and of the destructors, the theories of Definition 4.1 use only the base theory Γ 0 \Gamma_0 Γ 0 , i.e., EQUALITY, SORT, PAIR with (Pair Total), the specification of ↓ \mathord{\downarrow} ↓ , and the indexed family a : A ⊢ B [ a ] a\colon A \vdash B[a] a : A ⊢ B [ a ] , together with the dependent sum P P P of positions and the lists List ( P ) \operatorname{List}(P) List ( P ) for final coalgebras; functions are represented directly by the notation X B [ a ] X^{B[a]} X B [ a ] , and finite sums by dependent sums over finite sorts of tags. The general specifications of sum sorts and function sorts [8 ] are not used, and dependent products are not specified.
Two features of ML are essential. Fixpoint patterns express (NO JUNK) and (NO COJUNK), and free set variables allow the existence axioms (TAB) and (REALISATION) to speak about every subset of a model; without them, the theories have non-standard models (Remarks 4.7 and 4.17). The comparison of the two theories (Proposition 4.24 ) also clarifies the duality between them: the fixpoint axioms and the (co)confusion axioms are dual, while the remaining axioms play the same role in both theories, in a local form for initial algebras, where induction propagates them, and in a global form for final coalgebras, where it does not.
A classical polynomial functor can be translated into a container functor, because container functors are closed under sum, product, and exponentiation by a constant object (§ 2.1 ). The result may be cumbersome, because the construction starts from the constant and identity functors, so it is preferable to simplify it using isomorphisms in the category of sets, as we did for lists and Moore machines.
These results can help in defining in ML programming languages that use both inductive and coinductive data types, and in a better understanding of the abstract constructions of category theory. A possible use is as follows:
define in a front-end a suitable syntax for data types intended to be defined as initial algebras or final coalgebras;
extract the canonical container form of the functor underlying the front-end definition;
generate the corresponding ML theory;
derive the proof principles needed to soundly handle the defined data type.
Future work will focus on the following aspects of the proposed approach:
formal proof objects for the derived principles;
the iteration and primitive recursion principles, and their duals for final coalgebras [12 ] , which are not covered by the notion of capture used here; for term algebras, the iteration principle is derived in ML in [9 ] ;
extending the approach to larger classes of functors admitting initial algebras and final coalgebras, e.g., indexed containers [3 ] , the bounded natural functors (BNFs) underlying Isabelle/HOL’s datatypes [20 ] , or the quotients of polynomial functors, experimentally implemented in Lean [5 ] .
AI disclosure Parts of the manuscript were prepared with the support of Claude Fable. All AI-generated suggestions were carefully reviewed and edited by the author to ensure scientific accuracy and compliance with academic standards. The author takes full responsibility for the content of the publication.
The Pair Sort in ML
We recall from [8 ] the ML specification of pair sorts, with the adaptations described below. The specification of sum sorts is not recalled: a finite sum of sorts is represented as a dependent sum ∑ i : T a g C [ i ] \sum_{i:\mathit{TagC}[i]} ∑ i : TagC [ i ] over a finite sort of tags (Definitions 4.1 and 4.20 ). The specification PAIR states (Pair Inj) for all elements, not only for elements of sorts, and adds (Pair Total), which makes pairing defined on all elements. (Pair Total) is needed because the constructor cons is applied to pairs ⟨ a , f ⟩ \langle a,f\rangle ⟨ a , f ⟩ whose second component represents a function and belongs to no sort; the unrelativized (Pair Inj) is needed for dependent pairs ⟨ a , b ⟩ \langle a,b\rangle ⟨ a , b ⟩ , whose second components b : B [ a ] b:B[a] b : B [ a ] need not belong to a common sort. The specification of function sorts is not recalled either: the theories represent functions by the notation X B [ a ] X^{B[a]} X B [ a ] of § 4.4 . Of the specifications of sort operators of [8 ] , only PAIR is part of the theories F Γ \mathcal{F}_{\Gamma} F Γ , F F \mathcal{F}_{F} F F , and F F V \mathcal{F}_{F}^{V} F F V of Definition 4.1.
spec PAIR_{s_1,s_2} Imports: SORT
Symbols: Pair,pair,fst,snd
Notations: s_1 ⊗ s_2 ≡ Pair s_1 s_2, ⟨φ_1,φ_2⟩ ≡ pair φ_1 φ_2
Axioms: // all axioms are quantified by “∀s_1,s_2:Sort”
(Pair Sort) (s_1 ⊗ s_2):Sort
(Pair) ∀x_1:s_1. ∀x_2:s_2. ⟨x_1,x_2⟩:(s_1 ⊗ s_2)
(Pair Fst) ∀x_1:s_1. ∀x_2:s_2. fst ⟨x_1,x_2⟩ = x_1
(Pair Snd) ∀x_1:s_1. ∀x_2:s_2. snd ⟨x_1,x_2⟩ = x_2
(Pair Inj) ∀x_1,x_2,y_1,y_2. ⟨x_1,x_2⟩ = ⟨y_1,y_2⟩ → x_1=y_1 ∧ x_2=y_2
(not relativized to sorts)
(Pair Domain) T_{s_1⊗s_2} = ⟨T_{s_1},T_{s_2}⟩
(Pair Total) ∀x. ∀y. ∃z. ⟨x,y⟩ = z (not relativized to sorts)
endspec
A Standard Model
In this appendix we construct, for a container functor X ↦ F X = ∑ a : A X B [ a ] X \mapsto F X = \sum_{a:A} X^{B[a]} X ↦ F X = ∑ a : A X B [ a ] , one model of the theories of Section 4 in which T μ F T_{\mu F} T μ F is the W-type and T ν F T_{\nu F} T ν F is the M-type of a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] . This proves Propositions 4.6 and 4.18.
The theory Recall (Definition 4.1 ) that Γ F \Gamma_F Γ F is the union of EQUALITY, SORT, PAIR (Appendix § 9 ), the specification of ι \iota ι (Section 4.1), the indexed family a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] , the theory of the initial algebra (§ 4.5 ), and the theory of the final coalgebra, including the dependent sum P ≡ ∑ a : A B [ a ] P \equiv\sum_{a:A} B[a] P ≡ ∑ a : A B [ a ] and L i s t ( P ) List(P) L i s t ( P ) (§ 4.6 ). The model below also interprets 1 1 1 , ⋆ \star ⋆ , and ! ! ! , which are used by the parameter specifications and the examples, and satisfies (NO CONFUSION) and (NO COCONFUSION.3), which are consequences of Γ F \Gamma_F Γ F (Lemma 4.10 ).
Disjoint representatives The construction needs the shapes and the positions to be distinct from each other and from the objects it builds, which is not the case for arbitrary sets: for the identity functor, A = B [ ⋆ ] = { ⋆ } A = B[\star] = \{\star\} A = B [ ⋆ ] = { ⋆ } , and a position set may itself contain ordered pairs. We therefore use tagged copies. Let A # = { s h } × A A^{\#} = \{\mathrm{sh}\} \times A A # = { sh } × A and, for a ∈ A a \in A a ∈ A , B # [ ( s h , a ) ] = { p o s } × B [ a ] B^{\#}[(\mathrm{sh},a)] = \{\mathrm{pos}\} \times B[a] B # [( sh , a )] = { pos } × B [ a ] , whose elements are taken as fresh atoms, distinct from all the other objects below. The tagging bijections ι A : A → A # \iota_A : A \to A^{\#} ι A : A → A # and ι B , a : B [ a ] → B # [ ι A ( a ) ] \iota_{B,a} : B[a] \to B^{\#}[\iota_A(a)] ι B , a : B [ a ] → B # [ ι A ( a )] form an isomorphism between the containers a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] and a : A # ⊢ B # [ a ] a:A^{\#} \vdash B^{\#}[a] a : A # ⊢ B # [ a ] , hence a natural isomorphism between the corresponding functors, and isomorphisms between their W-types and between their M-types. Positions are tagged by their role only, not by their shape, so equality and inclusion between position sets are preserved: shapes with the same position set still share their codes, and nested position sets remain nested. We carry out the construction for a : A # ⊢ B # [ a ] a:A^{\#} \vdash B^{\#}[a] a : A # ⊢ B # [ a ] and, to keep the notation light, we write A A A and B [ a ] B[a] B [ a ] for A # A^{\#} A # and B # [ a ] B^{\#}[a] B # [ a ] in the rest of this appendix, except in the statement of Theorem B.2 .
Trees Let ζ : Z → F Z \zeta: Z \to FZ ζ : Z → F Z be the final F F F -coalgebra, whose elements are the possibly infinite trees with nodes labelled by shapes a ∈ A a \in A a ∈ A and with branching B [ a ] B[a] B [ a ] ; by Lambek’s lemma, ζ \zeta ζ is a bijection. Let W Z ⊆ Z W_Z \subseteq Z W Z ⊆ Z be the set of well-founded trees. By well-founded recursion, the W-type of a : A ⊢ B [ a ] a:A \vdash B[a] a : A ⊢ B [ a ] is isomorphic to W Z W_Z W Z with the algebra structure ζ − 1 \zeta^{-1} ζ − 1 restricted to F W Z F W_Z F W Z ; equivalently, W Z W_Z W Z is the least set S ⊆ Z S \subseteq Z S ⊆ Z with ζ − 1 ( a , g ) ∈ S \zeta^{-1}(a,g) \in S ζ − 1 ( a , g ) ∈ S for all a ∈ A a \in A a ∈ A and g : B [ a ] → S g : B[a] \to S g : B [ a ] → S .
External and internal finality The final coalgebra ( Z , ζ ) (Z,\zeta) ( Z , ζ ) exists in ZFC, e.g., as the limit of the terminal sequence 1 ← F 1 ← F 2 1 ← ⋯ 1 \leftarrow F1 \leftarrow F^2 1 \leftarrow\cdots 1 ← F 1 ← F 2 1 ← ⋯ , since container functors preserve connected limits, in particular limits of ω o p \omega^{\mathrm{op}} ω op -chains. The construction below uses the finality of ( Z , ζ ) (Z,\zeta) ( Z , ζ ) and the description of W Z W_Z W Z as a least fixpoint only externally , as set-theoretic facts used to check that M M M satisfies the axioms, in particular (NO JUNK), (NO COJUNK), and (BISIMILARITY). The internal characterization, i.e., that the algebra α μ ( M ) \alpha_{\mu}(M) α μ ( M ) extracted from M M M is initial and the coalgebra α ν ( M ) \alpha_{\nu}(M) α ν ( M ) is final, is not assumed: once M M M is shown to be a model, it follows from the axioms by Theorems 4.4 and 4.15.
Tagging convention All objects of the construction are tagged with their kind, so that objects of different kinds are distinct: a symbol atom is ( s y m , σ ) (\mathrm{sym},\sigma) ( sym , σ ) , a sort name is ( s r t , n ) (\mathrm{srt},n) ( srt , n ) , a shape and a position are ( s h , a ) (\mathrm{sh},a) ( sh , a ) and ( p o s , b ) (\mathrm{pos},b) ( pos , b ) as above, a tree is ( t r e e , z ) (\mathrm{tree},z) ( tree , z ) , a pair is ( p a i r , x , y ) (\mathrm{pair},x,y) ( pair , x , y ) , a sequence is ( s e q , x 1 , … , x n ) (\mathrm{seq},x_1,\ldots,x_n) ( seq , x 1 , … , x n ) , a partial application is ( p a r t , σ , x ) (\mathrm{part},\sigma,x) ( part , σ , x ) , a code is ( c o d e , graph ( g ) ) (\mathrm{code},\operatorname{graph}(g)) ( code , graph ( g )) , and a fresh term is ( s u p , a , f ) (\mathrm{sup},a,f) ( sup , a , f ) ; the element ⋆ \star ⋆ is ( s t a r ) (\mathrm{star}) ( star ) . Objects of the same kind are equal iff their components are equal, and every constructed object differs from its components. These objects are defined set-theoretically, independently of the stages below, which only determine which of them belong to M M M ; we keep the usual notation, e.g., ⟨ x , y ⟩ \langle x,y\rangle ⟨ x , y ⟩ for (pair,x , y x,y x , y ) and z z z for (tree,z z z ). The tagged copies A # A^{\#} A # and B ˉ # [ a ] \bar{B}^{\#}[a] B ˉ # [ a ] are an instance of this convention. In the combined construction below, the trees of Z j Z_j Z j and the fresh terms of G j G_j G j are tagged with treej _j j and supj _j j , and the constants of (Fin) with fin.
The carrier The atoms are the following pairwise distinct objects, which are also distinct from all objects constructed below: an atom σ ^ \hat{\sigma} σ ^ for each symbol σ \sigma σ of Γ F \Gamma_F Γ F ; the elements of A A A and of B ˉ = ⋃ a ∈ A B [ a ] \bar{B}=\bigcup_{a\in A}B[a] B ˉ = ⋃ a ∈ A B [ a ] ; the element ⋆ \star ⋆ ; the trees of Z Z Z ; and the sort names , i.e., the elements of the least set N N N that contains S r t \mathrm{Srt} Srt , 1 1 1 , A A A , B a B_a B a for a ∈ A a\in A a ∈ A , P P P , L P \mathrm{LP} LP , m u \mathrm{mu} mu , and n u \mathrm{nu} nu , and contains s ⊗ s ′ s\otimes s' s ⊗ s ′ for all s , s ′ ∈ N s,s'\in N s , s ′ ∈ N . Fix a regular cardinal θ > ℵ 0 \theta>\aleph_0 θ > ℵ 0 with ∣ B [ a ] ∣ < θ |B[a]|<\theta ∣ B [ a ] ∣ < θ for all a ∈ A a\in A a ∈ A . Let M 0 M_0 M 0 be the set of atoms. For an ordinal ξ < θ \xi<\theta ξ < θ , let M ξ + 1 M_{\xi+1} M ξ + 1 be M ξ M_\xi M ξ together with the following new objects:
(C1) the pairs ⟨ x , y ⟩ \langle x,y\rangle ⟨ x , y ⟩ , for x , y ∈ M ξ x,y\in M_\xi x , y ∈ M ξ ;
(C2) the finite sequences ( x 1 , … , x n ) (x_1,\ldots,x_n) ( x 1 , … , x n ) , n ≥ 0 n\geq0 n ≥ 0 , of elements of M ξ M_\xi M ξ ;
(C3) the partial applications σ x \sigma_x σ x , for σ ∈ { p a i r , p c o n s , P a i r , d e p O f , D e p S u m } \sigma\in\{\mathit{pair},\mathit{pcons},\mathit{Pair},\mathit{depOf},\mathit{DepSum}\} σ ∈ { pair , pcons , Pair , depOf , DepSum } and x ∈ M ξ x\in M_\xi x ∈ M ξ ;
(C4) the codes ⌜ g ⌝ \ulcorner g\urcorner ┌ g ┐ , for a ∈ A a\in A a ∈ A with B [ a ] ≠ ∅ B[a]\ne\varnothing B [ a ] = ∅ and g : B [ a ] → M ξ g:B[a]\to M_\xi g : B [ a ] → M ξ ; a code is determined by the graph of g g g , so shapes with the same position set share their codes;
(C5) the fresh terms s u p ( a , f ) \mathit{sup}(a,f) sup ( a , f ) , for a ∈ A a\in A a ∈ A and f ∈ M ξ f\in M_\xi f ∈ M ξ .
At limit ordinals we take unions, and we let M = ⋃ ξ < θ M ξ M=\bigcup_{\xi<\theta}M_\xi M = ⋃ ξ < θ M ξ . The stage of x ∈ M x\in M x ∈ M is the least ξ \xi ξ with x ∈ M ξ x\in M_\xi x ∈ M ξ . Since θ \theta θ is regular and ∣ B [ a ] ∣ < θ |B[a]|<\theta ∣ B [ a ] ∣ < θ , every function g : B [ a ] → M g:B[a]\to M g : B [ a ] → M has its values in some M ξ M_\xi M ξ , so ⌜ g ⌝ ∈ M \ulcorner g\urcorner\in M ┌ g ┐ ∈ M ; similarly, M M M is closed under (C1)–(C3) and (C5).
The interpretation Each symbol σ \sigma σ is interpreted as { σ ^ } \{\hat{\sigma}\} { σ ^ } , except the sort symbols, which are interpreted as their sort names (S o r t \mathit{Sort} Sort as { S r t } \{\mathrm{Srt}\} { Srt } , 1 1 1 as { 1 } \{1\} { 1 } , A A A as { A } \{A\} { A } , μ F \mu_F μ F as { m u } \{\mathrm{mu}\} { mu } , ν F \nu_F ν F as { n u } \{\mathrm{nu}\} { nu } ), s t a r \mathit{star} star , which is interpreted as { ⋆ } \{\star\} { ⋆ } , and p n i l \mathit{pnil} pnil , which is interpreted as { ( ) } \{()\} {( )} . For a ∈ A a\in A a ∈ A , let F u n a ( M ) \mathit{Fun}_a(M) Fun a ( M ) be defined as in Section 4.5: { ı ^ } \{\hat{\imath}\} { ^ } if B [ a ] = ∅ B[a]=\varnothing B [ a ] = ∅ , and otherwise the set of f ∈ M f\in M f ∈ M such that f ∙ b f\mathbin{\bullet}b f ∙ b is a singleton for b ∈ B [ a ] b\in B[a] b ∈ B [ a ] and f ∙ b = ∅ f\mathbin{\bullet}b=\varnothing f ∙ b = ∅ for b ∉ B [ a ] b\notin B[a] b ∈ / B [ a ] . Application is ∅ \varnothing ∅ except in the following cases:
p a i r ^ ∙ x = { p a i r x } \hat{\mathit{pair}}\mathbin{\bullet}x=\{\mathit{pair}_x\} pair ^ ∙ x = { pair x } , p a i r x ∙ y = { ⟨ x , y ⟩ } \mathit{pair}_x\mathbin{\bullet}y=\{\langle x,y\rangle\} pair x ∙ y = {⟨ x , y ⟩} , f s t ^ ∙ ⟨ x , y ⟩ = { x } \hat{\mathit{fst}}\mathbin{\bullet}\langle x,y\rangle=\{x\} fst ^ ∙ ⟨ x , y ⟩ = { x } , s n d ^ ∙ ⟨ x , y ⟩ = { y } \hat{\mathit{snd}}\mathbin{\bullet}\langle x,y\rangle=\{y\} snd ^ ∙ ⟨ x , y ⟩ = { y } ;
P a i r ^ ∙ s = { P a i r s s } \hat{\mathit{Pair}}\mathbin{\bullet}s=\{\mathit{Pairs}_s\} Pair ^ ∙ s = { Pairs s } and P a i r s s ∙ s ′ = { s ⊗ s ′ } \mathit{Pairs}_{s}\mathbin{\bullet}s'=\{s\otimes s'\} Pairs s ∙ s ′ = { s ⊗ s ′ } , for s , s ′ ∈ N s,s'\in N s , s ′ ∈ N ;
d e p O f ^ ∙ B ^ = { d e p O f B ^ } \hat{\mathit{depOf}}\mathbin{\bullet}\hat{B}=\{\mathit{depOf}_{\hat{B}}\} depOf ^ ∙ B ^ = { depOf B ^ } and d e p O f B ^ ∙ a = { B a } \mathit{depOf}_{\hat{B}}\mathbin{\bullet}a=\{B_a\} depOf B ^ ∙ a = { B a } , for a ∈ A a\in A a ∈ A ; D e p S u m ^ ∙ A = { D e p S u m A } \widehat{\mathit{DepSum}}\mathbin{\bullet}A=\{\mathit{DepSum}_A\} DepSum ∙ A = { DepSum A } and D e p S u m A ∙ B ^ = { P } \mathit{DepSum}_A\mathbin{\bullet}\hat{B}=\{P\} DepSum A ∙ B ^ = { P } ;
L i s t ^ ∙ P = { L P } \widehat{\mathit{List}}\mathbin{\bullet}P=\{\mathit{LP}\} List ∙ P = { LP } ; p c o n s ^ ∙ q = { p c o n s q } \widehat{\mathit{pcons}}\mathbin{\bullet}q=\{\mathit{pcons}_q\} pcons ∙ q = { pcons q } and p c o n s q ∙ ( x 1 , … , x n ) = { ( q , x 1 , … , x n ) } \mathit{pcons}_q\mathbin{\bullet}(x_1,\ldots,x_n)=\{(q,x_1,\ldots,x_n)\} pcons q ∙ ( x 1 , … , x n ) = {( q , x 1 , … , x n )} ;
for a ∈ A a\in A a ∈ A and f ∈ F u n a ( M ) f\in\mathit{Fun}_a(M) f ∈ Fun a ( M ) : c o n s ^ ∙ ⟨ a , f ⟩ = { ζ − 1 ( a , ∣ f ∣ ) } \widehat{\mathit{cons}}\mathbin{\bullet}\langle a,f\rangle=\{\zeta^{-1}(a,|f|)\} cons ∙ ⟨ a , f ⟩ = { ζ − 1 ( a , ∣ f ∣ )} if all values of ∣ f ∣ |f| ∣ f ∣ are trees, and c o n s ^ ∙ ⟨ a , f ⟩ = { s u p ( a , f ) } \widehat{\mathit{cons}}\mathbin{\bullet}\langle a,f\rangle=\{\mathit{sup}(a,f)\} cons ∙ ⟨ a , f ⟩ = { sup ( a , f )} otherwise;
for z ∈ Z z\in Z z ∈ Z with ζ ( z ) = ( a , g ) \zeta(z)=(a,g) ζ ( z ) = ( a , g ) : o u t ^ ∙ z = { a } \widehat{\mathit{out}}\mathbin{\bullet}z=\{a\} out ∙ z = { a } , and n x t ^ ∙ z = { ⌜ g ⌝ } \widehat{\mathit{nxt}}\mathbin{\bullet}z=\{\ulcorner g\urcorner\} nxt ∙ z = { ┌ g ┐ } if B [ a ] ≠ ∅ B[a]\ne\varnothing B [ a ] = ∅ , { ı ^ } \{\hat{\imath}\} { ^ } otherwise; o u t ^ ∙ s u p ( a , f ) = { a } \widehat{\mathit{out}}\mathbin{\bullet}\mathit{sup}(a,f)=\{a\} out ∙ sup ( a , f ) = { a } and n x t ^ ∙ s u p ( a , f ) = { f } \widehat{\mathit{nxt}}\mathbin{\bullet}\mathit{sup}(a,f)=\{f\} nxt ∙ sup ( a , f ) = { f } .
The case of c o n s ^ \widehat{\mathrm{cons}} cons is well defined: whether f ∈ Fun a ( M ) f \in\operatorname{Fun}_{a}(M) f ∈ Fun a ( M ) depends on the applications f ∙ b f \mathbin{\bullet} b f ∙ b , and c o n s ^ \widehat{\mathrm{cons}} cons itself is not in Fun a ( M ) \operatorname{Fun}_{a}(M) Fun a ( M ) , since c o n s ^ ∙ b = ∅ \widehat{\mathrm{cons}} \mathbin{\bullet} b = \varnothing cons ∙ b = ∅ for the atoms b ∈ B [ a ] b \in B[a] b ∈ B [ a ] . The inhabitants of the sort names are: T ( S r t ) = N \mathsf{T}(\mathsf{Srt}) = N T ( Srt ) = N , T ( 1 ) = { ⋆ } \mathsf{T}(1) = \{\star\} T ( 1 ) = { ⋆ } , T ( A ) = A \mathsf{T}(A) = A T ( A ) = A , T ( B a ) = B [ a ] \mathsf{T}(B_a) = B[a] T ( B a ) = B [ a ] , T ( P ) = { ⟨ a , b ⟩ ∣ a ∈ A , b ∈ B [ a ] } \mathsf{T}(P) = \{\langle a,b\rangle\mid a \in A,b \in B[a]\} T ( P ) = {⟨ a , b ⟩ ∣ a ∈ A , b ∈ B [ a ]} , T ( L P ) \mathsf{T}(\mathsf{LP}) T ( LP ) the set of finite sequences of elements of T ( P ) \mathsf{T}(P) T ( P ) , T ( s ⊗ s ′ ) = { ⟨ x , y ⟩ ∣ x ∈ T ( s ) , y ∈ T ( s ′ ) } \mathsf{T}(s \otimes s') = \{\langle x,y\rangle\mid x \in\mathsf{T}(s),y \in\mathsf{T}(s')\} T ( s ⊗ s ′ ) = {⟨ x , y ⟩ ∣ x ∈ T ( s ) , y ∈ T ( s ′ )} , T ( m u ) = W Z \mathsf{T}(\mathsf{mu}) = W_Z T ( mu ) = W Z , and T ( n u ) = Z \mathsf{T}(\mathsf{nu}) = Z T ( nu ) = Z .
Lemma B.1. Let a ∈ A a \in A a ∈ A with B [ a ] ≠ ∅ B[a] \ne\varnothing B [ a ] = ∅ , and let S ⊆ M S \subseteq M S ⊆ M consist of trees and fresh terms. Then f ∈ Fun a ( S ) f \in\operatorname{Fun}_{a}(S) f ∈ Fun a ( S ) iff f f f is a code ⌜ g ⌝ \ulcorner g\urcorner ┌ g ┐ with g : B [ a ] → S g \colon B[a] \to S g : B [ a ] → S .
Proof. Codes on B [ a ] B[a] B [ a ] with values in S S S are clearly in Fun a ( S ) \operatorname{Fun}_{a}(S) Fun a ( S ) . Conversely, let f ∈ Fun a ( S ) f \in\operatorname{Fun}_{a}(S) f ∈ Fun a ( S ) and b ∈ B [ a ] b \in B[a] b ∈ B [ a ] , so f ∙ b = { s } f \mathbin{\bullet} b = \{s\} f ∙ b = { s } with s s s a tree or a fresh term. By the definition of application, the only elements whose application to an atom of B ‾ \overline{B} B can return a tree or a fresh term are the codes: c o n s ^ \widehat{\mathrm{cons}} cons , f s t \mathit{fst} fst , and s n d \mathit{snd} snd return non-empty sets only on pairs, o u t ^ \widehat{\mathit{out}} out and n x t ^ \widehat{\mathit{nxt}} nxt only on trees and fresh terms, d e f ^ \widehat{\mathit{def}} def returns M M M , which is not a singleton, and the other cases return elements that are neither trees nor fresh terms (positions are atoms, distinct from sort names, shapes, pairs, and sequences). So f = ⌜ g ⌝ f = \ulcorner g\urcorner f = ┌ g ┐ for some g : B [ a ′ ] → M g \colon B[a'] \to M g : B [ a ′ ] → M , and strictness forces B [ a ′ ] = B [ a ] B[a'] = B[a] B [ a ′ ] = B [ a ] : an element of B [ a ] ∖ B [ a ′ ] B[a] \setminus B[a'] B [ a ] ∖ B [ a ′ ] would have an empty application, and an element of B [ a ′ ] ∖ B [ a ] B[a'] \setminus B[a] B [ a ′ ] ∖ B [ a ] a non-empty one.
Theorem B.2. M M M is a model of Γ F \Gamma_F Γ F in which A M = A ♯ A_M = A^{\sharp} A M = A ♯ and B M [ ι A ( a ) ] = B ♯ [ ι A ( a ) ] B_M[\iota_A(a)] = B^{\sharp}[\iota_A(a)] B M [ ι A ( a )] = B ♯ [ ι A ( a )] for a ∈ A a \in A a ∈ A , which are in bijection with A A A and B [ a ] B[a] B [ a ] via ι A \iota_A ι A and ι B , a \iota_{B,a} ι B , a ; τ μ F \tau_{\mu F} τ μ F is interpreted as W Z W_Z W Z , τ ν F \tau_{\nu F} τ ν F as Z Z Z , and c o n s \mathit{cons} cons acts on them as ζ − 1 \zeta^{-1} ζ − 1 . Hence, by Theorems 4.4 and 4.15 (or directly from this interpretation), α μ ( M ) \alpha_{\mu}(M) α μ ( M ) and α ν ( M ) \alpha_{\nu}(M) α ν ( M ) are an initial algebra and a final coalgebra, isomorphic to the W W W -type and to the M M M -type of a : A ⊢ B [ a ] a \colon A \vdash B[a] a : A ⊢ B [ a ] .
Proof. We check the axioms by groups. Patterns are interpreted pointwise, so it suffices to check them on elements.
Equality, sorts, pairs, 1 1 1 , ι \mathord{\iota} ι , ! \mathord{!} ! , the indexed family, and the dependent sum. (Definedness) holds because d e f ^ ∙ x = M \widehat{\mathit{def}} \mathbin{\bullet} x = M def ∙ x = M . Sort denotes the element S r t ∈ N = T ( S r t ) \mathsf{Srt} \in N = \mathsf{T}(\mathsf{Srt}) Srt ∈ N = T ( Srt ) . For s , s ′ ∈ N s,s' \in N s , s ′ ∈ N , s ⊗ s ′ ∈ N s \otimes s' \in N s ⊗ s ′ ∈ N , and the axioms of PAIR hold because pairs are injective and T ( s ⊗ s ′ ) \mathsf{T}(s \otimes s') T ( s ⊗ s ′ ) is the set of pairs of inhabitants; (Pair Total) holds because ⟨ x , y ⟩ ∈ M \langle x,y\rangle\in M ⟨ x , y ⟩ ∈ M for all x , y ∈ M x,y \in M x , y ∈ M . The axioms of Section 4 for ⋆ \star ⋆ , 1 1 1 , ι \mathord{\iota} ι , and ! ! ! hold by definition. A A A denotes A ∈ N A \in N A ∈ N , B [ a ] B[a] B [ a ] denotes B a ∈ N B_a \in N B a ∈ N for a ∈ A a \in A a ∈ A , and P P P denotes P ∈ N P \in N P ∈ N , with T ( P ) \mathsf{T}(P) T ( P ) the set of dependent pairs. μ F \mu F μ F and ν F \nu F ν F denote m u , n u ∈ N \mathsf{mu},\mathsf{nu} \in N mu , nu ∈ N , so (MU SORT) and (NU SORT) hold.
Constructor. By Lemma B.1, the elements of Fun a ( M ) \operatorname{Fun}_{a}(M) Fun a ( M ) whose values are all trees are the codes on B [ a ] B[a] B [ a ] (or ι ^ \widehat{\mathord{\iota}} ι , if B [ a ] = ∅ B[a] = \varnothing B [ a ] = ∅ ). (FUNCTIONAL) holds by the definition of c o n s ^ \widehat{\mathrm{cons}} cons . For (NO CONFUSION), let c ( a , f ) = c ( a ′ , f ′ ) c(a,f) = c(a',f') c ( a , f ) = c ( a ′ , f ′ ) . If this element is a tree z z z , then ζ ( z ) = ( a , ∣ f ∣ ) = ( a ′ , ∣ f ′ ∣ ) \zeta(z) = (a,|f|) = (a',|f'|) ζ ( z ) = ( a , ∣ f ∣ ) = ( a ′ , ∣ f ′ ∣ ) , so a = a ′ a = a' a = a ′ , and f f f and f ′ f' f ′ are codes on B [ a ] B[a] B [ a ] with the same graph, so f = f ′ f = f' f = f ′ . Otherwise it is a fresh term, and fresh terms are injective in ( a , f ) (a,f) ( a , f ) .
Initial algebra. For S ⊆ Z S \subseteq Z S ⊆ Z , Lemma B.1 and the closure of M M M under codes give Φ F ( S ) = { ζ − 1 ( a , g ) ∣ a ∈ A , g : B [ a ] → S } ⊆ Z \Phi_F(S) = \{\zeta^{-1}(a,g) \mid a \in A,\ g \colon B[a] \to S\} \subseteq Z Φ F ( S ) = { ζ − 1 ( a , g ) ∣ a ∈ A , g : B [ a ] → S } ⊆ Z . The least fixedpoint of Φ F \Phi_F Φ F is the union of the transfinite iteration of Φ F \Phi_F Φ F from ∅ \varnothing ∅ , which stays in Z Z Z ; so it is the least S ⊆ Z S \subseteq Z S ⊆ Z closed under ζ − 1 \zeta^{-1} ζ − 1 , i.e., W Z W_Z W Z , and (NO JUNK) holds. By Lemma B.1, Fun a ( W Z ) \operatorname{Fun}_{a}(W_Z) Fun a ( W Z ) is the set of codes on B [ a ] B[a] B [ a ] with values in W Z W_Z W Z , and every function B [ a ] → W Z B[a] \to W_Z B [ a ] → W Z has exactly one code. This gives (EXT), and (TAB): if R R R satisfies the premise of (TAB), the code of the function that maps b b b to the unique x x x with ⟨ b , x ⟩ ∈ R \langle b,x\rangle\in R ⟨ b , x ⟩ ∈ R satisfies the conclusion.
Final coalgebra. Every tree z z z with ζ ( z ) = ( a , g ) \zeta(z) = (a,g) ζ ( z ) = ( a , g ) is c ( a , f ) c(a,f) c ( a , f ) , where f f f is the code of g g g (or ι ^ \widehat{\mathord{\iota}} ι ), so Z ⊆ Φ F ( Z ) Z \subseteq\Phi_F(Z) Z ⊆ Φ F ( Z ) and Z ⊆ U = gfp ( Φ F ) Z \subseteq U = \operatorname{gfp}(\Phi_F) Z ⊆ U = gfp ( Φ F ) . Conversely, U ⊆ Φ F ( U ) U \subseteq\Phi_F(U) U ⊆ Φ F ( U ) , so every element of U U U is a tree or a fresh term. If sup ( a , f ) ∈ U \operatorname{sup}(a,f) \in U sup ( a , f ) ∈ U , then f ∈ Fun a ( U ) f \in\operatorname{Fun}_{a}(U) f ∈ Fun a ( U ) , so f f f is a code by Lemma B.1, and, since c o n s ^ ⟨ a , f ⟩ \widehat{\mathrm{cons}}\langle a,f\rangle cons ⟨ a , f ⟩ is not a tree, some value of f f f is a fresh term in U U U of a smaller stage. Iterating, we would get an infinite decreasing sequence of ordinals, which is impossible. Hence U = Z U = Z U = Z , and (NO COJUNK) holds. The cofusion axioms hold by the definitions of o u t ^ \widehat{\mathit{out}} out and n x t ^ \widehat{\mathit{nxt}} nxt , using that codes on B [ a ] B[a] B [ a ] are determined by their graphs.
For (BISIMILARITY), let R R R be a set of pairs with R ⊆ ∣ b i s ( R ) ∣ R \subseteq\lvert bis(R)\rvert R ⊆ ∣ bi s ( R )∣ ; it relates trees with the same shape whose children at each position are related by R R R , so it is a bisimulation on ( Z , ζ ) (Z,\zeta) ( Z , ζ ) . Since ( Z , ζ ) (Z,\zeta) ( Z , ζ ) is final, related trees are equal (both projections of a bisimulation are coalgebra morphisms into Z Z Z ). The interpretation of B i s i m Bisim B i s im is the union of all such R R R , so (BISIMILARITY) holds.
Lists and realisation. L i s t ( P ) List(P) L i s t ( P ) denotes L P ∈ N L_P \in\mathbb{N} L P ∈ N , so (LIST SORT) holds, and ⊤ ( L P ) \top(L_P) ⊤ ( L P ) is the set of finite sequences over ⊤ ( P ) \top(P) ⊤ ( P ) , with p n i l pnil p ni l the empty sequence and p c o n s pcons p co n s the prepending of an element; the axioms of L i s t ( P ) List(P) L i s t ( P ) hold, and the least fixpoint in its (NO JUNK) axiom is exactly this set. Let T ⊆ M T \subseteq M T ⊆ M satisfy T r e e ( T ) Tree(T) T r ee ( T ) . The other axioms of Γ F V \Gamma_F^V Γ F V hold, as shown above, and β \beta β is the identity of Z Z Z ; so, by Lemma 4.14(2) and (3), the tree z T z_T z T satisfies B e h ( z T , T ) Beh(z_T,T) B e h ( z T , T ) , and (REALISATION) holds.
Finally, A M = ⊤ ( A ) = A # A_M = \top(A) = A^\# A M = ⊤ ( A ) = A # and B M [ a ] = ⊤ ( B a ) = B # [ a ] B_M[a] = \top(B_a) = B^\#[a] B M [ a ] = ⊤ ( B a ) = B # [ a ] , which are in bijection with the original sets via the tagging bijections, and, on W Z W_Z W Z and Z Z Z , c o n s cons co n s acts as ζ − 1 \zeta^{-1} ζ − 1 and ( o u t , n x t ) (out,nxt) ( o u t , n x t ) as ζ \zeta ζ , up to replacing children functions by their codes.
Variants of the Standard Model
The following variants of the construction give models in which one axiom fails; they show that (EXT), (TAB), (BISIMILARITY), and (REALISATION) are needed for the adequacy theorems. A seed is a set Z ′ Z' Z ′ of atoms, tagged as trees, with an injective map ζ ′ : Z ′ → F Z ′ \zeta': Z' \to FZ' ζ ′ : Z ′ → F Z ′ . For a seed and m ∈ { 0 , 1 , 2 } m \in\{0,1,2\} m ∈ { 0 , 1 , 2 } , the structure M ( Z ′ , ζ ′ , m ) M(Z',\zeta',m) M ( Z ′ , ζ ′ , m ) is defined as M M M above, with the following changes:
the tree atoms are the elements of Z ′ Z' Z ′ instead of those of Z Z Z ;
(C4) adds m m m copies ⌈ g 0 ⌉ , … , ⌈ g m − 1 ⌉ \lceil g^0\rceil,\ldots,\lceil g^{m-1}\rceil ⌈ g 0 ⌉ , … , ⌈ g m − 1 ⌉ of each code, tagged with their index, with ⌈ g i ⌉ ∙ b = { g ( b ) } \lceil g^i\rceil\mathbin{\bullet} b = \{g(b)\} ⌈ g i ⌉ ∙ b = { g ( b )} for all copies;
for a ∈ A a \in A a ∈ A and f ∈ F u n a ( M ) f \in Fun_a(M) f ∈ F u n a ( M ) , c o n s ^ ∙ ⟨ a , f ⟩ = { z } \widehat{cons} \mathbin{\bullet} \langle a,f\rangle= \{z\} co n s ∙ ⟨ a , f ⟩ = { z } if ζ ′ ( z ) = ( a , ∣ f ∣ ) \zeta'(z) = (a,\lvert f\rvert) ζ ′ ( z ) = ( a , ∣ f ∣) for some z ∈ Z ′ z \in Z' z ∈ Z ′ , and { s u p ( a , f ) } \{sup(a,f)\} { s u p ( a , f )} otherwise;
for z ∈ Z ′ z \in Z' z ∈ Z ′ with ζ ′ ( z ) = ( a , g ) \zeta'(z) = (a,g) ζ ′ ( z ) = ( a , g ) , o u t ^ ∙ z = { a } \widehat{out} \mathbin{\bullet} z = \{a\} o u t ∙ z = { a } and n x t ^ ∙ z = { ⌈ g 0 ⌉ } \widehat{nxt} \mathbin{\bullet} z = \{\lceil g^0\rceil\} n x t ∙ z = {⌈ g 0 ⌉} if B [ a ] ≠ ∅ B[a] \ne\varnothing B [ a ] = ∅ , { ı ^ } \{\hat{\imath}\} { ^ } otherwise (for m = 0 m=0 m = 0 we only use Z ′ = ∅ Z'=\varnothing Z ′ = ∅ );
⊤ ( m u ) = lfp ( Φ F ) \top(\mathop{\mathrm{mu}}) = \operatorname{lfp}(\Phi_F) ⊤ ( mu ) = lfp ( Φ F ) and ⊤ ( n u ) = gfp ( Φ F ) \top(\mathop{\mathrm{nu}}) = \operatorname{gfp}(\Phi_F) ⊤ ( nu ) = gfp ( Φ F ) , where Φ F ( S ) = { c ( a , f ) ∣ a ∈ A , f ∈ F u n a ( S ) } \Phi_F(S) = \{c(a,f) \mid a \in A,\ f \in Fun_a(S)\} Φ F ( S ) = { c ( a , f ) ∣ a ∈ A , f ∈ F u n a ( S )} is determined by the application alone.
The standard model is M ( Z , ζ , 1 ) M(Z,\zeta,1) M ( Z , ζ , 1 ) .
Lemma B.3. Let M ′ = M ( Z ′ , ζ ′ , m ) M' = M(Z',\zeta',m) M ′ = M ( Z ′ , ζ ′ , m ) .
M ′ M' M ′ satisfies Γ 0 \Gamma_0 Γ 0 , the axioms of the dependent sum P P P and of L i s t ( P ) List(P) L i s t ( P ) , and the axioms (MU SORT), (NU SORT), (FUNCTIONAL), (NO JUNK), and (NO COJUNK). For a ∈ A a \in A a ∈ A with B [ a ] ≠ ∅ B[a] \ne\varnothing B [ a ] = ∅ and a set S S S of tree atoms and fresh terms, F u n a ( S ) Fun_a(S) F u n a ( S ) is the set of the codes, of any copy, of the functions g : B [ a ] → S g : B[a] \to S g : B [ a ] → S .
If m ≤ 1 m \le1 m ≤ 1 or Z ′ = ∅ Z' = \varnothing Z ′ = ∅ , then M ′ M' M ′ satisfies (NO CONFUSION) and (NO COCONFUSION.1–2).
If m = 1 m = 1 m = 1 , then M ′ M' M ′ satisfies (EXT) and (TAB).
If m = 1 m = 1 m = 1 and ζ ′ \zeta' ζ ′ is a bijection, then gfp ( Φ F ) = Z ′ \operatorname{gfp}(\Phi_F) = Z' gfp ( Φ F ) = Z ′ .
Proof. (1) The axioms of Γ 0 \Gamma_0 Γ 0 , of P P P , and of L i s t ( P ) List(P) L i s t ( P ) are checked as in the proof of Theorem B.2; c o n s ^ ∙ ⟨ a , f ⟩ \widehat{cons}\bullet\langle a,f\rangle co n s ∙ ⟨ a , f ⟩ is a singleton for a ∈ A a \in A a ∈ A and f ∈ F u n a ( M ) f \in Fun_a(M) f ∈ F u n a ( M ) ; (NO JUNK) and (NO COJUNK) hold by the definition of ⊤ \top ⊤ on mu and nu. The description of F u n a ( S ) Fun_a(S) F u n a ( S ) is proved as Lemma B.1, whose proof does not depend on the number of copies of the codes or on the set of tree atoms. (2) Let c ( a , f ) = c ( a ′ , f ′ ) c(a,f)=c(a',f') c ( a , f ) = c ( a ′ , f ′ ) . If it is a fresh term, then ( a , f ) = ( a ′ , f ′ ) (a,f)=(a',f') ( a , f ) = ( a ′ , f ′ ) . If it is z ∈ Z ′ z\in Z' z ∈ Z ′ , then ζ ′ ( z ) = ( a , ∣ f ∣ ) = ( a ′ , ∣ f ′ ∣ ) \zeta'(z)=(a,\lvert f\rvert)=(a',\lvert f'\rvert) ζ ′ ( z ) = ( a , ∣ f ∣) = ( a ′ , ∣ f ′ ∣) , so a = a ′ a=a' a = a ′ and ∣ f ∣ = ∣ f ′ ∣ \lvert f\rvert=\lvert f'\rvert ∣ f ∣ = ∣ f ′ ∣ ; by (1), f f f and f ′ f' f ′ are codes of the same function (or both are ı ^ \hat{\imath} ^ ), and f = f ′ f=f' f = f ′ since m ≤ 1 m\le1 m ≤ 1 . For Z ′ = ∅ Z'=\varnothing Z ′ = ∅ , only the first case occurs. The coconfusion axioms hold by the definitions of o u t ^ \widehat{out} o u t and n x t ^ \widehat{nxt} n x t : on a fresh term they return a a a and f f f , and on z = c ( a , f ) ∈ Z ′ z=c(a,f)\in Z' z = c ( a , f ) ∈ Z ′ they return a a a and the code ⌈ ∣ f ∣ ⌉ 0 \lceil\lvert f\rvert\rceil^0 ⌈∣ f ∣ ⌉ 0 , which is f f f by (1), since m ≤ 1 m\le1 m ≤ 1 . (3) Every element of lfp ( Φ F ) \operatorname{lfp}(\Phi_F) lfp ( Φ F ) is a value of c o n s ^ \widehat{cons} co n s , i.e., a tree atom or a fresh term; by (1), F u n a ( lfp ( Φ F ) ) Fun_a(\operatorname{lfp}(\Phi_F)) F u n a ( lfp ( Φ F )) is the set of the codes of the functions from B [ a ] B[a] B [ a ] to lfp ( Φ F ) \operatorname{lfp}(\Phi_F) lfp ( Φ F ) , and each function has exactly one code. (4) If ζ ′ ( z ) = ( a , g ) \zeta'(z)=(a,g) ζ ′ ( z ) = ( a , g ) , then z = c ( a , f ) z=c(a,f) z = c ( a , f ) , where f f f is the code of g g g (or ı ^ \hat{\imath} ^ ), so Z ′ ⊆ Φ F ( Z ′ ) Z'\subseteq\Phi_F(Z') Z ′ ⊆ Φ F ( Z ′ ) and Z ′ ⊆ gfp ( Φ F ) Z'\subseteq\operatorname{gfp}(\Phi_F) Z ′ ⊆ gfp ( Φ F ) . Conversely, every element of the greatest fixpoint is a value of c o n s ^ \widehat{cons} co n s . If it is a fresh term s u p ( a , f ) sup(a,f) s u p ( a , f ) , then f ∈ F u n a ( gfp ( Φ F ) ) f\in Fun_a(\operatorname{gfp}(\Phi_F)) f ∈ F u n a ( gfp ( Φ F )) , and not all values of ∣ f ∣ \lvert f\rvert ∣ f ∣ are in Z ′ Z' Z ′ : otherwise ( a , ∣ f ∣ ) ∈ F Z ′ = ζ ′ ( Z ′ ) (a,\lvert f\rvert)\in FZ'=\zeta'(Z') ( a , ∣ f ∣) ∈ F Z ′ = ζ ′ ( Z ′ ) and c o n s ^ ∙ ⟨ a , f ⟩ \widehat{cons}\mathbin{\bullet}\langle a,f\rangle co n s ∙ ⟨ a , f ⟩ would be a tree atom. So f f f is a code, by (1), one of whose values is a fresh term in the greatest fixpoint, of a smaller stage. Iterating gives an infinite strictly decreasing sequence of ordinals, which is impossible.
Proposition B.4. Each of the following structures satisfies all the axioms of the indicated theory except the indicated one, and its extracted algebra or coalgebra is not initial or final.
Without (EXT). For the natural numbers (shapes { z , s } \{z,s\} { z , s } , B [ z ] = ∅ B[z]=\varnothing B [ z ] = ∅ , B [ s ] = { ⋆ } B[s]=\{\star\} B [ s ] = { ⋆ } ), M ( ∅ , ∅ , 2 ) M(\varnothing,\varnothing,2) M ( ∅ , ∅ , 2 ) satisfies Γ F μ \Gamma_F^\mu Γ F μ except (EXT). The element 0 = c ( z , ı ^ ) 0=c(z,\hat{\imath}) 0 = c ( z , ^ ) is in T μ F T_{\mu F} T μ F , and the function ⋆ ↦ 0 \star\mapsto0 ⋆ ↦ 0 has two codes f 0 ≠ f 1 f^0\ne f^1 f 0 = f 1 , so c ( s , f 0 ) ≠ c ( s , f 1 ) c(s,f^0)\ne c(s,f^1) c ( s , f 0 ) = c ( s , f 1 ) represent the same tree. For every choice of a code ⌜ g ⌝ \ulcorner g\urcorner ┌ g ┐ for each function, the map α ( a , g ) = c ( a , ⌜ g ⌝ ) \alpha(a,g)=c(a,\ulcorner g\urcorner) α ( a , g ) = c ( a , ┌ g ┐ ) is not surjective onto T μ F T_{\mu F} T μ F , so it is not the structure map of an initial algebra, which is a bijection.
Without (TAB). For the same container, M ( ∅ , ∅ , 0 ) M(\varnothing,\varnothing,0) M ( ∅ , ∅ , 0 ) satisfies Γ F μ \Gamma_F^\mu Γ F μ except (TAB). No element represents a function on { ⋆ } \{\star\} { ⋆ } into the fresh terms, so T μ F T_{\mu F} T μ F is interpreted as { 0 } \{0\} { 0 } , while the W-type is N \mathbb{N} N . (TAB) fails for R = { ⟨ ⋆ , 0 ⟩ } R=\{\langle\star,0\rangle\} R = {⟨ ⋆ , 0 ⟩} .
Without (BISIMILARITY). For the streams over { 0 } \{0\} { 0 } (one shape 0 0 0 with B [ 0 ] = { ⋆ } B[0]=\{\star\} B [ 0 ] = { ⋆ } ), let Z ′ = { x , y } Z'=\{x,y\} Z ′ = { x , y } with ζ ′ ( x ) = ( 0 , ⋆ ↦ x ) \zeta'(x)=(0,\star\mapsto x) ζ ′ ( x ) = ( 0 , ⋆ ↦ x ) and ζ ′ ( y ) = ( 0 , ⋆ ↦ y ) \zeta'(y)=(0,\star\mapsto y) ζ ′ ( y ) = ( 0 , ⋆ ↦ y ) , a bijection onto F Z ′ FZ' F Z ′ . Then M ( Z ′ , ζ ′ , 1 ) M(Z',\zeta',1) M ( Z ′ , ζ ′ , 1 ) satisfies Γ F \Gamma_F Γ F except (BISIMILARITY): T ν F T_{\nu F} T ν F is interpreted as { x , y } \{x,y\} { x , y } , and { ⟨ x , y ⟩ } \{\langle x,y\rangle\} {⟨ x , y ⟩} is included in its image under b i s bis bi s , so ⟨ x , y ⟩ ∈ B i s i m \langle x,y\rangle\in Bisim ⟨ x , y ⟩ ∈ B i s im and x ≠ y x\ne y x = y . The final coalgebra has one element.
Without (REALISATION), empty ν F \nu F ν F . For the identity functor (one shape with one position), M ( ∅ , ∅ , 1 ) M(\varnothing,\varnothing,1) M ( ∅ , ∅ , 1 ) satisfies Γ F \Gamma_F Γ F except (REALISATION), and T ν F T_{\nu F} T ν F is interpreted as ∅ \varnothing ∅ , while the final coalgebra has one element.
Without (REALISATION), missing behaviours. For the streams over E = { 0 , 1 } E=\{0,1\} E = { 0 , 1 } (shapes E E E , B [ e ] = { ⋆ } B[e]=\{\star\} B [ e ] = { ⋆ } ), let E P ⊆ E ω EP\subseteq E^\omega E P ⊆ E ω be the set of eventually periodic streams, with ζ ′ ( e ⋅ s ) = ( e , ⋆ ↦ s ) \zeta'(e\mathbin{\cdot}s)=(e,\star\mapsto s) ζ ′ ( e ⋅ s ) = ( e , ⋆ ↦ s ) , a bijection onto F E P FEP F E P . Then M ( E P , ζ ′ , 1 ) M(EP,\zeta',1) M ( E P , ζ ′ , 1 ) satisfies Γ F \Gamma_F Γ F except (REALISATION), and T ν F T_{\nu F} T ν F is interpreted as the countable set E P EP E P , while the final coalgebra E ω E^\omega E ω is uncountable.
Without (REALISATION), with T μ F T_{\mu F} T μ F non-empty and dense. For the colists over E = { 0 , 1 } E=\{0,1\} E = { 0 , 1 } (shapes { n , c 0 , c 1 } \{n,c_0,c_1\} { n , c 0 , c 1 } , B [ n ] = ∅ B[n]=\varnothing B [ n ] = ∅ , B [ c e ] = { ⋆ } B[c_e]=\{\star\} B [ c e ] = { ⋆ } ), let Z ′ = E ∗ ∪ E P Z'=E^*\cup EP Z ′ = E ∗ ∪ E P be the set of the finite lists and of the eventually periodic infinite lists, with ζ ′ ( ε ) = ( n , ∅ ↦ Z ′ ) \zeta'(\varepsilon)=(n,\varnothing\mapsto Z') ζ ′ ( ε ) = ( n , ∅ ↦ Z ′ ) and ζ ′ ( e ⋅ s ) = ( c e , ⋆ ↦ s ) \zeta'(e\mathbin{\cdot}s)=(c_e,\star\mapsto s) ζ ′ ( e ⋅ s ) = ( c e , ⋆ ↦ s ) , a bijection onto F Z ′ FZ' F Z ′ . Then M ( Z ′ , ζ ′ , 1 ) M(Z',\zeta',1) M ( Z ′ , ζ ′ , 1 ) satisfies Γ F \Gamma_F Γ F except (REALISATION); T μ F T_{\mu F} T μ F is interpreted as the set E ∗ E^* E ∗ of the finite lists, which is non-empty and dense in the interpretation Z ′ Z' Z ′ of T ν F T_{\nu F} T ν F (Proposition 4.26 (3)), and the infinite lists that are not eventually periodic are not represented.
Proof. In all cases, Lemma B.3(1) and (2) give the axioms other than (EXT), (TAB), (BISIMILARITY), and (REALISATION).
(1) All the values of c o n s ^ \widehat{cons} co n s are fresh terms. (TAB) holds: every function from { ⋆ } \{\star\} { ⋆ } to lfp ( Φ F ) \operatorname{lfp}(\Phi_F) lfp ( Φ F ) has the code of copy 0 0 0 , which is in F u n s ( lfp ( Φ F ) ) Fun_s(\operatorname{lfp}(\Phi_F)) F u n s ( lfp ( Φ F )) by Lemma B.3(1). (EXT) fails for f 0 f^0 f 0 and f 1 f^1 f 1 . Since lfp ( Φ F ) = Φ F ( lfp ( Φ F ) ) \operatorname{lfp}(\Phi_F)=\Phi_F(\operatorname{lfp}(\Phi_F)) lfp ( Φ F ) = Φ F ( lfp ( Φ F )) contains c ( s , f 0 ) c(s,f^0) c ( s , f 0 ) and c ( s , f 1 ) c(s,f^1) c ( s , f 1 ) , and α \alpha α reaches at most one of them, α \alpha α is not surjective.
(2) By Lemma B.3(1), Funs ( S ) = ∅ \operatorname{Funs}(S)=\varnothing Funs ( S ) = ∅ for every set S S S of fresh terms, so Φ F ( S ) = { c ( z , ı ^ ) } = { 0 } \Phi_F(S)=\{c(z,\hat{\imath})\}=\{0\} Φ F ( S ) = { c ( z , ^ )} = { 0 } for such S S S , and lfp ( Φ F ) = { 0 } \operatorname{lfp}(\Phi_F)=\{0\} lfp ( Φ F ) = { 0 } . (EXT) holds vacuously. The set R = { ⟨ ⋆ , 0 ⟩ } R=\{\langle\star,0\rangle\} R = {⟨ ⋆ , 0 ⟩} satisfies the premise of (TAB) for the shape s s s , and no f f f satisfies its conclusion.
(3) (EXT) and (TAB) hold by Lemma B.3(3), and the greatest fixpoint is Z ′ Z' Z ′ by Lemma B.3(4). The M-type has a single tree u u u , so β ( x ) = β ( y ) = u \beta(x)=\beta(y)=u β ( x ) = β ( y ) = u , and, for every T T T with T r e e ( T ) Tree(T) T r ee ( T ) , z T = u z_T=u z T = u and B e h ( x , T ) Beh(x,T) B e h ( x , T ) holds by Lemma 4.14(3); so (REALISATION) holds. Since x . o u t = y . o u t = 0 x.out=y.out=0 x . o u t = y . o u t = 0 and the children of x x x and y y y at ⋆ \star ⋆ are x x x and y y y , the pair ⟨ x , y ⟩ \langle x,y\rangle ⟨ x , y ⟩ is in the interpretation of b i s ( R ) bis(R) bi s ( R ) for R = { ⟨ x , y ⟩ } R=\{\langle x,y\rangle\} R = {⟨ x , y ⟩} , hence in B i s i m Bisim B i s im by the Knaster–Tarski theorem.
(4) F ∅ = ∅ F\varnothing=\varnothing F ∅ = ∅ , since the shape has a position, so the empty map is a bijection and the greatest fixpoint is empty, by Lemma B.3(4). (EXT) and (TAB) hold by Lemma B.3(3), (BISIMILARITY) vacuously. The set T T T of all the pairs ⟨ p , a ⟩ \langle p,a\rangle ⟨ p , a ⟩ , with p p p in T ( L P ) \mathsf{T}(LP) T ( L P ) and a a a the shape, satisfies T r e e ( T ) Tree(T) T r ee ( T ) , and there is no element of T ν F \mathsf{T}_{\nu F} T ν F , so (REALISATION) fails.
(5) The greatest fixpoint is E P EP E P , by Lemma B.3(4), and (EXT) and (TAB) hold by Lemma B.3(3). Here γ ( e ⋅ s ) = ( e , ⋆ ↦ s ) \gamma(e\mathbin{\cdot}s)=(e,\star\mapsto s) γ ( e ⋅ s ) = ( e , ⋆ ↦ s ) , so β \beta β is the inclusion of E P EP E P into E ω E^\omega E ω . If a set R R R of pairs is included in its image under b i s bis bi s , then related streams have equal heads and related tails, so they have the same n n n -th element for every n n n , by induction on n n n , and are equal; hence (BISIMILARITY) holds. Let z ∈ E ω ∖ E P z\in E^\omega\setminus EP z ∈ E ω ∖ E P . The set of pairs ⟨ [ π ] , a ⟩ \langle[\pi],a\rangle ⟨[ π ] , a ⟩ with ( π , a ) ∈ T z (\pi,a)\in T_z ( π , a ) ∈ T z satisfies T r e e Tree T r ee , by Lemma 4.14(1), and an element x x x with B e h ( x , T z ) Beh(x,T_z) B e h ( x , T z ) would have β ( x ) = z \beta(x)=z β ( x ) = z , by Lemma 4.14(3), which is impossible. So (REALISATION) fails.
(6) s ∈ Z ′ s\in Z' s ∈ Z ′ iff e ⋅ s ∈ Z ′ e\mathbin{\cdot}s\in Z' e ⋅ s ∈ Z ′ , so ζ \zeta ζ is a bijection onto F Z ′ FZ' F Z ′ , and the greatest fixpoint is Z ′ Z' Z ′ , by Lemma B.3(4). For S ⊆ Z ′ S\subseteq Z' S ⊆ Z ′ , Φ F ( S ) \Phi_F(S) Φ F ( S ) consists of ε \varepsilon ε and of the lists e ⋅ s e\mathbin{\cdot}s e ⋅ s with s ∈ S s\in S s ∈ S , so the least fixpoint is E ∗ E^* E ∗ . (EXT) and (TAB) hold by Lemma B.3(3). As in (5), β \beta β is the inclusion of Z ′ Z' Z ′ into the set E ∗ ∪ E ω E^*\cup E^\omega E ∗ ∪ E ω of all finite and infinite lists, a set of pairs included in its image under b i s bis bi s relates lists that have the same shape at every index, hence equal lists, so (BISIMILARITY) holds, and (REALISATION) fails for T z T_z T z with z ∈ E ω ∖ E P z\in E^\omega\setminus EP z ∈ E ω ∖ E P . Every prefix of such a z z z is in E ∗ E^* E ∗ , so z z z is approximated to every depth by elements of T μ F \mathsf{T}_{\mu F} T μ F .
Several Containers and Parameter Specifications
We now extend the construction to Γ F \Gamma_F Γ F together with parameter specifications from C p a r C^{par} C p a r (Definition 4.20), as needed for Theorem 4.21 and for the case studies. We fix an instance, i.e., a set S s S_s S s for each parameter sort s s s introduced by (Par).
The combined construction The specifications involve finitely many containers G 1 , … , G k G_1,\ldots,G_k G 1 , … , G k (those introduced by (Ind)), with G k = F G_k=F G k = F , such that the shapes A j A_j A j and the positions B j [ a ] B_j[a] B j [ a ] of each G j G_j G j are built by (Par), (Fin), (Prod), (Fam), and (Sum) from G 1 , … , G j − 1 G_1,\ldots,G_{j-1} G 1 , … , G j − 1 . Each G j G_j G j has its own symbols c o n s j cons_j co n s j , o u t j out_j o u t j , n x t j nxt_j n x t j , and sort names m μ j m\mathord{\mu}_j m μ j , n μ j n\mathord{\mu}_j n μ j . The atoms now also include the constants of (Fin), as fresh atoms, the elements of the tagged copies S s ♯ = { par s } × S s S_s^\sharp=\{\operatorname{par}_s\}\times S_s S s ♯ = { par s } × S s of the sets chosen for the parameter sorts, also as fresh atoms, and the trees of the M-types Z 1 , … , Z k Z_1,\ldots,Z_k Z 1 , … , Z k , where Z j Z_j Z j is built over the interpretations of A j A_j A j and B j B_j B j described next. The sorts of the specifications are again interpreted by their intended sets: a parameter sort by S s ♯ S_s^\sharp S s ♯ , the constants of (Fin) by themselves, products by pairs, dependent sums by dependent pairs, and μ G j \mu G_j μ G j and ν G j \nu G_j ν G j by the well-founded trees W Z j WZ_j W Z j and all trees Z j Z_j Z j . Here the shapes and positions are not tagged atoms, but these objects; for instance, the positions of lists are the element ⋆ \star ⋆ of 1 1 1 , and positions in a dependent sum are pairs. The stages are as before, with (C4) adding the codes on all the position sets B j [ a ] B_j[a] B j [ a ] , (C5) adding fresh terms s u p j ( a , f ) sup_j(a,f) s u p j ( a , f ) for every j j j , and a regular cardinal θ \theta θ larger than all the position sets. Application is defined as before for each j j j : c o n s ^ j ⋅ ⟨ a , f ⟩ con\hat{s}_j\mathbin{\cdot}\langle a,f\rangle co n s ^ j ⋅ ⟨ a , f ⟩ , for a ∈ A j a\in A_j a ∈ A j and f ∈ F u n j a ( M ) f\in Fun_j^a(M) f ∈ F u n j a ( M ) , is { ζ j − 1 ( a , ∣ f ∣ ) } \{\zeta_j^{-1}(a,|f|)\} { ζ j − 1 ( a , ∣ f ∣ )} if all values of ∣ f ∣ |f| ∣ f ∣ are trees of Z j Z_j Z j , and { sup ^ j ( a , f ) } \{\widehat{\operatorname{sup}}_j(a,f)\} { sup j ( a , f )} otherwise; out ^ j \widehat{\operatorname{out}}_j out j and nxt ^ j \widehat{\operatorname{nxt}}_j nxt j are defined on the trees of Z j Z_j Z j and on the fresh terms of G j G_j G j as before. Here F u n a j ( S ) Fun^j_a(S) F u n a j ( S ) is { ı ^ } \{\hat{\imath}\} { ^ } if B j [ a ] = ∅ B_j[a]=\varnothing B j [ a ] = ∅ , and otherwise the set of f f f with f ∙ b f\mathbin{\bullet}b f ∙ b a singleton included in S S S for b ∈ B j [ a ] b\in B_j[a] b ∈ B j [ a ] and f ∙ x = ∅ f\mathbin{\bullet}x=\varnothing f ∙ x = ∅ for x ∉ B j [ a ] x\notin B_j[a] x ∈ / B j [ a ] . Let F r e s h j Fresh_j F r es h j be the set of fresh terms of G j G_j G j .
Canonical rather than literal interpretations “Intended” is meant up to canonical bijections: the pairs of the model are the objects of (C1), not set-theoretic pairs, and μ G j \mu G_j μ G j and ν G j \nu G_j ν G j are interpreted by the sets of trees W Z j W_{Z_j} W Z j and Z j Z_j Z j , which are isomorphic to the W-type and the M-type of G j G_j G j . This is all that Theorem 4.21 requires, since it states bijections with the intended sets. Tagging is needed only for the parameter sorts of (Par). For a single container, tagging was needed because A A A and B [ a ] B[a] B [ a ] are arbitrary external sets, whose elements might coincide with objects of the construction, such as codes, symbol atoms, or pairs; the same holds for the sets S s S_s S s , and the tagged copies S s # S_s^\# S s # consist of fresh atoms. All the other parameter sets are built inside the construction, from fresh atoms, ⋆ \star ⋆ , pairs, and trees, so no such coincidence can occur, and the disjointness provided by tagging is replaced by the facts (F1) and (F2) below and by Lemma B.5. Coincidences between the parameter sets themselves are harmless: for instance, for the identity functor, ⋆ \star ⋆ is both the shape and the position, and Lemma B.5 does not use the disjointness of shapes and positions.
Sort names The axioms of (Fam) are equations between sort names, not only between sets of inhabitants, so the sort names must be chosen accordingly. The set N N N of sort names contains Srt, 1, one name for each sort introduced by (Par), by (Fin), and by (Sum), the names μ j \mu_j μ j and ν j \nu_j ν j of μ G j \mu G_j μ G j and ν G j \nu G_j ν G j , and the names P j P_j P j and L P j LP_j L P j of the sorts of positions and of paths of each G j G_j G j , and it is closed under ⊗ \otimes ⊗ . The function ⊤ \top ⊤ gives each name its intended set: S s # S_s^\# S s # for a parameter sort s s s , the constants for (Fin), pairs for ⊗ \otimes ⊗ , dependent pairs for (Sum), and W Z j W_{Z_j} W Z j and Z j Z_j Z j for (Ind). A family B B B introduced by (Fam) creates no new sort names. Its symbol is interpreted as the atom B ^ \widehat B B , and d e p O f B ^ depOf_{\widehat B} d e pO f B returns an existing name: d e p O f B ^ ∙ a depOf_{\widehat B}\mathbin{\bullet}a d e pO f B ∙ a is the name of s s s for every a a a in the interpretation of A A A , for a constant family; the name of s i s_i s i for a = c i a=c_i a = c i , for a family defined by cases; and the name of s i s_i s i for a = ⟨ c i , x ⟩ a=\langle c_i,x\rangle a = ⟨ c i , x ⟩ with x ∈ ⊤ ( C [ c i ] ) x\in\top(C[c_i]) x ∈ ⊤ ( C [ c i ]) , for a family defined by cases on the tag; it is empty otherwise. A compound sort, such as s 1 ⊗ s 2 s_1\otimes s_2 s 1 ⊗ s 2 , is returned as its compound name. Similarly, the shapes A j A_j A j of G j G_j G j denote the name of the sort of C p a r Cpar C p a r that gives them. For each j j j , D e p S u m ∙ n j = { D e p S u m n j } DepSum\mathbin{\bullet}n_j=\{DepSum_{n_j}\} D e pS u m ∙ n j = { D e pS u m n j } and D e p S u m n j ∙ B ^ j = { P j } DepSum_{n_j}\mathbin{\bullet}\widehat B_j=\{P_j\} D e pS u m n j ∙ B j = { P j } , where n j n_j n j is the name of A j A_j A j , and L i s t ˙ ∙ P j = { L P j } L\dot{ist}\mathbin{\bullet}P_j=\{LP_j\} L i s t ˙ ∙ P j = { L P j } , with ⊤ ( P j ) = { ⟨ a , b ⟩ ∣ a ∈ A j , b ∈ B j [ a ] } \top(P_j)=\{\langle a,b\rangle\mid a\in A_j,\ b\in B_j[a]\} ⊤ ( P j ) = {⟨ a , b ⟩ ∣ a ∈ A j , b ∈ B j [ a ]} and ⊤ ( L P j ) \top(LP_j) ⊤ ( L P j ) the set of finite sequences over ⊤ ( P j ) \top(P_j) ⊤ ( P j ) ; the dependent sums of (Sum) are named in the same way. The fresh names B a B_a B a of the single-container model are used only there, where the family is not constrained by equations.
We use two facts about the sorts of the parameter specifications, which we call specified sorts .
(F1) Every element of a sort of the parameter specifications has an empty application on every argument: it is an atom of some S s # S_s^\# S s # , a constant of (Fin), ⋆ \star ⋆ , a pair, a sequence, or a tree. Specified sorts contain no sort names, symbol atoms, codes, ı ^ \hat{\imath} ^ , partial applications, or fresh terms.
(F2) The positions of G j G_j G j are built only from (Par), (Fin), (Prod), (Sum), and G 1 , … , G j − 1 G_1,\ldots,G_{j-1} G 1 , … , G j − 1 ; so neither they nor their components are trees of Z j Z_j Z j or fresh terms of any G i G_i G i .
Lemma B.5. Let 1 ≤ j ≤ k 1\leq j\leq k 1 ≤ j ≤ k , a ∈ A j a\in A_j a ∈ A j with B j [ a ] ≠ ∅ B_j[a]\ne\varnothing B j [ a ] = ∅ , and S ⊆ Z j ∪ F r e s h j S\subseteq Z_j\cup Fresh_j S ⊆ Z j ∪ F r es h j . Then f ∈ F u n a j ( S ) f\in Fun^j_a(S) f ∈ F u n a j ( S ) iff f f f is a code ⌜ g ⌝ \ulcorner g\urcorner ┌ g ┐ with g : B j [ a ] → S g:B_j[a]\to S g : B j [ a ] → S .
Proof. Codes on B j [ a ] B_j[a] B j [ a ] with values in S S S are in F u n a j ( S ) Fun^j_a(S) F u n a j ( S ) . Conversely, let f ∈ F u n a j ( S ) f\in Fun^j_a(S) f ∈ F u n a j ( S ) and b ∈ B j [ a ] b\in B_j[a] b ∈ B j [ a ] , so that f ∙ b = { s } f\mathbin{\bullet}b=\{s\} f ∙ b = { s } with s ∈ Z j ∪ F r e s h j s\in Z_j\cup Fresh_j s ∈ Z j ∪ F r es h j . We examine all the elements of M M M by their kind.
def ^ ∙ b = M \hat{\operatorname{def}}\mathbin{\bullet}b=M def ^ ∙ b = M , which is not a singleton.
ı n h ^ \hat{\imath n h} nh ^ has non-empty applications only on sort names, and positions are not sort names, by (F1).
p a i r ^ \widehat{pair} p ai r , P a i r ^ \widehat{Pair} P ai r , d e p O f ^ \widehat{depOf} d e pO f , D e p S u m ^ \widehat{DepSum} D e pS u m , L i s t ^ \widehat{List} L i s t , p c o n s ^ \widehat{pcons} p co n s , and their partial applications yield partial applications, pairs, sort names, or sequences, which are not in Z j ∪ F r e s h j Z_j \cup Fresh_j Z j ∪ F r es h j .
f s t ^ \widehat{fst} f s t and s n d ^ \widehat{snd} s n d yield, on a pair-shaped position ⟨ x , y ⟩ \langle x,y\rangle ⟨ x , y ⟩ , its components x x x or y y y , which are not in Z j ∪ F r e s h j Z_j \cup Fresh_j Z j ∪ F r es h j by (F2). Moreover, they are defined on every pair of M M M , e.g., on pairs of sort names, which are not positions, so they are not strict on B j [ a ] B_j[a] B j [ a ] .
ı ^ ∙ b = ∅ \hat{\imath} \mathbin{\bullet} b = \varnothing ^ ∙ b = ∅ , and f i n M o r ^ ∙ b = { ⋆ } \widehat{finMor} \mathbin{\bullet} b = \{\star\} f in M or ∙ b = { ⋆ } , with ⋆ ∉ Z j ∪ F r e s h j \star\notin Z_j \cup Fresh_j ⋆ ∈ / Z j ∪ F r es h j .
c o n s ^ i ^ \widehat{con\hat{s}_i} co n s ^ i , for any i i i , has non-empty applications only on pairs ⟨ a ′ , f ′ ⟩ \langle a',f'\rangle ⟨ a ′ , f ′ ⟩ with f ′ ∈ F u n a ′ i ( M ) f' \in Fun^i_{a'}(M) f ′ ∈ F u n a ′ i ( M ) . If b = ⟨ x , y ⟩ b = \langle x,y\rangle b = ⟨ x , y ⟩ is a pair-shaped position, then y y y is an element of a specified sort; by (F1) it has an empty application everywhere and is not ı ^ \hat{\imath} ^ , so y ∉ F u n a ′ i ( M ) y \notin Fun^i_{a'}(M) y ∈ / F u n a ′ i ( M ) , and c o n s ^ i ∙ b = ∅ \widehat{cons}_i \mathbin{\bullet} b = \varnothing co n s i ∙ b = ∅ .
o u t ^ i \widehat{out}_i o u t i and n x t ^ i \widehat{nxt}_i n x t i , for any i i i , have non-empty applications only on the trees of Z i Z_i Z i and on the fresh terms of G i G_i G i . By (F2), a position can be such a tree only if i < j i < j i < j , and is never a fresh term. On a tree of Z i Z_i Z i , o u t ^ i \widehat{out}_i o u t i yields a shape of G i G_i G i , an element of a specified sort built from G 1 , … , G i − 1 G_1,\ldots,G_{i-1} G 1 , … , G i − 1 , hence not in Z j ∪ F r e s h j Z_j \cup Fresh_j Z j ∪ F r es h j ; and n x t ^ i \widehat{nxt}_i n x t i yields a code or ı ^ \hat{\imath} ^ . Moreover, independently of the values, o u t ^ i \widehat{out}_i o u t i and n x t ^ i \widehat{nxt}_i n x t i are defined on the fresh terms of G i G_i G i , which are not positions, so they are not strict on B j [ a ] B_j[a] B j [ a ] .
A code ⌜ g ⌝ \ulcorner g\urcorner ┌ g ┐ , of any container, yields { g ( b ) } \{g(b)\} { g ( b )} for b b b in the domain of g g g . Strictness forces the domain of g g g to be B j [ a ] B_j[a] B j [ a ] : an element of B j [ a ] B_j[a] B j [ a ] outside the domain would have an empty application, and an element of the domain outside B j [ a ] B_j[a] B j [ a ] a non-empty one.
All other elements, i.e., atoms, trees, fresh terms, pairs, sequences, sort names, and the remaining symbol atoms, have empty applications on positions.
So f f f is a code ⌜ g ⌝ \ulcorner g\urcorner ┌ g ┐ with domain B j [ a ] B_j[a] B j [ a ] , and its values are in S S S .
In other words, neither the auxiliary operations nor the operations of the other containers yield elements of F u n a j ( S ) Fun^j_a(S) F u n a j ( S ) other than the intended codes. A code created for another container counts only when its domain is exactly B j [ a ] B_j[a] B j [ a ] , and then it is an intended code, since codes are determined by their graphs.
Theorem B.6. For every instance of a parametric specification, the combined theory, i.e., Γ G 1 ∪ ⋯ ∪ Γ G k \Gamma_{G_1} \cup\cdots\cup\Gamma_{G_k} Γ G 1 ∪ ⋯ ∪ Γ G k together with the parameter specifications, has a model in which every parameter sort s s s is interpreted by a set in bijection with the chosen set S s S_s S s , and every other sort by a set in canonical bijection with its intended set; in particular, it is consistent.
Proof. Let M M M be the structure of the combined construction. We check the axioms by groups.
Base theory. (Definedness), the axioms of SORT and PAIR, and the axioms of ı ^ \hat{\imath} ^ , ⋆ \star ⋆ , and 1 1 1 hold as in the proof of Theorem B.2: N N N is closed under ⊗ \otimes ⊗ , pairs are injective and total, and T ( s ⊗ s ′ ) \mathcal{T}(s \otimes s') T ( s ⊗ s ′ ) is the set of pairs of inhabitants.
Parameter specifications. (a) Equations between sort names. The axioms of (Fam), ∀ a : A . B [ a ] = s \forall a\!:\!A.\ B[a] = s ∀ a : A . B [ a ] = s , B [ c i ] = s i B[c_i] = s_i B [ c i ] = s i , and ∀ x : C [ c i ] . B [ ⟨ c i , x ⟩ ] = s i \forall x\!:\!C[c_i].\ B[\langle c_i,x\rangle] = s_i ∀ x : C [ c i ] . B [⟨ c i , x ⟩] = s i , hold because d e p O f ^ ȷ ^ \widehat{depOf}_{\hat{\jmath}} d e pO f ^ returns exactly the name of the required sort; in particular, the family axiom ∀ a : A . B [ a ] : S o r t \forall a\!:\!A.\ B[a]\!:\!Sort ∀ a : A . B [ a ] : S or t holds. The sorting axioms, i.e., s : S o r t s\!:\!Sort s : S or t for (Par) and (Fin), A : S o r t A\!:\!Sort A : S or t , ( s 1 ⊗ s 2 ) : S o r t (s_1 \otimes s_2)\!:\!Sort ( s 1 ⊗ s 2 ) : S or t , the sort axioms of the dependent sums, and (MU SORT), (NU SORT), and (LIST SORT) for each G j G_j G j , hold because these names belong to N = T ( S r t ) N = \mathcal{T}(Srt) N = T ( S r t ) . (b) Equations between inhabitants. The axioms of (Fin), (Prod), and (Sum), and the equalities T B [ a ] = T s \mathcal{T}_{B[a]} = \mathcal{T}_s T B [ a ] = T s , follow from the definition of T \mathcal{T} T on N N N ; the constants of (Fin) are pairwise distinct atoms. A parameter sort s s s has no further axioms, and T \mathcal{T} T maps its name to S s # S_s^{\#} S s # , in bijection with S s S_s S s .
Containers. Fix j j j . The interpretations of A j A_j A j and of B j [ a ] B_j[a] B j [ a ] are the sets A j A_j A j and B j [ a ] B_j[a] B j [ a ] of the construction, by (a) and (b). We repeat the proof of Theorem B.2 for G j G_j G j , with Lemma B.5 in place of Lemma B.1.
Constructor. (FUNCTIONAL) holds by the definition of cons ^ j \widehat{\operatorname{cons}}_j cons j . For (NO CONFUSION), if c j ( a , f ) = c j ( a ′ , f ′ ) c_j(a,f)=c_j(a',f') c j ( a , f ) = c j ( a ′ , f ′ ) is a tree z ∈ Z j z\in Z_j z ∈ Z j , then ζ j ( z ) = ( a , ∣ f ∣ ) = ( a ′ , ∣ f ′ ∣ ) \zeta_j(z)=(a,\lvert f\rvert)=(a',\lvert f'\rvert) ζ j ( z ) = ( a , ∣ f ∣) = ( a ′ , ∣ f ′ ∣) , so a = a ′ a=a' a = a ′ , and, by Lemma B.5 with S = Z j S=Z_j S = Z j , f f f and f ′ f' f ′ are codes on B j [ a ] B_j[a] B j [ a ] with the same graph (or both are ι ^ \hat{\iota} ι ^ ), so f = f ′ f=f' f = f ′ ; otherwise it is a fresh term sup j ( a , f ) \operatorname{sup}_j(a,f) sup j ( a , f ) , and fresh terms are injective.
Initial algebra. For S ⊆ Z j S\subseteq Z_j S ⊆ Z j , Lemma B.5 and the closure of M M M under codes give Φ G j ( S ) = { ζ j − 1 ( a , g ) ∣ a ∈ A j , g : B j [ a ] → S } \Phi_{G_j}(S)=\{\zeta_j^{-1}(a,g)\mid a\in A_j,\ g:B_j[a]\to S\} Φ G j ( S ) = { ζ j − 1 ( a , g ) ∣ a ∈ A j , g : B j [ a ] → S } , so the least fixpoint is W Z j = T ( μ j ) W_{Z_j}=\mathsf{T}(\mu_j) W Z j = T ( μ j ) , and (NO JUNK) holds; (EXT) and (TAB) hold because every function B j [ a ] → W Z j B_j[a]\to W_{Z_j} B j [ a ] → W Z j has exactly one code, and Fun j a ( W Z j ) \operatorname{Fun}_j^a(W_{Z_j}) Fun j a ( W Z j ) consists of these codes.
Final coalgebra. Z j ⊆ Φ G j ( Z j ) Z_j\subseteq\Phi_{G_j}(Z_j) Z j ⊆ Φ G j ( Z j ) , and every element of the greatest fixpoint is a tree of Z j Z_j Z j or a fresh term of G j G_j G j . A fresh term sup j ( a , f ) \operatorname{sup}_j(a,f) sup j ( a , f ) in the greatest fixpoint has f ∈ Fun j a ( Z j ∪ Fresh j ) f\in\operatorname{Fun}_j^a(Z_j\cup\operatorname{Fresh}_j) f ∈ Fun j a ( Z j ∪ Fresh j ) , so f f f is a code by Lemma B.5, one of whose values is a fresh term of G j G_j G j in the greatest fixpoint, of a smaller stage; this is impossible, as in the proof of Theorem B.2 . So the greatest fixpoint is Z j = T ( ν j ) Z_j=\mathsf{T}(\nu_j) Z j = T ( ν j ) , and (NO COJUNK) holds. (NO COCONFUSION.1–2) hold by the definitions of out ^ j \widehat{\operatorname{out}}_j out j and nxt ^ j \widehat{\operatorname{nxt}}_j nxt j , and (BISIMILARITY) because a set of pairs included in its image under bis \operatorname{bis} bis is a bisimulation on the final coalgebra ( Z j , ζ j ) (Z_j,\zeta_j) ( Z j , ζ j ) .
Paths and realisation. P j P_j P j denotes P j P_j P j and List ( P j ) \operatorname{List}(P_j) List ( P j ) denotes L P j LP_j L P j , by the definition of the applications of DepSum ^ \widehat{\operatorname{DepSum}} DepSum and List ^ \widehat{\operatorname{List}} List , and T ( P j ) \mathsf{T}(P_j) T ( P j ) is the set of dependent pairs, so the axiom of the dependent sum P j P_j P j holds. T ( L P j ) \mathsf{T}(LP_j) T ( L P j ) is the set of finite sequences over T ( P j ) \mathsf{T}(P_j) T ( P j ) , with p n i l pnil p ni l the empty sequence and p c o n s pcons p co n s the prepending of an element, so the axioms of List ( P j ) \operatorname{List}(P_j) List ( P j ) hold; sequences over different sets T ( P j ) \mathsf{T}(P_j) T ( P j ) are handled by the same symbols p n i l pnil p ni l and p c o n s pcons p co n s , which are defined on all sequences. The other axioms of Γ G j ν \Gamma^{\nu}_{G_j} Γ G j ν hold, and the unique coalgebra morphism from the extracted coalgebra to ( Z j , ζ j ) (Z_j,\zeta_j) ( Z j , ζ j ) is the identity of Z j Z_j Z j ; so, for T T T with Tree ( T ) \operatorname{Tree}(T) Tree ( T ) , the tree z T z_T z T of Lemma 4.14 (2) satisfies Beh ( z T , T ) \operatorname{Beh}(z_T,T) Beh ( z T , T ) by Lemma 4.14 (3), and (REALISATION) holds.
The symbols of G j G_j G j do not occur in the axioms of the other containers, except through the sorts μ G j \mu G_j μ G j and ν G j \nu G_j ν G j , whose interpretations are W Z j W_{Z_j} W Z j and Z j Z_j Z j . Finally, every sort is interpreted by T \mathsf{T} T of its name, which is S ♯ S^{\sharp} S ♯ for a parameter sort and the intended set, up to the canonical bijections, for the others.
Corollary B.7. For every set E E E , the theory of lists over E E E of § 6 has a model in which E E E is interpreted by a set in bijection with E E E , and, for all sets O O O and I I I , the theory of Moore machines of § 7 has a model in which O O O and I I I are interpreted by sets in bijection with O O O and I I I .
Proof. The parameter specification of lists consists of the parameter sort E E E , the sorts Tag \operatorname{Tag} Tag , 0 0 0 , and 1 1 1 given by (Fin), the family C C C defined by cases, the dependent sum ∑ i : Tag C [ i ] \sum_{i:\operatorname{Tag}} C[i] ∑ i : Tag C [ i ] , and the family of positions defined by cases on the tag; that of Moore machines consists of the parameter sorts O O O and I I I and the constant family o : O → I o:O\to I o : O → I . Both are in C p a r C_{\mathrm{par}} C par , so Theorem B.6 applies.
Changes with Respect to the FROM 2023 Version
The main changes with respect to [15 ] are:
Corrected axioms. Several axioms were corrected: the notation for partial functions (which now also allows empty target sorts), the representation X B [ a ] X^{B[a]} X B [ a ] of functions, which is made strict, the injectivity of pairs (now stated for all elements, as needed for dependent pairs), the generic axiom (FUNCTIONAL), (NO CONFUSION) (now restricted to elements representing functions), the coconfusion axioms, and the axioms of the list and Moore machine case studies. The initial morphism ı \imath is now required to be functional.
Initial algebra. Two axioms, (EXT) and (TAB), fix which elements represent functions. Theorem 4.4 proves that, in every model, the extracted algebra is initial (a W-type), and Proposition 4.6 gives a model. The approximation of the least fixpoint by φ F n ( ⊥ ) \varphi_F^n(\bot) φ F n ( ⊥ ) is proved for finitary functors (Lemma 4.2).
Final coalgebra. Two axioms, (BISIMILARITY) and (REALISATION), are added. Theorem 4.15 proves that, in every model, the extracted coalgebra is final (an M-type), and Proposition 4.18 gives a model. Models in which one axiom fails show that the new axioms are needed (Proposition B.4 ), and Proposition 4.24 relates the axioms of the two theories.
Parameters. The notion of capturing a data type is stated for parametric data types: the theories capture μ F \mu F μ F and ν F \nu F ν F relative to the interpretation of the sorts of shapes and positions, and absolutely when these sorts are themselves captured (Proposition 4.19 ); Theorem 4.21 gives sufficient conditions, and its limits are stated in Remark 4.23.
Theories. The theories used by the adequacy results are fixed formally (Definition 4.1 ), together with the typing of their symbols; Appendix § 9 states which recalled specifications are adapted and which are not used, and PAIR gets an axiom making pairing total. The sorts μ F \mu F μ F and ν F \nu F ν F are declared as sorts, the derivable axioms (NO CONFUSION) and (NO COCONFUSION.3) are not axioms of Γ F \Gamma_F Γ F (Lemma 4.10 ), and finite sums are represented as dependent sums over finite sorts of tags, so the specification of sum sorts is no longer recalled; functions are represented by the notation X B [ a ] X^{B[a]} X B [ a ] , so the specification of function sorts is no longer recalled either; the ML specification of dependent products, which no result used, is removed.
Summary. Section 4.8 classifies the results into well-formedness, satisfiability, semantic adequacy, derivable proof principles, and results that need additional assumptions.
Boundary cases. Section 4.9 analyses empty shape and position sets, empty exponent domains, infinite position sets, and functors with empty initial algebra and non-empty final coalgebra.
Standard model. Appendix § 10 gives a full construction of a model of the theories of the initial algebra and of the final coalgebra, using tagged representatives of the shape and position sets and including several containers used as parameters (Lemma B.5 and Theorem B.6 ), which proves that they have models with the intended interpretation, up to canonical bijections (the tagging bijections, for a single container). It also separates the external use of the final coalgebra in the construction from the internal characterization given by the axioms.
Audit of the revised version. The class of parametric specifications (rule (Par) of Definition 4.20 ) and the complete proof of Theorem B.6 give models for the case studies over arbitrary parameters (Corollary B.7); L i s t ( P ) \mathit{List}(P) List ( P ) is declared as a sort and interpreted in the standard model; structures in which one axiom fails are constructed (Proposition B.4 ); the two sorts are related by an inclusion, a density property, and a characterisation of (REALISATION) as completeness (Proposition 4.26 ); and all statements are numbered with one counter.