| Alternative 1 | |
|---|---|
| Error | 22.2 |
| Cost | 580 |
\[\begin{array}{l}
\mathbf{if}\;y \leq 1.7 \cdot 10^{-104}:\\
\;\;\;\;\frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot \left(y + 1\right)}\\
\end{array}
\]
(FPCore (x y) :precision binary64 (/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))
(FPCore (x y)
:precision binary64
(if (<= x -3.4e+93)
(/ y (* (+ 1.0 x) x))
(if (<= x -9.5e-142)
(/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0)))
(/ x (* y (+ y 1.0))))))double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
double code(double x, double y) {
double tmp;
if (x <= -3.4e+93) {
tmp = y / ((1.0 + x) * x);
} else if (x <= -9.5e-142) {
tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
} else {
tmp = x / (y * (y + 1.0));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) / (((x + y) * (x + y)) * ((x + 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 (x <= (-3.4d+93)) then
tmp = y / ((1.0d0 + x) * x)
else if (x <= (-9.5d-142)) then
tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0d0))
else
tmp = x / (y * (y + 1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
public static double code(double x, double y) {
double tmp;
if (x <= -3.4e+93) {
tmp = y / ((1.0 + x) * x);
} else if (x <= -9.5e-142) {
tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
} else {
tmp = x / (y * (y + 1.0));
}
return tmp;
}
def code(x, y): return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0))
def code(x, y): tmp = 0 if x <= -3.4e+93: tmp = y / ((1.0 + x) * x) elif x <= -9.5e-142: tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0)) else: tmp = x / (y * (y + 1.0)) return tmp
function code(x, y) return Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * Float64(Float64(x + y) + 1.0))) end
function code(x, y) tmp = 0.0 if (x <= -3.4e+93) tmp = Float64(y / Float64(Float64(1.0 + x) * x)); elseif (x <= -9.5e-142) tmp = Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * Float64(Float64(x + y) + 1.0))); else tmp = Float64(x / Float64(y * Float64(y + 1.0))); end return tmp end
function tmp = code(x, y) tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0)); end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.4e+93) tmp = y / ((1.0 + x) * x); elseif (x <= -9.5e-142) tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0)); else tmp = x / (y * (y + 1.0)); end tmp_2 = tmp; end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, -3.4e+93], N[(y / N[(N[(1.0 + x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -9.5e-142], N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(y * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)}
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+93}:\\
\;\;\;\;\frac{y}{\left(1 + x\right) \cdot x}\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{-142}:\\
\;\;\;\;\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot \left(y + 1\right)}\\
\end{array}
Results
| Original | 19.8 |
|---|---|
| Target | 0.1 |
| Herbie | 9.4 |
if x < -3.4e93Initial program 26.1
Taylor expanded in y around 0 11.2
if -3.4e93 < x < -9.49999999999999967e-142Initial program 8.7
if -9.49999999999999967e-142 < x Initial program 22.3
Taylor expanded in x around 0 8.4
Simplified8.4
[Start]8.4 | \[ \frac{x}{y \cdot \left(1 + y\right)}
\] |
|---|---|
rational.json-simplify-1 [=>]8.4 | \[ \frac{x}{y \cdot \color{blue}{\left(y + 1\right)}}
\] |
Final simplification9.4
| Alternative 1 | |
|---|---|
| Error | 22.2 |
| Cost | 580 |
| Alternative 2 | |
|---|---|
| Error | 13.1 |
| Cost | 580 |
| Alternative 3 | |
|---|---|
| Error | 35.9 |
| Cost | 324 |
| Alternative 4 | |
|---|---|
| Error | 61.4 |
| Cost | 192 |
| Alternative 5 | |
|---|---|
| Error | 47.4 |
| Cost | 192 |
| Alternative 6 | |
|---|---|
| Error | 61.6 |
| Cost | 128 |
| Alternative 7 | |
|---|---|
| Error | 61.8 |
| Cost | 64 |
herbie shell --seed 2023077
(FPCore (x y)
:name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, A"
:precision binary64
:herbie-target
(/ (/ (/ x (+ (+ y 1.0) x)) (+ y x)) (/ 1.0 (/ y (+ y x))))
(/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))