Average Error: 7.1 → 0.2
Time: 2.4s
Precision: binary64
\[\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 \]
\[\mathsf{fma}\left(x.im, -3 \cdot \left(x.im \cdot x.re\right), {x.re}^{3}\right) \]
(FPCore (x.re x.im)
 :precision binary64
 (-
  (* (- (* x.re x.re) (* x.im x.im)) x.re)
  (* (+ (* x.re x.im) (* x.im x.re)) x.im)))
(FPCore (x.re x.im)
 :precision binary64
 (fma x.im (* -3.0 (* x.im x.re)) (pow x.re 3.0)))
double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
double code(double x_46_re, double x_46_im) {
	return fma(x_46_im, (-3.0 * (x_46_im * x_46_re)), pow(x_46_re, 3.0));
}
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im)) * x_46_re) - Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_im))
end
function code(x_46_re, x_46_im)
	return fma(x_46_im, Float64(-3.0 * Float64(x_46_im * x_46_re)), (x_46_re ^ 3.0))
end
code[x$46$re_, x$46$im_] := N[(N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision] - N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_] := N[(x$46$im * N[(-3.0 * N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] + N[Power[x$46$re, 3.0], $MachinePrecision]), $MachinePrecision]
\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
\mathsf{fma}\left(x.im, -3 \cdot \left(x.im \cdot x.re\right), {x.re}^{3}\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. Simplified7.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.im \cdot \left(x.im \cdot -3\right), {x.re}^{3}\right)} \]
  3. Taylor expanded in x.re around 0 7.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.im, x.im \cdot \left(-3 \cdot x.re\right), {x.re}^{3}\right)} \]
  5. Applied egg-rr0.6

    \[\leadsto \mathsf{fma}\left(x.im, \color{blue}{{\left(\sqrt[3]{\left(x.im \cdot x.re\right) \cdot -3}\right)}^{3}}, {x.re}^{3}\right) \]
  6. Applied egg-rr0.2

    \[\leadsto \mathsf{fma}\left(x.im, \color{blue}{-3 \cdot \left(x.im \cdot x.re\right)}, {x.re}^{3}\right) \]
  7. Final simplification0.2

    \[\leadsto \mathsf{fma}\left(x.im, -3 \cdot \left(x.im \cdot x.re\right), {x.re}^{3}\right) \]

Reproduce

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

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

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