<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Understanding Safety Constraints Coalgebraically</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Theoretical and Applied Computer Science School of Mathematics and Computer Science V.N. Karazin Kharkiv National University 4</institution>
          ,
          <addr-line>Svobody Sqr., Kharkiv, 61022</addr-line>
          ,
          <country country="UA">Ukraine</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Safety constraints are crucial to the development of missioncritical systems. The practice of developing software for systems of this type requires reliable methods for identifying and analysing project artefacts. This paper proposes a coalgebraic approach to understanding behavioural constraints for systems of a kind. The advantage of the proposed approach is that it gives a framework for providing abstract semantic models of the domain-specific languages designed for specifying behavioural constraints.</p>
      </abstract>
      <kwd-group>
        <kwd>behavioural constraint</kwd>
        <kwd>safety constraint</kwd>
        <kwd>coalgebra</kwd>
        <kwd>final coalgebra</kwd>
        <kwd>coalgebraical semantic model</kwd>
        <kwd>final semantics</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>A lot of modern technical systems are compound and smart. Moreover, they are
hybrid in the sense that ones consisted of both physical and cybernetic
(software) components. In other words, we can state that modern technical systems
of such a kind are cyber-physical systems (see, for example, [11]). This requires
the corresponding approaches to designing these systems. First of all, we need to
remark that software complex of such a system contains necessarily reactive
components i.e. programs intending rather for providing the required behaviour of
the system than for handling data [12]. This is because of the incorrect behaviour
of a complex technical system can have serious and some times catastrophic
consequences for the system surroundings. Thus, we should classify such systems as
safety-critical [4]. As well-known, specification and analysis of the behavioural
requirements is the most critical phase under safety-critical systems development
process [7] taking into account the fact that a most of system faults and errors
are consequences of incorrect specifications or of incomplete analysis. Hence,
we need a dependable and mathematically grounded toolkit for specifying and
analysing behavioural constraints for designing such systems.</p>
      <p>This paper introduces some general framework for constructing rigorous
models of safety constraints, which can be used for constructing domain-specific
languages for specifying safety constraints. This framework can be included as a
component of the mentioned above development toolkit.</p>
      <p>In the paper, we use coalgebraic techniques as the main research
methodology. This choice is motivated by the fact that universal coalgebras give an
adequate mathematical tool for modelling behaviour of systems [13,9].</p>
      <p>Sec. 2 introduces the needed notions and notation for sequences of system
notifications.</p>
      <p>For completeness and reader convenience, we have collected the used
coalgebraic concepts in Sec. 3.</p>
      <p>Sec. 4 is devoted to studying concrete endofunctors and properties of the
coalgebras corresponding to these endofunctors related to safety constraints.</p>
      <p>Finally, Sec. 5 is the central section of the paper. It contains definitions of
the target constructions and results providing achieving of the claimed goals.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Basic Concepts and Notation</title>
      <p>In this section, we assume that X is a finite set with at least two elements.
Elements of this set are usually interpreted as system notifications.</p>
      <p>A mapping (generally speaking partial) s : N ! X is called an X-sequence
if for any k 2 N, s k0 is defined whenever s k is defined and 0 k0 &lt; k.</p>
      <p>An X-sequence s is called an X-word if there exists k 2 N such that s k is
undefined; in contrast, an X-sequence s is called a X-stream if s k is defined
for all k 2 N.</p>
      <p>We use the notation X for referring to the set of all X-words, and XN for
referring to the set of all X-streams. The set X contains the sequence defined
nowhere, which is below denoted by .</p>
      <p>We use also the notation X1 for referring to the set X S XN, and X+ for
referring to the set of all X-words without the word defined nowhere.</p>
      <p>For an X-word u, we denote by juj the minimal natural number such that
u juj is undefined.</p>
      <p>The value juj where u 2 X is called length of u.</p>
      <p>As usually, we identify n 2 X with the X-word u 2 X such that u 0 = n
and u k is undefined if k &gt; 0.</p>
      <p>For u 2 X and s 2 X1, we denote by us the next X-sequence
us =
For s 2 X1 and m 2 N, we denote by sm:: the next X-sequence
sm:: =
s(k + m) if this value is defined
is undefined otherwise
Also for s 2 X1 and m; l 2 N, we denote by sm::l the next X-word
sm::l =
s(k + m) if this value is defined and k &lt; l
is undefined otherwise
m</p>
      <p>The principal concepts for our studying is given by the following definitions</p>
      <sec id="sec-2-1">
        <title>Definition 1. A subset P</title>
        <p>P whenever 0 m &lt; juj.</p>
        <p>X is called prefix-free if u 2 P ensures u0::m 2=
Remark 1. If a prefix-free subset of X contains then this subset is f g. Indeed,
if a prefix-free subset of X contains both and another X-word u then u0::0 =
cannot belong to this subset. This contradiction grounds the remark.
Definition 2 (see [2]). A safety constraint is a subset S
s 2 S if for any m 2 N, s0::m = s00::m for some s0 2 S.</p>
        <sec id="sec-2-1-1">
          <title>XN such that</title>
          <p>3</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Coalgebras Preliminaries</title>
      <p>In this section, we remind the basic definitions and facts related to the concept of
a coalgebra in an arbitrary category. In addition, we give some specific concepts
in the case when C = Set.</p>
      <p>Thus, we assume the category C and the endofunctor F of C are given and
held fixed in this section (general information on category theory can be found
in [10,3]).</p>
      <p>Definition 3. A morphism a of C is called an F -coalgebra if the equality
cod a = F (dom a) is fulfilled. In the case, dom a is called the carrier of a and
denoted below by a.</p>
      <p>Definition 4. Let a and b be F -coalgebras then a morphism f : a ! b is called
