
(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 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -2.85e-83) (not (<= y 6.6e-18))) (/ (+ y 2.0) (- y (/ 4.0 y))) (/ (- x) (+ x -2.0))))
double code(double x, double y) {
double tmp;
if ((y <= -2.85e-83) || !(y <= 6.6e-18)) {
tmp = (y + 2.0) / (y - (4.0 / y));
} else {
tmp = -x / (x + -2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2.85d-83)) .or. (.not. (y <= 6.6d-18))) then
tmp = (y + 2.0d0) / (y - (4.0d0 / y))
else
tmp = -x / (x + (-2.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.85e-83) || !(y <= 6.6e-18)) {
tmp = (y + 2.0) / (y - (4.0 / y));
} else {
tmp = -x / (x + -2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.85e-83) or not (y <= 6.6e-18): tmp = (y + 2.0) / (y - (4.0 / y)) else: tmp = -x / (x + -2.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.85e-83) || !(y <= 6.6e-18)) tmp = Float64(Float64(y + 2.0) / Float64(y - Float64(4.0 / y))); else tmp = Float64(Float64(-x) / Float64(x + -2.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.85e-83) || ~((y <= 6.6e-18))) tmp = (y + 2.0) / (y - (4.0 / y)); else tmp = -x / (x + -2.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.85e-83], N[Not[LessEqual[y, 6.6e-18]], $MachinePrecision]], N[(N[(y + 2.0), $MachinePrecision] / N[(y - N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-x) / N[(x + -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.85 \cdot 10^{-83} \lor \neg \left(y \leq 6.6 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{y + 2}{y - \frac{4}{y}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{x + -2}\\
\end{array}
\end{array}
if y < -2.85e-83 or 6.6000000000000003e-18 < y Initial program 99.9%
Simplified99.9%
add-cbrt-cube99.9%
pow399.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
Applied egg-rr99.9%
rem-cbrt-cube99.9%
associate-+r+99.9%
flip-+45.1%
metadata-eval45.1%
associate-+r-45.1%
associate-/l*43.3%
associate-*l/45.0%
clear-num45.0%
associate-*l/45.1%
*-un-lft-identity45.1%
sub-neg45.1%
metadata-eval45.1%
div-sub45.1%
Applied egg-rr75.9%
Taylor expanded in x around 0 75.9%
+-commutative75.9%
associate-*r/75.9%
metadata-eval75.9%
Simplified75.9%
if -2.85e-83 < y < 6.6000000000000003e-18Initial program 100.0%
Simplified100.0%
Taylor expanded in y around 0 82.5%
associate-*r/82.5%
mul-1-neg82.5%
sub-neg82.5%
metadata-eval82.5%
Simplified82.5%
Final simplification78.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.05e-82) (not (<= y 6.4e-25))) (/ y (- y 2.0)) (/ (- x) (+ x -2.0))))
double code(double x, double y) {
double tmp;
if ((y <= -1.05e-82) || !(y <= 6.4e-25)) {
tmp = y / (y - 2.0);
} else {
tmp = -x / (x + -2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.05d-82)) .or. (.not. (y <= 6.4d-25))) then
tmp = y / (y - 2.0d0)
else
tmp = -x / (x + (-2.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.05e-82) || !(y <= 6.4e-25)) {
tmp = y / (y - 2.0);
} else {
tmp = -x / (x + -2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.05e-82) or not (y <= 6.4e-25): tmp = y / (y - 2.0) else: tmp = -x / (x + -2.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.05e-82) || !(y <= 6.4e-25)) tmp = Float64(y / Float64(y - 2.0)); else tmp = Float64(Float64(-x) / Float64(x + -2.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.05e-82) || ~((y <= 6.4e-25))) tmp = y / (y - 2.0); else tmp = -x / (x + -2.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.05e-82], N[Not[LessEqual[y, 6.4e-25]], $MachinePrecision]], N[(y / N[(y - 2.0), $MachinePrecision]), $MachinePrecision], N[((-x) / N[(x + -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-82} \lor \neg \left(y \leq 6.4 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{y}{y - 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{x + -2}\\
\end{array}
\end{array}
if y < -1.05e-82 or 6.4000000000000002e-25 < y Initial program 99.9%
Simplified99.9%
Taylor expanded in x around 0 75.9%
if -1.05e-82 < y < 6.4000000000000002e-25Initial program 100.0%
Simplified100.0%
Taylor expanded in y around 0 82.5%
associate-*r/82.5%
mul-1-neg82.5%
sub-neg82.5%
metadata-eval82.5%
Simplified82.5%
Final simplification78.6%
(FPCore (x y)
:precision binary64
(if (<= y -2.7e-6)
1.0
(if (<= y -4.4e-217)
-1.0
(if (<= y 3e-240) (* x 0.5) (if (<= y 3e+64) -1.0 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.7e-6) {
tmp = 1.0;
} else if (y <= -4.4e-217) {
tmp = -1.0;
} else if (y <= 3e-240) {
tmp = x * 0.5;
} else if (y <= 3e+64) {
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 (y <= (-2.7d-6)) then
tmp = 1.0d0
else if (y <= (-4.4d-217)) then
tmp = -1.0d0
else if (y <= 3d-240) then
tmp = x * 0.5d0
else if (y <= 3d+64) 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 (y <= -2.7e-6) {
tmp = 1.0;
} else if (y <= -4.4e-217) {
tmp = -1.0;
} else if (y <= 3e-240) {
tmp = x * 0.5;
} else if (y <= 3e+64) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.7e-6: tmp = 1.0 elif y <= -4.4e-217: tmp = -1.0 elif y <= 3e-240: tmp = x * 0.5 elif y <= 3e+64: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.7e-6) tmp = 1.0; elseif (y <= -4.4e-217) tmp = -1.0; elseif (y <= 3e-240) tmp = Float64(x * 0.5); elseif (y <= 3e+64) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.7e-6) tmp = 1.0; elseif (y <= -4.4e-217) tmp = -1.0; elseif (y <= 3e-240) tmp = x * 0.5; elseif (y <= 3e+64) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.7e-6], 1.0, If[LessEqual[y, -4.4e-217], -1.0, If[LessEqual[y, 3e-240], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 3e+64], -1.0, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{-6}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -4.4 \cdot 10^{-217}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-240}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+64}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.69999999999999998e-6 or 3.0000000000000002e64 < y Initial program 100.0%
Simplified100.0%
Taylor expanded in y around inf 81.4%
if -2.69999999999999998e-6 < y < -4.39999999999999964e-217 or 2.99999999999999991e-240 < y < 3.0000000000000002e64Initial program 99.9%
Simplified99.9%
Taylor expanded in x around inf 56.7%
if -4.39999999999999964e-217 < y < 2.99999999999999991e-240Initial program 100.0%
Simplified100.0%
Taylor expanded in y around 0 90.7%
associate-*r/90.7%
mul-1-neg90.7%
sub-neg90.7%
metadata-eval90.7%
Simplified90.7%
Taylor expanded in x around 0 63.3%
*-commutative63.3%
Simplified63.3%
Final simplification69.1%
(FPCore (x y) :precision binary64 (if (<= x -9.5e+134) -1.0 (if (<= x 5.2e+60) (/ y (- y 2.0)) -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -9.5e+134) {
tmp = -1.0;
} else if (x <= 5.2e+60) {
tmp = y / (y - 2.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 <= (-9.5d+134)) then
tmp = -1.0d0
else if (x <= 5.2d+60) then
tmp = y / (y - 2.0d0)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e+134) {
tmp = -1.0;
} else if (x <= 5.2e+60) {
tmp = y / (y - 2.0);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9.5e+134: tmp = -1.0 elif x <= 5.2e+60: tmp = y / (y - 2.0) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -9.5e+134) tmp = -1.0; elseif (x <= 5.2e+60) tmp = Float64(y / Float64(y - 2.0)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9.5e+134) tmp = -1.0; elseif (x <= 5.2e+60) tmp = y / (y - 2.0); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9.5e+134], -1.0, If[LessEqual[x, 5.2e+60], N[(y / N[(y - 2.0), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+134}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+60}:\\
\;\;\;\;\frac{y}{y - 2}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -9.5000000000000004e134 or 5.20000000000000016e60 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around inf 86.0%
if -9.5000000000000004e134 < x < 5.20000000000000016e60Initial program 99.9%
Simplified99.9%
Taylor expanded in x around 0 72.0%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (<= x -9.5e+134) -1.0 (if (<= x 2.6e+58) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -9.5e+134) {
tmp = -1.0;
} else if (x <= 2.6e+58) {
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 <= (-9.5d+134)) then
tmp = -1.0d0
else if (x <= 2.6d+58) 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 <= -9.5e+134) {
tmp = -1.0;
} else if (x <= 2.6e+58) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9.5e+134: tmp = -1.0 elif x <= 2.6e+58: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -9.5e+134) tmp = -1.0; elseif (x <= 2.6e+58) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9.5e+134) tmp = -1.0; elseif (x <= 2.6e+58) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9.5e+134], -1.0, If[LessEqual[x, 2.6e+58], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+134}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+58}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -9.5000000000000004e134 or 2.59999999999999988e58 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in x around inf 86.0%
if -9.5000000000000004e134 < x < 2.59999999999999988e58Initial program 99.9%
Simplified99.9%
Taylor expanded in y around inf 56.1%
Final simplification66.4%
(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 99.9%
Simplified99.9%
Taylor expanded in x around inf 35.1%
Final simplification35.1%
(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 2023326
(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))))