| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 1225 |
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ x -1.0) (* y y))))
(if (<= y -270000.0)
(- (+ x t_0) (/ (+ x -1.0) y))
(if (<= y 18000.0)
(+ 1.0 (* y (/ (+ x -1.0) (+ y 1.0))))
(+ (+ t_0 (+ x (/ (- 1.0 x) (pow y 3.0)))) (/ (- 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 t_0 = (x + -1.0) / (y * y);
double tmp;
if (y <= -270000.0) {
tmp = (x + t_0) - ((x + -1.0) / y);
} else if (y <= 18000.0) {
tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0)));
} else {
tmp = (t_0 + (x + ((1.0 - x) / pow(y, 3.0)))) + ((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) :: t_0
real(8) :: tmp
t_0 = (x + (-1.0d0)) / (y * y)
if (y <= (-270000.0d0)) then
tmp = (x + t_0) - ((x + (-1.0d0)) / y)
else if (y <= 18000.0d0) then
tmp = 1.0d0 + (y * ((x + (-1.0d0)) / (y + 1.0d0)))
else
tmp = (t_0 + (x + ((1.0d0 - x) / (y ** 3.0d0)))) + ((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 t_0 = (x + -1.0) / (y * y);
double tmp;
if (y <= -270000.0) {
tmp = (x + t_0) - ((x + -1.0) / y);
} else if (y <= 18000.0) {
tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0)));
} else {
tmp = (t_0 + (x + ((1.0 - x) / Math.pow(y, 3.0)))) + ((1.0 - x) / y);
}
return tmp;
}
def code(x, y): return 1.0 - (((1.0 - x) * y) / (y + 1.0))
def code(x, y): t_0 = (x + -1.0) / (y * y) tmp = 0 if y <= -270000.0: tmp = (x + t_0) - ((x + -1.0) / y) elif y <= 18000.0: tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0))) else: tmp = (t_0 + (x + ((1.0 - x) / math.pow(y, 3.0)))) + ((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) t_0 = Float64(Float64(x + -1.0) / Float64(y * y)) tmp = 0.0 if (y <= -270000.0) tmp = Float64(Float64(x + t_0) - Float64(Float64(x + -1.0) / y)); elseif (y <= 18000.0) tmp = Float64(1.0 + Float64(y * Float64(Float64(x + -1.0) / Float64(y + 1.0)))); else tmp = Float64(Float64(t_0 + Float64(x + Float64(Float64(1.0 - x) / (y ^ 3.0)))) + 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) t_0 = (x + -1.0) / (y * y); tmp = 0.0; if (y <= -270000.0) tmp = (x + t_0) - ((x + -1.0) / y); elseif (y <= 18000.0) tmp = 1.0 + (y * ((x + -1.0) / (y + 1.0))); else tmp = (t_0 + (x + ((1.0 - x) / (y ^ 3.0)))) + ((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_] := Block[{t$95$0 = N[(N[(x + -1.0), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -270000.0], N[(N[(x + t$95$0), $MachinePrecision] - N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 18000.0], N[(1.0 + N[(y * N[(N[(x + -1.0), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 + N[(x + N[(N[(1.0 - x), $MachinePrecision] / N[Power[y, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{x + -1}{y \cdot y}\\
\mathbf{if}\;y \leq -270000:\\
\;\;\;\;\left(x + t_0\right) - \frac{x + -1}{y}\\
\mathbf{elif}\;y \leq 18000:\\
\;\;\;\;1 + y \cdot \frac{x + -1}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\left(t_0 + \left(x + \frac{1 - x}{{y}^{3}}\right)\right) + \frac{1 - x}{y}\\
\end{array}
Results
| Original | 64.0% |
|---|---|
| Target | 99.7% |
| Herbie | 99.9% |
if y < -2.7e5Initial program 27.2%
Simplified52.2%
[Start]27.2 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]27.2 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]27.2 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
neg-mul-1 [=>]27.2 | \[ \color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}} + 1
\] |
associate-*l/ [<=]52.1 | \[ -1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)} + 1
\] |
associate-*r* [=>]52.1 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y} + 1
\] |
fma-def [=>]52.2 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{1 - x}{y + 1}, y, 1\right)}
\] |
associate-*r/ [=>]52.2 | \[ \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{y + 1}}, y, 1\right)
\] |
neg-mul-1 [<=]52.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{-\left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
neg-sub0 [=>]52.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
associate--r- [=>]52.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right)
\] |
metadata-eval [=>]52.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{-1} + x}{y + 1}, y, 1\right)
\] |
+-commutative [<=]52.2 | \[ \mathsf{fma}\left(\frac{\color{blue}{x + -1}}{y + 1}, y, 1\right)
\] |
+-commutative [=>]52.2 | \[ \mathsf{fma}\left(\frac{x + -1}{\color{blue}{1 + y}}, y, 1\right)
\] |
Taylor expanded in y around -inf 100.0%
Simplified100.0%
[Start]100.0 | \[ \left(\frac{1}{y} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \frac{x}{y}
\] |
|---|---|
associate--l+ [=>]100.0 | \[ \color{blue}{\frac{1}{y} + \left(\left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right) - \frac{x}{y}\right)}
\] |
+-commutative [=>]100.0 | \[ \color{blue}{\left(\left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right) - \frac{x}{y}\right) + \frac{1}{y}}
\] |
associate-+l- [=>]100.0 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right) - \left(\frac{x}{y} - \frac{1}{y}\right)}
\] |
+-commutative [=>]100.0 | \[ \color{blue}{\left(x + -1 \cdot \frac{1 - x}{{y}^{2}}\right)} - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
associate-*r/ [=>]100.0 | \[ \left(x + \color{blue}{\frac{-1 \cdot \left(1 - x\right)}{{y}^{2}}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
sub-neg [=>]100.0 | \[ \left(x + \frac{-1 \cdot \color{blue}{\left(1 + \left(-x\right)\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-lft-in [=>]100.0 | \[ \left(x + \frac{\color{blue}{-1 \cdot 1 + -1 \cdot \left(-x\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
*-commutative [<=]100.0 | \[ \left(x + \frac{-1 \cdot 1 + \color{blue}{\left(-x\right) \cdot -1}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-lft-neg-in [<=]100.0 | \[ \left(x + \frac{-1 \cdot 1 + \color{blue}{\left(-x \cdot -1\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-rgt-neg-in [=>]100.0 | \[ \left(x + \frac{-1 \cdot 1 + \color{blue}{x \cdot \left(--1\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
metadata-eval [=>]100.0 | \[ \left(x + \frac{-1 \cdot 1 + x \cdot \color{blue}{1}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-rgt-in [<=]100.0 | \[ \left(x + \frac{\color{blue}{1 \cdot \left(-1 + x\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
+-commutative [<=]100.0 | \[ \left(x + \frac{1 \cdot \color{blue}{\left(x + -1\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
*-lft-identity [=>]100.0 | \[ \left(x + \frac{\color{blue}{x + -1}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
+-commutative [=>]100.0 | \[ \left(x + \frac{\color{blue}{-1 + x}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
unpow2 [=>]100.0 | \[ \left(x + \frac{-1 + x}{\color{blue}{y \cdot y}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
div-sub [<=]100.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \color{blue}{\frac{x - 1}{y}}
\] |
sub-neg [=>]100.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \frac{\color{blue}{x + \left(-1\right)}}{y}
\] |
metadata-eval [=>]100.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \frac{x + \color{blue}{-1}}{y}
\] |
+-commutative [=>]100.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \frac{\color{blue}{-1 + x}}{y}
\] |
if -2.7e5 < y < 18000Initial program 99.9%
Simplified99.9%
[Start]99.9 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
remove-double-neg [<=]99.9 | \[ 1 - \color{blue}{\left(-\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)\right)}
\] |
neg-mul-1 [=>]99.9 | \[ 1 - \left(-\color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}}\right)
\] |
associate-*l/ [<=]99.9 | \[ 1 - \left(--1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)}\right)
\] |
associate-*r* [=>]99.9 | \[ 1 - \left(-\color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}\right)
\] |
distribute-lft-neg-in [=>]99.9 | \[ 1 - \color{blue}{\left(--1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}
\] |
distribute-lft-neg-in [=>]99.9 | \[ 1 - \color{blue}{\left(\left(--1\right) \cdot \frac{1 - x}{y + 1}\right)} \cdot y
\] |
metadata-eval [=>]99.9 | \[ 1 - \left(\color{blue}{1} \cdot \frac{1 - x}{y + 1}\right) \cdot y
\] |
*-lft-identity [=>]99.9 | \[ 1 - \color{blue}{\frac{1 - x}{y + 1}} \cdot y
\] |
+-commutative [=>]99.9 | \[ 1 - \frac{1 - x}{\color{blue}{1 + y}} \cdot y
\] |
if 18000 < y Initial program 28.2%
Simplified54.0%
[Start]28.2 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]28.2 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]28.2 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
neg-mul-1 [=>]28.2 | \[ \color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}} + 1
\] |
associate-*l/ [<=]54.1 | \[ -1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)} + 1
\] |
associate-*r* [=>]54.1 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y} + 1
\] |
fma-def [=>]54.0 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{1 - x}{y + 1}, y, 1\right)}
\] |
associate-*r/ [=>]54.0 | \[ \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{y + 1}}, y, 1\right)
\] |
neg-mul-1 [<=]54.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{-\left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
neg-sub0 [=>]54.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
associate--r- [=>]54.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right)
\] |
metadata-eval [=>]54.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{-1} + x}{y + 1}, y, 1\right)
\] |
+-commutative [<=]54.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{x + -1}}{y + 1}, y, 1\right)
\] |
+-commutative [=>]54.0 | \[ \mathsf{fma}\left(\frac{x + -1}{\color{blue}{1 + y}}, y, 1\right)
\] |
Taylor expanded in y around -inf 100.0%
Simplified100.0%
[Start]100.0 | \[ \left(\frac{1}{y} + \left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right)\right) - \left(\frac{x}{{y}^{3}} + \frac{x}{y}\right)
\] |
|---|---|
associate--l+ [=>]100.0 | \[ \color{blue}{\frac{1}{y} + \left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \left(\frac{x}{{y}^{3}} + \frac{x}{y}\right)\right)}
\] |
+-commutative [=>]100.0 | \[ \color{blue}{\left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \left(\frac{x}{{y}^{3}} + \frac{x}{y}\right)\right) + \frac{1}{y}}
\] |
associate--r+ [=>]100.0 | \[ \color{blue}{\left(\left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \frac{x}{{y}^{3}}\right) - \frac{x}{y}\right)} + \frac{1}{y}
\] |
associate-+l- [=>]100.0 | \[ \color{blue}{\left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \frac{x}{{y}^{3}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 1225 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 968 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 713 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.9% |
| Cost | 585 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 585 |
| Alternative 7 | |
|---|---|
| Accuracy | 73.6% |
| Cost | 456 |
| Alternative 8 | |
|---|---|
| Accuracy | 73.5% |
| Cost | 328 |
| Alternative 9 | |
|---|---|
| Accuracy | 38.3% |
| Cost | 64 |
herbie shell --seed 2023133
(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))))