
(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 -4.5e+19) (not (<= y 3.05e+50))) (+ 1.0 (/ (* x -2.0) y)) (/ x (- 2.0 x))))
double code(double x, double y) {
double tmp;
if ((y <= -4.5e+19) || !(y <= 3.05e+50)) {
tmp = 1.0 + ((x * -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 ((y <= (-4.5d+19)) .or. (.not. (y <= 3.05d+50))) then
tmp = 1.0d0 + ((x * (-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 ((y <= -4.5e+19) || !(y <= 3.05e+50)) {
tmp = 1.0 + ((x * -2.0) / y);
} else {
tmp = x / (2.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.5e+19) or not (y <= 3.05e+50): tmp = 1.0 + ((x * -2.0) / y) else: tmp = x / (2.0 - x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.5e+19) || !(y <= 3.05e+50)) tmp = Float64(1.0 + Float64(Float64(x * -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 ((y <= -4.5e+19) || ~((y <= 3.05e+50))) tmp = 1.0 + ((x * -2.0) / y); else tmp = x / (2.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.5e+19], N[Not[LessEqual[y, 3.05e+50]], $MachinePrecision]], N[(1.0 + N[(N[(x * -2.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+19} \lor \neg \left(y \leq 3.05 \cdot 10^{+50}\right):\\
\;\;\;\;1 + \frac{x \cdot -2}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2 - x}\\
\end{array}
\end{array}
if y < -4.5e19 or 3.05000000000000013e50 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 81.8%
associate--l+81.8%
+-commutative81.8%
mul-1-neg81.8%
unsub-neg81.8%
associate-*r/81.8%
metadata-eval81.8%
Simplified81.8%
Taylor expanded in x around inf 81.8%
associate-*r/81.8%
*-commutative81.8%
Simplified81.8%
if -4.5e19 < y < 3.05000000000000013e50Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
+-commutative99.9%
associate-+l+99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 76.6%
mul-1-neg76.6%
sub-neg76.6%
metadata-eval76.6%
Simplified76.6%
unpow-176.6%
distribute-neg-frac76.6%
associate-/r/76.5%
+-commutative76.5%
distribute-neg-in76.5%
metadata-eval76.5%
Applied egg-rr76.5%
associate-*l/76.7%
*-lft-identity76.7%
unsub-neg76.7%
Simplified76.7%
Final simplification79.0%
(FPCore (x y) :precision binary64 (if (<= y -2.75e+19) 1.0 (if (<= y 8.2e+52) (+ -1.0 (/ -2.0 x)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.75e+19) {
tmp = 1.0;
} else if (y <= 8.2e+52) {
tmp = -1.0 + (-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.75d+19)) then
tmp = 1.0d0
else if (y <= 8.2d+52) then
tmp = (-1.0d0) + ((-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.75e+19) {
tmp = 1.0;
} else if (y <= 8.2e+52) {
tmp = -1.0 + (-2.0 / x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.75e+19: tmp = 1.0 elif y <= 8.2e+52: tmp = -1.0 + (-2.0 / x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.75e+19) tmp = 1.0; elseif (y <= 8.2e+52) tmp = Float64(-1.0 + Float64(-2.0 / x)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.75e+19) tmp = 1.0; elseif (y <= 8.2e+52) tmp = -1.0 + (-2.0 / x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.75e+19], 1.0, If[LessEqual[y, 8.2e+52], N[(-1.0 + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.75 \cdot 10^{+19}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+52}:\\
\;\;\;\;-1 + \frac{-2}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.75e19 or 8.1999999999999999e52 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 79.8%
if -2.75e19 < y < 8.1999999999999999e52Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 76.7%
associate-*r/76.7%
mul-1-neg76.7%
sub-neg76.7%
metadata-eval76.7%
Simplified76.7%
Taylor expanded in x around inf 57.4%
distribute-neg-in57.4%
metadata-eval57.4%
associate-*r/57.4%
metadata-eval57.4%
distribute-neg-frac57.4%
metadata-eval57.4%
Simplified57.4%
Final simplification67.5%
(FPCore (x y) :precision binary64 (if (<= y -2.5e+19) 1.0 (if (<= y 2e+52) (/ x (- 2.0 x)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.5e+19) {
tmp = 1.0;
} else if (y <= 2e+52) {
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.5d+19)) then
tmp = 1.0d0
else if (y <= 2d+52) 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.5e+19) {
tmp = 1.0;
} else if (y <= 2e+52) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e+19: tmp = 1.0 elif y <= 2e+52: tmp = x / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5e+19) tmp = 1.0; elseif (y <= 2e+52) 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.5e+19) tmp = 1.0; elseif (y <= 2e+52) tmp = x / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5e+19], 1.0, If[LessEqual[y, 2e+52], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+19}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+52}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.5e19 or 2e52 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 79.8%
if -2.5e19 < y < 2e52Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
+-commutative99.9%
associate-+l+99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 76.6%
mul-1-neg76.6%
sub-neg76.6%
metadata-eval76.6%
Simplified76.6%
unpow-176.6%
distribute-neg-frac76.6%
associate-/r/76.5%
+-commutative76.5%
distribute-neg-in76.5%
metadata-eval76.5%
Applied egg-rr76.5%
associate-*l/76.7%
*-lft-identity76.7%
unsub-neg76.7%
Simplified76.7%
Final simplification78.1%
(FPCore (x y) :precision binary64 (if (<= y -2e+19) 1.0 (if (<= y 4e+50) -1.0 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2e+19) {
tmp = 1.0;
} else if (y <= 4e+50) {
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+19)) then
tmp = 1.0d0
else if (y <= 4d+50) 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+19) {
tmp = 1.0;
} else if (y <= 4e+50) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e+19: tmp = 1.0 elif y <= 4e+50: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2e+19) tmp = 1.0; elseif (y <= 4e+50) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e+19) tmp = 1.0; elseif (y <= 4e+50) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e+19], 1.0, If[LessEqual[y, 4e+50], -1.0, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+19}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+50}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2e19 or 4.0000000000000003e50 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 79.8%
if -2e19 < y < 4.0000000000000003e50Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.0%
+-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 57.2%
Final simplification67.4%
(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%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
distribute-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
+-commutative100.0%
sub-neg100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
metadata-eval100.0%
/-rgt-identity100.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 2023302
(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))))