\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)}\]
Test:
math.sqrt on complex, imaginary part, im greater than 0 branch
Bits:
128 bits
Bits error versus re
Bits error versus im
Time: 9.2 s
Input Error: 42.2
Output Error: 0.1
Log:
Profile: 🕒
\(\begin{cases} \sqrt{(-1 * re + re)_* \cdot 2.0} \cdot 0.5 & \text{when } re \le 6.104117820416424 \cdot 10^{-288} \\ 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re + im} \cdot \sqrt{re - im} + re\right)} & \text{otherwise} \end{cases}\)

    if re < 6.104117820416424e-288

    1. Started with
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)}\]
      48.0
    2. Applied taylor to get
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)} \leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(-1 \cdot re + re\right)}\]
      0
    3. Taylor expanded around -inf to get
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\color{red}{-1 \cdot re} + re\right)} \leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{-1 \cdot re} + re\right)}\]
      0
    4. Applied simplify to get
      \[\color{red}{0.5 \cdot \sqrt{2.0 \cdot \left(-1 \cdot re + re\right)}} \leadsto \color{blue}{\sqrt{(-1 * re + re)_* \cdot 2.0} \cdot 0.5}\]
      0

    if 6.104117820416424e-288 < re

    1. Started with
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)}\]
      30.4
    2. Using strategy rm
      30.4
    3. Applied square-unmult to get
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - \color{red}{im \cdot im}} + re\right)} \leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - \color{blue}{{im}^2}} + re\right)}\]
      30.4
    4. Applied square-unmult to get
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{red}{re \cdot re} - {im}^2} + re\right)} \leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{{re}^2} - {im}^2} + re\right)}\]
      30.4
    5. Applied difference-of-squares to get
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{red}{{re}^2 - {im}^2}} + re\right)} \leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{\left(re + im\right) \cdot \left(re - im\right)}} + re\right)}\]
      30.4
    6. Applied sqrt-prod to get
      \[0.5 \cdot \sqrt{2.0 \cdot \left(\color{red}{\sqrt{\left(re + im\right) \cdot \left(re - im\right)}} + re\right)} \leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{\sqrt{re + im} \cdot \sqrt{re - im}} + re\right)}\]
      0.2

  1. Removed slow pow expressions

Original test:


(lambda ((re default) (im default))
  #:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
  (* 0.5 (sqrt (* 2.0 (+ (sqrt (- (* re re) (* im im))) re)))))