The Magic of Specifications and Type Systems Amin Bandali June 17, - - PowerPoint PPT Presentation

the magic of specifications and type systems
SMART_READER_LITE
LIVE PREVIEW

The Magic of Specifications and Type Systems Amin Bandali June 17, - - PowerPoint PPT Presentation

The Magic of Specifications and Type Systems Amin Bandali June 17, 2017 Software Engineering Lab, EECS York University Outline 1. Introduction 2. Significance & Contributions 3. Type Checking 4. Well-definedness Checking 5. Conclusion


slide-1
SLIDE 1

The Magic of Specifications and Type Systems

Amin Bandali

June 17, 2017

Software Engineering Lab, EECS York University

slide-2
SLIDE 2

Outline

  • 1. Introduction
  • 2. Significance & Contributions
  • 3. Type Checking
  • 4. Well-definedness Checking
  • 5. Conclusion

1

slide-3
SLIDE 3

Introduction

slide-4
SLIDE 4

Specifications

Architects draw detailed plans before a brick is laid or a nail is

  • hammered. Programmers and software engineers don’t.

Can this be why houses seldom collapse and programs often crash? To designers of complex systems, the need for formal specifications should be as obvious as the need for blueprints of a skyscraper. But few software developers write specifications because they have little time to learn how on the job, and they are unlikely to have learned in school. — Leslie Lamport, Turing Award Winner, 2013

2

slide-5
SLIDE 5

Specifications

Architects draw detailed plans before a brick is laid or a nail is

  • hammered. Programmers and software engineers don’t.

Can this be why houses seldom collapse and programs often crash? To designers of complex systems, the need for formal specifications should be as obvious as the need for blueprints of a skyscraper. But few software developers write specifications because they have little time to learn how on the job, and they are unlikely to have learned in school. — Leslie Lamport, Turing Award Winner, 2013

2

slide-6
SLIDE 6

Specifications

Architects draw detailed plans before a brick is laid or a nail is

  • hammered. Programmers and software engineers don’t.

Can this be why houses seldom collapse and programs often crash? To designers of complex systems, the need for formal specifications should be as obvious as the need for blueprints of a skyscraper. But few software developers write specifications because they have little time to learn how on the job, and they are unlikely to have learned in school. — Leslie Lamport, Turing Award Winner, 2013

2

slide-7
SLIDE 7

Specifications

Architects draw detailed plans before a brick is laid or a nail is

  • hammered. Programmers and software engineers don’t.

Can this be why houses seldom collapse and programs often crash? To designers of complex systems, the need for formal specifications should be as obvious as the need for blueprints of a skyscraper. But few software developers write specifications because they have little time to learn how on the job, and they are unlikely to have learned in school. — Leslie Lamport, Turing Award Winner, 2013

2

slide-8
SLIDE 8

Specifications

Architects draw detailed plans before a brick is laid or a nail is

  • hammered. Programmers and software engineers don’t.

Can this be why houses seldom collapse and programs often crash? To designers of complex systems, the need for formal specifications should be as obvious as the need for blueprints of a skyscraper. But few software developers write specifications because they have little time to learn how on the job, and they are unlikely to have learned in school. — Leslie Lamport, Turing Award Winner, 2013

2

slide-9
SLIDE 9

Gaining Traction

Formal methods used to be relegated to safety critical systems:

  • nuclear plants
  • avionics
  • medical devices

3

slide-10
SLIDE 10

Gaining Traction

Some formal methods are now practical and adopted by technology leaders:

  • Amazon
  • Microsoft
  • Facebook
  • Dropbox

4

slide-11
SLIDE 11

Significance & Contributions

slide-12
SLIDE 12

Unit-B

Unit-B [3] is a new framework for specifying and modelling systems that must satisfy both safety and liveness properties.

5

slide-13
SLIDE 13

Unit-B Logic

Unit-B Logic supports arithmetic, sets, functions, relations, and intervals theories.

6

slide-14
SLIDE 14

Unit-B Logic & Related Work

Unit-B vs Event-B [1]

  • record types
  • complete well-definedness

Unit-B vs TLA+ [4]

  • type checking
  • [static] well-definedness checking
  • quantification over infinite sets1

