Skip to content

Instantly share code, notes, and snippets.

@ParadoxV5
Created August 17, 2025 03:42
Show Gist options
  • Save ParadoxV5/0cc5c73a128aa96c942f7302ff30182c to your computer and use it in GitHub Desktop.
Save ParadoxV5/0cc5c73a128aa96c942f7302ff30182c to your computer and use it in GitHub Desktop.
≠ and ≶ are different.

Today, I realized that != and <> can be different.

Of course, they are equivalent in the ideal domain, but we live in a polymorphic world where two values can be incomparable with each other. For example, 1, a number, is incomparable to "Hello", a string of text. This relation is mathematically known as a Partial Ordering.

Arguably, "Hello" doesn’t literally equal one, which we can denote as "Hello" ≠ 1. On the other hand, "Hello" ≶ 1 doesn’t quite hold. Their mutual incomparability means that neither is less or greather than the other; it would instead be "Hello" ≸ 1.

That said, we write != and <>, especially in coding, not and . And, depending on the coding language, comparison operators < ≤ = ≥ > might error or return null/nil for incomparable values. By set logic, Partial Ordering happily defines false for all five incomparable comparisons, since it has “or incomparable” versions for them: ≱ ≯ ≸ ≮ ≰.

The spaceship operator <=> boolean-wise matches the comparison in Ruby, thanks to everything but false and nil being truthful in Ruby, and Ruby’s <=> results in nil for incomparables. Are there any other coïncidences? Shall we create more?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment