Rigorous Software Development CSCI-GA 3033-011 Instructor: Thomas Wies Spring 2012 Lecture 10.

Slides:



Advertisements
Similar presentations
CH4.1 Type Checking Md. Fahim Computer Engineering Department Jamia Millia Islamia (A Central University) New Delhi –
Advertisements

Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 12.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2013 Lecture 5 Disclaimer. These notes are derived from notes originally.
Recitation 4. 2-D arrays. Exceptions. Animal[] v= new Animal[3]; 2 declaration of array v v null Create array of 3 elements a6 Animal[] null Assign.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 6 Disclaimer. These notes are derived from notes originally.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
Lilian Blot VARIABLE SCOPE EXCEPTIONS FINAL WORD Final Lecture Spring 2014 TPOP 1.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Semantics Static semantics Dynamic semantics attribute grammars
Intermediate Code Generation
Models of Concurrency Manna, Pnueli.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Lecture 02 – Structural Operational Semantics (SOS) Eran Yahav 1.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Dec Formal Semantics1 Programming Language Theory Formal Semantics Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
Slides prepared by Rose Williams, Binghamton University Chapter 9 More Exception Handling.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Describing Syntax and Semantics
Imperative Programming
1 Exception Handling Introduction to Exception Handling Exception Handling in PLs –Ada –C++ –Java Sebesta Chapter 14.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Chapter 3 Part II Describing Syntax and Semantics.
Exceptions and Assertions Chapter 15 – CSCI 1302.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
CMSC 330: Organization of Programming Languages Operational Semantics.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CSE 501N Fall ’09 07: Iteration 17 September 2009 Nick Leidenfrost.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Information and Computer Sciences University of Hawaii, Manoa
Representation, Syntax, Paradigms, Types
Corky Cartwright January 18, 2017
Variables ICS2O.
Representation, Syntax, Paradigms, Types
Semantics In Text: Chapter 3.
Representation, Syntax, Paradigms, Types
Representation, Syntax, Paradigms, Types
Classes, Objects and Methods
Program correctness Axiomatic semantics
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 10

What does this program print? class A { public static int x = B.x + 1; } class B { public static int x = A.x + 1; } class C { public static void main(String[] p) { System.err.println("A: " + A.x + ", B: " + B.x); }

If we run class C : 1)main-method of class C first accesses A.x. 2)Class A is initialized. The lock for A is taken. 3)Static initializer of A runs and accesses B.x. 4)Class B is initialized. The lock for B is taken. 5)Static initializer of B runs and accesses A.x. 6)Class A is still locked by current thread (recursive initialization). Therefore, initialization returns immediately. 7)The value of A.x is still 0 (section and ), so B.x is set to 1. 8)Initialization of B finishes. 9)The value of A.x is now set to 2. 10)The program prints A: 2, B: 1. What does this program print?

Formal Semantics of Java Programs The Java Language Specification (JLS) 3rd edition gives semantics to Java programs – The document has 684 pages. – 118 pages to define semantics of expression. – 42 pages to define semantics of method invocation. Semantics is only defined in prose. – How can we make the semantics formal? – We need a mathematical model of computation.

Semantics of Programming Languages Denotational Semantics – Meaning of a program is defined as the mathematical object it computes (e.g., partial functions). – Example: Abstract Interpretation Axiomatic Semantics – Meaning of a program is defined in terms of its effect on the truth of logical assertions. – Example: Hoare Logic (Structural) Operational Semantics – Meaning of a program is defined by formalizing the individual computation steps of the program. – Example: Labeled Transition Systems

IMP: A Simple Imperative Language Before we move on to Java, we look at a simple imperative programming language IMP. An IMP program: p := 0; x := 1; while x · n do x := x + 1; p := p + m;

IMP: Syntactic Entities n 2 Z – integers true,false 2 B – booleans x,y 2 L– locations (program variables) e 2 Aexp – arithmetic expressions b 2 Bexp – boolean expressions c 2 Com – commands

