49194Jackson 1/31/06 9:30 AM Page 1 computer science/software engineering S o Software Abstractions f Logic, Language, and Analysis t Daniel Jackson w In Software Abstractions Daniel Jackson introduces a new approach to software design that a draws on traditional formal methods but exploits automated tools to find flaws as early as r possible. This approach—which Jackson calls “lightweight formal methods” or “agile model- e ing”—takes from formal specification the idea of a precise and expressive notation based on a tiny core of simple and robust concepts but replaces conventional analysis based on theo- A rem proving with a fully automated analysis that gives designers immediate feedback. Jackson has developed Alloy, a language that captures the essence of software abstractions simply and b succinctly, using a minimal toolkit of mathematical notions. The designer can use automated s analysis not only to correct errors but also to make models that are more precise and elegant. t This approach, Jackson says, can rescue designers from “the tarpit of implementation tech- r Software Abstractions nologies” and return them to thinking deeply about underlying concepts. a Software Abstractions introduces the key elements of the approach: a logic, which pro- c vides the building blocks of the language; a language, which adds a small amount of syntax to the logic for structuring descriptions; and an analysis, a form of constraint solving that t i offers both simulation (generating sample states and executions) and checking (finding coun- o Logic, Language, and Analysis terexamples to claimed properties). The book uses Alloy as a vehicle because of its simplici- ty and tool support, but the book’s lessons are mostly language-independent, and could also n be applied in the context of other modeling languages. s Daniel Jackson is Professor in the Department of Electrical Engineering and Computer Science and leads the Software Design Group at the Computer Science and Artificial Intelligence Lab at MIT. Daniel Jackson “Abstraction is the essence of simple and effective software design, and logic is the essential J tool for exploring and validating abstractions. These basic insights, which have been labori- a ously rediscovered by many practicing programmers, are now accessible to students and pro- c k fessionals at all levels of experience. Daniel Jackson supports his clear and elegant text with s o a powerful logical analysis tool that brings his witty examples to life.” n —Tony Hoare, Senior Researcher, Microsoft “Alloy’s streamlined combination of predicate logic and relational algebra makes modeling a pleasure. I rely on the Alloy Analyzer, and this book shows how easy it is to start using it.” —Pamela Zave, AT&T Research “Alloy is to modeling what Excel is to office work: an incredibly powerful way to make mod- els into concrete, tangible objects. Jackson’s book is essential for practitioners to master the power of this new tool.” —Alain Wegmann, Ecole Polytechnique Fédérale de Lausanne 0-262-10114-9 The MIT Press Massachusetts Institute of Technology Cambridge, Massachusetts 02142 http://mitpress.mit.edu Software Abstractions: Logic, Language, and Analysis Software Abstractions Logic, Language, and Analysis Daniel Jackson The MIT Press Cambridge, Massachusetts London, England © 2006 Daniel Jackson All rights reserved. No part of this book may be reproduced in any form by any electronic or mechanical means (including photocopying, recording, or information storage and retrieval) without permission in writing from the publisher. MIT Press books may be purchased at special quantity discounts for busi- ness or sales promotion use. For information, please email special_sales@ mitpress.mit.edu or write to Special Sales Department, The MIT Press, 55 Hayward Street, Cambridge, MA 02142. This book was set in Adobe Warnock and ITC Officina Sans, by the author, using Adobe Indesign and his own software, on Apple computers. Diagrams were drawn with OmniGraffle Pro. Printed and bound in the United States of America. Library of Congress Cataloguing-in-Publication Data Jackson, Daniel. Software abstractions : logic, language, and analysis / Daniel Jackson. p. cm. Includes bibliographical references and index. ISBN 0-262-10114-9 (alk. paper) 1. Computer software—Development. I. Title. QA76.76.D47J29 2006 005.1—dc22 2005056155 10 9 8 7 6 5 4 3 2 1 to Claudia Contents Preface xi Acknowledgments xv 1: Introduction 1 2: A Whirlwind Tour 5 2.1 Statics: Exploring States .........................................................................6 2.2 Dynamics: Adding Operations .............................................................9 2.3 Classification Hierarchy ......................................................................17 2.4 Execution Traces...................................................................................22 2.5 Summary ................................................................................................28 3: Logic 33 3.1 Three Logics in One .............................................................................33 3.2 Atoms and Relations ............................................................................35 3.3 Snapshots ...............................................................................................48 3.4 Operators ...............................................................................................50 3.5 Constraints .............................................................................................69 3.6 Declarations and Multiplicity Constraints ......................................74 3.7 Cardinality Constraints .......................................................................80 4: Language 83 4.1 An Example: Self-Grandpas ...............................................................83 4.2 Signatures and Fields ...........................................................................91 4.3 Model Diagrams .................................................................................101 4.4 Types and Type Checking .................................................................107 4.5 Facts, Predicates, Functions, and Assertions ................................117 4.6 Commands and Scope .......................................................................127 4.7 Modules and Polymorphism ............................................................130 4.8 Integers and Arithmetic ....................................................................134 viii contents 5: Analysis 139 5.1 Scope-Complete Analysis .................................................................139 5.2 Instances, Examples, and Counterexamples .................................144 5.3 Unbounded Universal Quantifiers ..................................................155 5.4 Scope Selection and Monotonicity .................................................163 6: Examples 169 6.1 Leader Election in a Ring ..................................................................169 6.2 Hotel Room Locking ..........................................................................185 6.3 Media Asset Management ................................................................203 6.4 Memory Abstractions ........................................................................216 Appendix A: Exercises 229 A.1 Logic Exercises ....................................................................................230 A.2 Extending Simple Models .................................................................239 A.3 Classic Puzzles ....................................................................................242 A.4 Metamodels .........................................................................................245 A.5 Small Case Studies ..............................................................................247 A.6 Open-Ended Case Studies ................................................................251 Appendix B: Alloy Language Reference 253 B.1 Lexical Issues .......................................................................................253 B.2 Namespaces .........................................................................................254 B.3 Grammar ..............................................................................................255 B.4 Precedence and Associativity ...........................................................257 B.5 Semantic Basis .....................................................................................258 B.6 Types and Overloading......................................................................260 B.7 Language Features ..............................................................................265 Appendix C: Kernel Semantics 291 C.1 Semantics of the Alloy Kernel ..........................................................291 C.2 Semantics of Integer Expressions and Formulas ..........................293 Appendix D: Diagrammatic Notation 295 contents ix Appendix E: Alternative Approaches 297 E.1 An Example ..........................................................................................299 E.2 B .............................................................................................................306 E.3 OCL .......................................................................................................312 E.4 VDM ......................................................................................................318 E.5 Z .............................................................................................................324 References 333 Index 341
Description: