?

Average Error: 11.06% → 0.26%
Time: 8.7s
Precision: binary64
Cost: 13376

?

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

Error?

Target

Original11.06%
Target0.38%
Herbie0.26%
\[\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 11.06

    \[\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. Simplified0.27

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

    [Start]11.06

    \[ \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 \]

    +-commutative [=>]11.06

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

    *-commutative [=>]11.06

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

    distribute-rgt-out-- [<=]11.06

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

    associate-+r- [=>]11.06

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

    *-commutative [<=]11.06

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

    *-commutative [=>]11.06

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

    *-commutative [<=]11.06

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

    distribute-lft-out [=>]11.06

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

    associate-*r* [=>]11.1

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

    distribute-lft-out [=>]11.1

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

    associate-*l* [=>]0.39

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

    count-2 [=>]0.39

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

    distribute-lft1-in [=>]0.39

    \[ x.re \cdot \left(x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot x.im\right)}\right) - x.im \cdot \left(x.im \cdot x.im\right) \]

    *-commutative [=>]0.39

    \[ x.re \cdot \left(x.re \cdot \color{blue}{\left(x.im \cdot \left(2 + 1\right)\right)}\right) - x.im \cdot \left(x.im \cdot x.im\right) \]

    metadata-eval [=>]0.39

    \[ x.re \cdot \left(x.re \cdot \left(x.im \cdot \color{blue}{3}\right)\right) - x.im \cdot \left(x.im \cdot x.im\right) \]

    cube-unmult [=>]0.27

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

    \[\leadsto x.re \cdot \color{blue}{\left(3 \cdot \left(x.re \cdot x.im\right)\right)} - {x.im}^{3} \]
  4. Applied egg-rr0.26

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

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

Alternatives

Alternative 1
Error0.27%
Cost7040
\[x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right) - {x.im}^{3} \]
Alternative 2
Error0.27%
Cost7040
\[x.re \cdot \left(x.re \cdot \left(3 \cdot x.im\right)\right) - {x.im}^{3} \]
Alternative 3
Error0.62%
Cost3912
\[\begin{array}{l} t_0 := x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ t_1 := x.re \cdot x.re - x.im \cdot x.im\\ t_2 := t_0 + x.im \cdot t_1\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;x.re \cdot \left(\left(3 \cdot x.re\right) \cdot x.im\right)\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+302}:\\ \;\;\;\;t_0 + \frac{x.im}{\frac{1}{t_1}}\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right)\\ \end{array} \]
Alternative 4
Error0.6%
Cost3272
\[\begin{array}{l} t_0 := x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;x.re \cdot \left(\left(3 \cdot x.re\right) \cdot x.im\right)\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+302}:\\ \;\;\;\;x.im \cdot \left(3 \cdot \left(x.re \cdot x.re\right) - x.im \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right)\\ \end{array} \]
Alternative 5
Error0.42%
Cost1856
\[\begin{array}{l} t_0 := \frac{x.im}{\frac{-1}{x.im - x.re}}\\ \left(x.re \cdot t_0 + x.im \cdot t_0\right) + x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) \end{array} \]
Alternative 6
Error0.48%
Cost1600
\[x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + \frac{x.im}{\frac{-1}{x.im - x.re}} \cdot \frac{-1}{\frac{-1}{x.re + x.im}} \]
Alternative 7
Error8.71%
Cost713
\[\begin{array}{l} \mathbf{if}\;x.re \leq -1.75 \cdot 10^{-22} \lor \neg \left(x.re \leq 9.2 \cdot 10^{-72}\right):\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \end{array} \]
Alternative 8
Error8.85%
Cost712
\[\begin{array}{l} \mathbf{if}\;x.re \leq -1.75 \cdot 10^{-22}:\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{elif}\;x.re \leq 1.35 \cdot 10^{-77}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right)\\ \end{array} \]
Alternative 9
Error8.87%
Cost712
\[\begin{array}{l} \mathbf{if}\;x.re \leq -1.4 \cdot 10^{-18}:\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{elif}\;x.re \leq 1.3 \cdot 10^{-71}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(3 \cdot x.im\right)\right)\\ \end{array} \]
Alternative 10
Error8.7%
Cost712
\[\begin{array}{l} \mathbf{if}\;x.re \leq -1.75 \cdot 10^{-22}:\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{elif}\;x.re \leq 9.2 \cdot 10^{-72}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(\left(3 \cdot x.re\right) \cdot x.im\right)\\ \end{array} \]
Alternative 11
Error39.9%
Cost649
\[\begin{array}{l} \mathbf{if}\;x.re \leq -1.1 \cdot 10^{+60} \lor \neg \left(x.re \leq 6 \cdot 10^{+53}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \end{array} \]
Alternative 12
Error66.52%
Cost320
\[x.re \cdot \left(x.re \cdot x.im\right) \]

Error

Reproduce?

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

  :herbie-target
  (+ (* (* x.re x.im) (* 2.0 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)))