
(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 6 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
(let* ((t_0 (- x (* x y))))
(if (<= x -1e-22)
t_0
(if (<= x -6.6e-58) y (if (<= x -5.8e-155) t_0 (* y (- 1.0 x)))))))
double code(double x, double y) {
double t_0 = x - (x * y);
double tmp;
if (x <= -1e-22) {
tmp = t_0;
} else if (x <= -6.6e-58) {
tmp = y;
} else if (x <= -5.8e-155) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x - (x * y)
if (x <= (-1d-22)) then
tmp = t_0
else if (x <= (-6.6d-58)) then
tmp = y
else if (x <= (-5.8d-155)) then
tmp = t_0
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x - (x * y);
double tmp;
if (x <= -1e-22) {
tmp = t_0;
} else if (x <= -6.6e-58) {
tmp = y;
} else if (x <= -5.8e-155) {
tmp = t_0;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): t_0 = x - (x * y) tmp = 0 if x <= -1e-22: tmp = t_0 elif x <= -6.6e-58: tmp = y elif x <= -5.8e-155: tmp = t_0 else: tmp = y * (1.0 - x) return tmp
function code(x, y) t_0 = Float64(x - Float64(x * y)) tmp = 0.0 if (x <= -1e-22) tmp = t_0; elseif (x <= -6.6e-58) tmp = y; elseif (x <= -5.8e-155) tmp = t_0; else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) t_0 = x - (x * y); tmp = 0.0; if (x <= -1e-22) tmp = t_0; elseif (x <= -6.6e-58) tmp = y; elseif (x <= -5.8e-155) tmp = t_0; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1e-22], t$95$0, If[LessEqual[x, -6.6e-58], y, If[LessEqual[x, -5.8e-155], t$95$0, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - x \cdot y\\
\mathbf{if}\;x \leq -1 \cdot 10^{-22}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -6.6 \cdot 10^{-58}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{-155}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -1e-22 or -6.60000000000000052e-58 < x < -5.80000000000000021e-155Initial program 100.0%
Taylor expanded in x around inf 86.3%
*-commutative86.3%
distribute-rgt-out--86.3%
*-lft-identity86.3%
Simplified86.3%
if -1e-22 < x < -6.60000000000000052e-58Initial program 100.0%
Taylor expanded in x around 0 83.8%
if -5.80000000000000021e-155 < x Initial program 100.0%
Taylor expanded in y around inf 70.5%
Final simplification76.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (- y)))) (if (<= y -1.0) t_0 (if (<= y 2.4e-52) x (if (<= y 1.1e+130) 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 <= 2.4e-52) {
tmp = x;
} else if (y <= 1.1e+130) {
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 <= 2.4d-52) then
tmp = x
else if (y <= 1.1d+130) 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 <= 2.4e-52) {
tmp = x;
} else if (y <= 1.1e+130) {
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 <= 2.4e-52: tmp = x elif y <= 1.1e+130: 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 <= 2.4e-52) tmp = x; elseif (y <= 1.1e+130) 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 <= 2.4e-52) tmp = x; elseif (y <= 1.1e+130) 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, 2.4e-52], x, If[LessEqual[y, 1.1e+130], 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 2.4 \cdot 10^{-52}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+130}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1 or 1.09999999999999997e130 < y Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in x around inf 53.7%
mul-1-neg53.7%
distribute-rgt-neg-out53.7%
Simplified53.7%
if -1 < y < 2.4000000000000002e-52Initial program 100.0%
Taylor expanded in y around 0 77.2%
if 2.4000000000000002e-52 < y < 1.09999999999999997e130Initial program 100.0%
Taylor expanded in x around 0 54.5%
Final simplification64.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x (- y)) (if (<= y 6.2e-54) x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * -y;
} else if (y <= 6.2e-54) {
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 <= (-1.0d0)) then
tmp = x * -y
else if (y <= 6.2d-54) 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 <= -1.0) {
tmp = x * -y;
} else if (y <= 6.2e-54) {
tmp = x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * -y elif y <= 6.2e-54: tmp = x else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * Float64(-y)); elseif (y <= 6.2e-54) 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 <= -1.0) tmp = x * -y; elseif (y <= 6.2e-54) tmp = x; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * (-y)), $MachinePrecision], If[LessEqual[y, 6.2e-54], x, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-54}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
Taylor expanded in y around inf 99.7%
Taylor expanded in x around inf 46.1%
mul-1-neg46.1%
distribute-rgt-neg-out46.1%
Simplified46.1%
if -1 < y < 6.20000000000000008e-54Initial program 100.0%
Taylor expanded in y around 0 77.2%
if 6.20000000000000008e-54 < y Initial program 100.0%
Taylor expanded in y around inf 93.0%
Final simplification74.7%
(FPCore (x y) :precision binary64 (if (<= x -5.2e-22) x y))
double code(double x, double y) {
double tmp;
if (x <= -5.2e-22) {
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 <= (-5.2d-22)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5.2e-22) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.2e-22: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -5.2e-22) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.2e-22) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.2e-22], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{-22}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -5.2e-22Initial program 100.0%
Taylor expanded in y around 0 52.6%
if -5.2e-22 < x Initial program 100.0%
Taylor expanded in x around 0 49.9%
Final simplification50.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 37.4%
Final simplification37.4%
herbie shell --seed 2023274
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))