Distributive-Law Semantics for Cellular Automata

0 downloads 0 Views 387KB Size Report
nite, and local transition rule, but may be in individually different states at any time. ... ational semantics (SOS) in the bialgebraic style of [7] serve to structure and.
Distributive-Law Semantics for Cellular Automata and Agent-Based Models Baltasar Tranc´on y Widemann and Michael Hauhs [email protected] Ecological Modelling, University of Bayreuth, Germany

Abstract. We present an effort to give formal semantics to the popular but theoretically rather unreflected scientific modelling paradigm of agent- or individual-based models. To this end, we give a generic formalization of two-dimensional cellular automata with flexible topology as the abstract basis of such models. The semantic approach of structural operational semantics a la Turi and Plotkin [7], based on bialgebras and distributive laws, leads in this case to a natural separation of the concerns of spatial structure, temporal behavior and local interaction. We give a generic distributive law for local behavior of automata and prove the equivalence to a more traditional, array-based formalization.

1

Introduction

In empirical sciences, computers have been perceived traditionally as mechanical extensions of the established modelling methods, allowing the numerical solution of analytically intractable equations. The power of computers to display complex interactive behavior has been harnessed rather lately, in particular in the form of so-called individual-based or agent-based models (ABMs). These models and their mathematical abstraction, cellular automata (CAs), are widely used in empirical areas of natural and social sciences. The epistemological and methodological implications of these models remain unexplored, not least because appropriate semantic theories are not available to modelling practitioners. Formal theories of interactive behavior have been developed in theoretical computer science. Categorial notions, especially coalgebra and modal logic, have proven fruitful [5, 6]. Here, we make results of this recent development from [7, 1] accessible for modelling. To this end we show that distributive laws and their bialgebras can be used as a common semantic theory behind cellular models. In particular, we will define a large class of CAs by a parametric class of distributive laws of spatial syntax over temporal behavior. The principle of CAs is to cover space with identical copies of simple automata. All of these share a common state space, often but not necessarily finite, and local transition rule, but may be in individually different states at any time. Global behavior emerges through the interaction of neighboring automata, with the pre-state of neighbors, or some observation of it, serving as input to each automaton. The patterns of global behavior, both stationary and mobile

2

Baltasar Tranc´ on y Widemann and Michael Hauhs

and both periodic and asymptotic, are the principal properties of interest when studying CAs. The basic CA design has a number of degrees of freedom: the global shape of the world, the local shape of neighborhoods, the local state space and transition rule, the initial and boundary conditions, and the amount of observable information about neighbor states. Here, we demonstrate how structural operational semantics (SOS) in the bialgebraic style of [7] serve to structure and separate these concerns. We also demonstrate that the coalgebraic part of bialgebras leverages the powers of coinductive reasoning about the behavior of CAs, in terms of equivalence, bisimulation or corecursive definition, in a natural way. Our main result Theorem 4 is a first and promising example of such a coinductive argument. The implications of our approach for the implementation of CAs and ABMs in a functional programming language on one hand, and for the epistemological and methodological assessment of the relation of ABMs to empirical phenomena on the other hand, shall be addressed in two forthcoming companion articles. An appendix with omitted proofs and advanced examples is available as an electronic supplement to this article.

2

Theory of Bialgebras

This section introduces the basic concepts of bialgebraic semantics. The notation follows [3] in many, but not all aspects. Definition 1 (Algebra). Let Σ be an endofunctor. A pair (X, x) where X is an object and x : ΣX → X is called a Σ-algebra. Let (W, w) and (X, x) be two Σ-algebras. A morphism f : W → X is called a Σ-algebra homomorphism iff f ◦ w = x ◦ Σf . We write f : w → x in this case. A Σ-algebra (A, α) such that there is a unique homomorphism x? : α → x into every other Σ-algebra is called initial. Definition 2 (Coalgebra). Let B be an endofunctor. A pair (Y, y) where Y is an object and y : Y → BY is called a B-coalgebra. Let (Y, y) and (Z, z) be two B-coalgebras. A morphism f : Y → Z is called a B-coalgebra homomorphism iff Bf ◦ y = z ◦ f . We write f : y → z in this case. A B-coalgebra (Ω, ω) such that there is a unique homomorphism y! : y → ω from every other B-coalgebra (Y, y) is called final. Definition 3 (Distributive Law). Let Σ, B be two endofunctors. A natural transformation λ : ΣB ⇒ BΣ is called a distributive law of Σ over B, or just Σ/B-distributive law. Lemma 1. Let λ be a Σ/B-distributive law. Then 1. for each Σ-algebra (X, f ) there is a Σ-algebra (BX, Bf ◦ λX ), 2. for each B-coalgebra (Y, g) there is a B-coalgebra (ΣY, λY ◦ Σg).

