ALGEBRAIC METHODS FOR DISCRETE EVENT SYSTEMS - A TUTORIAL
Johan Gunnarsson
Division of Automatic Control Department of Electrical Engineering Link ¨oping University
S-581 83 Link ¨oping, Sweden Email: johan@isy.liu.se
WWW: http://www.control.isy.liu.se
WODES96
Keywords
DEDS, Algebra, Gr ¨obner Basis, BDD, Tutorial
Abstract
Discrete event dynamic systems (DEDS) are treated in a mathematical framework using algebra and polynomials over finite fields. In this framework DEDS interacts with the environment by signals rather than events. The polynomial framework give symbolic representation of a DEDS behavior and can be used for modeling, synthesis and verification.
Two tools, Gr ¨obner basis and binary decision dia- grams, are described. These tools compute canoni- cal representations for solutions or behaviors.
1 Introduction
The interest in formal tools that can deal with com- plex DEDS is greater then ever in industry. The interest is driven by real world problems and real world costs rather then purely academic interest.
Today there are several methods and approaches for formal modeling, verification and synthesis of dis- crete event dynamic systems (DEDS). Still the com- plexity of methods and tools makes it hard to apply to real problems.
In this paper
1we give a tutorial on symbolic al- gebraic methods based on polynomials over finite fields (POFF). With this framework we represent DEDS with polynomials which gives a compact represen- tation. The theory of POFF is derived from ba- sic commutative algebra and uses tools like Gr¨obner basis, and at the same time as it gives a theoretic
1
This work was supported by the Swedish Research Council for Engineering Sciences (TFR) and the Swedish National Board for Industrial and Technical Development (NUTEK), which is gratefully acknowledged.
motivation for tools like binary decision diagrams (BDD).
After defining what we mean by a DEDS some commutative algebra preparations will be given to make POFF more understandable. At the end two different tools for POFF computations will be dis- cussed.
2 Finite Discrete Systems
Inspired by the mathematical description for contin- uous systems x_ = f
(xu
)we write a DEDS with n
states, p inputs and m outputs as
x
+=f
(xu
)(1)
where x+ (next state), xu belongs to finite sets
X n X n U p and the transition function is a mapping
f
:X n U p ! X n . The expression (1) models an explicit behavior whereas f
(x
+xu
)=0models an
implicit behavior. For outputs we write y =g
(xu
), y2Y m .
Y m .
The variables xux+and y are regarded as sig- nals and the models fg are signal models. This differs from a pure event based approach where value (or symbol) represents a change in the envi- ronment. Instead we say that the environment can always be measured and we do not need to remem- ber values on the inputs. Signal based models has a closer connections to physical systems controlled by some sampling device. Pure event based models can translated to signal based models, see [6].
3 Commutative Algebra
We define the basic components of commutative al- gebra, ring and field.
Definition 1 A commutative ring R is a set of ele- ments and two operations,
+and
, which both are com- mutative, associative, distributive and closed in R .
+and
have identity elements,
0and
1respectively. For every
element a 2 R there exists an element b
2 R such that
a
+b
=0, i.e.
+has an inverse.
Definition 2 A field
Fis a commutative ring where ev- ery element except
0has a multiplicative inverse, i.e.,
(8
a
2R
nf0g9 ~a
2R
nf0g)a
~a
=1:
The general field defined above may contain an infinite number of elements. To be able to build a theory for finite domains we need the following.
Theorem 1 A field with q elements denoted
Fq is a finite field iff q=p l for some l
2Z+and some prime p .
This means that we cannot have a finite field
Fq for all q2Z+, e.g.,
F8 is a finite field but
F6 is not.
Elements from a field can be used as coefficients in polynomials.
Definition 3 A polynomial ring (denoted
FZ
]or
F
z
1::: z n]) is the set of all polynomials in the variables
z
1z
2::: z n with coefficients from a fieldF.
The main objects in our theory are sets of poly- nomials called ideals. Here we will give a simplified definition, see [3].
Definition 4 The ideal I =hg
1g
2::: g s
iFZ
]is
a set of polynomials where each polynomial f 2I can be
written as
f
=Xs
i
=1h i g i (2)
where h i
2FZ
]i
=1:::s . The polynomials g
1::: g s are called generators to the ideal I .
Generators for an ideal serves as a basis for the poly- nomial set, and to manipulate the ideal we manip- ulate its generators. As an illustration of ideals we have
h
z
2ihz
ih1i=Fz
]and
h
z
1i hz
2ihz
1z
2iIn the last expression we have always strict inclusion (try the polynomial z1+z
2). In fact, the union of two ideals is not an ideal in general and this is also true for intersection. Set theoretic operations do not pre- serve the algebraic structure of ideals. There exists algebraic operations on ideals, but we will not dis- cuss them here. See [5] for a thorough presentation.
4 Representing Finite Functions
From the brief introduction of commutative algebra above, we will present what use we will have of polynomials and ideals for DEDS.
When modeling a DEDS we end up with map- pings between variables of finite domains, e.g., tran- sition functions. The representation or realization of the mappings can be made by tables, where each row gives information of how to map one combina- tion of values of the inputvariables to output vari- ables. Instead of tables we want an algebraic repre- sentation of the mappings. The reasons for this are first that it is convenient to build a framework for analysis and design on mathematic rather than al- gorithms. Secondly, the algebra can capture a struc- ture in the mappings which might give easier com- putations or data reduction. Compare with the con- tinuous domain where a differential equation repre- sents a behavior of infinite data size. Computations on continuous behavior is made by using the differ- ential equation rather than on the behavior directly.
By using a polynomial representation of the mappings we have mathematical objects which is what we need. But we cannot hope that polynomi- als will have the same tremendous impact on DEDS, as differential equations and linear algebra have had on linear systems, since we have not a metric for fi- nite domains and linearity.
Consider the mapping
J :F7 !F7below.
x
0 1 2 3 4 5 6J(
x
) 3 2 1 0 1 2 3We want a polynomial J(x
) 2 F7x
] to give
the same value as
J(x
)when J(x
)is evaluated
2for given values of x . One possible choice is the polyno- mial
J
(x
)=3+3x
+6x
2+x
3+2x
4+6x
5+2x
6:
In addition to functions we can represent rela- tions as polynomials. Consider the relation
f(
xy
)j(00)(21)(22)gwhich is represented by the solution set to the equa- tion r(xy
)=0where
r
(xy
)=2x
;2y
;2xy
+xy
22F3xy
]:
The examples above indicates that we can use polynomials to represent both functions and rela- tions of finite domains. We will now show that all functions and relations in finite domains can be rep- resented by polynomials over finite fields.
Theorem 2 A polynomial ring
Fq
Z
]over finite field is functionally complete.
2
Evaluate
J(x)using normal
+and and take modulus
qon
the result.
Proof:[[5]] Let f(z
1::: z n
):Fnq
!Fq be any func- tion. The corresponding polynomial f p
(Z
) 2 Fq
Z
]is computed as
f p(Z
)= X
2FnqL (Z
)f
() (3)
where L
(Z
)=L 1(z
1)L n(z n)2Fq
Z
]and L
i(z i)=
z n)2Fq
Z
]and L
i(z i)=
Q
2Fqnfig(z i;)
Q
2Fqnfig(i;) =
(
1
z i= i
0
z i6= i (4) is the Lagrange interpolating polynomial. We then have
f
()=f p()for all
2Fnq .
It can be shown that a polynomial ring R q
Z
]with
coefficients from a finite ring R q is not functionally complete. Therefore R q
Z
]cannot be used to repre- sent all functions. Clearly
Fq
Z
]is much more useful but it has one major disadvantage. Let f(x
)g
(x
) 2
F
5
x
]and let
f
(x
)=x
10+x
9+x
8)f03231gg
(x
)=x
4+x
2+x
)f03231gwhere value set is presented last. This indicates that there are several polynomials in
Fq
Z
]representing the same function. In fact, it can be shown that ev- ery function can be represented by an infinite num- ber of polynomials in
FZ
]. To get a one-to-one corre- spondence between functions and polynomials we need to reduce the set of polynomials usable to rep- resent functions. What we then have is canonical form of polynomials making it possible to compare two polynomials and if they are found to be differ- ent we know that the represented functions must be different.
Fermats little theorem shows that if q is prime
then x q
;1=1mod q , x
6=0which in turn gives Lemma 1 (Zero polynomials) Let z q
(x
)=x q;x
2
F
q
z
]then z q
()=0for all
2Fq .
The zero polynomial can be used to generate the ideal
hz q(x
)iof all zero polynomials in
Fx
]. Then
all polynomials f~(x
)2 Fq
x
]representing the same function as the polynomial f(x
)can be written as
x
)can be written as
f
~(x
)=f
(x
)+h
(x
)h
(x
)2hz q(x
)i (5)
To choose one polynomial uniquely from all polynomials representing the same function can be done by taking the remainder of the polyno- mial quotient f~(x
)=z q
(x
), i.e., assuming f(x
)is irre-
ducible with respect to z q
(x
)in (5) we get
f
(x
)=Reminder
f
~(x
)z q(x
)
!
(6)
We generalize this to the polynomial ring.
Definition 5 The quotient polynomial ring
Rq
Z
]is
defined as
R
q
Z
]=Fq
Z
]=
hz q(z
1)::: z q(z n)i
z n)i
We note that
Rq
Z
]contains all polynomials in
F
q
Z
]. However, the polynomials are partitioned into equivalence classes by the ideal
h
z q(z
1)::: z q(z n)i:
z n)i:
It is shown in [5] that we can represent any relation between the variables Z (where Z = fz
1::: z n
g
and z i
2 Fq ) uniquely with a polynomial in
Rq
Z
],
i.e. there is a one-to-one correspondence between the relations and the equivalence classes in
Rq
Z
].
Each equivalence class of polynomials in
Rq
Z
]can
be represented by one of its members in all opera- tions on relations. For every equivalence class there is a polynomial with degree less than q . Therefore the polynomial representing an equivalence class in
R
q
Z
]can be chosen such that the degree and the
“length” of the polynomial has an upper limit. This gives some complexity advantages.
Polynomials in
Rq
Z
]will be the “language” we use to model DEDS, i.e., we let f(xu
)be a polyno- mial in
Rq
xu
]representing the transition mapping for the system.
5 Representing Logical Expressions
In the previous section we showed how to represent a function f : Fnq
! Fq as a polynomial in
Rq
Z
].
To reduce complexity for addition and multiplica- tion of finite integers it is often useful to choose q >
2
. Still we need to represent logical expressions and conditions in the formalism, i.e. to consider func- tions b:Fnq
!ftrue false
g. This could be done by interpreting the values of the polynomial b(Z
)as
Z
)as
b
(Z
)=0)true
b
(Z
)6=0)false (7)
If a(Z
)b
(Z
) 2 Rq
Z
] represent two logical expressions, the result of AND-, OR- and NOT- operations can be computed by algebraically manip- ulating the polynomials a and b as
a
(Z
)^b
(Z
)=1;(1;a
(Z
)q
;1)(1;b
(Z
)q
;1)a
(Z
)_b
(Z
)=a
(Z
)b
(Z
)(8) (9)
:
a
(Z
)=1;a
(Z
)q
;1(10)
where the NOT-operation maps zero on one. This
gives a natural extension of the logical operations to
ideals in
Rq
Z
]. See [5] for further details.
For convenience we will sometimes use the log- ical operations
!$9and
8, which can be ex- pressed using the logical operations defined above as follows.
a
(Z
)!b
(Z
)=:(a
(Z
)^:b
(Z
))(11) a(Z
)$b
(Z
)=(:a
(Z
)^:b
(Z
))_(a
(Z
)^b
(Z
))
(12)
9
z i a
(z
1::: z n)=q
_;1
j
=0a
(z
1::: z i;1jz i+1::: z n)
(13)
::: z n)
(13)
8
z i a
(z
1::: z n)=q
^;1
j
=0a
(z
1::: z i;1jz i+1::: z n)
(14)
::: z n)
(14)
Example 1 Given the polynomial
a(x), let
b(x)be defined as
b(x)=
1 a(x)6=0
0 a(x)=0
(15)
The polynomial
b(x)can be generated as
b(x)=::a(x)
(16)
since the expression for NOT in (10) maps all zeros to ones.
For simplicity and clarity it is sometimes conve- nient to express polynomials as logical expressions.
We can e.g. write that a polynomial p2R3Z
]is p(Z
)=z
1^z
2: (17)
Z
)=z
1^z
2: (17)
Using the logical operation in (8), we interpret this as
p
(Z
)=z
12+z
22;z
12z
22: (18)
6 Bases
Consider a DEDS x+=f
(xu
)and an initial state set
p I(x
). Assume that we want to know if it is possible to reach the state set p F
(x
)in the next iteration. This forms a the following equations
x
+;f
(xu
)=0p I(x
)=0 (19) p F
(x
+)=0
which also can be written as a single polynomial us- ing logic operators
(
x
+;f
(xu
))^p I(x
)^p F(x
+) (20)
x
+)(20)
If there are any solutions in (19) and roots in (20) then we have proved that it is possible to reach the state set p F
(x
)in the next iteration.
To find solutions is a delicate matter of the tools that we need to have if the POFF framework shall
be feasible. Here we will present two different tools that uses bases to find canonical forms for polyno- mials or polyno mials equations. A common feature of these tools is that the canonical
3form is as simple as possible. This means e.g. that the canonical form for a polynomial without solutions is the constant
1. Therefore if the canonical form for (19) and (20) is not
1
then there exists solution.
6.1 Gr ¨obner Bases
For each ideal in a polynomial ring there are many possible sets of polynomials that generate the ideal.
To be able to decide if two ideals are equal, we need a standard for choosing generators of an ideal.
Gr ¨obner bases form one standard representation for ideals. The Gr ¨obner bases are in a sense a nonlinear generalization of Gaussian elimination.
6.1.1 Gr ¨obner Bases for General Polynomial Rings
Gr ¨obner bases can be regarded as the “simplest”
representation of an ideal w.r.t. some term ordering.
A monomial term ordering gives an order to all monomials in the polynomial ring, and a way to de- fine the degree,
deg (f
(Z
)), of a polynomial f(Z
).
For example by lexicographic order y > x we mean
a term ordering where e.g.
deg (
y
2x
)>
deg(yx
5)>
deg (yx
4)>
deg (x
9):
The leading term, LT(f
(Z
)), is the term in f(Z
)with
Z
)with
highest degree. The degree of a polynomial f(Z
)is
deg (
f
(Z
))=deg(LT
(f
(Z
))): (21)
The Gr ¨obner basis of an ideal can be regarded as the set of generators which has the lowest possible degree w.r.t. a given term ordering.
Given a polynomial p and a polynomial set F , the
remainder polynomial r is computed as
r
=p
;Xf
2F f f (22)
where f are chosen to give r the lowest possible de- gree. Note that
deg (r
)<
deg(f
)for all polynomials
f
2F . We say that p reduces to r w.r.t. F and denote
this
p
;!Fr: (23)
If p;!F p we say that p is reduced w.r.t. F . If F is au-
toreduced then all polynomials in F are reduced w.r.t.
F .
3
Polynomial with the lowest degree in
RZ]is unique, but the
form is not. The form
x(x+1)and the form
x2+xare the same
polynomial.
S
(p
1p
2)denotes the S-polynomial of p1 and p2,
,
and is computed as
S
(p
1p
2)=h
1p
1;h
2p
2(24)
where h1and h2are terms of lowest degree such that
are terms of lowest degree such that
LT
(h
1p
1)=LT
(h
2p
2).
The polynomial set G = fg
1::: g n
g is a Gr ¨obner basis for the ideal I iff GI ,
hG
i=I , and S
(g i g j)2I
8i
6=j (25)
i.e. S(g i g j
);!G 0. To avoid further details we can use this result as a definition of a Gr ¨obner basis.
A polynomial p is a member of an ideal I iff
p
;!G 0(26)
where G is a Gr ¨obner basis of I .
To compute a Gr ¨obner basis we can use Buch- berger’s algorithm (see [3]):
Algorithm 1
1. Take the generators of I as candidates for a Gr ¨obner basis. Denote this set G .
2. If all s-polynomials S(g i g j
) ;!G 0, i 6= j ,
then G is a Gr ¨obner basis.
3. Otherwise add to G the remainder r computed
as S(g i g j
);!G r
6=04. Make G autoreduced and go to 2.
An autoreduced Gr ¨obner basis G for an ideal is unique and a canonical form for I . If two ideals have the same autoreduced Gr ¨obner basis w.r.t. to the same term ordering, the ideals are equal.
6.1.2 Gr ¨obner Bases in
Rq
Z
]Gr ¨obner bases are used and defined in
Rq
Z
]in anal-
ogy with the general polynomial ring
FZ
], except
that in every arithmetic operation on the polynomi- als in
Rq
Z
],
degrees higher or equal than q are reduced as
z q!z , and
coefficients only take values in
Fq .
The ring
Rq
Z
]is a quotient ring. Therefore the term ordering is not well defined since the relation
deg (
fg
)=deg(f
)+deg (g
)is not always fulfilled.
Example 2 Let
f1 =y4f2 =y3 2R7y]. Then
fg=yand therefore
deg (fg)6=7.
To deal with this problem formally, the Gr ¨obner ba- sis for an ideal I 2 Rq
Z
]is computed in the free (not quotient) polynomial ring
Fq
Z
]with the rela- tions z q
1;z
1::: z qn
;z n (see Definition 5) included in the set of generators for the ideal I .
Definition 6 The Gr¨obner basis of the ideal I =
h
f
1f
2::: f ni 2 Rq
Z
]for some given term ordering is denoted
GB q(f
1f
2::: f n): (27)
: (27)
As explained above the set
fz q1 ;z
1::: z qn;z ng
is added to the generator polynomials to give a true Gr ¨obner basis. This makes a significant difference when computing a Gr ¨obner basis of an ideal defined by a single polynomial. For an application of con- trol law synthesis for a DEDS using Gr ¨obner basis see [6, 9].
z ng
is added to the generator polynomials to give a true Gr ¨obner basis. This makes a significant difference when computing a Gr ¨obner basis of an ideal defined by a single polynomial. For an application of con- trol law synthesis for a DEDS using Gr ¨obner basis see [6, 9].
6.2 Binary Decision Diagram
For the Gr ¨obner bases above the canonical form is often expressed as a set of polynomials representing the ideal. But as indicated in (20) it is always possi- ble in
Rq
Z
]to represent and generate an ideal by a single polynomial. This feature makes
Rq
Z
]a prin-
cipal ideal domain which is proven in [5]. Bases using a single polynomial as a canonical representation of a ideal are called principal bases.
Binary decision diagram (BDD) [2] is a principal basis for
F2Z
]. BDD is a method to represent large Boolean expressions and is used for verification ap- plications in the area of computer science. Boolean expressions and polynomials in
F2Z
]is essentially the same thing, and BDD can be used to effectively represent polynomials in
F2Z
]. Efficient tools for BDD exists [1] whereas there is yet no usable tool for the more general Q:ary Decision Diagrams (QDD) for polynomials in
Fq
Z
], see [5]. Therefore we will fo- cus only on BDDs from here.
The basic idea used in BDDs is to rewrite Boolean (or
F2Z
]) expressions in a recursive form and reuse common subexpressions, a technique that has been used in compiler optimization for several decades.
In the case of Boolean expressions this leads to highly efficient computations in most cases.
Suppose we have a Boolean expression
f
(x
1::: x n). We can then rewrite it using Shan-
non’s expansion formula (see e.g. [4]):
f
(x
1::: x n)=((:x
1)^f
(0x
2::: x n))
_(
x
1^f
(1x
2::: x n)):
If we continue with this recursively for each of the functions f(0x
2::: x n
)and f(1x
2::: x n
)w.r.t.
x
2and then x3etc., we obtain
f
(x
1::: x n)=:x
1^(((:x n^)
| {z }
g
n;10:::0(x
n)_(
x n^)
| {z }
g
n;10:::1(x
n)))
| {z }
g
10(x
2:::x
n)_
x
1^(((:x n^)
| {z }
g
1:::0n;1 (x
n)_ (
x n^)
| {z }
g
1:::n;11(x
n)))
| {z }
g
11(x
2:::x
n)where 2 f01g. Furthermore we see that we obtain several subexpressions with pro- gressively fewer variables. In fact all expressions
g i above are Boolean expressions in the variables
f
x i+1::: x ng. In case some of these expressions are equal we should not have to repeat this part more than once but instead substitute a reference to this common subexpression. The recursive Boolean ex- pression form above can be visualized as a binary tree, where each node corresponds to the
_ oper- ator and essentially the g i expressions as subtrees.
. In case some of these expressions are equal we should not have to repeat this part more than once but instead substitute a reference to this common subexpression. The recursive Boolean ex- pression form above can be visualized as a binary tree, where each node corresponds to the
_oper- ator and essentially the g i expressions as subtrees.
This is the basis of the name BDD. The number of remaining nodes (or equivalently the number of dif- ferent subexpressions) is a measure of the complex- ity of the given expression. By changing the order in which we expand w.r.t. the various variables we usually get wildly different node counts. The order- ing is termed variable ordering and plays a significant role in lowering the representational complexity of a DEDS.
Example 3 The Boolean function
f=x1x2+:x4is rep- resented by the following ordered but unreduced BDD if we use the variable ordering
x1>x2>x3>x4.
1
2
4
0 1
2
3 3
3 3
4 4 4 4 4 4 4
0 0 0 0
1 1 1 0 1 1 1 1 1 1
1 0
1 0
0 1
1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
where the number in the nodes correspond to the index of the variables. After reduction we get
1
2 4
0 1
1 0
1 0 0 1