| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 1476 |
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ -1.0 (* y y))))
(if (<= y -12000.0)
(+ (* (/ (+ x -1.0) y) (+ -1.0 t_0)) (+ x (+ t_0 (/ x (* y y)))))
(if (<= y 6100000000.0)
(- 1.0 (/ (* y (- 1.0 x)) (+ y 1.0)))
(+ x (/ 1.0 y))))))double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
double t_0 = -1.0 / (y * y);
double tmp;
if (y <= -12000.0) {
tmp = (((x + -1.0) / y) * (-1.0 + t_0)) + (x + (t_0 + (x / (y * y))));
} else if (y <= 6100000000.0) {
tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0));
} else {
tmp = x + (1.0 / 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) :: t_0
real(8) :: tmp
t_0 = (-1.0d0) / (y * y)
if (y <= (-12000.0d0)) then
tmp = (((x + (-1.0d0)) / y) * ((-1.0d0) + t_0)) + (x + (t_0 + (x / (y * y))))
else if (y <= 6100000000.0d0) then
tmp = 1.0d0 - ((y * (1.0d0 - x)) / (y + 1.0d0))
else
tmp = x + (1.0d0 / 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 t_0 = -1.0 / (y * y);
double tmp;
if (y <= -12000.0) {
tmp = (((x + -1.0) / y) * (-1.0 + t_0)) + (x + (t_0 + (x / (y * y))));
} else if (y <= 6100000000.0) {
tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0));
} else {
tmp = x + (1.0 / y);
}
return tmp;
}
def code(x, y): return 1.0 - (((1.0 - x) * y) / (y + 1.0))
def code(x, y): t_0 = -1.0 / (y * y) tmp = 0 if y <= -12000.0: tmp = (((x + -1.0) / y) * (-1.0 + t_0)) + (x + (t_0 + (x / (y * y)))) elif y <= 6100000000.0: tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0)) else: tmp = x + (1.0 / 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) t_0 = Float64(-1.0 / Float64(y * y)) tmp = 0.0 if (y <= -12000.0) tmp = Float64(Float64(Float64(Float64(x + -1.0) / y) * Float64(-1.0 + t_0)) + Float64(x + Float64(t_0 + Float64(x / Float64(y * y))))); elseif (y <= 6100000000.0) tmp = Float64(1.0 - Float64(Float64(y * Float64(1.0 - x)) / Float64(y + 1.0))); else tmp = Float64(x + Float64(1.0 / 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) t_0 = -1.0 / (y * y); tmp = 0.0; if (y <= -12000.0) tmp = (((x + -1.0) / y) * (-1.0 + t_0)) + (x + (t_0 + (x / (y * y)))); elseif (y <= 6100000000.0) tmp = 1.0 - ((y * (1.0 - x)) / (y + 1.0)); else tmp = x + (1.0 / 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_] := Block[{t$95$0 = N[(-1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -12000.0], N[(N[(N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision] * N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision] + N[(x + N[(t$95$0 + N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6100000000.0], N[(1.0 - N[(N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{-1}{y \cdot y}\\
\mathbf{if}\;y \leq -12000:\\
\;\;\;\;\frac{x + -1}{y} \cdot \left(-1 + t_0\right) + \left(x + \left(t_0 + \frac{x}{y \cdot y}\right)\right)\\
\mathbf{elif}\;y \leq 6100000000:\\
\;\;\;\;1 - \frac{y \cdot \left(1 - x\right)}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{y}\\
\end{array}
Results
| Original | 63.8% |
|---|---|
| Target | 99.7% |
| Herbie | 99.8% |
if y < -12000Initial program 29.0%
Simplified55.4%
[Start]29.0 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]29.0 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]29.0 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
*-lft-identity [<=]29.0 | \[ \color{blue}{1 \cdot \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)} + 1
\] |
associate-/l* [=>]55.4 | \[ 1 \cdot \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\right) + 1
\] |
distribute-neg-frac [=>]55.4 | \[ 1 \cdot \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*r/ [=>]55.4 | \[ \color{blue}{\frac{1 \cdot \left(-\left(1 - x\right)\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*l/ [<=]55.3 | \[ \color{blue}{\frac{1}{\frac{y + 1}{y}} \cdot \left(-\left(1 - x\right)\right)} + 1
\] |
fma-def [=>]55.3 | \[ \color{blue}{\mathsf{fma}\left(\frac{1}{\frac{y + 1}{y}}, -\left(1 - x\right), 1\right)}
\] |
associate-/l* [<=]55.4 | \[ \mathsf{fma}\left(\color{blue}{\frac{1 \cdot y}{y + 1}}, -\left(1 - x\right), 1\right)
\] |
*-lft-identity [=>]55.4 | \[ \mathsf{fma}\left(\frac{\color{blue}{y}}{y + 1}, -\left(1 - x\right), 1\right)
\] |
+-commutative [=>]55.4 | \[ \mathsf{fma}\left(\frac{y}{\color{blue}{1 + y}}, -\left(1 - x\right), 1\right)
\] |
neg-sub0 [=>]55.4 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right)
\] |
associate--r- [=>]55.4 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right)
\] |
metadata-eval [=>]55.4 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{-1} + x, 1\right)
\] |
+-commutative [<=]55.4 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right)
\] |
Taylor expanded in y around inf 100.0%
Simplified100.0%
[Start]100.0 | \[ \left(\frac{x}{{y}^{2}} + \left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right)\right) - \frac{1}{{y}^{2}}
\] |
|---|---|
sub-neg [=>]100.0 | \[ \color{blue}{\left(\frac{x}{{y}^{2}} + \left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right)\right) + \left(-\frac{1}{{y}^{2}}\right)}
\] |
+-commutative [=>]100.0 | \[ \color{blue}{\left(\left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right) + \frac{x}{{y}^{2}}\right)} + \left(-\frac{1}{{y}^{2}}\right)
\] |
associate-+l+ [=>]100.0 | \[ \color{blue}{\left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right) + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)}
\] |
associate-+r+ [=>]100.0 | \[ \color{blue}{\left(\left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right) + x\right)} + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)
\] |
associate-+l+ [=>]100.0 | \[ \color{blue}{\left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right) + \left(x + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)\right)}
\] |
if -12000 < y < 6.1e9Initial program 99.8%
if 6.1e9 < y Initial program 26.9%
Simplified54.5%
[Start]26.9 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]26.9 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]26.9 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
*-lft-identity [<=]26.9 | \[ \color{blue}{1 \cdot \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)} + 1
\] |
associate-/l* [=>]54.5 | \[ 1 \cdot \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\right) + 1
\] |
distribute-neg-frac [=>]54.5 | \[ 1 \cdot \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*r/ [=>]54.5 | \[ \color{blue}{\frac{1 \cdot \left(-\left(1 - x\right)\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*l/ [<=]54.5 | \[ \color{blue}{\frac{1}{\frac{y + 1}{y}} \cdot \left(-\left(1 - x\right)\right)} + 1
\] |
fma-def [=>]54.5 | \[ \color{blue}{\mathsf{fma}\left(\frac{1}{\frac{y + 1}{y}}, -\left(1 - x\right), 1\right)}
\] |
associate-/l* [<=]54.5 | \[ \mathsf{fma}\left(\color{blue}{\frac{1 \cdot y}{y + 1}}, -\left(1 - x\right), 1\right)
\] |
*-lft-identity [=>]54.5 | \[ \mathsf{fma}\left(\frac{\color{blue}{y}}{y + 1}, -\left(1 - x\right), 1\right)
\] |
+-commutative [=>]54.5 | \[ \mathsf{fma}\left(\frac{y}{\color{blue}{1 + y}}, -\left(1 - x\right), 1\right)
\] |
neg-sub0 [=>]54.5 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right)
\] |
associate--r- [=>]54.5 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right)
\] |
metadata-eval [=>]54.5 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{-1} + x, 1\right)
\] |
+-commutative [<=]54.5 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right)
\] |
Taylor expanded in y around inf 99.9%
Simplified99.9%
[Start]99.9 | \[ -1 \cdot \frac{x - 1}{y} + x
\] |
|---|---|
+-commutative [=>]99.9 | \[ \color{blue}{x + -1 \cdot \frac{x - 1}{y}}
\] |
mul-1-neg [=>]99.9 | \[ x + \color{blue}{\left(-\frac{x - 1}{y}\right)}
\] |
unsub-neg [=>]99.9 | \[ \color{blue}{x - \frac{x - 1}{y}}
\] |
sub-neg [=>]99.9 | \[ x - \frac{\color{blue}{x + \left(-1\right)}}{y}
\] |
metadata-eval [=>]99.9 | \[ x - \frac{x + \color{blue}{-1}}{y}
\] |
Taylor expanded in x around 0 99.7%
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 1476 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 1092 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 968 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 968 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 836 |
| Alternative 6 | |
|---|---|
| Accuracy | 74.3% |
| Cost | 720 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 592 |
| Alternative 10 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 585 |
| Alternative 11 | |
|---|---|
| Accuracy | 86.1% |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Accuracy | 74.4% |
| Cost | 328 |
| Alternative 13 | |
|---|---|
| Accuracy | 38.1% |
| Cost | 64 |
herbie shell --seed 2023135
(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))))