Average Error: 7.0 → 0.2
Time: 5.5m
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(x.re \cdot \left(x.re - x.im\right)\right) \cdot \left(x.im + x.re\right) + \left(\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot \left(-x.im\right)\right))_*\]

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.0
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.0

    \[\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. Taylor expanded around 0 6.9

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

    \[\leadsto \color{blue}{\left(x.re \cdot \left(x.re - x.im\right)\right) \cdot \left(x.im + x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  4. Using strategy rm
  5. Applied fma-neg0.2

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

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

Reproduce

herbie shell --seed 2019089 +o rules:numerics
(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)))