Distributive-Law Semantics for Cellular Automata and Agent-Based Models

3

Definition 4 (Lifting). Let λ be a Σ/B-distributive law. Let (X, f ) be a Σalgebra and (Y, g) be a B-coalgebra. We call 1. B λ f = Bf ◦ λX the behavioral lifting of f , 2. Σλ g = λY ◦ Σg the syntactic lifting of g. Definition 5 (Bialgebra). Let λ be a Σ/B-distributive law. A triple (X, f, g) is called a λ-bialgebra iff 1. (X, f ) is a Σ-algebra, 2. (X, g) is a B-coalgebra, and 3. any of the following three, equivalent properties holds: (a) f : Σλ g → g,

ΣX

(b) g : f → B λ f , or

Σg

(c) the following diagram commutes.

 ΣBX

f

/ X

g

/ BX O Bf

λX

/ BΣX

A morphism that is a homomorphism on both the algebra and the coalgebra part of two λ-bialgebras is called a λ-bialgebra homomorphism. Initial and final bialgebras are defined in the obvious way. The following results are trivial when the free monad of Σ and the cofree comonad of B are considered instead [7]. But we consider the bare functors precisely because we are interested in behavior with bounded spatio-temporal context. Without reference to the additional structure, an explicit proof is in order; cf. appendix. Lemma 2. Let λ be a Σ/B-distributive law. Each initial Σ-algebra extends uniquely to an initial λ-bialgebra. Lemma 3. Dually, let λ be a Σ/B-distributive law. Each final B-coalgebra extends uniquely to a final λ-bialgebra. Theorem 1. Let λ be a Σ/B-distributive law. For each initial Σ-algebra (A, α) and final B-coalgebra (Ω, ω) there is a unique morphism h : A → Ω that is a λ-bialgebra homomorphism. Proof. Combines the previous lemmata. Each initial Σ-algebra (A, α) extends to a unique initial λ-bialgebra A, α, (B λ α)? . Each final B-coalgebra (Ω, ω) extends to a unique λ-bialgebra Ω, (Σλ ω)!, ω . Then there is a λ-bialgebra homomorphism h : A → Ω that is unique by both initiality and finality; cf. appendix. t u Definition 6 (Bialgebraic Semantics). The homomorphism induced by the preceding theorem is called the bialgebraic semantics of the distributive law λ. It is unique up to the unique isomorphisms between initial Σ-algebras or final B-coalgebras. In this section, we have reviewed the basic notions of bialgebraic semantics, most notably the unique homomorphisms that arise from initial algebras and final coalgebras, and the lifting operations that arise from a distributive law.

4

3

Baltasar Tranc´ on y Widemann and Michael Hauhs

Syntax

The global state of a CA is composed of local states arranged in a discrete n-dimensional structure, usually a regular grid, but possibly with a nontrivial topology. We restrict our considerations to the most common case, n = 2, although the approach should be generalizable in a straightforward way. We allow for the syntactic description of the regular grid by a lifting operation singleton for local states, and binary combining operations beside and above for global states. As a simple, but instructive case of nontrivial topology, we add unary operations vwrap and hwrap for connecting opposite edges of a grid. The resulting syntax functor ΣL , for some local state space L, is shown in Table 1. We use the graphic notation both for elements of ΣL X and for elements of initial ΣL -algebras. To avoid unneccessary parentheses, it is implied that ↔ and l bind stronger than |, which binds stronger than /. Real-world implementations of CAs and ABMs usually allow wrapping operations only at the outermost level of spatial syntax: The world can be a rectangle (unwrapped), cylinder (wrapped in one dimension) or torus (wrapped in both dimensions). We allow for full compositionality of the syntax; combining and wrapping operations can be nested in any order. For instance, a trouser-shaped world can be constructed out of three rectangles A, B, C by writing A↔ /B ↔ |C ↔ . In this section, we have defined a syntax for denoting both the current (spatially distributed) state of a CA and its topology. Departing from conventional modelling frameworks for CAs, we have made the syntax fully compositional, with every operation applicable at any level. Although our syntax deals only with certain regular shapes in two-dimensional space, generalization to other topological shapes and dimensions is possible. For instance, two-dimensional context-sensitive Lindenmayer systems, where the grid grows locally over time, for instance used for forest growth models [4], could be formalized analogously.

