Numeric comparison with nil - Math masochists only!

Alright, i’m trying to do three things at once, and I’m almost
succeeding.
The first thing is learn Ruby, the second thing is learn Surreal
Numbers,
and the third is to make a Ruby class for Surreal numbers. :stuck_out_tongue: My
problem
is this: part of the definition of a surreal number is pretty much a
comparison with nil. So how would one go about this? Should I write a
<=>
and mixin Comparable? What else should I include to make this easier??
Any
help & suggestions are most welcome!!

And for those of you who are interested and want more info on surreal
numbers, here are some links…

http://www.tondering.dk/claus/surreal.html
http://scienceblogs.com/goodmath/goodmath/numbers/surreal_numbers/
http://www.dm.unipi.it/~fornasiero/phd_thesis/thesis_fornasiero_linearized.pdf

thats all of my links to surreal numbers… it kinda sucks that my
biggest
hurdle is at the very beggining!! :stuck_out_tongue:

thanks again!

-hex

On Fri, Dec 24, 2010 at 3:45 AM, serialhex [email protected] wrote:

Alright, i’m trying to do three things at once, and I’m almost succeeding.
The first thing is learn Ruby, the second thing is learn Surreal Numbers,
and the third is to make a Ruby class for Surreal numbers. :stuck_out_tongue: My problem
is this: part of the definition of a surreal number is pretty much a
comparison with nil. So how would one go about this? Should I write a <=>
and mixin Comparable? What else should I include to make this easier?? Any
help & suggestions are most welcome!!

A possibly unhelpful suggestion about nil <=> y and y <=> nil: does the
nil
for Surreal have to be the Ruby nil of NilClass?

I think it could be (as you say, write Nil#<=> and mixin Comparable) and
I
guess that it’s unlikely that a SurrealNumbers class would be used with
anything else?? (But you can never be sure: another of my lecturers (see
Semi-OT below) was Ian Stewart, and in one of his 1990s (sort of)
popular
books on modern mathematics he says non-standard arithmetic has been
used to
devise better ways of representing images using pixels (or something
like
that): basically work out the theory using “finite” “infinite” integers,
then use the results to make a practical algorithm by changing a
“finite”
“infinite” integer to a large finite integer.)

So if you wanted to avoid possible clashes with other code which expects
(nil <=> other) to raise an exception you could set up

class Surreal::SurrealNil

define appropriate methods

end
Surreal::Nil = Surreal::SurrealNil.new
Nil = Surreal::Nil # maybe

You can do:
class Surreal::SurrealNil < NilClass
but then there isn’t Surreal::SurrealNil.new, presumably because there
isn’t
NilClass.new

I’d be interested to see what you come up with, because periodically I
try
to really understand NonStandard Analysis, and the NonStandard Reals are
a
subset of the Surreals.

*** Semi-OT: I followed up some links from your links, and found a name
I
recognized as the lecturer who gave my first (or at least one of my
first)
lectures in mathematics at the University of Warwick in October 1973, a
one
term course on the Foundations of Mathematics. (Basically set theory
using
Paul Halmos’s Naive Set Theory.) I knew he became very interested in
mathematical education some time after I’d graduated, but I didn’t know
that
he was also interested in “intuitive” concepts of infinity. Following up
links and trying to find out more about David O Tall’s “super-real”
numbers
I found:
Infinitesimals in Modern Mathematics (section 3.2)
A less ambitious but much more accessible approach to defining
infinitesimals is one by David Tall from the University of Warwick. His
motivation was to create a system which was more intuitive for students
and
to make Calculus concepts easier to grasp. The simplicity of his
approach is
very appealing, as it quickly gets to the use of infinitesimals without
the
large construction found *R’s construction. …
David Tall Research Papers
David Tall - Limits, Infinitesimals and Infinities
and in particular this delightful conversation about infinity between
David
Tall and his seven year old son:
http://www.warwick.ac.uk/staff/David.Tall/pdfs/dot2001l-childs-infinity.pdf

On Sat, Dec 25, 2010 at 2:34 AM, serialhex [email protected] wrote:

def <=> other
neg infinity, cause with neg infinity you still have SOMETHING right?)

