Re: Forth PARANOIA



Marcel Hendrix wrote:
Krishna Myneni <krishnamyneni@xxxxxxxxxxxxx> writes Re: Forth PARANOIA
[..]
I ran paranoia on a few Forth systems.

Please keep in mind that there may still be bugs lurking in the Forth
translation. This was a difficult program to port, owing to its length,
and the need to take care not to unintentionally modify any arithmetic
expressions.

Paranoia reports a FLAW and a SERIOUS DEFECT on iForth.
I *think* (paranoia is unreadable) that the problem is rooted in what constitutes a "subexpression" for paranoia.

Paranoia announces:

| Extra-precise subexpressions are revealed but NOT YET tested.

Note that the error is "Addition/Subtraction/Sqr root neither rounds nor chops."

In C or Pascal, a final result of a function is assigned to a
typed variable. In Forth, the result will be on the stack, and
therefore doesn't have a single defined type. E.g. in iForth the FPU stack has 80 significant bits, but FVARIABLEs are IEEE doubles (64bit). That means that 1e 2e F+ has 80 significant bits, while with a F@ b F@ F+ c F! the variable c only has 64 significant bits.

The above could be handled by rounding every elementary FPU operation (f+ f* f/ fsqrt ..) to 64 bits, but costs one extra cycle (the mentioned
operations run in 1..3 cycles). Of course, iForth could make its FLOATs 80 bits, but that is incompatible with modern SSE2 hardware extensions
and OS libraries (all 64 bit) and consumes 1.5 the memory for neglible precision increase.

The iForth programmer should assign final DOUBLE results to a memory variable before using them further. If not, results could have 80 bits
of precision instead of 64. Some numeric algorithms could have problems with that.

-marcel
-- -------------------------------------------------------
...
Page: 6

Checking rounding on multiply, divide and add/subtract.
F* is neither chopped nor correctly rounded.
F/ is neither chopped nor correctly rounded.
Addition/Subtraction neither rounds nor chops.
Sticky bit used incorrectly or not at all.
FLAW lack(s) of guard digits or failure(s) to correctly round or chop (noted above) count as one flaw in the final tally below.

Does Multiplication commute? Testing on 20 random pairs.
No failures found in 20 integer pairs.

Running test of square root(x).
Testing if sqrt(X * X) == X for 20 Integers X.
Test for sqrt monotonicity.
sqrt has passed a test for Monotonicity.
Testing whether sqrt is rounded or chopped.
Square root is neither chopped nor correctly rounded.
Observed errors run from -4.779823e38 to 5.000000e-1 ulps.
SERIOUS sqrt gets too many last digits wrong.

...
FAILUREs encountered = 0
SERIOUS DEFECTs discovered = 1
DEFECTs discovered = 0
FLAWs discovered = 1


Below is the comparable output from kForth on x86/Linux, which does not
keep intermediate results, e.g. 1e 2e F+ in the hardware fpu stack, but
in a double cell (1 cell = 4 bytes) on the data stack. It has the same
issues with "Addition/Subtraction neither rounds nor chops" and with
"Square root is neither chopped nor correctly rounded", although no
SERIOUS defect is encountered with square root. What is odd is that in
your diagnostic message, observed errors run from *-4.779E38* to 0.5
ulps. Why the large number on the negative error?

Krishna

=================
... Page: 6

Checking rounding on multiply, divide and add/subtract.
F* is neither chopped nor correctly rounded.
F/ is neither chopped nor correctly rounded.
Addition/Subtraction neither rounds nor chops.
Sticky bit used incorrectly or not at all.
FLAW lack(s) of guard digits or failure(s) to correctly round or chop (noted above) count as one flaw in the final tally below.

Does Multiplication commute? Testing on 20 random pairs.
No failures found in 20 integer pairs.

Running test of square root(x).
Testing if sqrt(X * X) == X for 20 Integers X.
Test for sqrt monotonicity.
sqrt has passed a test for Monotonicity.
Testing whether sqrt is rounded or chopped.
Square root is neither chopped nor correctly rounded.
Observed errors run from -0.5 to 0.5 ulps.

....

Testing X^((X + 1) / (X - 1)) vs. exp(2) = 7.38906 as X -> 1.
DEFECT Calculated 7.38906 for
(1 + (-1.11022e-16 ) ^ (-1.80144e+16 );
differs from correct value by -3.44131e-09 This much error may spoil financial
calculations involving tiny interest rates.
Testing powers Z^Q at four nearly extreme values.
.... no discrepancies found.

....
FAILUREs encountered = 0 SERIOUS DEFECTs discovered = 0 DEFECTs discovered = 1 FLAWs discovered = 1

The arithmetic diagnosed may be Acceptable
despite inconvenient Defects.
END OF TEST.
ok
.



Relevant Pages

  • Re: Riemann surface
    ... function is the projection taking the x value. ... So, the sqrt function *is* ... globally defined analytic square root on C or on C without the origin. ... instead of just Z the complex plane that represents the y-component only. ...
    (sci.math)
  • Re: read string to float
    ... It can represent square root of 2 and any other real number. ... doesn't use (sqrt 2) as representation though. ... digit, untested) ... That's something like that reallib does. ...
    (comp.lang.lisp)
  • Re: the number of divisors, number theory
    ... sqrt is the square root of n. ... is always smaller than 2 time the sqrt of n). ... and that tau is a multiplicative function. ...
    (sci.math)
  • Re: solution to nonlinear eq
    ... b and g are unknown ... The following finds all possible non-negative integer solutions. ... I have assumed here that the 'sqrt' function gives an exact answer for the ... square root of any integer squared. ...
    (comp.soft-sys.matlab)
  • Re: solution to nonlinear eq
    ... b and g are unknown ... The following finds all possible non-negative integer solutions. ... I have assumed here that the 'sqrt' function gives an exact answer for the ... square root of any integer squared. ...
    (comp.soft-sys.matlab)

Loading