
(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 8 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%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ x (- 2.0 (+ x y))))) (if (<= x -8.9e+77) t_0 (if (<= x 1.5e+76) (/ (- x y) (- 2.0 y)) t_0))))
double code(double x, double y) {
double t_0 = x / (2.0 - (x + y));
double tmp;
if (x <= -8.9e+77) {
tmp = t_0;
} else if (x <= 1.5e+76) {
tmp = (x - y) / (2.0 - y);
} 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 = x / (2.0d0 - (x + y))
if (x <= (-8.9d+77)) then
tmp = t_0
else if (x <= 1.5d+76) then
tmp = (x - y) / (2.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (2.0 - (x + y));
double tmp;
if (x <= -8.9e+77) {
tmp = t_0;
} else if (x <= 1.5e+76) {
tmp = (x - y) / (2.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (2.0 - (x + y)) tmp = 0 if x <= -8.9e+77: tmp = t_0 elif x <= 1.5e+76: tmp = (x - y) / (2.0 - y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(2.0 - Float64(x + y))) tmp = 0.0 if (x <= -8.9e+77) tmp = t_0; elseif (x <= 1.5e+76) tmp = Float64(Float64(x - y) / Float64(2.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (2.0 - (x + y)); tmp = 0.0; if (x <= -8.9e+77) tmp = t_0; elseif (x <= 1.5e+76) tmp = (x - y) / (2.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.9e+77], t$95$0, If[LessEqual[x, 1.5e+76], N[(N[(x - y), $MachinePrecision] / N[(2.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2 - \left(x + y\right)}\\
\mathbf{if}\;x \leq -8.9 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+76}:\\
\;\;\;\;\frac{x - y}{2 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.8999999999999998e77 or 1.4999999999999999e76 < x Initial program 100.0%
Taylor expanded in x around inf
Simplified80.8%
if -8.8999999999999998e77 < x < 1.4999999999999999e76Initial program 100.0%
Taylor expanded in x around 0
--lowering--.f6491.7%
Simplified91.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ x (- 2.0 (+ x y))))) (if (<= x -1.2e-7) t_0 (if (<= x 1.9e+75) (/ y (+ y -2.0)) t_0))))
double code(double x, double y) {
double t_0 = x / (2.0 - (x + y));
double tmp;
if (x <= -1.2e-7) {
tmp = t_0;
} else if (x <= 1.9e+75) {
tmp = y / (y + -2.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 = x / (2.0d0 - (x + y))
if (x <= (-1.2d-7)) then
tmp = t_0
else if (x <= 1.9d+75) then
tmp = y / (y + (-2.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (2.0 - (x + y));
double tmp;
if (x <= -1.2e-7) {
tmp = t_0;
} else if (x <= 1.9e+75) {
tmp = y / (y + -2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (2.0 - (x + y)) tmp = 0 if x <= -1.2e-7: tmp = t_0 elif x <= 1.9e+75: tmp = y / (y + -2.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(2.0 - Float64(x + y))) tmp = 0.0 if (x <= -1.2e-7) tmp = t_0; elseif (x <= 1.9e+75) tmp = Float64(y / Float64(y + -2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (2.0 - (x + y)); tmp = 0.0; if (x <= -1.2e-7) tmp = t_0; elseif (x <= 1.9e+75) tmp = y / (y + -2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.2e-7], t$95$0, If[LessEqual[x, 1.9e+75], N[(y / N[(y + -2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2 - \left(x + y\right)}\\
\mathbf{if}\;x \leq -1.2 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+75}:\\
\;\;\;\;\frac{y}{y + -2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.19999999999999989e-7 or 1.9000000000000001e75 < x Initial program 100.0%
Taylor expanded in x around inf
Simplified76.8%
if -1.19999999999999989e-7 < x < 1.9000000000000001e75Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
mul-1-negN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
+-lowering-+.f64N/A
metadata-eval77.6%
Simplified77.6%
(FPCore (x y) :precision binary64 (if (<= x -4.3e-7) (/ 1.0 (+ (/ 2.0 x) -1.0)) (if (<= x 3.5e+74) (/ y (+ y -2.0)) (/ x (- 2.0 x)))))
double code(double x, double y) {
double tmp;
if (x <= -4.3e-7) {
tmp = 1.0 / ((2.0 / x) + -1.0);
} else if (x <= 3.5e+74) {
tmp = y / (y + -2.0);
} 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 <= (-4.3d-7)) then
tmp = 1.0d0 / ((2.0d0 / x) + (-1.0d0))
else if (x <= 3.5d+74) then
tmp = y / (y + (-2.0d0))
else
tmp = x / (2.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.3e-7) {
tmp = 1.0 / ((2.0 / x) + -1.0);
} else if (x <= 3.5e+74) {
tmp = y / (y + -2.0);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.3e-7: tmp = 1.0 / ((2.0 / x) + -1.0) elif x <= 3.5e+74: tmp = y / (y + -2.0) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -4.3e-7) tmp = Float64(1.0 / Float64(Float64(2.0 / x) + -1.0)); elseif (x <= 3.5e+74) tmp = Float64(y / Float64(y + -2.0)); else tmp = Float64(x / Float64(2.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.3e-7) tmp = 1.0 / ((2.0 / x) + -1.0); elseif (x <= 3.5e+74) tmp = y / (y + -2.0); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.3e-7], N[(1.0 / N[(N[(2.0 / x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.5e+74], N[(y / N[(y + -2.0), $MachinePrecision]), $MachinePrecision], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{\frac{2}{x} + -1}\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+74}:\\
\;\;\;\;\frac{y}{y + -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if x < -4.3000000000000001e-7Initial program 99.9%
Taylor expanded in y around 0
/-lowering-/.f64N/A
--lowering--.f6471.4%
Simplified71.4%
clear-numN/A
/-lowering-/.f64N/A
div-subN/A
sub-negN/A
*-inversesN/A
metadata-evalN/A
+-lowering-+.f64N/A
/-lowering-/.f6471.4%
Applied egg-rr71.4%
if -4.3000000000000001e-7 < x < 3.50000000000000014e74Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
mul-1-negN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
+-lowering-+.f64N/A
metadata-eval77.6%
Simplified77.6%
if 3.50000000000000014e74 < x Initial program 100.0%
Taylor expanded in y around 0
/-lowering-/.f64N/A
--lowering--.f6481.5%
Simplified81.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ x (- 2.0 x)))) (if (<= x -2.85e-7) t_0 (if (<= x 7.2e+71) (/ y (+ y -2.0)) t_0))))
double code(double x, double y) {
double t_0 = x / (2.0 - x);
double tmp;
if (x <= -2.85e-7) {
tmp = t_0;
} else if (x <= 7.2e+71) {
tmp = y / (y + -2.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 = x / (2.0d0 - x)
if (x <= (-2.85d-7)) then
tmp = t_0
else if (x <= 7.2d+71) then
tmp = y / (y + (-2.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (2.0 - x);
double tmp;
if (x <= -2.85e-7) {
tmp = t_0;
} else if (x <= 7.2e+71) {
tmp = y / (y + -2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (2.0 - x) tmp = 0 if x <= -2.85e-7: tmp = t_0 elif x <= 7.2e+71: tmp = y / (y + -2.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(2.0 - x)) tmp = 0.0 if (x <= -2.85e-7) tmp = t_0; elseif (x <= 7.2e+71) tmp = Float64(y / Float64(y + -2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (2.0 - x); tmp = 0.0; if (x <= -2.85e-7) tmp = t_0; elseif (x <= 7.2e+71) tmp = y / (y + -2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.85e-7], t$95$0, If[LessEqual[x, 7.2e+71], N[(y / N[(y + -2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2 - x}\\
\mathbf{if}\;x \leq -2.85 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{+71}:\\
\;\;\;\;\frac{y}{y + -2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.8500000000000002e-7 or 7.1999999999999999e71 < x Initial program 100.0%
Taylor expanded in y around 0
/-lowering-/.f64N/A
--lowering--.f6476.0%
Simplified76.0%
if -2.8500000000000002e-7 < x < 7.1999999999999999e71Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
mul-1-negN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
+-lowering-+.f64N/A
metadata-eval77.6%
Simplified77.6%
(FPCore (x y) :precision binary64 (if (<= y -2.6e+19) 1.0 (if (<= y 2.55e+51) (/ x (- 2.0 x)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.6e+19) {
tmp = 1.0;
} else if (y <= 2.55e+51) {
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 <= (-2.6d+19)) then
tmp = 1.0d0
else if (y <= 2.55d+51) 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 <= -2.6e+19) {
tmp = 1.0;
} else if (y <= 2.55e+51) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.6e+19: tmp = 1.0 elif y <= 2.55e+51: tmp = x / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.6e+19) tmp = 1.0; elseif (y <= 2.55e+51) 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 <= -2.6e+19) tmp = 1.0; elseif (y <= 2.55e+51) tmp = x / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.6e+19], 1.0, If[LessEqual[y, 2.55e+51], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{+51}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.6e19 or 2.55000000000000005e51 < y Initial program 100.0%
Taylor expanded in y around inf
Simplified78.8%
if -2.6e19 < y < 2.55000000000000005e51Initial program 100.0%
Taylor expanded in y around 0
/-lowering-/.f64N/A
--lowering--.f6474.1%
Simplified74.1%
(FPCore (x y) :precision binary64 (if (<= x -1.95e+78) -1.0 (if (<= x 4.1e+70) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.95e+78) {
tmp = -1.0;
} else if (x <= 4.1e+70) {
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 <= (-1.95d+78)) then
tmp = -1.0d0
else if (x <= 4.1d+70) 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 <= -1.95e+78) {
tmp = -1.0;
} else if (x <= 4.1e+70) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.95e+78: tmp = -1.0 elif x <= 4.1e+70: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.95e+78) tmp = -1.0; elseif (x <= 4.1e+70) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.95e+78) tmp = -1.0; elseif (x <= 4.1e+70) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.95e+78], -1.0, If[LessEqual[x, 4.1e+70], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+78}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+70}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -1.9500000000000002e78 or 4.1000000000000002e70 < x Initial program 100.0%
Taylor expanded in x around inf
Simplified80.2%
if -1.9500000000000002e78 < x < 4.1000000000000002e70Initial program 100.0%
Taylor expanded in y around inf
Simplified55.3%
(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%
Taylor expanded in x around inf
Simplified35.6%
(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 2024161
(FPCore (x y)
:name "Data.Colour.RGB:hslsv from colour-2.3.3, C"
:precision binary64
:alt
(! :herbie-platform default (- (/ x (- 2 (+ x y))) (/ y (- 2 (+ x y)))))
(/ (- x y) (- 2.0 (+ x y))))