Case-reduced verification condition generation system and method by use of dynamic single assumption and assigning labels to variables at control join points

Information

  • Patent Application
  • 20020062476
  • Publication Number
    20020062476
  • Date Filed
    July 16, 2001
    23 years ago
  • Date Published
    May 23, 2002
    22 years ago
Abstract
The instructions in a computer program are converted into a form of weakest precondition so as to produce a verification condition that is to be evaluated by a theorem prover. In generating the weakest precondition, labels are introduced for values of variables at control join points. In two preferred embodiments, the computer program is converted into a set of guarded commands prior to the application of weakest precondition operators. In one embodiment, as part of the process of generating the verification condition, assignment commands that assign values to variables are removed from the program through use of a “dynamic single assumption” technique. In another embodiment, the weakest precondition is expressed in terms of strongest postconditions. In both embodiments, a simplified verification condition is produced in which duplications of sets of instructions following a choice operator is avoided.
Description


FIELD OF THE INVENTION

[0002] The present invention relates generally to tools that automatically verify, using static checking techniques, the correctness of a computer program with respect to predefined criteria, and particularly to a tool that derives verification conditions from a computer program source code. In particular, the present invention relates to the simplification of the verification condition to avoid repeated evaluation by a theorem prover of a subexpression in the verification condition that corresponds to a portion of the computer program that is common to two or more alternative paths through the program.



BACKGROUND

[0003] The purpose of a computer program verification system is to analyze a given computer program to determine whether or not it has certain desirable properties. Verification systems can also be used to analyze hardware components. A typical verification system works by generating a verification condition from a given behavioral design, and then evaluating the verification condition with a theorem prover. The verification condition is a mathematical formula. Ideally this formula is valid if and only if the original source program is free of certain kinds of errors.


[0004] The verification condition (VC) is analyzed by a theorem prover that attempts to prove the “theorem” that the VC is true. When the theorem prover is unable to prove that the VC is true, it preferably provides a counter-example, which specifies at least one condition for which the VC is false. For example, if the VC is x+y>x, then a counter-example is y≦0.


[0005] In general, theorem proving is difficult and may consume exorbitant computer resources. Many verification conditions are not solvable in general. Also, the size of the VC may grow exponentially with the size of the computer program from which it is derived. Another circumstance is that two mathematical formulae may be logically equivalent but one may be harder to prove than the other. Overall, significant computer resources may be expended in theorem proving, even when the computer program corresponding to the VC is not unusually complex or long.


[0006] The theory behind VC generation and theorem proving derives from that branch of mathematics known as Logic. Principles underlying VC generation also underlie the general theory of the construction of computer programs and the operation and implementation of programming languages. A theoretical treatment of VC generation in the prior-art can be found in E. W. Dijkstra, A Discipline of Programming, Prentice-Hall, (1976); and in C. A. R. Hoare, “An Axiomatic Basis for Computer Programming,” Communications of the Association for Computing Machinery, 12(10):576-83 (October 1969), both of which are hereby incorporated by reference as background information.


[0007] Several program verification systems exist in the prior art. Examples include: A Program Verifier, J. King, Ph.D. thesis, Carnegie-Mellon University (1969) in which a system, called Effigy, used Symbolic execution to generate verification conditions; L. P. Deutsch, An Interactive Program Verifier, Ph.D. thesis, Univ. Calif., Berkeley, (1973), the first program verifier to use an interactive theorem prover; D. Luckham and N. Suzuki, Automatic Program Verification V: verification-oriented rules for arrays, records and pointers, Stanford Artificial Intelligence Laboratory Memo AIM-278, (March 1976). The last of these, the Stanford Pascal Verifier, used “Hoare Logic” to generate VC's.


[0008] A major contribution to the intensivity of effort in applying the theorem prover is in case-splitting situations, i.e., where choices arise in the program. For example, an “if . . . then . . . else” construct in a computer program provides two alternative, i.e., a pair of, conditional program execution paths, more generally called a choice. Other examples of program constructs that result in a choice are a loop with a loop termination condition, and a conditional branch. All of the aforementioned systems produced VC's with enormous numbers of cases for programs containing a sequential composition of a significant number of alternative choice constructs.


[0009] When a computer program has the structure (S1□S2) S3 (wherein the □ operator represents choice), the corresponding VC generated by methods in the prior art will normally include two instances of an expression corresponding to S3, wherein one instance is combined with an expression corresponding to S1 and another instance is combined with an expression for S2. More generally, each choice in a computer program will approximately double the size of the resulting VC because of the duplication of S3, and will thereby double the amount of work to be performed by the theorem prover to evaluate the VC. Thus, the presence of multiple choices within a computer program will typically cause the complexity of the corresponding VC to increase exponentially when using the methods of the prior art.


[0010] Therefore it is a goal of the present invention to generate a VC that is easier for the theorem prover to evaluate and which is smaller in size than the normal VC for the computer program for which the VC is being generated. None of the aforementioned program verification systems featured a solution to the problem, as addressed by the present invention.



SUMMARY OF THE INVENTION

[0011] The present invention relates to the generation of a verification condition (VC) from a computer program source code that comprises a collection of program statements.


[0012] Accordingly, the present invention involves a method of generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point, the method comprising: applying at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.


[0013] Although a computer program can be transformed directly into a VC and take advantage of the benefits of the present invention, the overall process is facilitated by introducing an intermediate step, whereby the computer program is first converted into an intermediate form comprising “guarded commands.” The preferred input to the VC generator is then a set of guarded commands. In principle, a program written in any computer language can be converted this way.


[0014] In a preferred embodiment, the VC generation algorithm is the computation of a weakest precondition. In one embodiment, the weakest precondition of the set of guarded commands is computed and assignment commands (which assign values to variables) are removed from the program through use of the “dynamic single assumption” technique that transforms assignment commands into program assumptions. In another embodiment, the weakest precondition is expressed in terms of strongest postconditions. The commonality between the embodiments is that labels are introduced for the values of variables at control join points and that duplication or near duplication in the VC of subexpressions derived from the expression following the control join point is avoided.


[0015] The present invention includes a method of generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point, the method comprising: when the program statements in the computer program include at least one assignment statement, transforming the at least one assignment statement into an assume command, wherein the transforming includes mapping a variable that is assigned a value by the at least one assignment statement into an expression denoting a value of the variable after the at least one assignment statement; and applying at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths. A method according to the present invention also preferably comprises passing the verification condition to a theorem prover and determining whether or not the verification condition is valid.


[0016] In a preferred embodiment, the method of the present invention additionally comprises expressing the weakest precondition operator in terms of at least one strongest postcondition operator.


[0017] Accordingly the present invention additionally comprises a computer readable medium for use in conjunction with a computer system, the computer readable medium comprising a computer readable storage medium and a computer program mechanism embedded therein, the computer program mechanism comprising: instructions for generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point; instructions for determining when the program statements in the computer program include at least one assignment statement, and, instructions for transforming the at least one assignment statement into an assume command, wherein the transforming includes mapping a variable that is assigned a value by the at least one assignment statement into an expression denoting a value of the variable after the at least one assignment statement; and instructions for applying at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.


[0018] The present invention also includes a computer readable medium for use in conjunction with a computer system, the computer readable medium comprising a computer readable storage medium and a computer program mechanism embedded therein, the computer program mechanism comprising: instructions for generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point; instructions for applying at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.


[0019] The present invention further includes a computer readable medium that comprises instructions for computing at least one precondition operator in terms of a weakest precondition operator expressed by at least one strongest postcondition operator.


[0020] The present invention additionally includes an apparatus for generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point, the apparatus comprising: a memory containing the computer program, an operating system and at least one processor configured to execute mathematical operations on the computer program, wherein the computer processor: when the program statements in the computer program include at least one assignment statement, transforms the at least one assignment statement into an assume command, and includes mapping a variable that is assigned a value by the at least one assignment statement into an expression denoting a value of the variable after the at least one assignment statement; and applies at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.


[0021] The present invention also includes an apparatus for generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point, the apparatus comprising: a memory containing the computer program, an operating system and at least one processor configured to execute mathematical operations on the computer program, wherein the computer processor: applies at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.


[0022] The apparatus of the present invention also includes a computer processor that computes at least one precondition operator in terms of a weakest precondition operator expressed as at least one strongest postcondition operator.







BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Additional objects and features of the invention will be more readily apparent from the following detailed description and appended claims when taken in conjunction with the drawings, in which:


[0024]
FIG. 1 is a block diagram of a programmed general purpose computer according to an embodiment of the Verification Condition Static Checking system.


[0025]
FIG. 2 is a flow chart of a method of determining whether a specified computer program satisfies a set of program conditions including the step of generating a simplified verification condition according to the method of the present invention.


[0026]
FIG. 3 is a schematic view of names assigned to a variable, x, on different branches of a program following a choice.


[0027]
FIG. 4 is a flow chart of a method of determining whether a specified computer program satisfies a set of program conditions including a two stage process of generating a simplified verification condition according to a preferred embodiment of the method of the present invention.


[0028]
FIG. 5 is a flow chart of a method of determining whether a specified computer program satisfies a set of program conditions including a process of generating a simplified verification condition expressed as strongest post conditions according to a second embodiment of the method of the present invention.







DESCRIPTION OF THE PREFERRED EMBODIMENTS

[0029] The present invention provides a method of generating a VC that is simpler and easier for a theorem prover to evaluate than a VC generated using methods in the prior art. The VC generated using the present invention takes advantage of situations where a single evaluation of an expression by the theorem prover may be valid for multiple computational contexts.


[0030] The VC has a branching structure that governs its evaluation by the theorem prover. By reducing the number of branches in accordance with the present invention, repeated evaluation of various subexpressions is eliminated or reduced. In some situations, repeated evaluations of a subtree, representing a postcondition for two conditional program execution paths of the computer program, may nevertheless be required because of differences in the assumptions that apply to evaluation of the subtree for each of the alternate execution paths. But in many situations the theorem prover will need to evaluate a subtree corresponding to the postcondition only once.


