Average Error: 37.5 → 29.4
Time: 25.4s
Precision: 64
Internal Precision: 128
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
\[\begin{array}{l} \mathbf{if}\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0} \le 1.1467506651561026 \cdot 10^{+77}:\\ \;\;\;\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(im - re\right)}\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 2 regimes
  2. if (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) < 1.1467506651561026e+77

    1. Initial program 16.5

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]

    if 1.1467506651561026e+77 < (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))

    1. Initial program 61.6

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Taylor expanded around 0 44.2

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \color{blue}{\left(im - re\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification29.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0} \le 1.1467506651561026 \cdot 10^{+77}:\\ \;\;\;\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(im - re\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019090 
(FPCore (re im)
  :name "math.sqrt on complex, imaginary part, im greater than 0 branch"
  (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))