Average Error: 37.1 → 28.8
Time: 26.3s
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}\;re \le -3.700420673745336 \cdot 10^{+127}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 1.6130609402823183 \cdot 10^{-296}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{elif}\;re \le 1.3378356563173365 \cdot 10^{-270}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(im - re\right) \cdot 2.0}\\ \mathbf{elif}\;re \le 1.1094617218247845 \cdot 10^{+156}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 4 regimes
  2. if re < -3.700420673745336e+127

    1. Initial program 54.3

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

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

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

    if -3.700420673745336e+127 < re < 1.6130609402823183e-296 or 1.3378356563173365e-270 < re < 1.1094617218247845e+156

    1. Initial program 29.7

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

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}} - re\right)}\]
    4. Using strategy rm
    5. Applied rem-square-sqrt29.7

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

    if 1.6130609402823183e-296 < re < 1.3378356563173365e-270

    1. Initial program 35.0

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

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

    if 1.1094617218247845e+156 < re

    1. Initial program 62.3

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

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \color{blue}{0}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification28.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -3.700420673745336 \cdot 10^{+127}:\\ \;\;\;\;\sqrt{\left(-2 \cdot re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;re \le 1.6130609402823183 \cdot 10^{-296}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{elif}\;re \le 1.3378356563173365 \cdot 10^{-270}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(im - re\right) \cdot 2.0}\\ \mathbf{elif}\;re \le 1.1094617218247845 \cdot 10^{+156}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

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