| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 712 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -1.58 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 150000000:\\
\;\;\;\;y \cdot \frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{y}\\
\end{array}
\]

(FPCore (x y) :precision binary64 (/ (* x y) (+ y 1.0)))
(FPCore (x y) :precision binary64 (if (<= y -1.58e+38) x (if (<= y 150000000.0) (* y (/ x (+ y 1.0))) (- x (/ x y)))))
double code(double x, double y) {
return (x * y) / (y + 1.0);
}
double code(double x, double y) {
double tmp;
if (y <= -1.58e+38) {
tmp = x;
} else if (y <= 150000000.0) {
tmp = y * (x / (y + 1.0));
} else {
tmp = x - (x / y);
}
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 <= (-1.58d+38)) then
tmp = x
else if (y <= 150000000.0d0) then
tmp = y * (x / (y + 1.0d0))
else
tmp = x - (x / y)
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 <= -1.58e+38) {
tmp = x;
} else if (y <= 150000000.0) {
tmp = y * (x / (y + 1.0));
} else {
tmp = x - (x / y);
}
return tmp;
}
def code(x, y): return (x * y) / (y + 1.0)
def code(x, y): tmp = 0 if y <= -1.58e+38: tmp = x elif y <= 150000000.0: tmp = y * (x / (y + 1.0)) else: tmp = x - (x / y) 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 <= -1.58e+38) tmp = x; elseif (y <= 150000000.0) tmp = Float64(y * Float64(x / Float64(y + 1.0))); else tmp = Float64(x - Float64(x / y)); 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 <= -1.58e+38) tmp = x; elseif (y <= 150000000.0) tmp = y * (x / (y + 1.0)); else tmp = x - (x / y); 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, -1.58e+38], x, If[LessEqual[y, 150000000.0], N[(y * N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -1.58 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 150000000:\\
\;\;\;\;y \cdot \frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{y}\\
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 87.9% |
|---|---|
| Target | 100.0% |
| Herbie | 99.9% |
if y < -1.58e38Initial program 72.8%
Simplified100.0%
[Start]72.8% | \[ \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%
if -1.58e38 < y < 1.5e8Initial program 99.9%
Simplified99.7%
[Start]99.9% | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
*-commutative [=>]99.9% | \[ \frac{\color{blue}{y \cdot x}}{y + 1}
\] |
associate-/l* [=>]99.7% | \[ \color{blue}{\frac{y}{\frac{y + 1}{x}}}
\] |
Applied egg-rr100.0%
[Start]99.7% | \[ \frac{y}{\frac{y + 1}{x}}
\] |
|---|---|
clear-num [=>]97.9% | \[ \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 1.5e8 < y Initial program 74.0%
Simplified100.0%
[Start]74.0% | \[ \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}}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 712 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 713 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 585 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 456 |
| Alternative 5 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 448 |
| Alternative 6 | |
|---|---|
| Accuracy | 51.6% |
| Cost | 64 |
herbie shell --seed 2023178
(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)))