In article Pine.LNX.4.44.0210251926200.4149-100000@candle.superlink.net,
Hi –
In article Pine.LNX.4.44.0210250754010.2650-100000@candle.superlink.net,
Hello –
I am wondering if there is a good reason why Ruby does not by default
support, for instance,
true <=> false (should be +1 or -1)
or even
false <=> false (should be 0)
I guess one reason is that it’s not clear (to me, anyway) why true
would be > false, or false > true. Is there ordinality to Boolean
values?
Actually if you want to get theoretical and mathematical there is an
ordering to boolean values in Boolean Algebra.
Here’s a definition from one of my textbooks (“Logic Synthesis and
Verification Algorithms” by Hachtel and Somenzi):
“A complemented, distributive lattice is a Boolean Lattice or Boolean
Algebra”
What’s a lattice:
“A lattice is a poset [partially ordered set] (AXA, <=) [meaning that
the Cartesian product of the set A with itself with the result ordered by
the less-than or equal relation] in which any two elements have a meet
[greatest lower bound] and a join [least upper bound]. Consequently, all
finite lattices have a greatest element, denoted by 1 [or true], and a
least element 0 [or false], where 1 [true] is an element of set A and 0
[false] is an element of set A.”
So technically true is greater than false.
We’re waaaay over my head mathematically, but I’m finding this
interesting enough that I’ll go ahead and ask a couple of stupid
questions 
No they’re good questions…
- Why couldn’t one swap ‘true’ and ‘false’ in your square-bracket
comments in the above? That is: why does true have to go with 1 and
false with 0?
Well, you’re getting deep with this one. I suppose you could say that its
a human imposed convention to associate 1 with true and 0 with false.
But yes, the book I referred to does (I think in order to play with your
mind a bit and to illustrate that different types of boolean algebras can
be concocted [more below]) show an example where the 1 and 0 are switched.
However, I don’t think we’d want to do that. It would be kind of like
saying that every place in your program where you see a ‘0’ it actually
means ‘9’ and everyplace you see an ‘8’ it actually means ‘1’ and so on
like:
0 ↔ 9
1 ↔ 8
2 ↔ 7
3 ↔ 6
4 ↔ 5
Yes you could do it as a mathematical exercise, but others wouldn’t get
the same meaning out of it.
- Does being the greatest and least, in a lattice, have to propagate
to a direct comparison between the two elements? I’m thinking (by way
of analogy) of an array: [3,1,5,4], where 5 is the greatest element in
one sense, and 4 is the greatest in another sense (highest indexed).
Well, a lattice represents a partially ordered set, so some kind of
comparison relation (which you can define, but usually based on
less-than-or-equal) needs to exist between them.
3, 1, 5, and 4 are just symbols whose meaning we supply:
3 generally means a cardinality of three as in here are 3 dots: …
You could just as easily supply some alternate notation as is done by
Hofstadter in “Godel, Escher, Bach” (yeah, I was reading it again recently :):
0 - means 0
S0 - successor to 0 (1)
SS0 - successor to the successor to 0 (2)
… and so on.
(oops, jump back from tangent)
And when you look at a set A = [3,1,5,4] you could interpret it as:
4>5>1>3
5>1>3
1>3
if you decide that the cardinality of (or magnitude represented by)
these symbols is solely based on their index position within the array.
- Does all of this necessarily apply to Ruby? That is, does the
presence of true and false in a programming language imply support for
Boolean algebra?
Primarily I was responding to your question above:
“Is there ordinality to Boolean values?”
To which I reply: yes, there is in the context of the Boolean Algebra.
There has to be for the rules of Boolean Algebra to ‘work’ at a basic level.
BTW: what we’re calling the Boolean Algebra here is commonly
known as the switching algebra. I don’t want to go into it, but there are
potentially an infinite number of boolean algebras that could be concocted
(note the change in case to lower case, where the Boolean Algebra refers
to the specific type of boolean algebra that is familiar to us.)
Now whereas true and false are often referred to as boolean values perhaps
we’re splitting semantic hairs to say that that infers a relation to the
Boolean Algebra since in Ruby true and false are just constant values that
have no common superclass (as is often proposed) called Boolean.
However, we do depend on boolean operations (&&,||,!,and,or,not) in our
programs, true? (!false?)
and we do expect these identities to hold:
true && true = true
true && false = false
true || false = true
true || true = true
false || false= false
And if x,y can take on only the values true or false:
if x || y = true
and
x && y = false
then
x is the complement of y and vce versa.
And: x || false = x, x && true = x (Identity)
Given the way we’ve defined the operators to work with the true and false
values in Ruby it would seem isomorphic to the Boolean Algebra
(ie. they match the properties of a boolean algebra in that they are
Idempotent, Commutative, Associative, Absoptive ( x && (x || y) = x ),
Distributive, Identities, and there exists a complement)
If it walks like a duck…
These questions are probably all OT babytalk, but I thought I’d give
it a try, just out of curiosity.
it’s a fun discussion.
Phil
“What is truth?” - Pilate’s question to Jesus circa 33AD
···
dblack@candle.superlink.net wrote:
On Sat, 26 Oct 2002, Phil Tomson wrote:
dblack@candle.superlink.net wrote:
On Fri, 25 Oct 2002, Rudi Cilibrasi wrote: