Velocity Reviews > Quasi 0

# Quasi 0

David RF
Guest
Posts: n/a

 06-04-2012
On 4 jun, 13:10, James Kuyper <(E-Mail Removed)> wrote:
> On 06/04/2012 06:05 AM, David RF wrote:
>
> > On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
> >> David RF wrote:
> >>> Is this a good method for test the equality?

>
> >> If you're bored on a rainy afternoon, you can read David Goldberg's
> >> looong article on FP arithmetic.

>
> >>http://docs.oracle.com/cd/E19957-01/..._goldberg.html

>
> > Can you link to someone else's website where formulas do not mix
> > letters and numbers?

>
> Such formulas are the clearest and most natural way to describe the
> concepts being discussed. If your mathematical background is not
> sufficiently advanced for you to be able to understand such formulas,
> it's also insufficient to understand the corresponding concepts. You
> should wait until you've learned some algebra before attempting to read
> things like this. If you've already tried to learn algebra, and came
> away with an aversion to it, you should consider avoiding technically
> oriented career paths such as computer programming.

I'm asking for the simplest way to detect round errors due to binary
representation
of floating numbers. learn algebra? career? you assume too much

BartC
Guest
Posts: n/a

 06-04-2012
"Eric Sosman" <(E-Mail Removed)> wrote in message
news:jqi3ur\$u1d\$(E-Mail Removed)...
> On 6/4/2012 5:32 AM, David RF wrote:

>> Is this a good method for test the equality?

>
> No.

>consider the values 1E-20 and 1E-30: They differ
> by much less than the typical DBL_EPSILON, yet one is ten billion
> times the other. Do you want to consider a ten billion-fold
> discrepancy "equal?"

I remember having a similar conversation with my bank: I was suggesting that
a 0.1% interest rate was, to all intents and purposes, a zero interest rate;
they insisted on still calling it an interest-bearing account.

Of course, from their point of view, it was still returning an infinitely
higher amount of interest than the zero-rated one, even after tax.

--
Bartc

James Kuyper
Guest
Posts: n/a

 06-04-2012
On 06/04/2012 05:32 AM, David RF wrote:
> Hi friends:
> Machine epsilon is the maximum relative error of the chosen rounding
> procedure
>
> #include <stdio.h>
> #include <math.h>
> #include <float.h>
>
> int main(void)
> {
> double a = 0.1;
> double b = 0.1;
>
> a += 1.0;
> a -= 1.0;
>
> printf("a == b = %s\n", a == b ? "equals" : "unequals");
> printf("a == b = %s\n", fabs(a - b) < DBL_EPSILON ? "equals" :
> "unequals");
> return 0;
> }
>
> Is this a good method for test the equality?

Not particularly.

First of all, it's not a test for equality, that's simply done in C by
the == operator. It's a test for near-equality. It's seldom correct to
test floating point values for equality with each other; it's sometimes
appropriate to compare them for approximate equality, but you should
always be sure that it actually is appropriate.

The general form for conducting approximate equality tests is

fabs(a-b) < epsilon

where epsilon will, in general, have different values for different
comparisons.

You correctly described machine epsilon as describing a relative error.
That means that you should not use DBL_EPSILON directly. If the only
source of error in you calculations was a single floating point roundoff
error, you should scale it according to the numbers being compared, by
multiplying it by fabs(a) or fabs(b), whichever is larger.

If multiple floating point errors are involved (as, for instance, with
a+=1.0 and a-=1.0 in your example), then the calculation of the
appropriate value for epsilon gets more complicated. If any of the
quantities you compare are measurements, or numbers calculated from
measurements, measurement error is likely to be much larger than
floating point round-off error.

There's a subject called "propagation of errors" or "propagation of
uncertainty), which is essentially devoted to determining the correct
way of calculating the appropriate value to use for epsilon in such
contexts. The corresponding wikipedia page is at least as good a place
to start learning about that subject as any other.
--
James Kuyper

David RF
Guest
Posts: n/a

 06-04-2012
On 4 jun, 13:48, David RF <(E-Mail Removed)> wrote:
> On 4 jun, 13:10, James Kuyper <(E-Mail Removed)> wrote:
>
>
>
> > On 06/04/2012 06:05 AM, David RF wrote:

>
> > > On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
> > >> David RF wrote:
> > >>> Is this a good method for test the equality?

>
> > >> If you're bored on a rainy afternoon, you can read David Goldberg's
> > >> looong article on FP arithmetic.

>
> > >>http://docs.oracle.com/cd/E19957-01/..._goldberg.html

>
> > > Can you link to someone else's website where formulas do not mix
> > > letters and numbers?

>
> > Such formulas are the clearest and most natural way to describe the
> > concepts being discussed. If your mathematical background is not
> > sufficiently advanced for you to be able to understand such formulas,
> > it's also insufficient to understand the corresponding concepts. You
> > should wait until you've learned some algebra before attempting to read
> > things like this. If you've already tried to learn algebra, and came
> > away with an aversion to it, you should consider avoiding technically
> > oriented career paths such as computer programming.

>
> I'm asking for the simplest way to detect round errors due to binary
> representation
> of floating numbers. learn algebra? career? you assume too much

representation of floating point numbers, excuse my poor english

David RF
Guest
Posts: n/a

 06-04-2012
On 4 jun, 13:55, James Kuyper <(E-Mail Removed)> wrote:

[snip ...]
> If multiple floating point errors are involved (as, for instance, with
> a+=1.0 and a-=1.0 in your example), then the calculation of the
> appropriate value for epsilon gets more complicated. If any of the
> quantities you compare are measurements, or numbers calculated from
> measurements, measurement error is likely to be much larger than
> floating point round-off error.

Thanks

Keith Thompson
Guest
Posts: n/a

 06-04-2012
"BartC" <(E-Mail Removed)> writes:
> "David RF" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> On 4 jun, 13:10, James Kuyper <(E-Mail Removed)> wrote:

>
>> I'm asking for the simplest way to detect round errors due to binary
>> representation
>> of floating numbers. learn algebra? career? you assume too much

>
> The simplest way is to test whether the absolute difference between two
> numbers, is less than some threshold such as 0.0001.
>
> What the best value of that should be, and whether having a fixed limit at
> all would work, depends on your application.
>
> If you want to test whether two results are equal, allowing for minor
> rounding errors, then that's a little different, especially if possible
> results cover a wide range of magnitudes. Here you really want to ignore the
> last few bits of the floating point representation, but it gets tricky to do
> and you need a bit of background.

Ideally, the nature of the test for near-equality needs to reflect the
nature of the computation(s) that created the error.

A simple test like

abs(x - y) <= 0.0001

is sensible only in limited circumstances. Sometimes it makes sense to
test for an absolute difference, sometimes it makes sense to test the
ratio, and sometimes you really need something more complicated.

The question you're trying to answer is whether the discrepancy between
two floating-point values reflects an actual mathematical difference or
a rounding error. Determining that, even imperfectly, requires an
understanding of what errors the computation(s) *could* have produced.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

nick_keighley_nospam@hotmail.com
Guest
Posts: n/a

 06-05-2012
On Monday, June 4, 2012 12:10:24 PM UTC+1, James Kuyper wrote:
> On 06/04/2012 06:05 AM, David RF wrote:
> > On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:
> >> David RF wrote:

> >> If you're bored on a rainy afternoon, you can read David Goldberg's
> >> looong article on FP arithmetic.
> >>
> >> http://docs.oracle.com/cd/E19957-01/..._goldberg.html

excellent stuff. I must re-read it.

> > Can you link to someone else's website where formulas do not mix
> > letters and numbers?

>
> Such formulas are the clearest and most natural way to describe the
> concepts being discussed. If your mathematical background is not
> sufficiently advanced for you to be able to understand such formulas,
> it's also insufficient to understand the corresponding concepts. You
> should wait until you've learned some algebra before attempting to read
> things like this.

