
(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%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.0)
t_0
(if (<= y 1.8e-95)
x
(if (<= y 1.15e+157)
y
(if (or (<= y 1.6e+251) (not (<= y 9.5e+304))) t_0 y))))))
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.8e-95) {
tmp = x;
} else if (y <= 1.15e+157) {
tmp = y;
} else if ((y <= 1.6e+251) || !(y <= 9.5e+304)) {
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 = y * -x
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.8d-95) then
tmp = x
else if (y <= 1.15d+157) then
tmp = y
else if ((y <= 1.6d+251) .or. (.not. (y <= 9.5d+304))) then
tmp = t_0
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.8e-95) {
tmp = x;
} else if (y <= 1.15e+157) {
tmp = y;
} else if ((y <= 1.6e+251) || !(y <= 9.5e+304)) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): t_0 = y * -x tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.8e-95: tmp = x elif y <= 1.15e+157: tmp = y elif (y <= 1.6e+251) or not (y <= 9.5e+304): tmp = t_0 else: tmp = y return tmp
function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.8e-95) tmp = x; elseif (y <= 1.15e+157) tmp = y; elseif ((y <= 1.6e+251) || !(y <= 9.5e+304)) tmp = t_0; else tmp = y; end return tmp end
function tmp_2 = code(x, y) t_0 = y * -x; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 1.8e-95) tmp = x; elseif (y <= 1.15e+157) tmp = y; elseif ((y <= 1.6e+251) || ~((y <= 9.5e+304))) tmp = t_0; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.8e-95], x, If[LessEqual[y, 1.15e+157], y, If[Or[LessEqual[y, 1.6e+251], N[Not[LessEqual[y, 9.5e+304]], $MachinePrecision]], t$95$0, y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-95}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+157}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+251} \lor \neg \left(y \leq 9.5 \cdot 10^{+304}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 1.15000000000000002e157 < y < 1.5999999999999999e251 or 9.5000000000000004e304 < y Initial program 100.0%
Taylor expanded in x around inf 58.9%
Taylor expanded in y around inf 58.3%
mul-1-neg58.3%
distribute-rgt-neg-out58.3%
Simplified58.3%
if -1 < y < 1.8e-95Initial program 100.0%
Taylor expanded in y around 0 83.9%
if 1.8e-95 < y < 1.15000000000000002e157 or 1.5999999999999999e251 < y < 9.5000000000000004e304Initial program 100.0%
Taylor expanded in x around 0 52.6%
Final simplification67.8%
(FPCore (x y) :precision binary64 (if (<= x -5.2e-113) (* x (- 1.0 y)) (if (<= x 1.0) y (* y (- x)))))
double code(double x, double y) {
double tmp;
if (x <= -5.2e-113) {
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 <= (-5.2d-113)) 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 <= -5.2e-113) {
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 <= -5.2e-113: 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 <= -5.2e-113) 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 <= -5.2e-113) 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, -5.2e-113], 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 -5.2 \cdot 10^{-113}:\\
\;\;\;\;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 < -5.1999999999999998e-113Initial program 100.0%
Taylor expanded in x around inf 85.4%
if -5.1999999999999998e-113 < x < 1Initial program 100.0%
Taylor expanded in x around 0 76.9%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.6%
Taylor expanded in y around inf 53.0%
mul-1-neg53.0%
distribute-rgt-neg-out53.0%
Simplified53.0%
Final simplification74.0%
(FPCore (x y) :precision binary64 (if (<= x -3.8e-113) (- x (* x y)) (if (<= x 1.0) y (* y (- x)))))
double code(double x, double y) {
double tmp;
if (x <= -3.8e-113) {
tmp = x - (x * 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 <= (-3.8d-113)) then
tmp = x - (x * 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 <= -3.8e-113) {
tmp = x - (x * y);
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.8e-113: tmp = x - (x * y) elif x <= 1.0: tmp = y else: tmp = y * -x return tmp
function code(x, y) tmp = 0.0 if (x <= -3.8e-113) tmp = Float64(x - Float64(x * 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 <= -3.8e-113) tmp = x - (x * y); elseif (x <= 1.0) tmp = y; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.8e-113], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(y * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-113}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -3.79999999999999983e-113Initial program 100.0%
Taylor expanded in x around inf 85.4%
*-commutative85.4%
distribute-rgt-out--85.4%
*-lft-identity85.4%
Simplified85.4%
if -3.79999999999999983e-113 < x < 1Initial program 100.0%
Taylor expanded in x around 0 76.9%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.6%
Taylor expanded in y around inf 53.0%
mul-1-neg53.0%
distribute-rgt-neg-out53.0%
Simplified53.0%
Final simplification74.0%
(FPCore (x y) :precision binary64 (if (<= x -4.9e-113) (- x (* x y)) (- y (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -4.9e-113) {
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 (x <= (-4.9d-113)) 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 (x <= -4.9e-113) {
tmp = x - (x * y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.9e-113: tmp = x - (x * y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (x <= -4.9e-113) 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 (x <= -4.9e-113) tmp = x - (x * y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.9e-113], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{-113}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if x < -4.9000000000000003e-113Initial program 100.0%
Taylor expanded in x around inf 85.4%
*-commutative85.4%
distribute-rgt-out--85.4%
*-lft-identity85.4%
Simplified85.4%
if -4.9000000000000003e-113 < x Initial program 100.0%
Taylor expanded in y around inf 67.0%
distribute-lft-out--67.0%
*-rgt-identity67.0%
Simplified67.0%
Final simplification74.0%
(FPCore (x y) :precision binary64 (if (<= y 2.8e-96) x y))
double code(double x, double y) {
double tmp;
if (y <= 2.8e-96) {
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 <= 2.8d-96) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.8e-96) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.8e-96: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.8e-96) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.8e-96) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.8e-96], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{-96}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.80000000000000015e-96Initial program 100.0%
Taylor expanded in y around 0 54.7%
if 2.80000000000000015e-96 < y Initial program 100.0%
Taylor expanded in x around 0 43.3%
Final simplification51.0%
(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.9%
Final simplification40.9%
herbie shell --seed 2023268
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))