
(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 (<= x -3.4e+66) -1.0 (if (<= x 2.85e+94) (/ (- y) (- 2.0 y)) -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -3.4e+66) {
tmp = -1.0;
} else if (x <= 2.85e+94) {
tmp = -y / (2.0 - y);
} 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 <= (-3.4d+66)) then
tmp = -1.0d0
else if (x <= 2.85d+94) then
tmp = -y / (2.0d0 - y)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.4e+66) {
tmp = -1.0;
} else if (x <= 2.85e+94) {
tmp = -y / (2.0 - y);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.4e+66: tmp = -1.0 elif x <= 2.85e+94: tmp = -y / (2.0 - y) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.4e+66) tmp = -1.0; elseif (x <= 2.85e+94) tmp = Float64(Float64(-y) / Float64(2.0 - y)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.4e+66) tmp = -1.0; elseif (x <= 2.85e+94) tmp = -y / (2.0 - y); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.4e+66], -1.0, If[LessEqual[x, 2.85e+94], N[((-y) / N[(2.0 - y), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+66}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 2.85 \cdot 10^{+94}:\\
\;\;\;\;\frac{-y}{2 - y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -3.4000000000000003e66 or 2.8500000000000001e94 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 83.9%
if -3.4000000000000003e66 < x < 2.8500000000000001e94Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around 0 77.2%
mul-1-neg77.2%
distribute-neg-frac77.2%
Simplified77.2%
Final simplification79.5%
(FPCore (x y) :precision binary64 (if (<= x -3e+66) -1.0 (if (<= x 2.2e+94) (+ 1.0 (/ 2.0 y)) -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -3e+66) {
tmp = -1.0;
} else if (x <= 2.2e+94) {
tmp = 1.0 + (2.0 / y);
} 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 <= (-3d+66)) then
tmp = -1.0d0
else if (x <= 2.2d+94) then
tmp = 1.0d0 + (2.0d0 / y)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3e+66) {
tmp = -1.0;
} else if (x <= 2.2e+94) {
tmp = 1.0 + (2.0 / y);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3e+66: tmp = -1.0 elif x <= 2.2e+94: tmp = 1.0 + (2.0 / y) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3e+66) tmp = -1.0; elseif (x <= 2.2e+94) tmp = Float64(1.0 + Float64(2.0 / y)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3e+66) tmp = -1.0; elseif (x <= 2.2e+94) tmp = 1.0 + (2.0 / y); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3e+66], -1.0, If[LessEqual[x, 2.2e+94], N[(1.0 + N[(2.0 / y), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+66}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+94}:\\
\;\;\;\;1 + \frac{2}{y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -3.00000000000000002e66 or 2.20000000000000012e94 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 83.9%
if -3.00000000000000002e66 < x < 2.20000000000000012e94Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 58.1%
associate--l+58.1%
associate-*r/58.1%
associate-*r/58.1%
div-sub58.1%
cancel-sign-sub-inv58.1%
metadata-eval58.1%
*-lft-identity58.1%
+-commutative58.1%
mul-1-neg58.1%
unsub-neg58.1%
Simplified58.1%
Taylor expanded in x around 0 57.9%
Final simplification66.7%
(FPCore (x y) :precision binary64 (if (<= y -5.8e+77) 1.0 (if (<= y 112.0) (/ x (- 2.0 x)) (+ 1.0 (/ 2.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= -5.8e+77) {
tmp = 1.0;
} else if (y <= 112.0) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0 + (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 (y <= (-5.8d+77)) then
tmp = 1.0d0
else if (y <= 112.0d0) then
tmp = x / (2.0d0 - x)
else
tmp = 1.0d0 + (2.0d0 / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -5.8e+77) {
tmp = 1.0;
} else if (y <= 112.0) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0 + (2.0 / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.8e+77: tmp = 1.0 elif y <= 112.0: tmp = x / (2.0 - x) else: tmp = 1.0 + (2.0 / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -5.8e+77) tmp = 1.0; elseif (y <= 112.0) tmp = Float64(x / Float64(2.0 - x)); else tmp = Float64(1.0 + Float64(2.0 / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5.8e+77) tmp = 1.0; elseif (y <= 112.0) tmp = x / (2.0 - x); else tmp = 1.0 + (2.0 / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.8e+77], 1.0, If[LessEqual[y, 112.0], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(2.0 / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+77}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 112:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{2}{y}\\
\end{array}
\end{array}
if y < -5.8000000000000003e77Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 85.1%
if -5.8000000000000003e77 < y < 112Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 71.5%
if 112 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 78.6%
associate--l+78.6%
associate-*r/78.6%
associate-*r/78.6%
div-sub78.6%
cancel-sign-sub-inv78.6%
metadata-eval78.6%
*-lft-identity78.6%
+-commutative78.6%
mul-1-neg78.6%
unsub-neg78.6%
Simplified78.6%
Taylor expanded in x around 0 77.8%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (<= x -3e+66) -1.0 (if (<= x 2.45e+94) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -3e+66) {
tmp = -1.0;
} else if (x <= 2.45e+94) {
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 <= (-3d+66)) then
tmp = -1.0d0
else if (x <= 2.45d+94) 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 <= -3e+66) {
tmp = -1.0;
} else if (x <= 2.45e+94) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3e+66: tmp = -1.0 elif x <= 2.45e+94: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3e+66) tmp = -1.0; elseif (x <= 2.45e+94) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3e+66) tmp = -1.0; elseif (x <= 2.45e+94) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3e+66], -1.0, If[LessEqual[x, 2.45e+94], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+66}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 2.45 \cdot 10^{+94}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -3.00000000000000002e66 or 2.4499999999999999e94 < x Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 83.9%
if -3.00000000000000002e66 < x < 2.4499999999999999e94Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 57.8%
Final simplification66.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 34.4%
Final simplification34.4%
(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 2023185
(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))))