| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7305 |

(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 (if (or (<= x.im -2.3e+113) (not (<= x.im 6e+72))) (+ (* x.im (* (- x.re x.im) (+ x.im x.re))) (* x.re 8.0)) (- (* x.re (* 3.0 (* x.im x.re))) (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) {
double tmp;
if ((x_46_im <= -2.3e+113) || !(x_46_im <= 6e+72)) {
tmp = (x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))) + (x_46_re * 8.0);
} else {
tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - pow(x_46_im, 3.0);
}
return tmp;
}
real(8) function code(x_46re, x_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
code = (((x_46re * x_46re) - (x_46im * x_46im)) * x_46im) + (((x_46re * x_46im) + (x_46im * x_46re)) * x_46re)
end function
real(8) function code(x_46re, x_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8) :: tmp
if ((x_46im <= (-2.3d+113)) .or. (.not. (x_46im <= 6d+72))) then
tmp = (x_46im * ((x_46re - x_46im) * (x_46im + x_46re))) + (x_46re * 8.0d0)
else
tmp = (x_46re * (3.0d0 * (x_46im * x_46re))) - (x_46im ** 3.0d0)
end if
code = tmp
end function
public static 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);
}
public static double code(double x_46_re, double x_46_im) {
double tmp;
if ((x_46_im <= -2.3e+113) || !(x_46_im <= 6e+72)) {
tmp = (x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))) + (x_46_re * 8.0);
} else {
tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - Math.pow(x_46_im, 3.0);
}
return tmp;
}
def code(x_46_re, 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)
def code(x_46_re, x_46_im): tmp = 0 if (x_46_im <= -2.3e+113) or not (x_46_im <= 6e+72): tmp = (x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))) + (x_46_re * 8.0) else: tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - math.pow(x_46_im, 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_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) tmp = 0.0 if ((x_46_im <= -2.3e+113) || !(x_46_im <= 6e+72)) tmp = Float64(Float64(x_46_im * Float64(Float64(x_46_re - x_46_im) * Float64(x_46_im + x_46_re))) + Float64(x_46_re * 8.0)); else tmp = Float64(Float64(x_46_re * Float64(3.0 * Float64(x_46_im * x_46_re))) - (x_46_im ^ 3.0)); end return tmp end
function tmp = code(x_46_re, x_46_im) tmp = (((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); end
function tmp_2 = code(x_46_re, x_46_im) tmp = 0.0; if ((x_46_im <= -2.3e+113) || ~((x_46_im <= 6e+72))) tmp = (x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))) + (x_46_re * 8.0); else tmp = (x_46_re * (3.0 * (x_46_im * x_46_re))) - (x_46_im ^ 3.0); end tmp_2 = 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$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_] := If[Or[LessEqual[x$46$im, -2.3e+113], N[Not[LessEqual[x$46$im, 6e+72]], $MachinePrecision]], N[(N[(x$46$im * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x$46$re * 8.0), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$re * N[(3.0 * N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision]), $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
\begin{array}{l}
\mathbf{if}\;x.im \leq -2.3 \cdot 10^{+113} \lor \neg \left(x.im \leq 6 \cdot 10^{+72}\right):\\
\;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + x.re \cdot 8\\
\mathbf{else}:\\
\;\;\;\;x.re \cdot \left(3 \cdot \left(x.im \cdot x.re\right)\right) - {x.im}^{3}\\
\end{array}
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 82.3% |
|---|---|
| Target | 91.1% |
| Herbie | 99.4% |
if x.im < -2.29999999999999997e113 or 6.00000000000000006e72 < x.im Initial program 57.1%
Applied egg-rr72.6%
[Start]57.1% | \[ \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
\] |
|---|---|
difference-of-squares [=>]72.6% | \[ \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
*-commutative [=>]72.6% | \[ \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
Applied egg-rr54.8%
[Start]72.6% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
|---|---|
*-commutative [<=]72.6% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re
\] |
flip-+ [=>]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}} \cdot x.re
\] |
+-inverses [=>]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re
\] |
metadata-eval [<=]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{\color{blue}{{0}^{3}}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re
\] |
+-inverses [<=]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{{\color{blue}{\left(x.im \cdot x.im - x.im \cdot x.im\right)}}^{3}}{x.re \cdot x.im - x.re \cdot x.im} \cdot x.re
\] |
+-inverses [=>]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{{\left(x.im \cdot x.im - x.im \cdot x.im\right)}^{3}}{\color{blue}{0}} \cdot x.re
\] |
metadata-eval [<=]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{{\left(x.im \cdot x.im - x.im \cdot x.im\right)}^{3}}{\color{blue}{{0}^{3}}} \cdot x.re
\] |
+-inverses [<=]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \frac{{\left(x.im \cdot x.im - x.im \cdot x.im\right)}^{3}}{{\color{blue}{\left(x.im - x.im\right)}}^{3}} \cdot x.re
\] |
cube-div [<=]0.0% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{{\left(\frac{x.im \cdot x.im - x.im \cdot x.im}{x.im - x.im}\right)}^{3}} \cdot x.re
\] |
flip-+ [<=]54.8% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + {\color{blue}{\left(x.im + x.im\right)}}^{3} \cdot x.re
\] |
count-2 [=>]54.8% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + {\color{blue}{\left(2 \cdot x.im\right)}}^{3} \cdot x.re
\] |
unpow-prod-down [=>]54.8% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left({2}^{3} \cdot {x.im}^{3}\right)} \cdot x.re
\] |
metadata-eval [=>]54.8% | \[ \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(\color{blue}{8} \cdot {x.im}^{3}\right) \cdot x.re
\] |
Simplified100.0%
if -2.29999999999999997e113 < x.im < 6.00000000000000006e72Initial program 92.1%
Simplified99.8%
[Start]92.1% | \[ \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 [=>]92.1% | \[ \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 [=>]92.1% | \[ \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)}
\] |
sub-neg [=>]92.1% | \[ \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)}
\] |
distribute-lft-in [=>]92.1% | \[ \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot \left(x.re \cdot x.re\right) + x.im \cdot \left(-x.im \cdot x.im\right)\right)}
\] |
associate-+r+ [=>]92.1% | \[ \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + x.im \cdot \left(-x.im \cdot x.im\right)}
\] |
distribute-rgt-neg-out [=>]92.1% | \[ \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) + \color{blue}{\left(-x.im \cdot \left(x.im \cdot x.im\right)\right)}
\] |
unsub-neg [=>]92.1% | \[ \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + x.im \cdot \left(x.re \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right)}
\] |
associate-*r* [=>]99.7% | \[ \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(x.im \cdot x.re\right) \cdot x.re}\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
distribute-rgt-out [=>]99.8% | \[ \color{blue}{x.re \cdot \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) + x.im \cdot x.re\right)} - x.im \cdot \left(x.im \cdot x.im\right)
\] |
*-commutative [=>]99.8% | \[ x.re \cdot \left(\left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
count-2 [=>]99.8% | \[ x.re \cdot \left(\color{blue}{2 \cdot \left(x.im \cdot x.re\right)} + x.im \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
distribute-lft1-in [=>]99.8% | \[ x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \left(x.im \cdot x.re\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right)
\] |
metadata-eval [=>]99.8% | \[ x.re \cdot \left(\color{blue}{3} \cdot \left(x.im \cdot x.re\right)\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
*-commutative [=>]99.8% | \[ x.re \cdot \color{blue}{\left(\left(x.im \cdot x.re\right) \cdot 3\right)} - x.im \cdot \left(x.im \cdot x.im\right)
\] |
*-commutative [<=]99.8% | \[ x.re \cdot \left(\color{blue}{\left(x.re \cdot x.im\right)} \cdot 3\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
associate-*r* [<=]99.7% | \[ x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 3\right)\right)} - x.im \cdot \left(x.im \cdot x.im\right)
\] |
cube-unmult [=>]99.8% | \[ x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - \color{blue}{{x.im}^{3}}
\] |
Taylor expanded in x.re around 0 99.9%
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7305 |
| Alternative 2 | |
|---|---|
| Accuracy | 93.6% |
| Cost | 2372 |
| Alternative 3 | |
|---|---|
| Accuracy | 94.4% |
| Cost | 1225 |
| Alternative 4 | |
|---|---|
| Accuracy | 93.1% |
| Cost | 1097 |
| Alternative 5 | |
|---|---|
| Accuracy | 94.3% |
| Cost | 1097 |
| Alternative 6 | |
|---|---|
| Accuracy | 90.8% |
| Cost | 969 |
| Alternative 7 | |
|---|---|
| Accuracy | 28.8% |
| Cost | 717 |
| Alternative 8 | |
|---|---|
| Accuracy | 59.4% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 44.0% |
| Cost | 584 |
| Alternative 10 | |
|---|---|
| Accuracy | 44.7% |
| Cost | 584 |
| Alternative 11 | |
|---|---|
| Accuracy | 21.9% |
| Cost | 452 |
| Alternative 12 | |
|---|---|
| Accuracy | 20.7% |
| Cost | 256 |
| Alternative 13 | |
|---|---|
| Accuracy | 3.7% |
| Cost | 192 |
| Alternative 14 | |
|---|---|
| Accuracy | 2.7% |
| Cost | 64 |
| Alternative 15 | |
|---|---|
| Accuracy | 2.7% |
| Cost | 64 |
| Alternative 16 | |
|---|---|
| Accuracy | 2.7% |
| Cost | 64 |
| Alternative 17 | |
|---|---|
| Accuracy | 2.7% |
| Cost | 64 |
herbie shell --seed 2023277
(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)))