| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1088 |
(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 -1.5e+97)
(* x.im (* x.im (* x.re -3.0)))
(if (<= x.im 5.4e+120)
(-
(* x.re (- (* x.re x.re) (* x.im x.im)))
(* x.im (* x.re (+ x.im x.im))))
(* x.im (* x.re (* 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_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 <= -1.5e+97) {
tmp = x_46_im * (x_46_im * (x_46_re * -3.0));
} else if (x_46_im <= 5.4e+120) {
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_re * (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_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 <= (-1.5d+97)) then
tmp = x_46im * (x_46im * (x_46re * (-3.0d0)))
else if (x_46im <= 5.4d+120) 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_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_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 <= -1.5e+97) {
tmp = x_46_im * (x_46_im * (x_46_re * -3.0));
} else if (x_46_im <= 5.4e+120) {
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_re * (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_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 <= -1.5e+97: tmp = x_46_im * (x_46_im * (x_46_re * -3.0)) elif x_46_im <= 5.4e+120: 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_re * (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_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 <= -1.5e+97) tmp = Float64(x_46_im * Float64(x_46_im * Float64(x_46_re * -3.0))); elseif (x_46_im <= 5.4e+120) 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_re * Float64(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_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 <= -1.5e+97) tmp = x_46_im * (x_46_im * (x_46_re * -3.0)); elseif (x_46_im <= 5.4e+120) 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_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$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, -1.5e+97], N[(x$46$im * N[(x$46$im * N[(x$46$re * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$im, 5.4e+120], 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$re * N[(x$46$im * -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 -1.5 \cdot 10^{+97}:\\
\;\;\;\;x.im \cdot \left(x.im \cdot \left(x.re \cdot -3\right)\right)\\
\mathbf{elif}\;x.im \leq 5.4 \cdot 10^{+120}:\\
\;\;\;\;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.re \cdot \left(x.im \cdot -3\right)\right)\\
\end{array}
Results
| Original | 88.8% |
|---|---|
| Target | 99.6% |
| Herbie | 99.6% |
if x.im < -1.4999999999999999e97Initial program 47.6%
Simplified47.6%
[Start]47.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 [=>]47.6 | \[ \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 [=>]47.6 | \[ \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 [=>]47.6 | \[ \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 [=>]47.6 | \[ \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 [=>]47.6 | \[ \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 [=>]47.6 | \[ \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 [=>]47.6 | \[ \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 [=>]47.6 | \[ \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 [<=]47.6 | \[ \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 47.3%
Simplified99.3%
[Start]47.3 | \[ \left(-2 \cdot {x.im}^{2} + -1 \cdot {x.im}^{2}\right) \cdot x.re
\] |
|---|---|
distribute-rgt-out [=>]47.3 | \[ \color{blue}{\left({x.im}^{2} \cdot \left(-2 + -1\right)\right)} \cdot x.re
\] |
metadata-eval [=>]47.3 | \[ \left({x.im}^{2} \cdot \color{blue}{-3}\right) \cdot x.re
\] |
metadata-eval [<=]47.3 | \[ \left({x.im}^{2} \cdot \color{blue}{\left(-1 + -2\right)}\right) \cdot x.re
\] |
associate-*l* [=>]47.4 | \[ \color{blue}{{x.im}^{2} \cdot \left(\left(-1 + -2\right) \cdot x.re\right)}
\] |
*-commutative [<=]47.4 | \[ {x.im}^{2} \cdot \color{blue}{\left(x.re \cdot \left(-1 + -2\right)\right)}
\] |
distribute-rgt-out [<=]47.4 | \[ {x.im}^{2} \cdot \color{blue}{\left(-1 \cdot x.re + -2 \cdot x.re\right)}
\] |
unpow2 [=>]47.4 | \[ \color{blue}{\left(x.im \cdot x.im\right)} \cdot \left(-1 \cdot x.re + -2 \cdot x.re\right)
\] |
associate-*l* [=>]99.3 | \[ \color{blue}{x.im \cdot \left(x.im \cdot \left(-1 \cdot x.re + -2 \cdot x.re\right)\right)}
\] |
distribute-rgt-out [=>]99.3 | \[ x.im \cdot \left(x.im \cdot \color{blue}{\left(x.re \cdot \left(-1 + -2\right)\right)}\right)
\] |
metadata-eval [=>]99.3 | \[ x.im \cdot \left(x.im \cdot \left(x.re \cdot \color{blue}{-3}\right)\right)
\] |
if -1.4999999999999999e97 < x.im < 5.3999999999999999e120Initial 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 5.3999999999999999e120 < x.im Initial program 33.0%
Simplified33.0%
[Start]33.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 [<=]33.0 | \[ \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 [=>]33.0 | \[ \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* [=>]33.0 | \[ \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 [=>]33.0 | \[ \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-- [=>]32.9 | \[ \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- [=>]32.9 | \[ 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- [<=]32.9 | \[ 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 [=>]32.9 | \[ 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+ [=>]32.9 | \[ 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 [<=]32.9 | \[ 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 [=>]32.9 | \[ 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 [=>]32.9 | \[ 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* [=>]32.9 | \[ 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-- [=>]32.9 | \[ 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* [<=]33.0 | \[ 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 [=>]33.0 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot \color{blue}{-3}\right)\right)
\] |
Applied egg-rr33.0%
[Start]33.0 | \[ x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot -3\right)\right)
\] |
|---|---|
fma-udef [=>]33.0 | \[ x.re \cdot \color{blue}{\left(x.re \cdot x.re + x.im \cdot \left(x.im \cdot -3\right)\right)}
\] |
Taylor expanded in x.re around 0 33.0%
Simplified99.4%
[Start]33.0 | \[ -3 \cdot \left(x.re \cdot {x.im}^{2}\right)
\] |
|---|---|
unpow2 [=>]33.0 | \[ -3 \cdot \left(x.re \cdot \color{blue}{\left(x.im \cdot x.im\right)}\right)
\] |
associate-*r* [=>]33.0 | \[ \color{blue}{\left(-3 \cdot x.re\right) \cdot \left(x.im \cdot x.im\right)}
\] |
*-commutative [=>]33.0 | \[ \color{blue}{\left(x.im \cdot x.im\right) \cdot \left(-3 \cdot x.re\right)}
\] |
associate-*r* [<=]99.4 | \[ \color{blue}{x.im \cdot \left(x.im \cdot \left(-3 \cdot x.re\right)\right)}
\] |
associate-*l* [<=]99.4 | \[ x.im \cdot \color{blue}{\left(\left(x.im \cdot -3\right) \cdot x.re\right)}
\] |
*-commutative [<=]99.4 | \[ x.im \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot -3\right)\right)}
\] |
*-commutative [=>]99.4 | \[ x.im \cdot \left(x.re \cdot \color{blue}{\left(-3 \cdot x.im\right)}\right)
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1088 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 968 |
| Alternative 3 | |
|---|---|
| Accuracy | 92.0% |
| Cost | 840 |
| Alternative 4 | |
|---|---|
| Accuracy | 81.0% |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Accuracy | 91.8% |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Accuracy | 91.8% |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Accuracy | 91.8% |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Accuracy | 60.2% |
| Cost | 649 |
| Alternative 9 | |
|---|---|
| Accuracy | 56.2% |
| Cost | 320 |
herbie shell --seed 2023151
(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)))