Average Error: 37.4 → 21.0
Time: 1.0m
Precision: 64
Internal Precision: 3648
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
\[\begin{array}{l} \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le -1.5719872873895795 \cdot 10^{+171}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1.0}{\frac{-1}{im}} \cdot \frac{\frac{-1}{re}}{\frac{-1}{im}}}\\ \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le -6.314044412187757 \cdot 10^{-271}:\\ \;\;\;\;\frac{\sqrt{\left(2.0 \cdot im\right) \cdot im}}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}} \cdot 0.5\\ \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le 1.4828868948050535 \cdot 10^{-201}:\\ \;\;\;\;\sqrt{\left(re + re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le 2.6290378242455047 \cdot 10^{-147} \lor \neg \left(\left(im + re\right) \cdot 2.0 \le 1.467254064795174 \cdot 10^{+145}\right):\\ \;\;\;\;0.5 \cdot \sqrt{\left(im + re\right) \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(re + \sqrt{im \cdot im + re \cdot re}\right)} \cdot 0.5\\ \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

Target

Original37.4
Target32.4
Herbie21.0
\[\begin{array}{l} \mathbf{if}\;re \lt 0:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{\sqrt{re \cdot re + im \cdot im} - re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \end{array}\]

Derivation

  1. Split input into 5 regimes
  2. if (* 2.0 (+ im re)) < -1.5719872873895795e+171

    1. Initial program 61.9

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

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

      \[\leadsto 0.5 \cdot \sqrt{e^{\color{blue}{\left(\log \left(\frac{-1}{re}\right) + \log 1.0\right) - 2 \cdot \log \left(\frac{-1}{im}\right)}}}\]
    5. Applied simplify40.2

      \[\leadsto \color{blue}{\sqrt{\frac{\frac{-1}{re}}{\frac{-1}{im}} \cdot \frac{1.0}{\frac{-1}{im}}} \cdot 0.5}\]

    if -1.5719872873895795e+171 < (* 2.0 (+ im re)) < -6.314044412187757e-271

    1. Initial program 33.9

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{e^{\log \left(2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)\right)}}}\]
    4. Using strategy rm
    5. Applied flip-+35.4

      \[\leadsto 0.5 \cdot \sqrt{e^{\log \left(2.0 \cdot \color{blue}{\frac{\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re}{\sqrt{re \cdot re + im \cdot im} - re}}\right)}}\]
    6. Applied associate-*r/35.5

      \[\leadsto 0.5 \cdot \sqrt{e^{\log \color{blue}{\left(\frac{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)}{\sqrt{re \cdot re + im \cdot im} - re}\right)}}}\]
    7. Applied log-div35.8

      \[\leadsto 0.5 \cdot \sqrt{e^{\color{blue}{\log \left(2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)\right) - \log \left(\sqrt{re \cdot re + im \cdot im} - re\right)}}}\]
    8. Applied exp-diff35.8

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{e^{\log \left(2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)\right)}}{e^{\log \left(\sqrt{re \cdot re + im \cdot im} - re\right)}}}}\]
    9. Applied sqrt-div35.8

      \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{e^{\log \left(2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)\right)}}}{\sqrt{e^{\log \left(\sqrt{re \cdot re + im \cdot im} - re\right)}}}}\]
    10. Applied simplify22.6

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im \cdot \left(im \cdot 2.0\right)}}}{\sqrt{e^{\log \left(\sqrt{re \cdot re + im \cdot im} - re\right)}}}\]
    11. Applied simplify20.4

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

    if -6.314044412187757e-271 < (* 2.0 (+ im re)) < 1.4828868948050535e-201

    1. Initial program 55.7

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

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

    if 1.4828868948050535e-201 < (* 2.0 (+ im re)) < 2.6290378242455047e-147 or 1.467254064795174e+145 < (* 2.0 (+ im re))

    1. Initial program 57.0

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

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

    if 2.6290378242455047e-147 < (* 2.0 (+ im re)) < 1.467254064795174e+145

    1. Initial program 0.0

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
  3. Recombined 5 regimes into one program.
  4. Applied simplify21.0

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le -1.5719872873895795 \cdot 10^{+171}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1.0}{\frac{-1}{im}} \cdot \frac{\frac{-1}{re}}{\frac{-1}{im}}}\\ \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le -6.314044412187757 \cdot 10^{-271}:\\ \;\;\;\;\frac{\sqrt{\left(2.0 \cdot im\right) \cdot im}}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}} \cdot 0.5\\ \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le 1.4828868948050535 \cdot 10^{-201}:\\ \;\;\;\;\sqrt{\left(re + re\right) \cdot 2.0} \cdot 0.5\\ \mathbf{if}\;\left(im + re\right) \cdot 2.0 \le 2.6290378242455047 \cdot 10^{-147} \lor \neg \left(\left(im + re\right) \cdot 2.0 \le 1.467254064795174 \cdot 10^{+145}\right):\\ \;\;\;\;0.5 \cdot \sqrt{\left(im + re\right) \cdot 2.0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(re + \sqrt{im \cdot im + re \cdot re}\right)} \cdot 0.5\\ \end{array}}\]

Runtime

Time bar (total: 1.0m)Debug logProfile

herbie shell --seed 2018296 
(FPCore (re im)
  :name "math.sqrt on complex, real part"

  :herbie-target
  (if (< re 0) (* 0.5 (* (sqrt 2) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))

  (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))