Introduction to Dafny

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:23 PM on 4/3/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

18 Terms

1
New cards

Weakest Precondition Definition

• wp(S, Q) is the weakest precondition.
• {wp(S, Q)} S {Q} holds.
• Valid if P → wp(S, Q).
• Enables backward reasoning.

2
New cards

wp for Assignment

• wp(x, y := E, F, P) = P[x, y := E, F].
• Same as assignment rule precondition.
• Substitutes E for x and F for y.

3
New cards

wp for Composition

• wp(S₁; S₂; …; Sₙ, Q) = wp(S₁, wp(S₂, …, wp(Sₙ, Q))).
• Computes weakest precondition working backwards.

4
New cards

wp for Conditional

• wp(if G {S} {T}, Q) = (G → wp(S, Q)) ∧ (¬G → wp(T, Q)).
• Determines branch's weakest precondition.

5
New cards

wp for While Loop

• Given invariant P and variant v:
• P ∧ B → wp(S, P)
• P ∧ B ∧ v=V → wp(S, v < V)
• P ∧ B → v ≥ 0
• P ∧ ¬B → Q
• Then P → wp(while B {S}, Q).

6
New cards

Consequence Rule in wp

• Not required; wp computes weakest precondition.
• If P → wp(S, Q) then {P} S {Q} holds.

7
New cards

Dafny Language Overview

• Object-oriented language.
• Java-like syntax based on Hoare logic and weakest precondition.
• Used for formal verification.

8
New cards

Dafny Method Specification

• Example: method inc(x: int) returns (y: int)
• requires x > 2
• ensures y > 3.
• Specifies preconditions and postconditions.

9
New cards

Dafny Array Types

• array: non-null integer arrays.
• array?: nullable arrays.
• Forall quantifier:
• forall i: int :: 0

10
New cards

Dafny Quantifier Scope

• Bound variable names are local to quantifier.
• Example:
• forall x: int :: 0

11
New cards

Dafny Modifies Clause

• modifies thisa, thisb: indicates modifiable fields.
• Essential for object state change reasoning.

12
New cards

Dafny Old Quantifier

• ensures this.a == old(this.b) && this.b == old(this.a).
• old(expr): value before method execution.

13
New cards

Dafny Loop Invariant

• Invariants hold before, during, and after loop.
• Example:
• invariant r >= 0 && y > 0.
• invariant x == r + y \* q.

14
New cards

Dafny Decrease Clause

• specifies loop variant.
• Expression must decrease on each iteration, bounded below.

15
New cards

Dafny Quotient-Remainder Example

• Example: method quotient_remainder(x: int, y: int) returns (r: int, q: int).
• requires x >= 0 && y > 0.
• Implements division algorithm with loop.

16
New cards

Dijkstra on Programming

• Edsger Dijkstra quote:
• "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
• Emphasizes formal methods.

17
New cards

Rustan Leino's Work

• Principal designer of Dafny at Microsoft Research.
• Focused on provably correct software and formal verification.

18
New cards

Dafny Playground

• Online environment for experimenting with Dafny code.