Skip to content

Commit 0ab5fdb

Browse files
author
davidcok
committed
Corrected some show examples
1 parent c948e0b commit 0ab5fdb

File tree

10 files changed

+26
-43
lines changed

10 files changed

+26
-43
lines changed

tutorial/Debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ First note that there are different kinds of problems that can lead to a failed
1515
* The prover is missing some vital information that prevents it from making the necessary proof steps. For this situation you can add lemmas or other assumptions [here](Lemmas).
1616

1717
It is worth restating a few points:
18-
* Just because a specification and implementation agree (`openjml` verifies) does not mean that they are correct. They could still be both wrong in the same way compared to what is really desired of the program. Careful human review and understanding of requirements cannot replace either traditional testing or verification, though both of those are necessary in giving confidence in a program's correctness.
18+
* Just because a specification and implementation agree (`openjml` verifies) does not mean that they are correct. They could still be both wrong in the same way compared to what is really desired of the program. Careful human review and understanding of requirements cannot be replaced by either traditional testing or verification, though both of those are necessary in giving confidence in a program's correctness.
1919
* The techniques presented here are largely specific to `openjml`, at least in the details. Each tool and prover has different ways in which it has difficulties, though some general ideas and techniques may translate from one situation to another.
2020
* Start with simple problems, understand them well, and then move on to complex situations.
2121

