
(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 8 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 x (- 1.0 y) y))
double code(double x, double y) {
return fma(x, (1.0 - y), y);
}
function code(x, y) return fma(x, Float64(1.0 - y), y) end
code[x_, y_] := N[(x * N[(1.0 - y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 1 - y, y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
*-commutative100.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 (* y (- x))))
(if (<= x -2.4e+252)
t_0
(if (<= x -5.2e+228)
x
(if (<= x -9.5e+196)
t_0
(if (<= x -1.5e-93) x (if (<= x 1.0) y t_0)))))))
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (x <= -2.4e+252) {
tmp = t_0;
} else if (x <= -5.2e+228) {
tmp = x;
} else if (x <= -9.5e+196) {
tmp = t_0;
} else if (x <= -1.5e-93) {
tmp = x;
} else if (x <= 1.0) {
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 = y * -x
if (x <= (-2.4d+252)) then
tmp = t_0
else if (x <= (-5.2d+228)) then
tmp = x
else if (x <= (-9.5d+196)) then
tmp = t_0
else if (x <= (-1.5d-93)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (x <= -2.4e+252) {
tmp = t_0;
} else if (x <= -5.2e+228) {
tmp = x;
} else if (x <= -9.5e+196) {
tmp = t_0;
} else if (x <= -1.5e-93) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * -x tmp = 0 if x <= -2.4e+252: tmp = t_0 elif x <= -5.2e+228: tmp = x elif x <= -9.5e+196: tmp = t_0 elif x <= -1.5e-93: tmp = x elif x <= 1.0: tmp = y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (x <= -2.4e+252) tmp = t_0; elseif (x <= -5.2e+228) tmp = x; elseif (x <= -9.5e+196) tmp = t_0; elseif (x <= -1.5e-93) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * -x; tmp = 0.0; if (x <= -2.4e+252) tmp = t_0; elseif (x <= -5.2e+228) tmp = x; elseif (x <= -9.5e+196) tmp = t_0; elseif (x <= -1.5e-93) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[x, -2.4e+252], t$95$0, If[LessEqual[x, -5.2e+228], x, If[LessEqual[x, -9.5e+196], t$95$0, If[LessEqual[x, -1.5e-93], x, If[LessEqual[x, 1.0], y, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{+252}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -5.2 \cdot 10^{+228}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{+196}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.5 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.3999999999999999e252 or -5.20000000000000015e228 < x < -9.5000000000000004e196 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.8%
Taylor expanded in y around inf 43.3%
associate-*r*43.3%
neg-mul-143.3%
*-commutative43.3%
Simplified43.3%
if -2.3999999999999999e252 < x < -5.20000000000000015e228 or -9.5000000000000004e196 < x < -1.5000000000000001e-93Initial program 100.0%
Taylor expanded in y around 0 50.6%
if -1.5000000000000001e-93 < x < 1Initial program 100.0%
Taylor expanded in x around 0 74.9%
(FPCore (x y) :precision binary64 (if (<= x -6.8e-96) (* x (- 1.0 y)) (if (<= x 1.0) y (* y (- x)))))
double code(double x, double y) {
double tmp;
if (x <= -6.8e-96) {
tmp = x * (1.0 - y);
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-6.8d-96)) then
tmp = x * (1.0d0 - y)
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.8e-96) {
tmp = x * (1.0 - y);
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.8e-96: tmp = x * (1.0 - y) elif x <= 1.0: tmp = y else: tmp = y * -x return tmp
function code(x, y) tmp = 0.0 if (x <= -6.8e-96) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 1.0) tmp = y; else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.8e-96) tmp = x * (1.0 - y); elseif (x <= 1.0) tmp = y; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.8e-96], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(y * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-96}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -6.8000000000000002e-96Initial program 100.0%
Taylor expanded in x around inf 92.0%
if -6.8000000000000002e-96 < x < 1Initial program 100.0%
Taylor expanded in x around 0 74.9%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.4%
Taylor expanded in y around inf 34.6%
associate-*r*34.6%
neg-mul-134.6%
*-commutative34.6%
Simplified34.6%
(FPCore (x y) :precision binary64 (if (<= x -1.6e-93) (- x (* x y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -1.6e-93) {
tmp = x - (x * y);
} 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 (x <= (-1.6d-93)) then
tmp = x - (x * y)
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.6e-93) {
tmp = x - (x * y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.6e-93: tmp = x - (x * y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.6e-93) tmp = Float64(x - Float64(x * y)); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.6e-93) tmp = x - (x * y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.6e-93], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-93}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1.5999999999999999e-93Initial program 100.0%
Taylor expanded in x around inf 92.0%
sub-neg92.0%
distribute-rgt-in92.0%
*-un-lft-identity92.0%
Applied egg-rr92.0%
if -1.5999999999999999e-93 < x Initial program 100.0%
Taylor expanded in y around inf 60.4%
Final simplification71.9%
(FPCore (x y) :precision binary64 (if (<= x -1.6e-93) (* x (- 1.0 y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -1.6e-93) {
tmp = x * (1.0 - y);
} 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 (x <= (-1.6d-93)) then
tmp = x * (1.0d0 - y)
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.6e-93) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.6e-93: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.6e-93) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.6e-93) tmp = x * (1.0 - y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.6e-93], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-93}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1.5999999999999999e-93Initial program 100.0%
Taylor expanded in x around inf 92.0%
if -1.5999999999999999e-93 < x Initial program 100.0%
Taylor expanded in y around inf 60.4%
(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}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.55e-93) x y))
double code(double x, double y) {
double tmp;
if (x <= -1.55e-93) {
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 (x <= (-1.55d-93)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.55e-93) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.55e-93: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.55e-93) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.55e-93) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.55e-93], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.55e-93Initial program 100.0%
Taylor expanded in y around 0 46.7%
if -1.55e-93 < x Initial program 100.0%
Taylor expanded in x around 0 46.2%
(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 43.2%
herbie shell --seed 2024106
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))