Trajectories

James Edward Gray II wrote:

But that's where BigDecimal comes in. It's clearly a floating-point
number, but it's actually accurate. Semantically clear, numerically

If you put BigDecimal against Float, I'm pretty darn certain you will
notice a very real speed difference.

Ruby 1.8.7p72 on Mac OS 10.6.1:

$ time ruby -rbigdecimal -e "1000.times{x = BigDecimal.new('3.5') *
BigDecimal.new('4.2')}"

real 0m0.009s
user 0m0.005s
sys 0m0.003s

$ time ruby -rbigdecimal -e "a = BigDecimal.new('3.5'); b =
BigDecimal.new('4.2'); 1000.times{x = a * b}"

real 0m0.007s
user 0m0.004s
sys 0m0.003s

$ time ruby -e "1000.times{x = 3.5 * 4.2}"
real 0m0.008s
user 0m0.004s
sys 0m0.004s

Looks darn close to me.

James Edward Gray II

Best,

···

On Nov 14, 2009, at 7:41 PM, Marnen Laibow-Koser wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

I think Marnen originally was suggesting that the imprecisions will
stack, like an arrow at a target going more and more off course during
its flight, of course depending on the application. For some apps,
it's totally reasonable to see something go chaotic because of these
things.

For a short and unimportant game I'm playing, I wouldn't be upset.
But, for a game that takes 10's of hours and have it ride my butt
later at a crucial moment, I might just call that a bug.

Does the imprecision in the calculation stack in ballistic calcs? A
virtual magic bullet as it were? I'm not sure, but I'm guessing it
doesn't to great effect.

Todd

···

On Sun, Nov 15, 2009 at 5:32 PM, Eleanor McHugh <eleanor@games-with-brains.com> wrote:

On 15 Nov 2009, at 23:02, Marnen Laibow-Koser wrote:

Rick Denatale wrote:

When I was a young lad, it used to be that young programmers took a
semester long course on numerical analysis, which started with, and
continuously came back to dealing with the properties of floating
point numbers.

I guess that doesn't happen much anymore.

Again, I could do that or (more likely) find out how to do it. But why
bother when wise use of BigDecimal and Rational will completely obviate
the need?

The physical limitations imposed on arbitrary-precision decimal computation
by binary representation are something you should know *before* arguing that
one representation is better than another.

Eleanor McHugh wrote:

bother when wise use of BigDecimal and Rational will completely
obviate
the need?

The physical limitations imposed on arbitrary-precision decimal
computation by binary representation are something you should know
*before* arguing that one representation is better than another.

I am aware of the limitations. I believe I'm even fully aware of them.
:slight_smile: What do you think I have failed to take into account?

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason

Best,

···

On 15 Nov 2009, at 23:02, Marnen Laibow-Koser wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

Eleanor McHugh wrote:

major and going for a math major.
Also, I'll content that abstract algebra was about the best course
I've taken for helping the way I think about programming.

Too bad the CS students are all too busy trying to get their Java/C++
projects to compile :slight_smile:

Never hire a computer scientist if you can get a maths, physics or
philosophy grad instead :wink:

Yup. Or music. :smiley:

Ellie

Best,

···

On 17 Nov 2009, at 19:55, Gregory Brown wrote:

--
Marnen Laibow-Koser
Composer / Web developer
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

Don't want to hijack (these are all good qualities by the way, but
with a sardonic tone :slight_smile:

Maths grad: F equals MA if the axioms are founded
Phys grad: F does in "fact" equal MA no matter what
Philosophy grad: F equals MA only when it must
Engineering grad: F sometimes equals MA, but that's not the crux of the issue

···

On Tue, Nov 17, 2009 at 8:16 PM, Eleanor McHugh <eleanor@games-with-brains.com> wrote:

On 17 Nov 2009, at 19:55, Gregory Brown wrote:

On Sun, Nov 15, 2009 at 2:13 PM, Rick DeNatale <rick.denatale@gmail.com> wrote:

When I was a young lad, it used to be that young programmers took a
semester long course on numerical analysis, which started with, and
continuously came back to dealing with the properties of floating
point numbers.

I guess that doesn't happen much anymore.

I took numerical analysis, but ironically, only after dropping my CS
major and going for a math major.
Also, I'll content that abstract algebra was about the best course
I've taken for helping the way I think about programming.

Too bad the CS students are all too busy trying to get their Java/C++
projects to compile :slight_smile:

Never hire a computer scientist if you can get a maths, physics or philosophy grad instead :wink:

Marnen Laibow-Koser:

