Replies: 1 comment
-
Note that your code also works with the following simpler magic function: function magic<S, T>(f: S -> T): (r: S -> T)
{
x => f(x)
} and now you can see why it's equivalent to the case when you explicitely use Let's dive deep into the Boogie pool, which is the intermediate language in which Dafny compile. You can see such a file by running
I did that, and under the hood, Dafny sends to Boogie the following axiom: axiom (forall ty: Ty, heap: Heap, len: int, init: HandleType, i: int ::
{ Seq#Index(Seq#Create(ty, heap, len, init), i) }
$IsGoodHeap(heap) && 0 <= i && i < len
==> Seq#Index(Seq#Create(ty, heap, len, init), i)
== Apply1(TInt, ty, heap, init, $Box(i))); I verified that this axiom could be instantiated correctly in the context of the assertion, and Boogie is able to prove that: assert $Unbox(Seq#Index(Seq#Create(TInt, $Heap, LitInt(1), f#0), LitInt(0))) ==
$Unbox(Apply1(TInt, TSeq(TInt), $Heap, f#0, $Box(LitInt(0)))); However, assert $Unbox(Seq#Index(Seq#Create(TInt, $Heap, LitInt(1), f#0), LitInt(0))): int
== $Unbox(Apply1(TInt, TInt, $Heap, f#0, $Box(LitInt(0)))): int; Note the subtle different, we can prove the assert when the second element is For the assertion that you can prove with axiom (forall t0: Ty,
t1: Ty,
heap: Heap,
h: [Heap,Box]Box,
r: [Heap,Box]bool,
rd: [Heap,Box]Set Box,
bx0: Box,
bx: Box ::
{ Reads1(t0, t1, heap, Handle1(h, r, rd), bx0)[bx] }
Reads1(t0, t1, heap, Handle1(h, r, rd), bx0)[bx] == rd[heap, bx0][bx]); Thanks for pointing this verification incompleteness. I'll convert it to an issue. |
Beta Was this translation helpful? Give feedback.
-
Hi All,
I recently met a problem when verifying with higher-order functions. It boils down to the following minimal example:
In the general case (especially when writing class methods), one would have to write
x reads f.reads(x) requires f.requires(x) => f(x)
in the place off
. This will be quite a boilerplate.After some random attempts, I found an acceptable workaround:
I am still curious about what exactly is happening under the hood and whether there are more elegant ways to deal with this. Any suggestion is welcome.
Beta Was this translation helpful? Give feedback.
All reactions