Average Error: 29.9 → 14.3
Time: 7.9s
Precision: 64
Internal precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;im \le -1.1496000680102836 \cdot 10^{+163}:\\ \;\;\;\;-im\\ \mathbf{if}\;im \le 4.692828868299432 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{{im}^2 + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;im\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 3 regimes.
  2. if im < -1.1496000680102836e+163

    1. Initial program 59.5

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Applied simplify 59.5

      \[\leadsto \color{blue}{\sqrt{{im}^2 + re \cdot re}}\]
    3. Applied taylor 0

      \[\leadsto -1 \cdot im\]
    4. Taylor expanded around -inf 0

      \[\leadsto \color{blue}{-1 \cdot im}\]
    5. Applied simplify 0

      \[\leadsto \color{blue}{-im}\]

    if -1.1496000680102836e+163 < im < 4.692828868299432e+91

    1. Initial program 20.4

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Applied simplify 20.4

      \[\leadsto \color{blue}{\sqrt{{im}^2 + re \cdot re}}\]

    if 4.692828868299432e+91 < im

    1. Initial program 47.2

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Applied simplify 47.2

      \[\leadsto \color{blue}{\sqrt{{im}^2 + re \cdot re}}\]
    3. Applied taylor 0

      \[\leadsto im\]
    4. Taylor expanded around inf 0

      \[\leadsto \color{blue}{im}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 7.9s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(3132427909 2405578827 4278482967 2215509689 1521496148 2758201993)'
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))