an F -morphism from a into b (symbolically, f : a ! b) if the diagram
a
a
F a
f
F f
b</p>
      <p>b
F b
commutes
or, equivalently, the equation (F f ) a = b f holds.</p>
      <p>Proposition 1. The class of F -coalgebras equipped with F -morphisms is a
category denoted usually by CoalgF (C) or CoalgF if the category C is clear from
the context.</p>
      <p>Final objects of this category are very important for constructing semantic
models of programming and specification languages.</p>
      <sec id="sec-3-1">
        <title>Definition 5.</title>
        <p>
          (
          <xref ref-type="bibr" rid="ref1">1</xref>
          ) A terminal object of CoalgF if it exists is called a final F -coalgebra, which
is denoted by nF .
(
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) For any F -coalgebra a, the unique F -morphism from a into nF is called an
anamorphism and denoted by (a) .
        </p>
        <p>The concept of bisimulation is a key concept in the theory of universal coalgebras.
Definition 6 (see P. Aczel and N. Mendler [1]). A bisimulation of F
coalgebras a and b is a span a ra r r!b b in category CoalgF (C) such that the
span a ra r r!b b in category C is a mono-span i.e. the validity of rah0 = rah00
and rbh0 = rbh00 for any object c in C and morphisms h0; h00 : c ! r ensures
h0 = h00.</p>
        <p>The next proposition demonstrates that coalgebra morphisms give the simplest
examples of bisimulations.
span a ida a !f b is a bisimulation of a and b.</p>
        <p>Proposition 2. For any F -coalgebras a and b and F -morphism f : a ! b, the
Proof. We need to note only that the span a ida a !f b is evidently a
monospan.
tu
Proposition 3. Assume that category C is finitely complete and there is a final
F -coalgebra then for any bisimulation a ra r r!b b of F -coalgebras a and b,
there exists a unique monomorphism f : r ! P such that ra = paf and rb = pbf
where a pa P p!b b is the pullback of the cospan a (a!) nF (b) b.
Proof. Indeed, the definition of an anamorphism ensures the commutativity of
the next diagram
ra
r
a
rb
(a)
b</p>
        <p>(b)
nF
i.e. for the pullback a pa P p!b b of the cospan a (a!) nF (b) b, we have the
existence of a unique morphism f : r ! P . One can see that this morphism is a
monomorphism taking into account the mono-span and pullback properties. tu
This statement can be inverted for some class of endofunctors.
nF
Proposition 4. If category C is finitely complete, endofunctor F preserves
pull(a)
!
backs, and there exists a final F -coalgebra then the pullback of the cospan a
(b)</p>
        <p>b is the greatest bisimulation of F -coalgebras a and b.</p>
        <p>Proof. Indeed, let a pa P p!b b be the mentioned above pullback then it is
mono-span and the next diagram
is a pullback diagram. Further, note that the outer square of the following
diagram commutes.</p>
        <p>pa</p>
        <p>P
a</p>
        <p>F pa</p>
        <p>F P
F a
9
a</p>
        <p>F pb
F (a)</p>
        <p>pb
F P</p>
        <p>F a
F pa</p>
        <p>F b</p>
        <p>F (b)
F nF
F pb
F (a)
b</p>
        <p>b
F b</p>
        <p>F (b)
F nF
Indeed,</p>
        <p>F (a) apa = (nF ) (a) pa
= (nF ) (b) pb
=</p>
        <p>F (b) bpb
considering that (a) is an F -morphism
using the pullback property for a pa P
considering that (b) is an F -morphism.
p!b b
Thus, taking into account the pullback property for the inner subdiagram in
the diagram above, one can derive the existence of ensuring the diagram
commutativity. But it means that the span a pa P p!b b can be lifted up to the
corresponding span of coalgebras.
tu
Another concept used below is the concept of subcoalgebra.</p>
        <p>Definition 7. Let a 2 CoalgF (C) and j : j ! a be a monomorphism in C with
the domain j then an F -coalgebra c is called a subcoalgebra of a if c = j and
j is lifted upto a coalgebraic monomorphism j : c ! a.</p>
        <p>We complete this section by enumerating a series of facts specific for the
category Set and endofunctors of this category. If C = Set then an F -coalgebra
is called an F -system due to J. Rutten [13] and the corresponding category is
denoted below by Sys(F ) instead of CoalgF (Set).</p>
        <p>
          It is well-known that category Set is finitely complete. The important class
of endofunctors of the category Set is called the class of polynomial endofunctors
and defined as follows (see, for example, [9])
(
          <xref ref-type="bibr" rid="ref1">1</xref>
          ) a constant endofunctor i.e. an endofunctor C X = C for some set C and
        </p>
        <p>
          C f = idC is a polynomial endofunctor;
(
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) if F 1 and F 2 are polynomial endofunctors then the endofunctor F X =
        </p>
        <p>
          F 1 X F 2 X and F f = F 1 f F 2 f is a polynomial endofunctor;
(
          <xref ref-type="bibr" rid="ref3">3</xref>
          ) if F 1 and F 2 are polynomial endofunctors then the endofunctor F X =
F 1 X + F 2 X and F f = F 1 f + F 2 f is a polynomial endofunctor (here and
below, “ +” refers to a disjunctive sum of sets).
        </p>
        <p>An important property of polynomial endofunctor is that such an endofunctor
preserves pullbacks.
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Systems as Coalgebras</title>
      <p>In this section, we introduce and study some endofunctors, systems related to
the endofunctors, and their property. Note that all considered here endofunctors
are polynomial.
4.1</p>
      <p>Discrete Dynamical Systems