[0031] As used herein, a postcondition and a precondition are both examples of predicates. As understood by one skilled in the art, a predicate is a function whose result represents the truth or falsehood of some condition. A predicate transformer is a characterization of the semantics of a program or program statement as a function from predicates to predicates.


[0032] Referring to FIG. 1, the present invention may be implemented using a programmed general-purpose computer system 100. The computer system 100 includes: (a) one or more data processing units (CPU's) 102; (b) memory 106, which will typically include both high speed random access memory as well as non-volatile memory (such as one or more magnetic disk drives); (c) a user interface 108; (d) a network or other communication interface 110 for communicating with other computers as well as other devices; and (e) one or more communication busses 104 for interconnecting the CPU(s) 102, memory 106, user interface 108, and network interface 110.


[0033] The computer system's memory 106 stores procedures and data, typically including:


[0034] an operating system 112 for providing basic system services;


[0035] application programs 114, such as user level programs for viewing and manipulating images;


[0036] one or more authoring tools 116, for assisting with the writing of computer programs; and


[0037] an annotated computer program 118 that comprises a collection of program statements, representing a computer program to be analyzed by a verification condition static checking module 120. It is understood that the system and method of the present invention is also applicable to fragments of computer programs, for example, individual or several of the procedures, functions, subroutines, modules, or applets of which a computer program may be comprised.


[0038] The verification condition static checking module 120 preferably includes:


[0039] a verification condition generator 122, which generates as its output a verification condition 124;


[0040] a theorem prover 126 that analyzes the verification condition and optionally generates one or more counterexamples 128 when it is unable to prove the verification condition; and


[0041] an analysis module 130 that performs post processing on the counterexamples 128 generated by the theorem prover 126, and when an error or potential error in the computer program 118 is detected, produces one or more error messages 132.


[0042] A preferred embodiment of the method of the present invention is shown in FIG. 2. Referring to FIG. 2, the annotated computer program 118 to be checked is first converted into an intermediate form of the program to facilitate analysis (step 140 ). In a preferred embodiment, the intermediate form utilizes guarded commands that are the basis of a particularly simple programming language. Thereafter, the intermediate form of the program is processed by the verification condition generator 122. To facilitate the work of the theorem prover, the intermediate form of the program is transformed in accordance with the present invention (step 142 ). During the transformation step 142, labels are introduced into the VC that correspond to values of program variables at control join points. In contrast, methods in the prior art only introduce labels that correspond to the values of variables at the beginning or end of the program. The verification condition 124 produced by the VC generator according to the methods of the present invention is simplified in that certain subexpressions derived from the expressions that follow control join points are present only once in the VC. Such a simplified VC is referred to herein as a “case reduced verification condition.”


[0043] The verification condition 124 for the program is represented as a “logical equation”. In a preferred embodiment, the logical equation that is the verification condition 124 is expressed as a “weakest precondition”. The logical equation is typically represented as a tree of sub-expressions. Various subsets and combinations of the sub-expressions must be conclusively proved to be true for all possible program conditions.


[0044] The VC is passed to the theorem prover 126 whose job is to evaluate the sub-expressions of the verification condition, for all possible program conditions, to determine which ones (if any) it cannot conclusively prove to be true. Failure to prove sufficient combinations of sub-expressions to always be true means that one or more of the pre-conditions or postconditions required for proper operation of the program is not satisfied, or may potentially not be satisfied.


[0045] It is noted that the theorem prover may not be able to prove the truth of a sub-expression, even though it is in fact true, in which case a false error report may be generated. However, the operation of the theorem prover and the generation of such false error reports are outside the scope of the present document. When it is unable to prove the truth of the VC, the theorem prover ideally produces one or more counter-examples 138 that are processed by an analysis module 130 and output as error messages 132.


[0046]
FIG. 3 illustrates the flow of control through a program that contains a control join point. The single execution trace 300 precedes a branch point 302. At branch point 302, one of two conditional program execution paths 304 and 306 are possible. These paths join one another at control join point 308, coalescing into a single path 310 that proceeds to execute expressions following control join point 308. In general, for any computer program, the (normal) termination of the program is a control join point. The methods of the present invention have greatest utility where they are applied to a program in which an expression or a collection of commands follows a control join point.


[0047] In this document, the term “expression” will be used, in different contexts, to mean two distinct things. First, an “expression” may be a string (such as x+1) representing the computation of a value to be stored in a variable, or used as the basis for making a decision. Secondly, an “expression” may be what is more formally called a “statement” in a program, where a statement may include a sequence or other combination of program statements (or commands). The symbol S is often used to represent a “statement” (herein called an expression), where the statement may include many lines of program code, each of which may in turn be called a statement. Taken to its natural limit, S may represent an entire computer program. Thus, the term “expression” is used to mean a sequence, collection or combination of one or more commands (or program statements). Similarly, the term “command” can mean both a single command and a sequence, collection or combination of commands.


[0048] Guarded Commands


[0049] In a preferred embodiment of the present invention, the intermediate form into which the computer program 118 is converted, is composed of guarded commands. The methods of the present invention are not limited to using intermediate forms that are based on guarded commands. Guarded commands are particularly advantageous because of their simplicity. Guarded commands are a limited set of commands that together comprise a small simplified computer programming language. The embodiment of the present invention described herein is based on Dijkstra's guarded commands (see E. W. Dijkstra, A Discipline of Programming, Prentice-Hall, ( 1976 )). Other examples of guarded commands derived from Dijkstra are described elsewhere (see G. Nelson, “A Generalization of Dijkstra's Calculus”, ACM Transactions on Programming Languages and Systems, 11(4): 517-561, (1989); and M. S. Manasse and C. G. Nelson, “Correct Compilation of Control Structures,” Bell Labs Technical Memorandum, (Sep. 9th, 1984), both of which are incorporated herein by reference).


[0050] In Table 1, hereinbelow, are the “guarded commands” used in the present invention, some of which are derived from Dijkstra. The conversion of Java programs to the set of guarded commands described in Table 1 is described elsewhere in: K. R. M. Leino, J. B. Saxe and R. Stata, “Checking Java programs via guarded commands,” SRC Technical Note 1999-002, Compaq Computer Corporation, May 21, 1999, also available in Formal Techniques for Java Programs, Workship proceedings, Ed. B. Jacobs, et al., Technical Report 251, Fernuniversität Hagen, 1999, incorporated herein by reference.


[0051] In Table 1, x is a variable; e is an expression; and S is a statement.
1TABLE 1Description of Guarded Commands Used InA Preferred Embodiment of the InventionGuardedCommandExplanationx: = eAssign expression e to x; (“x gets e”).var x in S1 endIntroduce a new variable (has an arbitrary initial value).assume eAssume e is true at this point in the program (direct thechecker to treat e as true).assert eRequire that e is true (direct the checker to warn if e isnot true).S1; S2Sequential execution of S1 and S2.S1  S2Execute either S1 or S2raiseRaise an exception.S1 ! S2Catch an exception.


[0052] Accordingly, the term “guarded command” as used herein will be taken to mean those commands set forth in Table 1, though it is understood by one of skill in the art that the methods of the present invention are not limited to those commands but are applicable to Dijkstra's original commands or many other variations thereof.


[0053] The guarded command, “var x in S1 end” is similar to the use of a temporary variable in Java as might find application in, for example, swapping the values of two variables.


[0054] The context in which “assert e” finds application is in the annotation of programs. For the purposes of generating the verification conditions, annotations other than those required by the compiler can be introduced into the program. The purpose of “assert” is to introduce proof obligations into the verification condition. Proof obligations are conditions that permit the theorem prover to test various aspects of the operation of the program. One example is in the checking for null pointer dereferences. The annotation assert x not null represents a condition that the theorem prover checks. If there is a possibility that x is null, that possibility is encoded within the verification condition. Other examples of annotations include: a division operation wherein an “assert” is used to check whether the divisor is ever zero; and an array boundary checker.


[0055] Implied annotations are annotations that the programmer does not need to explicitly include in a program because the implied annotations are automatically assumed to apply to all instances of certain program constructs. Thus, pointer dereference instructions may be assumed to include an implied annotation asserting that the pointer to be dereferenced is not null, and division instructions may be assumed to include an implied annotation asserting that the divisor is not equal to zero.


[0056] Details of the commands “raise” and “bang” (“!”) are discussed hereinbelow when considering exceptions.


[0057] The control constructs in Table 1 hereinabove do not include any constructs for introducing loops into the program. This can be explained as follows. All treatments of loops by automatic program verification systems ultimately work by rewriting a program with loops into some other semantically equivalent program without loops. (Several possible ways of doing this are explained in Section 3 of Leino et al., “Checking Java programs via guarded commands,” SRC Technical Note 1999-002, Compaq Computer Corporation, May 21, 1999, referred to hereinabove). The methods of the present invention are to be applied to a loop-free program that results from some rewriting of this kind.


[0058] As an example illustrating the difference between Dijkstra's guarded commands and those presented here, the translation of an “if . . . else” control construct into guarded commands is presented:
2if (e){S1}else{S2}becomes(assume e; S1)  (assume e; S2).


[0059] The “if . . . else” construct has been translated into two choices: an assumption that e is True and an assumption that e is False. In the guarded command form, S1 and S2 are themselves replaced by their respective translations into guarded commands.


[0060] In contrast, in Dijkstra's original guarded command language, the “if . . . else” control construct becomes


ife→S1e→S2fi


[0061] wherein →is a “guard arrow”. Therefore, in the implementation presented here, “assume e” is like a guard.


[0062] Weakest Preconditions


