| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 7040 |
(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.im (- (* x.re x.re) (* x.im x.im))))
(t_1 (+ t_0 (* x.re (+ (* x.re x.im) (* x.re x.im))))))
(if (<= t_1 -5e+273)
(* x.re (* x.re (* x.im 3.0)))
(if (<= t_1 2e+301)
(+ (* x.re (* (* x.re x.im) 2.0)) t_0)
(* 3.0 (* x.re (* x.re x.im)))))))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_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im));
double t_1 = t_0 + (x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im)));
double tmp;
if (t_1 <= -5e+273) {
tmp = x_46_re * (x_46_re * (x_46_im * 3.0));
} else if (t_1 <= 2e+301) {
tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + t_0;
} else {
tmp = 3.0 * (x_46_re * (x_46_re * x_46_im));
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x_46im * ((x_46re * x_46re) - (x_46im * x_46im))
t_1 = t_0 + (x_46re * ((x_46re * x_46im) + (x_46re * x_46im)))
if (t_1 <= (-5d+273)) then
tmp = x_46re * (x_46re * (x_46im * 3.0d0))
else if (t_1 <= 2d+301) then
tmp = (x_46re * ((x_46re * x_46im) * 2.0d0)) + t_0
else
tmp = 3.0d0 * (x_46re * (x_46re * x_46im))
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 t_0 = x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im));
double t_1 = t_0 + (x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im)));
double tmp;
if (t_1 <= -5e+273) {
tmp = x_46_re * (x_46_re * (x_46_im * 3.0));
} else if (t_1 <= 2e+301) {
tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + t_0;
} else {
tmp = 3.0 * (x_46_re * (x_46_re * x_46_im));
}
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_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)) t_1 = t_0 + (x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im))) tmp = 0 if t_1 <= -5e+273: tmp = x_46_re * (x_46_re * (x_46_im * 3.0)) elif t_1 <= 2e+301: tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + t_0 else: tmp = 3.0 * (x_46_re * (x_46_re * x_46_im)) 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_im * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))) t_1 = Float64(t_0 + Float64(x_46_re * Float64(Float64(x_46_re * x_46_im) + Float64(x_46_re * x_46_im)))) tmp = 0.0 if (t_1 <= -5e+273) tmp = Float64(x_46_re * Float64(x_46_re * Float64(x_46_im * 3.0))); elseif (t_1 <= 2e+301) tmp = Float64(Float64(x_46_re * Float64(Float64(x_46_re * x_46_im) * 2.0)) + t_0); else tmp = Float64(3.0 * Float64(x_46_re * Float64(x_46_re * x_46_im))); 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_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)); t_1 = t_0 + (x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im))); tmp = 0.0; if (t_1 <= -5e+273) tmp = x_46_re * (x_46_re * (x_46_im * 3.0)); elseif (t_1 <= 2e+301) tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + t_0; else tmp = 3.0 * (x_46_re * (x_46_re * x_46_im)); 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$im * 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$re * N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+273], N[(x$46$re * N[(x$46$re * N[(x$46$im * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+301], N[(N[(x$46$re * N[(N[(x$46$re * x$46$im), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], N[(3.0 * N[(x$46$re * N[(x$46$re * x$46$im), $MachinePrecision]), $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}
t_0 := x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\
t_1 := t_0 + x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+273}:\\
\;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+301}:\\
\;\;\;\;x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 2\right) + t_0\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\
\end{array}
Results
| Original | 88.4% |
|---|---|
| Target | 99.6% |
| Herbie | 98.5% |
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)) < -4.99999999999999961e273Initial program 20.4%
Applied egg-rr20.4%
[Start]20.4 | \[ \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
\] |
|---|---|
*-un-lft-identity [=>]20.4 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(\color{blue}{1 \cdot \left(x.re \cdot x.im\right)} + x.im \cdot x.re\right) \cdot x.re
\] |
*-commutative [<=]20.4 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(1 \cdot \left(x.re \cdot x.im\right) + \color{blue}{x.re \cdot x.im}\right) \cdot x.re
\] |
*-un-lft-identity [=>]20.4 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(1 \cdot \left(x.re \cdot x.im\right) + \color{blue}{1 \cdot \left(x.re \cdot x.im\right)}\right) \cdot x.re
\] |
distribute-rgt-out [=>]20.4 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot \left(1 + 1\right)\right)} \cdot x.re
\] |
metadata-eval [=>]20.4 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(\left(x.re \cdot x.im\right) \cdot \color{blue}{2}\right) \cdot x.re
\] |
Taylor expanded in x.re around inf 5.8%
Simplified84.9%
[Start]5.8 | \[ {x.re}^{2} \cdot \left(x.im + 2 \cdot x.im\right)
\] |
|---|---|
unpow2 [=>]5.8 | \[ \color{blue}{\left(x.re \cdot x.re\right)} \cdot \left(x.im + 2 \cdot x.im\right)
\] |
associate-*l* [=>]84.9 | \[ \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im + 2 \cdot x.im\right)\right)}
\] |
distribute-rgt1-in [=>]84.9 | \[ x.re \cdot \left(x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot x.im\right)}\right)
\] |
metadata-eval [=>]84.9 | \[ x.re \cdot \left(x.re \cdot \left(\color{blue}{3} \cdot x.im\right)\right)
\] |
*-commutative [=>]84.9 | \[ x.re \cdot \left(x.re \cdot \color{blue}{\left(x.im \cdot 3\right)}\right)
\] |
if -4.99999999999999961e273 < (+.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)) < 2.00000000000000011e301Initial program 99.7%
Applied egg-rr99.7%
[Start]99.7 | \[ \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
\] |
|---|---|
*-un-lft-identity [=>]99.7 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(\color{blue}{1 \cdot \left(x.re \cdot x.im\right)} + x.im \cdot x.re\right) \cdot x.re
\] |
*-commutative [<=]99.7 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(1 \cdot \left(x.re \cdot x.im\right) + \color{blue}{x.re \cdot x.im}\right) \cdot x.re
\] |
*-un-lft-identity [=>]99.7 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(1 \cdot \left(x.re \cdot x.im\right) + \color{blue}{1 \cdot \left(x.re \cdot x.im\right)}\right) \cdot x.re
\] |
distribute-rgt-out [=>]99.7 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot \left(1 + 1\right)\right)} \cdot x.re
\] |
metadata-eval [=>]99.7 | \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(\left(x.re \cdot x.im\right) \cdot \color{blue}{2}\right) \cdot x.re
\] |
if 2.00000000000000011e301 < (+.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 2.8%
Simplified2.8%
[Start]2.8 | \[ \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 [=>]2.8 | \[ \color{blue}{x.im \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.re
\] |
*-commutative [<=]2.8 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re
\] |
distribute-rgt-out [=>]2.8 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.re
\] |
associate-*l* [=>]2.8 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) \cdot x.re\right)}
\] |
distribute-lft-out [=>]2.8 | \[ \color{blue}{x.im \cdot \left(\left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.re + x.re\right) \cdot x.re\right)}
\] |
+-commutative [<=]2.8 | \[ x.im \cdot \color{blue}{\left(\left(x.re + x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right)\right)}
\] |
associate-+r- [=>]2.8 | \[ x.im \cdot \color{blue}{\left(\left(\left(x.re + x.re\right) \cdot x.re + x.re \cdot x.re\right) - x.im \cdot x.im\right)}
\] |
count-2 [=>]2.8 | \[ x.im \cdot \left(\left(\color{blue}{\left(2 \cdot x.re\right)} \cdot x.re + x.re \cdot x.re\right) - x.im \cdot x.im\right)
\] |
associate-*l* [=>]2.8 | \[ x.im \cdot \left(\left(\color{blue}{2 \cdot \left(x.re \cdot x.re\right)} + x.re \cdot x.re\right) - x.im \cdot x.im\right)
\] |
distribute-lft1-in [=>]2.8 | \[ x.im \cdot \left(\color{blue}{\left(2 + 1\right) \cdot \left(x.re \cdot x.re\right)} - x.im \cdot x.im\right)
\] |
fma-neg [=>]2.8 | \[ x.im \cdot \color{blue}{\mathsf{fma}\left(2 + 1, x.re \cdot x.re, -x.im \cdot x.im\right)}
\] |
metadata-eval [=>]2.8 | \[ x.im \cdot \mathsf{fma}\left(\color{blue}{3}, x.re \cdot x.re, -x.im \cdot x.im\right)
\] |
Taylor expanded in x.im around 0 0.9%
Simplified97.6%
[Start]0.9 | \[ 3 \cdot \left({x.re}^{2} \cdot x.im\right)
\] |
|---|---|
unpow2 [=>]0.9 | \[ 3 \cdot \left(\color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im\right)
\] |
associate-*l* [=>]97.6 | \[ 3 \cdot \color{blue}{\left(x.re \cdot \left(x.re \cdot x.im\right)\right)}
\] |
Final simplification98.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 7040 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1216 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 1096 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 968 |
| Alternative 5 | |
|---|---|
| Accuracy | 80.6% |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Accuracy | 91.8% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Accuracy | 91.8% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 54.9% |
| Cost | 384 |
herbie shell --seed 2023133
(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)))