| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 7616 |
(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
(let* ((t_0 (* x.re (- (* x.re x.re) (* x.im x.im))))
(t_1 (- t_0 (* x.im (+ (* x.im x.re) (* x.im x.re))))))
(if (<= t_1 (- INFINITY))
(* -3.0 (* x.im (* x.im x.re)))
(if (<= t_1 2e+296)
(- t_0 (* x.im (* x.re (+ x.im x.im))))
(* x.im (* (* x.im 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 t_0 = x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im));
double t_1 = t_0 - (x_46_im * ((x_46_im * x_46_re) + (x_46_im * x_46_re)));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = -3.0 * (x_46_im * (x_46_im * x_46_re));
} else if (t_1 <= 2e+296) {
tmp = t_0 - (x_46_im * (x_46_re * (x_46_im + x_46_im)));
} else {
tmp = x_46_im * ((x_46_im * x_46_re) * -3.0);
}
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_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
public static double code(double x_46_re, double x_46_im) {
double t_0 = x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im));
double t_1 = t_0 - (x_46_im * ((x_46_im * x_46_re) + (x_46_im * x_46_re)));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = -3.0 * (x_46_im * (x_46_im * x_46_re));
} else if (t_1 <= 2e+296) {
tmp = t_0 - (x_46_im * (x_46_re * (x_46_im + x_46_im)));
} else {
tmp = x_46_im * ((x_46_im * x_46_re) * -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_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im)
def code(x_46_re, x_46_im): t_0 = x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im)) t_1 = t_0 - (x_46_im * ((x_46_im * x_46_re) + (x_46_im * x_46_re))) tmp = 0 if t_1 <= -math.inf: tmp = -3.0 * (x_46_im * (x_46_im * x_46_re)) elif t_1 <= 2e+296: tmp = t_0 - (x_46_im * (x_46_re * (x_46_im + x_46_im))) else: tmp = x_46_im * ((x_46_im * 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) t_0 = Float64(x_46_re * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))) t_1 = Float64(t_0 - Float64(x_46_im * Float64(Float64(x_46_im * x_46_re) + Float64(x_46_im * x_46_re)))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(-3.0 * Float64(x_46_im * Float64(x_46_im * x_46_re))); elseif (t_1 <= 2e+296) tmp = Float64(t_0 - Float64(x_46_im * Float64(x_46_re * Float64(x_46_im + x_46_im)))); else tmp = Float64(x_46_im * Float64(Float64(x_46_im * x_46_re) * -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_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im); end
function tmp_2 = code(x_46_re, x_46_im) t_0 = x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im)); t_1 = t_0 - (x_46_im * ((x_46_im * x_46_re) + (x_46_im * x_46_re))); tmp = 0.0; if (t_1 <= -Inf) tmp = -3.0 * (x_46_im * (x_46_im * x_46_re)); elseif (t_1 <= 2e+296) tmp = t_0 - (x_46_im * (x_46_re * (x_46_im + x_46_im))); else tmp = x_46_im * ((x_46_im * x_46_re) * -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$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_] := Block[{t$95$0 = N[(x$46$re * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[(x$46$im * N[(N[(x$46$im * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(-3.0 * N[(x$46$im * N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+296], N[(t$95$0 - N[(x$46$im * N[(x$46$re * N[(x$46$im + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(N[(x$46$im * x$46$re), $MachinePrecision] * -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}
t_0 := x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\
t_1 := t_0 - x.im \cdot \left(x.im \cdot x.re + x.im \cdot x.re\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-3 \cdot \left(x.im \cdot \left(x.im \cdot x.re\right)\right)\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+296}:\\
\;\;\;\;t_0 - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x.im \cdot \left(\left(x.im \cdot x.re\right) \cdot -3\right)\\
\end{array}
Results
| Original | 88.2% |
|---|---|
| Target | 99.6% |
| Herbie | 99.2% |
if (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)) < -inf.0Initial program 0.0%
Simplified0.0%
[Start]0.0 | \[ \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
\] |
|---|---|
sub-neg [=>]0.0 | \[ \color{blue}{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)}
\] |
*-commutative [=>]0.0 | \[ \color{blue}{x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)
\] |
sub-neg [=>]0.0 | \[ x.re \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)
\] |
distribute-rgt-in [=>]0.0 | \[ \color{blue}{\left(\left(x.re \cdot x.re\right) \cdot x.re + \left(-x.im \cdot x.im\right) \cdot x.re\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)
\] |
associate-+l+ [=>]0.0 | \[ \color{blue}{\left(x.re \cdot x.re\right) \cdot x.re + \left(\left(-x.im \cdot x.im\right) \cdot x.re + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{\left(\left(-x.im \cdot x.im\right) \cdot x.re + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re}
\] |
*-commutative [=>]0.0 | \[ \left(\color{blue}{x.re \cdot \left(-x.im \cdot x.im\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
distribute-rgt-neg-in [=>]0.0 | \[ \left(x.re \cdot \left(-x.im \cdot x.im\right) + \color{blue}{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \left(-x.im\right)}\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
*-commutative [=>]0.0 | \[ \left(x.re \cdot \left(-x.im \cdot x.im\right) + \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) \cdot \left(-x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
distribute-rgt-out [=>]0.0 | \[ \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 \left(-x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
associate-*l* [=>]0.0 | \[ \left(x.re \cdot \left(-x.im \cdot x.im\right) + \color{blue}{x.re \cdot \left(\left(x.im + x.im\right) \cdot \left(-x.im\right)\right)}\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
distribute-lft-out [=>]0.0 | \[ \color{blue}{x.re \cdot \left(\left(-x.im \cdot x.im\right) + \left(x.im + x.im\right) \cdot \left(-x.im\right)\right)} + \left(x.re \cdot x.re\right) \cdot x.re
\] |
fma-def [=>]0.0 | \[ \color{blue}{\mathsf{fma}\left(x.re, \left(-x.im \cdot x.im\right) + \left(x.im + x.im\right) \cdot \left(-x.im\right), \left(x.re \cdot x.re\right) \cdot x.re\right)}
\] |
Taylor expanded in x.re around 0 0.0%
Simplified99.4%
[Start]0.0 | \[ -3 \cdot \left(x.re \cdot {x.im}^{2}\right)
\] |
|---|---|
unpow2 [=>]0.0 | \[ -3 \cdot \left(x.re \cdot \color{blue}{\left(x.im \cdot x.im\right)}\right)
\] |
associate-*r* [=>]99.4 | \[ -3 \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot x.im\right)}
\] |
*-commutative [=>]99.4 | \[ -3 \cdot \color{blue}{\left(x.im \cdot \left(x.re \cdot x.im\right)\right)}
\] |
if -inf.0 < (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)) < 1.99999999999999996e296Initial program 99.7%
Simplified99.7%
[Start]99.7 | \[ \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 [=>]99.7 | \[ \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
\] |
*-commutative [=>]99.7 | \[ x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - \color{blue}{x.im \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}
\] |
*-commutative [=>]99.7 | \[ x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right)
\] |
distribute-rgt-out [=>]99.7 | \[ x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \color{blue}{\left(x.re \cdot \left(x.im + x.im\right)\right)}
\] |
if 1.99999999999999996e296 < (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)) Initial program 9.3%
Simplified9.4%
[Start]9.3 | \[ \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
\] |
|---|---|
sub-neg [=>]9.3 | \[ \color{blue}{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)}
\] |
*-commutative [=>]9.3 | \[ \color{blue}{x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)
\] |
sub-neg [=>]9.3 | \[ x.re \cdot \color{blue}{\left(x.re \cdot x.re + \left(-x.im \cdot x.im\right)\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)
\] |
distribute-rgt-in [=>]9.3 | \[ \color{blue}{\left(\left(x.re \cdot x.re\right) \cdot x.re + \left(-x.im \cdot x.im\right) \cdot x.re\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)
\] |
associate-+l+ [=>]9.3 | \[ \color{blue}{\left(x.re \cdot x.re\right) \cdot x.re + \left(\left(-x.im \cdot x.im\right) \cdot x.re + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right)}
\] |
+-commutative [=>]9.3 | \[ \color{blue}{\left(\left(-x.im \cdot x.im\right) \cdot x.re + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re}
\] |
*-commutative [=>]9.3 | \[ \left(\color{blue}{x.re \cdot \left(-x.im \cdot x.im\right)} + \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
distribute-rgt-neg-in [=>]9.3 | \[ \left(x.re \cdot \left(-x.im \cdot x.im\right) + \color{blue}{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot \left(-x.im\right)}\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
*-commutative [=>]9.3 | \[ \left(x.re \cdot \left(-x.im \cdot x.im\right) + \left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right) \cdot \left(-x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
distribute-rgt-out [=>]9.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 \left(-x.im\right)\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
associate-*l* [=>]9.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 \left(-x.im\right)\right)}\right) + \left(x.re \cdot x.re\right) \cdot x.re
\] |
distribute-lft-out [=>]9.3 | \[ \color{blue}{x.re \cdot \left(\left(-x.im \cdot x.im\right) + \left(x.im + x.im\right) \cdot \left(-x.im\right)\right)} + \left(x.re \cdot x.re\right) \cdot x.re
\] |
fma-def [=>]9.3 | \[ \color{blue}{\mathsf{fma}\left(x.re, \left(-x.im \cdot x.im\right) + \left(x.im + x.im\right) \cdot \left(-x.im\right), \left(x.re \cdot x.re\right) \cdot x.re\right)}
\] |
Taylor expanded in x.re around 0 2.5%
Simplified92.6%
[Start]2.5 | \[ -3 \cdot \left(x.re \cdot {x.im}^{2}\right)
\] |
|---|---|
unpow2 [=>]2.5 | \[ -3 \cdot \left(x.re \cdot \color{blue}{\left(x.im \cdot x.im\right)}\right)
\] |
associate-*r* [=>]92.6 | \[ -3 \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot x.im\right)}
\] |
*-commutative [=>]92.6 | \[ -3 \cdot \color{blue}{\left(x.im \cdot \left(x.re \cdot x.im\right)\right)}
\] |
Taylor expanded in x.im around 0 2.5%
Simplified92.6%
[Start]2.5 | \[ -3 \cdot \left(x.re \cdot {x.im}^{2}\right)
\] |
|---|---|
*-commutative [=>]2.5 | \[ -3 \cdot \color{blue}{\left({x.im}^{2} \cdot x.re\right)}
\] |
unpow2 [=>]2.5 | \[ -3 \cdot \left(\color{blue}{\left(x.im \cdot x.im\right)} \cdot x.re\right)
\] |
associate-*r* [<=]92.6 | \[ -3 \cdot \color{blue}{\left(x.im \cdot \left(x.im \cdot x.re\right)\right)}
\] |
*-commutative [=>]92.6 | \[ \color{blue}{\left(x.im \cdot \left(x.im \cdot x.re\right)\right) \cdot -3}
\] |
associate-*r* [<=]92.6 | \[ \color{blue}{x.im \cdot \left(\left(x.im \cdot x.re\right) \cdot -3\right)}
\] |
*-commutative [=>]92.6 | \[ x.im \cdot \color{blue}{\left(-3 \cdot \left(x.im \cdot x.re\right)\right)}
\] |
*-commutative [=>]92.6 | \[ x.im \cdot \left(-3 \cdot \color{blue}{\left(x.re \cdot x.im\right)}\right)
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 7616 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 7040 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1224 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1216 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Accuracy | 91.5% |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Accuracy | 91.1% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 91.1% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 58.0% |
| Cost | 649 |
| Alternative 10 | |
|---|---|
| Accuracy | 55.8% |
| Cost | 320 |
herbie shell --seed 2023137
(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)))