
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
(FPCore (x y) :precision binary64 (fma y (- 1.0 x) x))
double code(double x, double y) {
return fma(y, (1.0 - x), x);
}
function code(x, y) return fma(y, Float64(1.0 - x), x) end
code[x_, y_] := N[(y * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 1 - x, x\right)
\end{array}
Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
*-lft-identity100.0%
metadata-eval100.0%
distribute-rgt-out--100.0%
fma-define100.0%
metadata-eval100.0%
Simplified100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= y -1.0)
t_0
(if (<= y 5.1e-166)
x
(if (<= y 7.6e-116)
y
(if (<= y 1.1e-73) x (if (<= y 7e+249) y t_0)))))))
double code(double x, double y) {
double t_0 = x * -y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.1e-166) {
tmp = x;
} else if (y <= 7.6e-116) {
tmp = y;
} else if (y <= 1.1e-73) {
tmp = x;
} else if (y <= 7e+249) {
tmp = 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 * -y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 5.1d-166) then
tmp = x
else if (y <= 7.6d-116) then
tmp = y
else if (y <= 1.1d-73) then
tmp = x
else if (y <= 7d+249) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * -y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.1e-166) {
tmp = x;
} else if (y <= 7.6e-116) {
tmp = y;
} else if (y <= 1.1e-73) {
tmp = x;
} else if (y <= 7e+249) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * -y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 5.1e-166: tmp = x elif y <= 7.6e-116: tmp = y elif y <= 1.1e-73: tmp = x elif y <= 7e+249: tmp = y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 5.1e-166) tmp = x; elseif (y <= 7.6e-116) tmp = y; elseif (y <= 1.1e-73) tmp = x; elseif (y <= 7e+249) tmp = y; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * -y; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 5.1e-166) tmp = x; elseif (y <= 7.6e-116) tmp = y; elseif (y <= 1.1e-73) tmp = x; elseif (y <= 7e+249) tmp = y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 5.1e-166], x, If[LessEqual[y, 7.6e-116], y, If[LessEqual[y, 1.1e-73], x, If[LessEqual[y, 7e+249], y, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{-166}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{-116}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-73}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+249}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 7.00000000000000024e249 < y Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in x around inf 53.0%
mul-1-neg53.0%
*-commutative53.0%
distribute-rgt-neg-in53.0%
Simplified53.0%
if -1 < y < 5.1000000000000002e-166 or 7.6000000000000003e-116 < y < 1.1e-73Initial program 100.0%
Taylor expanded in y around 0 80.2%
if 5.1000000000000002e-166 < y < 7.6000000000000003e-116 or 1.1e-73 < y < 7.00000000000000024e249Initial program 100.0%
Taylor expanded in x around 0 49.5%
Final simplification63.1%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -4.4e-63)
t_0
(if (<= x -1.35e-117)
y
(if (<= x -9e-176) t_0 (if (<= x 1.0) y (* x (- y))))))))
double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -4.4e-63) {
tmp = t_0;
} else if (x <= -1.35e-117) {
tmp = y;
} else if (x <= -9e-176) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * -y;
}
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 * (1.0d0 - y)
if (x <= (-4.4d-63)) then
tmp = t_0
else if (x <= (-1.35d-117)) then
tmp = y
else if (x <= (-9d-176)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * -y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -4.4e-63) {
tmp = t_0;
} else if (x <= -1.35e-117) {
tmp = y;
} else if (x <= -9e-176) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y): t_0 = x * (1.0 - y) tmp = 0 if x <= -4.4e-63: tmp = t_0 elif x <= -1.35e-117: tmp = y elif x <= -9e-176: tmp = t_0 elif x <= 1.0: tmp = y else: tmp = x * -y return tmp
function code(x, y) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -4.4e-63) tmp = t_0; elseif (x <= -1.35e-117) tmp = y; elseif (x <= -9e-176) tmp = t_0; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) t_0 = x * (1.0 - y); tmp = 0.0; if (x <= -4.4e-63) tmp = t_0; elseif (x <= -1.35e-117) tmp = y; elseif (x <= -9e-176) tmp = t_0; elseif (x <= 1.0) tmp = y; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4.4e-63], t$95$0, If[LessEqual[x, -1.35e-117], y, If[LessEqual[x, -9e-176], t$95$0, If[LessEqual[x, 1.0], y, N[(x * (-y)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -4.4 \cdot 10^{-63}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.35 \cdot 10^{-117}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -9 \cdot 10^{-176}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -4.3999999999999999e-63 or -1.35000000000000001e-117 < x < -9e-176Initial program 100.0%
Taylor expanded in x around inf 87.2%
if -4.3999999999999999e-63 < x < -1.35000000000000001e-117 or -9e-176 < x < 1Initial program 100.0%
Taylor expanded in x around 0 75.7%
if 1 < x Initial program 99.9%
Taylor expanded in y around inf 48.0%
Taylor expanded in x around inf 45.6%
mul-1-neg45.6%
*-commutative45.6%
distribute-rgt-neg-in45.6%
Simplified45.6%
Final simplification73.3%
(FPCore (x y) :precision binary64 (if (<= y 5.1e-166) (* x (- 1.0 y)) (if (<= y 7.6e-116) y (if (<= y 3.6e-74) x (* y (- 1.0 x))))))
double code(double x, double y) {
double tmp;
if (y <= 5.1e-166) {
tmp = x * (1.0 - y);
} else if (y <= 7.6e-116) {
tmp = y;
} else if (y <= 3.6e-74) {
tmp = x;
} else {
tmp = y * (1.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 <= 5.1d-166) then
tmp = x * (1.0d0 - y)
else if (y <= 7.6d-116) then
tmp = y
else if (y <= 3.6d-74) then
tmp = x
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 5.1e-166) {
tmp = x * (1.0 - y);
} else if (y <= 7.6e-116) {
tmp = y;
} else if (y <= 3.6e-74) {
tmp = x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.1e-166: tmp = x * (1.0 - y) elif y <= 7.6e-116: tmp = y elif y <= 3.6e-74: tmp = x else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 5.1e-166) tmp = Float64(x * Float64(1.0 - y)); elseif (y <= 7.6e-116) tmp = y; elseif (y <= 3.6e-74) tmp = x; else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5.1e-166) tmp = x * (1.0 - y); elseif (y <= 7.6e-116) tmp = y; elseif (y <= 3.6e-74) tmp = x; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.1e-166], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.6e-116], y, If[LessEqual[y, 3.6e-74], x, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.1 \cdot 10^{-166}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{-116}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-74}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 5.1000000000000002e-166Initial program 100.0%
Taylor expanded in x around inf 69.6%
if 5.1000000000000002e-166 < y < 7.6000000000000003e-116Initial program 100.0%
Taylor expanded in x around 0 55.7%
if 7.6000000000000003e-116 < y < 3.6000000000000002e-74Initial program 100.0%
Taylor expanded in y around 0 100.0%
if 3.6000000000000002e-74 < y Initial program 100.0%
Taylor expanded in y around inf 85.8%
(FPCore (x y) :precision binary64 (- (+ y x) (* y x)))
double code(double x, double y) {
return (y + x) - (y * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) - (y * x)
end function
public static double code(double x, double y) {
return (y + x) - (y * x);
}
def code(x, y): return (y + x) - (y * x)
function code(x, y) return Float64(Float64(y + x) - Float64(y * x)) end
function tmp = code(x, y) tmp = (y + x) - (y * x); end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) - y \cdot x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y 5.1e-166) x y))
double code(double x, double y) {
double tmp;
if (y <= 5.1e-166) {
tmp = x;
} else {
tmp = 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.1d-166) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 5.1e-166) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.1e-166: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 5.1e-166) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5.1e-166) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.1e-166], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.1 \cdot 10^{-166}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 5.1000000000000002e-166Initial program 100.0%
Taylor expanded in y around 0 49.9%
if 5.1000000000000002e-166 < y Initial program 100.0%
Taylor expanded in x around 0 45.5%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 40.3%
herbie shell --seed 2024097
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))