Stream- and State-Based Semantics of Hierarchy in Block Diagrams Ben Denckla * Pieter J. Mosterman ** * Denckla Consulting, USA (Tel: 310-275-4249; e-mail: bdenckla@alum.mit.edu). ** The MathWorks, Inc., Natick, MA 01760 USA (e-mail: pieter.mosterman@mathworks.com) Abstract: Block diagrams are often used in embedded system design for modeling both plant and controller, typically with continuous and discrete modeling, respectively. Though easy to use, advanced users and implementers of these languages often run afoul of subtle semantic problems these seemingly simple languages can have. Based on the stream- and state-based approaches, this paper discusses how the specialized state-based semantics of continuous-time block diagrams can interoperate hierarchichally with discrete-time block diagrams. The languages presented may serve as a reference of sorts, helping to clarify some of the underlying choices in block diagram language design, and in the process shedding light on the differences between, and limitations of, existing block diagram languages. 1. INTRODUCTION To manage the complexity of engineered systems three concepts can be applied: (i) partitioning, (ii) modularity, and (iii) hierarchy. This work adds the notion of hierarchy to previous work by Denckla and Mosterman [2004, 2005] and Denckla et al. [2005] on developing a precise semantics for block diagrams. A block diagram consists of a collection of blocks with geometric shapes that represent mathemati- cal operations on a set of input variables to produce output variables. Such diagrams are also referred to as causal block diagrams by Posse et al. [2002], hierarchical signal- flow diagrams by Karsai et al. [2003] and time-based block diagrams by Mosterman and Ciolfi [2004]. Block diagrams are the basic language of the widely used commercial product Simulink R (Simulink [2004]). Block diagrams support continuous time as well as discrete time, which is important to facilitate analysis of a continuous- time plant model in combination with a discrete-time controller model. The combination of continuous-time and discrete-time models leads to a mathematical representa- tion called a hybrid dynamic system. In this context, the precise definition of how hierarchy is implemented is critical in the context of formalizing block diagrams. In industrial strength design products different implementations of hierarchy are supported. For example, in Simulink hierarchy exists in the form of virtual and nonvirtual subsystems, libraries, referenced models, and referenced binaries with a well-defined application programming interface (API). Though users desire such flexibility, it complicates a formal analysis of the language. In particular, support for binaries through an API is difficult to analyze as it pertains to a language other than block diagrams. The work presented in this paper seeks to be more precise, and, as such, it will be more limited in its flexibility to facilitate different implementations of hierarchy. In another sense, however, this work is more flexible as it will analyze the use of hierarchy in the context of both stream-based execution as well as state-based execution. A stream-based approach to analyzing block diagrams is a natural fit that allows a functional perspective on the block diagram language. As such, it supports developing precise and unambiguous semantics, which has been ex- ploited in work by Halbwachs et al. [1991], Halbwachs [1998] and Halbwachs and Raymond [1999] to design a language for safety critical systems. This language applies to discrete-time reactive systems only, though. This work investigates the differences between stream- based and state-based execution and studies their use in hierarchical hybrid dynamic system decomposition. The state-based approach is presented as more amenable to handling continuous-time behaviors because it requires so- phisticated state-based numerical integration algorithms. In other work, Caspi and Pouzet [1997] examine the dif- ferences between stream- and state-based discrete system models outside the block diagram context. It covers the im- portant issue of the limited scope of the state-based model. For example, the state-based model cannot easily describe multirate systems, whereas the stream-based model can. In work by Liu et al. [2004] the state-based approach is effectively used to model hybrid dynamic systems, where a director implements the integration algorithms. The block diagram language is then specified by a mapping onto an imperative programming language. Instead, this work takes a higher level approach to language design by using lambda calculus (Nielson and Nielson [1992]) as a general model of computation onto which the block diagram language is mapped. This eliminates the need of introducing imperative concepts at an early state in the language design, and, therefore, reasoning on the semantics can be at a higher level and without the need to deal with the specific execution details.