Average Error: 6.8 → 0.3
Time: 2.0m
Precision: 64
Internal Precision: 128
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
\[\left(x.im \cdot \left(x.re + x.im\right)\right) \cdot \left(x.re - x.im\right) + \left(x.im \cdot x.re + x.im \cdot x.re\right) \cdot x.re\]

Error

Bits error versus x.re

Bits error versus x.im

Target

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

Derivation

  1. Initial program 6.8

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  2. Taylor expanded around inf 6.8

    \[\leadsto \color{blue}{\left(x.im \cdot {x.re}^{2} - {x.im}^{3}\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  3. Simplified0.3

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

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

Reproduce

herbie shell --seed 2019072 +o rules:numerics
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"

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

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