James Edward Gray II wrote:

If you put BigDecimal against Float, I'm pretty darn
certain you will notice a very real speed difference.

Ruby 1.8.7p72 on Mac OS 10.6.1:

$ time ruby -rbigdecimal -e "1000.times{x = BigDecimal.new('3.5') * BigDecimal.new('4.2')}"
real 0m0.009s
user 0m0.005s
sys 0m0.003s

$ time ruby -rbigdecimal -e "a = BigDecimal.new('3.5'); b = BigDecimal.new('4.2'); 1000.times{x = a * b}"
real 0m0.007s
user 0m0.004s
sys 0m0.003s

$ time ruby -e "1000.times{x = 3.5 * 4.2}"
real 0m0.008s
user 0m0.004s
sys 0m0.004s

Looks darn close to me.

When the time results are so small they don’t really mean anything:

shot@devielle:~$ ruby -v
ruby 1.9.1p243 (2009-07-16) [x86_64-linux]

shot@devielle:~$ time ruby -rbigdecimal -e "10_000_000.times{x = BigDecimal.new('3.5') * BigDecimal.new('4.2')}"
real 0m50.280s
user 0m47.719s
sys 0m0.112s

shot@devielle:~$ time ruby -rbigdecimal -e "a = BigDecimal.new('3.5'); b = BigDecimal.new('4.2'); 10_000_000.times{x = a * b}"
real 0m16.507s
user 0m14.213s
sys 0m0.020s

shot@devielle:~$ time ruby -e "10_000_000.times{x = 3.5 * 4.2}"
real 0m3.506s
user 0m2.960s
sys 0m0.008s

— Shot

···

--
Those that could learn¹ did, and those that couldn’t learn² were
sufficiently cowed to shut the fsck up and leave the rest of us alone.
¹ a surprisingly large fraction of the divisional workforce
² an appallingly large fraction of the divisional workforce
                                                        [Mike Andrews]

On Sun, Nov 15, 2009 at 5:32 PM, Eleanor McHugh

The physical limitations imposed on arbitrary-precision decimal computation
by binary representation are something you should know *before* arguing that
one representation is better than another.

I think Marnen originally was suggesting that the imprecisions will
stack, like an arrow at a target going more and more off course during
its flight, of course depending on the application. For some apps,
it's totally reasonable to see something go chaotic because of these
things.

This isn't an issue of chaotic behaviour (that has a very fixed meaning mathematically) but of unnoticeable error. The difference between 1e10-13 and 2e10-13 matters a lot when working on a system which needs to be accurate to a resolution of 1e10-14 but not when working to a resolution of 1e10-4. The additional nine decimal places tell us nothing meaningful in this latter case as we'll still end up rounding the result to zero.

For a short and unimportant game I'm playing, I wouldn't be upset.
But, for a game that takes 10's of hours and have it ride my butt
later at a crucial moment, I might just call that a bug.

That's not a bug but a fundamental outcome of the nature of binary coded non-integral numbers. Many rational non-integral numbers cannot be expressed accurately in binary representations, whilst binary coded decimal brings a whole host of other problems: lower information density, higher memory usage, and heavier processing load. BCD also does nothing to resolve the problem of how to represent irrational numbers such as π.

Does the imprecision in the calculation stack in ballistic calcs? A
virtual magic bullet as it were? I'm not sure, but I'm guessing it
doesn't to great effect.

The imprecision can indeed stack for complex ballistics systems, depending on the complexity of the forces involved. However to the extent of the precision chosen for performing these calculations the resultant inaccuracy is irrelevant.

Accuracy and precision - Wikipedia explains all of this in reasonable detail.

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

···

On 16 Nov 2009, at 01:12, Todd Benson wrote:
----
raise ArgumentError unless @reality.responds_to? :reason

Well I've known very few serious coders who didn't have a strong interest in music of one sort or another :slight_smile:

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

···

On 18 Nov 2009, at 02:30, Marnen Laibow-Koser wrote:

Eleanor McHugh wrote:

On 17 Nov 2009, at 19:55, Gregory Brown wrote:

major and going for a math major.
Also, I'll content that abstract algebra was about the best course
I've taken for helping the way I think about programming.

Too bad the CS students are all too busy trying to get their Java/C++
projects to compile :slight_smile:

Never hire a computer scientist if you can get a maths, physics or
philosophy grad instead :wink:

Yup. Or music. :smiley:

----
raise ArgumentError unless @reality.responds_to? :reason

Cultural studies graduate: Bourgeois hegemony constructs F as an
arbitrary signifier of MA.

