Program Verification Using 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/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 6:34 PM on 3/20/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

16 Terms

1
New cards

Compositional Verification Principle

Verification of individual methods where postcondition verified once, precondition checked at each call. After calling a method, only its postcondition is assumed; Dafny does not expand callee implementation. Enables modular reasoning.

2
New cards

Method Call Verification

For method call inc(x), Dafny checks that caller's precondition implies callee's precondition. After call, only callee's postcondition is assumed about return values. Implementation details not examined.

3
New cards

Example 1 Verification Result

method inc requires x > 2 ensures y > 3. In Main: x=3 satisfies precondition, so call valid. Postcondition ensures y > 3, which Dafny can verify. Assert y > 3 holds.

4
New cards

Example 2 Verification Result

method inc requires x > 2 ensures y > 3. In Main: x=4 satisfies precondition. Postcondition only guarantees y > 3, not y > 4. Assert y > 4 cannot be verified from postcondition alone.

5
New cards

Max Method Specification

method max(a: array) returns (m: int) requires a.Length > 1 ensures forall i: int :: 0

6
New cards

Max Method Assertion Failure

In Main: a = [0,1,3]. Postcondition ensures y >= each element, but y could be 5, 10, etc. Assert y == 3 cannot be proved because postcondition is too weak.

7
New cards

Max Method Loop Invariant Needed

Loop invariant must track maximum found so far: invariant forall j: int :: 0

8
New cards

Square Method by Sum of Odds

method square(x: nat) returns (y: int) ensures y == x * x. Uses identity: sum of first x odd numbers = x². Loop adds odd numbers: b starts at 1, increments by 2 each iteration.

9
New cards

Square Method Loop Invariant

Invariant: a == i * i and b == 2*i + 1. Initially i=0: a=0, b=1. Each iteration: a += b gives (i² + (2i+1)) = (i+1)², b += 2 gives 2(i+1)+1.

10
New cards

Loop Invariant for Max

invariant forall j: int :: 0

11
New cards

Dafny Assertion Verification

Dafny uses weakest precondition to verify assertions. Assert statement must be provable from current context (preconditions, loop invariants, postconditions of called methods).

12
New cards

Array Element Assignment

a[0] := 0; updates array element. Dafny tracks array contents through modifications. For verification, arrays must be properly initialized before use.

13
New cards

New Array Creation

var a: array := new nat[3]; creates new array of length 3 with unspecified initial values. Elements must be explicitly assigned before reading.

14
New cards

Method Parameter Immutability

In Dafny, method parameters are immutable. To modify values, use returns clause to produce new values. Array contents can be modified via indices.

15
New cards

Loop Invariant Necessity

For loops, Dafny requires invariants to prove properties. Without invariants, Dafny cannot verify that loop establishes required postcondition. Invariants must be inductive (hold before loop, preserved by body).

16
New cards

Termination Proof via Decrease

For loops, Dafny requires decrease clause to prove termination. For simple loops with integer counter, decrease can be automatically inferred. Complex loops need explicit variant

Explore top notes

note
Matter & Energy
Updated 1108d ago
0.0(0)
note
AE Slides Ch1-7
Updated 501d ago
0.0(0)
note
Animal Kingdom - Chordata
Updated 893d ago
0.0(0)
note
Mistakes chem
Updated 303d ago
0.0(0)
note
Power sharing
Updated 917d ago
0.0(0)
note
Forensic Anthropology
Updated 1401d ago
0.0(0)
note
Matter & Energy
Updated 1108d ago
0.0(0)
note
AE Slides Ch1-7
Updated 501d ago
0.0(0)
note
Animal Kingdom - Chordata
Updated 893d ago
0.0(0)
note
Mistakes chem
Updated 303d ago
0.0(0)
note
Power sharing
Updated 917d ago
0.0(0)
note
Forensic Anthropology
Updated 1401d ago
0.0(0)

Explore top flashcards

flashcards
english 10 vocab 2
20
Updated 935d ago
0.0(0)
flashcards
Blow Flies and Beetles
20
Updated 888d ago
0.0(0)
flashcards
Electricity - grade 9
49
Updated 1153d ago
0.0(0)
flashcards
Junior All State Terms
44
Updated 1198d ago
0.0(0)
flashcards
El tiempo y el calendario
42
Updated 1136d ago
0.0(0)
flashcards
English Final (vocab)
50
Updated 1020d ago
0.0(0)
flashcards
english 10 vocab 2
20
Updated 935d ago
0.0(0)
flashcards
Blow Flies and Beetles
20
Updated 888d ago
0.0(0)
flashcards
Electricity - grade 9
49
Updated 1153d ago
0.0(0)
flashcards
Junior All State Terms
44
Updated 1198d ago
0.0(0)
flashcards
El tiempo y el calendario
42
Updated 1136d ago
0.0(0)
flashcards
English Final (vocab)
50
Updated 1020d ago
0.0(0)