so while the rest of the project is FAR from finished, at least this part is
completed. thanks for the help!!

If you need additional input I have written about numeric classes in our
blog
http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html

Kind regards

robert

hey robert, thanks for the great article, i’ll keep that stuff in mind
as
i’m writing the rest of this class!

hex

On Mon, Dec 27, 2010 at 5:46 AM, Robert K.

Colin, your amazing insight has led me to programming greatness!!!

…ok, mabye not so much, but i have (mostly) solved the problem using
the
Delegate class, heres the relevant code:

require ‘delegate’

class SurrealNil < DelegateClass(NilClass)
include Comparable
def <=> other
return -1
end
def initialize
super nil
end
end

it returns -1 all the time so no matter what you compare it against it’s
less than that (i mean, sereously, an empty set is WAAAAYYYYYYY less
than
neg infinity, cause with neg infinity you still have SOMETHING right?)

so while the rest of the project is FAR from finished, at least this
part is
completed. thanks for the help!!

-hex

p.s. i’ll post a link to the source once it’s in a form that’s not
embarrasing! :stuck_out_tongue:

where i get that from is this:

when you look at a graph of 1/x lim(+x->0) +infinity; lim(-x->0)
-infinity;
(that’s also what i learned in my calculus courses) so 1/0 (kind of) has
a
value depending on which direction you approach 0 from.