Unit-B vs Logitext

  • support for higher-order logic in

both predicate and sequent calculi

7

slide-15
SLIDE 15

Unit-B Logic & Related Work

Unit-B vs Event-B [1]

  • record types
  • complete well-definedness

Unit-B vs TLA+ [4]

  • type checking
  • [static] well-definedness checking
  • quantification over infinite sets1

Unit-B vs Logitext

  • support for higher-order logic in

both predicate and sequent calculi

1limitation of the TLC tooling

7

slide-16
SLIDE 16

Unit-B Logic & Related Work

Unit-B vs Event-B [1]

  • record types
  • complete well-definedness

Unit-B vs TLA+ [4]

  • type checking
  • [static] well-definedness checking
  • quantification over infinite sets1

Unit-B vs Logitext

  • support for higher-order logic in

both predicate and sequent calculi

1limitation of the TLC tooling

7

slide-17
SLIDE 17

Unit-B Web

Unit-B Web makes the Literate Unit-B prover available on the web. While Literate Unit-B supports both the Unit-B Logic and Unit-B’s computation models, Unit-B Web currently only supports Unit-B Logic.

8

slide-18
SLIDE 18

Unit-B Web

Unit-B Web makes the Literate Unit-B prover available on the web. While Literate Unit-B supports both the Unit-B Logic and Unit-B’s computation models, Unit-B Web currently only supports Unit-B Logic.

8

slide-19
SLIDE 19

Unit-B Web

Teaching

  • demonstrations
  • online evaluations
  • support for assignments

Online Proof Environment

  • making specifications more

accessible to casual users

  • proof of concept for a web IDE

for full modelling capabilities of Unit-B

9

slide-20
SLIDE 20

Unit-B Web

Teaching

  • demonstrations
  • online evaluations
  • support for assignments

Online Proof Environment

  • making specifications more

accessible to casual users

  • proof of concept for a web IDE

for full modelling capabilities of Unit-B

9

slide-21
SLIDE 21

Technology Stack

Syntax

  • L

AT

EX-based Web

  • JavaScript
  • JSON
  • Yesod / Haskell

Prover Haskell

  • Type checking
  • Well-definedness
  • Proof tactics

Z3

  • Predicate prover

10

slide-22
SLIDE 22

Technology Stack

Syntax

  • L

AT

EX-based Web

  • JavaScript
  • JSON
  • Yesod / Haskell

Prover Haskell

  • Type checking
  • Well-definedness
  • Proof tactics

Z3

  • Predicate prover

10

slide-23
SLIDE 23

Technology Stack

Syntax

  • L

AT

EX-based Web

  • JavaScript
  • JSON
  • Yesod / Haskell

Prover Haskell

  • Type checking
  • Well-definedness
  • Proof tactics

Z3

  • Predicate prover

10

slide-24
SLIDE 24

Type Checking

slide-25
SLIDE 25

Type Checking

  • {x} + 3 ≤ 7
  • not meaningful
  • caught by Unit-B’s type checker
  • TLA+ doesn’t recognize this as an error

11

slide-26
SLIDE 26

Type Checking

  • {x} + 3 ≤ 7
  • not meaningful
  • caught by Unit-B’s type checker
  • TLA+ doesn’t recognize this as an error

11

slide-27
SLIDE 27

Type Checking

  • {x} + 3 ≤ 7
  • not meaningful
  • caught by Unit-B’s type checker
  • TLA+ doesn’t recognize this as an error

11

slide-28
SLIDE 28

Figure 1: A type error — x is expected to be a set of numbers

slide-29
SLIDE 29

Type Checking

  • {x} + 3 ≤ 7
  • not meaningful
  • caught by Unit-B’s type checker
  • TLA+ doesn’t recognize this as an error

13

slide-30
SLIDE 30

Type Checking

  • {x} + 3 ≤ 7
  • not meaningful
  • caught by Unit-B’s type checker
  • TLA+ doesn’t recognize this as an error

13

slide-31
SLIDE 31

Challenges & Rewards

  • TLA+’s untyped logic allows {3, {7}}
  • Event-B’s simple type system forbids this
  • ???
  • subtyping to the rescue!
  • type variables → polymorphic definitions

