\[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.9 s
Input Error: 37.2
Output Error: 13.9
Log:
Profile: 🕒
\(0.5 \cdot {\left(\sqrt[3]{\sqrt{(\left(\sqrt{re^2 + im^2}^*\right) * 2.0 + \left(2.0 \cdot re\right))_*}}\right)}^3\)
  1. Started with
    \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
    37.2
  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))_*}}\]
    12.9
  3. Using strategy rm
    12.9
  4. Applied add-cube-cbrt 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(\sqrt[3]{\sqrt{(\left(\sqrt{re^2 + im^2}^*\right) * 2.0 + \left(2.0 \cdot re\right))_*}}\right)}^3}\]
    13.9

  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))))))