    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Surreal Numbers</title>
        <link>https://members.accu.org/index.php/journals/729</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 8, #2 - Apr 1996 + Francis' Scribbles from CVu journal</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c136/">082</a>
                    (9)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c181/">Francis' Scribbles</a>
                    (29)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c136-181/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c136+181/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Surreal Numbers</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 April 1996 13:15:27 +01:00 or Wed, 03 April 1996 13:15:27 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a></h2>
</div>
<p>A few weeks ago there was an intense discussion on the
International C Standards reflector about introducing a built-in
complex number type in C9X. I suppose 95% of programmers have no
interest in such a type and most of the remaining 5% would be happy
with the kind of implementation that they will find in the C++
Standard Library. Just a few will be aware that there is an IEEE
specification for the complex type that includes such oddities as
infinities, signed zeroes and NaNs (not a number). What was the
point of the discussion? Well you cannot have a built-in type
<tt class="literal">complex</tt> that meets everyone's needs.</p>
<p>Does this mean that we should abandon such a type? Whatever your
answer, what can be done to provide the basic building blocks so
that those who have such specialist needs as signed zeroes can
construct what they need? This is not a trivial question, and
though it may be totally insignificant to the majority, it is of
vital concern to a small number. Our attitude to such minority
needs is important because many of us have needs for specialist
tools. As long as we can build them from the general bits that a
language makes available we will be quite happy. But that does not
mean we should discard the needs of others as no concern of
ours.</p>
<p>During the debate someone said '<span class="emphasis"><em>The
next thing you will be asking for is Conway's Surreals as
built-ins.</em></span>' Now that is a show stopper if ever I heard
one. Very few people will have the slightest idea as to what those
are. Before I give you a hint, a topic area where they are useful,
a short reading list and then a challenge let me explore a couple
of other oddities.</p>
<p>C specifies that the representation of integers shall be binary
with the possible exception of the high order bit. There are at
least three different ways that negative integers can be
represented.</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Sign and value - the high bit gives the sign and the rest is the
absolute value. To negate a number just flip the high bit.</p>
</li>
<li>
<p>1's compliment - the bit patterns for negative numbers are those
for positive ones with all the bits inverted. To negate a number
flip all the bits</p>
</li>
<li>
<p>2's compliment - difficult to define but the result is that to
negate a number flip all the bits then add 1 to the result.</p>
</li>
</ul>
</div>
<p>In all three systems negative numbers are identified by the high
bit being set. Both the first two methods provide a signed zero.
The third method has a number of advantages for hardware, not least
that the number system wraps around. The bit pattern for the most
negative number is the successor to that for the most positive.
This version is so widespread that many programmers think that it
is the only representation of signed integers. Note that the
representation has serious implications when you come to apply bit
operations to negative integers.</p>
<p>The above is pretty old hat and is largely the consequence of
trying to represent positive and negative numbers with a single
sensible set of bit patterns. How many of you know that mathematics
has no need for a negative sign? Some time in the fifties a young
mathematician (sorry, I have forgotten who) realised that negative
binary is an entirely valid numerical system that requires no
symbol for negative. Let me list a few values in negative binary
(I'll just use 4-bits for simplicity):</p>
<div class="table"><a name="d0e48" id="d0e48"></a>
<p class="title c3">Table 1. </p>
<table summary="" border="1">
&lt;colgroup&gt;
&lt;col class=&quot;c4&quot;&gt;
&lt;col class=&quot;c4&quot;&gt;
&lt;col class=&quot;c4&quot;&gt;
&lt;col class=&quot;c4&quot;&gt;
&lt;col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
<tr>
<td align="center">-8's (-2)^3</td>
<td align="center">4's (-2)^2</td>
<td align="center">-2's (-2)^1</td>
<td align="center">1's (-2)^0</td>
<td>value</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td>0</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">1</td>
<td>1</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">0</td>
<td>-2</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">1</td>
<td>-1</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">0</td>
<td>4</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">1</td>
<td>5</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">0</td>
<td>2</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td>3</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
<td>-8</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">1</td>
<td>-7</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">0</td>
<td>-10</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">1</td>
<td>-9</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">0</td>
<td>-4</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">1</td>
<td>-3</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">0</td>
<td>-6</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td>-5</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>I am quite sure that this representation of numbers would be
ruled out by C on the grounds that negative binary is not a binary
system, but I wonder if they even thought about it. It does have
the advantage that there is no artificial convention for
identifying negative numbers (rather like a natural language that
has no word for 'true' but uses 'false false')- that is about its
only advantage and the system is quite unsuitable for ordinary
arithmetic (that does not mean that there might not be some problem
domain where such a representation makes otherwise obscure
solutions 'obvious'). So far we have only been talking about
representations, the underlying set of values represented remains
the same.</p>
<p>In inventing (I think that is appropriate, rather than
discovering) <span class="bold"><b>Surreal Numbers</b></span> Dr
Conway (<span class="emphasis"><em>probably best known for being
the inventor of 'Life', but he has a vivid inventive mind and
delights in producing instructive games that are fun to play. He
was also the inventor of 'Sprouts' and when it had become the most
popular leisure pursuit at Cambridge, under pressure invented
'Brussels Sprouts'. One is a challenging intellectual game the
other is a total waste of time, the problem was that it took the
students two weeks to discover that while Dr Conway smiled happily
in temporary peace.</em></span>) produced something arcane that was
much more than a weird way of deriving number. This is not the
place to try to summarise what took him over 200 pages
(<span class="emphasis"><em>On Numbers and Games - Academic Press 0
12 186350 6</em></span>) to describe. All I will say here is that
<span class="bold"><b>Surreal Numbers</b></span> include all the
more traditional real numbers as well as an unlimited range of new
ones (no, I am not talking about traditional infinities). The
second part of the book shows how <span class="bold"><b>Surreal
Numbers</b></span> can be given meaningful interpretations and
represent a particular kind of information.</p>
<p>Surreals are of significant and useful in analysing strategies
in complete knowledge games. Most of you are familiar with the game
of nim. Some of you may know how to analyse a nim position to
determine whether it is a winning one (perfect play will result in
a win for the person next to play) or a losing one. Of course the
best methods will not only determine that a position is a winning
one, but what move you should make.</p>
<p>As it is nearing Christmas (well it was when I first wrote this)
let me give you a couple of nim type games. First take the opening
game from Winning Ways (a two volume work by Berlekamp, Conway and
Guy, Academic Press, 0 12 091101 9 &amp; 0 12 091102 7) called
Blue-Red Hackenbush. You have a stick picture (like the one on this
page) in which the lines joining nodes are either blue (continuous)
or red (broken). In turn two players choose a line of their own
colour to remove. After the chosen line has been removed, any part
of the drawing that is no longer connected to the ground by some
continuous route (without regard to the colour of the arcs) is also
removed.</p>
<div class="figure"><a name="d0e267" id="d0e267"></a>
<p class="title c3">Figure 1. </p>
<div class="mediaobject"><img src=
"/var/uploads/journals/resources/stick_figure.jpg"></div>
</div>
<p>Suppose that you have a choice of first move, or colour, which
choices should you make. That is, does the first player win (lose)
regardless as to colour or does one colour win (lose) regardless of
who has first move?</p>
<p>Winning ways is a two volume work using <span class=
"bold"><b>Surreal Numbers</b></span> to answer such questions.</p>
<p>Here's one more game for fun. Lay out five rows of five
matchsticks (counters or whatever). When it is your move you may
remove an entire row or column of contiguous matches. So the first
move must be to select any single row (column) of five matches. But
after this move the layout will normally be in two (exceptionally
if a boundary row or column has been removed it will still be in
one part) disparate parts. Now you can remove a whole contiguous
row or column from either part (but not both) and so on until there
are no more matches left. Last to move wins. If both players play
perfectly, should the first to play win or lose?</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e281" id=
"d0e281"></a>Challenges</h2>
</div>
<p>Write a program to play this last game. (Hint, generalise the
problem. Yes its tougher than it looks, which is why <span class=
"bold"><b>Surreal Numbers</b></span> are useful)</p>
<p>Write a program to play Red-Blue Hackenbush (Well you might
start by writing a program that can display a bi-coloured graph -
network to the non-mathematicians - such as the crude diagram
here.)</p>
<p>(By the way, those that want ideas for strategy type computer
games might find 'Winning Ways' an excellent source of inspiration
and programming perfect strategies for the computer would teach you
a lot about this kind of task.)</p>
<p>Go out and find a copy of either of the books mentioned above
(or there is a book called Surreal Numbers but I have no other
details) and start to develop a <span class=
"bold"><b>Surreal</b></span> type in C++.</p>
<p>One last thing, both books are a mixture of deep maths and pure
fun, but that is typical of much of Dr Conway's work. His automata
game, 'Life', gave much pleasure to those that just played with it
while requiring several (I think it was more than ten) years of
expert analysis to determine if it met the full target criteria
(can you build a programmable computer out of Life cells would be
one phrasing of the critical question? The answer is yes but that
is another story)</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
