| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 585 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.35\right):\\
\;\;\;\;x - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\]
(FPCore (x y) :precision binary64 (/ (* x y) (+ y 1.0)))
(FPCore (x y) :precision binary64 (if (or (<= y -400000000.0) (not (<= y 240000000.0))) (- x (/ x y)) (* y (/ x (+ y 1.0)))))
double code(double x, double y) {
return (x * y) / (y + 1.0);
}
double code(double x, double y) {
double tmp;
if ((y <= -400000000.0) || !(y <= 240000000.0)) {
tmp = x - (x / y);
} else {
tmp = y * (x / (y + 1.0));
}
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 <= (-400000000.0d0)) .or. (.not. (y <= 240000000.0d0))) then
tmp = x - (x / y)
else
tmp = y * (x / (y + 1.0d0))
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 <= -400000000.0) || !(y <= 240000000.0)) {
tmp = x - (x / y);
} else {
tmp = y * (x / (y + 1.0));
}
return tmp;
}
def code(x, y): return (x * y) / (y + 1.0)
def code(x, y): tmp = 0 if (y <= -400000000.0) or not (y <= 240000000.0): tmp = x - (x / y) else: tmp = y * (x / (y + 1.0)) 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 <= -400000000.0) || !(y <= 240000000.0)) tmp = Float64(x - Float64(x / y)); else tmp = Float64(y * Float64(x / Float64(y + 1.0))); 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 <= -400000000.0) || ~((y <= 240000000.0))) tmp = x - (x / y); else tmp = y * (x / (y + 1.0)); end tmp_2 = tmp; end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[Or[LessEqual[y, -400000000.0], N[Not[LessEqual[y, 240000000.0]], $MachinePrecision]], N[(x - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -400000000 \lor \neg \left(y \leq 240000000\right):\\
\;\;\;\;x - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y + 1}\\
\end{array}
Results
| Original | 8.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.0 |
if y < -4e8 or 2.4e8 < y Initial program 17.0
Simplified0.0
[Start]17.0 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
associate-/l* [=>]0.0 | \[ \color{blue}{\frac{x}{\frac{y + 1}{y}}}
\] |
Taylor expanded in y around inf 0
Simplified0
[Start]0 | \[ -1 \cdot \frac{x}{y} + x
\] |
|---|---|
+-commutative [=>]0 | \[ \color{blue}{x + -1 \cdot \frac{x}{y}}
\] |
mul-1-neg [=>]0 | \[ x + \color{blue}{\left(-\frac{x}{y}\right)}
\] |
unsub-neg [=>]0 | \[ \color{blue}{x - \frac{x}{y}}
\] |
if -4e8 < y < 2.4e8Initial program 0.0
Simplified0.2
[Start]0.0 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
associate-/l* [=>]0.2 | \[ \color{blue}{\frac{x}{\frac{y + 1}{y}}}
\] |
Applied egg-rr0.0
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 585 |
| Alternative 2 | |
|---|---|
| Error | 1.3 |
| Cost | 456 |
| Alternative 3 | |
|---|---|
| Error | 0.1 |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Error | 31.0 |
| Cost | 64 |
herbie shell --seed 2023046
(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)))