The Grinnell Scheme Web: Inequality

How do you find out whether one number is unequal to another?

Scheme doesn't provide a built-in procedure to test whether two numbers are unequal, but it's easy to define one:

(define (~= first-number second-number)
  (not (= first-number second-number)))
(You may prefer to use the variable != to name this procedure, if you're acquainted with C; Pascal programmers may prefer <>, TeX users \not=, and so on.)

Why does Scheme provide the other five numerical relations and not this one?

Because the other five are transitive and therefore have a natural extension to more than two operands, and the multi-operand extensions are not easily interdefinable. For example, you couldn't simply define >= as the negation of <, because both (>= 1 4 2) and (< 1 4 2) are false.

Inequality, on the other hand, is intransitive. It does not have a unique natural extension to more than two operands (Should (~= 4 7 4) be true or false? Does ``unequal'' mean ``not all equal'' or ``pairwise distinct''?). And its two-operand case is easily definable, as shown above.


Next topic
Previous topic
Table of contents


This document is available on the World Wide Web as

http://www.math.grin.edu/~stone/scheme-web/unequal.html


created July 2, 1995
last revised December 30, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)