| Alternative 1 | |
|---|---|
| Accuracy | 95.8% |
| Cost | 7241 |

(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 (if (or (<= x.re -5e+103) (not (<= x.re 5e+53))) (* x.re (fma x.re x.re (* x.im (* x.im -3.0)))) (fma (* -3.0 (* x.re x.im)) x.im (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) {
double tmp;
if ((x_46_re <= -5e+103) || !(x_46_re <= 5e+53)) {
tmp = x_46_re * fma(x_46_re, x_46_re, (x_46_im * (x_46_im * -3.0)));
} else {
tmp = fma((-3.0 * (x_46_re * x_46_im)), x_46_im, pow(x_46_re, 3.0));
}
return tmp;
}
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) tmp = 0.0 if ((x_46_re <= -5e+103) || !(x_46_re <= 5e+53)) tmp = Float64(x_46_re * fma(x_46_re, x_46_re, Float64(x_46_im * Float64(x_46_im * -3.0)))); else tmp = fma(Float64(-3.0 * Float64(x_46_re * x_46_im)), x_46_im, (x_46_re ^ 3.0)); end return tmp 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_] := If[Or[LessEqual[x$46$re, -5e+103], N[Not[LessEqual[x$46$re, 5e+53]], $MachinePrecision]], N[(x$46$re * N[(x$46$re * x$46$re + N[(x$46$im * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-3.0 * N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision] * x$46$im + 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
\begin{array}{l}
\mathbf{if}\;x.re \leq -5 \cdot 10^{+103} \lor \neg \left(x.re \leq 5 \cdot 10^{+53}\right):\\
\;\;\;\;x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot -3\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-3 \cdot \left(x.re \cdot x.im\right), x.im, {x.re}^{3}\right)\\
\end{array}
| Original | 82.5% |
|---|---|
| Target | 86.9% |
| Herbie | 96.7% |
if x.re < -5e103 or 5.0000000000000004e53 < x.re Initial program 69.6%
Simplified92.1%
[Start]69.6 | \[ \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
\] |
|---|---|
*-commutative [<=]69.6 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.im
\] |
distribute-lft-out [=>]69.6 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \color{blue}{\left(x.re \cdot \left(x.im + x.im\right)\right)} \cdot x.im
\] |
associate-*l* [=>]69.6 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \color{blue}{x.re \cdot \left(\left(x.im + x.im\right) \cdot x.im\right)}
\] |
*-commutative [=>]69.6 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \color{blue}{\left(\left(x.im + x.im\right) \cdot x.im\right) \cdot x.re}
\] |
distribute-rgt-out-- [=>]81.4 | \[ \color{blue}{x.re \cdot \left(\left(x.re \cdot x.re - x.im \cdot x.im\right) - \left(x.im + x.im\right) \cdot x.im\right)}
\] |
associate--l- [=>]81.4 | \[ x.re \cdot \color{blue}{\left(x.re \cdot x.re - \left(x.im \cdot x.im + \left(x.im + x.im\right) \cdot x.im\right)\right)}
\] |
associate--l- [<=]81.4 | \[ x.re \cdot \color{blue}{\left(\left(x.re \cdot x.re - x.im \cdot x.im\right) - \left(x.im + x.im\right) \cdot x.im\right)}
\] |
sub-neg [=>]81.4 | \[ x.re \cdot \left(\color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} - \left(x.im + x.im\right) \cdot x.im\right)
\] |
associate--l+ [=>]81.4 | \[ x.re \cdot \color{blue}{\left(x.re \cdot x.re + \left(\left(-x.im \cdot x.im\right) - \left(x.im + x.im\right) \cdot x.im\right)\right)}
\] |
fma-udef [<=]92.1 | \[ x.re \cdot \color{blue}{\mathsf{fma}\left(x.re, x.re, \left(-x.im \cdot x.im\right) - \left(x.im + x.im\right) \cdot x.im\right)}
\] |
neg-mul-1 [=>]92.1 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, \color{blue}{-1 \cdot \left(x.im \cdot x.im\right)} - \left(x.im + x.im\right) \cdot x.im\right)
\] |
count-2 [=>]92.1 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, -1 \cdot \left(x.im \cdot x.im\right) - \color{blue}{\left(2 \cdot x.im\right)} \cdot x.im\right)
\] |
associate-*l* [=>]92.1 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, -1 \cdot \left(x.im \cdot x.im\right) - \color{blue}{2 \cdot \left(x.im \cdot x.im\right)}\right)
\] |
distribute-rgt-out-- [=>]92.1 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, \color{blue}{\left(x.im \cdot x.im\right) \cdot \left(-1 - 2\right)}\right)
\] |
associate-*r* [<=]92.1 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, \color{blue}{x.im \cdot \left(x.im \cdot \left(-1 - 2\right)\right)}\right)
\] |
metadata-eval [=>]92.1 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot \color{blue}{-3}\right)\right)
\] |
if -5e103 < x.re < 5.0000000000000004e53Initial program 91.1%
Simplified91.2%
[Start]91.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
\] |
|---|---|
*-commutative [=>]91.1 | \[ \color{blue}{x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im
\] |
sub-neg [=>]91.1 | \[ x.re \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im
\] |
distribute-lft-in [=>]91.1 | \[ \color{blue}{\left(x.re \cdot \left(x.re \cdot x.re\right) + x.re \cdot \left(-x.im \cdot x.im\right)\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im
\] |
associate--l+ [=>]91.1 | \[ \color{blue}{x.re \cdot \left(x.re \cdot x.re\right) + \left(x.re \cdot \left(-x.im \cdot x.im\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)}
\] |
cube-unmult [=>]91.2 | \[ \color{blue}{{x.re}^{3}} + \left(x.re \cdot \left(-x.im \cdot x.im\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)
\] |
*-commutative [<=]91.2 | \[ {x.re}^{3} + \left(x.re \cdot \left(-x.im \cdot x.im\right) - \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.im\right)
\] |
distribute-lft-out [=>]91.2 | \[ {x.re}^{3} + \left(x.re \cdot \left(-x.im \cdot x.im\right) - \color{blue}{\left(x.re \cdot \left(x.im + x.im\right)\right)} \cdot x.im\right)
\] |
associate-*l* [=>]91.2 | \[ {x.re}^{3} + \left(x.re \cdot \left(-x.im \cdot x.im\right) - \color{blue}{x.re \cdot \left(\left(x.im + x.im\right) \cdot x.im\right)}\right)
\] |
distribute-lft-out-- [=>]91.3 | \[ {x.re}^{3} + \color{blue}{x.re \cdot \left(\left(-x.im \cdot x.im\right) - \left(x.im + x.im\right) \cdot x.im\right)}
\] |
neg-mul-1 [=>]91.3 | \[ {x.re}^{3} + x.re \cdot \left(\color{blue}{-1 \cdot \left(x.im \cdot x.im\right)} - \left(x.im + x.im\right) \cdot x.im\right)
\] |
count-2 [=>]91.3 | \[ {x.re}^{3} + x.re \cdot \left(-1 \cdot \left(x.im \cdot x.im\right) - \color{blue}{\left(2 \cdot x.im\right)} \cdot x.im\right)
\] |
associate-*l* [=>]91.3 | \[ {x.re}^{3} + x.re \cdot \left(-1 \cdot \left(x.im \cdot x.im\right) - \color{blue}{2 \cdot \left(x.im \cdot x.im\right)}\right)
\] |
distribute-rgt-out-- [=>]91.3 | \[ {x.re}^{3} + x.re \cdot \color{blue}{\left(\left(x.im \cdot x.im\right) \cdot \left(-1 - 2\right)\right)}
\] |
associate-*l* [<=]91.2 | \[ {x.re}^{3} + \color{blue}{\left(x.re \cdot \left(x.im \cdot x.im\right)\right) \cdot \left(-1 - 2\right)}
\] |
metadata-eval [=>]91.2 | \[ {x.re}^{3} + \left(x.re \cdot \left(x.im \cdot x.im\right)\right) \cdot \color{blue}{-3}
\] |
Applied egg-rr99.8%
[Start]91.2 | \[ {x.re}^{3} + \left(x.re \cdot \left(x.im \cdot x.im\right)\right) \cdot -3
\] |
|---|---|
+-commutative [=>]91.2 | \[ \color{blue}{\left(x.re \cdot \left(x.im \cdot x.im\right)\right) \cdot -3 + {x.re}^{3}}
\] |
*-commutative [=>]91.2 | \[ \color{blue}{-3 \cdot \left(x.re \cdot \left(x.im \cdot x.im\right)\right)} + {x.re}^{3}
\] |
associate-*r* [=>]99.8 | \[ -3 \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot x.im\right)} + {x.re}^{3}
\] |
associate-*r* [=>]99.8 | \[ \color{blue}{\left(-3 \cdot \left(x.re \cdot x.im\right)\right) \cdot x.im} + {x.re}^{3}
\] |
fma-def [=>]99.8 | \[ \color{blue}{\mathsf{fma}\left(-3 \cdot \left(x.re \cdot x.im\right), x.im, {x.re}^{3}\right)}
\] |
Final simplification96.8%
| Alternative 1 | |
|---|---|
| Accuracy | 95.8% |
| Cost | 7241 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.2% |
| Cost | 1616 |
| Alternative 3 | |
|---|---|
| Accuracy | 82.4% |
| Cost | 978 |
| Alternative 4 | |
|---|---|
| Accuracy | 82.5% |
| Cost | 976 |
| Alternative 5 | |
|---|---|
| Accuracy | 82.4% |
| Cost | 976 |
| Alternative 6 | |
|---|---|
| Accuracy | 82.4% |
| Cost | 976 |
| Alternative 7 | |
|---|---|
| Accuracy | 96.6% |
| Cost | 969 |
| Alternative 8 | |
|---|---|
| Accuracy | 61.4% |
| Cost | 649 |
| Alternative 9 | |
|---|---|
| Accuracy | 61.4% |
| Cost | 648 |
| Alternative 10 | |
|---|---|
| Accuracy | 59.0% |
| Cost | 320 |
herbie shell --seed 2023159
(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)))