[0063] A verification condition can be produced by applying a weakest precondition operator to a program. According to methods in the prior art, it is possible to compute the weakest precondition, wp, of a program from the weakest preconditions of its various subparts. By definition, the “weakest precondition” of a program is a logical condition that ensures that the program S executes without error and terminates in a state where a postcondition P is True.


[0064] Formally, wp(S,P) (also written as wp[S.P] or wp.S.P) is a predicate, or condition, that ensures that program S terminates in a state where P is True. Such a precondition operator is referred to herein as a ‘traditional’ precondition operator.


[0065] As an example, consider the weakest precondition of a “program” that simply increments variable x.




wp
(x:=x+1,x≦10)



[0066] In this case, the weakest precondition is the condition that must be fulfilled such that x has value ≧10 after execution. The weakest precondition is then that x is at least 9, i.e., x ≧9.


[0067] Computing Weakest Preconditions for Guarded Commands


[0068] The weakest precondition operators of the prior art, which are examples of traditional precondition operators, may be applied to the set of guarded commands used herein. Table 2 shows how the weakest precondition computations of the prior art are used to produce a VC. The variables that result in the VC refer to, i.e., label the values of the corresponding program variables in the initial state of the program.
3TABLE 2Weakest Preconditions of Guarded CommandsGuarded CommandWeakest PreconditionSwp · S · PCommentsx: = ePx: = eP holds with everyoccurrence of xreplaced by e.var x in S1 end∀ x: wp · S1 · PS1 should establish Pregardless of the initialvalue of x.assume ee = PIf e is True, P shouldhold.assert ee  PBoth e is True and Pholds.S1; S2wp · S1 · (wp · S2 · P)Weakest precondition onS1 is a precursor to theweakest precondition onS2.S1  S2wp · S1 · P  wp · S2 · PWeakest precondition isvalid for both S1 and S2.


[0069] As shown in Table 2 hereinabove, for an assignment command, “x gets e,” the weakest precondition, wp.S.P, is the postcondition P with every occurrence of x replaced by e. As an example, for the statement S, given by x:=x+1, (i.e., increment x), subject to the postcondition P, given by x>0, the weakest precondition, wp.S.P, is x+1>0, i.e., x>−1.


[0070] For introduction of a new variable, “var x in S1 end”, i.e., where a new variable x is introduced with scope S1, the weakest precondition, given by wp.(var x in S1).P, is simply:




∀x:wp.S


1


.P.




[0071] I.e., the postcondition, P, holds, no matter what the initial value of x.


[0072] For the choice expression, S1□S2, the weakest precondition involves a duplication of the postcondition, P (which is the precondition for the remainder of the program, if any, after the choice expression). This problem of duplication is magnified for the case of combinations of sequence and choice expressions. For example, consider the expression




S
=(S1□S2);(S3□S4)



[0073] subject to the postcondition, P. In this case, the resulting expression involves four copies of P.
1wp·S·P=wp·(S1S2)·(wp·(S3S4)·P)=wp·(S1S2)·(wp·S3·Pwp·S4·P)=wp·S1·(wp·S3·Pwp·S4·P)wp·S2·(wp·S3·Pwp·S4·P)


[0074] Similar problems arise for nested choice, meaning that the verification condition is difficult to prove. In such cases, therefore, the resulting verification condition increases exponentially in size with the number of sequentially composed choice operators, and the resulting verification condition will include a corresponding large number of instances of certain postcondition expressions. As a result, the theorem prover will need to repeatedly evaluate the correctness of the repeated postcondition expressions. It is an object of the present invention to simplify the form of the VC so that it contains fewer instances of the postcondition expressions.


[0075] Dynamic Single Assumption


[0076] Thus the computation of weakest preconditions by the prior art methods of Table 2 hereinabove introduces labels only for initial values of program variables, which leads to large and difficult VC's. The methods of the present invention, as described hereinbelow, introduces names for the values of program variables at control join points when the variable is modified on at least one of the conditional program execution paths that preceded the control join point, in addition to names for their initial values. In a preferred embodiment of the present invention, shown in FIG. 4, a computer program 118 is first converted to guarded command form, step 402. Then, instead of carrying out a weakest precondition computation according to the formulae of Table 2, the transformation from a set of guarded commands to a VC involves two steps. In the first step 404, the guarded command form is transformed into a semantically equivalent form called the passive guarded command form, which does not include assignments, by application of a technique referred to herein as “dynamic single assumption” (DSA). The DSA is also described in, Cormac Flanagan and James B. Saxe, “Avoiding Exponential Explosion: Generating Compact Verification Conditions,” Conference Record of POPL 2001: The 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Jan. 17-19, 2001, London, UK., ACM SIGPLAN Notices 36(3): 193-205, (March 2001), ISBN 1-58113-336-7, which is incorporated herein by reference in its entirety.


[0077] The application of DSA permits the introduction of labels for values of variables at control join points. Implicit in step 404 can be the derivation of “fix-up” and “merge” code, as described hereinbelow. In the second step 406, a precondition operator is applied to the passive form of the guarded commands to give rise to the VC 124. The transformation of commands to DSA form in step 404 is not limited to programs expressed in guarded command form.


[0078] As an illustration, consider the following code fragment, in guarded command form, comprising three assignments:




x:=
1;





x:=x+
1;





x:=x+
1;



[0079] While transforming each assignment statement into an assume command, the variable that is assigned a value by the respective assignment statement is mapped into a new variable corresponding to the assignment statement. Thus, for each assignment, a new variable is introduced, and each assignment in the original code is transformed, in the DSA form, into an assumption about one of the new variables. The DSA form of the code fragment is:


assume x1=1;


assume x2=x1+1;


assume x3=x2+1;


[0080] Thus the outcome of using the DSA is to replace every assignment by an “assume,” accompanied by introduction of a new variable name. Such an “assume” can be referred to as a “guarded assume” command.


[0081] Although an “assume” appears similar to an assignment, each “assume” introduced by the DSA transformation can only be carried out once for each variable during the execution of a program. It is to be noted that two alternate conditional execution paths of a program can both contain an “assume” for the same variable.


[0082] The aim of the DSA transformation is to arrive at a program that is free of assignments. For example, if all variable names are different, the “var” statements may be taken to the outside of any control structure and effectively ignored. The resulting program consists entirely of statements comprising the guarded commands “assume”, “assert”, choice (□) and sequential execution (;). The DSA form of a program may also be referred to as a “passive” form of the program, since it contains no assignment statements.


[0083] In order to transform commands such as guarded commands into DSA form, it is important to keep track of the mappings between variable names in the original program and variable names in the DSA program at each control point. Such a map is referred to as the “context” for a particular control point. The transformation is defined using a function, dsa, that takes two arguments, a command S and a context R for the initial state of S, and produces a pair of results: a new command S′ and a context R′ for the final state of S.


[0084] Accordingly, the DSA of a guarded command, such as x :=e, utilizes a mapping to keep track of variable names. As an example, if e is the expression x+y−z wherein x, y, z are variables in the guarded command form of the program, let R be the mapping




{x→x


1


,y→y


3


,z→z


2
}.



[0085] Then R(e) is the expression x1+y3−z2. In general, R(e) is obtained from e by replacing each free occurrence of any variable ν by the renaming prescribed for v by R.


[0086] Operationally, the dsa function transforms a command-map pair into another such pair. For example, if R is the mapping {y→y1} and S is the command




x:=y




[0087] then dsa(S,R) is the pair


(assume x1=y1,{y→y1,x→x1})


[0088] In general, if S is a guarded command and R is a mapping, then dsa(S,R) is a pair of passive commands (called T) and a new mapping (called U), such that


[0089] (1) dom(U), the domain of U, includes (at least) every variable in dom(R) and every variable assigned to in any execution of S; and


[0090] (2) every possible execution of S has at least one “corresponding” possible execution of T, and vice-versa,


[0091] where “corresponding” executions are related as follows:


[0092] (a) for every variable v mentioned in dom(R), the initial value of v in any execution of S is equal to the value of R(v) in any corresponding execution of T;


[0093] (b) corresponding executions of S and T either both go wrong or both complete normally; and


[0094] (c) if a corresponding pair of executions of S and T both complete normally, then for every variable v in dom(U) the final value of ν after the execution of S is equal to the value of U(ν) in the execution of T.


[0095] By definition, a program “goes wrong” when it is caused to execute a sub-command of the form “assert e” from a state where the expression e evaluates to False. (Note that it is unnecessary to distinguish initial and final values for the execution of T, since T includes no assignment commands.)


[0096] Condition (2)(b) hereinabove means that the verification condition for S will be valid (signifying that S can never go wrong) if and only if the verification condition for T is valid. Because T contains no assignment statements, its VC can be computed by a specialized method (described hereinbelow and summarized in Table 5). The resulting formula will often be smaller, and its validity easier to test, than would be the case for a verification condition for the original command S computed using prior art methods (e.g., as in Table 2).


[0097] The DSA for each guarded command is shown in Table 3 hereinbelow, in which “where” means that the ensuing code defines how the replacement commands (such as D1 and D2) and the new renaming function(s) (such as R1 and R2) are generated. Before applying the DSA rules in Table 3, each subcommand of the form “var x in S end” should be replaced by Sx:=x′ where the various x′ are chosen to be unique.


[0098] The DSA transformation is applied to any nested set of commands from the inside to the outside. Thus, also, as shown in Table 3, hereinbelow, a pair of conditional program execution paths is converted into a first group of guarded commands coupled by a choice operator to a second group of guarded commands.
4TABLE 3Transforming Guarded Commands to Dynamic Single Assumption FormGuarded Command, Sdsa(S, R)x: = e(assume xn = R(e), R[x → xn])where xn is a new nameOR(assume True, R[x → R(e)])assume e(assume R(e), R)assert e(assert R(e), R)S1; S2(D1; D2, R2)where(D1, R1)= dsa(S1, R)(D2, R2)= dsa(S2, R1)S1  S2((D1; FX1)  (D2; FX2), R3)where(D1, R1)= dsa(S1, R)(D2, R2)= dsa(S2, R1)(FX1, FX2, R3)= merge(R1, R2);