Syntax of Arithmetic Expressions Arithmetic expressions (Aexp) e ::= n for n Z | x for x L | e 1 + e 2 | e 1 - e 2 | e 1 * e 2 Notes: – Variables are not declared before use. – All variables have integer type. – Expressions have no side-effects.

Syntax of Boolean Expressions Boolean expressions (Bexp) b ::= true | false | e 1 = e 2 for e 1, e 2 Aexp | e 1 e 2 for e 1, e 2 Aexp | ¬ b for b Bexp | b 1 b 2 for b 1, b 2 Bexp | b 1 b 2 for b 1, b 2 Bexp

Syntax of Commands Commands (Com) c ::= skip | x := e | c 1 ; c 2 | if b then c 1 else c 2 | while b do c Notes: – The typing rules have been embedded in the syntax definition. – Other parts are not context-free and need to be checked separately (e.g., all variables are declared). – Commands contain all the side-effects in the language. – Missing: references, function calls, …

Meaning of IMP Programs Questions to answer: What is the meaning of a given IMP expression/command? How would we evaluate IMP expressions and commands? How are the evaluator and the meaning related? How can we reason about the effect of a command?

Semantics of IMP The meaning of IMP expressions depends on the values of variables, i.e. the current state. A state at a given moment is represented as a function from L to Z The set of all states is Q = L ! Z We shall use q to range over Q

Judgments We write n to mean that e evaluates to n in state q. – The formula n is a judgment (a statement about a relation between e, q and n) – In this case, we can view as a function of two arguments e and q This formulation is called natural operational semantics – or big-step operational semantics – the judgment relates the expression and its meaning How can we define … ?

Inference Rules We express the evaluation rules as inference rules for our judgments. The rules are also called evaluation rules. An inference rule defines a relation between judgments F 1,...,F n and G. The judgments F 1,...,F n are the premises of the rule; The judgments G is the conclusion of the rule; The formula H is called the side condition of the rule. If n=0 the rule is called an axiom. In this case, the line separating premises and conclusion may be omitted. An inference rule defines a relation between judgments F 1,...,F n and G. The judgments F 1,...,F n are the premises of the rule; The judgments G is the conclusion of the rule; The formula H is called the side condition of the rule. If n=0 the rule is called an axiom. In this case, the line separating premises and conclusion may be omitted. F 1... F n G where H

Inference Rules for Aexp In general, we have one rule per language construct: This is called structural operational semantics. – rules are defined base on the structure of the expressions. n q(x) n 1 + n 2 n 1 n 2 n 1 - n 2 n 1 n 2 n 1 ¢ n 2 n 1 n 2 Axiom

Inference Rules for Bexp true false n 1 = n 2 n 1 n 2 n 1 · n 2 n 1 n 2 t 1 Æ t 2 t 1 t 2

How to Read Inference Rules? Forward, as derivation rules of judgments – if we know that the judgments in the premise hold then we can infer that the conclusion judgment also holds. – Example: 6 2 3

How to Read Inference Rules? Backward, as evaluation rules: – Suppose we want to evaluate e 1 + e 2, i.e., find n s.t. e 1 + e 2 n is derivable using the previous rules. – By inspection of the rules we notice that the last step in the derivation of e 1 + e 2 n must be the addition rule. – The other rules have conclusions that would not match e 1 + e 2 n. This is called reasoning by inversion on the derivation rules. – Thus we must find n 1 and n 2 such that e 1 n 1 and e 2 n 2 are derivable. – This is done recursively. Since there is exactly one rule for each kind of expression we say that the rules are syntax-directed. – At each step at most one rule applies. – This allows a simple evaluation procedure as above.

How to Read Inference Rules? Example: evaluation of an arithmetic expression via reasoning by inversion: ? 3 ? 2 7 4

Semantics of Commands The evaluation of a command in Com has side- effects, but no direct result. – What is the result of evaluating a command? The result of a command c in a pre-state q is a transition from the to a post-state q: q ! q We can formalize this in terms of transition systems. c

