
(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 7 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 (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}
Initial program 100.0%
div-sub100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -3.2e+19)
-1.0
(if (<= x 1.22e-76)
(/ (- y) (- 2.0 y))
(if (<= x 8.6e-35) (/ x (- 2.0 x)) (if (<= x 6.5e+24) 1.0 -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -3.2e+19) {
tmp = -1.0;
} else if (x <= 1.22e-76) {
tmp = -y / (2.0 - y);
} else if (x <= 8.6e-35) {
tmp = x / (2.0 - x);
} else if (x <= 6.5e+24) {
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 <= (-3.2d+19)) then
tmp = -1.0d0
else if (x <= 1.22d-76) then
tmp = -y / (2.0d0 - y)
else if (x <= 8.6d-35) then
tmp = x / (2.0d0 - x)
else if (x <= 6.5d+24) 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 <= -3.2e+19) {
tmp = -1.0;
} else if (x <= 1.22e-76) {
tmp = -y / (2.0 - y);
} else if (x <= 8.6e-35) {
tmp = x / (2.0 - x);
} else if (x <= 6.5e+24) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.2e+19: tmp = -1.0 elif x <= 1.22e-76: tmp = -y / (2.0 - y) elif x <= 8.6e-35: tmp = x / (2.0 - x) elif x <= 6.5e+24: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.2e+19) tmp = -1.0; elseif (x <= 1.22e-76) tmp = Float64(Float64(-y) / Float64(2.0 - y)); elseif (x <= 8.6e-35) tmp = Float64(x / Float64(2.0 - x)); elseif (x <= 6.5e+24) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.2e+19) tmp = -1.0; elseif (x <= 1.22e-76) tmp = -y / (2.0 - y); elseif (x <= 8.6e-35) tmp = x / (2.0 - x); elseif (x <= 6.5e+24) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.2e+19], -1.0, If[LessEqual[x, 1.22e-76], N[((-y) / N[(2.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8.6e-35], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.5e+24], 1.0, -1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+19}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{-76}:\\
\;\;\;\;\frac{-y}{2 - y}\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{-35}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{+24}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -3.2e19 or 6.4999999999999996e24 < x Initial program 100.0%
Taylor expanded in x around inf 81.8%
if -3.2e19 < x < 1.22e-76Initial program 100.0%
Taylor expanded in x around 0 84.9%
mul-1-neg84.9%
distribute-neg-frac84.9%
Simplified84.9%
if 1.22e-76 < x < 8.6000000000000004e-35Initial program 100.0%
Taylor expanded in y around 0 89.7%
if 8.6000000000000004e-35 < x < 6.4999999999999996e24Initial program 100.0%
Taylor expanded in y around inf 80.1%
Final simplification83.5%
(FPCore (x y)
:precision binary64
(if (<= x -5e+21)
-1.0
(if (<= x 3e-87)
1.0
(if (<= x 1.3e-30) (* x 0.5) (if (<= x 5e+24) 1.0 -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -5e+21) {
tmp = -1.0;
} else if (x <= 3e-87) {
tmp = 1.0;
} else if (x <= 1.3e-30) {
tmp = x * 0.5;
} else if (x <= 5e+24) {
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 <= (-5d+21)) then
tmp = -1.0d0
else if (x <= 3d-87) then
tmp = 1.0d0
else if (x <= 1.3d-30) then
tmp = x * 0.5d0
else if (x <= 5d+24) 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 <= -5e+21) {
tmp = -1.0;
} else if (x <= 3e-87) {
tmp = 1.0;
} else if (x <= 1.3e-30) {
tmp = x * 0.5;
} else if (x <= 5e+24) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+21: tmp = -1.0 elif x <= 3e-87: tmp = 1.0 elif x <= 1.3e-30: tmp = x * 0.5 elif x <= 5e+24: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+21) tmp = -1.0; elseif (x <= 3e-87) tmp = 1.0; elseif (x <= 1.3e-30) tmp = Float64(x * 0.5); elseif (x <= 5e+24) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5e+21) tmp = -1.0; elseif (x <= 3e-87) tmp = 1.0; elseif (x <= 1.3e-30) tmp = x * 0.5; elseif (x <= 5e+24) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+21], -1.0, If[LessEqual[x, 3e-87], 1.0, If[LessEqual[x, 1.3e-30], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 5e+24], 1.0, -1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+21}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-87}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-30}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+24}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -5e21 or 5.00000000000000045e24 < x Initial program 100.0%
Taylor expanded in x around inf 81.8%
if -5e21 < x < 3.00000000000000016e-87 or 1.29999999999999993e-30 < x < 5.00000000000000045e24Initial program 100.0%
Taylor expanded in y around inf 62.1%
if 3.00000000000000016e-87 < x < 1.29999999999999993e-30Initial program 100.0%
Taylor expanded in y around 0 80.9%
Taylor expanded in x around 0 80.9%
*-commutative80.9%
Simplified80.9%
Final simplification71.1%
(FPCore (x y) :precision binary64 (if (<= y -7.2e+35) 1.0 (if (<= y 10000.0) (/ x (- 2.0 x)) (+ 1.0 (/ 2.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= -7.2e+35) {
tmp = 1.0;
} else if (y <= 10000.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 <= (-7.2d+35)) then
tmp = 1.0d0
else if (y <= 10000.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 <= -7.2e+35) {
tmp = 1.0;
} else if (y <= 10000.0) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0 + (2.0 / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.2e+35: tmp = 1.0 elif y <= 10000.0: tmp = x / (2.0 - x) else: tmp = 1.0 + (2.0 / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -7.2e+35) tmp = 1.0; elseif (y <= 10000.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 <= -7.2e+35) tmp = 1.0; elseif (y <= 10000.0) tmp = x / (2.0 - x); else tmp = 1.0 + (2.0 / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.2e+35], 1.0, If[LessEqual[y, 10000.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 -7.2 \cdot 10^{+35}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 10000:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{2}{y}\\
\end{array}
\end{array}
if y < -7.2000000000000001e35Initial program 100.0%
Taylor expanded in y around inf 77.2%
if -7.2000000000000001e35 < y < 1e4Initial program 100.0%
Taylor expanded in y around 0 71.5%
if 1e4 < y Initial program 100.0%
Taylor expanded in x around 0 76.2%
mul-1-neg76.2%
distribute-neg-frac76.2%
Simplified76.2%
Taylor expanded in y around inf 75.5%
associate-*r/75.5%
metadata-eval75.5%
Simplified75.5%
Final simplification74.0%
(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 -5e+23) -1.0 (if (<= x 1.95e+25) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (x <= -5e+23) {
tmp = -1.0;
} else if (x <= 1.95e+25) {
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 <= (-5d+23)) then
tmp = -1.0d0
else if (x <= 1.95d+25) 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 <= -5e+23) {
tmp = -1.0;
} else if (x <= 1.95e+25) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+23: tmp = -1.0 elif x <= 1.95e+25: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+23) tmp = -1.0; elseif (x <= 1.95e+25) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5e+23) tmp = -1.0; elseif (x <= 1.95e+25) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+23], -1.0, If[LessEqual[x, 1.95e+25], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+23}:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.95 \cdot 10^{+25}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -4.9999999999999999e23 or 1.9500000000000001e25 < x Initial program 100.0%
Taylor expanded in x around inf 81.8%
if -4.9999999999999999e23 < x < 1.9500000000000001e25Initial program 100.0%
Taylor expanded in y around inf 58.5%
Final simplification68.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%
Taylor expanded in x around inf 36.4%
Final simplification36.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 2023319
(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))))