[0099] In Table 3, FX is “fix-up” code and merge is a function that generates the “fix-up” code and a merge-map, both of which are defined below. The dsa function is thus an exemplary transformation function having as one of its outputs a modified mapping for application to a subsequent statement of the computer program, such that the modified mapping is based on variable mappings produced by transformation functions on earlier statements of the computer program.


[0100] In general, the outcome of applying dsa to a guarded command S and an initial renaming function R is both a new command S and a new renaming function R. The DSA additionally introduces new variable names.


[0101] The transformation of an assignment statement produces an assume command, such that the transformation includes mapping a variable that is assigned a value by the assignment statement into an expression denoting a value of the variable after the assignment statement.


[0102] In a preferred embodiment, as shown in the first entry in Table 3, for simple assignment expressions it is possible to avoid introducing a new variable. In such cases the mapping just associates the variable x with whatever expression was originally present, i.e., includes a mapping function that maps said variable to the result of applying to the simple expression a mapping corresponding to a program state before the assignment statement, and accompanies it with a no-op, “assume True.” Thus the range of possible mappings for an assignment includes variables to expressions as well as variables to variables. In practice, according to the preferred embodiment of the present invention, whether an assignment is represented by mapping that introduces a new variable name or one which produces a simple substitution, is determined by the complexity of the expression on the right hand side of the assignment.


[0103] The implicit assumption behind the DSA is that, as demonstrated in FIG. 3, although the same variable x starts in R, before a branch point such as 302, it may attain different variable assignments on either of the ensuing conditional program execution paths such as 304 and 306. In FIG. 3, D1 and D2 are collections of one or more executed statements. In FIG. 3, variable x before the branch point attains variable names x10 and x11 in each respective branch 304 and 306, both of which need to be merged together after the control join point 308. There is always an implicit control join point at the end of a program.


[0104] As an example, the following program fragment is transformed into DSA, or “passive,” command form:




dsa
(x:=5□(x:=6;x:=x+1)); assert x>y,(x→x0,y→y0))



[0105] where the last term in the parentheses is the mapping given, say, by R. This example comprises a choice (□) as well as a sequential composition (semi-colon) operator. The DSA's for each command are therefore embedded in the DSA for the program fragment. The form of the DSA translation for each command is presented in Table 3, hereinabove. Inserting the appropriate expressions, the translation is:


(((assume x1=5;assume x4=x1)□(assume x2=6; assume x3=x2+1);


assume x4=x3));


assert x4>y0;


[0106] In this example, “assume x4=x1” in the first parenthesis and “assume x4=x3” in the second set of parentheses are respectively “fix-up code.” The purpose of the fix-up code is to synchronize, i.e., produce a consistent labeling of, the variables at the conclusion of each conditional execution path of the choice operator. This is important to achieve if the program fragment is embedded in a larger piece of code that includes commands following the program fragment.


[0107] The fix-up code FX1 and FX2 for merging the renaming functions of two program paths, merge(R1, R2), is generated using the merge procedure of Table 4.
5TABLE 4Merge Procedure for Merging Mapping Functions R1 and R2FX1: = Assume True;FX2: = Assume True;R: = empty map;for each x in dom(R1) ∪ dom(R2) doif x is not in dom(R1) thenR: = R[x → R2(x)]elseif x is not in dom(R2) thenR: = R[x → R1(x)]elseif R1(x) = R2(x) thenR: = R[x → R1(x)]elselet xn be a new name for xFX1: = “FX1; assume xn = R1(x)”FX2: = “FX2; assume xn = R2(x)”R: = R[x → xn]endifend forreturn (FX1, FX2, R)


[0108] At the top of the merge procedure of Table 4, the fix-up codes are initially null and the mapping set is empty. The for-loop in the merge code iterates over all the variables that are either in the map R1 or the map R2. For each variable x, if R1 and R2 map x to the same variable name, there is no conflict, no new fix-up code is needed and the return output variable map, R, just maps x to whatever it was mapped to by R1 (or R2). However, the last else branch within the for loop takes care of the general case where x is mapped differently, i.e., to different variable names, by R1 and R2. A new name xn is introduced to represent the value of x at the control join point, and the fix-up code for each path to the join point is extended with an assumption that the value of x at the end of that path is equal to xn. The extension of the fix-up code is effectively a concatenation operation and could be written in the form:




FX


1


:=FX


1
+“;assume xn=R1(x)”



[0109] Whatever string FX represented before, i.e., whatever set of assume commands, has now tacked on to it another assume command to cope with the variable in question. Ultimately, the two pieces of fix-up code and the mapping are returned; the result of merge is used in the DSA for a choice operator.


[0110] VC Generation for Passive Commands


[0111] In a language with assignments, one can think of a program starting in an initial state comprising certain values of its constituent variables and finishing in a final state with certain values of its constituent variables, some of which may be different from the respective initial values.


[0112] By contrast, in a program comprising guarded commands in which assignments are represented by assumes, the starting states are constrained. As an example, consider the program:


assume x=6;


[0113] This program can only execute with the starting value, x=6. By contrast, the program:


assume x=6□assume x=7;


[0114] has only two possible starting states. Furthermore, in a language composed of assumes and asserts, certain starting states will result in error-free termination of the program, whereas others will not. The goal of the theorem prover is to ascertain those states that result in, say, a bad assertion. For example, a “good” program (i.e., a program that will execute and terminate correctly) is:


assume x>1; assert x>1.


[0115] This is a good program because it can only execute in states where x is >1 and the condition that x>0 must therefore be true. By contrast, the following program is not good:


assume x>0; assert x>1.


[0116] The assertion could be wrong in the case x=1 and the program could go wrong.


[0117] In summary, there may be some states in which a program executes correctly, some in which the program goes wrong, and even some in which the program does not execute at all.


[0118] The absence of assignment statements means that the execution of a passive statement cannot change the program state, and the only effect of such an execution is to choose among the two possible outcomes: normal termination and going wrong. Thus the semantics of a passive statement S can be completely captured by two outcome predicates, one which describes the initial states from which the execution of S may terminate normally, and one which describes states from which the execution of S may go wrong.


[0119] According to the methods of the present invention, two operators are introduced to enable computation of wp for passive commands, namely norm(S) and bad(S):


[0120] norm(S) represents the set of states from which the program S could execute normally;


[0121] bad(S) represents the set of states from which the program S could go wrong.


[0122] For any passive command, S,




wp
(S,True)=bad(S)



[0123] Both bad and norm are precondition-like predicate transformers that are different from traditional precondition operators such as wp and which may only be applied to passive commands. In generating the case-reduced VC according to the methods of the present invention, bad and norm take the place of the conventional wp of the prior art. The present invention also utilizes a special predicate transformer, exc, for the “exceptional” termination of a program, which is further described hereinbelow.


[0124] In the foregoing example, represent the program:


assume x>0; assert x>1.


[0125] by S. Then:


norm(S)>x>1;


bad(S)=x>0x≦1.


[0126] The ultimate goal is to generate a good program, S. A program S is free of errors when bad(S)=“False”, i.e., when no states can go wrong. Accordingly, the expressions for the application of the norm and bad operators to each kind of passive guarded command are shown in Table 5, hereinbelow.
6TABLE 5Precondition Operators Applied to Passive CommandsGuardedCommand, Snorm(S)bad(S)Commentassert eee“assert e” is executednormally if e is True;conversely, if e is False,“assert e” causes theprogram to executeincorrectly.assume eeFalseProgram can executenormally if e is True; sincee is assumed to be True, itcannot at the same time beFalse, and therefore theassume command cannotgo wrong.S1  S2norm(S1)bad(S1)Program can execute norm(S2) bad(S2)normally if either S1 or S2executes normally.Program can go wrong ifeither S1 or S2 goes wrong.S1; S2norm(S1)bad(S1) Program can execute norm(S2)(norm(S1)normally when both S1 and bad(S2))S2 execute normally,in sequence; programgoes wrong if eitherS1 goes wrongor if S1 executesnormally but thenS2 goes wrong.


[0127] The bad and norm functions shown in Table 5 can be used to compute the weakest precondition of a specified program that is expressed in passive command form.


