Introduction to Cyber-Physical Systems [5] : Modeling Discrete Dynamics

A discrete system is a system that  operates in a sequence of discrete steps, it is said to have discrete dynamics.
Example : counting the people that enter and leave a company building.


here we see the actual-model for personnel counter, starting from the left we see sensors that detect the arrival or departure of personals, on the right we see the output that shows the number of people in the building and in the middle we see the core logic for this personals counter.
for each actor the ports to that actor are labeled, example the arrival detector has a sensor that detects the arrival of a person and there is going to be some encoding of that signal so the output of this actor is connected to the input of the counter actor which is labeled up which is responsible of increasing the internal count likewise the counter actor has an output count which is connected to the display.
if we want to describe the types of these input / output ports, if we take for example the up port we are going to define it as of type pure and more formally we say that up takes one of two values either absent / present. We define it as a signal that maps the real values which represent timeline to one of two values absent  and present.

that is
up : R → {absent,present}
that is
up(t)∈  {absent,present}

and now if we focus on the entire counter we find 
Counter : ( R→ {absent,present})^p  →  (R → {absent}∪N )

So count is a signal mapping the reals to the set absent union n. So n here as commonly used, denotes the set of natural numbers, so the set of numbers starting with 0,1, 2 3, 4, et cetera.And we include that also the special value absent.And this is to indicate the fact that if you
sample the value of the single count at arbitrary times,you may not always get a legal value, which is a natural number.
Count is not a pure signal because it's not just taking two values, absent and present.
It can take either absent or any natural number.And now, given the type descriptions of the input ports and the output ports of the counter actor,we can write down the overall type of the counter actor as follows.So the counter actor is something that takes
in two signals, that are pure signals, so they map r to absent, present.And the way I indicate that these are two signals is to write this notation where it is, the type of each signal raised to p, which is the set of port names for the two inputs.

Visual representation of the state machine



State machine is a way of describing the discrete behavior of systems. it represents the transitions between states of the system. Here we see the states that the count variable can be at ( 0 , 1 , 2 , .. M ) where M is the maximum value that the counter can take. the arrows represents the transition between states. for example the transition between state 0 , state 1 occurs when up counter is active and down signal is not active ( notice the logical notation for and and not and how it is used )  the input that triggered the transition is written on the arrow (also called the guard ) followed by  a forward slash which is used to indicate the output produced from this transition ( the count variable here ). there is two types of state machine available :

MEALY machines

Mealy machine are ones in which the output of the state machine occurs on the transition and associated with the transition.

MOORE machines

Moore state machines are machines where the outputs of the state machine are associated with states rather than transitions.

Our choice of using the Mealy machine is somewhat arbitrary. You could use either one, depending on which better fits your modeling context.
In a lot of situations, the output value of a system doesn't always have you legal or a consistent value. And so usually when the transition is made, you set the output value. And then when you're in the state, it may be the case that you don't want to regard that output value as being something that's legal. And in such a situation it make sense to have a Mealy machine. And so really the convention of using the Mealy versus the Moore machine depends on the reality of the system that you are modeling.