
(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 (or (<= y -1.16e+39) (not (<= y 2.8e+67))) (/ (- y x) y) (/ x (- 2.0 x))))
double code(double x, double y) {
double tmp;
if ((y <= -1.16e+39) || !(y <= 2.8e+67)) {
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 <= (-1.16d+39)) .or. (.not. (y <= 2.8d+67))) 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 <= -1.16e+39) || !(y <= 2.8e+67)) {
tmp = (y - x) / y;
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.16e+39) or not (y <= 2.8e+67): tmp = (y - x) / y else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.16e+39) || !(y <= 2.8e+67)) tmp = Float64(Float64(y - 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 <= -1.16e+39) || ~((y <= 2.8e+67))) tmp = (y - x) / y; else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.16e+39], N[Not[LessEqual[y, 2.8e+67]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] / y), $MachinePrecision], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.16 \cdot 10^{+39} \lor \neg \left(y \leq 2.8 \cdot 10^{+67}\right):\\
\;\;\;\;\frac{y - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if y < -1.16000000000000003e39 or 2.7999999999999998e67 < y Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
clear-num100.0%
associate-/r/99.7%
+-commutative99.7%
associate-+l+99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 84.4%
associate-*l/84.7%
*-un-lft-identity84.7%
Applied egg-rr84.7%
if -1.16000000000000003e39 < y < 2.7999999999999998e67Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 76.6%
mul-1-neg76.6%
distribute-neg-frac276.6%
neg-sub076.6%
associate-+l-76.6%
neg-sub076.6%
+-commutative76.6%
unsub-neg76.6%
Simplified76.6%
Final simplification80.3%
(FPCore (x y) :precision binary64 (if (<= y -1.5e+39) 1.0 (if (<= y 1.36e+65) (/ x (- 2.0 x)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.5e+39) {
tmp = 1.0;
} else if (y <= 1.36e+65) {
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 <= (-1.5d+39)) then
tmp = 1.0d0
else if (y <= 1.36d+65) 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 <= -1.5e+39) {
tmp = 1.0;
} else if (y <= 1.36e+65) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.5e+39: tmp = 1.0 elif y <= 1.36e+65: tmp = x / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.5e+39) tmp = 1.0; elseif (y <= 1.36e+65) 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 <= -1.5e+39) tmp = 1.0; elseif (y <= 1.36e+65) tmp = x / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.5e+39], 1.0, If[LessEqual[y, 1.36e+65], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+39}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.36 \cdot 10^{+65}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.5e39 or 1.3600000000000001e65 < y Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 84.2%
if -1.5e39 < y < 1.3600000000000001e65Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 76.6%
mul-1-neg76.6%
distribute-neg-frac276.6%
neg-sub076.6%
associate-+l-76.6%
neg-sub076.6%
+-commutative76.6%
unsub-neg76.6%
Simplified76.6%
Final simplification80.1%
(FPCore (x y) :precision binary64 (if (<= y -9.5e+38) (+ 1.0 (/ (+ 2.0 (* x -2.0)) y)) (if (<= y 1.35e+65) (/ x (- 2.0 x)) (/ (- y x) y))))
double code(double x, double y) {
double tmp;
if (y <= -9.5e+38) {
tmp = 1.0 + ((2.0 + (x * -2.0)) / y);
} else if (y <= 1.35e+65) {
tmp = x / (2.0 - x);
} else {
tmp = (y - 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 <= (-9.5d+38)) then
tmp = 1.0d0 + ((2.0d0 + (x * (-2.0d0))) / y)
else if (y <= 1.35d+65) then
tmp = x / (2.0d0 - x)
else
tmp = (y - x) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -9.5e+38) {
tmp = 1.0 + ((2.0 + (x * -2.0)) / y);
} else if (y <= 1.35e+65) {
tmp = x / (2.0 - x);
} else {
tmp = (y - x) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9.5e+38: tmp = 1.0 + ((2.0 + (x * -2.0)) / y) elif y <= 1.35e+65: tmp = x / (2.0 - x) else: tmp = (y - x) / y return tmp
function code(x, y) tmp = 0.0 if (y <= -9.5e+38) tmp = Float64(1.0 + Float64(Float64(2.0 + Float64(x * -2.0)) / y)); elseif (y <= 1.35e+65) tmp = Float64(x / Float64(2.0 - x)); else tmp = Float64(Float64(y - x) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9.5e+38) tmp = 1.0 + ((2.0 + (x * -2.0)) / y); elseif (y <= 1.35e+65) tmp = x / (2.0 - x); else tmp = (y - x) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9.5e+38], N[(1.0 + N[(N[(2.0 + N[(x * -2.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.35e+65], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+38}:\\
\;\;\;\;1 + \frac{2 + x \cdot -2}{y}\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+65}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{y}\\
\end{array}
\end{array}
if y < -9.4999999999999995e38Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 78.7%
associate--l+78.7%
+-commutative78.7%
mul-1-neg78.7%
unsub-neg78.7%
associate-*r/78.7%
metadata-eval78.7%
div-sub78.7%
unsub-neg78.7%
mul-1-neg78.7%
div-sub78.7%
mul-1-neg78.7%
associate--l+78.7%
sub-neg78.7%
mul-1-neg78.7%
mul-1-neg78.7%
distribute-rgt-out78.7%
metadata-eval78.7%
Simplified78.7%
if -9.4999999999999995e38 < y < 1.35000000000000009e65Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 76.6%
mul-1-neg76.6%
distribute-neg-frac276.6%
neg-sub076.6%
associate-+l-76.6%
neg-sub076.6%
+-commutative76.6%
unsub-neg76.6%
Simplified76.6%
if 1.35000000000000009e65 < y Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
clear-num100.0%
associate-/r/99.7%
+-commutative99.7%
associate-+l+99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 90.3%
associate-*l/90.5%
*-un-lft-identity90.5%
Applied egg-rr90.5%
Final simplification80.3%
(FPCore (x y) :precision binary64 (if (<= y -2e+39) 1.0 (if (<= y 4.1e+42) -1.0 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2e+39) {
tmp = 1.0;
} else if (y <= 4.1e+42) {
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+39)) then
tmp = 1.0d0
else if (y <= 4.1d+42) 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+39) {
tmp = 1.0;
} else if (y <= 4.1e+42) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e+39: tmp = 1.0 elif y <= 4.1e+42: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2e+39) tmp = 1.0; elseif (y <= 4.1e+42) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e+39) tmp = 1.0; elseif (y <= 4.1e+42) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e+39], 1.0, If[LessEqual[y, 4.1e+42], -1.0, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+39}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+42}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.99999999999999988e39 or 4.1e42 < y Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 83.1%
if -1.99999999999999988e39 < y < 4.1e42Initial program 100.0%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 60.7%
Final simplification71.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%
remove-double-neg100.0%
+-commutative100.0%
distribute-neg-frac2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 40.4%
Final simplification40.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 2024059
(FPCore (x y)
:name "Data.Colour.RGB:hslsv from colour-2.3.3, C"
:precision binary64
:alt
(- (/ x (- 2.0 (+ x y))) (/ y (- 2.0 (+ x y))))
(/ (- x y) (- 2.0 (+ x y))))