The simplest manner for modelling a discrete dynamical system is to represent
it by a pair (X; g) where X is a set called the state set and g : X ! X is a
mapping called the dynamics.</p>
      <p>It is evident that g can be considered as IdSet-coalgebra of the category Set and,
in this context, X denoted by g.</p>
      <p>Morphisms of such coalgebras are mappings that intertwine the dynamics of the
corresponding coalgebras. More precise, for IdSet-coalgebras g and h, a morphism
f : g ! h is a mapping f : g ! h such that f g = hf .</p>
      <p>Easy seen that the final coalgebra exists in this case but it is trivial namely
nIdSet = 1 and nIdSet = id1. Thus, taking into account that category Set and
functor IdSet satisfy conditions of Prop. 4 one can conclude that any two
dynamical systems are bisimilar.</p>
      <p>A less trivial example is given by the endofunctor T : Set ! Set defined as
follows (here and below, 1 refers to an one-element set f+g containing a fault
indicator).</p>
      <p>T X = 1 + X for any object X of category Set;</p>
      <p>T f = id1 +f for any morphism f of category Set.</p>
      <p>A system of such a kind is called a system with termination.</p>
      <p>The corresponding class of morphisms (see Def. 4) from a T-system g into a
T-system h contains a mapping f : g ! h if and only if for any x 2 g, either
gx = + and h(f x) = + or gx 6= + and f (gx) = h(f x).</p>
      <p>There is a final nT in the category Sys(T). This object is structured as follows
nT = 1 + N
nT =
x 2 1 + N :
&lt;8 + if x = 0</p>
      <p>1 if x = 1
: x 1 otherwise
where 1 + N = N Sf1g
For a T-system g, the corresponding anamorphism (g) is defined as follows
(g) =
x 2 g :</p>
      <p>
        1 if g(k)x 6= + for all k 2 N+
minfk 2 N j g(k+1)x = +g otherwise
where
g(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
      </p>
      <p>= g
g(k+1) =
x 2 g :</p>
      <p>+ if g(k)x = +
g(g(k)x) otherwise
for k 2 N+:
Note 1. Everybody familiar with the concept of a monad can easily see that g(k)
is the kth-power of g in the corresponding Kleisli category.
4.2</p>
      <p>Systems with Output
In this subsection, we consider the class of dynamical systems equipped with a
mechanism for the external monitoring of the current system state. We use the
term a system with output for referring to a system of this class. Following
the coalgebraic approach, we model systems of this class as coalgebras, which
signature is defined by the corresponding endofunctor SN : Set ! Set that is
defined as follows</p>
      <p>SN X = N
SN f = idN</p>
      <p>X for any object X of category Set;
f for any objects X and Y of category Set and a morphism</p>
      <p>f : X ! Y .</p>
      <p>In this definition, N refers to a finite set of possible output values.</p>
      <p>Thus, a system with output is a mapping : ! SN where is a set
called usually the system state set. Taking into account the universality of the
product (see, [10, Sec. III.4] or [3, Sec. 2.4]), one can see that an SN-system
is uniquely represented as = h out; trii where out = prN : ! N and
tr = pr : ! called respectively the output and transition functions
of the system.</p>
      <p>The general coalgebraic framework (see Def. 4) gives the following concept
of an SN-morphism: for SN-system and , a mapping f : ! is called an
SN-morphism if ( out)f = out and ( tr)f = f ( tr).</p>
      <p>There is a final object nSN in the category Sys(SN). This object is structured
as follows
nSN
(nSN)out =
(nSN)tr =
= NN;
s 2 NN : s 0;
s 2 NN : k 2 N : s(k + 1).</p>
      <p>For an N-system
formula
( ) =</p>
      <p>Thus, the proposed model allows considering a point of the final N-system
carrier as an observed behaviour of the system being studied. It means that we
are interested in specifying and analysing constraints that allow distinguishing
an admissible and inadmissible system behaviour.</p>
      <p>, the corresponding anamorphism ( ) is defined by the next
4.3</p>
      <p>Detectors of Behavioural Violations
The remaining part of the paper is devoted to demonstrating that the safeness
of a subset can be described with using the category-theoretic language.</p>
      <p>In this subsection, we introduce some class of systems that used as a tool
for distinguishing admissible and inadmissible system behaviours. We refer to
systems of this class as detectors of behavioural violations.</p>
      <p>This class is determined with the endofunctor DN : Set ! Set defined as
follows</p>
      <p>DN X = (1 + X)N for any object X of category Set;
DN f = 2 (1 + X)N : n 2 N : (id1 +f )( n)</p>
      <p>for any objects X and Y of category Set and a morphism f : X ! Y .</p>
      <p>We call below a DN-system a detector and for a detector a, we refer to a as
to the detector state set.</p>
      <p>
        A detector morphism f from a detector a into a detector b is (compare with
Def. 4) a mapping f : a ! b such that for any x 2 a and n 2 N,
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) (ax) n = + if and only if (b(f x)) n = +;
(
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) if (ax) n 6= + then b(f x) n = f (ax) n .
      </p>
      <p>Proposition 5. The class Sys(DN) of N-detectors equipped with detector
morphisms forms a category.</p>
      <p>Proof is a simple check of the categories axioms.</p>
      <p>The following theorem describes a final detector.
tu
Theorem 1. There is a final object in category Sys(DN) that is structured as
follows
nDN is the set of all prefix-free subsets of N+;
nDN = P 2 nDN : n 2 N : n 1+ P iofthner2wPise .</p>
      <p>For an a N-detector, the corresponding anamorphism (a) is defined by the next