doesn't everyone's education include basic algebra?

> If you've already tried to learn algebra, and came
> away with an aversion to it,

I never quite understood this, though I've encounterd it. It's like there's a conceptual hole in their brain so that they can't take the abstraction step to encompass algebra. Actual neural architecture or just bad teaching?

> you should consider avoiding technically
> oriented career paths such as computer programming.

I'm not sure i'd go that far. you can do quite a lot without algebra. Though floating point arithmatic sounds to be pushing it!

James Kuyper
Guest
Posts: n/a

 06-05-2012
On 06/05/2012 06:54 AM, (E-Mail Removed) wrote:
> On Monday, June 4, 2012 12:10:24 PM UTC+1, James Kuyper wrote:
>> On 06/04/2012 06:05 AM, David RF wrote:
>>> On 4 jun, 11:56, Noob <r...@127.0.0.1> wrote:

....
>>>> http://docs.oracle.com/cd/E19957-01/..._goldberg.html

....
>>> Can you link to someone else's website where formulas do not mix
>>> letters and numbers?

>>
>> Such formulas are the clearest and most natural way to describe the
>> concepts being discussed. If your mathematical background is not
>> sufficiently advanced for you to be able to understand such formulas,
>> it's also insufficient to understand the corresponding concepts. You
>> should wait until you've learned some algebra before attempting to read
>> things like this.

>
> doesn't everyone's education include basic algebra?

People as young as six are learning to program nowadays; possibly
younger. The simplest explanation for his desire for "formulas [that] do
not mix letters and numbers" is that he hasn't taken algebra yet. I'm
not assuming he's that young, but I did consider the possibility. The
complexity of the language in his messages is near the upper limit of
what I'd expect such a young person to be capable of, but it's not over
that limit. The second simplest explanation is that he took algebra, but
failed to master it.

>> If you've already tried to learn algebra, and came
>> away with an aversion to it,

>
> I never quite understood this, though I've encounterd it. It's like there's a conceptual hole in their brain so that they can't take the abstraction step to encompass algebra. Actual neural architecture or just bad teaching?

I used to tutor math and science for undergrads at community college.
The ones who needed tutoring were often taking math or science classes
to meet a requirement, rather than because they found them interesting.
I ran into all kinds of math phobia. As a math lover, I never fully
understood it, but I did develop some helpful techniques for explaining
things to such people.

>> you should consider avoiding technically
>> oriented career paths such as computer programming.

>
> I'm not sure i'd go that far. you can do quite a lot without algebra. Though floating point arithmatic sounds to be pushing it!

That why I inserted the weasel words "consider" and "avoid".
--
James Kuyper

Joe keane
Guest
Posts: n/a

 06-05-2012
In article <(E-Mail Removed)>,
<(E-Mail Removed)> wrote:
>Actual neural architecture or just bad teaching?

the second one!

i used to [very long time ago] tutor kids

the kids are smart, it's the adults who are missing some knifes

i'm like go from basic algebra to understanding calculus in a few weeks

no prob, let's go

Stefan Ram
Guest
Posts: n/a

 06-05-2012
James Kuyper <(E-Mail Removed)> writes:
>People as young as six are learning to program nowadays; possibly
>younger.

Six year olds still can actually write a program to
draw a circle, while older children cannot!

(Alan Kay was teaching five-year old children how to
program a circle: They were asked to walk in a circle
and to report what they did. The children would answer
"walk a little and turn a little." After that cognition
they could write a program to draw a circle.

Ten-year old children already knew what a circle is:
"The set of all point, having the same distance to a
center." So they startet to program individual points
starting at a center, which was more complicated; and
the result was non a connected circle but only single
dots.

Fifteen-year old children already knew the formula »r² = x² + y²«.
They tried to draw a circle using that formula, but
failed. (This formula is not a good starting point for such a
program.) Just because of their additional knowledge, it was
actually more difficult or impossible for them to write such a
program. At least that is what Alan Kay said in a video.)