Skip to content

Commit

Permalink
Few more DafnyStdLibs references
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-aws committed Dec 6, 2023
1 parent 66946af commit d2a7d7d
Show file tree
Hide file tree
Showing 59 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Source/DafnyStandardLibraries/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ When `--standard-libraries` is switched on,
these source files are automatically emitted when compiling,
just like the contents of each backend's runtime.

See [Makefile](Makefile) and [src/DafnyStdLibs/TargetSpecific/Makefile](src/DafnyStdLibs/TargetSpecific/Makefile) for more details.
See [Makefile](Makefile) and [src/Std/TargetSpecific/Makefile](src/Std/TargetSpecific/Makefile) for more details.


### On brittleness
Expand Down
8 changes: 4 additions & 4 deletions Source/DafnyStandardLibraries/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ verify:
$(DAFNY) verify src/dfyconfig-arithmetic.toml

build-binary:
$(DAFNY) build -t:lib src/DafnyStdLibs/EnableNonLinearArithmetic/dfyconfig.toml --output:${DOO_FILE_SOURCE}
$(DAFNY) build -t:lib src/DafnyStdLibs/DisableNonLinearArithmetic/dfyconfig.toml --output:${DOO_FILE_ARITHMETIC_SOURCE}
$(DAFNY) build -t:lib src/Std/EnableNonLinearArithmetic/dfyconfig.toml --output:${DOO_FILE_SOURCE}
$(DAFNY) build -t:lib src/Std/DisableNonLinearArithmetic/dfyconfig.toml --output:${DOO_FILE_ARITHMETIC_SOURCE}

check-binary: build-binary
unzip -o ${DOO_FILE_SOURCE} -d build/current
Expand All @@ -25,12 +25,12 @@ check-binary: build-binary
unzip -o ${DOO_FILE_ARITHMETIC_SOURCE} -d build/current-arithmetic
unzip -o ${DOO_FILE_ARITHMETIC_TARGET} -d build/rebuilt-arithmetic
diff build/current-arithmetic build/rebuilt-arithmetic
make -C src/DafnyStdLibs/TargetSpecific check-binary-all
make -C src/Std/TargetSpecific check-binary-all

update-binary: build-binary
cp ${DOO_FILE_SOURCE} ${DOO_FILE_TARGET}
cp ${DOO_FILE_ARITHMETIC_SOURCE} ${DOO_FILE_ARITHMETIC_TARGET}
make -C src/DafnyStdLibs/TargetSpecific update-binary-all
make -C src/Std/TargetSpecific update-binary-all
# Rebuild Dafny to pick up the new embedded assets
dotnet build ../Dafny.sln

Expand Down
16 changes: 8 additions & 8 deletions Source/DafnyStandardLibraries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ No need to `include` any files! For example:
```dafny
module UsesWrappers {
import opened DafnyStdLibs.Wrappers
import opened Std.Wrappers
function SafeDiv(a: int, b: int): Option<int> {
if b == 0 then None else Some(a/b)
Expand Down Expand Up @@ -45,13 +45,13 @@ In particular, `--standard-libraries` currently cannot be used together with `--

The sections below describe how to use each library:

- [DafnyStdLibs.BoundedInts](src/DafnyStdLibs/BoundedInts) -- definitions of types and constants for fixed-bit-width integers
- [DafnyStdLibs.Wrappers](src/DafnyStdLibs/Wrappers) -- simple datatypes to support common patterns, such as optional values or the result of operations that can fail
- [DafnyStdLibs.Relations](src/DafnyStdLibs/Relations) -- properties of relations
- [DafnyStdLibs.Functions](src/DafnyStdLibs/Functions) -- properties of functions
- [DafnyStdLibs.Collections](src/DafnyStdLibs/Collections) -- properties of the built-in collection types (seq, set, iset, map, imap, array)
- DafnyStdLibs.DynamicArray -- an array that can grow and shrink
- [DafnyStdLibs.Base64](src/DafnyStdLibs/Base64) -- base-64 encoding and decoding
- [Std.BoundedInts](src/Std/BoundedInts) -- definitions of types and constants for fixed-bit-width integers
- [Std.Wrappers](src/Std/Wrappers) -- simple datatypes to support common patterns, such as optional values or the result of operations that can fail
- [Std.Relations](src/Std/Relations) -- properties of relations
- [Std.Functions](src/Std/Functions) -- properties of functions
- [Std.Collections](src/Std/Collections) -- properties of the built-in collection types (seq, set, iset, map, imap, array)
- Std.DynamicArray -- an array that can grow and shrink
- [Std.Base64](src/Std/Base64) -- base-64 encoding and decoding

