| Alternative 1 | |
|---|---|
| Error | 1.47% |
| Cost | 585 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.3\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 (<= y -6.5e+50) x (if (<= y 145000000.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 <= -6.5e+50) {
tmp = x;
} else if (y <= 145000000.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 <= (-6.5d+50)) then
tmp = x
else if (y <= 145000000.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 <= -6.5e+50) {
tmp = x;
} else if (y <= 145000000.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 <= -6.5e+50: tmp = x elif y <= 145000000.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 <= -6.5e+50) tmp = x; elseif (y <= 145000000.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 <= -6.5e+50) tmp = x; elseif (y <= 145000000.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, -6.5e+50], x, If[LessEqual[y, 145000000.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 -6.5 \cdot 10^{+50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 145000000:\\
\;\;\;\;y \cdot \frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{y}\\
\end{array}
Results
| Original | 13.16% |
|---|---|
| Target | 0.06% |
| Herbie | 0.13% |
if y < -6.5000000000000003e50Initial program 30.56
Simplified0
[Start]30.56 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
associate-/l* [=>]0 | \[ \color{blue}{\frac{x}{\frac{y + 1}{y}}}
\] |
Taylor expanded in y around inf 0
if -6.5000000000000003e50 < y < 1.45e8Initial program 0.29
Simplified0.37
[Start]0.29 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
associate-/l* [=>]0.37 | \[ \color{blue}{\frac{x}{\frac{y + 1}{y}}}
\] |
Applied egg-rr0.25
if 1.45e8 < y Initial program 26.83
Simplified0.02
[Start]26.83 | \[ \frac{x \cdot y}{y + 1}
\] |
|---|---|
associate-/l* [=>]0.02 | \[ \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}}
\] |
Final simplification0.13
| Alternative 1 | |
|---|---|
| Error | 1.47% |
| Cost | 585 |
| Alternative 2 | |
|---|---|
| Error | 2.04% |
| Cost | 456 |
| Alternative 3 | |
|---|---|
| Error | 0.21% |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Error | 48.73% |
| Cost | 64 |
herbie shell --seed 2023090
(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)))