| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 968 |

(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
:precision binary64
(if (<= y -1.2e+15)
(+ x (/ 1.0 y))
(if (<= y 105000000.0)
(- 1.0 (/ (* y (- 1.0 x)) (+ y 1.0)))
(+ x (/ (- 1.0 x) y)))))double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
double tmp;
if (y <= -1.2e+15) {
tmp = x + (1.0 / y);
} else if (y <= 105000000.0) {
tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0));
} else {
tmp = x + ((1.0 - x) / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - (((1.0d0 - 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.2d+15)) then
tmp = x + (1.0d0 / y)
else if (y <= 105000000.0d0) then
tmp = 1.0d0 - ((y * (1.0d0 - x)) / (y + 1.0d0))
else
tmp = x + ((1.0d0 - x) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
public static double code(double x, double y) {
double tmp;
if (y <= -1.2e+15) {
tmp = x + (1.0 / y);
} else if (y <= 105000000.0) {
tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0));
} else {
tmp = x + ((1.0 - x) / y);
}
return tmp;
}
def code(x, y): return 1.0 - (((1.0 - x) * y) / (y + 1.0))
def code(x, y): tmp = 0 if y <= -1.2e+15: tmp = x + (1.0 / y) elif y <= 105000000.0: tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0)) else: tmp = x + ((1.0 - x) / y) return tmp
function code(x, y) return Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0))) end
function code(x, y) tmp = 0.0 if (y <= -1.2e+15) tmp = Float64(x + Float64(1.0 / y)); elseif (y <= 105000000.0) tmp = Float64(1.0 - Float64(Float64(y * Float64(1.0 - x)) / Float64(y + 1.0))); else tmp = Float64(x + Float64(Float64(1.0 - x) / y)); end return tmp end
function tmp = code(x, y) tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0)); end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.2e+15) tmp = x + (1.0 / y); elseif (y <= 105000000.0) tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0)); else tmp = x + ((1.0 - x) / y); end tmp_2 = tmp; end
code[x_, y_] := N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[y, -1.2e+15], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 105000000.0], N[(1.0 - N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+15}:\\
\;\;\;\;x + \frac{1}{y}\\
\mathbf{elif}\;y \leq 105000000:\\
\;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1 - x}{y}\\
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 66.9% |
|---|---|
| Target | 99.6% |
| Herbie | 99.6% |
if y < -1.2e15Initial program 21.1%
Simplified50.0%
[Start]21.1% | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]21.1% | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
distribute-neg-frac [=>]21.1% | \[ 1 + \color{blue}{\frac{-\left(1 - x\right) \cdot y}{y + 1}}
\] |
neg-mul-1 [=>]21.1% | \[ 1 + \frac{\color{blue}{-1 \cdot \left(\left(1 - x\right) \cdot y\right)}}{y + 1}
\] |
associate-*l/ [<=]20.7% | \[ 1 + \color{blue}{\frac{-1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)}
\] |
metadata-eval [<=]20.7% | \[ 1 + \frac{\color{blue}{1 \cdot -1}}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
associate-*l/ [<=]20.7% | \[ 1 + \color{blue}{\left(\frac{1}{y + 1} \cdot -1\right)} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
associate-/r/ [<=]20.7% | \[ 1 + \color{blue}{\frac{1}{\frac{y + 1}{-1}}} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
metadata-eval [<=]20.7% | \[ 1 + \frac{\color{blue}{--1}}{\frac{y + 1}{-1}} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
distribute-neg-frac [<=]20.7% | \[ 1 + \color{blue}{\left(-\frac{-1}{\frac{y + 1}{-1}}\right)} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
cancel-sign-sub-inv [<=]20.7% | \[ \color{blue}{1 - \frac{-1}{\frac{y + 1}{-1}} \cdot \left(\left(1 - x\right) \cdot y\right)}
\] |
associate-/r/ [<=]21.0% | \[ 1 - \color{blue}{\frac{-1}{\frac{\frac{y + 1}{-1}}{\left(1 - x\right) \cdot y}}}
\] |
associate-/r* [<=]21.0% | \[ 1 - \frac{-1}{\color{blue}{\frac{y + 1}{-1 \cdot \left(\left(1 - x\right) \cdot y\right)}}}
\] |
neg-mul-1 [<=]21.0% | \[ 1 - \frac{-1}{\frac{y + 1}{\color{blue}{-\left(1 - x\right) \cdot y}}}
\] |
associate-/r/ [=>]20.7% | \[ 1 - \color{blue}{\frac{-1}{y + 1} \cdot \left(-\left(1 - x\right) \cdot y\right)}
\] |
distribute-rgt-neg-in [<=]20.7% | \[ 1 - \color{blue}{\left(-\frac{-1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)\right)}
\] |
associate-/r/ [<=]21.0% | \[ 1 - \left(-\color{blue}{\frac{-1}{\frac{y + 1}{\left(1 - x\right) \cdot y}}}\right)
\] |
distribute-neg-frac [=>]21.0% | \[ 1 - \color{blue}{\frac{--1}{\frac{y + 1}{\left(1 - x\right) \cdot y}}}
\] |
metadata-eval [=>]21.0% | \[ 1 - \frac{\color{blue}{1}}{\frac{y + 1}{\left(1 - x\right) \cdot y}}
\] |
associate-/r/ [=>]20.7% | \[ 1 - \color{blue}{\frac{1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)}
\] |
Taylor expanded in y around inf 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(\frac{1}{y} + x\right) - \frac{x}{y}
\] |
|---|---|
+-commutative [=>]100.0% | \[ \color{blue}{\left(x + \frac{1}{y}\right)} - \frac{x}{y}
\] |
associate--l+ [=>]100.0% | \[ \color{blue}{x + \left(\frac{1}{y} - \frac{x}{y}\right)}
\] |
div-sub [<=]100.0% | \[ x + \color{blue}{\frac{1 - x}{y}}
\] |
Applied egg-rr99.5%
[Start]100.0% | \[ x + \frac{1 - x}{y}
\] |
|---|---|
add-cube-cbrt [=>]99.5% | \[ x + \color{blue}{\left(\sqrt[3]{\frac{1 - x}{y}} \cdot \sqrt[3]{\frac{1 - x}{y}}\right) \cdot \sqrt[3]{\frac{1 - x}{y}}}
\] |
pow3 [=>]99.5% | \[ x + \color{blue}{{\left(\sqrt[3]{\frac{1 - x}{y}}\right)}^{3}}
\] |
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ x + {1}^{0.3333333333333333} \cdot \frac{1}{y}
\] |
|---|---|
pow-base-1 [=>]100.0% | \[ x + \color{blue}{1} \cdot \frac{1}{y}
\] |
*-lft-identity [=>]100.0% | \[ x + \color{blue}{\frac{1}{y}}
\] |
if -1.2e15 < y < 1.05e8Initial program 100.0%
if 1.05e8 < y Initial program 27.8%
Simplified55.3%
[Start]27.8% | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]27.8% | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
distribute-neg-frac [=>]27.8% | \[ 1 + \color{blue}{\frac{-\left(1 - x\right) \cdot y}{y + 1}}
\] |
neg-mul-1 [=>]27.8% | \[ 1 + \frac{\color{blue}{-1 \cdot \left(\left(1 - x\right) \cdot y\right)}}{y + 1}
\] |
associate-*l/ [<=]27.9% | \[ 1 + \color{blue}{\frac{-1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)}
\] |
metadata-eval [<=]27.9% | \[ 1 + \frac{\color{blue}{1 \cdot -1}}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
associate-*l/ [<=]27.9% | \[ 1 + \color{blue}{\left(\frac{1}{y + 1} \cdot -1\right)} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
associate-/r/ [<=]27.9% | \[ 1 + \color{blue}{\frac{1}{\frac{y + 1}{-1}}} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
metadata-eval [<=]27.9% | \[ 1 + \frac{\color{blue}{--1}}{\frac{y + 1}{-1}} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
distribute-neg-frac [<=]27.9% | \[ 1 + \color{blue}{\left(-\frac{-1}{\frac{y + 1}{-1}}\right)} \cdot \left(\left(1 - x\right) \cdot y\right)
\] |
cancel-sign-sub-inv [<=]27.9% | \[ \color{blue}{1 - \frac{-1}{\frac{y + 1}{-1}} \cdot \left(\left(1 - x\right) \cdot y\right)}
\] |
associate-/r/ [<=]27.7% | \[ 1 - \color{blue}{\frac{-1}{\frac{\frac{y + 1}{-1}}{\left(1 - x\right) \cdot y}}}
\] |
associate-/r* [<=]27.7% | \[ 1 - \frac{-1}{\color{blue}{\frac{y + 1}{-1 \cdot \left(\left(1 - x\right) \cdot y\right)}}}
\] |
neg-mul-1 [<=]27.7% | \[ 1 - \frac{-1}{\frac{y + 1}{\color{blue}{-\left(1 - x\right) \cdot y}}}
\] |
associate-/r/ [=>]27.9% | \[ 1 - \color{blue}{\frac{-1}{y + 1} \cdot \left(-\left(1 - x\right) \cdot y\right)}
\] |
distribute-rgt-neg-in [<=]27.9% | \[ 1 - \color{blue}{\left(-\frac{-1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)\right)}
\] |
associate-/r/ [<=]27.7% | \[ 1 - \left(-\color{blue}{\frac{-1}{\frac{y + 1}{\left(1 - x\right) \cdot y}}}\right)
\] |
distribute-neg-frac [=>]27.7% | \[ 1 - \color{blue}{\frac{--1}{\frac{y + 1}{\left(1 - x\right) \cdot y}}}
\] |
metadata-eval [=>]27.7% | \[ 1 - \frac{\color{blue}{1}}{\frac{y + 1}{\left(1 - x\right) \cdot y}}
\] |
associate-/r/ [=>]27.9% | \[ 1 - \color{blue}{\frac{1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)}
\] |
Taylor expanded in y around inf 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(\frac{1}{y} + x\right) - \frac{x}{y}
\] |
|---|---|
+-commutative [=>]100.0% | \[ \color{blue}{\left(x + \frac{1}{y}\right)} - \frac{x}{y}
\] |
associate--l+ [=>]100.0% | \[ \color{blue}{x + \left(\frac{1}{y} - \frac{x}{y}\right)}
\] |
div-sub [<=]100.0% | \[ x + \color{blue}{\frac{1 - x}{y}}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 968 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 968 |
| Alternative 3 | |
|---|---|
| Accuracy | 71.7% |
| Cost | 852 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.3% |
| Cost | 585 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 585 |
| Alternative 7 | |
|---|---|
| Accuracy | 73.4% |
| Cost | 328 |
| Alternative 8 | |
|---|---|
| Accuracy | 39.4% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, D"
:precision binary64
:herbie-target
(if (< y -3693.8482788297247) (- (/ 1.0 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) (- (/ 1.0 y) (- (/ x y) x))))
(- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))