| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 968 |
(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)) (- (- (/ (+ 1.0 (- x)) (pow y 2.0))) (/ x y)))))
(if (<= y -260000.0)
t_0
(if (<= y 340000.0) (- 1.0 (* y (/ (- 1.0 x) (+ 1.0 y)))) t_0))))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)) + (-((1.0 + -x) / pow(y, 2.0)) - (x / y));
double tmp;
if (y <= -260000.0) {
tmp = t_0;
} else if (y <= 340000.0) {
tmp = 1.0 - (y * ((1.0 - x) / (1.0 + y)));
} else {
tmp = t_0;
}
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)) + (-((1.0d0 + -x) / (y ** 2.0d0)) - (x / y))
if (y <= (-260000.0d0)) then
tmp = t_0
else if (y <= 340000.0d0) then
tmp = 1.0d0 - (y * ((1.0d0 - x) / (1.0d0 + y)))
else
tmp = t_0
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)) + (-((1.0 + -x) / Math.pow(y, 2.0)) - (x / y));
double tmp;
if (y <= -260000.0) {
tmp = t_0;
} else if (y <= 340000.0) {
tmp = 1.0 - (y * ((1.0 - x) / (1.0 + y)));
} else {
tmp = t_0;
}
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)) + (-((1.0 + -x) / math.pow(y, 2.0)) - (x / y)) tmp = 0 if y <= -260000.0: tmp = t_0 elif y <= 340000.0: tmp = 1.0 - (y * ((1.0 - x) / (1.0 + y))) else: tmp = t_0 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 + Float64(1.0 / y)) + Float64(Float64(-Float64(Float64(1.0 + Float64(-x)) / (y ^ 2.0))) - Float64(x / y))) tmp = 0.0 if (y <= -260000.0) tmp = t_0; elseif (y <= 340000.0) tmp = Float64(1.0 - Float64(y * Float64(Float64(1.0 - x) / Float64(1.0 + y)))); else tmp = t_0; 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)) + (-((1.0 + -x) / (y ^ 2.0)) - (x / y)); tmp = 0.0; if (y <= -260000.0) tmp = t_0; elseif (y <= 340000.0) tmp = 1.0 - (y * ((1.0 - x) / (1.0 + y))); else tmp = t_0; 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 + N[(1.0 / y), $MachinePrecision]), $MachinePrecision] + N[((-N[(N[(1.0 + (-x)), $MachinePrecision] / N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]) - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -260000.0], t$95$0, If[LessEqual[y, 340000.0], N[(1.0 - N[(y * N[(N[(1.0 - x), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \left(x + \frac{1}{y}\right) + \left(\left(-\frac{1 + \left(-x\right)}{{y}^{2}}\right) - \frac{x}{y}\right)\\
\mathbf{if}\;y \leq -260000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 340000:\\
\;\;\;\;1 - y \cdot \frac{1 - x}{1 + y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 22.6 |
|---|---|
| Target | 0.2 |
| Herbie | 0.0 |
if y < -2.6e5 or 3.4e5 < y Initial program 45.8
Simplified29.6
[Start]45.8 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
rational.json-simplify-49 [=>]29.6 | \[ 1 - \color{blue}{y \cdot \frac{1 - x}{y + 1}}
\] |
rational.json-simplify-1 [=>]29.6 | \[ 1 - y \cdot \frac{1 - x}{\color{blue}{1 + y}}
\] |
rational.json-simplify-17 [=>]29.6 | \[ 1 - y \cdot \frac{1 - x}{\color{blue}{y - -1}}
\] |
rational.json-simplify-50 [=>]29.6 | \[ 1 - y \cdot \color{blue}{\frac{-\left(1 - x\right)}{-1 - y}}
\] |
rational.json-simplify-8 [=>]29.6 | \[ 1 - y \cdot \frac{\color{blue}{\left(1 - x\right) \cdot -1}}{-1 - y}
\] |
rational.json-simplify-2 [=>]29.6 | \[ 1 - y \cdot \frac{\color{blue}{-1 \cdot \left(1 - x\right)}}{-1 - y}
\] |
rational.json-simplify-49 [=>]29.7 | \[ 1 - y \cdot \color{blue}{\left(\left(1 - x\right) \cdot \frac{-1}{-1 - y}\right)}
\] |
rational.json-simplify-2 [=>]29.7 | \[ 1 - y \cdot \color{blue}{\left(\frac{-1}{-1 - y} \cdot \left(1 - x\right)\right)}
\] |
rational.json-simplify-2 [<=]29.7 | \[ 1 - y \cdot \color{blue}{\left(\left(1 - x\right) \cdot \frac{-1}{-1 - y}\right)}
\] |
rational.json-simplify-49 [<=]29.6 | \[ 1 - y \cdot \color{blue}{\frac{-1 \cdot \left(1 - x\right)}{-1 - y}}
\] |
rational.json-simplify-2 [<=]29.6 | \[ 1 - y \cdot \frac{\color{blue}{\left(1 - x\right) \cdot -1}}{-1 - y}
\] |
rational.json-simplify-8 [<=]29.6 | \[ 1 - y \cdot \frac{\color{blue}{-\left(1 - x\right)}}{-1 - y}
\] |
rational.json-simplify-50 [<=]29.6 | \[ 1 - y \cdot \color{blue}{\frac{1 - x}{y - -1}}
\] |
rational.json-simplify-17 [<=]29.6 | \[ 1 - y \cdot \frac{1 - x}{\color{blue}{1 + y}}
\] |
Taylor expanded in y around inf 0.0
Simplified0.0
[Start]0.0 | \[ \left(\frac{1}{y} + \left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} + x\right)\right) - \frac{x}{y}
\] |
|---|---|
rational.json-simplify-41 [=>]0.0 | \[ \color{blue}{\left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} + \left(x + \frac{1}{y}\right)\right)} - \frac{x}{y}
\] |
rational.json-simplify-1 [<=]0.0 | \[ \left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} + \color{blue}{\left(\frac{1}{y} + x\right)}\right) - \frac{x}{y}
\] |
rational.json-simplify-48 [=>]0.0 | \[ \color{blue}{\left(\frac{1}{y} + x\right) + \left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} - \frac{x}{y}\right)}
\] |
rational.json-simplify-1 [=>]0.0 | \[ \color{blue}{\left(x + \frac{1}{y}\right)} + \left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} - \frac{x}{y}\right)
\] |
rational.json-simplify-2 [=>]0.0 | \[ \left(x + \frac{1}{y}\right) + \left(\color{blue}{\frac{1 + -1 \cdot x}{{y}^{2}} \cdot -1} - \frac{x}{y}\right)
\] |
rational.json-simplify-9 [=>]0.0 | \[ \left(x + \frac{1}{y}\right) + \left(\color{blue}{\left(-\frac{1 + -1 \cdot x}{{y}^{2}}\right)} - \frac{x}{y}\right)
\] |
rational.json-simplify-2 [=>]0.0 | \[ \left(x + \frac{1}{y}\right) + \left(\left(-\frac{1 + \color{blue}{x \cdot -1}}{{y}^{2}}\right) - \frac{x}{y}\right)
\] |
rational.json-simplify-9 [=>]0.0 | \[ \left(x + \frac{1}{y}\right) + \left(\left(-\frac{1 + \color{blue}{\left(-x\right)}}{{y}^{2}}\right) - \frac{x}{y}\right)
\] |
if -2.6e5 < y < 3.4e5Initial program 0.1
Simplified0.1
[Start]0.1 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
rational.json-simplify-49 [=>]0.1 | \[ 1 - \color{blue}{y \cdot \frac{1 - x}{y + 1}}
\] |
rational.json-simplify-1 [=>]0.1 | \[ 1 - y \cdot \frac{1 - x}{\color{blue}{1 + y}}
\] |
rational.json-simplify-17 [=>]0.1 | \[ 1 - y \cdot \frac{1 - x}{\color{blue}{y - -1}}
\] |
rational.json-simplify-50 [=>]0.1 | \[ 1 - y \cdot \color{blue}{\frac{-\left(1 - x\right)}{-1 - y}}
\] |
rational.json-simplify-8 [=>]0.1 | \[ 1 - y \cdot \frac{\color{blue}{\left(1 - x\right) \cdot -1}}{-1 - y}
\] |
rational.json-simplify-2 [=>]0.1 | \[ 1 - y \cdot \frac{\color{blue}{-1 \cdot \left(1 - x\right)}}{-1 - y}
\] |
rational.json-simplify-49 [=>]0.1 | \[ 1 - y \cdot \color{blue}{\left(\left(1 - x\right) \cdot \frac{-1}{-1 - y}\right)}
\] |
rational.json-simplify-2 [=>]0.1 | \[ 1 - y \cdot \color{blue}{\left(\frac{-1}{-1 - y} \cdot \left(1 - x\right)\right)}
\] |
rational.json-simplify-2 [<=]0.1 | \[ 1 - y \cdot \color{blue}{\left(\left(1 - x\right) \cdot \frac{-1}{-1 - y}\right)}
\] |
rational.json-simplify-49 [<=]0.1 | \[ 1 - y \cdot \color{blue}{\frac{-1 \cdot \left(1 - x\right)}{-1 - y}}
\] |
rational.json-simplify-2 [<=]0.1 | \[ 1 - y \cdot \frac{\color{blue}{\left(1 - x\right) \cdot -1}}{-1 - y}
\] |
rational.json-simplify-8 [<=]0.1 | \[ 1 - y \cdot \frac{\color{blue}{-\left(1 - x\right)}}{-1 - y}
\] |
rational.json-simplify-50 [<=]0.1 | \[ 1 - y \cdot \color{blue}{\frac{1 - x}{y - -1}}
\] |
rational.json-simplify-17 [<=]0.1 | \[ 1 - y \cdot \frac{1 - x}{\color{blue}{1 + y}}
\] |
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 968 |
| Alternative 2 | |
|---|---|
| Error | 9.2 |
| Cost | 848 |
| Alternative 3 | |
|---|---|
| Error | 9.1 |
| Cost | 848 |
| Alternative 4 | |
|---|---|
| Error | 1.0 |
| Cost | 776 |
| Alternative 5 | |
|---|---|
| Error | 16.7 |
| Cost | 720 |
| Alternative 6 | |
|---|---|
| Error | 1.2 |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Error | 1.4 |
| Cost | 648 |
| Alternative 8 | |
|---|---|
| Error | 16.8 |
| Cost | 592 |
| Alternative 9 | |
|---|---|
| Error | 16.6 |
| Cost | 328 |
| Alternative 10 | |
|---|---|
| Error | 39.4 |
| Cost | 64 |
herbie shell --seed 2023069
(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))))