I want to prove the following about fraction addition. Namely j/2+k/2 = (j+k)/2. To do so, I have the following below:
lemma adding_fraction(j: nat, k: nat)
ensures j / 2 + k / 2 == (j + k) / 2
{
assert j / 2 + k / 2
== j * (1 / 2) + k * (1 / 2)
== (1/2) * (j + k)
== (j + k) / 2
assert j/2 + k/2 == (j + k) / 2;
}
I get an invalid AssertStmt error on the last like of this lemma. I'm not entirely sure why. Moreover I'm not sure why dafny is unable to prove this about addition already. Could someone provide some assistance on how I can prove this lemma?
I see one error actually now. Namely in dafny 1/2 == 0 is true. So all division seems to be done with a floor operation. That said in the code above is j%2=0 and k%2=0 then dafny's able to prove it no problem. How can I force dafny not to use floor? This is an issue since in real life: 1/2 + 5/2 = 6/2 = 3 but in dafny with floor: 1/2 + 5/2 = 0 + 2 = 2.