I'll get my coat.

Rosie

···

On Wed, 2009-11-18 at 18:46 +0900, Todd Benson wrote:

On Tue, Nov 17, 2009 at 8:16 PM, Eleanor McHugh > <eleanor@games-with-brains.com> wrote:
> On 17 Nov 2009, at 19:55, Gregory Brown wrote:
>> On Sun, Nov 15, 2009 at 2:13 PM, Rick DeNatale <rick.denatale@gmail.com> wrote:
>>
>>> When I was a young lad, it used to be that young programmers took a
>>> semester long course on numerical analysis, which started with, and
>>> continuously came back to dealing with the properties of floating
>>> point numbers.
>>>
>>> I guess that doesn't happen much anymore.
>>
>> I took numerical analysis, but ironically, only after dropping my CS
>> major and going for a math major.
>> Also, I'll content that abstract algebra was about the best course
>> I've taken for helping the way I think about programming.
>>
>> Too bad the CS students are all too busy trying to get their Java/C++
>> projects to compile :slight_smile:
>
> Never hire a computer scientist if you can get a maths, physics or philosophy grad instead :wink:

Don't want to hijack (these are all good qualities by the way, but
with a sardonic tone :slight_smile:

Maths grad: F equals MA if the axioms are founded
Phys grad: F does in "fact" equal MA no matter what
Philosophy grad: F equals MA only when it must
Engineering grad: F sometimes equals MA, but that's not the crux of the issue

Todd Benson wrote:

I took numerical analysis, but ironically, only after dropping my CS
major and going for a math major.
Also, I'll content that abstract algebra was about the best course
I've taken for helping the way I think about programming.

Too bad the CS students are all too busy trying to get their Java/C++
projects to compile :slight_smile:

Never hire a computer scientist if you can get a maths, physics or philosophy grad instead :wink:

Don't want to hijack (these are all good qualities by the way, but
with a sardonic tone :slight_smile:

Maths grad: F equals MA if the axioms are founded
Phys grad: F does in "fact" equal MA no matter what
Philosophy grad: F equals MA only when it must
Engineering grad: F sometimes equals MA, but that's not the crux of the
issue

Hmmm...

Computer science: F = MA, but simple multiplication isn't OO enough, so
let's make an AbstractForceFactory...
XP: F = 3 always. When I need F to equal MA, I'll write a different
test.
Music: F is a M3rd below A.

Best,

···

On Tue, Nov 17, 2009 at 8:16 PM, Eleanor McHugh > <eleanor@games-with-brains.com> wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

--
Posted via http://www.ruby-forum.com/\.

Shot (Piotr Szotkowski) wrote:
[...]

When the time results are so small they don’t really mean anything:

shot@devielle:~$ ruby -v
ruby 1.9.1p243 (2009-07-16) [x86_64-linux]

shot@devielle:~$ time ruby -rbigdecimal -e "10_000_000.times{x =
BigDecimal.new('3.5') * BigDecimal.new('4.2')}"
real 0m50.280s
user 0m47.719s
sys 0m0.112s

[...]

Yeah, I tried longer runs as well and saw larger differences. I
question the applicability of those to actual programs, though; even
computationally intensive programs are going to be spending lots of time
doing things other than number crunching.

Besides, what good are fast calculations if they're wrong?

— Shot

Best,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

Eleanor McHugh wrote:

it's totally reasonable to see something go chaotic because of these
things.

This isn't an issue of chaotic behaviour (that has a very fixed
meaning mathematically) but of unnoticeable error. The difference
between 1e10-13 and 2e10-13 matters a lot when working on a system
which needs to be accurate to a resolution of 1e10-14 but not when
working to a resolution of 1e10-4. The additional nine decimal places
tell us nothing meaningful in this latter case as we'll still end up
rounding the result to zero.

For a short and unimportant game I'm playing, I wouldn't be upset.
But, for a game that takes 10's of hours and have it ride my butt
later at a crucial moment, I might just call that a bug.

That's not a bug but a fundamental outcome of the nature of binary
coded non-integral numbers.

If it gives you the wrong answer, it's a bug. Period. If your
representation cannot give you the precision you need for the task at
hand, then you need a different representation. Period. The end user
doesn't care about your representation -- he cares about getting the
right answer.

[...]

BCD also
does nothing to resolve the problem of how to represent irrational
numbers such as π.

No, becuase that's impossible to do with a finite representation AFAIK.
If I'm wrong, I would love to know how this can be done.

[...]

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason

Best,

···

On 16 Nov 2009, at 01:12, Todd Benson wrote:

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

