
(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 (- (+ 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%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -2.2e-46)
x
(if (<= x -1.9e-149)
y
(if (<= x -1.56e-190) x (if (<= x 1.0) y (* x (- y)))))))
double code(double x, double y) {
double tmp;
if (x <= -2.2e-46) {
tmp = x;
} else if (x <= -1.9e-149) {
tmp = y;
} else if (x <= -1.56e-190) {
tmp = x;
} 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) :: tmp
if (x <= (-2.2d-46)) then
tmp = x
else if (x <= (-1.9d-149)) then
tmp = y
else if (x <= (-1.56d-190)) then
tmp = x
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 tmp;
if (x <= -2.2e-46) {
tmp = x;
} else if (x <= -1.9e-149) {
tmp = y;
} else if (x <= -1.56e-190) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.2e-46: tmp = x elif x <= -1.9e-149: tmp = y elif x <= -1.56e-190: tmp = x elif x <= 1.0: tmp = y else: tmp = x * -y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.2e-46) tmp = x; elseif (x <= -1.9e-149) tmp = y; elseif (x <= -1.56e-190) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.2e-46) tmp = x; elseif (x <= -1.9e-149) tmp = y; elseif (x <= -1.56e-190) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.2e-46], x, If[LessEqual[x, -1.9e-149], y, If[LessEqual[x, -1.56e-190], x, If[LessEqual[x, 1.0], y, N[(x * (-y)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{-46}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{-149}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.56 \cdot 10^{-190}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -2.2000000000000001e-46 or -1.90000000000000003e-149 < x < -1.56e-190Initial program 100.0%
Taylor expanded in y around 0 51.7%
if -2.2000000000000001e-46 < x < -1.90000000000000003e-149 or -1.56e-190 < x < 1Initial program 100.0%
Taylor expanded in x around 0 69.0%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 48.4%
mul-1-neg48.4%
distribute-lft-neg-out48.4%
*-commutative48.4%
Simplified48.4%
Final simplification57.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -7e-77)
t_0
(if (<= x -3.6e-146)
y
(if (<= x -1.56e-190) 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 <= -7e-77) {
tmp = t_0;
} else if (x <= -3.6e-146) {
tmp = y;
} else if (x <= -1.56e-190) {
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 <= (-7d-77)) then
tmp = t_0
else if (x <= (-3.6d-146)) then
tmp = y
else if (x <= (-1.56d-190)) 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 <= -7e-77) {
tmp = t_0;
} else if (x <= -3.6e-146) {
tmp = y;
} else if (x <= -1.56e-190) {
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 <= -7e-77: tmp = t_0 elif x <= -3.6e-146: tmp = y elif x <= -1.56e-190: 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 <= -7e-77) tmp = t_0; elseif (x <= -3.6e-146) tmp = y; elseif (x <= -1.56e-190) 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 <= -7e-77) tmp = t_0; elseif (x <= -3.6e-146) tmp = y; elseif (x <= -1.56e-190) 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, -7e-77], t$95$0, If[LessEqual[x, -3.6e-146], y, If[LessEqual[x, -1.56e-190], 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 -7 \cdot 10^{-77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -3.6 \cdot 10^{-146}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.56 \cdot 10^{-190}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -7.00000000000000026e-77 or -3.59999999999999978e-146 < x < -1.56e-190Initial program 100.0%
Taylor expanded in x around inf 82.5%
if -7.00000000000000026e-77 < x < -3.59999999999999978e-146 or -1.56e-190 < x < 1Initial program 100.0%
Taylor expanded in x around 0 70.5%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 48.4%
mul-1-neg48.4%
distribute-lft-neg-out48.4%
*-commutative48.4%
Simplified48.4%
Final simplification68.5%
(FPCore (x y) :precision binary64 (if (<= y 4.4e-98) (* x (- 1.0 y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 4.4e-98) {
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 <= 4.4d-98) 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 <= 4.4e-98) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.4e-98: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.4e-98) 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 <= 4.4e-98) tmp = x * (1.0 - y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.4e-98], 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 4.4 \cdot 10^{-98}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 4.39999999999999993e-98Initial program 100.0%
Taylor expanded in x around inf 73.2%
if 4.39999999999999993e-98 < y Initial program 100.0%
Taylor expanded in y around inf 80.3%
Final simplification75.3%
(FPCore (x y) :precision binary64 (if (<= y 4.3e-98) (* x (- 1.0 y)) (- y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 4.3e-98) {
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 <= 4.3d-98) 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 <= 4.3e-98) {
tmp = x * (1.0 - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.3e-98: tmp = x * (1.0 - y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.3e-98) 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 <= 4.3e-98) tmp = x * (1.0 - y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.3e-98], 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 4.3 \cdot 10^{-98}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < 4.29999999999999988e-98Initial program 100.0%
Taylor expanded in x around inf 73.2%
if 4.29999999999999988e-98 < y Initial program 100.0%
Taylor expanded in y around inf 80.3%
sub-neg80.3%
distribute-rgt-in80.4%
*-un-lft-identity80.4%
Applied egg-rr80.4%
distribute-lft-neg-out80.4%
unsub-neg80.4%
*-commutative80.4%
Applied egg-rr80.4%
Final simplification75.3%
(FPCore (x y) :precision binary64 (if (<= y 4.4e-98) (- x (* x y)) (- y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 4.4e-98) {
tmp = x - (x * 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 <= 4.4d-98) then
tmp = x - (x * y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.4e-98) {
tmp = x - (x * y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.4e-98: tmp = x - (x * y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.4e-98) tmp = Float64(x - Float64(x * y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.4e-98) tmp = x - (x * y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.4e-98], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.4 \cdot 10^{-98}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < 4.39999999999999993e-98Initial program 100.0%
Taylor expanded in x around inf 73.2%
sub-neg73.2%
distribute-rgt-in73.2%
*-un-lft-identity73.2%
Applied egg-rr73.2%
if 4.39999999999999993e-98 < y Initial program 100.0%
Taylor expanded in y around inf 80.3%
sub-neg80.3%
distribute-rgt-in80.4%
*-un-lft-identity80.4%
Applied egg-rr80.4%
distribute-lft-neg-out80.4%
unsub-neg80.4%
*-commutative80.4%
Applied egg-rr80.4%
Final simplification75.3%
(FPCore (x y) :precision binary64 (if (<= y 1.42e-101) x y))
double code(double x, double y) {
double tmp;
if (y <= 1.42e-101) {
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 <= 1.42d-101) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.42e-101) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.42e-101: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.42e-101) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.42e-101) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.42e-101], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.42 \cdot 10^{-101}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.4200000000000001e-101Initial program 100.0%
Taylor expanded in y around 0 56.7%
if 1.4200000000000001e-101 < y Initial program 100.0%
Taylor expanded in x around 0 40.6%
Final simplification51.9%
(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 44.3%
Final simplification44.3%
herbie shell --seed 2023318
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))