[0128] As an example of the representation of guarded commands in this way, consider the conversion of the following Java code fragment (which is an instance of the “if . . . else” control construct considered previously):
7{if(b){x=x+1;}else{x=0;}S


[0129] (where S is some Java Statement). This simple Java construct becomes, in guarded command form:


((assume b;x:=x+1)□(assume b;x:=0));S


[0130] where, as before, S would be represented by its translation into guarded command form. Given the initial mapping {x→x1}, the transformation to DSA produces the following passive command and another map:


((assume b; assume x2=x1+1; assume x4=x2)□(assume b; assume x3=0; assume x4=x3));S′


[0131] where S′ is the passive form of S translated using {x→x4} as the initial mapping. The variable x4 has been introduced to capture the value of x at the control join point. Referring to the preceding expression as D, it may further be written as (D1□D2); S′. In order to obtain the verification condition, bad(D) is computed. This, according to the foregoing expression, is calculated as the bad of the two expressions, (D1□D2) and S′, separated by the semi-colon operator. Using the expressions shown in Table 5, bad(D) is computed as follows:


bad(D)=bad(D1□D2)(norm(D1□D2)bad(S′))


[0132] The first part of this expression is automatically False because in this case there are no asserts in D1 or D2. Therefore (D1□D2) never goes wrong in this particular case. This type of simplification is representative of the simplifications that are often (but not always) achievable when generating the VC expression for a program that has been transformed into passive form, wherein Dynamic Single Assumption has been used to transform the guarded commands into passive form.


[0133] After further simplification, bad(D) is evaluated as follows:
2bad(D)False((norm(D1)norm(D2))bad(S))((norm(assumeb)norm(assumex2=x1+1)norm(assumex4=x2))(norm(assumeb)norm(assumex3=0)norm(assumex4=x3))bad(S)((bx2=x1+1x4=x2)(bx3=0x4=x3))bad(S)


[0134] The guarded command expression of the “if . . . else” construct and bad(S′) are present in the final simplification. In other words, the postcondition expression bad(S′) is only present once in the VC expression for the portion of the program comprising the “if . . . else” construct.


[0135] Thus, in a situation whereby a pair of conditional program execution paths is transformed to a first group of guarded commands coupled by a choice operator to a second group of guarded commands, the resulting verification condition comprises:


[0136] a logical OR of a first condition corresponding to the first group of guarded commands and a second condition corresponding to the second group of guarded commands; connected by an implication to a single instance of a post-condition, corresponding to the expression following the control join point, that must always be true after execution of either the first or the second groups of guarded commands.


[0137] As illustrated hereinbelow, this outcome is contrasted with the standard VC expression, obtained according to the methods of the prior art, that contains at least two instances of the postcondition expression. The same code fragment in guarded command form is:


((assume b;x:=x+1)□(assume b;x:=0));S


[0138] Representing this expression by G, the conventional application of weakest preconditions to G is given by:




wp
(G,True)≡(b→(wp(S,True)x:=x+1)z,902 (b→(wp(S,True)x:=0)



[0139] To evaluate this expression for the weakest precondition for G, it is necessary to evaluate the weakest precondition of S twice, once each with x=0 and x=x+1. If S is itself a large or complex expression, this is costly. Also if there are further “if . . . else” constructs in the same program, even further copies of S will be included in the VC and thus even further copies of the weakest precondition of S will be required to be evaluated. Furthermore, if x appears in S, the multiple copies will be slightly different from one another. In this example, one copy would have x replaced by x+1 and the other copy would have x replaced by 0. Consequently, memory resources will be taken up by the similar, but not identical, copies.


[0140] In summary, one important aspect of the present invention is that when computing the weakest precondition of an expression such as (S1□S2); S3, wherein S3 is a complex expression (e.g., containing a collection of commands and possibly additional choice expressions), an evaluation of the weakest precondition of S3 for both branches of the choice is avoided. The weakest precondition of an expression, such as S3, that follows the choice operator is a postcondition for the expressions on either side of the choice operator. In particular, the application of the operators bad and norm to statements in passive form leads to a direct simplification that does not arise from the application of the conventional wp operators of the prior art. As an example, consider the program, S:


(assume e1□assume e2); assert P


[0141] and let S1 be “assume e1”, S2be “assume e1” and S3 be “assert P.” Using the bad and norm precondition operators of Table 5 hereinabove the weakest precondition is evaluated as follows:
3wp(S,True)=bad(S)=bad(S1S2)(norm(S1S2)bad(S3))=(FalseFalse)((e1e2)P)=((e1e2)P)


[0142] The final form includes the postcondition P only once. By contrast, using the wp operators of Table 2, hereinabove:




wp


9


S
,True)=(e1→P)z,902 (e2→P)



[0143] This expression contains two instances of P and must be further simplified by application of a rule of logic, viz: the equivalence of the expression (p→r)(q→r) to (pq)→r. The simplification that was inherent in the application of bad and norm to the passive command form is not automatically produced by the application of the traditional weakest precondition operator, wp.


[0144] A further important advantage of the present invention arises when expressions on either branch of program execution following a choice operator contain assignments. In general, the simplification of an expression of the form (pr)(qz,902 r) to (pq)r can only be achieved when r is the same on both branches. Assignments are troublesome because they can change the representation of r. Consequently, an expression appearing on both sides of a branch may not be the same on both sides because of the various variable replacements that occur.


[0145] As seen, the weakest precondition of any expression, P, involving an assignment, is:




wp
(x:=e,P)=P)=Px:=e



[0146] Consider the program T:


((assume e1;x=ƒ)□(assume e2;x=g)); assert P.


[0147] According to the application of traditional weakest precondition operators, as shown in Table 2, hereinabove,




wp
(T,True)=(e1=Px:=ƒ)(ex:=g)



[0148] Since the occurrences of P with x replaced by ƒ1 and ƒ2 respectively are not identical to one another, the simplification discussed hereinabove cannot be applied. However, simplification becomes possible by eliminating assignments from T using the Dynamic Single Assumption methodology described hereinabove. T is transformed into passive form by translating the assignment commands into “assume” commands according to the expressions in Table 3. The weakest precondition of the passive form of T can then be obtained by application of the bad and norm operators of Table 5, as described in the foregoing example, during which the simplified form in which P appears once is automatically generated.


[0149] Ultimately, then, the embodiment of the present invention described hereinabove eliminates assignment commands to avoid the need to include multiple instances of choice expression postconditions in the VC, thereby avoiding or reducing the repetitious evaluation of effectively identical expressions (i.e., the multiple instances of the choice expression postconditions) by the theorem prover. While the application of DSA does not vitiate all possible occurrences of duplication or near duplication of subexpressions, it relieves the situation in many cases.


[0150] Exceptions


[0151] Heretofore, the possibility that a program may terminate exceptionally has been ignored. The guarded commands, introduced in Table 1 hereinabove, are able to model exceptions, but the discussion of DSA and weakest preconditions ignored exceptions. The additional guarded commands, “raise” and “bang” (‘!’) permit exceptions to be modelled, and the VC-generation techniques described hereinabove can be extended to apply to situations where a program terminates exceptionally. Accordingly a modified version of DSA is described, hereinbelow.


[0152] An exceptional outcome leaves the variables in some state but is not the same as an outcome in which the program goes wrong or terminates normally. Exceptions are used to model premature exit conditions from portions of the code. They are used to control the behavior of the program when such a condition arises. A program written in a language such as Java can be written to explicitly handle specified exceptions and therefore the translation of such a program into guarded commands should be able to handle exceptions. Other programming constructs such as an intermediate “return” statement from a procedure (in Java, a “method”), or a “break” statement within a loop are also modeled as exceptions. Table 6 describes how the guarded commands of Table 1 behave when an exception arises
8TABLE 6Effect on Guarded Commands when an Exception ArisesGuardedCommand, SBehavior of S.x: = eAssign e to x and terminate normally. (An exception isnever raised)assume eif e = True, S terminates normally. No execution is possibleotherwise.assert eif e = True; S terminates normally. If e is False,S goes wrong.S1; S2Sequential composition. Execute S1. If S1 terminatesnormally, execute S2. If S1 goes wrong or terminatesexceptionally, S2 is ignored.S1  S2Execute either S1 or S2 choosing nondeterministically.raiseTerminate exceptionally.S1 ! S2Exception handling. Execute S1. If S1 goes wrongor terminates normally, S2 is ignored. If S1 terminatesexceptionally, execute S2.


[0153] In order to transform guarded commands into a VC that behaves properly when an exception arises, an alternate, expanded definition of the weakest precondition, wp, is utilized and written as wp (S, N, X), wherein S is a guarded command, N is a normal postcondition and X is an exceptional postcondition. In an equivalent notation, the expanded definition of the weakest precondition is expressed as wp.S.(N, X).


[0154] The weakest precondition is then the weakest predicate, P, such that:


[0155] every normally terminating execution of S that starts in a state satisfying P terminates in a state satisfying N;


[0156] every exceptionally terminating execution of S that starts in a state satisfying P, terminates in a state satisfying X; and


[0157] no execution of S starting in a state satisfying P goes wrong.


[0158] This is an extension of the teachings of Dijkstra to accommodate the possibility of exceptions. Dijkstra's only terminating condition was the normal postcondition, N. (See E. W. Dijkstra, A Discipline of Programming, Prentice-Hall (1976).)


[0159] The two guarded commands, “raise,” and “bang” (‘!’) which is the “dual” of the sequential operator “;” find special application to the modelling of exceptions.


[0160] When using the “raise” operator to model a language with multiple exceptions, an appropriate convention is to record the particular exception raised in a reserved global variable, for example xvar. Thus the raising of a particular exception E is modeled with xvar:- E; raise.


[0161] The “bang” operator (as in S1!S2) shows how to handle an exception when it is raised, say, by S1: the bang operator catches it. Here, if S1 terminates exceptionally, then S2 is executed. For example, in a string of sequentially executed statements:


[0162] ( . . . ; raise; . . . ) ! S2


[0163] The statements in parenthesis jump straight to S2 when an exception is raised. If the statements in parenthesis all execute normally, then the program finishes normally, unless S2 itself terminates exceptionally in which case the program can finish exceptionally.


[0164] Recalling the norm and bad operators, in Table 5 hereinabove, which represent, respectively, the set of states where a specified passive command could execute or terminate normally or badly, the exc operator is now introduced to enable computation of wp for passive commands that could terminate exceptionally. Accordingly, exc (S) represents the set of states from which the program, S, could terminate exceptionally.


[0165] The exc operator is used when generating verification conditions.


[0166] Table 7 extends the VC generation technique of Table 5 hereinabove to passive commands that may include exceptions.
9TABLE 7Precondition Conmands for Passive Commands when Exceptions OccurGuardedCommand, Snorm (S)exc (S)bad (S)assume eeFalseFalseassert eeFalseeS1; S2norm (S1) exc (S1) bad (S1) norm (S2)norm (S1) norm (S1) exc (S2))bad (S2))S1 S2norm (S1) exc (S1) bad (S1) norm (S2)exc (S2)bad (S2)raiseFalseTrueFalseS1 ! S2norm (S1) exc (S1) bad (S1) exc (S1) exc (S2)(exc (S1) norm (S2)bad (S2))