formula
(a) =
x 2 a : fu 2 N+ ja+(x; u) = + and</p>
      <p>a+(x; u0::k) 6= + whenever 0 &lt; k &lt; jujg
where a+ : a</p>
      <p>N+ ! 1 + a defined as follows
a+(x; n) = (ax) n
a+(x; un) =</p>
      <p>+
aa+(x; u) n
if a+(x; u) = +
otherwise
x 2 a; n 2 N;
x 2 a; n 2 N; u 2 N+:
The theorem can be derived from [8, Lemma 6] but we give a direct proof, which
details are used below. The proof is preceded by a statement of the facts being
used.</p>
      <p>Lemma 1. For any N-detector a, x 2 a, and u; v 2 N+, the equation
a+(x; uv) =</p>
      <p>+
a+ a+(x; u); v
if a+(x; u) = +
otherwise
holds.</p>
      <p>Proof. If a+(x; u) = + then a+(x; uv) = + by definition of a+. Hence we below
assume a+(x; u) 6= +.</p>
      <p>Let us use induction on v.</p>
      <p>
        For v = n 2 N, (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) follows from the definition of a+.
      </p>
      <p>
        Assume that v = v0n, n 2 N, and (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) holds for v0.
      </p>
      <p>Then under assumption that a+(x; uv0) = +, we have</p>
      <p>a+(x; u(v0n)) = a+(x; (uv0)n) = +
by definition of a+. Hence, a+(x; uv) = +.</p>
      <p>In the other side, we have a+(a+(x; u); v0) = a+(x; uv0) = + by induction
hypothesis. But then a+(a+(x; u); v) = a+(a+(x; u); v0n) = + by definition of a+.
Hence, we have a+(x; uv) = a+(a+(x; u); v).</p>
      <p>
        In contrary, assumption that a+(x; uv0) 6= + gives
= a+(a+(x; u); v0n) = a+(a+(x; u); v) by definition of a+:
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
tu
a+(x; uv) = a+(x; u(v0n)) = a+(x; (uv0)n)
= a a+(x; uv0) n
= a a+(a+(x; u); v0) n
Thus, the lemma is proved.
      </p>
      <p>Lemma 2. If P N+ is prefix-free then n 1 P
whenever n 2 N and n 2= P .
by definition of a+
by induction hypothesis</p>
      <sec id="sec-4-1">
        <title>N+ and it is prefix-free</title>
        <p>Proof. Firstly, n 2= P ensures 2= n 1 P i.e. n 1 P N+. Further, if u 2 n 1 P
and u0::m 2 n 1 P for 0 m &lt; juj then nu 2 P and nu0::m 2 P . Taking into
account nu0::m = (nu)0::m+1, one can obtain a contradiction, which completes
the proof.</p>
        <p>
          Lemma 3. Any prefix-free subset P of N+ can be represented as the following
disjunctive union
tu
(
          <xref ref-type="bibr" rid="ref2">2</xref>
          )
        </p>
        <p>X
n2NnNP
P = NP +
n Pn</p>
        <p>where</p>
        <p>
          NP = fn 2 N j n 2 P g and Pn = n 1 P:
Proof. Assume u 2 P then either u = n for some n 2 N or juj &gt; 1. In the
first case, we have u 2 NP and, therefore, u belongs to the right side of (
          <xref ref-type="bibr" rid="ref2">2</xref>
          ). In
another case, u = (u 0)u1:: where (u 0) 2= NP and ju1::j &gt; 0 i.e. u1:: 2 (u 0) 1 P
and u belongs to the right side of (
          <xref ref-type="bibr" rid="ref2">2</xref>
          ).
        </p>
        <p>
          Now assume u belongs to the right side of (
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) then either u 2 NP or u 2
        </p>
        <p>P n Pn. In the first case, we have u = n 2 NP i.e. u 2 P by definition
n2NnNP
of NP . In another case, u 2 n Pn where n 2 N n NP . Hence, u = nu1:: and
u1:: 2 n 1 P . The last means that u 2 P . tu
Now all is ready for proving Theorem 1.</p>
        <p>Proof (Proof of Theorem 1). Firstly, nDN : nDN ! DN nDN due to Lemma 2.
Hence, nDN is an N-detector.</p>
        <p>Further, let us show that the mapping (a) : a ! nDN defined above for any
N-detector a is an N-detector morphism.</p>
        <p>If (ax) n = + then n 2 (a) x i.e. nDN((a) x) n = +.</p>
        <p>Conversely, if nDN((a) x) n = + then n 2 (a) x i.e. (ax) n = +.</p>
        <p>If (ax) n 6= + then either (a) x = ? or this equation is wrong.</p>
        <p>In the first case, a+(x; u) 6= + for any u 2 N+ and, therefore, (a) (ax) n = ?
too. Also, we have</p>
        <p>nDN( (a) x) n = (nDN ?)n = n 1 ? = ? = (a) (ax) n :
In another case, we have both (ax) n 6= + and (a) x 6= ?.</p>
        <p>
          If u 2 nDN( (a) x) n = n 1 ( (a) x) then nu 2 (a) x i.e. a+(x; nu) = + but
a+(x; nu0::m) 6= + whenever m &lt; juj. Hence, for any m juj and v = u0::m, we
have
a+(x; nv) = a+(a+(x; n); v) = a+((ax) n; v)
(
          <xref ref-type="bibr" rid="ref3">3</xref>
          )
due to Lemma 1 and by definition of a+. Hence, one can conclude that
u 2 (a) (ax) n .
        </p>
        <p>
          Conversely, if u 2 (a) (ax) n then (
          <xref ref-type="bibr" rid="ref3">3</xref>
          ) guarantees a+(x; nu) = + but