4

Static Semantics

It is straightforward to give a semantic interpretation for the fragment of syntax that excludes wrapping operations: The semantic domain consists of ordinary finite, rectangular matrices over L. One must merely decide how to handle the combination of incompatible shape (different heights in beside, different widths in above). In the presence of wrapping, however, things become more complicated. We shall introduce semantic interpretations stepwise in the following two subsections. Definition 7 (World Functor). The world functor W takes a local state space L to initial ΣL -algebras W L = (AL , αL ) and acts on singletons: ↔ ↔ W f (x | y) = W f (x) | W f (y)    W f (x ) = W f (x) W f [a] = f (a)  l W f (xl ) = W f (x) W f (x / y) = W f (x) / W f (y) We write W L for the carrier AL where the initial operation is not relevant. We call an element x ∈ W L a world state over L.

Distributive-Law Semantics for Cellular Automata and Agent-Based Models

4.1

5

Flat Semantics

Any world can be represented approximately as a rectangular matrix, ignoring topological details. We take the local state space L to be pointed, that is, L is nonempty and there is a distinguished element ? ∈ L. We define the rectangular shape and content of the interpretation of syntactic expressions by operations wd (width), ht (height) and sl (select).

wd : W L → N  wd [a] = 1

ht : W L → N  ht [a] = 1

wd (x↔ ) = wd (x)

ht(x↔ ) = ht(x)

wd (xl ) = wd (x)

ht(xl ) = ht(x)

wd (x | y) = wd (x) + wd (y)

ht(x | y) = ht(x) t ht(y)

wd (x / y) = wd (x) t wd (y)

ht(x / y) = ht(x) + ht(y)

where t is the usual maximum operator. The sl operation has dependent type, for all x ∈ W L: sl (x) : ht(x) × wd (x) → L

sl (x↔ )(i, j) = sl (x)(i, j)

sl (a)(0, 0) = a sl (xl )(i, j) = sl (x)(i, j)   i < ht(x), j < wd (x) sl (x)(i, j)  sl (x | y)(i, j) = sl (y) i, j − wd (x) i < ht(y), j ≥ wd (x)   ? otherwise   i < ht(x), j < wd (x) sl (x)(i, j)  sl (x / y)(i, j) = sl (y) i − ht(x), j i ≥ ht(x), j < wd (y)   ? otherwise Note that: 1. Selection coordinates are of the form (row , column) and zero-based. 2. We write n for the set {k ∈ N | 0 ≤ k < n}. 3. Composition of submatrices of incompatible shapes results in padding of the smaller one with ?. 4. All matrices constructed from syntactic expressions are nonempty. 5. All operations are natural in L. We write sl ? for a totalized selection operation with ( sl (x) (i, j) ∈ ht(x) × wd (x), ? sl (x)(i, j) = ? otherwise . We call expressions x, y such that sl ? (x) = sl ? (y) similar, writing x ≈ y.

6

Baltasar Tranc´ on y Widemann and Michael Hauhs

(−1, 0)

(−1,−1) (−1, 0) (−1,+1)

j

(0, −1) i

j

(0, −1) (0, +1)

i

(+1,−1) (+1, 0)

(0, +1)

(+1,+1) (+1, 0)

Fig. 1. Common neighborhood shapes in two-dimensional grids, with axes and chart coordinates relative to the grey center cell. Left: von Neumann neighborhood (4 neighbors). Right: Moore neighborhood (8 neighbors).

4.2

Context and Template

In a two-dimensional CA, each cell may interact only locally with a particular neighborhood. See Fig. 1 for the most common shapes; a comprehensive survey may be found in [8]. We shall use the von Neumann neighborhood shape as the running example throughout this article. Each shape may be specified by a simple data structure. The semantics of wrapping operations can then be given in terms of that structure. Definition 8 (Context, Template). A context is a pair C = (C, γ) of 1. a set functor C acting as a datatype constructor for collections of neighbor cells; for a neighborhood of n cells, simply put CX = X n , 2. a distributive law γ : C ] W → W C ] , where C ] is the C-template functor: C ] X = CX × X

