<s>
Dafny	B-Application
is	O
an	O
imperative	B-Application
and	O
functional	B-Language
compiled	B-Language
language	I-Language
that	O
compiles	O
to	O
other	O
programming	O
languages	O
,	O
such	O
as	O
C#	B-Application
,	O
Java	B-Language
,	O
JavaScript	B-Language
,	O
Go	B-Application
and	O
Python	B-Language
.	O
</s>
<s>
It	O
supports	O
formal	B-Application
specification	I-Application
through	O
preconditions	O
,	O
postconditions	O
,	O
loop	B-Application
invariants	I-Application
,	O
loop	B-Application
variants	I-Application
,	O
termination	O
specifications	B-Application
and	O
read/write	O
framing	O
specifications	B-Application
.	O
</s>
<s>
The	O
language	O
combines	O
ideas	O
from	O
the	O
functional	B-Language
and	O
imperative	B-Application
paradigms	I-Application
;	O
it	O
includes	O
support	O
for	O
object-oriented	B-Language
programming	I-Language
.	O
</s>
<s>
Dafny	B-Application
was	O
created	O
by	O
Rustan	O
Leino	O
at	O
Microsoft	O
Research	O
after	O
his	O
previous	O
work	O
on	O
developing	O
ESC/Modula	O
-3	O
,	O
ESC/Java	B-Application
,	O
and	O
Spec#	O
.	O
</s>
<s>
Dafny	B-Application
is	O
widely	O
used	O
in	O
teaching	O
because	O
it	O
provides	O
a	O
simple	O
,	O
integrated	O
introduction	O
to	O
formal	B-Application
specification	I-Application
and	O
verification	O
;	O
it	O
is	O
regularly	O
featured	O
in	O
software	O
verification	O
competitions	O
(	O
e.g.	O
</s>
<s>
Dafny	B-Application
was	O
designed	O
as	O
a	O
verification-aware	O
programming	O
language	O
,	O
requiring	O
verification	O
along	O
with	O
code	O
development	O
.	O
</s>
<s>
Verification	O
obligations	O
are	O
discharged	O
automatically	O
,	O
given	O
sufficient	O
specification	B-Application
.	O
</s>
<s>
Dafny	B-Application
uses	O
some	O
program	O
analysis	O
to	O
infer	O
many	O
specification	B-Application
assertions	O
,	O
reducing	O
the	O
burden	O
on	O
the	O
user	O
of	O
writing	O
specifications	B-Application
.	O
</s>
<s>
Dafny	B-Application
builds	O
on	O
the	O
Boogie	O
intermediate	O
language	O
which	O
uses	O
the	O
Z3	B-Language
automated	I-Language
theorem	I-Language
prover	I-Language
for	O
discharging	O
proof	O
obligations	O
.	O
</s>
<s>
Dafny	B-Application
provides	O
methods	O
for	O
implementation	O
which	O
may	O
have	O
side-effects	O
and	O
functions	O
for	O
use	O
in	O
specification	B-Application
which	O
are	O
pure	B-Application
.	O
</s>
<s>
Methods	O
consist	O
of	O
sequences	O
of	O
statements	O
following	O
a	O
familiar	O
imperative	B-Application
style	O
whilst	O
,	O
in	O
contrast	O
,	O
the	O
body	O
of	O
a	O
function	O
is	O
simply	O
an	O
expression	O
.	O
</s>
<s>
Dafny	B-Application
also	O
provides	O
a	O
range	O
of	O
immutable	O
collection	O
types	O
including	O
:	O
sequences	O
(	O
e.g.	O
</s>
<s>
The	O
following	O
illustrates	O
many	O
of	O
the	O
features	O
in	O
Dafny	B-Application
,	O
including	O
the	O
use	O
of	O
preconditions	O
,	O
postconditions	O
,	O
loop	B-Application
invariants	I-Application
and	O
loop	B-Application
variants	I-Application
.	O
</s>
<s>
Likewise	O
,	O
the	O
loop	B-Application
invariant	I-Application
and	O
loop	B-Application
variant	I-Application
are	O
given	O
through	O
the	O
invariant	O
and	O
decreases	O
clauses	O
(	O
respectively	O
)	O
.	O
</s>
<s>
The	O
treatment	O
of	O
loop	B-Application
invariants	I-Application
in	O
Dafny	B-Application
differs	O
from	O
traditional	O
Hoare	O
logic	O
.	O
</s>
<s>
Information	O
required	O
to	O
prove	O
properties	O
of	O
such	O
variables	O
must	O
be	O
expressed	O
explicitly	O
in	O
the	O
loop	B-Application
invariant	I-Application
.	O
</s>
<s>
This	O
fails	O
verification	O
because	O
Dafny	B-Application
cannot	O
establish	O
that	O
(	O
sum	O
+	O
arr[i]	O
)	O
>=	O
0	O
holds	O
at	O
the	O
assignment	O
.	O
</s>
<s>
From	O
the	O
precondition	O
,	O
intuitively	O
,	O
forall	O
i	O
::	O
0	O
<= i < arr.Length ==> arr[i] >	O
=	O
0	O
holds	O
in	O
the	O
loop	O
since	O
arr[i]	O
:=	O
arr[i];	O
is	O
a	O
NOP	B-Language
.	O
</s>
<s>
However	O
,	O
this	O
assignment	O
causes	O
Dafny	B-Application
to	O
treat	O
arr	O
as	O
a	O
mutable	O
variable	O
and	O
drop	O
information	O
known	O
about	O
it	O
from	O
before	O
the	O
loop	O
.	O
</s>
<s>
Dafny	B-Application
additionally	O
employs	O
limited	O
static	O
analysis	O
to	O
infer	O
simple	O
loop	B-Application
invariants	I-Application
where	O
possible	O
.	O
</s>
<s>
In	O
the	O
example	O
above	O
,	O
it	O
would	O
seem	O
that	O
the	O
loop	B-Application
invariant	I-Application
invariant	O
i	O
>=	O
0	O
is	O
also	O
required	O
as	O
variable	O
i	O
is	O
mutated	O
within	O
the	O
loop	O
.	O
</s>
<s>
Whilst	O
the	O
underlying	O
logic	O
does	O
require	O
such	O
an	O
invariant	O
,	O
Dafny	B-Application
automatically	O
infers	O
this	O
and	O
,	O
hence	O
,	O
it	O
can	O
be	O
omitted	O
at	O
the	O
source	O
level	O
.	O
</s>
<s>
Dafny	B-Application
includes	O
features	O
which	O
further	O
support	O
its	O
use	O
as	O
a	O
proof	O
assistant	O
.	O
</s>
<s>
Although	O
proofs	O
of	O
simple	O
properties	O
within	O
a	O
function	O
or	O
method	O
(	O
as	O
shown	O
above	O
)	O
are	O
not	O
unusual	O
for	O
tools	O
of	O
this	O
nature	O
,	O
Dafny	B-Application
also	O
allows	O
the	O
proof	O
of	O
properties	O
between	O
one	O
function	O
and	O
another	O
.	O
</s>
<s>
Dafny	B-Application
is	O
perhaps	O
unusual	O
in	O
employing	O
method	O
invocation	O
as	O
a	O
mechanism	O
for	O
applying	O
the	O
inductive	O
hypothesis	O
.	O
</s>
<s>
The	O
use	O
of	O
a	O
ghost	O
method	O
for	O
encoding	O
lemmas	O
and	O
theorems	O
is	O
standard	O
in	O
Dafny	B-Application
with	O
recursion	O
employed	O
for	O
induction	O
(	O
typically	O
,	O
structural	B-Algorithm
induction	I-Algorithm
)	O
.	O
</s>
