Skip to content

Commit

Permalink
Added 'min' and 'max' to front-end language
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewDaggitt committed Sep 24, 2024
1 parent f6cf551 commit d18f88c
Show file tree
Hide file tree
Showing 12 changed files with 949 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for Vehicle

## Version 0.15

* Added functions `min` and `max` over rationals.

## Version 0.14.1

* Removed `Explicit` as a command line compilation target option as it never worked.
Expand Down
9 changes: 3 additions & 6 deletions docs/language/tips-and-tricks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,16 @@ calculate the maximum score and then require it to be less than 0.2:

.. code-block:: agda
max : Rat -> Rat -> Rat
max x y = if x <= y then x else y
largestScore : Tensor Rat [10] -> Rat
largestScore xs = fold max 0 xs
isUncertainAbout : Tensor Rat [24, 24] -> Bool
isUncertainAbout x = largestScore (classify x) <= 0.2
However, this definition would experience an exponential blow-up when
compiled down to low-level verification queries, as each branch of the
10 :code:`if` statements would need to be explored. In total 1024 queries
would be generated.
compiled down to low-level verification queries, as :code:`max` is compiled down
to an :code:`if` statement and each branch of the 10 :code:`if` statements would
need to be explored. In total 1024 queries would be generated.

This blow-up can be avoided by instead using a "relational" approach to
encoding the constraint, instead stating that all classes scores must be less
Expand Down
10 changes: 10 additions & 0 deletions vehicle/lib/std.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ typeAnn t a = a
notBoolOp2 : (A -> B -> Bool) -> (A -> B -> Bool)
notBoolOp2 f x y = not (f x y)

--------------------------------------------------------------------------------
-- Orderings
--------------------------------------------------------------------------------

min : {{HasLeq a a}} -> a -> a -> a
min x y = if x <= y then x else y

max : {{HasLeq a a}} -> a -> a -> a
max x y = if y <= x then x else y

--------------------------------------------------------------------------------
-- List
--------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions vehicle/tests/golden/compile/simple-minmax/Marabou.err.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

Warning: In property 'p', at least one of the generated queries were found to contain a strict inequality (i.e. constraints of the form 'x < y'). Unfortunately the Marabou query format only supports non-strict inequalities (i.e. constraints of the form 'x <= y').

In order to provide support, Vehicle has automatically converted the strict inequalities to non-strict inequalites. This is not sound, but errors will be at most the floating point epsilon used by the verifier, which is usually very small (e.g. 1e-9). However, this may lead to unexpected behaviour (e.g. loss of the law of excluded middle).

See https://github.com/vehicle-lang/vehicle/issues/74 for further details.


Warning: In property 'p', the following network input variables do not always have both a lower and a upper bound. This is not currently supported by the Marabou query format.
In queries 1, 2, 3 and 4:
f₀[input]!0 - no lower or upper bound

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// WARNING: This file was generated automatically by Vehicle
// and should not be modified manually!
// Metadata:
// - Marabou query format version: unknown
// - Vehicle version: 0.14.1+dev
+y0 -y1 <= 0.0
y0 <= 0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// WARNING: This file was generated automatically by Vehicle
// and should not be modified manually!
// Metadata:
// - Marabou query format version: unknown
// - Vehicle version: 0.14.1+dev
-y0 +y1 <= 0.0
y1 <= 0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// WARNING: This file was generated automatically by Vehicle
// and should not be modified manually!
// Metadata:
// - Marabou query format version: unknown
// - Vehicle version: 0.14.1+dev
-y0 +y1 <= 0.0
y0 >= 1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// WARNING: This file was generated automatically by Vehicle
// and should not be modified manually!
// Metadata:
// - Marabou query format version: unknown
// - Vehicle version: 0.14.1+dev
+y0 -y1 <= 0.0
y1 >= 1.0
Loading

0 comments on commit d18f88c

Please sign in to comment.