
(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 (- (+ 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
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -1.75e-40)
t_0
(if (<= x -1.1e-73)
y
(if (<= x -1.16e-147) 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 <= -1.75e-40) {
tmp = t_0;
} else if (x <= -1.1e-73) {
tmp = y;
} else if (x <= -1.16e-147) {
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 <= (-1.75d-40)) then
tmp = t_0
else if (x <= (-1.1d-73)) then
tmp = y
else if (x <= (-1.16d-147)) 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 <= -1.75e-40) {
tmp = t_0;
} else if (x <= -1.1e-73) {
tmp = y;
} else if (x <= -1.16e-147) {
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 <= -1.75e-40: tmp = t_0 elif x <= -1.1e-73: tmp = y elif x <= -1.16e-147: 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 <= -1.75e-40) tmp = t_0; elseif (x <= -1.1e-73) tmp = y; elseif (x <= -1.16e-147) 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 <= -1.75e-40) tmp = t_0; elseif (x <= -1.1e-73) tmp = y; elseif (x <= -1.16e-147) 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, -1.75e-40], t$95$0, If[LessEqual[x, -1.1e-73], y, If[LessEqual[x, -1.16e-147], 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 -1.75 \cdot 10^{-40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.1 \cdot 10^{-73}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.16 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -1.7500000000000001e-40 or -1.1e-73 < x < -1.1599999999999999e-147Initial program 100.0%
Taylor expanded in x around inf 83.0%
if -1.7500000000000001e-40 < x < -1.1e-73 or -1.1599999999999999e-147 < x < 1Initial program 100.0%
Taylor expanded in x around 0 80.7%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 48.0%
mul-1-neg48.0%
distribute-lft-neg-out48.0%
*-commutative48.0%
Simplified48.0%
Final simplification73.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= y -1.0)
t_0
(if (<= y 3.5e-128)
x
(if (<= y 2.45e+101) y (if (<= y 1.42e+206) t_0 y))))))
double code(double x, double y) {
double t_0 = x * -y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.5e-128) {
tmp = x;
} else if (y <= 2.45e+101) {
tmp = y;
} else if (y <= 1.42e+206) {
tmp = t_0;
} else {
tmp = 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 * -y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 3.5d-128) then
tmp = x
else if (y <= 2.45d+101) then
tmp = y
else if (y <= 1.42d+206) then
tmp = t_0
else
tmp = y
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 <= 3.5e-128) {
tmp = x;
} else if (y <= 2.45e+101) {
tmp = y;
} else if (y <= 1.42e+206) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): t_0 = x * -y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 3.5e-128: tmp = x elif y <= 2.45e+101: tmp = y elif y <= 1.42e+206: tmp = t_0 else: tmp = y return tmp
function code(x, y) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 3.5e-128) tmp = x; elseif (y <= 2.45e+101) tmp = y; elseif (y <= 1.42e+206) tmp = t_0; else tmp = y; 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 <= 3.5e-128) tmp = x; elseif (y <= 2.45e+101) tmp = y; elseif (y <= 1.42e+206) tmp = t_0; else tmp = y; 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, 3.5e-128], x, If[LessEqual[y, 2.45e+101], y, If[LessEqual[y, 1.42e+206], t$95$0, y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-128}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{+101}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.42 \cdot 10^{+206}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 2.44999999999999991e101 < y < 1.42000000000000005e206Initial program 100.0%
Taylor expanded in x around inf 59.3%
Taylor expanded in y around inf 58.5%
mul-1-neg58.5%
distribute-lft-neg-out58.5%
*-commutative58.5%
Simplified58.5%
if -1 < y < 3.5e-128Initial program 100.0%
Taylor expanded in y around 0 82.4%
if 3.5e-128 < y < 2.44999999999999991e101 or 1.42000000000000005e206 < y Initial program 100.0%
Taylor expanded in x around 0 58.5%
Final simplification67.2%
(FPCore (x y) :precision binary64 (if (<= y 2.9e-128) (* x (- 1.0 y)) (- y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 2.9e-128) {
tmp = x * (1.0 - y);
} 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 <= 2.9d-128) then
tmp = x * (1.0d0 - y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.9e-128) {
tmp = x * (1.0 - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.9e-128: tmp = x * (1.0 - y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.9e-128) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.9e-128) tmp = x * (1.0 - y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.9e-128], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-128}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < 2.9e-128Initial program 100.0%
Taylor expanded in x around inf 70.7%
if 2.9e-128 < y Initial program 100.0%
Taylor expanded in y around inf 88.5%
sub-neg88.5%
distribute-rgt-in88.5%
*-un-lft-identity88.5%
Applied egg-rr88.5%
distribute-lft-neg-out88.5%
unsub-neg88.5%
Applied egg-rr88.5%
(FPCore (x y) :precision binary64 (if (<= y 8.4e-129) (* x (- 1.0 y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 8.4e-129) {
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 (y <= 8.4d-129) 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 (y <= 8.4e-129) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.4e-129: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 8.4e-129) 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 (y <= 8.4e-129) tmp = x * (1.0 - y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.4e-129], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.4 \cdot 10^{-129}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 8.4e-129Initial program 100.0%
Taylor expanded in x around inf 70.7%
if 8.4e-129 < y Initial program 100.0%
Taylor expanded in y around inf 88.5%
(FPCore (x y) :precision binary64 (if (<= y 3.5e-128) x y))
double code(double x, double y) {
double tmp;
if (y <= 3.5e-128) {
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 <= 3.5d-128) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.5e-128) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.5e-128: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 3.5e-128) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.5e-128) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.5e-128], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.5 \cdot 10^{-128}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 3.5e-128Initial program 100.0%
Taylor expanded in y around 0 49.6%
if 3.5e-128 < y Initial program 100.0%
Taylor expanded in x around 0 48.7%
(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 35.4%
herbie shell --seed 2024085
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))