Skip to content

Commit 3579fe9

Browse files
committed
Merge branch 'main' into fabian
2 parents 434c932 + b8b7aaa commit 3579fe9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+768
-855
lines changed

.github/workflows/format.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: 'Check formatting'
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'main'
8+
jobs:
9+
check-format:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- run: bash scripts/prep.sh
14+
- run: DAFNY=dafny/dafny bash scripts/checkformat.sh

Guidelines.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
Following are guidelines that one should follow unless there is a good technical reason not to.
1+
The Dafny 386 guidelines.
2+
3+
By default, you should adhere the following guidelines to structure your development.
4+
It may happen that not following the guidelines would lead to a better solution: when that is
5+
the case, you should present your case with the rest of the developers.
26

37
* Languages features to avoid:
48
* import opened.
@@ -8,10 +12,13 @@ Following are guidelines that one should follow unless there is a good technical
812

913
* Even if a function is not meant to be part of the compiled code, don't use ghost unless necessary.
1014
* Do not attach postconditions to functions. Instead, prove the postcondition as a separate lemma.
15+
* Use function preconditions only when the function is genuinely partial and that making total would requires the use of the error monad or a dummy value.
1116
* Make functions opaque.
1217
* Name preconditions of lemmas and reveal them only when necessary.
1318
* Be mindful of resource usage and refine your proof until it is less than 1M.
14-
* In particular, avoid `{:vcs_split_on_every_assert}` as this can increase the verification time a lot.
19+
* Do not use internal prover directives such as `{:vcs_split_on_every_assert}` or `{:trigger}`.
20+
* A method should have a unique postcondition that establishes its equivalence with a functional model.
21+
* Local variables must be typed explicitly.
1522
* Keep proofs short and modular, as for a pencil and paper proof.
1623
* Prefer structured proofs in natural deduction rathen than sequences of assertions.
1724
* Unless it is logically or mathematically necessary:
@@ -143,6 +150,7 @@ lemma Foo2()
143150
</td>
144151
</tr>
145152
</table>
153+
146154
* Establish preconditions of assertion in a by clause. For example, consider lemma Foo() requires A ensures B
147155
<table>
148156
<tr>

audit.log

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,22 @@
22
Auditing ./src/Dafny-VMC.dfy
33

44
Auditing ./src/Distributions/Base/Interface.dfy
5-
Coin: Definition has `assume {:axiom}` statement in body.
5+
Coin: Definition has `assume {:axiom}` statement in body.
66

77
Auditing ./src/Distributions/Base/Model.dfy
88

99
Auditing ./src/Distributions/Bernoulli/Correctness.dfy
10-
ProbBernoulliIsIndepFn: Declaration has explicit `{:axiom}` attribute.
11-
BernoulliCorrectness: Declaration has explicit `{:axiom}` attribute.
1210

1311
Auditing ./src/Distributions/Bernoulli/Implementation.dfy
1412

1513
Auditing ./src/Distributions/Bernoulli/Interface.dfy
16-
Bernoulli: Compiled declaration has no body and has an ensures clause.
1714

1815
Auditing ./src/Distributions/Bernoulli/Model.dfy
19-
ProbBernoulli: Definition has `assume {:axiom}` statement in body.
2016

2117
Auditing ./src/Distributions/BernoulliExpNeg/Implementation.dfy
2218

2319
Auditing ./src/Distributions/BernoulliExpNeg/Interface.dfy
2420

25-
Auditing ./src/Distributions/BernoulliRational/Correctness.dfy
26-
/!\ No terms found to trigger on.
27-
/!\ No terms found to trigger on.
28-
29-
Auditing ./src/Distributions/BernoulliRational/Implementation.dfy
30-
31-
Auditing ./src/Distributions/BernoulliRational/Interface.dfy
32-
BernoulliRational: Compiled declaration has no body and has an ensures clause.
33-
34-
Auditing ./src/Distributions/BernoulliRational/Model.dfy
35-
3621
Auditing ./src/Distributions/DiscreteGaussian/Implementation.dfy
3722

3823
Auditing ./src/Distributions/DiscreteGaussian/Interface.dfy
@@ -41,75 +26,64 @@ Auditing ./src/Distributions/DiscreteLaplace/Implementation.dfy
4126

