Majority voting
Mehrdad Mahdavi
83206054
Winning an election
(strict majority)
(exists majority)
(conditional majority)
Predicates:
Abstract program :
A straightforward attempt
Disjunction inherent
using
(i)(ii)
First refinementIf there is no majority is a as i, then the only possible maj . In as (i+1) is as[i](i)
Introduction count c
A Second attemp is faster
Define variable
Refine…
Count c
Linear Time Code
Add variable d(State transformation)
Remove auxiliary c,j
Fast Code ………..
Merge alternationLaw 18.2 left-distribution of composition over alternation
.);(||;)(||
fiprogbranchGifprogfibranchGiif
ii
ii
Right-distribution of assignment over alternation
.);:]\[(||)(||;:
fibranchExExGiffibranchGiifEx
ii
ii
Simplify alternationLaw 18.4 remove false guard Law 18.5 remove alternation
Flatten nested alternationsLaw 18.6
.),(||
))(||(||
fibranchHGjif
fifibranchHjifGiif
ijji
ijji
Introduce invariant d>=0
Thanks