[0167] As with bad, the exceptional termination of “assume e” never happens and is therefore False. Furthermore, norm (raise) is False because raise never terminates normally—it automatically raises an exception. Correspondingly, because “raise” always terminates exceptionally, exc (raise) is True.


[0168] The expressions for exc and bad of the sequential composition operator S1; S2 mirror one another. They have similar forms in which bad and exc occupy corresponding positions. On the other hand, S1! S2, which is the dual of S1; S2, is such that norm and exc have changed places as well as column positions in Table 7, compared with Table 5.


[0169] It is also possible to derive forms for exceptional termination using “weakest precondition” language. As before, the job of the theorem prover when evaluating the VC of a program is to determine if there are any states for which bad of the program is True, or alternatively to determine whether bad of the program is False for all possible states of the program.


[0170] As shown hereinafter, the technique (given in Table 3 hereinabove) for transforming guarded commands to passive form can be extended to deal with commands that may include exceptions. Before listing the version of the DSA transformation that handles exceptional as well as normal commands, the following three points should be noted.


[0171] First, the DSA transformation presented hereinabove had, as one of its results, a mapping describing the state of the program variables at termination. The result of the modified DSA transformation includes two maps, one describing the state of the program variables upon normal termination and the other describing their state upon exceptional termination.


[0172] Second, in the original guarded command language the only source of control join points was the non-deterministic choice operator □. It is also important to handle additional join points, for example, in (S1; S2)!S3 where the exceptional outcomes of S1 and S2 join at the start of S3. The implication for the DSA is additional calls to the merge function.


[0173] Third, since raise has no normal outcome and several commands have no exceptional outcome, it is worthwhile as an optimization to introduce the special map “bottom”, which represents the condition that control cannot reach the relevant control point. Thus “bottom” is used to indicate infeasible code paths.


[0174] A version of DSA embodying these changes is presented in Table 8. In the Table, FN and FX are fix-up codes for, respectively, normal and exceptional termination.
10TABLE 8GuardedCommand, Sdsa (S, R)Commentx: = e(assume xn = R(e), R[with x → xn],bottom)assume e(assume R(e), R, bottom)assert e(assert R(e), R, bottom)S1; S2let (D1, R1, X1) = dsa (S1, R)X is the renaminglet (D2, R2, X2) = dsa (S2, R1)function resultinglet (FX1, FX2, X) = merge (X1, X2)from merging of (((D1 ! (FX1; raise)); (D2 ! FX2; raise))), R2, X)X1, X2.S1  S2let (D1, R1, X1) =dsa (S1, R)let (D2, R2, X2) =dsa (S2, R)let (FN1, FN2, R3) = merge (R1, R2)let (FX1, FX2, X) = merge (X1, X2) ((((D1 ; FN1) ! (FX1; raise)) ((D2 ; FN2) ! FX2; raise))), R3, X)raise(raise, bottom, R)raise neverterminatesnormallyS1 ! S2let (D1, R1, X1) = dsa (S1, R)let (D2, R2, X2) = dsa (S2, R1)let (FN1, FN2, R3) = merge (R1, R2) ((D1; FN1) ! (D2; FN2), R3, X2)


[0175] In Table 8, the last argument of the dsa for the guarded command, x :=e, is “bottom”, meaning that this command never terminates exceptionally so no mapping is required for that outcome.


[0176] Having introduced the special map “bottom” as an optimization, merge(R1, R2) can be redefined to take advantage of it, as follows:


[0177] if R1=bottom then return (assume True, assume True, R2)


[0178] else if R2=bottom then return (assume True, assume True, R1)


[0179] else proceed as in the merge procedure described in Table 4 hereinabove.


[0180] In the above, “assume True” is a no-operation (a “no-op”). Since the fix-up code is only used as the right argument to “;”, and since “S; assume True” is equivalent to “S” for any command S, these cases require no insertion of fix-up code. Such a situation arises frequently, in, for example a long sequence of statements wherein many of the statements do not raise an exception. Therefore, many of the paths through the code have a “bottom” on them and it is not necessary to generate fix-up code.


[0181] Application of Strongest Postcondition to the Weakest Precondition Computation


[0182] In the embodiment described hereinabove, the command to be checked is translated into passive form via the DSA equations of Tables 3 and 8 and then the passive form is translated into a VC via a special version of the weakest precondition computation, using norm, bad, and, if applicable, exc, as described in Tables 5 and 7. Thereby, assignments are removed, and labels are introduced for variables at control join points as well as for their initial values.


[0183] In a second embodiment, a VC is computed directly from the original command using another special version of the weakest precondition computation, in which weakest preconditions of some subcommands are computed in terms of strongest postconditions. Although the equations involved are quite different from one another, both approaches end up labelling the values of targets at control join points, and thereby eliminate or reduce duplication or near duplication of subexpressions that follow the control join point in the eventual VC. In the second embodiment it is not necessary to remove assignments.


[0184] By definition, the strongest normal postcondition, snp, of an expression, S, is such that:


[0185] snp(S, P)≡the strongest predicate, N, such that every normally terminating execution of S starting from a state that satisfies P, terminates in a state satisfying N.


[0186] That is, if S starts in a state satisfying P, and terminates normally, snp is the most that can be said about the final state.


[0187] Analogously, the strongest exceptional postcondition, sxp(S, P) is given by:


[0188] sxp(S, P)≡the strongest predicate X such that every exceptionally terminating execution of S starting in a state satisfying P terminates in a state satisfying X.


[0189] The strongest postcondition, then, of an expression is computed according to the following equations, wherein Q and P are predicates, S1 and S2 are commands, x is a variable and e is an expression.


[0190] Strongest normal postconditions:




snp
(assume Q,P)≡QP





snp
(assert Q,P)≡QP





snp
(raise, P)≡False





snp
(x:=e,P)≡(∃x′:Px:=x′z,902 x=ex:=x′)





snp
(S1;S2,P)≡snp(S2,snp(S1,P))





snp
(S1!S2,P)≡snp(S1,P)snp(S2,sxp(S1,P))





snp
(S1□S2,P)≡snp(S1,P)snp(S2,P)



[0191] Strongest exceptional postconditions:




sxp
(assume Q,P)≡False





sxp
(assert Q,P)≡False





sxp
(raise,P)





sxp
(x:=e,P)≡False





sxp
(S1;S2,P)≡sxp(S1,P)sxp(S2,snp(S1,P))





sxp
(S1□S2,P)≡sxp(S1,P)sxp(S2,P)



[0192] An example of strongest postconditions is as follows. The strongest normal postcondition of an expression, given by:




snp
(ν:=μ2,μ≧3)



[0193] becomes


∃ν′such that ν′≧3z,902 ν=(ν′)2


[0194] That is, it is desired to ascertain what values integer v could end up with when it is squared, subject to the precondition that ν is at least 3. The answer is that there is some initial value of ν, denoted ν′, such that ν′ satisfies the precondition and such that the final value of ν is the value of the expression with ′ substituted for ν. (ν′ is rather like a dummy variable, but it is important to ensure that its name does not conflict with other variable names already used.)


[0195] For the simplification of expressions obtained by applying snp to expressions that include assignments, a general rule, the “one point rule” may be used. The one-point rule says that an expression of the form:




∀y:y=x→P




[0196] or




∃y:y=xP




[0197] is equivalent to Py:=x′


[0198] The approach adopted to case-reduced VC generation in this embodiment, is to compute the weakest precondition of subexpressions in terms of the strongest exceptional and strongest normal postconditions, according to the following relationship, denoted by Equation 1:
4wp(S,N,X)=wp(S,True,True)(TT,T:(snp(ST:=TT;T:=TT,TT=T)NT:=T)(sxp(ST:=TT!(T:=TT;raise),TT=T)XT:=T))(Eq.  1)


[0199] Equation 1 caters for the possibility of exceptional termination of the program. A simpler form of Equation 1 for use with a guarded command language without exceptions is presented as Equation 2:
5wp(S,N)=wp(S,True)(TT,T:=(sp(sT:=TT;T:=TT,TT=T)NT:=T))(Eq.  2)


[0200] wherein sp is an ordinary “strongest postcondition” operator. In the discussion hereinbelow, Equation 1 is discussed.


[0201] Selective application of Equation 1 to expressions containing the choice operator can lead to the desired simplified forms of verification conditions. In Equation 1, not disclosed in any previous publication, S is a command and N and X are normal and exceptional postconditions. The variables T, TT and T′ are tuples of variables. In particular, T represents the “target variables” of command S, that is a list of all program variables that may be modified by S. (Such variables are those that occur on the left hand sides of assignment commands that are subcommands of S.) An expression such as NT:=T′means N with each variable in T replaced by the corresponding adorned variable in T′. T′ and TT represent “adornments” of T, i.e., systematic renamings of the variables in T to new names that do not occur in S, N, or X. An adornment of a variable is also referred to herein as an adorned variable or an inflection of the variable. For example if S contains assignments to variables u and v (and to no other variables), then Equation 1 becomes:




wp
(S,N,X)(∀uu, νν,u′,ν′:(snp(Su:=uu,v:=vv; u′:=uu;ν′:=νν,(uu, νν)=(u,ν))→Nu:=u′,v:=v′)(sxp(Su:=uu, v:=vv!(u′=uu;ν′:=νν;raise), (uu, νν)=(u,ν))→Xu:=u′,v:=v′))



[0202] wherein uu, νν, u′, and ν′ are variable names not already occurring in S, N, or X.


[0203] In both the present embodiment and in the embodiment described hereinabove in which the DSA is employed, a given program variable may have several adornments, corresponding to the labels introduced for the values taken on by the given program variable at various points in the program.


[0204] The approach according to the present embodiment is outlined in FIG. 5. The computer program 118 is optionally converted to guarded command form, step 502, and the strongest postcondition representation of the weakest precondition is computed from the guarded command form, step 504, thereby generating a VC 124. According to this approach, it is not necessary to transform the guarded commands to passive form and there is no need to remove assignments.


