Average Error: 37.3 → 29.3
Time: 20.3s
Precision: 64
Internal Precision: 3392
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
\[\begin{array}{l} \mathbf{if}\;im \le -5.091179905359637 \cdot 10^{-136}:\\ \;\;\;\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;im \le 2.3083132279679466 \cdot 10^{-174}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(-2 \cdot re\right)}\\ \mathbf{elif}\;im \le 1.5249588866331115 \cdot 10^{+29}:\\ \;\;\;\;\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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if im < -5.091179905359637e-136 or 2.3083132279679466e-174 < im < 1.5249588866331115e+29

    1. Initial program 33.6

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Initial simplification33.6

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

      \[\leadsto 0.5 \cdot \sqrt{\left(\color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}} - re\right) \cdot 2.0}\]
    5. Using strategy rm
    6. Applied sqrt-unprod33.6

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

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

    if -5.091179905359637e-136 < im < 2.3083132279679466e-174

    1. Initial program 41.5

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Initial simplification41.5

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

      \[\leadsto 0.5 \cdot \sqrt{\left(\color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}} - re\right) \cdot 2.0}\]
    5. Using strategy rm
    6. Applied sqrt-unprod41.5

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

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

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

    if 1.5249588866331115e+29 < im

    1. Initial program 41.6

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\]
    2. Initial simplification41.6

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

      \[\leadsto 0.5 \cdot \sqrt{\left(\color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}} - re\right) \cdot 2.0}\]
    5. Using strategy rm
    6. Applied sqrt-unprod41.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \le -5.091179905359637 \cdot 10^{-136}:\\ \;\;\;\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} - re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{elif}\;im \le 2.3083132279679466 \cdot 10^{-174}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(-2 \cdot re\right)}\\ \mathbf{elif}\;im \le 1.5249588866331115 \cdot 10^{+29}:\\ \;\;\;\;\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}\]

Runtime

Time bar (total: 20.3s)Debug logProfile

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