
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (2.0d0 - (x + y))
end function
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (/ y x) -1.0)))
(if (<= x -1.25)
t_0
(if (<= x -9.4e-94)
(* x 0.5)
(if (<= x 5e-61)
1.0
(if (<= x 6.1e-30) (* x 0.5) (if (<= x 2.2e+111) 1.0 t_0)))))))
double code(double x, double y) {
double t_0 = (y / x) + -1.0;
double tmp;
if (x <= -1.25) {
tmp = t_0;
} else if (x <= -9.4e-94) {
tmp = x * 0.5;
} else if (x <= 5e-61) {
tmp = 1.0;
} else if (x <= 6.1e-30) {
tmp = x * 0.5;
} else if (x <= 2.2e+111) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
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 = (y / x) + (-1.0d0)
if (x <= (-1.25d0)) then
tmp = t_0
else if (x <= (-9.4d-94)) then
tmp = x * 0.5d0
else if (x <= 5d-61) then
tmp = 1.0d0
else if (x <= 6.1d-30) then
tmp = x * 0.5d0
else if (x <= 2.2d+111) then
tmp = 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y / x) + -1.0;
double tmp;
if (x <= -1.25) {
tmp = t_0;
} else if (x <= -9.4e-94) {
tmp = x * 0.5;
} else if (x <= 5e-61) {
tmp = 1.0;
} else if (x <= 6.1e-30) {
tmp = x * 0.5;
} else if (x <= 2.2e+111) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (y / x) + -1.0 tmp = 0 if x <= -1.25: tmp = t_0 elif x <= -9.4e-94: tmp = x * 0.5 elif x <= 5e-61: tmp = 1.0 elif x <= 6.1e-30: tmp = x * 0.5 elif x <= 2.2e+111: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(y / x) + -1.0) tmp = 0.0 if (x <= -1.25) tmp = t_0; elseif (x <= -9.4e-94) tmp = Float64(x * 0.5); elseif (x <= 5e-61) tmp = 1.0; elseif (x <= 6.1e-30) tmp = Float64(x * 0.5); elseif (x <= 2.2e+111) tmp = 1.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (y / x) + -1.0; tmp = 0.0; if (x <= -1.25) tmp = t_0; elseif (x <= -9.4e-94) tmp = x * 0.5; elseif (x <= 5e-61) tmp = 1.0; elseif (x <= 6.1e-30) tmp = x * 0.5; elseif (x <= 2.2e+111) tmp = 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y / x), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[x, -1.25], t$95$0, If[LessEqual[x, -9.4e-94], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 5e-61], 1.0, If[LessEqual[x, 6.1e-30], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 2.2e+111], 1.0, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{x} + -1\\
\mathbf{if}\;x \leq -1.25:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -9.4 \cdot 10^{-94}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-61}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 6.1 \cdot 10^{-30}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+111}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.25 or 2.19999999999999999e111 < x Initial program 100.0%
clear-num99.9%
associate-/r/99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 81.7%
Taylor expanded in x around 0 81.9%
if -1.25 < x < -9.40000000000000007e-94 or 4.9999999999999999e-61 < x < 6.09999999999999981e-30Initial program 100.0%
Taylor expanded in y around 0 75.3%
Taylor expanded in x around 0 72.3%
*-commutative72.3%
Simplified72.3%
if -9.40000000000000007e-94 < x < 4.9999999999999999e-61 or 6.09999999999999981e-30 < x < 2.19999999999999999e111Initial program 100.0%
Taylor expanded in y around inf 55.0%
Final simplification67.7%
(FPCore (x y)
:precision binary64
(if (<= x -2.0)
-1.0
(if (<= x -8e-94)
(* x 0.5)
(if (<= x 2e-61)
1.0
(if (<= x 4e-33) (* x 0.5) (if (<= x 1.7e+110) 1.0 -1.0))))))
double code(double x, double y) {
double tmp;
if (x <= -2.0) {
tmp = -1.0;
} else if (x <= -8e-94) {
tmp = x * 0.5;
} else if (x <= 2e-61) {
tmp = 1.0;
} else if (x <= 4e-33) {
tmp = x * 0.5;
} else if (x <= 1.7e+110) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.0d0)) then
tmp = -1.0d0
else if (x <= (-8d-94)) then
tmp = x * 0.5d0
else if (x <= 2d-61) then
tmp = 1.0d0
else if (x <= 4d-33) then
tmp = x * 0.5d0
else if (x <= 1.7d+110) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.0) {
tmp = -1.0;
} else if (x <= -8e-94) {
tmp = x * 0.5;
} else if (x <= 2e-61) {
tmp = 1.0;
} else if (x <= 4e-33) {
tmp = x * 0.5;
} else if (x <= 1.7e+110) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.0: tmp = -1.0 elif x <= -8e-94: tmp = x * 0.5 elif x <= 2e-61: tmp = 1.0 elif x <= 4e-33: tmp = x * 0.5 elif x <= 1.7e+110: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -2.0) tmp = -1.0; elseif (x <= -8e-94) tmp = Float64(x * 0.5); elseif (x <= 2e-61) tmp = 1.0; elseif (x <= 4e-33) tmp = Float64(x * 0.5); elseif (x <= 1.7e+110) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.0) tmp = -1.0; elseif (x <= -8e-94) tmp = x * 0.5; elseif (x <= 2e-61) tmp = 1.0; elseif (x <= 4e-33) tmp = x * 0.5; elseif (x <= 1.7e+110) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.0], -1.0, If[LessEqual[x, -8e-94], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 2e-61], 1.0, If[LessEqual[x, 4e-33], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 1.7e+110], 1.0, -1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq -8 \cdot 10^{-94}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-61}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 4 \cdot 10^{-33}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+110}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -2 or 1.7000000000000001e110 < x Initial program 100.0%
Taylor expanded in x around inf 81.4%
if -2 < x < -7.9999999999999996e-94 or 2.0000000000000001e-61 < x < 4.0000000000000002e-33Initial program 100.0%
Taylor expanded in y around 0 75.3%
Taylor expanded in x around 0 72.3%
*-commutative72.3%
Simplified72.3%
if -7.9999999999999996e-94 < x < 2.0000000000000001e-61 or 4.0000000000000002e-33 < x < 1.7000000000000001e110Initial program 100.0%
Taylor expanded in y around inf 55.0%
Final simplification67.5%
(FPCore (x y) :precision binary64 (if (or (<= y -3.25e+41) (not (<= y 4e+21))) (- 1.0 (/ (* x 2.0) y)) (/ x (- 2.0 x))))
double code(double x, double y) {
double tmp;
if ((y <= -3.25e+41) || !(y <= 4e+21)) {
tmp = 1.0 - ((x * 2.0) / y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-3.25d+41)) .or. (.not. (y <= 4d+21))) then
tmp = 1.0d0 - ((x * 2.0d0) / y)
else
tmp = x / (2.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3.25e+41) || !(y <= 4e+21)) {
tmp = 1.0 - ((x * 2.0) / y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.25e+41) or not (y <= 4e+21): tmp = 1.0 - ((x * 2.0) / y) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.25e+41) || !(y <= 4e+21)) tmp = Float64(1.0 - Float64(Float64(x * 2.0) / y)); else tmp = Float64(x / Float64(2.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.25e+41) || ~((y <= 4e+21))) tmp = 1.0 - ((x * 2.0) / y); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.25e+41], N[Not[LessEqual[y, 4e+21]], $MachinePrecision]], N[(1.0 - N[(N[(x * 2.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.25 \cdot 10^{+41} \lor \neg \left(y \leq 4 \cdot 10^{+21}\right):\\
\;\;\;\;1 - \frac{x \cdot 2}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if y < -3.24999999999999988e41 or 4e21 < y Initial program 100.0%
Taylor expanded in y around inf 80.4%
sub-neg80.4%
mul-1-neg80.4%
unsub-neg80.4%
mul-1-neg80.4%
remove-double-neg80.4%
Simplified80.4%
associate-+l-80.4%
sub-div80.4%
Applied egg-rr80.4%
Taylor expanded in x around inf 80.4%
if -3.24999999999999988e41 < y < 4e21Initial program 100.0%
Taylor expanded in y around 0 81.4%
Final simplification81.0%
(FPCore (x y) :precision binary64 (if (or (<= y -6e+41) (not (<= y 4.8e+19))) (- 1.0 (/ x y)) (/ x (- 2.0 x))))
double code(double x, double y) {
double tmp;
if ((y <= -6e+41) || !(y <= 4.8e+19)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-6d+41)) .or. (.not. (y <= 4.8d+19))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (2.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -6e+41) || !(y <= 4.8e+19)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6e+41) or not (y <= 4.8e+19): tmp = 1.0 - (x / y) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -6e+41) || !(y <= 4.8e+19)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(2.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6e+41) || ~((y <= 4.8e+19))) tmp = 1.0 - (x / y); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6e+41], N[Not[LessEqual[y, 4.8e+19]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+41} \lor \neg \left(y \leq 4.8 \cdot 10^{+19}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if y < -5.9999999999999997e41 or 4.8e19 < y Initial program 100.0%
clear-num99.9%
associate-/r/99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 79.4%
Taylor expanded in y around 0 79.7%
mul-1-neg79.7%
unsub-neg79.7%
Simplified79.7%
if -5.9999999999999997e41 < y < 4.8e19Initial program 100.0%
Taylor expanded in y around 0 81.4%
Final simplification80.7%
(FPCore (x y) :precision binary64 (if (<= x -1.1e-23) -1.0 (if (<= x 1.7e+110) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.1e-23) {
tmp = -1.0;
} else if (x <= 1.7e+110) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.1d-23)) then
tmp = -1.0d0
else if (x <= 1.7d+110) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.1e-23) {
tmp = -1.0;
} else if (x <= 1.7e+110) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.1e-23: tmp = -1.0 elif x <= 1.7e+110: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.1e-23) tmp = -1.0; elseif (x <= 1.7e+110) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.1e-23) tmp = -1.0; elseif (x <= 1.7e+110) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.1e-23], -1.0, If[LessEqual[x, 1.7e+110], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-23}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+110}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -1.1e-23 or 1.7000000000000001e110 < x Initial program 100.0%
Taylor expanded in x around inf 78.8%
if -1.1e-23 < x < 1.7000000000000001e110Initial program 100.0%
Taylor expanded in y around inf 51.6%
Final simplification63.2%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 38.8%
Final simplification38.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (- 2.0 (+ x y)))) (- (/ x t_0) (/ y t_0))))
double code(double x, double y) {
double t_0 = 2.0 - (x + y);
return (x / t_0) - (y / t_0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
t_0 = 2.0d0 - (x + y)
code = (x / t_0) - (y / t_0)
end function
public static double code(double x, double y) {
double t_0 = 2.0 - (x + y);
return (x / t_0) - (y / t_0);
}
def code(x, y): t_0 = 2.0 - (x + y) return (x / t_0) - (y / t_0)
function code(x, y) t_0 = Float64(2.0 - Float64(x + y)) return Float64(Float64(x / t_0) - Float64(y / t_0)) end
function tmp = code(x, y) t_0 = 2.0 - (x + y); tmp = (x / t_0) - (y / t_0); end
code[x_, y_] := Block[{t$95$0 = N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]}, N[(N[(x / t$95$0), $MachinePrecision] - N[(y / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 - \left(x + y\right)\\
\frac{x}{t_0} - \frac{y}{t_0}
\end{array}
\end{array}
herbie shell --seed 2023331
(FPCore (x y)
:name "Data.Colour.RGB:hslsv from colour-2.3.3, C"
:precision binary64
:herbie-target
(- (/ x (- 2.0 (+ x y))) (/ y (- 2.0 (+ x y))))
(/ (- x y) (- 2.0 (+ x y))))