
(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 6 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 (<= y -6e+32)
1.0
(if (or (<= y 10.0) (and (not (<= y 6.4e+115)) (<= y 4.6e+152)))
(/ x (- 2.0 x))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6e+32) {
tmp = 1.0;
} else if ((y <= 10.0) || (!(y <= 6.4e+115) && (y <= 4.6e+152))) {
tmp = x / (2.0 - x);
} 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 <= (-6d+32)) then
tmp = 1.0d0
else if ((y <= 10.0d0) .or. (.not. (y <= 6.4d+115)) .and. (y <= 4.6d+152)) then
tmp = x / (2.0d0 - x)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6e+32) {
tmp = 1.0;
} else if ((y <= 10.0) || (!(y <= 6.4e+115) && (y <= 4.6e+152))) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e+32: tmp = 1.0 elif (y <= 10.0) or (not (y <= 6.4e+115) and (y <= 4.6e+152)): tmp = x / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6e+32) tmp = 1.0; elseif ((y <= 10.0) || (!(y <= 6.4e+115) && (y <= 4.6e+152))) tmp = Float64(x / Float64(2.0 - x)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6e+32) tmp = 1.0; elseif ((y <= 10.0) || (~((y <= 6.4e+115)) && (y <= 4.6e+152))) tmp = x / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e+32], 1.0, If[Or[LessEqual[y, 10.0], And[N[Not[LessEqual[y, 6.4e+115]], $MachinePrecision], LessEqual[y, 4.6e+152]]], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+32}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 10 \lor \neg \left(y \leq 6.4 \cdot 10^{+115}\right) \land y \leq 4.6 \cdot 10^{+152}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6e32 or 10 < y < 6.4e115 or 4.5999999999999997e152 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 80.5%
if -6e32 < y < 10 or 6.4e115 < y < 4.5999999999999997e152Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 75.3%
Final simplification77.7%
(FPCore (x y) :precision binary64 (if (<= x -1.32e+115) -1.0 (if (<= x 1.25e-56) (/ (- y) (- 2.0 y)) (/ x (- 2.0 x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.32e+115) {
tmp = -1.0;
} else if (x <= 1.25e-56) {
tmp = -y / (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 (x <= (-1.32d+115)) then
tmp = -1.0d0
else if (x <= 1.25d-56) then
tmp = -y / (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 (x <= -1.32e+115) {
tmp = -1.0;
} else if (x <= 1.25e-56) {
tmp = -y / (2.0 - y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.32e+115: tmp = -1.0 elif x <= 1.25e-56: tmp = -y / (2.0 - y) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.32e+115) tmp = -1.0; elseif (x <= 1.25e-56) tmp = Float64(Float64(-y) / Float64(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 (x <= -1.32e+115) tmp = -1.0; elseif (x <= 1.25e-56) tmp = -y / (2.0 - y); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.32e+115], -1.0, If[LessEqual[x, 1.25e-56], N[((-y) / N[(2.0 - y), $MachinePrecision]), $MachinePrecision], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{+115}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-56}:\\
\;\;\;\;\frac{-y}{2 - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if x < -1.32e115Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 92.1%
if -1.32e115 < x < 1.24999999999999999e-56Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around 0 77.7%
mul-1-neg77.7%
distribute-neg-frac77.7%
Simplified77.7%
if 1.24999999999999999e-56 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 76.6%
Final simplification79.5%
(FPCore (x y)
:precision binary64
(if (<= x -1e+53)
-1.0
(if (<= x 1.4e-57)
1.0
(if (<= x 1.15e-39) (* x 0.5) (if (<= x 980000000.0) 1.0 -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1e+53) {
tmp = -1.0;
} else if (x <= 1.4e-57) {
tmp = 1.0;
} else if (x <= 1.15e-39) {
tmp = x * 0.5;
} else if (x <= 980000000.0) {
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 <= (-1d+53)) then
tmp = -1.0d0
else if (x <= 1.4d-57) then
tmp = 1.0d0
else if (x <= 1.15d-39) then
tmp = x * 0.5d0
else if (x <= 980000000.0d0) 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 <= -1e+53) {
tmp = -1.0;
} else if (x <= 1.4e-57) {
tmp = 1.0;
} else if (x <= 1.15e-39) {
tmp = x * 0.5;
} else if (x <= 980000000.0) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1e+53: tmp = -1.0 elif x <= 1.4e-57: tmp = 1.0 elif x <= 1.15e-39: tmp = x * 0.5 elif x <= 980000000.0: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1e+53) tmp = -1.0; elseif (x <= 1.4e-57) tmp = 1.0; elseif (x <= 1.15e-39) tmp = Float64(x * 0.5); elseif (x <= 980000000.0) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1e+53) tmp = -1.0; elseif (x <= 1.4e-57) tmp = 1.0; elseif (x <= 1.15e-39) tmp = x * 0.5; elseif (x <= 980000000.0) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1e+53], -1.0, If[LessEqual[x, 1.4e-57], 1.0, If[LessEqual[x, 1.15e-39], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 980000000.0], 1.0, -1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+53}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-57}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{-39}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 980000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -9.9999999999999999e52 or 9.8e8 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 79.4%
if -9.9999999999999999e52 < x < 1.4e-57 or 1.15000000000000004e-39 < x < 9.8e8Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 56.6%
if 1.4e-57 < x < 1.15000000000000004e-39Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification67.4%
(FPCore (x y) :precision binary64 (if (<= x -1e+53) -1.0 (if (<= x 6500000000.0) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1e+53) {
tmp = -1.0;
} else if (x <= 6500000000.0) {
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 <= (-1d+53)) then
tmp = -1.0d0
else if (x <= 6500000000.0d0) 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 <= -1e+53) {
tmp = -1.0;
} else if (x <= 6500000000.0) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1e+53: tmp = -1.0 elif x <= 6500000000.0: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1e+53) tmp = -1.0; elseif (x <= 6500000000.0) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1e+53) tmp = -1.0; elseif (x <= 6500000000.0) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1e+53], -1.0, If[LessEqual[x, 6500000000.0], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+53}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 6500000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -9.9999999999999999e52 or 6.5e9 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 79.4%
if -9.9999999999999999e52 < x < 6.5e9Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 54.9%
Final simplification65.6%
(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 37.1%
Final simplification37.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 2023279
(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))))