| Alternative 1 | |
|---|---|
| Error | 16.7 |
| Cost | 840 |
(FPCore (x y z) :precision binary64 (/ (* x y) (* (* z z) (+ z 1.0))))
(FPCore (x y z)
:precision binary64
(if (<= (* x y) -5e-307)
(/ (* x y) (* (* z z) (+ z 1.0)))
(if (<= (* x y) 0.0)
(* x (+ y (+ (- (/ y z)) (/ y (pow z 2.0)))))
(/ (* x y) (* (* z z) (+ z (* z (/ 1.0 z))))))))double code(double x, double y, double z) {
return (x * y) / ((z * z) * (z + 1.0));
}
double code(double x, double y, double z) {
double tmp;
if ((x * y) <= -5e-307) {
tmp = (x * y) / ((z * z) * (z + 1.0));
} else if ((x * y) <= 0.0) {
tmp = x * (y + (-(y / z) + (y / pow(z, 2.0))));
} else {
tmp = (x * y) / ((z * z) * (z + (z * (1.0 / z))));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) / ((z * z) * (z + 1.0d0))
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x * y) <= (-5d-307)) then
tmp = (x * y) / ((z * z) * (z + 1.0d0))
else if ((x * y) <= 0.0d0) then
tmp = x * (y + (-(y / z) + (y / (z ** 2.0d0))))
else
tmp = (x * y) / ((z * z) * (z + (z * (1.0d0 / z))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x * y) / ((z * z) * (z + 1.0));
}
public static double code(double x, double y, double z) {
double tmp;
if ((x * y) <= -5e-307) {
tmp = (x * y) / ((z * z) * (z + 1.0));
} else if ((x * y) <= 0.0) {
tmp = x * (y + (-(y / z) + (y / Math.pow(z, 2.0))));
} else {
tmp = (x * y) / ((z * z) * (z + (z * (1.0 / z))));
}
return tmp;
}
def code(x, y, z): return (x * y) / ((z * z) * (z + 1.0))
def code(x, y, z): tmp = 0 if (x * y) <= -5e-307: tmp = (x * y) / ((z * z) * (z + 1.0)) elif (x * y) <= 0.0: tmp = x * (y + (-(y / z) + (y / math.pow(z, 2.0)))) else: tmp = (x * y) / ((z * z) * (z + (z * (1.0 / z)))) return tmp
function code(x, y, z) return Float64(Float64(x * y) / Float64(Float64(z * z) * Float64(z + 1.0))) end
function code(x, y, z) tmp = 0.0 if (Float64(x * y) <= -5e-307) tmp = Float64(Float64(x * y) / Float64(Float64(z * z) * Float64(z + 1.0))); elseif (Float64(x * y) <= 0.0) tmp = Float64(x * Float64(y + Float64(Float64(-Float64(y / z)) + Float64(y / (z ^ 2.0))))); else tmp = Float64(Float64(x * y) / Float64(Float64(z * z) * Float64(z + Float64(z * Float64(1.0 / z))))); end return tmp end
function tmp = code(x, y, z) tmp = (x * y) / ((z * z) * (z + 1.0)); end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * y) <= -5e-307) tmp = (x * y) / ((z * z) * (z + 1.0)); elseif ((x * y) <= 0.0) tmp = x * (y + (-(y / z) + (y / (z ^ 2.0)))); else tmp = (x * y) / ((z * z) * (z + (z * (1.0 / z)))); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] / N[(N[(z * z), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e-307], N[(N[(x * y), $MachinePrecision] / N[(N[(z * z), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 0.0], N[(x * N[(y + N[((-N[(y / z), $MachinePrecision]) + N[(y / N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / N[(N[(z * z), $MachinePrecision] * N[(z + N[(z * N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{-307}:\\
\;\;\;\;\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}\\
\mathbf{elif}\;x \cdot y \leq 0:\\
\;\;\;\;x \cdot \left(y + \left(\left(-\frac{y}{z}\right) + \frac{y}{{z}^{2}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + z \cdot \frac{1}{z}\right)}\\
\end{array}
Results
| Original | 15.4 |
|---|---|
| Target | 4.3 |
| Herbie | 13.8 |
if (*.f64 x y) < -5.00000000000000014e-307Initial program 13.1
if -5.00000000000000014e-307 < (*.f64 x y) < -0.0Initial program 26.2
Simplified26.2
[Start]26.2 | \[ \frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]26.2 | \[ \frac{x \cdot y}{\color{blue}{\left(z + 1\right) \cdot \left(z \cdot z\right)}}
\] |
rational_best_oopsla_all_46_json_45_simplify-7 [=>]26.2 | \[ \frac{x \cdot y}{\color{blue}{z \cdot \left(\left(z + 1\right) \cdot z\right)}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]26.2 | \[ \frac{x \cdot y}{z \cdot \color{blue}{\left(z \cdot \left(z + 1\right)\right)}}
\] |
Taylor expanded in z around 0 26.8
Simplified26.8
[Start]26.8 | \[ \frac{y \cdot x}{{z}^{2}} + \left(-1 \cdot \frac{y \cdot x}{z} + y \cdot x\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]26.8 | \[ \frac{y \cdot x}{{z}^{2}} + \color{blue}{\left(y \cdot x + -1 \cdot \frac{y \cdot x}{z}\right)}
\] |
Taylor expanded in x around 0 16.2
Simplified16.2
[Start]16.2 | \[ \left(-1 \cdot \frac{y}{z} + \left(y + \frac{y}{{z}^{2}}\right)\right) \cdot x
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]16.2 | \[ \color{blue}{x \cdot \left(-1 \cdot \frac{y}{z} + \left(y + \frac{y}{{z}^{2}}\right)\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-82 [=>]16.2 | \[ x \cdot \color{blue}{\left(y + \left(-1 \cdot \frac{y}{z} + \frac{y}{{z}^{2}}\right)\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]16.2 | \[ x \cdot \left(y + \left(\color{blue}{\frac{y}{z} \cdot -1} + \frac{y}{{z}^{2}}\right)\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-92 [=>]16.2 | \[ x \cdot \left(y + \left(\color{blue}{\left(-\frac{y}{z}\right)} + \frac{y}{{z}^{2}}\right)\right)
\] |
if -0.0 < (*.f64 x y) Initial program 13.7
Simplified13.7
[Start]13.7 | \[ \frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]13.7 | \[ \frac{x \cdot y}{\color{blue}{\left(z + 1\right) \cdot \left(z \cdot z\right)}}
\] |
rational_best_oopsla_all_46_json_45_simplify-7 [=>]13.7 | \[ \frac{x \cdot y}{\color{blue}{z \cdot \left(\left(z + 1\right) \cdot z\right)}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]13.7 | \[ \frac{x \cdot y}{z \cdot \color{blue}{\left(z \cdot \left(z + 1\right)\right)}}
\] |
Applied egg-rr22.9
Applied egg-rr13.7
Final simplification13.8
| Alternative 1 | |
|---|---|
| Error | 16.7 |
| Cost | 840 |
| Alternative 2 | |
|---|---|
| Error | 15.4 |
| Cost | 704 |
| Alternative 3 | |
|---|---|
| Error | 15.4 |
| Cost | 704 |
| Alternative 4 | |
|---|---|
| Error | 26.2 |
| Cost | 448 |
herbie shell --seed 2023090
(FPCore (x y z)
:name "Statistics.Distribution.Beta:$cvariance from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(if (< z 249.6182814532307) (/ (* y (/ x z)) (+ z (* z z))) (/ (* (/ (/ y z) (+ 1.0 z)) x) z))
(/ (* x y) (* (* z z) (+ z 1.0))))