| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 713 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\
\end{array}
\]
(FPCore (x y) :precision binary64 (/ (* x y) (+ y 1.0)))
(FPCore (x y) :precision binary64 (if (<= y -125000000.0) (- x (/ x y)) (if (<= y 5.5e+15) (* y (/ x (+ y 1.0))) x)))
double code(double x, double y) {
return (x * y) / (y + 1.0);
}
double code(double x, double y) {
double tmp;
if (y <= -125000000.0) {
tmp = x - (x / y);
} else if (y <= 5.5e+15) {
tmp = y * (x / (y + 1.0));
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) / (y + 1.0d0)
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-125000000.0d0)) then
tmp = x - (x / y)
else if (y <= 5.5d+15) then
tmp = y * (x / (y + 1.0d0))
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
return (x * y) / (y + 1.0);
}
public static double code(double x, double y) {
double tmp;
if (y <= -125000000.0) {
tmp = x - (x / y);
} else if (y <= 5.5e+15) {
tmp = y * (x / (y + 1.0));
} else {
tmp = x;
}
return tmp;
}
def code(x, y): return (x * y) / (y + 1.0)
def code(x, y): tmp = 0 if y <= -125000000.0: tmp = x - (x / y) elif y <= 5.5e+15: tmp = y * (x / (y + 1.0)) else: tmp = x return tmp
function code(x, y) return Float64(Float64(x * y) / Float64(y + 1.0)) end
function code(x, y) tmp = 0.0 if (y <= -125000000.0) tmp = Float64(x - Float64(x / y)); elseif (y <= 5.5e+15) tmp = Float64(y * Float64(x / Float64(y + 1.0))); else tmp = x; end return tmp end
function tmp = code(x, y) tmp = (x * y) / (y + 1.0); end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -125000000.0) tmp = x - (x / y); elseif (y <= 5.5e+15) tmp = y * (x / (y + 1.0)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[y, -125000000.0], N[(x - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.5e+15], N[(y * N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]]
\frac{x \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -125000000:\\
\;\;\;\;x - \frac{x}{y}\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+15}:\\
\;\;\;\;y \cdot \frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
Results
| Original | 87.4% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
if y < -1.25e8Initial program 74.4%
Simplified100.0%
[Start]74.4 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
associate-*r/ [<=]100.0 | \[ \color{blue}{x \cdot \frac{y}{y + 1}}
\] |
*-commutative [<=]100.0 | \[ \color{blue}{\frac{y}{y + 1} \cdot x}
\] |
Taylor expanded in y around inf 100.0%
Simplified100.0%
[Start]100.0 | \[ -1 \cdot \frac{x}{y} + x
\] |
|---|---|
+-commutative [=>]100.0 | \[ \color{blue}{x + -1 \cdot \frac{x}{y}}
\] |
mul-1-neg [=>]100.0 | \[ x + \color{blue}{\left(-\frac{x}{y}\right)}
\] |
unsub-neg [=>]100.0 | \[ \color{blue}{x - \frac{x}{y}}
\] |
if -1.25e8 < y < 5.5e15Initial program 99.9%
Simplified99.6%
[Start]99.9 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
*-commutative [=>]99.9 | \[ \frac{\color{blue}{y \cdot x}}{y + 1}
\] |
associate-/l* [=>]99.6 | \[ \color{blue}{\frac{y}{\frac{y + 1}{x}}}
\] |
Applied egg-rr100.0%
[Start]99.6 | \[ \frac{y}{\frac{y + 1}{x}}
\] |
|---|---|
clear-num [=>]98.5 | \[ \color{blue}{\frac{1}{\frac{\frac{y + 1}{x}}{y}}}
\] |
associate-/r/ [=>]99.8 | \[ \color{blue}{\frac{1}{\frac{y + 1}{x}} \cdot y}
\] |
clear-num [<=]100.0 | \[ \color{blue}{\frac{x}{y + 1}} \cdot y
\] |
if 5.5e15 < y Initial program 73.3%
Simplified100.0%
[Start]73.3 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
associate-*r/ [<=]100.0 | \[ \color{blue}{x \cdot \frac{y}{y + 1}}
\] |
*-commutative [<=]100.0 | \[ \color{blue}{\frac{y}{y + 1} \cdot x}
\] |
Taylor expanded in y around inf 100.0%
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 713 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 585 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 456 |
| Alternative 4 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Accuracy | 50.9% |
| Cost | 64 |
herbie shell --seed 2023153
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, B"
:precision binary64
:herbie-target
(if (< y -3693.8482788297247) (- (/ x (* y y)) (- (/ x y) x)) (if (< y 6799310503.41891) (/ (* x y) (+ y 1.0)) (- (/ x (* y y)) (- (/ x y) x))))
(/ (* x y) (+ y 1.0)))