Labeled Transition Systems A labeled transition system (LTS) is a structure LTS = (Q, Act, ! ) where – Q is a set of states, – Act is a set of actions, – ! µ Q £ Act £ Q is a transition relation. A labeled transition system (LTS) is a structure LTS = (Q, Act, ! ) where – Q is a set of states, – Act is a set of actions, – ! µ Q £ Act £ Q is a transition relation. We write q ! q for (q, a, q) 2 !. a

q q ++ {x n} x := e Inference Rules for Transitions n q skip q c 1 ; c 2 q c1c1 c2c2 if b then c 1 else c 2 true q c1c1 if b then c 1 else c 2 false q c2c2 while b do c true q c while b do c false q while b do c

Operational Semantics of Java (and JML) Can we give an operational semantics of Java programs and JML specifications? What is the state of a Java program? – We have to take into account the state of the heap. How can we deal with side-effects in expressions? How can we handle exceptions?

Operational Semantics of Java A (labeled) transition system (LTS) is a structure LTS = (Q, Act, ! ) where – Q is a set of states, – Act is a set of actions, – ! µ Q £ Act £ Q is a transition relation. A (labeled) transition system (LTS) is a structure LTS = (Q, Act, ! ) where – Q is a set of states, – Act is a set of actions, – ! µ Q £ Act £ Q is a transition relation. Q reflects the current dynamic state of the program (heap and local variables). Act is the executed code. Based on: D. v. Oheimb, T. Nipkow, Machine-checking the Java specification: Proving type-safety, 1999

Example: State of a Java Program What is the state after executing this code? List mylist = new LinkedList(); mylist.add(new Integer(1)); heaplcl mylist: 6 6 6: LinkedList 7: LinkedList.Node 8: LinkedList.Node 9: Integer

State of a Java Program A state of a Java program gives valuations to local and global (heap) variables. Q = Heap £ Local Heap = Address ! Class £ seq Value Local = Identifier ! Value Value = Z, Address µ Z A state is denoted as (heap, lcl), where heap : Heap and lcl : Local.

Actions of a Java Program An action of a Java program is either the evaluation of an expression e to a value v, denoted as e À v, or a Java statement, or a Java code block. Note that expressions with side effects can modify the current state.

