evenly_divides(
other : SAME
) : BOOL is
-- This predicate returns true if and only if self is an exact divisor
-- of other.
return (other % self) = zero
end ;
is_prime_to(
other : SAME
) : BOOL is
-- This predicate returns true if and only if self is relatively prime
-- to other.
return gcd(other) = 1
end ;
middle(
first,
second : SAME
) : SAME
pre true
post ((self > first)
and (first > second)
and (result = first))
or ((self < first)
and (self > second)
and (result = self))
or (result = second)
is
-- This routine returns the result of min(second) being applied to
-- max(first).
extended_gcd(
other : SAME,
out self_factor,
out i_factor : SAME
) : SAME
pre true
post ((result % self) = 0)
and ((result % other) = 0)
and (((self_factor * self) + (i_factor * other)) = result)
is
-- This routine returns the result of applying the extended Euclidean
-- algorithm (Geddes et al, p36) to self and other. The three parts of
-- the return value `g', `g1', and `g2' are such that `g' is the greatest
-- common divisor of self and other and `g1 * self + g2 * other = g'.
aelt! : BOOL is
-- This iter is effectively a predicate which yields true or false
-- depending upon whether the indicated bit of self was set or not.
binary!(
once limit : SAME
) : SAME
pre limit >= one
post (result >= one)
and (result <= limit)
is
-- This iter yields successive doublings of the initial value (1) up to
-- the given limit.