a+(x; nu0::m) 6= + whenever m &lt; juj. It means that u 2 n 1 ( (a) x) =
nDN( (a) x) n.
        </p>
        <p>Thus, we have checked the N-detector morphism properties for (a).
For completing the proof, we need to show that (a) is the only N-detector
morphism from a into nDN i.e. f = (a) for any f : a ! nDN.</p>
        <p>Assume f x = ? then we have the next chain of equivalent statements
f x = ?
n 1 (f x) = ? for all n 2 N
nDN(f x) n = ? for all n 2 N
(ax) n 6= +</p>
        <p>and f (ax) n = ? for any n 2 N
a+(x; u) 6= +
(a) x = ?
for all u 2 N+
by definition of nDN
due to the N-morphism
properties
by induction on u
by definition of (a):
Hence, f x = ? iff (a) x = ?.</p>
        <p>Now using induction on juj, prove that u 2 f x if and only if u 2 (a) x.
If juj = 1 then we have the next chain of equivalent statements.
Hence, u 2 f x iff u 2 (a) x for any u 2 N+ such that juj = 1.</p>
        <p>If juj = m &gt; 1 and the required statement is true for v 2 N+ such that jvj &lt; m
then we have the next chain of equivalent statements.</p>
        <p>by definition of nDN
due to the N-morphism properties
by definition of (a):
by definition of nDN
and due to Lemma 3
due to the N-morphism
properties
by induction hypothesis
due to Lemma 1
by definition of (a):
n 2 f x for some n 2 N
nDN(f x) n = +
(ax) n = +
n 2 (a) x
u 2 f x
u1:: 2 (u 0) 1 (f x)
u1:: 2 nDN(f x) (u 0)
u1:: 2 f (ax) (u 0)
u1:: 2 (a) (ax)(u 0)
a+ (ax)(u 0); u1:: = + but
a+ x; (u 0)u1:: = + but
u 2 (a) x
a+ (ax)(u 0); u1::k 6= + whenever k &lt; m
by definition of (a)
a+ x; (u 0)u1::k 6= + whenever k &lt; m
Thus, f = (a) .
tu
Below we need a characterisation of the subsets of nDN that are carriers of
subcoalgebras. The next proposition gives this characterisation.
Proposition 6. A subset C nDN is the carrier of a subcoalgebras of the final
detector defined by the natural embedding jC : C ! nDN if and only if the
condition
for any P 2 C and n 2 N;
either
n 2 P
or</p>
        <p>Proof boils down to simply checking the requirements of definitions.
5</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Coalgebraic Understanding Safety Constraints</title>
      <p>The general coalgebraic framework for recognising violations of the behaviour of
a system with output is introduced and studied in this section.
This subsection defines bifunctor Join (see Theorem 2), which is the key tool for
our studying. The importance of this bifunctor is related to the fact it preserves
bisimulations (see Theorem 3).</p>
      <p>Firstly assuming and a is a system with output N and an N-detector
respectively, one can define the system with termination Join( ; a) : a !
T( a) as follows</p>
      <p>Join( ; a) =
(x; y) 2
a :</p>
      <p>+
tr x; (ay)( out x)
if (ay)( out x) = +
otherwise
Further for systems
morphism f :
Join(f; g) :</p>
      <p>
        and with output N and N-detectors a and b, an
SN! , and a detector morphism g : a ! b, we define the mapping
a ! b by the formula
Join(f; g) = f
g:
tu
(4a)
(4b)
Theorem 2. Rules (
        <xref ref-type="bibr" rid="ref4">4</xref>
        ) determine a bifunctor Join : Sys(SN)
Sys(T).
      </p>
      <p>Sys(DN) !
Proof. Firstly, let us check that for any f : ! and g : a ! b where ; 2
Sys(SN) and a; b 2 Sys(DN), Join(f; g) is a T-morphism from Join( ; a) into
Join( ; b).</p>
      <p>Indeed, let Join( ; a) (x; y) = + where x 2 , y 2 a then we have the next
chain of equivalent statements</p>
      <p>Join( ; a) hx; yi = +
(ay)( outx) = +
(ay)( out(f x)) = +
b(gy)</p>
      <p>out(f x) = +
Join( ; b) hf x; gyi = +
Join( ; b)</p>
      <p>Join(f; g)hx; yi = +
by definition of Join( ; a)
due to f is an SN -morphism
due to g is a DN -morphism
by definition of Join( ; b)
by definition of Join(f; g)
Now assume that Join( ; a) hx; yi 6= + (it means (ay)( outx) 6= +) where x 2 ,
y 2 a then</p>
      <p>Join(f; g)</p>
      <p>Join( ; a) hx; yi = Join(f; g)</p>
      <p>trx; (ay)( outx)
= f ( trx); g (ay)( outx)
by definitions of Join( ; a) and Join(f; g).</p>
      <p>Further,</p>
      <p>Join(f; g)</p>
      <p>Join( ; a) hx; yi =</p>
      <p>tr(f x); g (ay) out(f x)
=
tr(f x); b(gy)
out(f x)
taking into account that f is an SN-morphism, and g is a DN-morphism.
Finally,</p>
      <p>Join(f; g)</p>
      <p>Join( ; a) hx; yi = Join( ; b) f x; gy</p>
      <p>= Join( ; b) Join(f; g)hx; yi
by definitions of Join( ; b) and Join(f; g) respectivelly.</p>
      <p>Thus, Join(f; g) is a T-morphism (see Subsec. 4.1).</p>
      <p>Taking into account rule (4b) one can conclude that Join is a bifunctor.