Example: Actions of a Java Program Post-increment expression (heap, lcl [ {x 5}) (heap, lcl [ {x 6}) Pre-increment expression (heap, lcl [ {x 5}) (heap, lcl [ {x 6}) Assignment expression (heap, lcl [ {x 5}) (heap, lcl [ {x 10}) Assignment statement (heap, lcl [ {x 5}) (heap, lcl [ {x 10}) x++ À 5 ++x À 6 x=2*x À 10 x=2*x;

Rules for Java Expressions (1) axiom for evaluating local variables (heap, lcl) (heap, lcl) rule for assignment to local (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl ++ {x v}) rule for field access (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) x À lcl(x) e À ve À v x=e À v e.fld À heap(v)(idx) e À ve À v where idx is the index of the field fld in the object heap(v)

Rules for Java Expressions (2) axiom for evaluating a constant expression c (heap, lcl) (heap, lcl) rule for multiplication (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) similarly for other binary operators c À cc À c e1 À v1e1 À v1 e 1 * e 2 À v 1 ¢ v 2 mod 2 32 e2 À v2e2 À v2

Example: Derivation for x=2*x (heap, lcl [ {x 5}) x À 5 (heap, lcl [ {x 5}) 2 À 2 (heap, lcl [ {x 5}) 2*x À 10 (heap, lcl [ {x 5})(heap, lcl [ {x 10}) x=2*x À 10

Rules for Java Statements (1) expression statement (assignment or method call) (heap, lcl) (heap, lcl') (heap, lcl) (heap, lcl) sequence of statements (heap, lcl) (heap, lcl') (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) e À ve À v e; s1s1 s2s2 s 1 s 2

Rules for Java Statements (2) rules for if statement (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) e À ve À v bl 1 if (e) {bl 1 } else {bl 2 } where v 0 e À ve À v bl 2 if (e) {bl 1 } else {bl 2 } where v 0

Rules for Java Statements (3) rules for while statement (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) (heap, lcl) e À ve À v while (e) {bl} where v = 0 e À ve À v bl while (e) {bl} where v 0 while (e) {bl}

Rule for Java Method Calls (heap, lcl) (heap 0, lcl 0 ) e À ve À v e1 À v1e1 À v1 (heap 0, lcl 0 ) (heap 1, lcl 1 )(heap n-1, lcl n-1 ) (heap n, lcl n ) en À vnen À vn (heap, lcl) (heap n+1, lcl n ) e.m(e 1,...,e n ) À mlcl(\result) (heap n, mlcl) (heap n+1, mlcl) body... where body is the body of method m in the object heap n+1 (v), and mlcl = { this v, param 1 v 1,... param n v n } where param 1,..., param n are the names of the parameters of m.

Rule for Object Creation Object creation is always combined with a call of a constructor (heap, lcl) new Type(e 1,...,e n ) À na (heap 1, lcl) (heap, lcl) na. (e 1,...,e n ) À v where na dom(heap), heap 1 = heap [ {na (Type, h 0,...,0 i }, and stands for the internal name of the constructor

Formalizing Exceptions In order to handle exceptions, a few changes in the semantics are necessary: We extend states by a flow component Q = Flow £ Heap £ Local Flow ::= Norm | Ret | Exc hh Address ii We use the identifiers flow 2 Flow, heap 2 Heap and lcl 2 Local in the rules. Also q 2 Q stands for an arbitrary state. In an abnormal state, statements are not executed: (flow, heap, lcl) e À ve À v s where flow Norm

Rules for Expressions with Exceptions The previously defined rules are valid only if the left- hand-state is not an abnormal state. (Norm, heap, lcl) q q q (Norm, heap, lcl) q (Norm, heap, lcl) q q q (Norm, heap, lcl) q Note that exceptions are propagated using the axioms from the previous slide e1 À v1e1 À v1 e 1 * e 2 À v 1 ¢ v 2 mod 2 32 e2 À v2e2 À v2 s1s1 s2s2 s 1 s 2 (flow, heap, lcl) e À ve À v where flow Norm

Rules for Throwing Exceptions What happens if the object in a field access is null ? (Norm, heap, lcl) (Norm, heap, lcl) e À ve À v (Norm, heap, lcl) (Exc(v), heap, lcl) throw e; (Norm, heap, lcl) (Norm, heap, lcl) e À 0 (Norm, heap, lcl) q throw new NullPointerException(); (Norm, heap, lcl) q e.fld À v where v is some arbitrary value

(Norm, heap, lcl) (Norm, heap, lcl) e À ve À v (Norm, heap, lcl) (Exc(v), heap, lcl) throw e; (Norm, heap, lcl) (Norm, heap, lcl) e À 0 (Norm, heap, lcl) q throw new NullPointerException(); (Norm, heap, lcl) q e.fld À v where v is some arbitrary value Complete Rules for throw where v 0 (Norm, heap, lcl) (flow, heap, lcl) e À ve À v throw e; where flow Norm

Rules for Catching Exceptions Catching an exception No exception caught (Norm, heap, lcl) (Exc(v), heap, lcl) s1 s1 (Norm, heap, lcl) q try s 1 catch (Type ex) s 2 (Norm, heap, lcl [ {ex v}) q s2 s2 where v is an instance of Type (Norm, heap, lcl) (flow, heap, lcl) s1 s1 try s 1 catch (Type ex) s 2 where flow Exc(v) or v is not an instance of Type

Rules for return statements The return statement stores the return value in \result and signals Ret in the flow component: But evaluating e can also throw an exception (Norm, heap, lcl) (Norm, heap, lcl) e À ve À v (Norm, heap, lcl) (Ret, heap, lcl ++ {\result v) return e; (Norm, heap, lcl) (flow, heap, lcl) e À ve À v return e; where flow Norm

Method Call (Normal Case) (Norm, heap, lcl) q 0 e À ve À v e1 À v1e1 À v1 q 0 q 1 q n-1 (flow n, heap n, lcl n ) en À vnen À vn (Norm, heap, lcl) (Norm, heap n+1, lcl n ) e.m(e 1,...,e n ) À mlcl(\result) (flow n, heap n, mlcl) (Ret, heap n+1, mlcl) body... where body is the body of method m in the object heap n+1 (v), and mlcl = { this v, param 1 v 1,... param n v n } where param 1,..., param n are the names of the parameters of m.

Method Call (Exception Case) (Norm, heap, lcl) q 0 e À ve À v e1 À v1e1 À v1 q 0 q 1 q n-1 (flow n, heap n, lcl n ) en À vnen À vn (Norm, heap, lcl) (Exc(v e ), heap n+1, lcl n ) e.m(e 1,...,e n ) À mlcl(\result) (flow n, heap n, mlcl) (Exc(v e ), heap n+1, mlcl) body... where body is the body of method m in the object heap n+1 (v), and mlcl = { this v, param 1 v 1,... param n v n } where param 1,..., param n are the names of the parameters of m.

Semantics of Specifications requires x >= ensures \result <= Math.sqrt(x) && Math.sqrt(x) < \result + public static int isqrt(int x) { body } Whenever the method is called with values that satisfy the requires clause and the method terminates normally then the ensures clause holds. (Norm, heap, lcl) (Ret, heap, lcl) body If lcl( x ) >= x and then lcl(\result) <= Math.sqrt(lcl(x)) < lcl(\result) + 1

What about Exceptions? ensures \result <= Math.sqrt(x) && Math.sqrt(x) < \result + signals (IllegalArgumentException) x < signals_only public static int isqrt(int x) { body } For all transitions where lcl satisfies the precondition and v is an exception, v must be of type IllegalArgumentException. Furthermore, lcl must satisfy x < 0. (Norm, heap, lcl) (Exc(v), heap, lcl) body

Side Effects A method can change the heap in an unpredictable way. The assignable clause restricts changes: requires x >= assignable ensures \result <= Math.sqrt(x) && Math.sqrt(x) < \result + public static int isqrt(int x) { body } (Norm, heap, lcl) (Ret, heap, lcl) body If lcl( x ) >= x and then lcl(\result) <= Math.sqrt(lcl(x)) < lcl(\result) + 1 and heap = heap

What Is the Meaning of a JML Formula? A formula like x >= 0 is a Boolean Java expression. It can be evaluated with the operational semantics. x >= 0 holds in state (Norm, heap, lcl) iff A formula may not have side effects but it can throw an exception. For the ensures formula both the pre-state and the post-state are necessary to evaluate the formula. (Norm, heap, lcl) (flow, heap, lcl) x >= 0 À v where v 0

Semantics of Specifications (formally) A method satisfies the specification requires e 1 ; ensures e 2 ; iff for all executions with the post-condition holds, i.e., there exist v 2, q 2 s.t. However, we need a new rule for evaluating \old (Norm, heap, lcl) (Ret, heap, lcl) body (Norm, heap, lcl) q 1 e1 À v1e1 À v1 where v 1 0 (Norm, heap, lcl) q 2 e2 À v2e2 À v2 where v 2 0 (Norm, heap, lcl) q e À ve À v \old(e) À v where heap, lcl refer to the state before body was executed.

Method Parameters in ensures Clauses requires x >= assignable ensures \result <= Math.sqrt(x) && Math.sqrt(x) < \result + public static int isqrt(int x) { x = 0; return 0; } Is this code a correct implementation of the specification? No, because method parameters are always evaluated in the pre-state, so \result <= Math.sqrt(x) && Math.sqrt(x) < \result + 1; has the same meaning as \result <= Math.sqrt(\old(x)) && Math.sqrt(\old(x)) < \result + 1;

Side Effects in Specifications In JML side effects in specifications are forbidden: If e is an expression in a specification and then heap = heap and lcl = lcl. To be more precise, heap µ heap since the new heap may contain new (unreachable) objects. Also flow Norm is allowed. In that case the value of v may be unpredictable and the tools should assume the worst case, i.e., report that code is buggy. (Norm, heap, lcl) (flow, heap, lcl) e À ve À v