4227
Auditing ./src/Distributions/DiscreteLaplace/Interface.dfy
4328

44-
Auditing ./src/Distributions/Geometric/Correctness.dfy
45-
ProbGeometricIsIndepFn: Declaration has explicit `{:axiom}` attribute.
46-
ProbGeometricCorrectness: Declaration has explicit `{:axiom}` attribute.
47-
48-
Auditing ./src/Distributions/Geometric/Implementation.dfy
49-
50-
Auditing ./src/Distributions/Geometric/Interface.dfy
51-
Geometric: Compiled declaration has no body and has an ensures clause.
52-
53-
Auditing ./src/Distributions/Geometric/Model.dfy
54-
ProbWhileGeometricTerminates: Declaration has explicit `{:axiom}` attribute.
55-
5629
Auditing ./src/Distributions/Uniform/Correctness.dfy
5730
/!\ No terms found to trigger on.
5831
/!\ No terms found to trigger on.
59-
UniformCorrectnessCorrectMeasureCaseNGreaterOne: Definition has `assume {:axiom}` statement in body.
60-
ProbUniformIsIndepFn: Declaration has explicit `{:axiom}` attribute.
32+
UniformCorrectnessCorrectMeasureCaseNGreaterOne: Definition has `assume {:axiom}` statement in body.
33+
ProbUniformIsIndepFn: Declaration has explicit `{:axiom}` attribute.
6134

6235
Auditing ./src/Distributions/Uniform/Implementation.dfy
63-
Uniform: Definition has `assume {:axiom}` statement in body.
64-
Uniform: Definition has `assume {:axiom}` statement in body.
36+
Uniform: Definition has `assume {:axiom}` statement in body.
37+
Uniform: Definition has `assume {:axiom}` statement in body.
6538

6639
Auditing ./src/Distributions/Uniform/Interface.dfy
67-
Uniform: Compiled declaration has no body and has an ensures clause.
6840

6941
Auditing ./src/Distributions/Uniform/Model.dfy
7042

7143
Auditing ./src/Distributions/UniformPowerOfTwo/Correctness.dfy
72-
ProbUniformAlternative: Definition has `assume {:axiom}` statement in body.
73-
ProbUnifIsIndepFn: Declaration has explicit `{:axiom}` attribute.
74-
ProbUnifForAllStar: Declaration has explicit `{:axiom}` attribute.
44+
ProbUniformAlternative: Definition has `assume {:axiom}` statement in body.
45+
UnifCorrectness2: Definition has `assume {:axiom}` statement in body.
46+
UnifCorrectness2: Definition has `assume {:axiom}` statement in body.
47+
ProbUnifIsIndepFn: Declaration has explicit `{:axiom}` attribute.
7548

7649
Auditing ./src/Distributions/UniformPowerOfTwo/Implementation.dfy
7750

7851
Auditing ./src/Distributions/UniformPowerOfTwo/Interface.dfy
79-
UniformPowerOfTwo: Compiled declaration has no body and has an ensures clause.
8052

8153
Auditing ./src/Distributions/UniformPowerOfTwo/Model.dfy
82-
ProbUnifTerminates: Declaration has explicit `{:axiom}` attribute.
83-
ProbUnifCorrespondence: Definition has `assume {:axiom}` statement in body.
54+
ProbUnifTerminates: Declaration has explicit `{:axiom}` attribute.
55+
ProbUnifCorrespondence: Definition has `assume {:axiom}` statement in body.
8456

8557
Auditing ./src/Math/Helper.dfy
8658

8759
Auditing ./src/Math/MeasureTheory.dfy
88-
CountableSum: Definition has `assume {:axiom}` statement in body.
89-
CountableSumOfZeroesIsZero: Declaration has explicit `{:axiom}` attribute.
60+
CountableSum: Definition has `assume {:axiom}` statement in body.
61+
CountableSumOfZeroesIsZero: Declaration has explicit `{:axiom}` attribute.
62+
63+
Auditing ./src/Math/Rationals.dfy
9064