TNhaenodreamqa3.rLqe!bt b pbe a bpi!simubleataiobnisoimfuNla-dtieotnecotofrssysateamnsd batnhden Jwoiitnh(o;urt)puist
a bisimulation of Join( ; a) and Join( ; b).
tu
Proof. Let us consider the span</p>
      <p>Join( ; a) Join(p ;qa) Join( ; r) Join(p ;qb!) Join( ; b):
It is sufficient to show that the corresponding span b
in Set is a mono-span.</p>
      <p>Assume some mappings g; h : S ! r with common domain S satisfy the
equations (p qa)g = (p qa)h and (p qb)g = (p qb)h. These mappings
can be uniquely represented as follows g = hg ; gri and h = hh ; hri respectively
where g ; h : S ! and gr; hr : S ! r.</p>
      <p>Taking into account that
a p qa
r p q!b
(p
(p
qa)g = (p
qa)h = (p
qa)hg ; gri = hp g ; qagri
qa)hh ; hri = hp h ; qahri
and
we have hp g ; qagri = hp h ; qahri i.e. p g = p h and qagr = qahr due to
properties of product. Similarly, we have p g = p h and qbgr = qbhr from
and the bisimulation ! .</p>
      <p>Similarly, we have gr = hr due to the conditions qagr = qahr and qbgr = qbhr
and the bisimulation a qa r q!b b.</p>
      <p>Thus, g = h and, therefore, the considering span a p qa r p q!b
is realy a mono-span.
This subsection is central to the paper. Here we establish an association between
N-detectors and some subsets of NN. Further, we prove this class of subsets is
exactly the class of safety constraints.</p>
      <p>First of all for s 2 NN, let us define the following system [s] with output
namely
[s] = sk:: j k 2 N
and [s] =
t 2 [s] : t 0; t1:: :
Further for any N-detector a and x 2 a, let us define the following set</p>
      <p>JaKx = fs 2 NN j (Join([s]; a))hs; xi = 1g:
The next simple fact is useful below.</p>
      <p>Lemma 4. For s 2 NN, an N-detector a, and x 2 a,</p>
      <p>Join([s]; a) (m)hs; xi =</p>
      <p>+
hsm::; a+(x; s0::m)i
if a+(x; s0::m) = +
otherwise
for m &gt; 0:
Proof. For proving we apply induction on m. If m = 1 then the equation holds
due to (4a).</p>
      <p>Now assume the equation holds for some m &gt; 1.</p>
      <p>Let Join([s]; a) (m)hs; xi = + then a+(x; s0::m) = + by induction hypothesis.
The definition of a+ ensures a+(x; s0::m+1) = +. But Join([s]; a) (m+1)hs; xi =
+ by definition. Hence, the equation holds in this case.</p>
      <p>Finally, assume Join([s]; a) (m)hs; xi 6= + then</p>
      <p>Join([s]; a) (m)hs; xi = hsm::; a+(x; s0::m)i
by induction hypothesis i.e. a+(x; s0::m) 6= +. Thus,</p>
      <p>Join([s]; a) (m+1)hs; xi = Join([s]; a)</p>
      <p>Join([s]; a) (m)hs; xi
= Join([s]; a) hsm::; a+(x; s0::m)i:
Now applying (4a), we obtain the required expression for Join([s]; a) (m+1)hs; xi.
Lemma 5. For any N-detector a and x 2 a, the set JaKx is a safety constraint.
Proof. Indeed, let us assume the existence of s 2= JaKx such that the equation
s00::m = s0::m holds for any m 2 N and for some s0 2 JaKx depending in generally
on m.</p>
      <p>The fact s 2= JaKx ensures (Join([s]; a))hs; xi = K for some K 2 N. It means (see
Lemma 4) a+ x; s0::K+1 = +. Let s0 2 JaKx such that s00::K+1 = s0::K+1 then
a+ x; s00::K+1 = + and, therefore, (Join([s0]; a))hs0; xi = K. But (Join([s0]; a))hs0; xi =
1 by the assumption s0 2 JaKx. This contradiction completes the proof. tu
The following lemma is less simple.</p>
      <sec id="sec-5-1">
        <title>Lemma 6. For any safety constraint S</title>
        <p>x 2 aS such that JaS Kx = S.</p>
        <p>Proof. Let us define the N-detector aS as follows (note that
2 aS )</p>
        <p>NN, there exist an N-detector aS and
