
(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 (if (or (<= x -3000000000.0) (not (<= x 6.2e+25))) (+ (/ y x) -1.0) (/ (- y) (- 2.0 y))))
double code(double x, double y) {
double tmp;
if ((x <= -3000000000.0) || !(x <= 6.2e+25)) {
tmp = (y / x) + -1.0;
} else {
tmp = -y / (2.0 - y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-3000000000.0d0)) .or. (.not. (x <= 6.2d+25))) then
tmp = (y / x) + (-1.0d0)
else
tmp = -y / (2.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3000000000.0) || !(x <= 6.2e+25)) {
tmp = (y / x) + -1.0;
} else {
tmp = -y / (2.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3000000000.0) or not (x <= 6.2e+25): tmp = (y / x) + -1.0 else: tmp = -y / (2.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((x <= -3000000000.0) || !(x <= 6.2e+25)) tmp = Float64(Float64(y / x) + -1.0); else tmp = Float64(Float64(-y) / Float64(2.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3000000000.0) || ~((x <= 6.2e+25))) tmp = (y / x) + -1.0; else tmp = -y / (2.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3000000000.0], N[Not[LessEqual[x, 6.2e+25]], $MachinePrecision]], N[(N[(y / x), $MachinePrecision] + -1.0), $MachinePrecision], N[((-y) / N[(2.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3000000000 \lor \neg \left(x \leq 6.2 \cdot 10^{+25}\right):\\
\;\;\;\;\frac{y}{x} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{-y}{2 - y}\\
\end{array}
\end{array}
if x < -3e9 or 6.1999999999999996e25 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
expm1-log1p-u97.0%
associate--l-97.0%
Applied egg-rr97.0%
expm1-log1p-u100.0%
div-inv99.7%
flip--46.2%
associate-*l/46.2%
difference-of-squares46.6%
Applied egg-rr46.6%
Taylor expanded in x around inf 82.8%
neg-mul-182.8%
Simplified82.8%
Taylor expanded in x around inf 83.1%
if -3e9 < x < 6.1999999999999996e25Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around 0 71.9%
mul-1-neg71.9%
distribute-neg-frac71.9%
Simplified71.9%
Final simplification77.7%
(FPCore (x y) :precision binary64 (if (or (<= x -2850000000.0) (not (<= x 4.6e+25))) (+ (/ y x) -1.0) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -2850000000.0) || !(x <= 4.6e+25)) {
tmp = (y / x) + -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 <= (-2850000000.0d0)) .or. (.not. (x <= 4.6d+25))) then
tmp = (y / x) + (-1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2850000000.0) || !(x <= 4.6e+25)) {
tmp = (y / x) + -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2850000000.0) or not (x <= 4.6e+25): tmp = (y / x) + -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -2850000000.0) || !(x <= 4.6e+25)) tmp = Float64(Float64(y / x) + -1.0); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2850000000.0) || ~((x <= 4.6e+25))) tmp = (y / x) + -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2850000000.0], N[Not[LessEqual[x, 4.6e+25]], $MachinePrecision]], N[(N[(y / x), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2850000000 \lor \neg \left(x \leq 4.6 \cdot 10^{+25}\right):\\
\;\;\;\;\frac{y}{x} + -1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.85e9 or 4.5999999999999996e25 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
expm1-log1p-u97.0%
associate--l-97.0%
Applied egg-rr97.0%
expm1-log1p-u100.0%
div-inv99.7%
flip--46.2%
associate-*l/46.2%
difference-of-squares46.6%
Applied egg-rr46.6%
Taylor expanded in x around inf 82.8%
neg-mul-182.8%
Simplified82.8%
Taylor expanded in x around inf 83.1%
if -2.85e9 < x < 4.5999999999999996e25Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 48.1%
Final simplification66.3%
(FPCore (x y) :precision binary64 (if (or (<= y -5.6e+49) (not (<= y 2.7e+65))) (- 1.0 (/ x y)) (/ x (- 2.0 x))))
double code(double x, double y) {
double tmp;
if ((y <= -5.6e+49) || !(y <= 2.7e+65)) {
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 <= (-5.6d+49)) .or. (.not. (y <= 2.7d+65))) 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 <= -5.6e+49) || !(y <= 2.7e+65)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5.6e+49) or not (y <= 2.7e+65): tmp = 1.0 - (x / y) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -5.6e+49) || !(y <= 2.7e+65)) 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 <= -5.6e+49) || ~((y <= 2.7e+65))) tmp = 1.0 - (x / y); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5.6e+49], N[Not[LessEqual[y, 2.7e+65]], $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 -5.6 \cdot 10^{+49} \lor \neg \left(y \leq 2.7 \cdot 10^{+65}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if y < -5.5999999999999996e49 or 2.70000000000000019e65 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
expm1-log1p-u98.9%
associate--l-98.9%
Applied egg-rr98.9%
expm1-log1p-u100.0%
div-inv99.8%
flip--37.9%
associate-*l/38.0%
difference-of-squares38.6%
Applied egg-rr38.6%
Taylor expanded in y around inf 77.3%
Taylor expanded in y around inf 77.0%
mul-1-neg77.0%
unsub-neg77.0%
Simplified77.0%
if -5.5999999999999996e49 < y < 2.70000000000000019e65Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 74.4%
Final simplification75.3%
(FPCore (x y) :precision binary64 (if (or (<= y -5.1e+46) (not (<= y 5.5e+65))) (/ y (+ x y)) (/ x (- 2.0 x))))
double code(double x, double y) {
double tmp;
if ((y <= -5.1e+46) || !(y <= 5.5e+65)) {
tmp = y / (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 <= (-5.1d+46)) .or. (.not. (y <= 5.5d+65))) then
tmp = y / (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 <= -5.1e+46) || !(y <= 5.5e+65)) {
tmp = y / (x + y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5.1e+46) or not (y <= 5.5e+65): tmp = y / (x + y) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -5.1e+46) || !(y <= 5.5e+65)) tmp = Float64(y / 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 <= -5.1e+46) || ~((y <= 5.5e+65))) tmp = y / (x + y); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5.1e+46], N[Not[LessEqual[y, 5.5e+65]], $MachinePrecision]], N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.1 \cdot 10^{+46} \lor \neg \left(y \leq 5.5 \cdot 10^{+65}\right):\\
\;\;\;\;\frac{y}{x + y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if y < -5.0999999999999997e46 or 5.4999999999999996e65 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
expm1-log1p-u98.9%
associate--l-98.9%
Applied egg-rr98.9%
expm1-log1p-u100.0%
div-inv99.8%
flip--37.9%
associate-*l/38.0%
difference-of-squares38.6%
Applied egg-rr38.6%
Taylor expanded in y around inf 77.3%
if -5.0999999999999997e46 < y < 5.4999999999999996e65Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 74.4%
Final simplification75.4%
(FPCore (x y) :precision binary64 (if (<= x -3500000000.0) -1.0 (if (<= x 5.6e+25) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -3500000000.0) {
tmp = -1.0;
} else if (x <= 5.6e+25) {
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 <= (-3500000000.0d0)) then
tmp = -1.0d0
else if (x <= 5.6d+25) 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 <= -3500000000.0) {
tmp = -1.0;
} else if (x <= 5.6e+25) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3500000000.0: tmp = -1.0 elif x <= 5.6e+25: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3500000000.0) tmp = -1.0; elseif (x <= 5.6e+25) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3500000000.0) tmp = -1.0; elseif (x <= 5.6e+25) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3500000000.0], -1.0, If[LessEqual[x, 5.6e+25], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3500000000:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{+25}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -3.5e9 or 5.6000000000000003e25 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 82.4%
if -3.5e9 < x < 5.6000000000000003e25Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 48.1%
Final simplification65.9%
(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%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 45.0%
Final simplification45.0%
(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 2023182
(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))))