# Z 记号

Z 记号（Z notation）是一种用于描述计算系统的形式化规格语言，以类型化集合论和一阶谓词逻辑为基础，规格通过称为“模式”的单元来组织。<sup>[1](https://www.cs.ox.ac.uk/publications/publication3791-abstract.html)</sup><sup> • </sup><sup>[2](https://researchportal.lsbu.ac.uk/ws/portalfiles/portal/6315197/e0b10811_setss2014.pdf)</sup> 它由牛津大学编程研究组在让-雷蒙·阿布里亚尔（Jean-Raymond Abrial）领导下于1980年前后开发，名称来自策梅洛-弗兰克尔集合论（Zermelo-Fraenkel set theory）。<sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup> Z 是一种规格记号，而非完整的形式化方法：它描述系统应该做什么，而不描述如何根据该描述开发代码，并且 Z 规格不可执行。<sup>[4](https://www.researchgate.net/publication/2480325_Formal_Specification_and_Documentation_using_Z_A_Case_Study_Approach)</sup><sup> • </sup><sup>[5](https://etheses.whiterose.ac.uk/17776/1/thesis_acp12mus_rev.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 是什么 | 一种基于类型化集合论和一阶谓词逻辑的形式化规格记号，用于离散计算机系统<sup>[2](https://researchportal.lsbu.ac.uk/ws/portalfiles/portal/6315197/e0b10811_setss2014.pdf)</sup> |
| 核心构造 | 模式，即把声明和谓词组合在一起的具名方框；模式可以相互包含，并可用模式运算符组合<sup>[1](https://www.cs.ox.ac.uk/publications/publication3791-abstract.html)</sup><sup> • </sup><sup>[2](https://researchportal.lsbu.ac.uk/ws/portalfiles/portal/6315197/e0b10811_setss2014.pdf)</sup> |
| 起源 | 牛津大学编程研究组，在让-雷蒙·阿布里亚尔领导下，约1980年；以策梅洛-弗兰克尔集合论命名<sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup> |
| 标准 | ISO/IEC 13568:2002，涵盖语法、类型系统、语义、数学工具包，以及 LaTeX 和电子邮件标记<sup>[6](https://www.iso.org/cms/%20render/live/en/sites/isoorg/contents/data/standard/02/15/21573.html)</sup> |
| 最著名的工业应用 | 1981年起为 IBM 的 CICS 事务处理系统的新模块编写规格；1992年4月获女王技术成就奖<sup>[7](https://people.cs.nott.ac.uk/pszrq/files/SpecificationCaseStudies.pdf)</sup> |
| 现状 | 是一种规格语言，不可执行；普遍认为尚无代码生成器可用，工业实践已在很大程度上转向以工具为中心的方法，如 B/Event-B、Alloy 和 TLA+<sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup><sup> • </sup><sup>[8](https://codearchaeology.dev/languages/z-notation/)</sup> |

## 模式与数学工具包

Z 规格有两个层次：数学语言和模式语言。<sup>[9](https://eprints.soton.ac.uk/165419/1/ThesisM.pdf)</sup> 数学层次依托集合论、关系、函数和序列，参考手册将其呈现为一个“数学工具包”，其中每个符号都有用 Z 本身给出的形式定义、一段非形式描述，以及一组代数定律。<sup>[10](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)</sup> 阅读规格需要具备朴素集合论和谓词演算的基本知识。<sup>[10](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)</sup>

模式是主要的组织手段。一个模式由一组具名对象构成，这些对象由公理加以规定，Z 提供了组合模式的记号，使大型规格得以分阶段构建。<sup>[1](https://www.cs.ox.ac.uk/publications/publication3791-abstract.html)</sup> 在竖式形式中，声明位于分隔线上方，谓词位于下方；同一模式也可以用方括号写成横式，新模式可以通过用模式演算的运算组合旧模式来定义。<sup>[10](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)</sup> 模式语言可以描述系统的状态以及该状态可能变化的方式。<sup>[11](https://www.cs.cmu.edu/~15819/zedbook.pdf)</sup> 一个经典的教学示例是生日簿，它记录人们的生日并在适当的日子发出提醒；其状态模式声明一个已知姓名的集合和一个从姓名到生日的函数，并用一个不变式把该集合与函数的定义域联系起来。<sup>[10](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)</sup>

模式赋予规格模块化结构：模式可以被命名、包含、组合和复用，模式演算用于将规格模块化。<sup>[8](https://codearchaeology.dev/languages/z-notation/)</sup><sup> • </sup><sup>[10](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)</sup> 在比较性评估中，组合机制获得良好评价，这得益于关于模式和提升的明确定义的理论。<sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup>

## 精化与开发

Z 包含数据精化，即把抽象规格开发为更具体设计的过程，以及针对顺序程序的操作精化。<sup>[10](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)</sup> 其精化理论发展成熟，具有技术上完备的前向和后向精化证明规则。<sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup> 精化无法把开发一直带到代码层次：正如鲍恩（Bowen）所写，Z 允许一定程度的数据精化和操作精化，但要到达代码，最终需要一次通常以非形式方式完成的跳跃。<sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup>

B 方法（B-Method）正是从这一传统中发展出来的。其抽象机记号（Abstract Machine Notation）被描述为一种基于 Z 的形式化方法，配有工业级工具集支持，后来的 Event-B 方法及其工具 Rodin 和 ProB 则受到了 B、Z 和 VDM 实践经验的塑造。<sup>[12](https://www.sciencedirect.com/science/article/pii/095058499599366U)</sup><sup> • </sup><sup>[13](https://pure.au.dk/portal/en/publications/on-fitting-a-formal-method-into-practice)</sup>

## 工业应用：CICS 项目

IBM（英国）实验室与牛津编程研究组从1981年起开展了一项联合研究项目，考察形式化规格技术能否扩展到工业软件规模。<sup>[7](https://people.cs.nott.ac.uk/pszrq/files/SpecificationCaseStudies.pdf)</sup> 目标系统是 CICS（客户信息控制系统，Customer Information Control System），即 IBM 主要的 System/370 在线事务处理系统，用于银行、航空订票和保险业务，到20世纪80年代初已包含超过80万行代码。<sup>[7](https://people.cs.nott.ac.uk/pszrq/files/SpecificationCaseStudies.pdf)</sup> 在牛津研究人员完成早期案例研究后，CICS 程序的一部分被重构和重写，并为新代码编写了 Z 规格；Z 被用于约14%的新代码，仍然达到数万行。<sup>[7](https://people.cs.nott.ac.uk/pszrq/files/SpecificationCaseStudies.pdf)</sup> 1988年，当时均隶属于 IBM 的 C. J. Nix 和 B. P. Collins 在一篇 IBM 论文中报告，有可能在最终仅增加很少开发成本的情况下大幅减少软件质量缺陷的数量。<sup>[14](https://research.ibm.com/publications/use-of-software-engineering-including-the-z-notation-in-the-development-of-cics)</sup>

1992年4月，牛津大学计算实验室与 IBM（英国）实验室有限公司因在事务处理系统开发中使用 Z 记号而共同获得女王技术成就奖。<sup>[7](https://people.cs.nott.ac.uk/pszrq/files/SpecificationCaseStudies.pdf)</sup><sup> • </sup><sup>[11](https://www.cs.cmu.edu/~15819/zedbook.pdf)</sup> 关于 CICS/ESA 3.1 版本最广为宣传的说法是：客户报告的错误数不到正常水平的一半，总开发成本节省9%；1996年《系统与软件杂志》（*Journal of Systems and Software*）上的一项评估得出结论，该案例研究重要且有价值，但那些定量说法并未得到证实。<sup>[15](https://www.sciencedirect.com/science/article/pii/S0164121296001227)</sup> 后来 IBM 赫斯利（Hursley）的一个项目为 CICS 应用编程接口的很大一部分制作了形式化描述，由于该 API 是公共接口，因此可以公开发表。<sup>[7](https://people.cs.nott.ac.uk/pszrq/files/SpecificationCaseStudies.pdf)</sup>

Z 也被用于与安全和安保相关的开发。Tokeneer ID Station 项目由 Altran Praxis 为美国国家安全局开发，其规格用 Z 形式化，精化为形式设计，并用 SPARK 开发软件；该项目于2008年向更广泛的社区开放后，在严格审查下只发现了五个错误。<sup>[16](https://eceasst.org/index.php/eceasst/article/view/1885)</sup>

## 标准化与语言设计

国际标准 ISO/IEC 13568:2002《信息技术——Z 形式化规格记号——语法、类型系统和语义》涵盖该记号的语法、类型系统和语义，一套广泛使用的数学运算符工具包，以及 LaTeX 和电子邮件标记；它明确排除了任何使用 Z 的方法，不过一个资料性附录描述了一种广泛使用的惯例。该标准最近于2026年经过复审并确认，目前仍然有效。<sup>[6](https://www.iso.org/cms/%20render/live/en/sites/isoorg/contents/data/standard/02/15/21573.html)</sup>

该标准源于 J. M. 斯派维（J. M. Spivey）的《Z 记号：参考手册》（*The Z Notation: A Reference Manual*，第2版，Prentice-Hall，1992年），这是牛津大学的主要教学文本。<sup>[17](https://www.cs.ox.ac.uk/teaching/courses/2011-2012/intro2spec/)</sup> 斯派维的手册有意省略了重载，因为模式连接时识别公共成分很难与两个不同变量共用一个名称相协调；手册也省略了用于推导规格定理的形式推理规则，理由是当时经验不足以让这些规则顺畅地相互作用。<sup>[10](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)</sup>

## 工具支持与当前地位

按比较性评估，Z 的工具支持至少处于中等水平。CZT（社区 Z 工具，Community Z Tools）以 Java 编写并作为开源软件分发，为创建针对 Z 及其方言的形式化方法工具提供了基础；它提供覆盖 Z、Object-Z 和 Circus 的解析器、类型检查器和打印器，一个只处理 Z 的受限子集的动画器，以及用于规格编辑的 jEdit 和 Eclipse 插件。<sup>[18](https://czt.sourceforge.net/manual.html)</sup> ProB 动画器和模型检查器主要是一个 B 方法工具，通过其 ProZ 扩展支持 Z 规格。<sup>[19](https://prob.cs.hhu.de/w/index.php?title=ProZ)</sup><sup> • </sup><sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup> Z 的证明工具被认为难以做好，部分原因是每个证明工具实际上都定义了自己的语义，而且记号的变化构成了理解上的障碍。<sup>[20](https://www.researchgate.net/publication/2644718_Approaches_to_proof_in_Z_-_or_-_Why_effective_proof_tool_support_for_Z_is_hard)</sup>

作为一种语言，Z 不直接支持并发建模；并发系统可以通过 Object-Z 与 CSP 结合等扩展，或通过 Circus 来处理。<sup>[3](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)</sup> 自2002年 ISO 标准以来，该记号本身变化很小，专门的 Z 用户会议已被并入范围更广的 ABZ 会议，工业实践也在很大程度上转向以工具为中心的方法，如 B/Event-B、Alloy 和 TLA+。<sup>[8](https://codearchaeology.dev/languages/z-notation/)</sup> Z 仍在教学和研究中使用，包括近期的形式化工作，例如 W3C《核心 SHACL 语义草案》（Draft Core SHACL Semantics）的 Z 规格。<sup>[21](https://arxiv.org/abs/1511.00384)</sup>

## References

1. [Mike Spivey (1984). Towards a Formal Semantics for the Z Notation. Oxford University Computing Laboratory, PRG-41.](https://www.cs.ox.ac.uk/publications/publication3791-abstract.html)
2. [The Z Notation (Sets Seminar notes), London South Bank University Research Portal.](https://researchportal.lsbu.ac.uk/ws/portalfiles/portal/6315197/e0b10811_setss2014.pdf)
3. [Mashkoor (2018). Evaluating the suitability of state-based formal methods for industrial deployment. Software: Practice and Experience.](https://onlinelibrary.wiley.com/doi/full/10.1002/spe.2634)
4. [Formal Specification and Documentation using Z: A Case Study Approach.](https://www.researchgate.net/publication/2480325_Formal_Specification_and_Documentation_using_Z_A_Case_Study_Approach)
5. [Support for Model Checking Z Specifications (thesis), White Rose eTheses.](https://etheses.whiterose.ac.uk/17776/1/thesis_acp12mus_rev.pdf)
6. [ISO/IEC 13568:2002 — Information technology — Z formal specification notation — Syntax, type system and semantics.](https://www.iso.org/cms/%20render/live/en/sites/isoorg/contents/data/standard/02/15/21573.html)
7. [Steve King (1992). The use of Z in the restructure of IBM CICS, in I. Hayes (ed.), Specification Case Studies.](https://people.cs.nott.ac.uk/pszrq/files/SpecificationCaseStudies.pdf)
8. [Z notation, CodeArchaeology.](https://codearchaeology.dev/languages/z-notation/)
9. [Thesis on Z specifications, University of Southampton Research Repository.](https://eprints.soton.ac.uk/165419/1/ThesisM.pdf)
10. [J. M. Spivey. The Z Notation: A Reference Manual, 2nd edition.](https://www.informatik.uni-bremen.de/agbs/lehre/Books/Z/zrm.pdf)
11. [The Z notation (course text), Carnegie Mellon University.](https://www.cs.cmu.edu/~15819/zedbook.pdf)
12. [Formal development in B abstract machine notation. Information and Software Technology.](https://www.sciencedirect.com/science/article/pii/095058499599366U)
13. [Gmehlich et al. On Fitting a Formal Method into Practice. Aarhus University.](https://pure.au.dk/portal/en/publications/on-fitting-a-formal-method-into-practice)
14. [C. J. Nix and B. P. Collins (1988). Use of software engineering, including the Z notation, in the development of CICS. IBM Research.](https://research.ibm.com/publications/use-of-software-engineering-including-the-z-notation-in-the-development-of-cics)
15. [Evaluating the effectiveness of Z: The claims made about CICS and where we go from here. Journal of Systems and Software 35(3), 1996.](https://www.sciencedirect.com/science/article/pii/S0164121296001227)
16. [Janet Barnes (2011). Experiences in the Industrial use of Formal Methods. ECEASST vol. 46.](https://eceasst.org/index.php/eceasst/article/view/1885)
17. [Introduction to Specification course, Oxford University Department of Computer Science, 2011-2012.](https://www.cs.ox.ac.uk/teaching/courses/2011-2012/intro2spec/)
18. [Community Z Tools (CZT) manual.](https://czt.sourceforge.net/manual.html)
19. [ProZ — ProB Documentation.](https://prob.cs.hhu.de/w/index.php?title=ProZ)
20. [Approaches to proof in Z — or — Why effective proof tool support for Z is hard.](https://www.researchgate.net/publication/2644718_Approaches_to_proof_in_Z_-_or_-_Why_effective_proof_tool_support_for_Z_is_hard)
21. [Z Specification for the W3C Editor's Draft Core SHACL Semantics. arXiv:1511.00384.](https://arxiv.org/abs/1511.00384)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › Formal logic and foundations › Logical calculi and logical syntax › Lambda calculus and type theory › Dependent type theory and Martin-Löf type theory

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/z-notation

English original: https://www.edgepedia.org/z-notation