We are in the process of importing many more libraries,
in particular from the existing [`dafny-lang/libraries`](https://github.com/dafny-lang/libraries) GitHub repository.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## The `Base64` module

The `DafnyStdLibs.Base64` module contains an encoder and decoder for Base64, which allows arbitrary byte sequences to be represented in sequences of characters drawn entirely from 7-bit ASCII. This encoder and decoder have two interfaces, one which uses `uint8` to represent arbitrary bytes, and one which uses `bv8`. The encoder and decoder are proved to be inverses of each other, for both interfaces.
The `Std.Base64` module contains an encoder and decoder for Base64, which allows arbitrary byte sequences to be represented in sequences of characters drawn entirely from 7-bit ASCII. This encoder and decoder have two interfaces, one which uses `uint8` to represent arbitrary bytes, and one which uses `bv8`. The encoder and decoder are proved to be inverses of each other, for both interfaces.

The `uint8`-based interface consists of the `Encode` and `Decode` functions along with the `EncodeDecode` and `DecodeEncode` lemmas. The `bv8`-based interface consists of the `EncodeBV` and `DecodeBV` functions along with the `EncodeDecodeBV` and `DecodeEncodeBV` lemmas. The `uint8`-based interface is a wrapper on top of the `bv8`-based interface, because Base64 encoding is more straightforward to specify and verify using bit vectors.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## The `BoundedInts` module

The `DafnyStdLibs.BoundedInts` module contains definitions of types and constants for fixed-bit-width integers.
The `Std.BoundedInts` module contains definitions of types and constants for fixed-bit-width integers.

Dafny itself generally uses and reasons about mathematical, unbounded integers and natural numbers.
However compiled programs, for efficiency of computation and storage, will generally use fixed-bit-width
Expand All @@ -28,20 +28,20 @@ native signed 8-bit integer type.
In addition, the module defines a number of constants that are powers of two (not all of them, just those that are generally useful).
They are useful in stating the ranges of fixed-bit-width integers. Examples are `TWO_TO_THE_15`, `TWO_TO_THE_32`.

Here are two example methods. In the first, the module `DafnyStdLibs.BoundedInts` is renamed to `BI`, which is then used as the prefix for type and constant names.
Here are two example methods. In the first, the module `Std.BoundedInts` is renamed to `BI`, which is then used as the prefix for type and constant names.
In the second, the module is imported as opened, in which case the type and constant names can be used without qualification.
<!-- %check-verify -->
```dafny
module M {
import BI = DafnyStdLibs.BoundedInts
import BI = Std.BoundedInts
method m(k: BI.int16) {
assert k as int < BI.TWO_TO_THE_15;
}
}
module N {
import opened DafnyStdLibs.BoundedInts
import opened Std.BoundedInts
method m(k: int16) {
assert (k/256) as int < TWO_TO_THE_8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ As a simple example, you might define a predicate like this:
and then need to prove this lemma to use it in a sorting routine:
<!-- %check-verify %use tmp-intlt.dfy -->
```dafny
import opened DafnyStdLibs.Relations
import opened Std.Relations
lemma IntLTisStrictTotalOrder()
ensures StrictTotalOrdering(IntLT) {}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In this library module Dafny defines three such types:
Consider this routine that looks for a value in a sequence, beginning at position `k`, returning its index:
<!-- %check-verify %save tmp-find.dfy -->
```dafny
import opened DafnyStdLibs.Wrappers
import opened Std.Wrappers
function Find<T(==)>(s: seq<T>, k: int, value: T): (r: Option<int>)
requires 0 <= k <= |s|
ensures r.Some? ==> 0 <= r.Extract() < |s| && s[r.Extract()] == value
Expand Down Expand Up @@ -72,7 +72,7 @@ appropriate values in the success situation.
For example, if we have this method
<!-- %check-resolve %save tmp-matches.dfy -->
```dafny
import opened DafnyStdLibs.Wrappers
import opened Std.Wrappers
method FindAllMatches<T(==)>(s: seq<T>, value: T) returns (status: Outcome<string>, matches: seq<int>)
```
we can call it as
Expand Down Expand Up @@ -102,7 +102,7 @@ convert to values of the other types. For example, we can rewrite the example ab

<!-- %check-verify %save tmp-find.dfy -->
```dafny
import opened DafnyStdLibs.Wrappers
import opened Std.Wrappers
function Find<T(==)>(s: seq<T>, k: int, value: T): (r: Option<int>)
requires 0 <= k <= |s|
Expand Down Expand Up @@ -154,7 +154,7 @@ The workaround, however, is straightforward: just capture the results using `:=`

<!-- %check-verify -->
```dafny
import opened DafnyStdLibs.Wrappers
import opened Std.Wrappers
method Find<T(==)>(s: seq<T>, k: int, value: T) returns (r: Option<int>, v: T)
requires 0 <= k <= |s|
Expand Down

0 comments on commit d2a7d7d

Please sign in to comment.