Page 1 of 1

adventures in code coverage: Newton iteration failure

Posted: Wed Nov 25, 2020 6:57 pm
by Roger|Dyalog
In f⍣¯1⊢⍵ (the inverse of f) Newton iteration is employed for certain operands f. The code quits if the iteration still has not converged after 1000 iterations, at which point a DOMAIN ERROR is signaled. For code coverage how is the DOMAIN ERROR to be reached?

      {11::⍵ ⋄ 0⊣!⍣¯1⊢⍵}¨ 10*90+⍳10
1E90 1E91 1E92 1E93 1E94 1E95 1E96 0 1E98 0

!⍣¯1 ⊢1e90
DOMAIN ERROR
!⍣¯1 ⊢1E90

A non-zero value means the Newton iteration ran into trouble, or did not terminate after 1000 iterations. These values serve to reach the DOMAIN ERROR until the time (if ever) when !⍣¯1 is improved. For example:

      factInv ← {⍵ {⍵-(fx-⍺)÷((!⍵×1+d)-fx←!⍵)÷⍵×d←1e¯6}⍣≡ (!⍳171)⍸⍵}

⊢ a← factInv¨ 10*90+⍳10
64.495 65.0461 65.596 66.1449 66.6926 67.2394 67.785 68.3297 68.8733 69.4159

!a
1E90 1E91 1E92 1E93 1E94 1E95 1E96 1E97 1E98 1E99

By the way:

      cmpx '!⍣¯1 ⊢100' 'factInv 100'
!⍣¯1 ⊢100 → 9.53E¯4 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
factInv 100 → 4.88E¯5 | -95% ⎕⎕