9165
Auditing ./src/ProbabilisticProgramming/Independence.dfy
92-
IsIndepFn: Declaration has explicit `{:axiom}` attribute.
93-
DeconstructIsIndepFn: Declaration has explicit `{:axiom}` attribute.
94-
ReturnIsIndepFn: Declaration has explicit `{:axiom}` attribute.
95-
IndepFnIsCompositional: Declaration has explicit `{:axiom}` attribute.
66+
IsIndepFn: Declaration has explicit `{:axiom}` attribute.
67+
DeconstructIsIndepFn: Declaration has explicit `{:axiom}` attribute.
68+
ReturnIsIndepFn: Declaration has explicit `{:axiom}` attribute.
69+
IndepFnIsCompositional: Declaration has explicit `{:axiom}` attribute.
9670

9771
Auditing ./src/ProbabilisticProgramming/Monad.dfy
98-
TailIsRNG: Declaration has explicit `{:axiom}` attribute.
99-
HeadIsMeasurable: Declaration has explicit `{:axiom}` attribute.
100-
MeasureHeadDrop: Declaration has explicit `{:axiom}` attribute.
101-
TailIsMeasurePreserving: Declaration has explicit `{:axiom}` attribute.
72+
TailIsRNG: Declaration has explicit `{:axiom}` attribute.
73+
HeadIsMeasurable: Declaration has explicit `{:axiom}` attribute.
74+
MeasureHeadDrop: Declaration has explicit `{:axiom}` attribute.
75+
TailIsMeasurePreserving: Declaration has explicit `{:axiom}` attribute.
10276

10377
Auditing ./src/ProbabilisticProgramming/Quantifier.dfy
10478

10579
Auditing ./src/ProbabilisticProgramming/RandomNumberGenerator.dfy
106-
IsRNG: Declaration has explicit `{:axiom}` attribute.
107-
RNGHasMeasure: Declaration has explicit `{:axiom}` attribute.
80+
IsRNG: Declaration has explicit `{:axiom}` attribute.
81+
RNGHasMeasure: Declaration has explicit `{:axiom}` attribute.
10882

10983
Auditing ./src/ProbabilisticProgramming/WhileAndUntil.dfy
110-
ProbWhile: Definition has `assume {:axiom}` statement in body.
111-
EnsureProbWhileTerminates: Declaration has explicit `{:axiom}` attribute.
112-
ProbUntilProbabilityFraction: Declaration has explicit `{:axiom}` attribute.
113-
ProbUntilAsBind: Declaration has explicit `{:axiom}` attribute.
114-
EnsureProbUntilTerminatesAndForAll: Definition has `assume {:axiom}` statement in body.
84+
ProbWhile: Definition has `assume {:axiom}` statement in body.
85+
EnsureProbWhileTerminates: Declaration has explicit `{:axiom}` attribute.
86+
ProbUntilProbabilityFraction: Declaration has explicit `{:axiom}` attribute.
87+
ProbUntilAsBind: Declaration has explicit `{:axiom}` attribute.
88+
EnsureProbUntilTerminatesAndForAll: Definition has `assume {:axiom}` statement in body.
11589

docs/dafny/ExamplesExternUniform.dfy

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
include "../../src/Dafny-VMC.dfy"
99

