Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Lecture 4 Towards a Verifying Compiler: Data Abstraction Wolfram Schulte Microsoft Research Formal Methods 2006 Purity, Model fields, Inconsistency _____________.
Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 6 Disclaimer. These notes are derived from notes originally.
Semantics Static semantics Dynamic semantics attribute grammars
Addressing the Challenges of Current Software. Questions to Address Why? What? Where? How?
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Constraint Semantics for Abstract Read Permissions 28 th July 2014, FTfJP, Uppsala John Tang Boyland (UW-Milwaukee/ETH Zurich) Peter Müller, Malte Schwerhoff,
Automated Software Verification with a Permission-Based Logic 20 th June 2014, Zürich Malte Schwerhoff, ETH Zürich.
1 Regression-Verification Benny Godlin Ofer Strichman Technion.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CS 355 – Programming Languages
Dept. of Computer Science A Runtime Assertion Checker for the Java Modeling Language (JML) Yoonsik Cheon and Gary T. Leavens SERP 2002, June 24-27, 2002.
Code-Carrying Proofs Aytekin Vargun Rensselaer Polytechnic Institute.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor Formal Methods in Software Engineering1.
School of Computing and Mathematics, University of Huddersfield CAS2545: WEEK 11 LECTURE: n The meaning of Algebraic Specifications TUTORIAL/PRACTICAL:
Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps,
An overview of JML tools and applications Lilian Burdy Gemplus Yoonsik Cheon, Gary Leavens Iowa Univ. David Cok Kodak Michael Ernst MIT Rustan Leino Microsoft.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Katz Formal Specifications Larch 1 Algebraic Specification and Larch Formal Specifications of Complex Systems Shmuel Katz The Technion.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
A Z Approach in Validating ORA-SS Data Models Scott Uk-Jin Lee Jing Sun Gillian Dobbie Yuan Fang Li.
111 The Java Modeling Language Based on: Gary T. Leavens, et al., JML Tutorial at OOPSLA Gary. T Leavens, et al., Preliminary Design of JML: A Behavioral.
Overview of Formal Methods. Topics Introduction and terminology FM and Software Engineering Applications of FM Propositional and Predicate Logic Program.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
Ceg860 (Prasad)LADT1 Specification and Implementation of Abstract Data Types Algebraic Techniques.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
RESOLVE VERIFICATION: A New Perspective Joan Krone William F. Ogden.
A Type System for Higher-Order Modules Derek Dreyer, Karl Crary, and Robert Harper Carnegie Mellon University POPL 2003.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
1 Contractual Consistency Between BON Static and Dynamic Diagrams Ali Taleghani July 30, 2004.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each.
IS 2620: Developing Secure Systems Formal Verification/Methods Lecture 9 March 15, 2012.
Towards a Semantic Model for Java Wildcards Sophia Drossopoulou Mariangiola Dezani-Ciancaglini Imperial College London Università di Torino Italy Nicholas.
Laurea Triennale in Informatica – Corso di Ingegneria del Software I – A.A. 2006/2007 Andrea Polini IX. System Models (III)
Matching Logic An Alternative to Hoare/Floyd Logic
Stateful Manifest Contracts
IS 2935: Developing Secure Systems
A Design Structure for Higher Order Quotients
Semantics In Text: Chapter 3.
Sub-system interfaces
Java Modeling Language (JML)
Algebraic Specification Software Specification Lecture 34
OBJ first-order functional language based on equational logic
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS 2007, Dubrovnik, Croatia

2 Abstraction in OO specification languages  Abstraction is indispensable -to specify types with no implementation -to support subtyping and information hiding  Two-tiered specification languages (e.g. Larch) directly provide mathematical structures for abstraction  One-tiered specification languages (e.g. JML) provide model classes for abstraction

3 Model classes  Provide OO interface for mathematical concepts  Used as immutable types  Equipped with contracts (not shown) package org.jmlspecs.models; public final class JMLObjectSet { public JMLObjectSet(); public JMLObjectSet(Object e); public boolean has(Object elem); public boolean isEmpty(); public boolean isSubset(JMLObjectSet s2); public JMLObjectSet insert(Object elem); public JMLObjectSet remove(Object elem); … }

4 Use of model classes package java.util; import org.jmlspecs.models.JMLObjectSet; public interface Set extends Collection { public model instance JMLObjectSet _set; public ensures public boolean add(Object o); public ensures \result == public boolean contains(Object o); … }

5 Handling of model classes – pure methods For verification, model classes need to be encoded in underlying theorem prover By encoding pure methods [DarvasMüller06,JacobsPiessen06] -pure methods encoded as uninterpreted functions -functions axiomatized based on pure-method contracts Problems -theorem provers optimized for their own theories, rather than encodings of pure methods -difficult to ensure consistency of resulting axiom system

6 Handling of model classes – direct mappings For verification, model classes need to be encoded in underlying theorem prover By direct mappings [LeavensEA05,Charles06,LeavensEA07] -map model classes directly to theories of provers -map pure methods to functions of selected theories -mapping based on signature Problems -mapping ignores contracts -possible mismatch between contract and semantic meaning of selected function -leads to unexpected results during verification and runtime assertion checking

7 Faithful mapping of model classes to structures  Our contribution is an approach that -follows idea of direct mappings -takes contracts into account -formally proves that mappings are semantically correct -allows identification and checking of redundant specs  Approach -leads to better quality of model class specifications -eliminates semantic mismatches

8 Specifying and proving faithfulness of mappings Approach consists of 3 stages: 1. Specifying mapping 2. Proving consistency: what can be proven using contracts can also be proven using theory of theorem prover 3. Proving completeness: what can be proven using the theory of theorem prover can also be proven using contracts Correctness of mapping

