bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-apl] Unexpected results for the power function


From: Frederick H. Pitts
Subject: [Bug-apl] Unexpected results for the power function
Date: Wed, 23 Jul 2014 11:16:37 -0500

Jurgen,

        The last comment in the listing below summarizes the issue.  The input
file for the listing is attached.

Regards

Fred
Retired Chemical Engineer
 

      ⎕PP ← 16
      ⍝ Compute first 5, 14th, 15th, 70th and 71th Fibonacci numbers
using
      ⍝ Binet's formula
(http://www.math.rutgers.edu/~erowland/fibonacci.html)
      ⍝ Desired results:
      ⍝ 1 1 2 3 5 377 610 190392490709135 308061521170129
      
      R ← 1 2 3 4 5 14 15 70 71
      R5 ← 5 ⋆ .5
      P5 ← 1 + R5
      M5 ← 1 - R5
      ⍝ Using repeated multiplication to compute the powers gives valid
answers
      ⍝ up to the 70th number after rounding. Maybe this result is the
best one
      ⍝ can expect from double precision arithmetic.
      ( ( ( ×/ )¨ R ⍴¨ P5 ) - ( ( ×/ )¨ R ⍴¨ M5 ) ) ÷ R5 × ( ×/ )¨ R ⍴¨
2
1 1 2 3 5 377.0000000000001 610.0000000000003 190392490709135.4 
      308061521170129.7
      ⍝ Using the APL ⋆ operator to compute the powers gives valid
answers only
      ⍝ up to the 14th number.  The 15th number is no where near
correct.
      ⍝ Shouldn't the ⋆ operator results match the repeated
multiplication
      ⍝ results more closely?
      ( ( P5 ⋆ R ) - M5 ⋆ R ) ÷ R5 × 2 ⋆ R
1 1 2 3 5 377.0000000000002 0.001639344262295081 5.252307989014705E¯15 
      3.246104856593697E¯15

Attachment: fib0.apl
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]