14

slide-32
SLIDE 32

Challenges & Rewards

  • TLA+’s untyped logic allows {3, {7}}
  • Event-B’s simple type system forbids this
  • ???
  • subtyping to the rescue!
  • type variables → polymorphic definitions

14

slide-33
SLIDE 33

Challenges & Rewards

  • TLA+’s untyped logic allows {3, {7}}
  • Event-B’s simple type system forbids this
  • ???
  • subtyping to the rescue!
  • type variables → polymorphic definitions

14

slide-34
SLIDE 34

Challenges & Rewards

  • TLA+’s untyped logic allows {3, {7}}
  • Event-B’s simple type system forbids this
  • ???
  • subtyping to the rescue!
  • type variables → polymorphic definitions

14

slide-35
SLIDE 35

Challenges & Rewards

  • TLA+’s untyped logic allows {3, {7}}
  • Event-B’s simple type system forbids this
  • ???
  • subtyping to the rescue!
  • type variables → polymorphic definitions

14

slide-36
SLIDE 36

Well-definedness Checking

slide-37
SLIDE 37

Well-definedness Checking

Catches meaningless formulas that type checker can’t catch:

  • division by zero
  • array index out of bounds
  • more sophisticated errors

15

slide-38
SLIDE 38

Well-definedness Checking

Catches meaningless formulas that type checker can’t catch:

  • division by zero
  • array index out of bounds
  • more sophisticated errors

15

slide-39
SLIDE 39

Well-definedness Checking

Catches meaningless formulas that type checker can’t catch:

  • division by zero
  • array index out of bounds
  • more sophisticated errors

15

slide-40
SLIDE 40

Well-definedness Checking

Catches meaningless formulas that type checker can’t catch:

  • division by zero
  • array index out of bounds
  • more sophisticated errors

15

slide-41
SLIDE 41

Figure 2: An ill-defined predicate — x is not in the domain of f

slide-42
SLIDE 42

Conclusion

slide-43
SLIDE 43

Summary

  • Unit-B Web, a web application for doing predicate calculus proofs,

bringing the Literate Unit-B prover to the web.

  • Type Checking helps identify a certain class of meaningless

formulas (i.e. type-incorrect formulas) efficiently.

  • Well-definedness Checking catches the rest of meaningless

formulas that are not type errors.

17

slide-44
SLIDE 44

Summary

  • Unit-B Web, a web application for doing predicate calculus proofs,

bringing the Literate Unit-B prover to the web.

  • Type Checking helps identify a certain class of meaningless

formulas (i.e. type-incorrect formulas) efficiently.

  • Well-definedness Checking catches the rest of meaningless

formulas that are not type errors.

17

slide-45
SLIDE 45

Summary

  • Unit-B Web, a web application for doing predicate calculus proofs,

bringing the Literate Unit-B prover to the web.

  • Type Checking helps identify a certain class of meaningless

formulas (i.e. type-incorrect formulas) efficiently.

  • Well-definedness Checking catches the rest of meaningless

formulas that are not type errors.

17

slide-46
SLIDE 46

Try Unit-B Web

Unit-B Web is available under the MIT open source license. You can get the source code from GitHub: github.com/unitb/unitb-web

18

slide-47
SLIDE 47

Acknowledgements Simon Hudon (PhD Candidate) Professor Jonathan Ostroff

19

slide-48
SLIDE 48

Thanks!

19

slide-49
SLIDE 49

Summary

  • Unit-B Web, a web application for doing predicate calculus proofs,

bringing the Literate Unit-B prover to the web.

  • Type Checking helps identify a certain class of meaningless

formulas (i.e. type-incorrect formulas) efficiently.

  • Well-definedness Checking catches the rest of meaningless

formulas that are not type errors.

20

slide-50
SLIDE 50

Presentation

The source code of this presentation is available at github.com/aminb/cucsc-2017 licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

cba

slide-51
SLIDE 51

Polymorphic Definitions

SameFields SameFields(fs, r0, r1) ≜ (∀x : x ∈ fs : (x ∈ dom.r0 ∧ x ∈ dom.r1 ∧ r0.x = r1.x) ∨(¬x ∈ dom.r0 ∧ ¬x ∈ dom.r1))

  • Given a set of strings (fs) and two records (r0, r1), checks that all

