heapsink(S,i,n) is
{@$ i \gt 0 \land n\gt 0$@}
@$\bb$@ Var j @$\in$@ Int;
  initially j=i
  ;do 
     2j@$<$@n @$\rightarrow$@  let
                k:= 2j+1, if (2j+1)@$<$@n 
                             cand S(2j+1)@$>$@ S.2j
                    2j, otherwise
              in
                if 
                  S.j@$<$@S.k @$\rightarrow$@ S.j,S.k,j:=S.k,S.j,k
                 @$\assync$@ S.j@$ \ge $@S.k @$\rightarrow$@ j:= n
                fi
              tel 
   od
@$\be$@



