Average Error: 42.8 → 0.0
Time: 22.5s
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.280266654840657 \cdot 10^{-252}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(-1 \cdot re + re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re + im} \cdot \sqrt{re - im} + re\right)}\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 2 regimes.
  2. if re < 3.280266654840657e-252

    1. Initial program 49.1

      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)}\]
    2. Applied taylor 0

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(-1 \cdot re + re\right)}\]
    3. Taylor expanded around -inf 0

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

    if 3.280266654840657e-252 < re

    1. Initial program 28.9

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

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - \color{blue}{{im}^2}} + re\right)}\]
    4. Applied square-unmult 28.9

      \[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{{re}^2} - {im}^2} + re\right)}\]
    5. Applied difference-of-squares 28.8

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

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

Runtime

Time bar (total: 22.5s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(1052631102 1549666840 214851374 4124938917 336414485 3340135247)'
(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)))))