<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>StateWORKS Blog &#187; stateworks</title>
	<atom:link href="http://www.stateworks.net/tag/stateworks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stateworks.net</link>
	<description>StateWORKS blog about software engineering using virtual finite state machines</description>
	<lastBuildDate>Mon, 24 Aug 2009 15:38:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Calculator</title>
		<link>http://www.stateworks.net/2009/08/calculator/</link>
		<comments>http://www.stateworks.net/2009/08/calculator/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 12:34:10 +0000</pubDate>
		<dc:creator>Ferdinand Wagner</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[stateworks]]></category>
		<category><![CDATA[Calculator]]></category>
		<category><![CDATA[Calculator design]]></category>
		<category><![CDATA[state machine]]></category>

		<guid isPermaLink="false">http://www.stateworks.net/?p=25</guid>
		<description><![CDATA[Recently I was asked to complete our state machine designs presented on our web site by an example of an application controlling a user interface. The suggestion was to show an calculator design similar to the example of the Visual Basic calculator, as described in the book by Horrocks: “Constructing the User Interface with Statecharts” [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was asked to complete our state machine designs presented on our web site by an example of an application controlling a user interface. The suggestion was to show an calculator design similar to the example of the Visual Basic calculator, as described in the book by Horrocks: “Constructing the User Interface with Statecharts” and also discussed by Samek in his more recent book: “Practical Statecharts in C/C++”. Samek does at least establish a strong case for basing such a design on a finite state machine, after discussing many defects of the Microsoft solution, but his design can and should be improved upon.</p>
<p class="textkörper-einzug" lang="en-US">My first idea was just to repeat this example. Before I started I made a short analysis of the topic &#8220;calculator&#8221; discovering some interesting points. Using calculators I imagined that something like a standard user interface existed. I have been sometimes confused when getting into my hands a new calculator whose behavior is different to other ones. Anyway, I never worried much about this as my interest is limited to very simple operations. If my calculations are a bit longer or more complex I use spreadsheets.</p>
<p class="textkörper-einzug" lang="en-US">Let&#8217;s then define the calculator to be designed. The simplest calculator possesses the keys:</p>
<ul>
<li>
<p class="textkörper-einzug" lang="en-US">to define the 	operands: digits (0..9), number sign (±) and decimal point (.)</p>
</li>
<li>
<p class="textkörper-einzug" lang="en-US">to define the 	operations: add (+), subtract (-), multiply (*), divide (/), equals 	(=)</p>
</li>
</ul>
<p class="textkörper-einzug" lang="en-US">It has a display to show the operand typed in and the calculation result.</p>
<p class="textkörper-einzug" lang="en-US">The few calculators I had at hand are similar but the use of the keys is not standardized:</p>
<ul>
<li>
<p class="textkörper-einzug" lang="en-US">the role of keys C 	and CE are interchanged; sometimes they get other names</p>
</li>
<li>
<p class="textkörper-einzug" lang="en-US">the equals key (=) 	allows sometimes the calculation to be continued</p>
</li>
<li>
<p class="textkörper-einzug" lang="en-US">the continuation of 	calculation after termination may be done using operation keys +-*/</p>
</li>
</ul>
<p class="textkörper-einzug" lang="en-US">The calculation scheme of Samek&#8217;s example adheres to the standard one: an actuation of an operation key (+-*/) is unique and defines the next operation, the following actuation of operation keys are ignored and the calculator awaits the operand. The limitation has been introduced to show that in such a case it is possible to use the key “-” in a double role: as an operation key (subtract) and as a sign of the operand. The other simplification is the priority of operations: they are performed in the sequence in which they are entered, let&#8217;s call it the “arithmetic for dummies”. It means that typing “1+2*3=” you get 9 instead of the expected 7. Maybe for people who terminated their education in the first class of the grammar school such calculations make sense but most of us respect the usual priority of arithmetic operations and such calculator would be rather useless for them. Imagine you want to calculate your shopping expenses: a piece of butter, 4 bottles of beer, 3 bars of chocolate, etc; no chances to do it with such a calculator (unless it has an add-to-memory feature of course). You find this kind of arithmetic in “simple” calculators. A curiosity of the Windows calculator is that in the Standard mode uses the “arithmetic for dummies” and if you switch to the Scientific mode it uses the arithmetic priority rules. Strange, the use of normal arithmetic is considered as a scientific approach! This limitation in the Samek example is obvious: to make the example as simple as possible, otherwise it will be too difficult. This is a artificial example, used to explain how to use statecharts in UML design. Obviously, UML statecharts does not work for any more practical problem.</p>
<p class="textkörper-einzug" lang="en-US">As we prefer to work with examples taken from practice I had to decide which calculator from the few ones on my table and screen should be emulated. Eventually, I decided to design the calculator similar to one found on any computer running Windows.</p>
<p class="textkörper-einzug" lang="en-US">Playing a little bit with this calculator I have found it has rather strange behavior in some situations. It is fairly easy to get the calculator to produce random results without any indication that the only way out is to reset it using the key “C”. For instance, trying “2/0+” you get expected &#8220;Cannot divide by 0&#8243; but continuing with keys “CE” and “=” you get 10 (!). Maybe it is the code number of the software bug! Typing “2/0”= you get the same expected &#8220;Cannot divide by 0&#8243; but continuing with keys “CE” and any new operand the calculator is in a loop generating &#8220;Cannot divide by 0&#8243; which is in a way better. Of course the only solution is again the reset with the key “C”. Another example: “5+9/=” produces 10 which corresponds to “5+=” the pretended algorithm of using equals key “=”. But typing “5+9/CE=” produces an error message “Cannot divide by 0” (i.e. the clear key introduces 0 as an operand!). And now try “5+9/0=CE” and you get 100!</p>
<p class="textkörper-einzug" lang="en-US">The calculator has another problems with unexpected sequences of operation keys. For instance, if you type “2+7*=” you get 4 (in Scientific mode). The Windows calculator manifests also a specific behavior after terminating the calculation with the equals key “=”. Repeating the key “=” performs the last operation using the result and the last operand; effectively it is the cash register function which is done normally using the key “+”. But if you change the operation and continue with the key “=” it continues using in the first step the last result as both operands. No idea what is this function for. I could not find any explanation of the described (faulty?) behavior in the voluminous Help which describes many obvious topics but does not explain how the calculator is to behave in the above described situations. In this situation the calculator ignores also entered numbers without informing the user about it. So if you type for instance”1+2=” you get 3. Entering then “4=” you get 5 which is OK in relation to the cash registration function but is confusing for the user who entered 4 having something else in mind. Investigating more carefully the behavior after entering the key “=” you will find also an algorithm that explains the strange result of previously shown operation “2+7*=”. This algorithm says: forget the last operator and operand and perform the cashier function. This might explain the behavior but what is this functionality for? Of course, the results in examples discussed in this section are different for Scientific and Standard modes. A possible use for this feature is to calculate compound interest: try 1.06 * = = = = = ; each = shows the effect of an extra 6% compound interest.</p>
<p class="textkörper-einzug" lang="en-US">The calculator seems also to have difficulties with operation on and presentation of floating point numbers. By typing the sequence &#8220;9- sqrt =&#8221; you get 6 (as expected). By repeating the Equal sign you expect to get values decreasing by 3. It works but the 0 value is not correctly displayed. Namely the results are: 3, -3,46391&#8230;e-37, -3, -6, etc. I have not investigated this problem further as the numerical computation is not my favorite topic but it is a rather strange effect.</p>
<p class="textkörper-einzug" lang="en-US">To get a more complete picture I have taken another calculator that I have in my drawer and repeated the same exercises getting different results but also partly erroneous!</p>
<p class="textkörper-einzug" lang="en-US">I have to admit that after that experience I was a bit shocked. I have been convinced that a calculator is a mature product delivering correct results, not only for operations like 2+2. Obviously the software in these tested examples fails in &#8220;unexpected&#8221; situations. It is more or less a known problem in software implemented according to &#8220;use cases&#8221;, where the adequacy of the set of &#8220;cases&#8221; is left to the good will, time and ability of programmers.</p>
<p class="textkörper-einzug" lang="en-US">After that introductory work I decided to take the problem seriously and design it with StateWORKS. I have been convinced that it is possible to get a calculator which behaves as required in all situations. I will present it in few steps. You find the discussion in the Case study section in a document “<a href="http://www.stateworks.com/technology/casestudy/" target="_blank">Calculator</a>”.</p>
<p class="textkörper-einzug" lang="en-US">
]]></content:encoded>
			<wfw:commentRss>http://www.stateworks.net/2009/08/calculator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing &#8220;Questions&#8221;</title>
		<link>http://www.stateworks.net/2009/03/introducing-questions/</link>
		<comments>http://www.stateworks.net/2009/03/introducing-questions/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 11:16:27 +0000</pubDate>
		<dc:creator>Ferdinand Wagner</dc:creator>
				<category><![CDATA[Questions]]></category>
		<category><![CDATA[Finite state machine]]></category>
		<category><![CDATA[stateworks]]></category>
		<category><![CDATA[VFSM]]></category>

		<guid isPermaLink="false">http://stateworksnet.cmarc.net/2009/03/introducing-questions/</guid>
		<description><![CDATA[In the category &#8220;Questions&#8221; you can ask any question about Virtual Finite State Machines or about how to use StateWORKS development tools. Simply post a comment to this entry.
]]></description>
			<content:encoded><![CDATA[<p>In the category &#8220;Questions&#8221; you can ask any question about Virtual Finite State Machines or about how to use StateWORKS development tools. Simply post a comment to this entry.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stateworks.net/2009/03/introducing-questions/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Getting started</title>
		<link>http://www.stateworks.net/2008/07/getting-started/</link>
		<comments>http://www.stateworks.net/2008/07/getting-started/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 10:38:38 +0000</pubDate>
		<dc:creator>Ferdinand Wagner</dc:creator>
				<category><![CDATA[stateworks]]></category>
		<category><![CDATA[entry action]]></category>
		<category><![CDATA[Finite state machine]]></category>
		<category><![CDATA[input action]]></category>
		<category><![CDATA[state transition]]></category>

		<guid isPermaLink="false">http://stateworksnet.cmarc.net/2008/07/getting-started/</guid>
		<description><![CDATA[I received an email from John M. who is evaluating StateWORKS. He started with a fairly complex example that has confronted him with several issues that must be understood to use effectively our tools and the run-time system. Because of a general nature of his questions I put (with his acceptance) my answers into that [...]]]></description>
			<content:encoded><![CDATA[<p>I received an email from John M. who is evaluating StateWORKS. He started with a fairly complex example that has confronted him with several issues that must be understood to use effectively our tools and the run-time system. Because of a general nature of his questions I put (with his acceptance) my answers into that blog.</p>
<p><span id="more-7"></span><br />
Before I answer your questions I would like to make a general comment. There are two aspects of any method that uses a state machine concept. The first one is the specification, the second its implementation. Most methods are just limited to the specification. In that case the implementation is left to the user that interprets it on his own and completes the missing issues in the specification. After a while the specification looses its meaning and only the implementation (that is the code) counts. This rule is true not only for a state machine specification but defines a relation between any specification and implementation. We want to do it better in StateWORKS and provide a run-time system that executes the specification. The obvious consequences of our approach are:<br />
- The specification must be complete as there is no chance to complete it in the code.<br />
- While specifying we have to keep in mind the execution model.<br />
The last problem should not be underestimated as you will see later when I answer your question.<br />
<em>Q1) The execution sequence of input actions in the current state is not ordered per 4th point in box at top of page 187. Fine. From page 199 : “ …. actions may change other control variables and in turn corresponding virtual inputs: all of them are treated 1-by-1 in the emerging sequence until all events are fully processed.” Does this imply that input actions in the present state may be executed iteratively? [Yes - order of consequent and causative input actions in StateA ST immaterial!] If an input action that was not due initially then becomes due after a subsequent due action is performed will it get executed? [Yes] The flowchart on page 186 implies not, I think.</em><br />
A1. The first part of the book is about specification of a state machine and a system of state machines. We have tried to keep it implementation independent and therefore we have limited our consideration of the execution path to the flow chart represented on p.186. We need the flowcharts to explain the  basic idea of multiple state transitions after a single events. Note that other implementations are imaginable and also available in StateWORKS (we can discuss it sometime later). The executor as implemented in RTDB has a queue (which is not shown on the flow chart) where events wait to be served. If the executor terminates serving of a given state machines (i.e. there are no transitions due) it returns on the flow chart to the point &#8220;wait for VI change&#8221;. The real executor checks whether the queue is empty and if not it takes the event from the queue and continues. In reality it is still more complex but I try in this moment just to explain the mechanism.<br />
<em>Q2. With multiple state transitions after a single VI event, the input actions of the intermediate states are ignored per 2nd point in box at top of page 187. Ok but what about those of the final state? [Also ignored.] If these simply do not get executed I have concerns that the vfsm will be left sitting in the final state when it may have already due input actions that would cause actions resulting in changed outputs or even further state changes. [True] Assuming such due input actions remained so, they’d then get executed when the next (unrelated?) VI event occurred – yes? [Yes – toggling the increment Cnt1 DI causes StateB to then trigger input actioned DO-HIGH showing Cnt2 over!] Possible alternative ………determining no immediate state transition is due defines the “final” state and then if the VI has changed since starting execution of the original current state this should be a “new” VI event causing any due input actions of the “final” (for now) state? </em><br />
A2. Yes, by multiple transitions only the input actions in the starting state are performed. We are not able to distinguish between intermediate states and a final one. In event driven systems there is always a chance of &#8220;missing&#8221; trigger. We have to think about it while specifying the system. We should not overuse the input actions. The best state machines are of type Moore where the only actions are the entry actions. We pay for the simplicity with more states but avoid problems with input actions. Do not forget we are not building a hardware system where number of state does cost. In  software minimizing the number of state is a rather irrelevant criteria; we should speak about optimizing the number of state, i. e. to have as many states as we need to make an understandable state machine.<br />
<em>Q3. Something that came up in my test : An entry action does ResetStart on a counter that was over. There is a transition action with condition same counter over – it gets triggered? </em><br />
A3. If the counter is reset the control value OVER is replaced by RESET. Thus, any condition containing the RESET value could be triggered (but not the condition with OVER which is not present any more). This effect has come up because of the generation I have explained in my direct email to you discussing the details of your state transition diagram.<br />
<em>Q4. Lastly a probably silly question but just to make sure I’m not missing something ……. Is it true that there is no way to cause an external source input (DI, DAT, PAR, NI) to change other than to have the controlled system or the “user” do it or for an OFUN to do it (DAT I’d assume)? Don’t see a way to connect a controlled system input to one of it’s outputs in swLab or SwMon?</em><br />
A4. There are 3 types of objects in the specification system (and consequently in RTDB): input, output and input/output type. An input type as for instance DI can be used as a condition to control a transition or an input action. An output type as for instance DO can be used to define an action to be performed. The input/output as for instance XDA can be used (with some restrictions) for both purposes.<br />
Other issues seen in your first example:<br />
- The use of Input actions should be limited to actions that can be repeated without any side effects. For instance setting a Do output several times does not do any harm. But incrementing a counter on a static control value (like Di) will in general result in erroneous behavior: if the Di value (which triggers the counter) stays HIGH any event triggers the execution of Input actions, i.e. the counter will increment. Any event causes execution of the state machine as shown in the flow chart.<br />
- Due to multi state transition mechanism a not “consumed” transition condition may cause an unintended transition while returning to the initial state. This results in an infinite loop that is detected and terminated by the Executor but it is of course an erroneous, not intended behavior.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stateworks.net/2008/07/getting-started/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is a state machine?</title>
		<link>http://www.stateworks.net/2008/03/what-is-a-state-machine/</link>
		<comments>http://www.stateworks.net/2008/03/what-is-a-state-machine/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 06:00:00 +0000</pubDate>
		<dc:creator>Ferdinand Wagner</dc:creator>
				<category><![CDATA[Finite state machine]]></category>
		<category><![CDATA[automata]]></category>
		<category><![CDATA[state]]></category>
		<category><![CDATA[state machine]]></category>
		<category><![CDATA[stateworks]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://stateworksnet.cmarc.net/2008/03/what-is-a-state-machine/</guid>
		<description><![CDATA[Our web site contains several technical notes and papers that discuss some aspects of software engineering associated with the concept of a finite state machine. On introducing our blog we have decided to present you a few topics covered by a group of our documents. We started with the  Mealy and Moore models of [...]]]></description>
			<content:encoded><![CDATA[<p>Our web site contains several technical notes and papers that discuss some aspects of software engineering associated with the concept of a finite state machine. On introducing our blog we have decided to present you a few topics covered by a group of our documents. We started with the  Mealy and Moore models of a finite state machine, honoring the fact that it is a favorite topic according to visitors&#8217; statistics. The topic that we would like to present you today is &#8220;What is a state machine&#8221;.</p>
<p><span id="more-5"></span><br />
The concept of a state machine is old; its definition belongs to the basics of Automata Theory. In principle it seems to be a simple definition and requires understanding of the &#8220;state&#8221; concept. In spite of its simplicity the concept has been deformed, corrupted, misunderstood and up now the well known <a href="http://www.stateworks.com/active/download/wagf04-2-state-machine-misunderstandings.pdf"> misunderstandings</a> about a state machine result in a relatively modest use of the state machine idea in the specification and design of software. In our publications we try to indicate that a state machine is so well defined (see for instance <a href="http://www.stateworks.com/book/book/">the book</a> or <a href="http://www.stateworks.com/technology/TN15-Whats-All-This-State-Machine-Stuff/">the technical note</a> and the the already mentioned document about <a href="http://www.stateworks.com/technology/TN10-Moore-Or-Mealy-Model/">Moore and Mealy models</a>) that it does not require re-definitions or (mis-)interpretations, especially that:<br />
- <a href="http://www.stateworks.com/technology/TN9-Flowchart-is-not-State-Machine/">a flow chart is not a state machine</a><br />
- a Petri net is not a state machine<br />
- a statechart is not a state machine<br />
- there is no need to define an incomplete state machine under a new name (see for instance <a href="http://www.stateworks.com/technology/TN11-Going-Beyond-Limitations-Of-IEC-61131/"> the technical note</a>)<br />
- it is possible to create a complex control system <a href="http://www.stateworks.com/technology/TN3-HierarchicalSystem/">modeled </a> by a system of state machines<br />
to name only some topics discussed in our documents.<br />
We are convinced that the concept of a finite state machine is one of the strongest ideas in the world of modelling control tasks in general and specifically in the design of a software control flow. A typical implementation of software control flow using the if-then-else and switch like mechanisms supported by numerous flags is a primitive style of development difficult to understand and accept in the 21 century.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stateworks.net/2008/03/what-is-a-state-machine/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Moore or Mealy model</title>
		<link>http://www.stateworks.net/2008/02/moore-or-mealy-model/</link>
		<comments>http://www.stateworks.net/2008/02/moore-or-mealy-model/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 15:58:06 +0000</pubDate>
		<dc:creator>Ferdinand Wagner</dc:creator>
				<category><![CDATA[Finite state machine]]></category>
		<category><![CDATA[Mealy]]></category>
		<category><![CDATA[Moore]]></category>
		<category><![CDATA[state machine]]></category>
		<category><![CDATA[stateworks]]></category>

		<guid isPermaLink="false">http://stateworksnet.cmarc.net/2008/02/moore-or-mealy-model/</guid>
		<description><![CDATA[Moore and Mealy models are the basic two models of state machines as defined in the literature. To understand the differences between them the actions (outputs) must be defined and bound to state changes. The technical note &#8220;Moore or Mealy model?&#8221; discusses both models and shows that the optimal solution is achieved when features of [...]]]></description>
			<content:encoded><![CDATA[<p>Moore and Mealy models are the basic two models of state machines as defined in the literature. To understand the differences between them the actions (outputs) must be defined and bound to state changes. The technical note &#8220;<a href="http://www.stateworks.com/active/download/TN10-Moore-Or-Mealy-Model.pdf">Moore or Mealy model?</a>&#8221; discusses both models and shows that the optimal solution is achieved when features of both models are used in a mixed model. Although the concepts of these two models are useful when performing certain theoretical studies, they are also interesting for software developers, and StateWORKS makes the use of a mixed model easy and effective.</p>
<p><span id="more-4"></span><br />
Mealy and Moore models are the basic models of state machines. A state machine which uses only Entry Actions, so that its output depends on the state, is called a Moore model. A state machine which uses only Input Actions, so that the output depends on the state and also on inputs, is called a Mealy model. The models selected will influence a design but there are no general indications as to which model is better. Choice of a model depends on the application, execution means (for instance, hardware systems are usually best realized as Moore models) and personal preferences of a designer or programmer. In practice, mixed models are often used with several action types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stateworks.net/2008/02/moore-or-mealy-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

