| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 7040 |
\[{x.re}^{3} + \left(x.im \cdot -3\right) \cdot \left(x.re \cdot x.im\right)
\]
(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)))
(* x.im (+ (* x.re x.im) (* x.re x.im))))))
(if (<= t_0 -4e+287)
(* x.im (* x.im (* x.re -3.0)))
(if (<= t_0 2e+295)
(-
(* x.re (* (- x.re x.im) (+ x.re 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 t_0 = (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_re * x_46_im)));
double tmp;
if (t_0 <= -4e+287) {
tmp = x_46_im * (x_46_im * (x_46_re * -3.0));
} else if (t_0 <= 2e+295) {
tmp = (x_46_re * ((x_46_re - x_46_im) * (x_46_re + 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) :: t_0
real(8) :: tmp
t_0 = (x_46re * ((x_46re * x_46re) - (x_46im * x_46im))) - (x_46im * ((x_46re * x_46im) + (x_46re * x_46im)))
if (t_0 <= (-4d+287)) then
tmp = x_46im * (x_46im * (x_46re * (-3.0d0)))
else if (t_0 <= 2d+295) then
tmp = (x_46re * ((x_46re - x_46im) * (x_46re + 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 t_0 = (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_re * x_46_im)));
double tmp;
if (t_0 <= -4e+287) {
tmp = x_46_im * (x_46_im * (x_46_re * -3.0));
} else if (t_0 <= 2e+295) {
tmp = (x_46_re * ((x_46_re - x_46_im) * (x_46_re + 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): t_0 = (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_re * x_46_im))) tmp = 0 if t_0 <= -4e+287: tmp = x_46_im * (x_46_im * (x_46_re * -3.0)) elif t_0 <= 2e+295: tmp = (x_46_re * ((x_46_re - x_46_im) * (x_46_re + 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) t_0 = 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(Float64(x_46_re * x_46_im) + Float64(x_46_re * x_46_im)))) tmp = 0.0 if (t_0 <= -4e+287) tmp = Float64(x_46_im * Float64(x_46_im * Float64(x_46_re * -3.0))); elseif (t_0 <= 2e+295) tmp = Float64(Float64(x_46_re * Float64(Float64(x_46_re - x_46_im) * Float64(x_46_re + 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) t_0 = (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_re * x_46_im))); tmp = 0.0; if (t_0 <= -4e+287) tmp = x_46_im * (x_46_im * (x_46_re * -3.0)); elseif (t_0 <= 2e+295) tmp = (x_46_re * ((x_46_re - x_46_im) * (x_46_re + 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_] := Block[{t$95$0 = 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[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+287], N[(x$46$im * N[(x$46$im * N[(x$46$re * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+295], N[(N[(x$46$re * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$re + 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}
t_0 := x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\
\mathbf{if}\;t_0 \leq -4 \cdot 10^{+287}:\\
\;\;\;\;x.im \cdot \left(x.im \cdot \left(x.re \cdot -3\right)\right)\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+295}:\\
\;\;\;\;x.re \cdot \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\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 | 7.1 |
|---|---|
| Target | 0.2 |
| Herbie | 0.9 |
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)) < -4.0000000000000003e287Initial program 54.6
Simplified54.6
Taylor expanded in x.im around inf 60.9
Simplified60.9
Applied egg-rr6.6
Applied egg-rr6.6
if -4.0000000000000003e287 < (-.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)) < 2e295Initial program 0.2
Simplified0.2
Applied egg-rr0.2
if 2e295 < (-.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 57.3
Simplified57.3
Taylor expanded in x.im around inf 61.9
Simplified61.9
Applied egg-rr5.0
Applied egg-rr5.0
Taylor expanded in x.im around 0 5.0
Simplified5.0
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 7040 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 7040 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 1216 |
| Alternative 4 | |
|---|---|
| Error | 0.3 |
| Cost | 1216 |
| Alternative 5 | |
|---|---|
| Error | 0.2 |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Error | 5.5 |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 5.5 |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Error | 27.1 |
| Cost | 649 |
| Alternative 9 | |
|---|---|
| Error | 25.8 |
| Cost | 649 |
| Alternative 10 | |
|---|---|
| Error | 28.3 |
| Cost | 320 |
herbie shell --seed 2022343
(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)))