| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1096 |
(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 (<= x.im -5e+154)
(* (* x.im -3.0) (* x.re x.im))
(if (<= x.im 4e+86)
(-
(* x.re (- (* x.re x.re) (* x.im x.im)))
(* 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 tmp;
if (x_46_im <= -5e+154) {
tmp = (x_46_im * -3.0) * (x_46_re * x_46_im);
} else if (x_46_im <= 4e+86) {
tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (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;
}
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_46re) - (((x_46re * x_46im) + (x_46im * x_46re)) * x_46im)
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 <= (-5d+154)) then
tmp = (x_46im * (-3.0d0)) * (x_46re * x_46im)
else if (x_46im <= 4d+86) then
tmp = (x_46re * ((x_46re * x_46re) - (x_46im * x_46im))) - (x_46im * (x_46re * (x_46im + x_46im)))
else
tmp = x_46im * (x_46im * (x_46re * (-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_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 tmp;
if (x_46_im <= -5e+154) {
tmp = (x_46_im * -3.0) * (x_46_re * x_46_im);
} else if (x_46_im <= 4e+86) {
tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (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): tmp = 0 if x_46_im <= -5e+154: tmp = (x_46_im * -3.0) * (x_46_re * x_46_im) elif x_46_im <= 4e+86: tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (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) tmp = 0.0 if (x_46_im <= -5e+154) tmp = Float64(Float64(x_46_im * -3.0) * Float64(x_46_re * x_46_im)); elseif (x_46_im <= 4e+86) tmp = Float64(Float64(x_46_re * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))) - Float64(x_46_im * Float64(x_46_re * Float64(x_46_im + x_46_im)))); else tmp = Float64(x_46_im * Float64(x_46_im * Float64(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) tmp = 0.0; if (x_46_im <= -5e+154) tmp = (x_46_im * -3.0) * (x_46_re * x_46_im); elseif (x_46_im <= 4e+86) tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (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_] := If[LessEqual[x$46$im, -5e+154], N[(N[(x$46$im * -3.0), $MachinePrecision] * N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$im, 4e+86], N[(N[(x$46$re * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(x$46$re * N[(x$46$im + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(x$46$im * N[(x$46$re * -3.0), $MachinePrecision]), $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.im \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\left(x.im \cdot -3\right) \cdot \left(x.re \cdot x.im\right)\\
\mathbf{elif}\;x.im \leq 4 \cdot 10^{+86}:\\
\;\;\;\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x.im \cdot \left(x.im \cdot \left(x.re \cdot -3\right)\right)\\
\end{array}
Results
| Original | 88.4% |
|---|---|
| Target | 99.6% |
| Herbie | 99.6% |
if x.im < -5.00000000000000004e154Initial 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
\] |
|---|---|
*-commutative [=>]0.0 | \[ \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
\] |
fma-neg [=>]0.0 | \[ \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, -\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)}
\] |
distribute-lft-neg-in [=>]0.0 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \color{blue}{\left(-\left(x.re \cdot x.im + x.im \cdot x.re\right)\right) \cdot x.im}\right)
\] |
*-commutative [=>]0.0 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \color{blue}{x.im \cdot \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right)\right)}\right)
\] |
*-commutative [=>]0.0 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-\left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right)\right)\right)
\] |
count-2 [=>]0.0 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-\color{blue}{2 \cdot \left(x.im \cdot x.re\right)}\right)\right)
\] |
distribute-lft-neg-in [=>]0.0 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \color{blue}{\left(\left(-2\right) \cdot \left(x.im \cdot x.re\right)\right)}\right)
\] |
metadata-eval [=>]0.0 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(\color{blue}{-2} \cdot \left(x.im \cdot x.re\right)\right)\right)
\] |
*-commutative [<=]0.0 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \color{blue}{\left(x.re \cdot x.im\right)}\right)\right)
\] |
Taylor expanded in x.re around 0 0.0%
Simplified0.0%
[Start]0.0 | \[ \left(-2 \cdot {x.im}^{2} + -1 \cdot {x.im}^{2}\right) \cdot x.re
\] |
|---|---|
*-commutative [=>]0.0 | \[ \color{blue}{x.re \cdot \left(-2 \cdot {x.im}^{2} + -1 \cdot {x.im}^{2}\right)}
\] |
distribute-rgt-out [=>]0.0 | \[ x.re \cdot \color{blue}{\left({x.im}^{2} \cdot \left(-2 + -1\right)\right)}
\] |
unpow2 [=>]0.0 | \[ x.re \cdot \left(\color{blue}{\left(x.im \cdot x.im\right)} \cdot \left(-2 + -1\right)\right)
\] |
metadata-eval [=>]0.0 | \[ x.re \cdot \left(\left(x.im \cdot x.im\right) \cdot \color{blue}{-3}\right)
\] |
metadata-eval [<=]0.0 | \[ x.re \cdot \left(\left(x.im \cdot x.im\right) \cdot \color{blue}{\left(-1 + -2\right)}\right)
\] |
associate-*l* [=>]0.0 | \[ x.re \cdot \color{blue}{\left(x.im \cdot \left(x.im \cdot \left(-1 + -2\right)\right)\right)}
\] |
metadata-eval [=>]0.0 | \[ x.re \cdot \left(x.im \cdot \left(x.im \cdot \color{blue}{-3}\right)\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.5 | \[ -3 \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot x.im\right)}
\] |
*-commutative [<=]99.5 | \[ -3 \cdot \color{blue}{\left(x.im \cdot \left(x.re \cdot x.im\right)\right)}
\] |
associate-*r* [=>]99.4 | \[ \color{blue}{\left(-3 \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}
\] |
if -5.00000000000000004e154 < x.im < 4.0000000000000001e86Initial 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(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)
\] |
distribute-lft-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 4.0000000000000001e86 < x.im Initial program 50.4%
Simplified50.4%
[Start]50.4 | \[ \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 [=>]50.4 | \[ \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
\] |
fma-neg [=>]50.4 | \[ \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, -\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)}
\] |
distribute-lft-neg-in [=>]50.4 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \color{blue}{\left(-\left(x.re \cdot x.im + x.im \cdot x.re\right)\right) \cdot x.im}\right)
\] |
*-commutative [=>]50.4 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \color{blue}{x.im \cdot \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right)\right)}\right)
\] |
*-commutative [=>]50.4 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-\left(\color{blue}{x.im \cdot x.re} + x.im \cdot x.re\right)\right)\right)
\] |
count-2 [=>]50.4 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-\color{blue}{2 \cdot \left(x.im \cdot x.re\right)}\right)\right)
\] |
distribute-lft-neg-in [=>]50.4 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \color{blue}{\left(\left(-2\right) \cdot \left(x.im \cdot x.re\right)\right)}\right)
\] |
metadata-eval [=>]50.4 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(\color{blue}{-2} \cdot \left(x.im \cdot x.re\right)\right)\right)
\] |
*-commutative [<=]50.4 | \[ \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \color{blue}{\left(x.re \cdot x.im\right)}\right)\right)
\] |
Taylor expanded in x.re around 0 49.7%
Simplified99.2%
[Start]49.7 | \[ \left(-2 \cdot {x.im}^{2} + -1 \cdot {x.im}^{2}\right) \cdot x.re
\] |
|---|---|
distribute-rgt-out [=>]49.7 | \[ \color{blue}{\left({x.im}^{2} \cdot \left(-2 + -1\right)\right)} \cdot x.re
\] |
metadata-eval [=>]49.7 | \[ \left({x.im}^{2} \cdot \color{blue}{-3}\right) \cdot x.re
\] |
metadata-eval [<=]49.7 | \[ \left({x.im}^{2} \cdot \color{blue}{\left(-1 + -2\right)}\right) \cdot x.re
\] |
associate-*l* [=>]50.1 | \[ \color{blue}{{x.im}^{2} \cdot \left(\left(-1 + -2\right) \cdot x.re\right)}
\] |
*-commutative [<=]50.1 | \[ {x.im}^{2} \cdot \color{blue}{\left(x.re \cdot \left(-1 + -2\right)\right)}
\] |
distribute-rgt-out [<=]50.1 | \[ {x.im}^{2} \cdot \color{blue}{\left(-1 \cdot x.re + -2 \cdot x.re\right)}
\] |
unpow2 [=>]50.1 | \[ \color{blue}{\left(x.im \cdot x.im\right)} \cdot \left(-1 \cdot x.re + -2 \cdot x.re\right)
\] |
associate-*l* [=>]99.2 | \[ \color{blue}{x.im \cdot \left(x.im \cdot \left(-1 \cdot x.re + -2 \cdot x.re\right)\right)}
\] |
distribute-rgt-out [=>]99.2 | \[ x.im \cdot \left(x.im \cdot \color{blue}{\left(x.re \cdot \left(-1 + -2\right)\right)}\right)
\] |
metadata-eval [=>]99.2 | \[ x.im \cdot \left(x.im \cdot \left(x.re \cdot \color{blue}{-3}\right)\right)
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1096 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1088 |
| Alternative 3 | |
|---|---|
| Accuracy | 79.8% |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Accuracy | 91.1% |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Accuracy | 91.0% |
| Cost | 712 |
| Alternative 6 | |
|---|---|
| Accuracy | 55.2% |
| Cost | 320 |
herbie shell --seed 2023147
(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)))