[0205] According to this embodiment, labels are introduced for variables by selectively applying Eq. 1 to compute weakest preconditions instead of using the formulae of Table 2 for a traditional weakest precondition operator. Specifically, if Eq. 1 is used for subexpressions of the form (S1□S2) and if the prior art method is used for all other subexpressions, then this embodiment of the present invention effectively introduces the label T′ for the value at the control join point after (S1□S2) for each target T.


[0206] The reason that equation 1 is promising for case-reduced VC generation is that it separates the occurrences of S from the occurrences of N and X, placing them on opposite sides of implications (→symbols). If S contains choices, then antecedents of the implications (those expressions on the left hand side of the →symbol) will end up containing disjunctions, but the postconditions will not be duplicated for each arm of those disjunctions.


[0207] One convenient approach to simplifying an equation such as Equation 1 is to use the following relationship:


(∀x:x=e→P)≡Px:=e


[0208] Thus, in equation 1, application of this relationship permits the factoring out of TT.


[0209] An acceptable strategy, therefore, for generating a verification condition is to use equation 1 to expand the wp of choices and to use the ordinary wp equations (Table 2) for all other operators (and also for the expression wp( . . . , True, True) on the right hand side of equation 1).


[0210] Thus, the method described herein, by which weakest preconditions are written as expressions that comprise strongest postconditions, has succeeded in avoiding the duplication (or approximate duplication) of postconditions that would result in the methods of the prior art that utilize only weakest preconditions.


[0211] A program whose weakest precondition has been computed in a manner utilizing strongest postconditions, as described hereinabove, is passed to a theorem prover to test its validity as shown in FIG. 1. Savings of resources are consequently gained by avoiding the duplication of expressions following control join points.


[0212] As would be understood by one of skill in the art, the method of transforming a computer program in guarded command form to a weakest precondition in which subexpressions separated by choice operators are expressed as strongest postconditions, is applicable to computer programs written in other guarded command forms as well as other programming languages that are not first converted to guarded command form.



EXAMPLES


Example 1


Embodiment employing strongest postconditions

[0213] As an example of this strategy, suppose it is desired to compute the following weakest precondition expression of a choice expression.




wp
((x:=5□x:=x+1);K,N,X)



[0214] wherein K is a potentially large command. By applying the ordinary weakest precondition calculation, using the rule for semi-colon, as shown hereinabove in Table 2, the value is:




wp
(x:=5□x:=x+1),wp(K,N,X),X)



[0215] Applying the strongest postcondition expression, given above in Eq. 1, wherein S is represented by the choice expression in parenthesis, N is represented by the expression wp(K,N,X) and X is simply X, the only target of the command S is x. To apply Eq. 1, the adorned variables xx and x′ are introduced. Eq. 1 then gives:
6wp(x:=5x:=x+1,True,True)(xx,x:(snp((x:=5xx:=xx+1);x:=xx,xx=x)wp(K,N,X)x:=x)(sxp((x:=5xx:=xx+1);x:=xx,xx=x)Xx:=x))


[0216] Applying the ordinary weakest precondition formula (Table 2) and simple predicate calculus, the expression




wp
(x:=5□x:=x+1,True, True)



[0217] simplifies to True. Also, since there are no occurrences of “raise” in the command (xx:5 □xx :=xx+1); x′:=xx, the application of sxp in the antecedent of the second implication reduces to False, and the implication itself reduces to True. Thus, the entire formula reduces to


(∀xx, x′:snp(xx:=5□xx:=xx+1);x′:=xx, xx=x)→wp(K,N,X)x:=x′)


[0218] Applying the rules for snp for assignment, the subexpression




snp
((xx:=5□xx:=xx+1);x′:=xx,xx=x)



[0219] is simplified to




x′xx

(xx=5xx=x+1)



[0220] and therefore the entire formula becomes, on application of the “one-point” rule,


(∀x′:(x′=5x′=x+1)→wp(K,N,X)x:=x′)


[0221] which has effectively given the label x′ to the value of the program variable x at the control join point following the command (x :=5 □x:=x+1). Although wp(K,N,X)x:=x′may be large, it is not duplicated for each arm of the nondeterministic choice. There is only one copy of this expression. Instead of substituting both 5 and x+1 separately into wp(K, N, X), it is x′ that is substituted. This result is equivalent to the result of merging variables from the DSA used in the first preferred embodiment described above.


[0222] Note that if wp(K,N,X)x:=x′is valid for all values of x′, then a theorem prover might prove the preceding verification condition without separately analyzing the case x′=5 and the case x′=x+1.


[0223] By contrast if the ordinary wp equations are used to compute the weakest precondition of S, i.e.,




wp
(x:=5□x:=x+1);K,N,X)



[0224] the expression




wp
(K,N,X)x:=5wp(K,N,X)x:=x+1



[0225] is obtained, in which wp(K,N,X) is duplicated in two nearly, but not exactly, identical copies.



Example 2


Embodiment Employing Conversion to DSA and Comparison with Traditional Weakest Precondition Computation.

