
(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 (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%
associate--l+100.0%
+-commutative100.0%
*-rgt-identity100.0%
distribute-lft-out--100.0%
unsub-neg100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.0)
t_0
(if (<= y 4.5e-79)
x
(if (<= y 1.28e+110)
y
(if (or (<= y 9.5e+171) (and (not (<= y 2.05e+233)) (<= y 6.5e+273)))
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 <= 4.5e-79) {
tmp = x;
} else if (y <= 1.28e+110) {
tmp = y;
} else if ((y <= 9.5e+171) || (!(y <= 2.05e+233) && (y <= 6.5e+273))) {
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 <= 4.5d-79) then
tmp = x
else if (y <= 1.28d+110) then
tmp = y
else if ((y <= 9.5d+171) .or. (.not. (y <= 2.05d+233)) .and. (y <= 6.5d+273)) 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 <= 4.5e-79) {
tmp = x;
} else if (y <= 1.28e+110) {
tmp = y;
} else if ((y <= 9.5e+171) || (!(y <= 2.05e+233) && (y <= 6.5e+273))) {
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 <= 4.5e-79: tmp = x elif y <= 1.28e+110: tmp = y elif (y <= 9.5e+171) or (not (y <= 2.05e+233) and (y <= 6.5e+273)): 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 <= 4.5e-79) tmp = x; elseif (y <= 1.28e+110) tmp = y; elseif ((y <= 9.5e+171) || (!(y <= 2.05e+233) && (y <= 6.5e+273))) 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 <= 4.5e-79) tmp = x; elseif (y <= 1.28e+110) tmp = y; elseif ((y <= 9.5e+171) || (~((y <= 2.05e+233)) && (y <= 6.5e+273))) 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, 4.5e-79], x, If[LessEqual[y, 1.28e+110], y, If[Or[LessEqual[y, 9.5e+171], And[N[Not[LessEqual[y, 2.05e+233]], $MachinePrecision], LessEqual[y, 6.5e+273]]], 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 4.5 \cdot 10^{-79}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.28 \cdot 10^{+110}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+171} \lor \neg \left(y \leq 2.05 \cdot 10^{+233}\right) \land y \leq 6.5 \cdot 10^{+273}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 1.28e110 < y < 9.49999999999999924e171 or 2.04999999999999996e233 < y < 6.4999999999999996e273Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 49.8%
mul-1-neg49.8%
distribute-rgt-neg-out49.8%
Simplified49.8%
if -1 < y < 4.5000000000000003e-79Initial program 100.0%
Taylor expanded in y around 0 74.2%
if 4.5000000000000003e-79 < y < 1.28e110 or 9.49999999999999924e171 < y < 2.04999999999999996e233 or 6.4999999999999996e273 < y Initial program 99.9%
Taylor expanded in x around 0 54.9%
Final simplification62.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -2.5e-101)
t_0
(if (<= x -1.45e-182) y (if (<= x -2.65e-216) t_0 (* y (- 1.0 x)))))))
double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -2.5e-101) {
tmp = t_0;
} else if (x <= -1.45e-182) {
tmp = y;
} else if (x <= -2.65e-216) {
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 * (1.0d0 - y)
if (x <= (-2.5d-101)) then
tmp = t_0
else if (x <= (-1.45d-182)) then
tmp = y
else if (x <= (-2.65d-216)) 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 * (1.0 - y);
double tmp;
if (x <= -2.5e-101) {
tmp = t_0;
} else if (x <= -1.45e-182) {
tmp = y;
} else if (x <= -2.65e-216) {
tmp = t_0;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): t_0 = x * (1.0 - y) tmp = 0 if x <= -2.5e-101: tmp = t_0 elif x <= -1.45e-182: tmp = y elif x <= -2.65e-216: tmp = t_0 else: tmp = y * (1.0 - x) return tmp
function code(x, y) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -2.5e-101) tmp = t_0; elseif (x <= -1.45e-182) tmp = y; elseif (x <= -2.65e-216) tmp = t_0; else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) t_0 = x * (1.0 - y); tmp = 0.0; if (x <= -2.5e-101) tmp = t_0; elseif (x <= -1.45e-182) tmp = y; elseif (x <= -2.65e-216) tmp = t_0; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.5e-101], t$95$0, If[LessEqual[x, -1.45e-182], y, If[LessEqual[x, -2.65e-216], t$95$0, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -2.5 \cdot 10^{-101}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-182}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -2.65 \cdot 10^{-216}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -2.5e-101 or -1.44999999999999993e-182 < x < -2.64999999999999989e-216Initial program 99.9%
Taylor expanded in x around inf 85.9%
if -2.5e-101 < x < -1.44999999999999993e-182Initial program 100.0%
Taylor expanded in x around 0 77.7%
if -2.64999999999999989e-216 < x Initial program 100.0%
Taylor expanded in y around inf 72.3%
Final simplification77.6%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* y (- x)) (if (<= y 2.5e-77) x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * -x;
} else if (y <= 2.5e-77) {
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 = y * -x
else if (y <= 2.5d-77) 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 = y * -x;
} else if (y <= 2.5e-77) {
tmp = x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * -x elif y <= 2.5e-77: tmp = x else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * Float64(-x)); elseif (y <= 2.5e-77) 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 = y * -x; elseif (y <= 2.5e-77) tmp = x; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y * (-x)), $MachinePrecision], If[LessEqual[y, 2.5e-77], x, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-77}:\\
\;\;\;\;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 100.0%
Taylor expanded in x around inf 44.6%
mul-1-neg44.6%
distribute-rgt-neg-out44.6%
Simplified44.6%
if -1 < y < 2.49999999999999982e-77Initial program 100.0%
Taylor expanded in y around 0 74.2%
if 2.49999999999999982e-77 < y Initial program 99.9%
Taylor expanded in y around inf 87.7%
Final simplification70.2%
(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 (<= y 1.35e-75) x y))
double code(double x, double y) {
double tmp;
if (y <= 1.35e-75) {
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.35d-75) 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.35e-75) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.35e-75: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.35e-75) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.35e-75) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.35e-75], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{-75}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.3499999999999999e-75Initial program 100.0%
Taylor expanded in y around 0 49.5%
if 1.3499999999999999e-75 < y Initial program 99.9%
Taylor expanded in x around 0 48.6%
Final simplification49.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 38.5%
Final simplification38.5%
herbie shell --seed 2023175
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))