
(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 10 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 (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}
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -2.8e+35)
t_0
(if (<= y -1.15e-225)
-1.0
(if (<= y 5e-243) (* x 0.5) (if (<= y 2.8e+40) -1.0 t_0))))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -2.8e+35) {
tmp = t_0;
} else if (y <= -1.15e-225) {
tmp = -1.0;
} else if (y <= 5e-243) {
tmp = x * 0.5;
} else if (y <= 2.8e+40) {
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 = 1.0d0 - (x / y)
if (y <= (-2.8d+35)) then
tmp = t_0
else if (y <= (-1.15d-225)) then
tmp = -1.0d0
else if (y <= 5d-243) then
tmp = x * 0.5d0
else if (y <= 2.8d+40) 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 = 1.0 - (x / y);
double tmp;
if (y <= -2.8e+35) {
tmp = t_0;
} else if (y <= -1.15e-225) {
tmp = -1.0;
} else if (y <= 5e-243) {
tmp = x * 0.5;
} else if (y <= 2.8e+40) {
tmp = -1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) tmp = 0 if y <= -2.8e+35: tmp = t_0 elif y <= -1.15e-225: tmp = -1.0 elif y <= 5e-243: tmp = x * 0.5 elif y <= 2.8e+40: tmp = -1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -2.8e+35) tmp = t_0; elseif (y <= -1.15e-225) tmp = -1.0; elseif (y <= 5e-243) tmp = Float64(x * 0.5); elseif (y <= 2.8e+40) tmp = -1.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -2.8e+35) tmp = t_0; elseif (y <= -1.15e-225) tmp = -1.0; elseif (y <= 5e-243) tmp = x * 0.5; elseif (y <= 2.8e+40) tmp = -1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.8e+35], t$95$0, If[LessEqual[y, -1.15e-225], -1.0, If[LessEqual[y, 5e-243], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.8e+40], -1.0, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -2.8 \cdot 10^{+35}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-225}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-243}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+40}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= x -2.5e+70) (/ (- x y) (- x)) (if (<= x 3.55e-6) (/ (- x y) (- 2.0 y)) (/ x (- 2.0 (+ x y))))))
double code(double x, double y) {
double tmp;
if (x <= -2.5e+70) {
tmp = (x - y) / -x;
} else if (x <= 3.55e-6) {
tmp = (x - y) / (2.0 - y);
} else {
tmp = x / (2.0 - (x + y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.5d+70)) then
tmp = (x - y) / -x
else if (x <= 3.55d-6) then
tmp = (x - y) / (2.0d0 - y)
else
tmp = x / (2.0d0 - (x + y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.5e+70) {
tmp = (x - y) / -x;
} else if (x <= 3.55e-6) {
tmp = (x - y) / (2.0 - y);
} else {
tmp = x / (2.0 - (x + y));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.5e+70: tmp = (x - y) / -x elif x <= 3.55e-6: tmp = (x - y) / (2.0 - y) else: tmp = x / (2.0 - (x + y)) return tmp
function code(x, y) tmp = 0.0 if (x <= -2.5e+70) tmp = Float64(Float64(x - y) / Float64(-x)); elseif (x <= 3.55e-6) tmp = Float64(Float64(x - y) / Float64(2.0 - y)); else tmp = Float64(x / Float64(2.0 - Float64(x + y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.5e+70) tmp = (x - y) / -x; elseif (x <= 3.55e-6) tmp = (x - y) / (2.0 - y); else tmp = x / (2.0 - (x + y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.5e+70], N[(N[(x - y), $MachinePrecision] / (-x)), $MachinePrecision], If[LessEqual[x, 3.55e-6], N[(N[(x - y), $MachinePrecision] / N[(2.0 - y), $MachinePrecision]), $MachinePrecision], N[(x / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+70}:\\
\;\;\;\;\frac{x - y}{-x}\\
\mathbf{elif}\;x \leq 3.55 \cdot 10^{-6}:\\
\;\;\;\;\frac{x - y}{2 - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - \left(x + y\right)}\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(if (<= y -4.3e+33)
1.0
(if (<= y -1.32e-225)
-1.0
(if (<= y 5.8e-242) (* x 0.5) (if (<= y 6.5e+39) -1.0 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -4.3e+33) {
tmp = 1.0;
} else if (y <= -1.32e-225) {
tmp = -1.0;
} else if (y <= 5.8e-242) {
tmp = x * 0.5;
} else if (y <= 6.5e+39) {
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 <= (-4.3d+33)) then
tmp = 1.0d0
else if (y <= (-1.32d-225)) then
tmp = -1.0d0
else if (y <= 5.8d-242) then
tmp = x * 0.5d0
else if (y <= 6.5d+39) 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 <= -4.3e+33) {
tmp = 1.0;
} else if (y <= -1.32e-225) {
tmp = -1.0;
} else if (y <= 5.8e-242) {
tmp = x * 0.5;
} else if (y <= 6.5e+39) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.3e+33: tmp = 1.0 elif y <= -1.32e-225: tmp = -1.0 elif y <= 5.8e-242: tmp = x * 0.5 elif y <= 6.5e+39: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.3e+33) tmp = 1.0; elseif (y <= -1.32e-225) tmp = -1.0; elseif (y <= 5.8e-242) tmp = Float64(x * 0.5); elseif (y <= 6.5e+39) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.3e+33) tmp = 1.0; elseif (y <= -1.32e-225) tmp = -1.0; elseif (y <= 5.8e-242) tmp = x * 0.5; elseif (y <= 6.5e+39) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.3e+33], 1.0, If[LessEqual[y, -1.32e-225], -1.0, If[LessEqual[y, 5.8e-242], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 6.5e+39], -1.0, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{+33}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.32 \cdot 10^{-225}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{-242}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+39}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= y -7e+35) (not (<= y 9e+40))) (- 1.0 (/ x y)) (/ x (- 2.0 x))))
double code(double x, double y) {
double tmp;
if ((y <= -7e+35) || !(y <= 9e+40)) {
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 <= (-7d+35)) .or. (.not. (y <= 9d+40))) 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 <= -7e+35) || !(y <= 9e+40)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7e+35) or not (y <= 9e+40): tmp = 1.0 - (x / y) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7e+35) || !(y <= 9e+40)) 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 <= -7e+35) || ~((y <= 9e+40))) tmp = 1.0 - (x / y); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7e+35], N[Not[LessEqual[y, 9e+40]], $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 -7 \cdot 10^{+35} \lor \neg \left(y \leq 9 \cdot 10^{+40}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= y -7e-29) (/ y (+ y -2.0)) (if (<= y 3.9e+40) (/ x (- 2.0 x)) (- 1.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -7e-29) {
tmp = y / (y + -2.0);
} else if (y <= 3.9e+40) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-7d-29)) then
tmp = y / (y + (-2.0d0))
else if (y <= 3.9d+40) then
tmp = x / (2.0d0 - x)
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -7e-29) {
tmp = y / (y + -2.0);
} else if (y <= 3.9e+40) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7e-29: tmp = y / (y + -2.0) elif y <= 3.9e+40: tmp = x / (2.0 - x) else: tmp = 1.0 - (x / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -7e-29) tmp = Float64(y / Float64(y + -2.0)); elseif (y <= 3.9e+40) tmp = Float64(x / Float64(2.0 - x)); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7e-29) tmp = y / (y + -2.0); elseif (y <= 3.9e+40) tmp = x / (2.0 - x); else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7e-29], N[(y / N[(y + -2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.9e+40], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-29}:\\
\;\;\;\;\frac{y}{y + -2}\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{+40}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\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}
(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(Float64(2.0 - 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[(N[(2.0 - x), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\left(2 - x\right) - y}
\end{array}
(FPCore (x y) :precision binary64 (if (<= y -2e+36) 1.0 (if (<= y 1.95e+40) -1.0 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2e+36) {
tmp = 1.0;
} else if (y <= 1.95e+40) {
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 <= (-2d+36)) then
tmp = 1.0d0
else if (y <= 1.95d+40) 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 <= -2e+36) {
tmp = 1.0;
} else if (y <= 1.95e+40) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e+36: tmp = 1.0 elif y <= 1.95e+40: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2e+36) tmp = 1.0; elseif (y <= 1.95e+40) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e+36) tmp = 1.0; elseif (y <= 1.95e+40) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e+36], 1.0, If[LessEqual[y, 1.95e+40], -1.0, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+36}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+40}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
(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}
(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 2024003
(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))))