the specified fields have same value in both records.

  • Works on any pair of records represented as partial functions.
slide-52
SLIDE 52

Polymorphic Definitions

SameFields SameFields(fs, r0, r1) ≜ (∀x : x ∈ fs : (x ∈ dom.r0 ∧ x ∈ dom.r1 ∧ r0.x = r1.x) ∨(¬x ∈ dom.r0 ∧ ¬x ∈ dom.r1))

  • Given a set of strings (fs) and two records (r0, r1), checks that all

the specified fields have same value in both records.

  • Works on any pair of records represented as partial functions.
slide-53
SLIDE 53

Polymorphic Definitions

SameFields SameFields(fs, r0, r1) ≜ (∀x : x ∈ fs : (x ∈ dom.r0 ∧ x ∈ dom.r1 ∧ r0.x = r1.x) ∨(¬x ∈ dom.r0 ∧ ¬x ∈ dom.r1))

  • Given a set of strings (fs) and two records (r0, r1), checks that all

the specified fields have same value in both records.

  • Works on any pair of records represented as partial functions.
slide-54
SLIDE 54

Completeness

Unit-B’s WD-calculus [2] is complete; while Event-B’s isn’t. Consider four propositions A, B, C, and D, where A ⇒ WD(B) B ⇒ WD(C) B ⇒ WD(D)

slide-55
SLIDE 55

Completeness

Unit-B’s WD-calculus [2] is complete; while Event-B’s isn’t. Consider four propositions A, B, C, and D, where A ⇒ WD(B) B ⇒ WD(C) B ⇒ WD(D)

slide-56
SLIDE 56

Completeness

The following calculation is not well-defined in Event-B, but it is perfectly so in Unit-B: A ⇒ WD(B) B ⇒ WD(C) B ⇒ WD(D) A ∧ B ∧ (C ∨ D) = {commutativity} A ∧ (C ∨ D) ∧ B = {distributivity} ((A ∧ C) ∨ (A ∧ D)) ∧ B where A : x ∈ dom.f B : f.x ∈ dom.g C : g.(f.x) ≤ 3 D : 7 ≤ g.(f.x)

slide-57
SLIDE 57

Completeness

The following calculation is not well-defined in Event-B, but it is perfectly so in Unit-B: A ⇒ WD(B) B ⇒ WD(C) B ⇒ WD(D) A ∧ B ∧ (C ∨ D) = {commutativity} A ∧ (C ∨ D) ∧ B = {distributivity} ((A ∧ C) ∨ (A ∧ D)) ∧ B where A : x ∈ dom.f B : f.x ∈ dom.g C : g.(f.x) ≤ 3 D : 7 ≤ g.(f.x)

slide-58
SLIDE 58

Completeness

The following calculation is not well-defined in Event-B, but it is perfectly so in Unit-B: A ⇒ WD(B) B ⇒ WD(C) B ⇒ WD(D) A ∧ B ∧ (C ∨ D) = {commutativity} A ∧ (C ∨ D) ∧ B = {distributivity} ((A ∧ C) ∨ (A ∧ D)) ∧ B where A : x ∈ dom.f B : f.x ∈ dom.g C : g.(f.x) ≤ 3 D : 7 ≤ g.(f.x)

slide-59
SLIDE 59

References i

Jean-Raymond Abrial. Modeling in Event-B - System and Software Engineering. Cambridge University Press, 2010. Ádám Darvas, Farhad Mehta, and Arsenii Rudich. Efficient well-definedness checking. In Automated Reasoning, 4th International Joint Conference, IJCAR 2008, Sydney, Australia, August 12-15, 2008, Proceedings, pages 100–115, 2008. Simon Hudon, Thai Son Hoang, and Jonathan S. Ostroff. The Unit-B method: refinement guided by progress concerns. Software & Systems Modeling, pages 1–26, 2015.

slide-60
SLIDE 60

References ii

Leslie Lamport. Specifying Systems, The TLA+ Language and Tools for Hardware and Software Engineers. Addison-Wesley, 2002.