Count the `yes' and `no' votes for a leader.
(tally-leader-votes leader voters) → (mv yes-count no-count)
The
We go through the voters, and for each voter check whether the given leader authored one of the certificates referenced in the voter certificate, counting `yes' or `no' votes, respectively. We return both counts.
Function:
(defun tally-leader-votes (leader voters) (declare (xargs :guard (and (addressp leader) (certificate-setp voters)))) (let ((__function__ 'tally-leader-votes)) (declare (ignorable __function__)) (b* (((when (emptyp voters)) (mv 0 0)) (voter (head voters)) ((mv yes-count no-count) (tally-leader-votes leader (tail voters)))) (if (in leader (certificate->previous voter)) (mv (1+ yes-count) no-count) (mv yes-count (1+ no-count))))))
Theorem:
(defthm natp-of-tally-leader-votes.yes-count (b* (((mv ?yes-count ?no-count) (tally-leader-votes leader voters))) (natp yes-count)) :rule-classes :rewrite)
Theorem:
(defthm natp-of-tally-leader-votes.no-count (b* (((mv ?yes-count ?no-count) (tally-leader-votes leader voters))) (natp no-count)) :rule-classes :rewrite)