[0226] A method according to the present invention has been implemented, as part of the Extended Static Checker for Java (“ESC/Java”) project. ESC/Java is a tool for finding, by static analysis, common defects in Java programs that are not normally detected until run-time, if ever (see, K. R. M. Leino, J. B. Saxe and R. Stata, “Checking Java programs via guarded commands.”, in Formal Techniques for Java Programs, Technical Report 251, Ed. B. Jacobs, et al., Fernuniversität Hagen, 1999; and K. R. M. Leino, J. B. Saxe and R. Stata, “ESC/Java user's manual,” Compaq Systems Research Center Technical Note 2000-002, October 2000, available from http://research.compaq.com/SRC/publications, incorporated herein by reference). The executable object code of ESC/Java is publicly available for research and educational purposes (see Extended Static Checking web-page, Compaq Systems Research Center, http://research.compaq.com/SRC/esc). It takes as input a Java program, possibly including user annotations, and produces as output a list of possible defects in the program. The annotations in the input program describe program properties such as method preconditions, method postconditions, and object invariants. These annotations allow ESC/Java to catch software defects using a modular, or method-local, analysis. During this analysis, ESC/Java verifies that the annotations are consistent with the program, and it also uses the annotations to verify that each primitive operation (such as a dereference operation, an array access, or a type cast) will not raise a run-time exception (as might happen, for example, if a dereferenced pointer is null or if an array index is out-of-bounds). To perform this analysis, ESC/Java first translates each method and its correctness property into an intermediate representation, the guarded command form, then translates the intermediate representation into a verification condition, and then uses an automatic decision procedure to determine the validity of the verification condition.


[0227] In the implementation of the present invention used in this Example, the program to be checked is converted into a passive guarded command form before the VC is generated. Thus duplicated subexpressions in the VC are exact copies (and not substitution instances) of one another. This implementation uses a cutoff K, and only names a duplicated subexpression if the subexpression is larger than K (where the size of a subexpression is the number of nodes in its representation). For any finite value of this cutoff, the size of the resulting VC is linear in the size of the passive statement, and hence at most quadratic in the size of the source program. The validity of the VC is checked with an automatic decision procedure, Simplify (see for example, Nelson, G., “Techniques for program verification,” Technical Report CSL-81-10, Xerox Palo Alto Research Center, 1981).


[0228] This Example presents experimental results comparing five VC-generation options: the standard wp-based translation, and the two-stage translation based on the embodiment described hereinabove with four different values (0, 10, 30, ∞) for the cutoff size K above which to introduce names for duplicated outcome predicates.


[0229] These experiments were performed on a 667 MHz ES 40 Alpha workstation containing 4 Gb of memory running Tru 64 UNIX. ESC/Java is written in Java, and was run on the Compaq Fast VM. The Simplify theorem prover is written in Modula-3, and runs as a separate process. The two processes communicate via Unix pipes.


[0230] The benchmark used for these experiments is ESC/Java's front-end, which has been annotated with appropriate specifications. This front-end consists of 2292 routines (methods and constructors) totaling over 20,000 lines of code.


[0231] The routines in the benchmark have been divided into three categories according to their worst performance under any of the five options. The first category contains the ten “hardest” routines. The verification of each of these routines either exhausted a 1 Gb heap or required more than five minutes under at least one of the options. The second category of routines contains the 17 routines that required at least 100 seconds under some option, but no more than 300 seconds under any option. The third category contains the 2184 routines in the benchmark that were successfully verified in under 100 seconds regardless of the VC generation option chosen. The remaining 81 routines in the front end are routines for which ESC/Java performs no VC generation (for example, methods declared in interfaces); these routines are not included in the benchmark.


[0232] The performance of the five VC generation options on the routines in the benchmark are shown in Table 9 hereinbelow, with results for ten “hardest” routines given individually, and summed results for the tow categories.
11TABLE 9wp translationPresent invention using DSARoutine nameASTGCVCtimePGC%KVC%time%BinaryExpr.4201805too big154586057581.4postCheck1048400.63047000.655131.0LiteralExpr.4231417too big1608113057351.5PostCheck1050231.33051411.357651.3finishFloating6533464too big792722901313469.5PointLiteral10106168.9301058310.72041673.9ScanCharOr8123896too big2390461403350249.8String102985118.1302992417.15135716.3scanNumber10304170too big1238329701908034.6101533423.0301520414.62509310.7scanPunctuation50933264751446350.010457314015525026.071013748012.943013816012.031797206.82parseNew794705210278077.02717038503818637530.1688Expression103611635432.0561303574935419.05448365981339.2440checkExpr3945174482798672>2000.0354912030618132750.4<3010537792401.5<1630518742347.8<14906463169.4<7checkStmt2883157461041210309.0434172760679157457.514810613826251.18130577266145.44710529710151.949visitMethodDecl47943312022351381.55270122012423110.23101143018.72301158118.721254418.82sum of 17 other14735124511117826171574.5312822251048952941777.8113routines needing1046102741048.067>100 seconds in304500904900.757some rum9552768676.843sum of remaining1481681851166116683711613.4237997312907471786642473.11532184 routines107095724611662.8103306998342601508.5937530778651564.197


[0233] The columns of Table 9 identify:


[0234] the routine name (or summed category);


[0235] the size of the abstract syntax tree for the routine (number of nodes);


[0236] the size of the guarded command (number of nodes);


[0237] the size of the VC under the wp translation (number of nodes);


[0238] the time required to check this routine under the wp translation (seconds);


[0239] the size of the passive version of the guarded command (number of nodes and percentage of original guarded command);


[0240] the cutoff K for naming duplicated outcome predicates (number of nodes);


[0241] the size of the VC under the two-stage translation (number of nodes and percentage of the wp VC); and


[0242] the time required to verify this routine under the two-stage translation (seconds and percentage of time using wp).


[0243] The times in Table 9 include the time required to translate the Java abstract syntax tree representation into a guarded command, the time required to translate the guarded command into a VC (including translation into the intermediate passive representation, if necessary), and time required to check the VC. For the summed categories, the entries in the percentage columns tell how big one summed quantity is as a percentage of another.


[0244] The results indicate that all the VC generation algorithms work well on the simpler routines in the third category. The two-stage translation produces smaller VC's that are slightly easier to prove for K=30 or K=∞. Choosing K=0 results in the theorem prover performing significant extra work to process the resulting indirections.


[0245] The wp translation has difficulty scaling to the larger or more complex routines; for five of the routines in this benchmark the wp translation exhausted a 1 Gb heap limit.


[0246] The two-stage translation involving passive guarded commands performs much better on these complex routines; the resulting VC's are significantly smaller, and can easily fit in the heap. Again, choosing K=0 results in larger proof times. For K>0, the two-stage translation yields VC's that require significantly less time to prove (sometimes by an order of magnitude) than the VC's produced by the wp translation.


[0247] The routine “parseNewExpression” requires significantly more time to verify under the two-stage translation than under wp. In general, the time required by Simplify to verify a formula is highly dependent on the order in which Simplify chooses to perform various case-splits, and the case-split order is determined by a variety of heuristics. For this routine, we suspect that these heuristics are misled in some manner by the VC generated by the two-stage translation.


[0248] Overall, the two-stage translation via passive guarded commands performs significantly better than the direct wp translation. It enables ESC/Java to check all of the routines in this benchmark due to the smaller space requirements, and is significantly faster. Excluding the six routines that could not be checked using the wp translation, checking the entire benchmark using wp required 4305 seconds, whereas using the two-stage translation requires only 2994 seconds (for K=30), or 2748 seconds (for K=0).


[0249] All references cited herein are incorporated herein by reference in their entirety and for all purposes to the same extent as if each individual publication or patent or patent application was specifically and individually indicated to be incorporated by reference in its entirety for all purposes.


[0250] The present invention can be implemented as a computer program product, or a computer readable medium, that includes a computer program mechanism embedded in a computer readable storage medium. For instance, the computer program product could contain the program modules shown in FIG. 1. These program modules may be stored on a CD-ROM, magnetic disk storage product, or any other computer readable data or program storage product. The software modules in the computer program product may also be distributed electronically, via the Internet or otherwise, by transmission of a computer data signal (in which the software modules are embedded) on a carrier wave.


[0251] While the present invention has been described with reference to a few specific embodiments, the description is illustrative of the invention and is not to be construed as limiting the invention. Various modifications may occur to those skilled in the art without departing from the true spirit and scope of the invention as defined by the appended claims.


Claims
  • 1. A method of generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point, the method comprising: when the program statements in the computer program include at least one assignment statement, transforming said at least one assignment statement into an assume command, wherein said transforming includes mapping a variable that is assigned a value by said at least one assignment statement into an expression denoting a value of the variable after said at least one assignment statement; and applying at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.
  • 2. The method of claim 1, additionally comprising: when the program statements in the computer program include at least one assignment statement that assigns a simple expression to a variable, transforming, when said at least one assignment statement is present, said at least one assignment statement into an assume command, wherein said transforming also produces a mapping that maps said variable to the result of applying to said simple expression a mapping corresponding to a program state before said assignment statement.
  • 3. The method of claim 1 wherein said at least one precondition operator comprises at least one instance of a norm operator.
  • 4. The method of claim 1 wherein said at least one precondition operator comprises at least one instance of a bad operator.
  • 5. The method of claim 1 wherein said at least one precondition operator comprises at least one instance of an exc operator.
  • 6. The method of claim I additionally comprising, prior to said transforming, converting said computer program to an intermediate form.
  • 7. The method of claim 6 wherein said intermediate form is a guarded command form.
  • 8. The method of claim 7 wherein the at least one pair of conditional program execution paths is converted into a first group of guarded commands coupled by a choice operator to a second group of guarded commands and wherein the verification condition includes: a logical OR of a first condition corresponding to said first group of guarded commands and a second condition corresponding to said second group of guarded commands; connected by an implication to a single instance of a post-condition, corresponding to said expression following the control join point, that must always be true after execution of either the first or the second groups of guarded commands.
  • 9. The method of claim 8, wherein the variable mapping resulting from said at least one assignment statement is produced by a transformation function, the transformation function having as one of its outputs a modified variable mapping for application to a subsequent statement of the computer program, wherein the modified mapping is based on variable mappings produced by transformation functions on at least one earlier statement of the computer program.
  • 10. The method of claim 9, wherein the variable mapping resulting from said at least one assignment statement maps the variable assigned by that statement to a new variable introduced by the transformation function.
  • 11. The method of claim 9, wherein the transformation function, when applied to the first and second groups of guarded commands coupled by the choice operator, generates a set of fix up code for said first group and for said second group of guarded commands coupled by the choice operator, wherein each of said sets of fix up code collectively synchronize the new variables used in said first and second groups of guarded commands.
  • 12. The method of claim 11, wherein the modified mapping produced by the transformation function, when applied to the pair of groups of guarded commands coupled by the choice operator, is based on variable mappings produced by the transformation function when applied to both the first and second groups of guarded commands.
  • 13. The method of claim 1 additionally comprising: passing the verification condition to a theorem prover and determining whether or not the verification condition is valid.
  • 14. The method of claim 13 wherein said theorem prover generates at least one counter-example, if the truth of the verification condition cannot be proved.
  • 15. The method of claim 14 additionally comprising: analyzing said at least one counter-example and producing an error message.
  • 16. A computer readable medium for use in conjunction with a computer system, the computer readable medium comprising a computer readable storage medium and a computer program mechanism embedded therein, the computer program mechanism comprising: instructions for generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point; instructions for determining when the program statements in the computer program include at least one assignment statement, and, instructions for transforming said at least one assignment statement into an assume command, wherein said transforming includes mapping a variable that is assigned a value by said at least one assignment statement into an expression denoting a value of the variable after said at least one assignment statement; and instructions for applying at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.
  • 17. The computer readable medium of claim 16, additionally comprising: instructions for determining when the program statements in the computer program include at least one assignment statement that assigns a variable to a simple expression, and instructions for transforming, when said at least one assignment statement is present, said at least one assignment statement into an assume command, wherein said transforming also produces a mapping that maps said variable to the result of applying to said simple expression a mapping corresponding to a program state before said assignment statement.
  • 18. The computer readable medium of claim 16 additionally comprising instructions for expressing said precondition operator in a form containing at least one operator selected from the group consisting of bad, norm and exc.
  • 19. The computer readable medium of claim 16 additionally comprising instructions for converting said computer program into an intermediate form.
  • 20. The computer readable medium of claim 19 additionally comprising instructions for converting said computer program into a guarded command form.
  • 21. The computer readable medium of claim 19 additionally comprising instructions for passing the verification condition to a theorem prover and determining whether or not the verification condition is valid.
  • 22. An apparatus for generating a verification condition for a computer program that comprises a collection of program statements and that contains a pair of conditional program execution paths preceding a control join point and an expression following the control join point, the apparatus comprising: a memory containing the computer program, an operating system and at least one processor configured to execute mathematical operations on the computer program, wherein said computer processor: when the program statements in the computer program include at least one assignment statement, transforms said at least one assignment statement into an assume command, and includes mapping a variable that is assigned a value by said at least one assignment statement into an expression denoting a value of the variable after said at least one assignment statement;; and applies at least one precondition operator to the computer program to produce a verification condition which includes a single instance of a subexpression derived from the expression following the control join point, wherein, while applying the at least one precondition operator to the computer program, a label is given to a value, at the control join point, of a variable that is modified on at least one of the conditional program execution paths.
  • 23. The apparatus of claim 22, wherein said computer processor additionally: determines whether the program statements in the computer program include at least one assignment statement that assigns a variable to a simple expression, and transforms, when said at least one assignment statement is present, said at least one assignment statement into an assume command, and also produces a mapping that maps said variable to the result of applying to said simple expression a mapping corresponding to a program state before said assignment statement.
  • 24. The apparatus of claim 22, wherein said computer processor additionally expresses said precondition operator in a form containing at least one operator selected from the group consisting of bad, norm and exc.
  • 25. The apparatus of claim 22, wherein said computer processor additionally converts said computer program into an intermediate form.
  • 26. The apparatus of claim 22, wherein said computer processor additionally converts said computer program into a guarded command form.
  • 27. The apparatus of claim 22, wherein said computer processor additionally passes the verification condition to a theorem prover and determines whether or not the verification condition is valid.
Parent Case Info

[0001] This application claims priority to U.S. provisional patent application no. 60/218,305, filed Jul. 14, 2000, entitled “Case-reduced Verification Condition Generation System And Method,” which is hereby incorporated by reference in its entirety.

Provisional Applications (1)
Number Date Country
60218305 Jul 2000 US