
(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 y (- 1.0 x) x))
double code(double x, double y) {
return fma(y, (1.0 - x), x);
}
function code(x, y) return fma(y, Float64(1.0 - x), x) end
code[x_, y_] := N[(y * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 1 - x, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-lft1-in100.0%
*-commutative100.0%
associate-+l+100.0%
distribute-rgt-neg-out100.0%
sub-neg100.0%
*-lft-identity100.0%
distribute-rgt-out--100.0%
*-commutative100.0%
*-commutative100.0%
fma-def100.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.8e-120)
x
(if (<= y 1.2e-75)
y
(if (<= y 1.48e-52)
x
(if (<= y 3750000000.0)
y
(if (or (<= y 5e+62)
(and (not (<= y 3.5e+83))
(or (<= y 1.1e+210) (not (<= y 1.46e+248)))))
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.8e-120) {
tmp = x;
} else if (y <= 1.2e-75) {
tmp = y;
} else if (y <= 1.48e-52) {
tmp = x;
} else if (y <= 3750000000.0) {
tmp = y;
} else if ((y <= 5e+62) || (!(y <= 3.5e+83) && ((y <= 1.1e+210) || !(y <= 1.46e+248)))) {
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.8d-120) then
tmp = x
else if (y <= 1.2d-75) then
tmp = y
else if (y <= 1.48d-52) then
tmp = x
else if (y <= 3750000000.0d0) then
tmp = y
else if ((y <= 5d+62) .or. (.not. (y <= 3.5d+83)) .and. (y <= 1.1d+210) .or. (.not. (y <= 1.46d+248))) 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.8e-120) {
tmp = x;
} else if (y <= 1.2e-75) {
tmp = y;
} else if (y <= 1.48e-52) {
tmp = x;
} else if (y <= 3750000000.0) {
tmp = y;
} else if ((y <= 5e+62) || (!(y <= 3.5e+83) && ((y <= 1.1e+210) || !(y <= 1.46e+248)))) {
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.8e-120: tmp = x elif y <= 1.2e-75: tmp = y elif y <= 1.48e-52: tmp = x elif y <= 3750000000.0: tmp = y elif (y <= 5e+62) or (not (y <= 3.5e+83) and ((y <= 1.1e+210) or not (y <= 1.46e+248))): 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.8e-120) tmp = x; elseif (y <= 1.2e-75) tmp = y; elseif (y <= 1.48e-52) tmp = x; elseif (y <= 3750000000.0) tmp = y; elseif ((y <= 5e+62) || (!(y <= 3.5e+83) && ((y <= 1.1e+210) || !(y <= 1.46e+248)))) 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.8e-120) tmp = x; elseif (y <= 1.2e-75) tmp = y; elseif (y <= 1.48e-52) tmp = x; elseif (y <= 3750000000.0) tmp = y; elseif ((y <= 5e+62) || (~((y <= 3.5e+83)) && ((y <= 1.1e+210) || ~((y <= 1.46e+248))))) 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.8e-120], x, If[LessEqual[y, 1.2e-75], y, If[LessEqual[y, 1.48e-52], x, If[LessEqual[y, 3750000000.0], y, If[Or[LessEqual[y, 5e+62], And[N[Not[LessEqual[y, 3.5e+83]], $MachinePrecision], Or[LessEqual[y, 1.1e+210], N[Not[LessEqual[y, 1.46e+248]], $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 4.8 \cdot 10^{-120}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-75}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.48 \cdot 10^{-52}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3750000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+62} \lor \neg \left(y \leq 3.5 \cdot 10^{+83}\right) \land \left(y \leq 1.1 \cdot 10^{+210} \lor \neg \left(y \leq 1.46 \cdot 10^{+248}\right)\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 3.75e9 < y < 5.00000000000000029e62 or 3.49999999999999977e83 < y < 1.09999999999999993e210 or 1.46e248 < y Initial program 100.0%
Taylor expanded in x around inf 60.7%
Taylor expanded in y around inf 60.0%
mul-1-neg60.0%
distribute-rgt-neg-out60.0%
Simplified60.0%
if -1 < y < 4.7999999999999999e-120 or 1.2000000000000001e-75 < y < 1.47999999999999993e-52Initial program 100.0%
Taylor expanded in y around 0 78.8%
if 4.7999999999999999e-120 < y < 1.2000000000000001e-75 or 1.47999999999999993e-52 < y < 3.75e9 or 5.00000000000000029e62 < y < 3.49999999999999977e83 or 1.09999999999999993e210 < y < 1.46e248Initial program 100.0%
Taylor expanded in x around 0 62.1%
Final simplification68.1%
(FPCore (x y) :precision binary64 (if (or (<= x -4e-132) (not (<= x 1.4e-18))) (* x (- 1.0 y)) y))
double code(double x, double y) {
double tmp;
if ((x <= -4e-132) || !(x <= 1.4e-18)) {
tmp = x * (1.0 - y);
} 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 <= (-4d-132)) .or. (.not. (x <= 1.4d-18))) then
tmp = x * (1.0d0 - y)
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -4e-132) || !(x <= 1.4e-18)) {
tmp = x * (1.0 - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4e-132) or not (x <= 1.4e-18): tmp = x * (1.0 - y) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -4e-132) || !(x <= 1.4e-18)) tmp = Float64(x * Float64(1.0 - y)); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4e-132) || ~((x <= 1.4e-18))) tmp = x * (1.0 - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4e-132], N[Not[LessEqual[x, 1.4e-18]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-132} \lor \neg \left(x \leq 1.4 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.9999999999999999e-132 or 1.40000000000000006e-18 < x Initial program 100.0%
Taylor expanded in x around inf 89.3%
if -3.9999999999999999e-132 < x < 1.40000000000000006e-18Initial program 100.0%
Taylor expanded in x around 0 79.2%
Final simplification85.7%
(FPCore (x y) :precision binary64 (if (<= x -4e-132) (* x (- 1.0 y)) (- y (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -4e-132) {
tmp = x * (1.0 - y);
} else {
tmp = y - (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 <= (-4d-132)) then
tmp = x * (1.0d0 - y)
else
tmp = y - (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4e-132) {
tmp = x * (1.0 - y);
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4e-132: tmp = x * (1.0 - y) else: tmp = y - (y * x) return tmp
function code(x, y) tmp = 0.0 if (x <= -4e-132) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4e-132) tmp = x * (1.0 - y); else tmp = y - (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4e-132], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-132}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if x < -3.9999999999999999e-132Initial program 100.0%
Taylor expanded in x around inf 84.9%
if -3.9999999999999999e-132 < x Initial program 100.0%
Taylor expanded in y around inf 71.4%
distribute-lft-out--71.4%
*-rgt-identity71.4%
Simplified71.4%
Final simplification77.1%
(FPCore (x y) :precision binary64 (- (+ y x) (* y x)))
double code(double x, double y) {
return (y + x) - (y * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) - (y * x)
end function
public static double code(double x, double y) {
return (y + x) - (y * x);
}
def code(x, y): return (y + x) - (y * x)
function code(x, y) return Float64(Float64(y + x) - Float64(y * x)) end
function tmp = code(x, y) tmp = (y + x) - (y * x); end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) - y \cdot x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -4e-132) x y))
double code(double x, double y) {
double tmp;
if (x <= -4e-132) {
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 <= (-4d-132)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4e-132) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4e-132: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -4e-132) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4e-132) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4e-132], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-132}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.9999999999999999e-132Initial program 100.0%
Taylor expanded in y around 0 48.6%
if -3.9999999999999999e-132 < x Initial program 100.0%
Taylor expanded in x around 0 48.7%
Final simplification48.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.8%
Final simplification37.8%
herbie shell --seed 2023173
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))