Book contents
- Frontmatter
- Contents
- Preface
- I Why Z?
- II Introducing Z
- III Elements of Z
- 8 Elements
- 9 Structure
- 10 Logic
- 11 Synthesis
- 12 Schemas and schema calculus
- 13 Schema types and bindings
- 14 Generic definitions and free types
- 15 Formal reasoning
- Further reading
- IV Studies in Z
- V Programming with Z
- Further reading
- A Glossary of Z notation
- B Omitted features
- C Operator precedence
- D The Z mathematical tool-kit
- E Selected Laws
- F Solutions to selected exercises
- G Other formal notations
- Bibliography
- Index
8 - Elements
Published online by Cambridge University Press: 06 July 2010
- Frontmatter
- Contents
- Preface
- I Why Z?
- II Introducing Z
- III Elements of Z
- 8 Elements
- 9 Structure
- 10 Logic
- 11 Synthesis
- 12 Schemas and schema calculus
- 13 Schema types and bindings
- 14 Generic definitions and free types
- 15 Formal reasoning
- Further reading
- IV Studies in Z
- V Programming with Z
- Further reading
- A Glossary of Z notation
- B Omitted features
- C Operator precedence
- D The Z mathematical tool-kit
- E Selected Laws
- F Solutions to selected exercises
- G Other formal notations
- Bibliography
- Index
Summary
This chapter introduces the three basic constructs that appear everywhere in Z texts: declarations, expressions, and predicates. Declarations, introduce variables. Expressions describe the values that variables might have. Predicates express constraints that determine which values the variables actually do have.
Sets and types, declarations, and variables
The systems that we need to model might contain vast numbers of things. How can we possibly deal with them all? We gather similar objects into collections and treat each collection as a single object in its own right. These collections are called sets. Sets are central in Z.
Displaying sets
The obvious way to describe a set is to list or enumerate all of its members or elements. This is called a set display. In Z we follow the ordinary mathematical convention and write sets with braces, separating elements by commas. Here is a display of the set of lamps in a traffic light:
{red, yellow, green}
Elements in a set are not ordered, so the order you write elements in a set display is not significant. Here is another (equally good) display of the same set:
{yellow, red, green}
Sets contain no duplicate elements, and mentioning the same element more than once is redundant but innocuous.
- Type
- Chapter
- Information
- The Way of ZPractical Programming with Formal Methods, pp. 63 - 77Publisher: Cambridge University PressPrint publication year: 1996