C ] f = Cf × f

We write c`x for (c, x) to emphasize that (c, x) ∈ C ] X is a template element, calling x the center. Such a law γ transforms a template of worlds, namely the actual center world, surrounded by a global neighborhood of “phantom” worlds representing boundary conditions, into a world of templates of every cell embedded in its local neighborhood, thus enabling local transitions; see Fig. 2 for an example. The following axioms must hold for a context: (C1) γ preserves the shape of the center: for all c ∈ CW 1; x ∈ W 1  W † γ1 (c ` x) = x where 1 is a singleton set and † is the unique map † : C ] 1 → 1. (C2) γ does not distinguish similar neighborhoods: for all c1 , c2 ∈ CW L; x ∈ W L Csl ? (c1 ) = Csl ? (c2 ) =⇒ γL (c1 ` x) = γL (c2 ` x) .

Distributive-Law Semantics for Cellular Automata and Agent-Based Models c

a

b

c

d

I

J m n

e

f

g

h K L

f

o

p

I

7

d J

I

J m

K

L

I

J

γ

7−→

q

r

h K L

s

t

q

K L

o

r

Fig. 2. Distribution of von Neumann template over a flat world. The (2 × 2)-shape is preserved; cf. axiom (C1).

The white part of each diagram in Fig. 1 defines a context, namely the shape C and the neighborhood distribution law γ. The center of C ] corresponds to the grey middle cell. Example 1. The distributive law for the von Neumann neighborhood shape is sketched by an example application in Fig. 2. The context functor is CX = X 4 . For a general technique how to derive a distributive law γ from the given coordinate specifications see next subsection. Definition 9 (Update). Let C = (C, γ) be a context. A C ] -algebra (L, u) is called a C-update on L. Example 2. The CA for a diffusion system (discrete counterpart of the heat equation u˙ = α∆u) requires the von Neumann context CX = X 4 and is defined by the update dα (a, b, c, d ` e) = e + α · (a + b + c + d − 4e), where the parenthesis is the discrete Laplace operator. The CA for Conway’s Game of Life requires the Moore context CX = X 8 and is defined by the update  P  1 P ai = 3, v(a1 , . . . , a8 ` b) = b ai = 2,   0 otherwise . Lemma 4. Behavioral lifting for any context C = (C, γ) maps C-updates on local states L canonically to C-updates on world states W L. u : C ] L → L =⇒ W γ u : C ] W L → W L Definition 10 (Globalization). Let C = (C, γ) be a context. We call the Cupdate (W L, W γ u) the C-globalization of the C-update (L, u). Example 3. Reconsider Fig. 2; for the special case of linear forms u, such as the diffusion system from Example 2, the globalized operation W γ u = W u ◦ γL is also a rather high-level specification of a familiar array-programming technique called convolution with a stencil/kernel.

8

4.3

Baltasar Tranc´ on y Widemann and Michael Hauhs

Regular Contexts

