\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
Test:
math.sqrt on complex, real part
Bits:
128 bits
Bits error versus re
Bits error versus im
Time: 5.4 s
Input Error: 17.4
Output Error: 6.2
Log:
Profile: 🕒
\(0.5 \cdot {\left((\left(\sqrt{re^2 + im^2}^*\right) * 2.0 + \left(2.0 \cdot re\right))_*\right)}^{\frac{1}{2}}\)
  1. Started with
    \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
    17.4
  2. Applied simplify to get
    \[\color{red}{0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \leadsto \color{blue}{0.5 \cdot \sqrt{(\left(\sqrt{re^2 + im^2}^*\right) * 2.0 + \left(2.0 \cdot re\right))_*}}\]
    6.2
  3. Using strategy rm
    6.2
  4. Applied pow1/2 to get
    \[0.5 \cdot \color{red}{\sqrt{(\left(\sqrt{re^2 + im^2}^*\right) * 2.0 + \left(2.0 \cdot re\right))_*}} \leadsto 0.5 \cdot \color{blue}{{\left((\left(\sqrt{re^2 + im^2}^*\right) * 2.0 + \left(2.0 \cdot re\right))_*\right)}^{\frac{1}{2}}}\]
    6.2

  5. Removed slow pow expressions

Original test:


(lambda ((re default) (im default))
  #:name "math.sqrt on complex, real part"
  (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re))))
  #:target
  (if (< re 0) (* 0.5 (* (sqrt 2) (sqrt (/ (sqr im) (- (sqrt (+ (sqr re) (sqr im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re))))))