Hoare Logic (Loops)

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

1/10

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:22 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

11 Terms

1
New cards

Loop Invariant (Partial Correctness)

  • Property holds before execution, after each iteration, and after termination.

  • Rule {P ∧ B} S {P} ensures invariant is maintained.

  • After loop: P ∧ ¬B holds.

2
New cards

While Rule (Partial Correctness)

  • {P ∧ B} S {P} implies {P} while B {S} {P ∧ ¬B}.
  • Proves loop termination, ensures postcondition holds.
  • Does not guarantee termination.
3
New cards

Loop Variant (Total Correctness)

  • Integer expression v that decreases with each iteration.
  • Must satisfy: P ∧ B → v ≥ 0.
  • Proves termination: {P ∧ B ∧ v = V} S {v < V}.
4
New cards

While Rule (Total Correctness)

  • Requirements:
    • {P ∧ B} S {P} (invariant preserved).
    • {P ∧ B ∧ v = V} S {v < V} (variant decreases).
    • P ∧ B → v ≥ 0 (variant bounded).
  • Concludes {P} while B {S} {P ∧ ¬B}.
5
New cards

Euclid's Algorithm Example

  • Computes quotient q and remainder r:
    • r := x; q := 0;
    • while (y ≤ r) { r := r - y; q := 1 + q; }.
  • Postcondition: r < y ∧ x = r + y*q.
6
New cards

Euclid Loop Invariant

  • Invariant: x = r + y*q.
  • Holds initially: x = x + y*0.
  • Preserved by iteration: ((r-y) + y(q+1) = r + yq).
  • Loop exit r < y gives postcondition.
7
New cards

Euclid Loop Variant

  • Variant: r (the remainder).
  • Decreases each iteration (r := r - y, with y>0).
  • Bounded below by 0, proves termination.
8
New cards

Termination Importance

  • Necessary to ensure programs finish.
  • Illustrative examples: Zune bug, spinning wheel.
  • Total correctness combines partial correctness with termination guarantee.
9
New cards

Compact Proof Representation

  • Numbered lines with dependencies:
    • (1) {x>2} x:=x+1 {x>2} CONSEQUENCE
    • (2)(3)(4): (2) x>3→x>2; (3) {x+1>3} x:=x+1 {x>3} ASSIGNMENT; (4) x>2→x+1>3.
10
New cards

Proof Tree Structure

  • Root is goal statement.
  • Apply rules backward to create sub-goals.
  • Leaves closed by axioms (assignment) or implications.
  • Shows compact representation with steps, rules, and dependencies.
11
New cards

Sir Tony Hoare (1934-2026)

  • Pioneer of Hoare Logic and Quicksort.
  • Contributed to CSP (Communicating Sequential Processes) and UTP (Unifying Theories of Programming).
  • Passed away March 5, 2026.

Explore top notes

note
IB Chemistry 3.1 Periodic Table
Updated 1266d ago
0.0(0)
note
Aula APS Redes Territorializacao
Updated 501d ago
0.0(0)
note
EMSF110 - Trauma Exam
Updated 997d ago
0.0(0)
note
US History Chap. 11
Updated 926d ago
0.0(0)
note
AFPF casus 5
Updated 443d ago
0.0(0)
note
World History 2 Midterm
Updated 217d ago
0.0(0)
note
IB Chemistry 3.1 Periodic Table
Updated 1266d ago
0.0(0)
note
Aula APS Redes Territorializacao
Updated 501d ago
0.0(0)
note
EMSF110 - Trauma Exam
Updated 997d ago
0.0(0)
note
US History Chap. 11
Updated 926d ago
0.0(0)
note
AFPF casus 5
Updated 443d ago
0.0(0)
note
World History 2 Midterm
Updated 217d ago
0.0(0)

Explore top flashcards

flashcards
History Unit 5 Test
70
Updated 1127d ago
0.0(0)
flashcards
Los 99 nombres de Allah
100
Updated 215d ago
0.0(0)
flashcards
Antidiabetic Drugs
52
Updated 1219d ago
0.0(0)
flashcards
ИМА
553
Updated 442d ago
0.0(0)
flashcards
NL woordenschat blok 1 en 2
49
Updated 1231d ago
0.0(0)
flashcards
Hinduism
20
Updated 1103d ago
0.0(0)
flashcards
History Unit 5 Test
70
Updated 1127d ago
0.0(0)
flashcards
Los 99 nombres de Allah
100
Updated 215d ago
0.0(0)
flashcards
Antidiabetic Drugs
52
Updated 1219d ago
0.0(0)
flashcards
ИМА
553
Updated 442d ago
0.0(0)
flashcards
NL woordenschat blok 1 en 2
49
Updated 1231d ago
0.0(0)
flashcards
Hinduism
20
Updated 1103d ago
0.0(0)