Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SampCert submodule and build, alternative #173

Merged
merged 33 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0e28d3c
SampCert submodule and build
jtristan Apr 24, 2024
5ab0a4f
Modified prep
jtristan Apr 24, 2024
d6e159b
changed elan install
jtristan Apr 24, 2024
249a15e
changed elan install
jtristan Apr 24, 2024
43f5ee5
changed elan install
jtristan Apr 24, 2024
9ad672e
changed elan install
jtristan Apr 24, 2024
941e9dc
build script works
jtristan Apr 24, 2024
3396e2b
build script works
jtristan Apr 24, 2024
9a539db
build script works
jtristan Apr 24, 2024
893f7f6
build script works
jtristan Apr 24, 2024
aff71e7
Trying Lean4 install
jtristan Apr 25, 2024
c6ebcd7
Trying Lean4 install
jtristan Apr 25, 2024
890140c
Trying Lean4 install
jtristan Apr 25, 2024
d0aeab3
Trying Lean4 install
jtristan Apr 25, 2024
24d9e4a
Trying Lean4 install
jtristan Apr 25, 2024
f6300b4
Trying Lean4 install
jtristan Apr 25, 2024
617d7b0
Trying Lean4 install
jtristan Apr 25, 2024
049abfd
Trying Lean4 install
jtristan Apr 25, 2024
4ff05b2
Trying Lean4 install
jtristan Apr 25, 2024
5ff5ea4
Trying Lean4 install
jtristan Apr 25, 2024
c4710bf
Trying Lean4 install
jtristan Apr 25, 2024
3f04539
Trying Lean4 install
jtristan Apr 25, 2024
4ec6a05
Trying Lean4 install
jtristan Apr 25, 2024
8abf5b1
Trying Lean4 install
jtristan Apr 25, 2024
e5036ae
Trying Lean4 install
jtristan Apr 25, 2024
cefe0f6
small changes
stefan-aws Apr 25, 2024
eda2c83
Remove submodule requirement
stefan-aws Apr 25, 2024
e06a18b
Remove empty space
stefan-aws Apr 25, 2024
375cd65
Fix naming
stefan-aws Apr 25, 2024
6e1628f
Verify -> Compare
stefan-aws Apr 25, 2024
13a72c2
Merge branch 'main' into AutoLean2
stefan-aws Apr 25, 2024
1f3f8de
Change github job name
stefan-aws Apr 25, 2024
419c80a
Merge branch 'AutoLean2' of https://github.com/dafny-lang/Dafny-VMC i…
stefan-aws Apr 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/trait.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Compare DafnyVMCTrait.dfy'
on:
workflow_dispatch:
pull_request:
push:
branches:
- 'main'
jobs:
compare-trait:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- run: bash scripts/prep.sh
- run: cp src/DafnyVMCTrait.dfy src/DafnyVMCTrait_.dfy
- run: DAFNY=dafny/dafny bash scripts/sampcert.sh
- run: cat src/DafnyVMCTrait.dfy
- run: diff src/DafnyVMCTrait.dfy src/DafnyVMCTrait_.dfy
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "docs/py/Benchmarks/differential-privacy-library"]
path = docs/py/Benchmarks/differential-privacy-library
url = https://github.com/IBM/differential-privacy-library/
[submodule "SampCert"]
path = SampCert
url = git@github.com:leanprover/SampCert.git
1 change: 1 addition & 0 deletions SampCert
Submodule SampCert added at 58a104
6 changes: 6 additions & 0 deletions scripts/sampcert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pushd SampCert
set -o pipefail
curl -sSfL https://github.com/leanprover/elan/releases/download/v1.4.2/elan-x86_64-unknown-linux-gnu.tar.gz | tar xz
./elan-init -y --default-toolchain leanprover/lean4:v4.7.0
$HOME/.elan/bin/lake build VMC
popd
43 changes: 19 additions & 24 deletions src/DafnyVMCTrait.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module DafnyVMCTrait {

import FisherYates

import Uniform

import opened Pos

trait {:termination false} RandomTrait extends UniformPowerOfTwo.Interface.Trait, FisherYates.Implementation.Trait, Uniform.Interface.Trait {
import Uniform

trait {:termination false} RandomTrait extends UniformPowerOfTwo.Interface.Trait, FisherYates.Implementation.Trait, Uniform.Interface.Trait {

method {:verify false} UniformSample (n: pos)
returns (o: nat)
Expand All @@ -28,7 +28,7 @@ module DafnyVMCTrait {

method {:verify false} BernoulliSample (num: nat, den: pos)
returns (o: bool)
requires num <= den
requires num <= den
modifies this
decreases *
{
Expand All @@ -38,7 +38,7 @@ module DafnyVMCTrait {

method {:verify false} BernoulliExpNegSampleUnitLoop (num: nat, den: pos, state: (bool,pos))
returns (o: (bool,pos))
requires num <= den
requires num <= den
modifies this
decreases *
{
Expand All @@ -48,7 +48,7 @@ module DafnyVMCTrait {

method {:verify false} BernoulliExpNegSampleUnitAux (num: nat, den: pos)
returns (o: nat)
requires num <= den
requires num <= den
modifies this
decreases *
{
Expand All @@ -64,7 +64,7 @@ module DafnyVMCTrait {

method {:verify false} BernoulliExpNegSampleUnit (num: nat, den: pos)
returns (o: bool)
requires num <= den
requires num <= den
modifies this
decreases *
{
Expand Down Expand Up @@ -106,8 +106,7 @@ module DafnyVMCTrait {
var gamf := num / den;
var B := BernoulliExpNegSampleGenLoop(gamf);
if B == true {
var num := num - gamf * den;
var X := BernoulliExpNegSampleUnit(num, den);
var X := BernoulliExpNegSampleUnit(num % den, den);
o := X;
} else {
o := false;
Expand Down Expand Up @@ -140,26 +139,25 @@ module DafnyVMCTrait {
o := r1.0;
}

method {:verify false} DiscreteLaplaceSampleLoopIn2Aux (num: nat, den: pos, K: (bool,pos))
returns (o: (bool,pos))
requires num <= den
method {:verify false} DiscreteLaplaceSampleLoopIn2Aux (num: nat, den: pos, K: (bool,nat))
returns (o: (bool,nat))
modifies this
decreases *
{
var A := BernoulliExpNegSampleUnit(num, den);
var A := BernoulliExpNegSample(num, den);
o := (A,K.1 + 1);
}

method {:verify false} DiscreteLaplaceSampleLoopIn2 (num: nat, den: pos)
returns (o: pos)
returns (o: nat)
modifies this
decreases *
{
var K := (true,1);
var K := (true,0);
while K.0
decreases *
{
K := DiscreteLaplaceSampleLoopIn2Aux(1, 1, K);
K := DiscreteLaplaceSampleLoopIn2Aux(num, den, K);
}
var r2 := K;
o := r2.1;
Expand All @@ -170,13 +168,10 @@ module DafnyVMCTrait {
modifies this
decreases *
{
var U := DiscreteLaplaceSampleLoopIn1(num);
var v := DiscreteLaplaceSampleLoopIn2(1, 1);
var V := v - 2;
var X := U + num * V;
var Y := X / den;
var v := DiscreteLaplaceSampleLoopIn2(den, num);
var V := v - 1;
var B := BernoulliSample(1, 2);
o := (B,Y);
o := (B,V);
}

method {:verify false} DiscreteLaplaceSample (num: pos, den: pos)
Expand All @@ -202,7 +197,7 @@ module DafnyVMCTrait {
{
var Y := DiscreteLaplaceSample(t, 1);
var y := (if Y < 0 then -Y else Y);
var n := (y * t * den - num) * (y * t * den - num);
var n := ((if y * t * den - num < 0 then -y * t * den - num else y * t * den - num)) * ((if y * t * den - num < 0 then -y * t * den - num else y * t * den - num));
var d := 2 * num * (t) * (t) * den;
var C := BernoulliExpNegSample(n, d);
o := (Y,C);
Expand All @@ -228,6 +223,6 @@ module DafnyVMCTrait {
}


}
}

}