1. Handling Overflow When Doing Random Math

Andy Serpa wrote:
Begin quote: =====
I frankly wouldn't know to expect.  My program generates RANDOM
mathematical expressions.  They are all legal syntactically, but it is
up to me to use "safe" functions to keep everything in bounds so it
won't crash.  It is just a pain to debug your program using the
interpreter, then translate it and have it crash.  I'm not saying it
is
Euphoria's fault.

So I need a COMPLETE safe_power() function, it seems, that will
protect
me from overflows from any possible atoms (integer or floating point,
positive or negative) used for base and exponent.  Anyone?

-- Andy
End quote: =======

I wrote a program once in C that used "math-beings" in a genetic
algorithm to evolve equations from inputs.  Inaccurate beings were
treated the way nature treats inadequate lifeforms, of course.  It
worked, and the answers were interesting, even amusing -- the
algorithms were so unlike ours.  I wanted to develop this to include a
math parser, so the user could easily enter new formulas for the
program to try to match, but never got around to doing that.  The
distant ultimate goal was to have a "math-world" that could evolve
genuinely new math responses from inputs, where the formula was not
given (or even known).

I had 20 or so math functions (+, -, *, /, exp, abs, inv, etc) that
were called based on the randomly-generated numbers in the genetic
code of the beings.  The numbers generated were often huge (or hugely
tiny).  I had to fight the overflow problem constantly and never took
the time to do that job cleanly.  The point of all this is a question:
does anyone think there would be a simple way to confine specialized
randomly called math functions to numbers between -1 and +1 with a
scaling function?  This would be a loose analogy to core wars where
all the action is confined to a limited space.  I suspect there would
be precision issues here, but maybe that could be handled, at least
for the purposes of random math.  Thoughts? Comments?

--Quark

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu