Presentation is loading. Please wait.

Presentation is loading. Please wait.

Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each.

Similar presentations


Presentation on theme: "Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each."— Presentation transcript:

1 Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each specification must provide the information needed to use an interface and to write programs that implement it.

2 States States are mappings from locs (abstract storage locations, also known as objects) to values. Each variable identifier has a type and is associated with a loc of that type.

3 States The major kinds of values that can be stored in locs are: –basic values. These are mathematical constants, like the integer 3 and the letter A. Such values are independent of the state of any computation. –exposed types. These are data structures that are fully described by the type constructors of the programming language (e.g., C’s int * or Modula-3’s ARRAY [1..10] OF INTEGER). The representation is visible to, and may be relied on by, clients. –abstract types. data types are best thought of as collections of related operations on collections of related values. Abstract types are used to hide representation information from clients.

4 Each loc’s type defines the kind of values it can map to in any state. Just as each loc has a unique type, each LSL term has a unique sort. To connect the two tiers in a Larch specification, there is a mapping from interface language types (including abstract types) to LSL sorts. Each type of basic value, exposed type, and abstract type is based on an LSL sort. Interface specifications are written using types and values. Properties of these values are defined in LSL, using operators on the corresponding sorts. For each interface language, a standard LSL trait defines operators that can be applied to values of the sorts that the programming language’s basic types and other exposed types are based on.

5 Procedure Specification The requires clause is used to state restrictions on the state, including the values of any parameters, at the time of any call. The modifies and ensures clauses place constraints on the procedure’s behavior when it is called properly. They relate two states, the state when the procedure is called, the pre-state, and the state when it terminates, the post-state.

6 Procedure Specification A requires clause refers only to values in the pre-state. An ensures clause may also refer to values in the post- state. A modifies clause says what locs a procedure is allowed to change (its target list). –It says that the procedure must not change the value of any locs visible to the client except for those in the target list.

7 Procedure Specification A specification consists of a procedure header (declaring the types of its arguments and results) followed by a body of the form: requires reqP modifies modList ensures ensP A specification places constraints on both clients and implementations of the procedure.

8 Relating implementations to specifications One of the advantages of Larch’s two-tiered approach to specification is that the relationship of implementations to specifications is relatively straightforward. We say that if the implementation satisfies the specification then it is a correct implementation because the relation defined by the implementation is a subset of the relation defined by the specification. Every possible behavior that can be observed by a client of the implementation is permitted by the specification.

9 Relating implementations to specifications void choose(int x, int y) int z; { modifies z; ensures z’ = x  z’ = y; } void choose(int x, int y) int z; { if (x > y) z = x; else z = y; }

10 LP, the Larch proof assistant LP is a proof assistant for a subset of multisorted first- order logic with equality. It is designed to work efficiently on large problems and to be used by specifiers with relatively little experience with theorem proving. LP is intended primarily as an interactive proof assistant or proof debugger, rather than as a fully automatic theorem prover.

11 LP, the Larch proof assistant Its design is based on the assumption that initial attempts to state and prove conjectures usually fail. So LP is designed to carry out routine (but possibly lengthy) proof steps automatically and to provide useful information about why proofs fail. To keep users from being surprised and confused by its behavior, LP does not employ complicated heuristics for finding proofs automatically. It makes it easy for users to employ standard techniques such as proof by cases, by induction, or by contradiction, but the choice among such strategies is left to the user.

12 THE LIFE CYCLE OF PROOFS Proving is similar to programming: proofs are designed, coded, debugged, and (sometimes) documented. Before designing a proof it is necessary to formalize the things being reasoned about and the conjecture to be proved. Once part of a proof has been coded, LP can be used to debug it. Proofs of interesting conjectures hardly ever succeed the first time. Sometimes the conjecture is wrong. Sometimes the formalization is incorrect or incomplete. Sometimes the proof strategy is flawed or not detailed enough.

13 THE LIFE CYCLE OF PROOFS LP provides a variety of facilities that can be used to understand the problem when an attempted proof fails. While debugging proofs, users frequently reformulate axioms and conjectures. After any change in the axiomatization, it is necessary to recheck not only the conjecture whose proof attempt uncovered the problem, but also the conjectures previously proved using the old axioms. LP has facilities that support such regression testing.

14 Nat: Trait includes AC(+, Nat) introduces 0:  Nat s: Nat  Nat - < -: Nat, Nat  Bool asserts Nat generated by 0, s  i, j, k: Nat i + 0 == i; i + s(j) == s(i + j);  (i < 0); 0 < s(i); s(i) < s(j) == i < j implies  i, j, k: Nat i < j  i < (j + k)

15 The declare commands introduce the variables and operators in the LSL specification. The assert commands supply the LSL axioms relating the operators; the Nat generated by assertion provides an induction scheme for Nat.

16 set name nat declare sort Nat declare variables i, j, k: Nat declare operators 0:  Nat s: Nat  Nat +: Nat, Nat  Nat <: Nat, Nat  Bool.. assert Nat generated by 0, s assert ac + assert i + 0 == i i + s(j) == s(i + j)  (i < 0) 0 < s(i) s(i) < s(j) == i < j. implies  i, j, k: Nat i < j  i < (j + k) Sample LP Proof Script

17 set name lemma prove i < j  i < (j + k) by induction j <> 2 subgoals for proof by induction on j [ ] basis subgoal resume by induction on i <> 2 subgoals for proof by induction on i [ ] basis subgoal [ ] induction subgoal [ ] conjecture qed Sample LP Proof Script

18 The prove command initiates a proof by induction of the conjecture. The diamond (<>) annotations are provided by LP; they indicate the introduction of subgoals for the inductions. The box ([ ]) annotations are also provided by LP; they indicate the discharge of subgoals and, finally, of the main proof.

19 The resume command starts a nested induction. No other user intervention is needed to complete this proof. The qed command on the last line asks LP to confirm that there are no outstanding conjectures.


Download ppt "Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each."

Similar presentations


Ads by Google