| Alternative 1 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 7040 |
\[x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}
\]
(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
(let* ((t_0 (* x.re (+ (* x.re x.im) (* x.re x.im))))
(t_1 (+ t_0 (* x.im (- (* x.re x.re) (* x.im x.im))))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 5e+303)))
(+ t_0 (* (* x.re x.im) (- x.re x.im)))
t_1)))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 t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im));
double t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 5e+303)) {
tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im));
} else {
tmp = t_1;
}
return tmp;
}
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 t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im));
double t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
double tmp;
if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 5e+303)) {
tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im));
} else {
tmp = t_1;
}
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): t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im)) t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) tmp = 0 if (t_1 <= -math.inf) or not (t_1 <= 5e+303): tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im)) else: tmp = t_1 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) t_0 = Float64(x_46_re * Float64(Float64(x_46_re * x_46_im) + Float64(x_46_re * x_46_im))) t_1 = Float64(t_0 + Float64(x_46_im * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im)))) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 5e+303)) tmp = Float64(t_0 + Float64(Float64(x_46_re * x_46_im) * Float64(x_46_re - x_46_im))); else tmp = t_1; 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) t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im)); t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im))); tmp = 0.0; if ((t_1 <= -Inf) || ~((t_1 <= 5e+303))) tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im)); else tmp = t_1; 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_] := Block[{t$95$0 = N[(x$46$re * N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(x$46$im * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 5e+303]], $MachinePrecision]], N[(t$95$0 + N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$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
\begin{array}{l}
t_0 := x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\
t_1 := t_0 + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 5 \cdot 10^{+303}\right):\\
\;\;\;\;t_0 + \left(x.re \cdot x.im\right) \cdot \left(x.re - x.im\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 49.4% |
|---|---|
| Target | 55.5% |
| Herbie | 55.8% |
if (+.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.im) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.re)) < -inf.0 or 4.9999999999999997e303 < (+.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.im) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.re)) Initial program 0.0%
Applied egg-rr13.8%
[Start]0.0 | \[ \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
\] |
|---|---|
add-log-exp [=>]0.0 | \[ \color{blue}{\log \left(e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
*-un-lft-identity [=>]0.0 | \[ \log \color{blue}{\left(1 \cdot e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
log-prod [=>]0.0 | \[ \color{blue}{\left(\log 1 + \log \left(e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
metadata-eval [=>]0.0 | \[ \left(\color{blue}{0} + \log \left(e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
add-log-exp [<=]0.0 | \[ \left(0 + \color{blue}{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
*-commutative [=>]0.0 | \[ \left(0 + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
difference-of-squares [=>]0.0 | \[ \left(0 + x.im \cdot \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
associate-*r* [=>]13.8 | \[ \left(0 + \color{blue}{\left(x.im \cdot \left(x.re + x.im\right)\right) \cdot \left(x.re - x.im\right)}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
Taylor expanded in x.im around 0 14.3%
if -inf.0 < (+.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.im) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.re)) < 4.9999999999999997e303Initial program 99.7%
Final simplification59.0%
| Alternative 1 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 7040 |
| Alternative 2 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 7040 |
| Alternative 3 | |
|---|---|
| Accuracy | 55.6% |
| Cost | 3785 |
| Alternative 4 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 1216 |
| Alternative 5 | |
|---|---|
| Accuracy | 44.5% |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 32.8% |
| Cost | 649 |
| Alternative 10 | |
|---|---|
| Accuracy | 17.1% |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Accuracy | 18.1% |
| Cost | 320 |
| Alternative 12 | |
|---|---|
| Accuracy | 4.5% |
| Cost | 128 |
| Alternative 13 | |
|---|---|
| Accuracy | 2.7% |
| Cost | 64 |
herbie shell --seed 2023157
(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)))