Average Error: 37.7 → 29.7
Time: 21.6s
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}\;im \cdot im \le 1.1482653376689949 \cdot 10^{-262}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(re \cdot -2\right) \cdot 2.0}\\ \mathbf{elif}\;im \cdot im \le 1.0548611829945029 \cdot 10^{+282}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(im - re\right)} \cdot 0.5\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 3 regimes
  2. if (* im im) < 1.1482653376689949e-262

    1. Initial program 42.2

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

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \color{blue}{\left(-2 \cdot re\right)}}\]

    if 1.1482653376689949e-262 < (* im im) < 1.0548611829945029e+282

    1. Initial program 22.7

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

    if 1.0548611829945029e+282 < (* im im)

    1. Initial program 57.4

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt57.4

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{\left(\sqrt[3]{re \cdot re + im \cdot im} \cdot \sqrt[3]{re \cdot re + im \cdot im}\right) \cdot \sqrt[3]{re \cdot re + im \cdot im}}} - re\right)}\]
    4. Taylor expanded around 0 34.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \cdot im \le 1.1482653376689949 \cdot 10^{-262}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(re \cdot -2\right) \cdot 2.0}\\ \mathbf{elif}\;im \cdot im \le 1.0548611829945029 \cdot 10^{+282}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(im - re\right)} \cdot 0.5\\ \end{array}\]

Reproduce

herbie shell --seed 2019050 
(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)))))