Distributive laws for contexts are hard to define directly in practice. The reader is invited not to be deceived by the simplicity of Fig. 2, but to try and give a complete distributive law, dealing with (nested) wrapping as well, for the von Neumann neighborhood shape. The matter is simplified by reconsidering the relative coordinates in Fig. 1. Assume that for a context C = (C, γ), relative coordinates are given as a chart χ ∈ CZ2 . By adding the coordinates of the grey center cell componentwise, the absolute coordinates of neighbor cells are obtained. There are two cases: 1. The absolute coordinates of a neighbor are within the the center world: The internal neighbor is selected from the center. 2. The resulting coordinates are outside the the center: The external neighbor is selected from the appropriate context component. For certain contexts C = (C, γ), we can define an operation sl + that extends the selection operation sl to external neighbors, thus unifying the cases. sl + operates on world templates instead of single world states  and has dependent type, for all (c ` x) ∈ C ] W L, sl + (c ` x) : ht(x) × wd (x) ⊕ Dχ → L where Dχ , the domain ofχ, is the set of elements in χ, and ⊕ denotes the elementwise sum X ⊕ Y = (a + c, b + c) (a, b) ∈ X; (c, d) ∈ Y . We require that sl + be natural in L. Given a chart χ and an extended selection sl + , we can implement a distributive law. Definition 11 (Relocation). Let C be a context functor with chart χ ∈ CZ2 . The relocation map is a natural transformation χ bL : W L → W C ] Z2 defined as    χ bL [a] = χ ` (0, 0)   ↔  χ bL (x↔ ) = W C ] fx χ bL (x) fx (i, j) = i, j % wd (x)   l  χ bL (xl ) = W C ] gx χ bL (x) gx (i, j) = i % ht(x), j   χ bL (x | y) = χ bL (x) | W C ] hx χ bL (y) hx (i, j) = i, j + wd (x)   χ bL (x / y) = χ bL (x) / W C ] kx χ bL (y) kx (i, j) = i + ht(x), j where % is the usual remainder operator. This map assigns to a world w of arbitrary state a world of templates, each containing just the coordinates of the cells of w relevant for a single neighborhood.  Lemma 5. The relocation map preserves the shape of its input: W ‡ χ b1 (x) = x, where 1 is a singleton set and ‡ is the unique map ‡ : C ] Z2 → 1. Example 4. A possible specification of von Neumann neighborhoods with CX = X 4 , namely the one given in Fig. 1, is given as follows.  1. A chart: χ = (−1, 0), (0, +1), (+1, 0), (0, −1) . In prose, von Neumann neighbors are represented in the order north, east, south, west. Of course, every permutation is equally valid. The domain is Dχ = (−1, 0), (0, +1), (+1, 0), (0, −1) in any case.

Distributive-Law Semantics for Cellular Automata and Agent-Based Models

9

2. An extended selection:   ?  sl (n) i + ht(n), j     sl ? (e) i, j − wd (x)   + sl (n, e, s, w ` x)(i, j) = sl ? (s) i − ht(x), j     sl ? (w) i, j + wd (w)    sl ? (x)(i, j) = sl (x)(i, j)

i < 0, j ≥ wd (x), i ≥, ht(x) j < 0, otherwise .

where the first four cases are the subcases of external neighbors, and the last case covers internal neighbors. Note that the external cases do not overlap because of the type restriction given above.  Consider the (2 × 2)-torus with the flat matrix interpretation ac db defined for ↔l instance by t = [a] | [b] / [c] | [d] . The relocation function χ b for the von Neumann context yields a world r = χ b(t) of the same shape, but populated with von Neumann contexts of coordinates in the range wd (t) × ht(t) = 2 × 2. The elements  of t can be substituted for their coordinates by considering s = W C ] sl (t) (r), as depicted in Fig. 3. In the above example, cells have only internal neighbors because of wrapping. In the general case, external neighbors and extended selection are required. Theorem 2. A chart χ and extended selection operation sl + for a context functor C induce a distributive law and hence a context C = (C, γ).   γL (c ` x) = W C ] sl + (c ` x) χ bL (x) 4.4

Compositional Contexts

Definition 12. A context C = (C, γ) is called compositional iff it admits a lifting of each syntactic operation over context formation, namely a collection of natural transformations CW L → CL

cosingleton L : cohwrap L , covwrap L :

W L × CW L → CW L

