Average Error: 7.1 → 0.2
Time: 1.1m
Precision: 64
Internal Precision: 128
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
\[\left(\left(\sqrt{x.re \cdot x.re} - x.im\right) \cdot x.re\right) \cdot \left(x.im + \sqrt{x.re \cdot x.re}\right) - x.im \cdot \left(\left(x.re + x.re\right) \cdot x.im\right)\]

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.1
Target0.2
Herbie0.2
\[\left(x.re \cdot x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re \cdot x.im\right) \cdot \left(x.re - 3 \cdot x.im\right)\]

Derivation

  1. Initial program 7.1

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  2. Using strategy rm
  3. Applied *-commutative7.1

    \[\leadsto \left(x.re \cdot x.re - \color{blue}{x.im \cdot x.im}\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  4. Applied add-sqr-sqrt7.1

    \[\leadsto \left(\color{blue}{\sqrt{x.re \cdot x.re} \cdot \sqrt{x.re \cdot x.re}} - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  5. Applied difference-of-squares7.1

    \[\leadsto \color{blue}{\left(\left(\sqrt{x.re \cdot x.re} + x.im\right) \cdot \left(\sqrt{x.re \cdot x.re} - x.im\right)\right)} \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  6. Applied associate-*l*0.2

    \[\leadsto \color{blue}{\left(\sqrt{x.re \cdot x.re} + x.im\right) \cdot \left(\left(\sqrt{x.re \cdot x.re} - x.im\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  7. Using strategy rm
  8. Applied *-commutative0.2

    \[\leadsto \left(\sqrt{x.re \cdot x.re} + x.im\right) \cdot \left(\left(\sqrt{x.re \cdot x.re} - x.im\right) \cdot x.re\right) - \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) \cdot x.im\]
  9. Applied distribute-lft-out0.2

    \[\leadsto \left(\sqrt{x.re \cdot x.re} + x.im\right) \cdot \left(\left(\sqrt{x.re \cdot x.re} - x.im\right) \cdot x.re\right) - \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.im\]
  10. Applied associate-*l*0.2

    \[\leadsto \left(\sqrt{x.re \cdot x.re} + x.im\right) \cdot \left(\left(\sqrt{x.re \cdot x.re} - x.im\right) \cdot x.re\right) - \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) \cdot x.im\right)}\]
  11. Final simplification0.2

    \[\leadsto \left(\left(\sqrt{x.re \cdot x.re} - x.im\right) \cdot x.re\right) \cdot \left(x.im + \sqrt{x.re \cdot x.re}\right) - x.im \cdot \left(\left(x.re + x.re\right) \cdot x.im\right)\]

Reproduce

herbie shell --seed 2019088 
(FPCore (x.re x.im)
  :name "math.cube on complex, real part"

  :herbie-target
  (+ (* (* x.re x.re) (- x.re x.im)) (* (* x.re x.im) (- x.re (* 3 x.im))))

  (- (* (- (* x.re x.re) (* x.im x.im)) x.re) (* (+ (* x.re x.im) (* x.im x.re)) x.im)))