tutorial/InspectingCounterexamples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ which produces
2525
{% include_relative T_show2.out %}
2626
```
2727
The values shown are the result of a non-deterministic search; they might very well be different values on subsequent runs.
28-
Nevertheless, for the values of `a`, `b`, `c`, and `d` shown here, the result is equal to `b` or `d`, instead of, for these values, the value of `a`.
28+
Nevertheless, for the values of `a`, `b`, `c`, and `d` shown here, the result is equal to `b`, instead of, for these values, the value of `d`.
2929
Some code inspection shows that there is a cut&paste error on line 9.
3030

3131
The counterexample is always in terms of concrete values --- that is how the underlying solvers work. One would much rather have a symbolic condition that represents the cases that fail, but that is beyond the current state of the art. At present, the best one can do is do some human induction based on a few examples to understand when a program or its specification fails.

tutorial/MethodSelection.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ First, remember that the `OpenJML` command-line lists options (and their values)
1111
just like the Java compiler (`javac`) does. Usually though you have a set of interdependent files
1212
together in one folder. So `OpenJML` allows you to put a folder path on the command-line,
1313
after the `--dir` option, as in `openjml --esc --dir ~/myfiles`. You can use the `--dirs` option
14-
to list several files: `openjml --esc --dirs ~/myfiles1 ~/myfiles2 ~/myfiles3`. Listing a
14+
to list several folders: `openjml --esc --dirs ~/myfiles1 ~/myfiles2 ~/myfiles3`. Listing a
1515
folder name includes subfolders recursively by default. If you don't want recursion, then list
1616
the files using a wildcard as in `~/myfiles/*.java`. The `--dirs` option interprets all
1717
successive command-line arguments as folder paths, up to an argument that begins with a hyphen (`-`).
1818

19+
## Specific files
20+
21+
If you are only interested in proofs of methods within a given file, then list just that file on
22+
the command-line and make sure that any other needed file is present on the sourcepath or the classpath.
23+
1924
## Specific methods
2025

2126
To limit proof attempts to specific methods, use the `--method` and `--exclude` options.
@@ -30,4 +35,4 @@ a prepended fully-qualified class name or an appended argument signature, as in
3035
`--method="mypackage.MyClass.myMethod"` or `--method="myMethod(int,java.lang.String)"`. Note that
3136
when the expanded name includes characters interpreted by the shell, such as periods and
3237
parentheses, quotes around the method name are needed.
33-
* More complicated strings that include wildcards for matching are described in the Ope JML Users' Guide.
38+
* More complicated strings that include wildcards for matching are described in the OpenJML Users' Guide.

tutorial/T_show2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int max(int a, int b, int c, int d) {
66
int maxSoFar = a;
77
if (b > maxSoFar) maxSoFar = b;
88
if (c > maxSoFar) maxSoFar = c;
9-
if (d > maxSoFar) maxSoFar = b;
9+
if (d > maxSoFar) maxSoFar = c;
1010
//@ show a, b, c, d, maxSoFar;
1111
return maxSoFar;
1212
}

tutorial/T_show2.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
T_show2.java:10: verify: Show statement expression a has value ( - 2147480361 )
1+
T_show2.java:10: verify: Show statement expression a has value ( - 282 )
22
//@ show a, b, c, d, maxSoFar;
33
^
4-
T_show2.java:10: verify: Show statement expression b has value ( - 2147480362 )
4+
T_show2.java:10: verify: Show statement expression b has value ( - 281 )
55
//@ show a, b, c, d, maxSoFar;
66
^
7-
T_show2.java:10: verify: Show statement expression c has value ( - 2147477363 )
7+
T_show2.java:10: verify: Show statement expression c has value 1
88
//@ show a, b, c, d, maxSoFar;
99
^
10-
T_show2.java:10: verify: Show statement expression d has value ( - 2147477362 )
10+
T_show2.java:10: verify: Show statement expression d has value 2
1111
//@ show a, b, c, d, maxSoFar;
1212
^
13-
T_show2.java:10: verify: Show statement expression maxSoFar has value ( - 2147480362 )
13+
T_show2.java:10: verify: Show statement expression maxSoFar has value 1
1414
//@ show a, b, c, d, maxSoFar;
1515
^
1616
T_show2.java:11: verify: The prover cannot establish an assertion (Postcondition: T_show2.java:3:) in method max

tutorial/T_show4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// openjml --esc T_show4.java
1+
// ## openjml --esc T_show4.java
22
public class T_show4 {
33
//@ public invariant data.length >= 10;
44
//@ spec_public

tutorial/T_show6.out

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,27 @@ TRACE of T_show1.max(int,int,int,int)
99
T_show1.java:1: requires true;
1010
VALUE: true === true
1111
T_show1.java:6: int maxSoFar = a
12-
VALUE: a === ( - 8946 )
13-
VALUE: maxSoFar === ( - 8946 )
12+
VALUE: maxSoFar === ( - 536 )
1413
T_show1.java:7: if (b > maxSoFar) ...
15-
VALUE: b === ( - 8945 )
16-
VALUE: maxSoFar === ( - 8946 )
1714
VALUE: b > maxSoFar === true
1815
VALUE: (b > maxSoFar) === true
1916
Condition = true
2017
T_show1.java:7: maxSoFar = b
21-
VALUE: b === ( - 8945 )
22-
VALUE: maxSoFar = b === ( - 8945 )
18+
VALUE: maxSoFar = b === ( - 535 )
2319
T_show1.java:8: if (c > maxSoFar) ...
24-
VALUE: c === 1
25-
VALUE: maxSoFar === ( - 8945 )
2620
VALUE: c > maxSoFar === true
2721
VALUE: (c > maxSoFar) === true
2822
Condition = true
2923
T_show1.java:8: maxSoFar = c
30-
VALUE: c === 1
3124
VALUE: maxSoFar = c === 1
3225
T_show1.java:9: if (d > maxSoFar) ...
33-
VALUE: d === 2
34-
VALUE: maxSoFar === 1
3526
VALUE: d > maxSoFar === true
3627
VALUE: (d > maxSoFar) === true
3728
Condition = true
3829
T_show1.java:9: maxSoFar = c
39-
VALUE: c === 1
4030
VALUE: maxSoFar = c === 1
4131
T_show1.java:10: return maxSoFar;
42-
VALUE: maxSoFar === 1
4332
T_show1.java:3: ensures \result >= a && \result >= b && \result >= c && \result >= d;
44-
VALUE: \result === 1
45-
VALUE: a === ( - 8946 )
46-
VALUE: \result >= a === true
47-
VALUE: \result === 1
48-
VALUE: b === ( - 8945 )
49-
VALUE: \result >= b === true
50-
VALUE: \result >= a && \result >= b === true
51-
VALUE: \result === 1
52-
VALUE: c === 1
53-
VALUE: \result >= c === true
54-
VALUE: \result >= a && \result >= b && \result >= c === true
55-
VALUE: \result === 1
56-
VALUE: d === 2
57-
VALUE: \result >= d === false
5833
T_show1.java:10: Invalid assertion (Postcondition)
5934
: T_show1.java:3: Associated location
6035

tutorial/TimeAndErrorLimits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ find any more failures.
2222
However, the last step -- where no more assertion violations are found --
2323
can be time-consuming. So sometimes it is useful to stop after just one verification failure (or a small fixed number) is reported.
2424
The number of errors reported for each method can be limited using the
25-
`--escMaxWarnings` option. By default it is set to a very large number,
25+
`--esc-max-warnings` option. By default it is set to a very large number,
2626
but it is a reasonable working style to set it to 1.
2727

2828
Note that there will be no proof attempts for any methods in a file if there

tutorial/type-bigint.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ type `\bigint` and `i` a value of a Java numeric type.
2020
* `j / k` is mathematical integer division (truncation toward zero); `k` must not be 0; `j/k` is negative or zero if `j` and `k` have different signs and is positive or zero if `j` and `k` have the same sign
2121
* `j % k` is mathematical integer modulo, but is similar to Java's `%` operation: `k` may not be zero, `j%k` has the same sign as `j` and is independent of the sign of `k`, and for `k != 0`, `(j/k)*k + (j%k) == j`
2222
* `<` and `<=` and `>` and `>=` have their expected meanings with the result type being boolean
23-
* casts are allowed to and from other numeric types, such as `(\bigint)i` or `(int)j`. When casting from `\bigint` to a bounded type, a range check is performed, depending on the [arithmetic mode](ArithmeticModes).
23+
* implicit conversions are allowed from Java integral types to `\bigint`
24+
* casts are allowed to and from other numeric types, such as `(\bigint)i` or `(int)j`. When casting from `\bigint` to a bounded type, a range check is performed, depending on the [arithmetic mode](ArithmeticModes); when casting from `\real`, `double`, or `float`, the value is truncated toward zero.
25+
* implicit conversion of `java.math.BigInteger` to `\bigint` is permitted; use `i.bigValue()` to convert a `\bigint` value `i` to `java.math.BigInteger`
2426

2527
For example, one can write the following:
2628
```

tutorial/type-real.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ type `\real`.
1717
* `j - k` is mathematical real subtraction
1818
* `j * k` is mathematical real multiplication
1919
* `j / k` is mathematical real division (not rounded to an integer); `k` must not be 0
20-
* `j % k` is mathematical real modulo, but is similar to Java's `%` operation: `k` may not be zero, `j%k` has the same sign as `j` and is independent of the sign of `k`, and for `k != 0`, `(j/k)*k + (j%k) == j`.
20+
* `j % k` is mathematical real modulo, but is similar to Java's `%` operation: `k` may not be zero, `j%k` has the same sign as `j` and is independent of the sign of `k`, and for `k != 0`, `((\bigint)(j/k))*k + (j%k) == j`.
2121
* `<` and `<=` and `>` and `>=` have their expected meanings with the result type being boolean
22-
* casts are allowed to and from other numeric types, such as `(\bigint)j`, which truncates towards zero.
22+
* implicit conversions are allowed from `double`, `real`, `\bigint` and Java integral types
23+
* explicit casts are allowed to and from other numeric types, such as `(\bigint)j`, which truncates towards zero.
2324

2425
```diff
2526
! Caveat: Though real numbers are supported in OpenJML, the connection between real numbers and floating point numbers is incomplete and in some cases (such as handling NaN and infinite fp numbers) wrong
@@ -32,7 +33,7 @@ type `\real`.
3233
//@ set rr = r * 2;
3334
```
3435

35-
As for `\bigint`, many of the methods in `java.lang.Math` have been specified for `real` values:
36+
Just like for `\bigint`, many of the methods in `java.lang.Math` have been specified for `real` values:
3637
```
3738
{% include_relative Real.java %}
3839
```

0 commit comments

Comments
 (0)