cobeside L , coabove L : W L × W L × CW L → CW L × CW L such that, for all local updates (L, u) and their globalized counterparts g = W γ u:    u(cosingleton L (c) ` a) = g c ` [a] g(cohwrap L (x, c) ` x)↔ = g(c ` x↔ ) g(covwrap L (x, c) ` x)l = g(c ` xl ) g(c1 ` x1 ) | g(c2 ` x2 ) = g(c ` x1 | x2 )

(c1 , c2 ) = cobeside L (x1 , x2 , c)

g(c1 ` x1 ) / g(c2 ` x2 ) = g(c ` x1 / x2 )

(c1 , c2 ) = coabove L (x1 , x2 , c) (1)

10

Baltasar Tranc´ on y Widemann and Michael Hauhs

These operations are not quite uniquely determined: Since the split operations act only on external neighbors, and only under a map W γ u = W u ◦ γ, see equations (1), a loose specification up to similarity suffices thanks to context axiom (C2). See Figures 4, 5 for illustrations. Space does not permit to give a full set of compositionality laws, say, for the von Neumann context here; cf. appendix. In this section, we have formalized the context sensitivity of CAs for a variety of topologies. To this end we have introduced the notion of context and template functors to create data structures that accumulate the state of a neighborhood. We have defined local behavior of CAs (updates) as algebras of the template functor and their globalization as the behavioral lifting arising from a distributive law of context over worlds. We have addressed the problem of specifying a suitable distributive law by giving relative addresses of neighbors and a universal syntax-directed relocation procedure. Finally, we have investigated compositionality of contexts in the sense that syntactic composition can be lifted from the center of a world template over a globalized update. Together with the behavior functor to be defined in the next section, this compositionality will yield the desired spatio-temporal distributive law.

5

Behavior

Definition 13 (Behavior Functor). Let S be a set and C = (C, γ) a context. We call the following functor the C-behavior functor with observable state S: BSC X = S × X CS

BSC f = idS × (f ◦ )

of the left product functor S × and the The functor BSC is the composition  covariant hom-functor Hom CS, , whose function part we abbreviate as (f ◦ )  for Hom CS, (f ). The functor BSC is also the signature of deterministic Moore automata with input CS (context of state) and output S. We write s . t for (s, t) to emphasize that (s, t) ∈ BSC X is a behavior element. We also omit parentheses by having . bind less strongly than function composition ◦. Let (X, g) be a BSC -coalgebra. The prose reading of an equation g(x) = s . t is as follows: The automaton specified by (X, g), when in state x ∈ X, outputs s ∈ S and, for any input c ∈ CS, transits to state t(c) ∈ X. Definition 14 (Update Coalgebra). Let C = (C, γ) be a context. Let u be a C-update on S. The structure (S, u. ) where  u. (s) = s, u( ` s) is a BSC -coalgebra. Hence, the automaton specified by (S, u. ), when in state s, outputs s and transits to state u(c`s) for any input c. In other words, update coalgebras specify automata that transduce boundary conditions to observable global state of a system. The overall behavior of the automaton is given by the unique BSC -coalgebra homomorphism u. ! : S → Ω.

Distributive-Law Semantics for Cellular Automata and Agent-Based Models

11

Table 1. Syntax functor ΣL

(Textual) singleton hwrap vwrap beside above ↔ l (Graphic) [ ] | / (Objects) ΣL X = L + X + X + (X × X) + (X × X) (Morphisms) ΣL f = idL + f + f + (f × f ) + (f × f )

c b

d

a

d b

a

b

c

d

a

b

c

d

c

a

d

a

c

b

Fig. 3. Von Neumann neighborhoods on a (2 × 2)-torus, constructed by relocation.

a

b

a

b

c

d

c

d

I

J m n

I

J

e

f

g

h K L

o

I

7−→

p

J

I

J

K L K L K L

q

r

q

r

s

t

s

t

Fig. 4. cohwrap acting on von Neumann neighborhood of flat (2 × 2)-world.

a

b

c

d

I

J m n

e

f

g

h K L

a

b

c o

p

7−→

I

d

e

f

J

g

h K L

I

J m n

K L

q

r

q

r

s

t

s

t

o

p

Fig. 5. cobeside acting on von Neumann neighborhood of flat (2 × 2)-world.

12

Baltasar Tranc´ on y Widemann and Michael Hauhs

Note that we have adopted the convention that the local state of CAs be public, formally by returning s as the output component of u. (s). We could introduce some privacy, and more behavioral equivalence, by outputting o(s) for some observation function o instead. In this section, we have defined a behavior functor for CAs, seen as Moore automata that consume context of state (boundary conditions) and output the current state. Updates, by construction template algebras, can be massaged into behavioral coalgebra shape. The corresponding anamorphism gives the semantic objects of automaton behavior.

6

Distributive Law

Let C = (C, γ) be a compositional context. Let L be a pointed set with default C element ?. Let u be a C-update on L. Our task is now to give a ΣL /BW Ldistributive law that encodes the update u “properly”, preferrably in a generic way. Though we adopt a notation in the style of SOS, the focus is on certain distributive laws, and rule formats are considered only as a means of visualization. Definition 15 (Rule Format). We define a rule of the form s

1 x1 −→ y1

···

s

n xn −→ yn

s

k(x1 , . . . , xn ) − →y d

where x1 , . . . , xn , y1 , . . . , yn , s1 , . . . , sn are variables, s is an expression possibly depending on s1 , . . . , sn , y is an expression possibly depending on y1 , . . . , yn , k is a n-ary syntactic operation, and d is a (n + 1)-ary function, to denote a clause of a distributive law λ:  λ k(s1 . t1 , . . . , sn . tn ) = s . l ◦ (t1 × · · · × tn ) ◦ d(s1 , . . . , sn , ) where l(y1 , . . . , yn ) = y . The prose reading of this formula is rather involved: Consider n subsystems. If they are composed according to the syntactic operator k, the composite system, when in joint state (x1 , . . . , xn ), 1. outputs s, depending on each of the individual outputs si for individual state xi of the i-th subsystem, and 2. for input c transits to state y, where for each yi the post-state ti (ci ) of the i-th subsystem for state xi and input ci is substituted. The subinputs ci are projected from (c1 , . . . , cn ) = d(s1 , . . . , sn , c). Note that Moore automata allow the computation of output independently of input; hence there is no vicious circle here. Theorem 3. If the following properties hold, then a law specified in this format is natural. 1. The rules are complete: Every syntactic operation k is covered.

Distributive-Law Semantics for Cellular Automata and Agent-Based Models

s

x− →y s↔

x↔ −−−−−→ y ↔ cohwrap

  [a] [a] −−−−−−−→ u( ` a) cosingleton

g

x− →y sl

xl −−−−−→ y l covwrap

s

1 x1 −→ y1

13

s

2 x2 −→ y2

s1 |s2

x1 | x2 −−−−−→ y1 | y2 cobeside

s

1 x1 −→ y1

s

2 x2 −→ y2

s1 /s2

x1 / x2 −−−−→ y1 / y2 coabove

Fig. 6. Rules defining the spatio-temporal distributive law λu of cellular automaton with dynamics u.

2. Each rule is well-typed: s1 , . . . , sn ∈ W L t1 , . . . , tn : CW L → X lX ◦ (t1 × · · · × tn ) ◦ d(s1 , . . . , sn , ) : CW L → ΣL X 3. Each rule is syntactically natural: ΣL h ◦ lX = lY ◦ hn for all h : X → Y . Fig. 6 shows the rules that define λu . The leftmost is actually a rule scheme with one instance for each a ∈ L. The rules amount to the following equations:  λuX [a] = [a] . singleton X ◦ u( ` a) ◦ cosingleton L  λuX (s . t)↔ = s↔ . hwrap X ◦ t ◦ cohwrap L (s, )  λuX (s . t)l = sl . vwrap X ◦ t ◦ covwrap L (s, )  λuX (s1 . t1 ) | (s2 . t2 ) = (s1 | s2 ) . beside X ◦ (t1 × t2 ) ◦ cobeside L (s1 , s2 , )  λuX (s1 . t1 ) / (s2 . t2 ) = (s1 / s2 ) . above X ◦ (t1 × t2 ) ◦ coabove L (s1 , s2 , ) (2) We subscript the syntactic operations to emphasize that they are used as natural injections. It is easy to verify that these rules satisfy the naturality conditions of Theorem 3. In this section, we have introduced a rule format similar to well-known SOS formats for our particular behavior functor. A distributive law that deals with globalization of updates in a step-wise fashion, focusing on spatio-temporal tradeoff, can be specified in that format. The generality of the rule format is not considered. The law is structured in terms of careful pairing of syntactic constructions and their context-transforming duals. It is generic in the sense that the local update affects only the singleton rule. Generalization to other syntactic functors is straightforward.

7

Equivalence

Whereas the globalization of an update reflects the array programming style of loops, the distributive-law encoding reflects the recursive programming style of divide-and-conquer. The following theorem states that both styles are equivalent.

14

Baltasar Tranc´ on y Widemann and Michael Hauhs Σ(B o ΣBA 

A (W γ u).





 

j



BA

Bj

/ Ω   ω 

/ BΩ

λA





 



 



 



λ



BΣA

/ ΣΩ      (Σλ ω)!   α    h / A Ω    λ ω   (B α)?    / BA / BΩ o

α)?



ΣA 

/ ΣBΩ       λΩ    

Σh

Σω

Bh

B(Σλ ω)!

BΣΩ

C u u u Fig. 7. Diagrams of Theorem 4. We abbreviate ΣL , BW L , λ , h and j by dropping their fixed super- and subscripts.

Theorem 4. Globalized updating of a world template is equivalent to bialgebraic semantics induced by the spatio-temporal distributive law given above: Let C = (C, γ) be a compositional context. Let W L = (A, α) be an initial ΣL C u algebra and (Ω, ω) a final BW L -coalgebra. Let u be a C-update on L. Let j = C γ . u C (W u) ! be the associated globalized semantics. Let λ : ΣL BW L ⇒ BW L ΣL be the distributive law induced by u. Let hu : A → Ω be the associated bialgebraic semantics. Then j u = hu . Proof. Show that (W γ u). forms a λu -bialgebra with α, that is (W γ u). ◦ α = Bα◦λuA ◦Σ(W γ u). . This can be verified by syntactic case distinction, combining the equations of compositionality (1) and distributivity (2); cf. appendix. It follows by initiality that (W γ u). = (B λ α)?, and hence by finality that j u = hu . t u In this section, we have identified the two definition styles for a global update function, each defined by a distributive law, with two prominent programming styles for grid-based computations, namely loops and divide-and-conquer. We have demonstrated their equivalence by a straightforward bialgebraic, inductivecoinductive argument.

8

Conclusion

The class of ABMs is defined operationally as the class of program behavior that can be achieved within certain programming environments. There appears to be some consensus about what constitutes a well-behaved ABM, but only implicitly in the form of documentation standards [2], not by rigorous semantical criteria. Environments for agent-based modelling are based on a virtual world that can be represented abstractly as a cellular automaton. We conjecture that a reasonable approximation of the notion of a well-behaved ABM can be given

Distributive-Law Semantics for Cellular Automata and Agent-Based Models

15

by requiring that its behavior be expressible as a global update with a simple neighborhood shape. Coalgebraic formalisation of behavior has so far been largely restricted to computer science, with notable exceptions in physics. Here we showed that twodimensional CAs and hence many ABMs can concisely be presented in this language. In a companion article (in prep.) we demonstrate how to implement the bialgebraic framework and reproduce the results of a particular ABM of ecological phenomena in the functional programming language Haskell. In many disciplines CAs and ABMs have been used as tools for studying complex systems, i.e. systems in which the complex states can be recursively constructed from simple building blocks with persistent features. The present analysis demonstrates that this may only be part of a bigger picture: Bialgebras offer a second possibility of interpretation in which the focus is on corecursive unfolding of behavior. In another companion article (in prep.) we explore the epistemological and methodological implications of the dual viewpoints of the bialgebraic theory. Acknowledgments This work has been inspired by Bartek Klin’s talks and writing on SOS. Jan Rutten and Milad Niqui have provided valuable feedback on earlier stages of the work, which helped considerably to shape this article.

References 1. Bartels, F.: On Generalised Coinduction and Probabilistic Specification Formats. Phd thesis, Vrije Universiteit Amsterdam (2004) 2. Grimm, V., Berger, U., Bastiansen, F., Eliassen, S., Ginot, V., Giske, J., GossCustard, J., Grand, T., Heinz, S., Huse, G., Huth, A., Jepsen, J., Jrgensen, C., Mooij, W., Mller, B., Peer, G., Piou, C., Railsback, S., Robbins, A., Robbins, M., Rossmanith, E., Rger, N., Strand, E., Souissi, S., Stillman, R., Vab, R., Visser, U., DeAngelis, D.: A standard protocol for describing individual-based and agent-based models. Ecological Modelling 198, 115–126 (2006) 3. Klin, B.: Structural operational semantics and modal logic, revisited. Electr. Notes Theor. Comput. Sci. 264(2), 155–175 (2010) 4. Kurth, W., Sloboda, B.: Growth grammars simulating trees. Silva Fennica 31, 285– 295 (1997) 5. Kurz, A.: Logics for Coalgebras and Applications to Computer Science. Phd thesis, Ludwig-Maximilians-Universit¨ at M¨ unchen (2000) 6. Rutten, J.J.M.M.: Universal coalgebra: a theory of systems. Theor. Comput. Sci. 249(1), 3–80 (2000) 7. Turi, D., Plotkin, G.: Towards a mathematical operational semantics. In: Proceedings 12th International Conference on Logic in Computer Science (LICS). pp. 280– 291. IEEE (1997) 8. Tyler, T.: Cellular automata, http://cell-auto.com/neighbourhood/