Questions tagged [dafny]

Dafny is a programming language with built-in specification constructs.

Dafny is a compiled language used for functional testing of functional correctness of programs.

Home page: https://dafny.org/

485 questions
0
votes
1 answer

How can I add a feature to Dafny?

I would like to add some basic convenience features to Dafny, such as the ability to define set union in Dafny (see this question). But the internals of Dafny don't seem to be well documented and I don't know where to begin. How can I add such a…
Kevin S
  • 497
  • 2
  • 10
0
votes
1 answer

Dafny rejects a simple postcondition

Below is a first attempt to prove various simple theorems, in this case about parity. Dafny /v. 1.9.9.40414/ verifies that adding 2 to an even number yields an even number but does not accept either of the commented out conditions. function IsEven(a…
Attila Karoly
  • 951
  • 5
  • 13
0
votes
1 answer

Controlling Dafny naming convention and using constants

Is there any way to control the naming convention Dafny uses for the target code? Is it possible to use a symbolic constant globally? Something like this: ? global const MaxValue = 10000; ? method Method1 (a : int) returns (b : int) requires a <…
Attila Karoly
  • 951
  • 5
  • 13
0
votes
1 answer

Compilation with module refinement

When compiling the following code: module Interface { function addSome(n: nat): nat ensures addSome(n) > n } module Mod { import A : Interface method m() { assert 6 <= A.addSome(5); print "Test\n"; …
JAB
  • 20,783
  • 6
  • 71
  • 80
0
votes
1 answer

Dafny verifies insertion sort using swap

I'm working on how to use dafny to verify an insertion sort using "swap" adjacent elements but I can't find a reasonable invariant for the while loop, can anyone help me fix it? Here is the link: http://rise4fun.com/Dafny/wmYME
Lilac Liu
  • 49
  • 1
  • 4
0
votes
1 answer

dafny assert violated using sequence

Here is the dafny code, the second assertion never pass, anyone can help me out? enter link description here
Lilac Liu
  • 49
  • 1
  • 4
0
votes
1 answer

Why this trivial hint is required?

I wonder why Dafny requires the commented hint in http://rise4fun.com/Dafny/8sl7 to validate the assertion? Could someone explain it?
jiplucap
  • 155
  • 7
0
votes
1 answer

Boogie strange assert(false) behavior

I am working with Boogie and I have come across some behaviors I do not understand. I have been using assert(false) as a way to check if the previous assume statements are absurd. For instance in the following case, the program is verified without…
user2009400
  • 147
  • 9
0
votes
1 answer

Dafny verification - refer to original var in post condition

I am trying to verify my code in Dafny and I encountered a problem: I have a method that is iterating over a sequence and changes it. The method changes the sequence according to the elements in the sequence. I would like to add a post condition…
Ariel B
  • 31
  • 1
0
votes
2 answers

Confused by Dafny postcondition messages

A very simple multiplication code: method Product1 (m: nat, n: nat) returns (res:nat) ensures res == m * n; { var m1: nat := 0; var n1: nat := 0; res := 0; while (m1 < m) { n1 := 0; while (n1 <…
Richard Yang
  • 131
  • 1
  • 2
  • 5
0
votes
0 answers

Confused by Dafny postcondition messages

A very simple multiplication code: method Product1 (m: nat, n: nat) returns (res:nat) ensures res == m * n; { var m1: nat := 0; var n1: nat := 0; res := 0; while (m1 < m) { n1 := 0; while (n1 < n) {…
Richard Yang
  • 131
  • 1
  • 2
  • 5
0
votes
1 answer

Can Dafny be used non-interactively, for example from a python program?

I would like to query whether a particular Dafny program verifies. Dafny is typically used to develop programs in an interactive manner inside the visual studio IDE. However, I need to perform the query in a non-interactive manner. In particular I…
Tom
  • 904
  • 1
  • 7
  • 21
0
votes
1 answer

Dafny: Help proper invariant, decreases statement

Can anyone help me with what's wrong here. I get the below error when verifying this program. I have tried various ways but it never passess the verification. Please help. method Main() { var a:int := 0; var b:int := -1; var c:int :=…
RoshP
  • 19
  • 1
  • 5
0
votes
1 answer

invalid segment Count in dafny

i wrote the following proof for the code in the link below. i would like to get some help with prooving the count2 method . the alternation proof is not so clear to me thanks http://rise4fun.com/Dafny/ueBY method Main() { var a: array :=…
greenity
  • 419
  • 1
  • 5
  • 13
0
votes
0 answers

Dafny - Propagate ensures clause?

What I'm having issue with is two different methods in two different classes not cooperating, the set-up is as following: class A{ method b() ensures statement { // Do something } } class C{ method d() requires…
David S
  • 195
  • 5
  • 19
1 2 3
32
33