On Sun, Nov 15, 2009 at 5:32 PM, Eleanor McHugh

This isn't an issue of chaotic behaviour (that has a very fixed meaning
mathematically) but of unnoticeable error.

I'm talking about result. A small difference in initial conditions
causes big problem.

The difference between 1e10-13
and 2e10-13 matters a lot when working on a system which needs to be
accurate to a resolution of 1e10-14 but not when working to a resolution of
1e10-4. The additional nine decimal places tell us nothing meaningful in
this latter case as we'll still end up rounding the result to zero.

Right, sort of. See below.

That's not a bug but a fundamental outcome of the nature of binary coded
non-integral numbers. Many rational non-integral numbers cannot be expressed
accurately in binary representations, whilst binary coded decimal brings a
whole host of other problems: lower information density, higher memory
usage, and heavier processing load. BCD also does nothing to resolve the
problem of how to represent irrational numbers such as π.

Ok, not a bug. Just makes you want to scream at somebody (yes the
game thing happened to me recently). The binary inaccuracy thing has
been beaten to death on this list, but you're right.

The imprecision can indeed stack for complex ballistics systems, depending
on the complexity of the forces involved. However to the extent of the
precision chosen for performing these calculations the resultant inaccuracy
is irrelevant.

I agree. I thought we were talking about a simple game. In any case,
small perversions in data (i.e. rounding beforehand) can cause certain
systems to go haywire. If you stay, for example, at 1e10-4 from the
beginning, you could end up with errors several orders of magnitude
higher, so the "just rounding to zero anyway" argument doesn't make
sense. This probably doesn't apply so much in a simple parabolic
equation, but the equation is still nonlinear, so one must be terribly
wary. Error analysis class was way too long ago, otherwise I'd give
an example. If somebody wants to step in, please do.

Accuracy and precision - Wikipedia explains all of this in
reasonable detail.

Ah, yes, the first thing you learn when studying engineering. I'm
guessing the only thing affected in the result would be accuracy.
Just a guess.

Todd

···

On Sun, Nov 15, 2009 at 8:22 PM, Eleanor McHugh <eleanor@games-with-brains.com> wrote:

On 16 Nov 2009, at 01:12, Todd Benson wrote:

Ah, so that's what cultural studies is :wink:

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

···

On 18 Nov 2009, at 13:15, Rosalind Mitchell wrote:

On Wed, 2009-11-18 at 18:46 +0900, Todd Benson wrote:

On Tue, Nov 17, 2009 at 8:16 PM, Eleanor McHugh >> <eleanor@games-with-brains.com> wrote:

Never hire a computer scientist if you can get a maths, physics or philosophy grad instead :wink:

Don't want to hijack (these are all good qualities by the way, but
with a sardonic tone :slight_smile:

Maths grad: F equals MA if the axioms are founded
Phys grad: F does in "fact" equal MA no matter what
Philosophy grad: F equals MA only when it must
Engineering grad: F sometimes equals MA, but that's not the crux of the issue

Cultural studies graduate: Bourgeois hegemony constructs F as an
arbitrary signifier of MA.

----
raise ArgumentError unless @reality.responds_to? :reason

You should include differences in frequency :slight_smile: That was a pretty cool
spot, though.

Todd

···

On Wed, Nov 18, 2009 at 11:15 AM, Marnen Laibow-Koser <marnen@marnen.org> wrote:

Hmmm...

Computer science: F = MA, but simple multiplication isn't OO enough, so
let's make an AbstractForceFactory...
XP: F = 3 always. When I need F to equal MA, I'll write a different
test.
Music: F is a M3rd below A.

Best,

Marnen Laibow-Koser:

Yeah, I tried longer runs as well and saw larger differences.
I question the applicability of those to actual programs, though;
even computationally intensive programs are going to be spending lots
of time doing things other than number crunching.

To clarify, I also believe BigDecimals should be used by default (when
one’s serious about the results’ acccuracy) until they are actually
determined to be a performance bottleneck. There even was a motion
to make them the language default, but the resolution was that
the performance cost was way too large, and that most (if not all)
other general-purpose languages default to IEEE floats for exactly
this reason.

Besides, what good are fast calculations if they're wrong?

Well, if they’re slightly wrong, but a couple of times faster, they
might be good enough; the previous example in this thread was IMHO
a good one – you don’t usually need accurate float arithmetics in
action games, but you do often care for the performance gain.

— Shot, who wouldn’t mind if Ruby defaulted to BigDecimals :slight_smile:

···