9 Specifying mappings  Introducing new JML clause: mapped_to  Clause attached to a class -specifies theorem prover, theory, and type to which class is mapped  Clause attached to a method -specifies prover and term to which a call of the method is mapped mapped_to(“Isabelle”, “HOL/Set”, “ ’a set”); public final class JMLObjectSet mapped_to(“Isabelle”, “this Un s2”); public JMLObjectSet union(JMLObjectSet s2);

10 Proving consistency 1.Turn each invariant and method specification into a lemma in language of selected theory 2.Prove lemmas using selected theory public (\forall Object e; this.has(e) || (e == mapped_to("Isabelle","insert elem this"); public JMLObjectSet insert(Object elem);  e. \result.has(e) = (this.has(e)  e = elem)  this, elem.  e. \result.has(e) = (this.has(e)  e = elem)  this, elem.  e. e : \result = ( e : this  e = elem)  this, elem.  e. e : (insert elem this) = (e : this  e = elem) theory consistent imports Set: lemma  this, elem.  e. e : (insert elem this) = (e : this  e = elem) apply(auto)

11 Proving completeness Create theory file as follows 1.Turn each pure method into a function symbol 2.Turn each invariant and method specification into axiom 3.Turn each axiom and definition from theory into lemma 4.Prove each lemma using axioms created in step 2. theory complete: consts isProperSubset: ‘a set x ‘a set => bool … axiom ax_isPropSub:  s,s2,e1,e2. isProperSubset(s,s2) = (isSubset(s,s2)   equals(s,s2)) … lemma  A,B. isProperSubset(A,B) = (isSubset(A,B)   equals(A,B)) apply(simp add: ax_isPropSub) … public boolean isProperSubset(JMLObjectSet s2); s.isProperSubset(s2) == (s.isSubset(s2) && !s.equals(s2)) A < B == A <= B &  A=B

12 Guarantees Consistency -selected theory is model for model class -model-class specification is free of contradictions provided that theory is free of contradictions -can show consistency of recursive specifications  Completeness -extracted axiom system is complete relative to theory

13 Case study  Mapped JMLObjectSet to Isabelle’s HOL/Set theory  Considered 17 members: -2 constructors, 9 query methods, and 6 methods that return new JMLObjectSet objects -made several simplifications  Total of 380 lines of Isabelle code -100 for consistency, 110 for completeness, and 170 for equivalence proof (see later) -all code written manually

14 Case study – Division of specifications Specification of JMLObjectSet expressed by equational theory and method specifications public (\forall JMLObjectSet s2; s2 != (\forall Object e1, e2; equational_theory(this, s2, e1, public ensures s.insert(e1).has(e2) (e1 == e2 || static public pure model equational_theory(JMLObjectSet JMLObjectSet s2, Object e1, Object

15 Case study – Division of specifications Specification of JMLObjectSet expressed by equational theory and method specifications JMLObjectSet Equational theory Method specs JMLObjectSet Equational theory JMLObjectSet Method specs ?

16 Case study – Specifying the mapping  Mapping of model-class methods to function symbols of HOL/Set mostly straightforward  Some interesting cases mapped_to("Isabelle","this - {elem}"); public JMLObjectSet remove(Object elem); mapped_to("Isabelle","SOME x. x : this"); public Object choose(); public int int_size();

17 Case study – Consistency  Performed both for equational theory and method specifications  Revealed one unsound equation in equational theory Not true if e1 == e2 and s contains e1!  Possibility for high degree of automation -generation of lemmas based on few simple syntactic substitutions -lemmas proved automatically by Isabelle’s tactics s.insert(e1).remove(e2). equals(e1 == e2 ? s : s.remove(e2).insert(e1)) s.insert(e1).remove(e2). equals(e1 == e2 ? s : s.remove(e2).insert(e1))

18 Case study – Equivalence of specifications  Inspected relation of equational theory and method specifications: equivalent? one stronger than the other?  Answer: not equivalent and none stronger! -needed to add new specifications or strengthen some From equations over isEmpty new JMLObjectSet().isEmpty() and !s.insert(e1).isEmpty() could not derive public ensures \result == (\forall Object e; ; public boolean isEmpty();

19 Case study – Completeness  Performed both for equational theory and method specifications  Most Isabelle definitions expressed by set comprehension -JML supports construct on syntax level -axiomatized construct based on Isabelle’s definition (correct and provides connection to model class)  Most definitions easily mapped back and proved -could not map back some function symbols  Lower degree of automation -lemma and proof generation only partially possible

20 Mismatching classes and structures  Pure method cannot be mapped to semantically equivalent term of selected theory -no guarantee that specification is consistent and method corresponds to some mathematical operation -for instance, method int_size -need to pick other theory (e.g. HOL/Finite_Set)  Function symbol of selected theory cannot be mapped to expression of model class -no isomorphism but observational faithfulness: mapping of all client-accessible pure methods faithful -for instance, function image -sufficient result for sound use of mapped_to clauses

21 Conclusions  Improvements over previous work -formally proving semantic correspondence between mapped entities -better specifications for model classes: consistent and complete, redundancy identifiable and checkable -ensuring consistency of specifications even in the presence of recursion  Case study -revealed incorrect specification -identified missing specifications -identified relation between equational theory and method specifications

22 Future work  Tool support -typechecking of mapped_to clauses -(partial) generation of proof scripts -use of mappings in program verification system  More case studies -with more complex structures (e.g. sequence) -with structures that have no directly corresponding theory (e.g. stack)