// Derived from an example in the Boogie distribution // isr computes the (non-negative) integer square root of its input method isr(n: int) returns (r : int) requires n >= 0; // r is the largest non-negative integer whose square is at most n ensures 0 <= r*r && r*r <= n && n < (r+1)*(r+1); { r := 0 ; while ((r+1) * (r+1) <= n) invariant r*r <= n ; { r := r+1 ; } } method Main() { var res ; call res := isr(36) ; assert (res == 6) ; call res := isr(35) ; assert res == 5 ; }