\[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: 4.9 s
Input Error: 18.0
Output Error: 18.1
Log:
Profile: 🕒
\(0.5 \cdot \sqrt{2.0 \cdot {\left(\sqrt{re + \sqrt{{re}^2 + im \cdot im}}\right)}^2}\)
  1. Started with
    \[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
    18.0
  2. Using strategy rm
    18.0
  3. Applied add-sqr-sqrt to get
    \[0.5 \cdot \sqrt{2.0 \cdot \color{red}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \leadsto 0.5 \cdot \sqrt{2.0 \cdot \color{blue}{{\left(\sqrt{\sqrt{re \cdot re + im \cdot im} + re}\right)}^2}}\]
    18.1
  4. Applied simplify to get
    \[0.5 \cdot \sqrt{2.0 \cdot {\color{red}{\left(\sqrt{\sqrt{re \cdot re + im \cdot im} + re}\right)}}^2} \leadsto 0.5 \cdot \sqrt{2.0 \cdot {\color{blue}{\left(\sqrt{re + \sqrt{{re}^2 + im \cdot im}}\right)}}^2}\]
    18.1

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