1010
module RandomExamples {
11+
import Rationals
1112
import DafnyVMC
1213

1314
method Main()
@@ -55,62 +56,39 @@ module RandomExamples {
5556
}
5657
print "Estimated probabilities for UniformInterval(7,10): ", (a as real) / (n as real), "; ", (b as real) / (n as real), "; " , (c as real) / (n as real), " (each should be around 0.33)\n";
5758

58-
a := 0;
59-
b := 0;
60-
for i := 0 to n {
61-
var k := r.Geometric();
62-
if k == 5 {
63-
a := a + 1;
64-
} else if k == 10 {
65-
b := b + 1;
66-
}
67-
}
68-
print "Estimated probabilities for Geometric(0.5): " , (a as real) / (n as real), " (should be around 0.015625) and " , (b as real) / (n as real), " (should be around 0.00048828125) \n";
69-
7059
t := 0;
7160
for i := 0 to n {
72-
var b := r.BernoulliRational(1, 5);
61+
var b := r.Bernoulli(Rationals.Rational(1, 5));
7362
if b {
7463
t := t + 1;
7564
}
7665
}
7766

78-
print "Estimated parameter for BernoulliRational(1, 5): ", (t as real) / (n as real), " (should be around 0.2)\n";
67+
print "Estimated parameter for Bernoulli(1, 5): ", (t as real) / (n as real), " (should be around 0.2)\n";
7968

8069
t := 0;
8170
for i := 0 to n {
82-
var b := r.BernoulliRational(0, 5);
71+
var b := r.Bernoulli(Rationals.Rational(0, 5));
8372
if b {
8473
t := t + 1;
8574
}
8675
}
8776

88-
print "Estimated parameter for BernoulliRational(0, 5): ", (t as real) / (n as real), " (should be around 0.0)\n";
89-
90-
t := 0;
91-
for i := 0 to n {
92-
var b := r.BernoulliRational(5, 5);
93-
if b {
94-
t := t + 1;
95-
}
96-
}
97-
98-
print "Estimated parameter for BernoulliRational(5, 5): ", (t as real) / (n as real), " (should be around 1.0\n";
99-
77+
print "Estimated parameter for Bernoulli(0, 5): ", (t as real) / (n as real), " (should be around 0.0)\n";
10078

10179
t := 0;
10280
for i := 0 to n {
103-
var b := r.Bernoulli(0.2);
81+
var b := r.Bernoulli(Rationals.Rational(5, 5));
10482
if b {
10583
t := t + 1;
10684
}
10785
}
10886

109-
print "Estimated parameter for Bernoulli(0.2): ", (t as real) / (n as real), " (should be around 0.2)\n";
87+
print "Estimated parameter for Bernoulli(5, 5): ", (t as real) / (n as real), " (should be around 1.0\n";
11088

11189
t := 0;
11290
for i := 0 to n {
113-
var u := r.BernoulliExpNeg(2.30258509299); // about -ln(0.1)
91+
var u := r.BernoulliExpNeg(Rationals.Rational(12381, 5377)); // about -ln(0.1)
11492
if u {
11593
t := t + 1;
11694
}
@@ -121,7 +99,7 @@ module RandomExamples {
12199
var count1 := 0;
122100
var countneg1 := 0;
123101
for i := 0 to n {
124-
var u := r.DiscreteLaplace(5, 7); // DiscreteLaplace(7/5)
102+
var u := r.DiscreteLaplace(Rationals.Rational(7, 5));
125103
match u {
126104
case -1 => countneg1 := countneg1 + 1;
127105
case 0 => count0 := count0 + 1;
@@ -138,7 +116,7 @@ module RandomExamples {
138116
count1 := 0;
139117
countneg1 := 0;
140118
for i := 0 to n {
141-
var u := r.DiscreteGaussian(1.4);
119+
var u := r.DiscreteGaussian(Rationals.Rational(7, 5));
142120
match u {
143121
case -1 => countneg1 := countneg1 + 1;
144122
case 0 => count0 := count0 + 1;

docs/dafny/ExamplesFoundational.dfy

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
include "../../src/Dafny-VMC.dfy"
99

1010
module RandomExamples {
11+
import Rationals
1112
import DafnyVMC
1213

1314
method Main()
@@ -55,61 +56,39 @@ module RandomExamples {
5556
}
5657
print "Estimated probabilities for UniformInterval(7,10): ", (a as real) / (n as real), "; ", (b as real) / (n as real), "; " , (c as real) / (n as real), " (each should be around 0.33)\n";
5758

58-
a := 0;
59-
b := 0;
60-
for i := 0 to n {
61-
var k := r.Geometric();
62-
if k == 5 {
63-
a := a + 1;
64-
} else if k == 10 {
65-
b := b + 1;
66-
}
67-
}
68-
print "Estimated probabilities for Geometric(0.5): " , (a as real) / (n as real), " (should be around 0.015625) and " , (b as real) / (n as real), " (should be around 0.00048828125) \n";
69-
70-
t := 0;
71-
for i := 0 to n {
72-
var b := r.BernoulliRational(1, 5);
73-
if b {
74-
t := t + 1;
75-
}
76-
}
77-
78-
print "Estimated parameter for BernoulliRational(1, 5): ", (t as real) / (n as real), " (should be around 0.2)\n";
79-
8059
t := 0;
8160
for i := 0 to n {
82-
var b := r.BernoulliRational(0, 5);
61+
var b := r.Bernoulli(Rationals.Rational(1, 5));
8362
if b {
8463
t := t + 1;
8564
}
8665
}
8766

88-
print "Estimated parameter for BernoulliRational(0, 5): ", (t as real) / (n as real), " (should be around 0.0)\n";
67+
print "Estimated parameter for Bernoulli(1/5): ", (t as real) / (n as real), " (should be around 0.2)\n";
8968

9069
t := 0;
9170
for i := 0 to n {
92-
var b := r.BernoulliRational(5, 5);
71+
var b := r.Bernoulli(Rationals.Rational(0, 5));
9372
if b {
9473
t := t + 1;
9574
}
9675
}
9776

98-
print "Estimated parameter for BernoulliRational(5, 5): ", (t as real) / (n as real), " (should be around 1.0\n";
77+
print "Estimated parameter for Bernoulli(0/5): ", (t as real) / (n as real), " (should be around 0.0)\n";
9978

10079
t := 0;
10180
for i := 0 to n {
102-
var b := r.Bernoulli(0.2);
81+
var b := r.Bernoulli(Rationals.Rational(5, 5));
10382
if b {
10483
t := t + 1;
10584
}
10685
}
10786

108-
print "Estimated parameter for Bernoulli(0.2): ", (t as real) / (n as real), " (should be around 0.2)\n";
87+
print "Estimated parameter for Bernoulli(5/5): ", (t as real) / (n as real), " (should be around 1.0\n";
10988

11089
t := 0;
11190
for i := 0 to n {
112-
var u := r.BernoulliExpNeg(2.30258509299); // about -ln(0.1)
91+
var u := r.BernoulliExpNeg(Rationals.Rational(12381, 5377)); // about -ln(0.1)
11392
if u {
11493
t := t + 1;
11594
}
@@ -120,7 +99,7 @@ module RandomExamples {
12099
var count1 := 0;
121100
var countneg1 := 0;
122101
for i := 0 to n {
123-
var u := r.DiscreteLaplace(5, 7); // DiscreteLaplace(7/5)
102+
var u := r.DiscreteLaplace(Rationals.Rational(7, 5));
124103
match u {
125104
case -1 => countneg1 := countneg1 + 1;
126105
case 0 => count0 := count0 + 1;
@@ -137,7 +116,7 @@ module RandomExamples {
137116
count1 := 0;
138117
countneg1 := 0;
139118
for i := 0 to n {
140-
var u := r.DiscreteGaussian(1.4);
119+
var u := r.DiscreteGaussian(Rationals.Rational(7, 5));
141120
match u {
142121
case -1 => countneg1 := countneg1 + 1;
143122
case 0 => count0 := count0 + 1;

docs/dafny/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Using the Dafny-VMC library in a Dafny application.
22
<br>
3+
<a href="dafny-doc/index.html">Dafny documentation</a>
4+
<br>
35
<a href="ExamplesFoundational.dfy">Example using the foundational uniform sampler</a>
46
<br>
57
<a href="ExamplesExternUniform.dfy">Example using the extern uniform sampler</a>

scripts/audit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ echo '' > audit.log
1313
for file in `find ./src -type f -name '*.dfy' | xargs -n1 | sort | xargs`
1414
do
1515
echo Auditing $file >> audit.log
16-
$DAFNY audit $file | grep -v '{:termination false}\|{:extern}\|decreases *\|Dafny auditor completed\|Dafny program verifier' | sed 's/.*Warning://' | sed 's/Possible.*//' >> audit.log
16+
$DAFNY audit $file | grep -v '{:termination false}\|{:extern}\|decreases *\|Dafny auditor completed\|Dafny program verifier\|No terms found to trigger on\|Compiled declaration has no body' | sed 's/.*Warning://' | sed 's/Possible.*//' >> audit.log
1717
done

0 commit comments

Comments
 (0)