aS = f g
[</p>
        <p>u 2 N+ j u = s0::juj for some s 2 S
aS =
u 2 aS :
and prove that JaS K = S.</p>
        <p>Let us assume s 2 S then s0::m 2 aS for any m 2 N. Hence, aS+(s0::m; s m) =
s0::m+1 2 aS for each m i.e. (Join([s]; aS ))hs; i = 1. Thus, s 2 JaS K .
Conversely assume s 2 JaS K then (Join([s]; aS ))hs; i = 1 and, therefore,
Join([s]; aS ) (m)hs; i 6= + for each m &gt; 0. Lemma 4 ensures</p>
        <p>s0::m = aS+( ; s0::m) 2 aS for all m &gt; 0
that guarantees existence s(m) 2 S such that s(0m:: m) = s0::m. Now using the
safeness of S, one can conclude s 2 S. tu
Theorem 4 (about universal detector). A subset S NN is a safety
constraint if and only if there exist P 2 nDN such that S = JnDNKP .
Proof. Lemmas 5 and 6 ensure that a subset S NN is a safety constraint if
and only if there exist an N-detector a and x 2 a such that S = JaKx. Let us
take P = (a) x and prove (Join([s]; a))hs; xi = (Join([s]; nDN))hs; P i.
Indeed, for the T-morphism Join id[s]; (a) : Join([s]; a) ! Join([s]; nDN), we
have</p>
        <p>
          Join id[s]; (a)
hs; xi = id[s]
(a) hs; xi = hs; P i:
(
          <xref ref-type="bibr" rid="ref5">5</xref>
          )
Using the equation
(Join([s]; a)) = (Join([s]; nDN))
that follows from the definition of an anamorphism, one can derive from (
          <xref ref-type="bibr" rid="ref5">5</xref>
          ) the
follows
        </p>
        <p>(Join([s]; a))hs; xi = (Join([s]; nDN))hs; P i:
Considering the last equation holds whenever P = (a) x, one can conclude that
S = JaKx = JnDNKP .</p>
        <p>Corollary 1. A subset S NN is a safety constraint if and only if it is equal
to fs 2 NN j s0::m 2= P for any m &gt; 0g for some prefix-free subset of N+.
Proof. It follows immediately from Theorem 4.</p>
        <p>Corollary 2. For any N-detectors a and b and x 2 a and y 2 b, the equation
(a) x = (b) y is sufficient for JaKx = JbKy.</p>
        <p>Proof. The statement is true due to the construction method of P used in the
proof of Theorem 4.
Theorem 4 proved in the previous subsection establishes that for the family of
all safety constraints, there is a universal detector, i.e. a detector that recognises
any safety constraint of the family when the detector configured appropriately.
Such a general result, however, cannot be used in the practice of developing
software tools, if only because computability considerations limit our expressive
capabilities for specifying safety constraints and, in particular, guarantee the
impossibility of specifying an arbitrary prefix-free set. Therefore, we need to
consider more specific families of safety constraints. In this subsection, we try to
outline some general approach to solving this problem.</p>
        <p>We begin with the next definition.</p>
        <p>Definition 8. A family of safety constraints F is below called a family with
a universal detector if F = fJaKx j x 2 ag for some N-detector a being called
in this case a universal detector for F .</p>
        <p>
          Theorem 5. A family of safety constraints F is a family with a universal
detector if and only if there exists C nDN that meets the following conditions
for any P 2 C;
either n 2 P
or
Proof. Firstly, let us assume the family F is a family with a universal detector
then Prop. 6 guarantees the validity of conditions (
          <xref ref-type="bibr" rid="ref6">6</xref>
          ).
        </p>
        <p>Conversely, let us define the next mapping a : C ! DN C
a =
The correctness of this definition is ensured by (6a), hence a is an N-detector
and, due to (6b), it is a universal detector.</p>
        <p>Now we consider three specific safety constraint family and demonstrate that
each of them is a family with a universal detector.</p>
        <p>Regular Safety Constraints Here we consider the safety constraint family R
formed as follows a safety constraint S belongs to R if and only if there exists
a detector a with the finite carrier such that S = JaKx for some x 2 a. We call a
safety constraint belonging this family a regular safety constraint.
Theorem 6. The family of regular safety constraints is a family with a universal
detector.</p>
        <p>Proof. Let us consider</p>
        <p>C = fP</p>
        <p>N+ j P = (a) x for some detector a with finite carrier and x 2 ag
then any P 2 C is a regular prefix-free subset of N+ (see, for example,
[6, Theorem 1]).</p>
        <p>
          Now let us check that C satisfies conditions (
          <xref ref-type="bibr" rid="ref6">6</xref>
          ). Indeed, Lemma 2 ensures n 1 P
is prefix-free for any n 2 N such that n 2= P .
        </p>
        <p>Hence, we need only due to Theorem 5 to check that n 1 P is a regular set
under assumption n 2= P . To do this we consider a finite Eilenberg machine
hQ; T</p>
        <p>Q</p>
        <p>N</p>
        <p>Q; I</p>
        <p>Q; F</p>
        <p>Qi
that accepts only words from P (see [5]) and construct the new finite Eilenberg
machine</p>
        <p>hQ; T Q N Q; I0 Q; F Qi
where I0 = fq 2 Q j hq0; n; qi 2 T for some q0 2 Ig. It is evident that the
constructed machine accepts exactly n 1 P and, therefore, n 1 P 2 C. tu
Decidable Safety Constraints Here we consider the safety constraint family
D formed as follows a safety constraint S belongs to D if and only if there exists
P 2 nDN such that P is decidable and S = JnDNKP . We call a safety constraint
belonging this family a decidable safety constraint.</p>
        <p>Theorem 7. The family of decidable safety constraints is a family with a
universal detector.</p>
        <p>Proof. To prove the theorem is sufficient to check that the family of a decidable
prefix-free subset of N+ satisfies condition (6a). But this is really true because
one can check the statement u 2 n 1 P for a decidable prefix-free subset P
of N+, any u 2 N+, and n 2 N such that n 2= P , by checking nu 2 P with a
decision procedure for P .
Recursively Enumerable Safety Constraints Here we consider the safety
constraint family RE formed as follows a safety constraint S belongs to RE if
and only if there exists P 2 nDN such that P is recursively enumerable and
S = JnDNKP . We call a safety constraint belonging this family a recursively
enumerable safety constraint.</p>
        <p>Theorem 8. The family of recursively enumerable safety constraints is a family
with a universal detector.</p>
        <p>
          Proof. Similarly to proof of the previous theorem, we need to furnish a
semidecision procedure for checking the statement u 2 n 1 P with a recursively
enumerable prefix-free subset P of N+, any u 2 N+, and n 2 N such that
n 2= P . This procedure is as follows
(
          <xref ref-type="bibr" rid="ref1">1</xref>
          ) run parallelly checkings nu0::k 2 P for k = 1; : : : ; juj;
(
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) wait for any of these runs to halt;
(
          <xref ref-type="bibr" rid="ref3">3</xref>
          ) report success if the halting run is the run for checking nu 2 P .
An event waited in item (
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) may do not happen if nu 2= P i.e. u 2= n 1 P .
If the wait in paragraph (
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) is completed then only for one 0 &lt; k juj the
corresponding checking is completed due to P is prefix-free.
u 2 n 1 P or equivalently nu 2 P if and only if the checking with number
juj 1 is halted.
        </p>
        <p>In other cases, nu 2= P i.e. u 2= n 1 P .</p>
        <p>Thus, the furnished procedure is really a semi-decision procedure for the
statement u 2 n 1 P . tu
6</p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>Conclusion</title>
      <p>Summing up the mentioned above we can conclude that subdetectors of a final
detector correspond to families of safety constraints with universal detectors.
These families are candidates for semantic models of domain-specific languages
for specification of safety constraints.</p>
      <p>Of course, the obtained results tell nothing how to construct such languages.
But they turn this problem into more precisely defined.</p>
      <p>
        We can identify as problems for further studying the follows
(
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) Give syntactic characterisation of regular safety constraints family.
(
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) Understand what classes of grammars (for example, context-free) define
proper families of safety constraints.
(
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) Can we use complexity classes for defining families of safety constraints with
universal detectors?
(
        <xref ref-type="bibr" rid="ref4">4</xref>
        ) Understand how compositional theory of detectors can be developed.
      </p>
      <p>An especial area of further research is the dissemination of the proposed
approach for the specification and analysis of causality constraints, formulated
in terms of the logical clock model. Now authors are working on the paper
“Understanding Logical Clock Model Coalgebraically”.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Aczel</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mendler</surname>
          </string-name>
          , N.:
          <article-title>A final coalgebra theorem</article-title>
          .
          <source>In: Proc. CTCS'89, Lecture Notes in Comput. Sci.</source>
          , vol.
          <volume>389</volume>
          , pp.
          <fpage>357</fpage>
          -
          <lpage>365</lpage>
          . Springer (
          <year>1989</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Alpern</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schneider</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Recognizing safety and liveness</article-title>
          .
          <source>Distributed Computing</source>
          <volume>2</volume>
          ,
          <fpage>117</fpage>
          -
          <lpage>126</lpage>
          (
          <year>1987</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Awodey</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <source>Category Theory</source>
          . Oxford University Press, 2nd edn. (
          <year>2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Bowen</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Stavridou</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          :
          <article-title>Safety-critical systems, formal methods and standards</article-title>
          .
          <source>Software Engineering Journal</source>
          <volume>8</volume>
          (
          <issue>4</issue>
          ),
          <fpage>189</fpage>
          -
          <lpage>209</lpage>
          (
          <year>1993</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Eilenberg</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          : Automata,
          <source>Languages and Machines</source>
          , vol. A. Academic Press (
          <year>1974</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>G.</given-names>
            <surname>Zholtkevych</surname>
          </string-name>
          and
          <string-name>
            <surname>N.</surname>
          </string-name>
          <article-title>Polyakovska: Machine Learning Technique for Regular Pattern Detector Synthesis: toward Mathematical Rationale</article-title>
          .
          <source>In: Computational Linguistics and Intelligent Systems, CEUR Workshop Proceedings</source>
          , vol.
          <volume>2362</volume>
          , pp.
          <fpage>254</fpage>
          -
          <lpage>265</lpage>
          . CEUR-WS (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Grant</surname>
            ,
            <given-names>E.S.:</given-names>
          </string-name>
          <article-title>Requirements engineering for safety critical systems: An approach for avionic systems</article-title>
          .
          <source>In: 2nd IEEE International Conference on Computer and Communications (ICCC)</source>
          . pp.
          <fpage>991</fpage>
          -
          <lpage>995</lpage>
          . IEEE (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Jacobs</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          : Objects And Classes, Co-Algebraically. In: Freitag,
          <string-name>
            <surname>B.</surname>
          </string-name>
          , et al. (eds.)
          <article-title>Object Orientation with Parallelism and Persistence</article-title>
          , The Springer International Series in Engineering and Computer Science, vol.
          <volume>370</volume>
          , pp.
          <fpage>83</fpage>
          -
          <lpage>103</lpage>
          . Springer, Boston, MA (
          <year>1996</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Jacobs</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          : Introduction to Coalgebra:
          <source>Towards Mathematics of States and Observation</source>
          . Cambridge Tracts in Theoretical Computer Science, Cambridge University Press (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Lane</surname>
            ,
            <given-names>S.M.</given-names>
          </string-name>
          :
          <article-title>Categories for the Working Mathematician</article-title>
          . Springer, 2nd edn. (
          <year>2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>E.A.</given-names>
          </string-name>
          :
          <source>Cyber Physical Systems: Design Challenges. Tech. Rep. UCB/EECS2008-8</source>
          ,
          <string-name>
            <given-names>EECS</given-names>
            <surname>Department</surname>
          </string-name>
          , University of California, Berkeley (Jan
          <year>2008</year>
          ), http: //www2.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008
          <article-title>-8</article-title>
          .html
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Mana</surname>
            ,
            <given-names>Z.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pnueli</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>The Temporal Logic of Reactive and Concurrent Systems</article-title>
          : Specifications. Springer-Verlag (
          <year>1992</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Rutten</surname>
          </string-name>
          , J.:
          <article-title>Universal coalgebra: a theory of systems</article-title>
          .
          <source>Theor. Comput. Sci. 249</source>
          ,
          <fpage>3</fpage>
          -
          <lpage>80</lpage>
          (
          <year>2000</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>