omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / checker2 / lrat / p06_popcount.osc
| 1 | // prove: popcount |
| 2 | // expect: holds |
| 3 | // loop with a constant trip count; the count never exceeds 8. |
| 4 | fn popcount(x: u8) -> u8 ensures result <= 8 { |
| 5 | let mut n: u8 = 0; |
| 6 | for i in 0 .. 8 { |
| 7 | if (x >> (i as u8)) & 1 == 1 { n = n + 1; } |
| 8 | } |
| 9 | return n; |
| 10 | } |