--
‘Is it just me, or does anyone else here find it vaguely
unsettling that you get your theology from Star Trek?’
‘Yeah, he should get it from B5 like us normal people.’
                     [Anthony DeBoer, Paul Tomblin, asr]

Eleanor McHugh wrote:

it's totally reasonable to see something go chaotic because of these
things.

This isn't an issue of chaotic behaviour (that has a very fixed
meaning mathematically) but of unnoticeable error. The difference
between 1e10-13 and 2e10-13 matters a lot when working on a system
which needs to be accurate to a resolution of 1e10-14 but not when
working to a resolution of 1e10-4. The additional nine decimal places
tell us nothing meaningful in this latter case as we'll still end up
rounding the result to zero.

For a short and unimportant game I'm playing, I wouldn't be upset.
But, for a game that takes 10's of hours and have it ride my butt
later at a crucial moment, I might just call that a bug.

That's not a bug but a fundamental outcome of the nature of binary
coded non-integral numbers.

If it gives you the wrong answer, it's a bug. Period. If your
representation cannot give you the precision you need for the task at
hand, then you need a different representation. Period. The end user
doesn't care about your representation -- he cares about getting the
right answer.

[...]

BCD also
does nothing to resolve the problem of how to represent irrational
numbers such as π.

No, becuase that's impossible to do with a finite representation AFAIK.
If I'm wrong, I would love to know how this can be done.

Your above two points appear to be in conflict with each other.

···

On Mon, Nov 16, 2009 at 2:57 AM, Marnen Laibow-Koser <marnen@marnen.org> wrote:

On 16 Nov 2009, at 01:12, Todd Benson wrote:

[...]

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

--
Paul Smith
http://www.nomadicfun.co.uk

paul@pollyandpaul.co.uk

Shot (Piotr Szotkowski) wrote:

Marnen Laibow-Koser:

Yeah, I tried longer runs as well and saw larger differences.
I question the applicability of those to actual programs, though;
even computationally intensive programs are going to be spending lots
of time doing things other than number crunching.

To clarify, I also believe BigDecimals should be used by default (when
one’s serious about the results’ acccuracy) until they are actually
determined to be a performance bottleneck.

Yes, this is what I was trying to say.

There even was a motion
to make them the language default, but the resolution was that
the performance cost was way too large, and that most (if not all)
other general-purpose languages default to IEEE floats for exactly
this reason.

Interesting.

Besides, what good are fast calculations if they're wrong?

Well, if they’re slightly wrong, but a couple of times faster, they
might be good enough; the previous example in this thread was IMHO
a good one – you don’t usually need accurate float arithmetics in
action games, but you do often care for the performance gain.

Perhaps. I would think you actually would want accurate math, but it
depends on the game.

— Shot, who wouldn’t mind if Ruby defaulted to BigDecimals :slight_smile:

Likewise.

Best,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

Paul Smith wrote:

tell us nothing meaningful in this latter case as we'll still end up

representation cannot give you the precision you need for the task at

Your above two points appear to be in conflict with each other.

Well, they're not "my" two points -- Eleanor wrote the first line, and I
think you missed the "if" on the second one.

···

On Mon, Nov 16, 2009 at 2:57 AM, Marnen Laibow-Koser <marnen@marnen.org> > wrote:

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

--
Paul Smith
http://www.nomadicfun.co.uk

paul@pollyandpaul.co.uk

--
Posted via http://www.ruby-forum.com/\.

Paul Smith wrote:

tell us nothing meaningful in this latter case as we'll still end up

representation cannot give you the precision you need for the task at

Your above two points appear to be in conflict with each other.

Well, they're not "my" two points -- Eleanor wrote the first line, and I
think you missed the "if" on the second one.

No, I really mean your two points.

On the one hand, you say "If it gives you the wrong answer, it's a
bug. Period. If your representation cannot give you the precision
you need for the task at hand, then you need a different
representation. Period."

Then you say "No, becuase [representing irrational numbers is]
impossible to do with a finite representation AFAIK. If I'm wrong, I
would love to know how this can be done."

···

On Mon, Nov 16, 2009 at 3:18 PM, Marnen Laibow-Koser <marnen@marnen.org> wrote:

On Mon, Nov 16, 2009 at 2:57 AM, Marnen Laibow-Koser <marnen@marnen.org> >> wrote:

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

--
Paul Smith
http://www.nomadicfun.co.uk

paul@pollyandpaul.co.uk

--
Posted via http://www.ruby-forum.com/\.

--
Paul Smith
http://www.nomadicfun.co.uk

paul@pollyandpaul.co.uk