I'm wondering if there exists any rule/scheme of proceeding with proving algorithm correctness? For example we have a function $F$ defined on the natural numbers and defined below:
function F(n,k)
begin
if k=0 then return 1
else if (n mod 2 = 0) and (k mod 2 = 1) then return 0
else return F(n div 2, k div 2);
end;
where $n \ \text{div}\ 2 = \left\lfloor\frac{n}{2}\right\rfloor$
the task is to prove that $F(n,k)= \begin{cases} 1 \Leftrightarrow {n \choose k} \ \text{mod} \ 2 = 1 \\ 0 \text{ otherwise } \end{cases} $
It does not look very complicated (am I wrong?), but I don't know how does this kind of proof should be structured. I would be very grateful for help.
I'm extremely sorry for my mistake.. I've just edited the code (first else)..
Hint $\ $ By Kummer, $\rm\displaystyle\:{n \choose k}\:$ is odd iff there are no carries when adding $\rm\:n\:$ and $\rm\:n-k\:$ in base $2$.
Alternatively, here's a direct parity proof, split into cases based on the values of $\rm\:n,k\ mod\ 2\!:$
$\rm\displaystyle \begin{matrix}n\equiv 0:\\ \rm k\equiv 1:\end{matrix}\ \ {n\choose k}\ =\ \frac{n}k {n-1 \choose k-1 } \equiv\: 0$
$\rm\displaystyle\begin{matrix}n\equiv 0:\\ \rm k\equiv 0:\end{matrix}\ \ {n\choose k}\equiv \frac{n(n-2)(n-4)\:\cdots\:(n-k+2)}{2\cdot 4\cdot 6\:\cdots\:k}\equiv\frac{\frac{n}{2}(\frac{n}2-1)\:\cdots(\frac{n}2-\frac{k}2+1)}{1\cdot 2\cdot 3\:\cdots\:\frac{k}2}\equiv {n/2\choose k/2}$
$\rm\displaystyle \begin{matrix}n\equiv 1:\\ \rm k\equiv 1:\end{matrix} \ \ {n\choose k}\: =\: \frac{n}k {n-1 \choose k-1 }\:\equiv\:{n-1\choose k-1}\equiv {(n-1)/2\choose (k-1)/2}\equiv{\lfloor n/2\rfloor\choose \lfloor k/2\rfloor}$
$\rm\displaystyle\begin{matrix}n\equiv 1:\\ \rm k\equiv 0:\end{matrix} \ \ {n\choose k}\ \ \:=\:\ \ {n-1 \choose k-1 }\: +\: {n-1\choose k}\equiv {(n-1)/2\choose k/2}\equiv{\lfloor n/2\rfloor\choose \lfloor k/2\rfloor}$