null on the other hand - as you said - is undefined. and when you
compare
null to ANY value - even neg infinity - you still have a value on one
hand
and nothing on the other. and while it sucks, having -infinity dollars
you
have SOME value (to bill collectors) and having nil dollars you have no
value (to anyone). that example is kind of bad cause nil == 0, but
that’s
not my point. if you read some of the papers i provided in the first
post
(esp. this one:
http://www.tondering.dk/main/index.php/surreal-numbers) part of the
definition of a surreal number is a comparison with nil. the first
surreal
number { nil | nil } is defined as 0, and the second generation { { nil
|
nil } | nil } is defined as 1 and { nil | { nil | nil } } is -1 (
commonly
written simply as { | }; { 0 | } and { | 0 }. and { 0 | 0 } is not
well-defined in the definition of surreal numbers )

so while it might not make sense to most people (indeed, i’m working on
stretching my brain around all this) this is the definition i’m working
with, and i’m not going to argue with math phd’s

as for the utility of it all? surreal numbers are commonly used in game
theory. though the reason why i’m building this class is not for
utility,
but as an exercise in ‘can i do this?’ there are some problems that may
come up later i’m going to have to find some way to deal with ( sets of
infinite objects being one of them, surreal numbers being cool enough
that
it gives meaning to things like infinity + 6 and infinity/2 ).

so i hope i answered your question and maybe taught you something.

hex

p.s. i still might be mostly wrong, but again, i’m trusting the articles
i’m
reading. maybe i should have one of those cool math-like people look at
this?

serialhex wrote:

If you need additional input I have written about numeric classes in our
http://blog.rubybestpractices.com/

I can’t imagine where you got the idea that a nul is less than minus
infinity. Mathematically, a null is basically undefined as in dividing
by zero. I have no idea what your use of this is, but mathematically you
are in the wrong pew.

Everett L.(Rett) Williams II

serialhex wrote:

have SOME value (to bill collectors) and having nil dollars you have no
so while it might not make sense to most people (indeed, i’m working on
so i hope i answered your question and maybe taught you something.

hex

p.s. i still might be mostly wrong, but again, i’m trusting the articles i’m
reading. maybe i should have one of those cool math-like people look at
this?

I haven’t the time nor energy to get through all of that, but I can
clearly state that your explication of division by Zero is just wrong.
Undefined is just that…undefined. You can approach by any means that
you wish, but it does not change the nature of the beast. You might note
that, as much as physicists and cosmologists deal with very, very large
numbers, they still dislike infitities in equations, because they often
lead to mathematical and sometime physical black holes. All computer
logic is finite and deterministic, so you may model infinities on a
computer, as metadata, but you cannot do any calculation that includes
them.

Everett L.(Rett) Williams II

On Wed, Dec 29, 2010 at 1:59 PM, Everett L Williams II
[email protected] wrote:

I haven’t the time nor energy to get through all of that, but I can clearly
state that your explication of division by Zero is just wrong. Undefined is
just that…undefined. You can approach by any means that you wish, but it
does not change the nature of the beast. You might note that, as much as
physicists and cosmologists deal with very, very large numbers, they still
dislike infitities in equations, because they often lead to mathematical and
sometime physical black holes. All computer logic is finite and
deterministic, so you may model infinities on a computer, as metadata, but
you cannot do any calculation that includes them.

Why? Sciences are irrelevant in formalisms.

You can indeed do some calculations, the fact that there are infinite
natural numbers does not mean you can’t add some of them in a
computer. Certainly not all of them, but some.

In that sense arithmetic with infinite quantities is no different. You
can represent infinites or infinitessimals just fine and define
operators on them, just the way you do with natural numbers. In a
computer you are always modelling, you also model N.

It is common that formalisms in Set Theory start with the empty set,
because the axioms give you that one. That’s serialhex’s nil in
Conway’s classic book on the subject. That’s how the naturals are
modelled in Set Theory also, ∅ is 0, {∅} is 1, and n = n ∪ {n}. You
only have the empty set and operations like union or the power set to
build upon.

A pedantic and cautious (meaning I’m reasonably sure about what I
write below but I’m not 100% confident) person with a maths degree
from just over 30 years ago (so out of date, and I’ve forgotten a
lot!) writes:

On Tue, Dec 28, 2010 at 10:37 AM, Everett L Williams II
[email protected] wrote:

On Sat, Dec 25, 2010 at 2:34 AM, serialhex[email protected] wrote:


it returns -1 all the time so no matter what you compare it against it’s
less than that (i mean, sereously, an empty set is WAAAAYYYYYYY less
than neg infinity, cause with neg infinity you still have SOMETHING right?)

I can’t imagine where you got the idea that a nul is less than minus
infinity. Mathematically, a null is basically undefined as in dividing by
zero. I have no idea what your use of this is, but mathematically you are in
the wrong pew.

  1. In this case I think serialhex’s “<=>” may not always be returning
    the appropriate value for “comparisons” with nil (see below).

  2. But for the general case, I remain to be convinced that a null is
    necessarily undefined: depending on what one means by “null” in a
    particular context, then it might make sense to compare something with
    that. But if “a null is basically undefined” is restricting the use of
    null to stuff that is undefined in a particular context, then
    (cautiously) I agree!

  3. The statement by serialhex that
    “an empty set is WAAAAYYYYYYY less than neg infinity”
    did make me wonder if it was correct in the specific context of
    Surreal numbers, and I have been looking at the articles. The basis
    for comparisons is (in one formulation):
    x <= y if and only if
    (a) there are no values xLv in the Left set xL of x for which y <= xLv;
    and
    (b) there are no values yRv in the Right set yR of y for which yR <= x.

If the set xL is empty, then (a) is “vacuously” true; similarly, if
the set yR is empty, then (b) is “vacuously” true.
But the empty set itself is not (as I understand) it a Surreal
number, so strictly speaking I think (cautiously!) comparisons are not
with the empty set as such but with pairs of sets (L and R) of which
none or one or both of a pair may be the empty set.

In Tndering’s second chapter he does define comparisons between sets
of Surreal numbers, and then states:
“It follows from the definition above that
EmptySet <= b
is always true, regardless of the value of b; and so is
EmptySet > b, etc”

One needs to be very careful: I think (cautiously) that the definition
of Order in the Wikipedia article is correct, but that the “friendly”
explanations in brackets after the proper parts of the definition are
(probably/possibly!) either misleading or wrong.

On Wed, Dec 29, 2010 at 8:06 PM, Everett L Williams II
[email protected] wrote:

beyond that is modeled and entirely dependent on my logic rather than the
represented in any nat8ive form within a computer.

If you look up infinity on the wiki, you will find pages upon pages of
various means of manipulating infinities, and yours may be the latest. When
I have the time and energy, I will look, but it is hard to get excited about
the umpty-unth attempt.

My reply addressed a couple of points of your post:

  1. If we are programming symbolic mathematics, we are doing
    mathematics. The convenience or lack thereof of such and such concept
    for scientists doesn’t matter in discussing whether something can be
    given a well-defined formal meaning.

  2. Computations in computers: from a formal point of view I disagree,
    but do not want to enter into that. If by metadata you mean eg
    programs versus CPU registers, and if you agree that we can represent
    something infinite like the set of quadratic polynomials in on
    variable in Z, then we agree in this point. Not its members, but the
    set and its rules, akin to how we represent Z in C.

Xavier N. wrote:

sometime physical black holes. All computer logic is finite and
can represent infinites or infinitessimals just fine and define
operators on them, just the way you do with natural numbers. In a
computer you are always modelling, you also model N.

It is common that formalisms in Set Theory start with the empty set,
because the axioms give you that one. That’s serialhex’s nil in
Conway’s classic book on the subject. That’s how the naturals are
modelled in Set Theory also, ? is 0, {?} is 1, and n = n ? {n}. You
only have the empty set and operations like union or the power set to
build upon.

You are confusing computer logic and meta-data manipulation. No computer
can natively deal with the representation of, much less the calculation
of anything that involves infinity, either negative or positive. You
certainly can define a set of rules and attempt to create a program that
models those rules, but you cannot naatively do any such calculation.
Computers are, by definition, finitie and deterministic, and there is
not room here to explain exactly what that means, but there is plenty of
information spread all over the internet on the subject. Let me take a
small stab at an example. Given to finitie numbers whose sum is within
the capacity of the instructions of a computer, I can add those two
numbers and get a third number. Anything beyond that is modeled and
entirely dependent on my logic rather than the logic of the computer.
So, you can declare that infinity plus 6 has meaning and you can declare
what that meaning is, providing a routine that will decode your
expression of infinity and then follow your instructions for creating
whatever you have defined as infinity plus 6, but there is no native
instruction, even in floating point, that can impinge on the correctness
or the calculation of the answer. It is entirely dependent on the
meta-logic and meta-data that you have provided. Even extended precision
math libraries can break a large number down into segments and then use
the native facilities of the computer in a logically and mathematically
valid process that leads to arithmetically correct answers, but infinity
cannot be represented in any nat8ive form within a computer.

If you look up infinity on the wiki, you will find pages upon pages of
various means of manipulating infinities, and yours may be the latest.
When I have the time and energy, I will look, but it is hard to get
excited about the umpty-unth attempt.

Everett L.(Rett) Williams II

Xavier N. wrote:

exactly what that means, but there is plenty of information spread all over
the meta-logic and meta-data that you have provided. Even extended precision
My reply addressed a couple of points of your post:
variable in Z, then we agree in this point. Not its members, but the
set and its rules, akin to how we represent Z in C.

I’d go a bit past registers to the total logic of the computer. No
instruction in any computer can deal with infinity in any form, either
logically or physically. Of course, programs for symbolic manipulation
can and have been written, but there is no enforcement or checking
related to the logic or hardware of the computer. Unless something is
physically wrong, computers, adding binary 1 to binary 1 will get binary
10 every time. Your program, consisting of meta-data and meta-logic is a
construct entirely dependent on your definition of all parts of the
program. By the way, if you are programming symbolic mathematics, the
computer is merely following your algorithm. All elements and properties
of that algorithm are external to the computer.

Everett L.(Rett) Williams II

Everett, even in the act of adding two numbers, the computer is
following
our instructions & algorithms. The computer doesn’t know the difference
between ‘add’ or ‘subtract’ or ‘exponentiate’ or ‘do this cool MMX
function
thing’. The entire process is an abstraction, so while I agree that it
IS
impossible to literally do addition or multiplication with infinite
strings of numbers (unless you have some cool sci-fi infinite-computer
thing) you can figuratively do multiplication on infinite stings of
numbers. One example as when you use ruby’s rational class for numbers
like
1/3 or 17/9. Neither of those numbers can be completely represented
in
the computer as a floating point number, as they go on indefinitely. So
instead they are represented as a fraction and the math on an infinite
string of digits is done by changing the way the computer sees & acts
with
the number.

Now, one thing I do know, is that figuring out how to do the whole
‘surreal
multiplication with infinite numbers’ thing is going to be a pain in my
arse!! I’ve got some ideas but I’m not sure my programming-fu is up to
the
task just yet. But hey, gotta set goals high right?

hex

On Thu, Dec 30, 2010 at 7:19 AM, Everett L Williams II

serialhex wrote:

instead they are represented as a fraction and the math on an infinite

by
logic of the computer. So, you can declare that infinity plus 6 has
native facilities of the computer in a logically and mathematically valid

but do not want to enter into that. If by metadata you mean eg
instruction in any computer can deal with infinity in any form, either

Everett L.(Rett) Williams II

Finite addition, subtraction, multiplication, and division are native
functions of all but the simplest computers, whether the computer is
self-aware or not, silly as that is to even discuss. What we are talking
about here is native instructions as opposed to algorithmic processes.
Since I have been programming computers for 44 years, I tend to think
that most people, at least in these parts understand the distinction. As
they say, if you don’t understand it, you can’t program it. And, your
understanding of it will be what is programmed. Most of us who have been
programming for more than five minutes know that we must limit our use
of an instruction to the finite limits of the hardware capability.
Programmers must constantly be aware that all processes must be bounded,
or programs may loop until stopped, a condition not desirable, at least
in my experience. There is both a quantitative and a qualitative
difference between using the basic capacities of hardware and
instruction sets, and overlaying on those extreme sets of logic not
amenable to any computation.

Everett L.(Rett) Williams II

Xavier N. wrote:

you don’t understand it, you can’t program it. And, your understanding of it

bytes are just electronics, we are the ones interpreting them in a
convenient and natural, but also arbitrary manner.

nihilism and solipsism are not much fun to discuss, even in a philosophy
forum, one of which this is not. There is a nice one-to-one
correspondence to a subset of basic math and boolean logic found in the
data storage, manipulation, and instruction set of all but the most
trivial modern computer chips. Skip the semantic games and move on.

Everett L.(REett) Williams II

On Thu, Dec 30, 2010 at 8:30 PM, Everett L Williams II
[email protected] wrote:

aware that all processes must be bounded, or programs may loop until
stopped, a condition not desirable, at least in my experience. There is both
a quantitative and a qualitative difference between using the basic
capacities of hardware and instruction sets, and overlaying on those extreme
sets of logic not amenable to any computation.

But don’t you realize you are doing an interpretation?

The computer knows nothing about numbers. The computer is a physical
machine, numbers are abstractions you are putting onto it.

I could say that for every representable n, any given native 4-bytes
represent the infinite number ∞ + n. By definition (∞ + n) + (∞ + m) =
∞ + (n + m).

There you have it, infinite quantities dealt with in a “finite”
computer.

My ∞ + 0 is no different than your vanilla 0 for a blank 4-bytes. The
bytes are just electronics, we are the ones interpreting them in a
convenient and natural, but also arbitrary manner.