
(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 (fma (- 1.0 x) y x))
double code(double x, double y) {
return fma((1.0 - x), y, x);
}
function code(x, y) return fma(Float64(1.0 - x), y, x) end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1 - x, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (+ x y) (* x y))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+304)))
(* (- y) x)
(fma 1.0 y x))))
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e+304)) {
tmp = -y * x;
} else {
tmp = fma(1.0, y, x);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e+304)) tmp = Float64(Float64(-y) * x); else tmp = fma(1.0, y, x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 5e+304]], $MachinePrecision]], N[((-y) * x), $MachinePrecision], N[(1.0 * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 5 \cdot 10^{+304}\right):\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 4.9999999999999997e304 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6497.3
Applied rewrites97.3%
Taylor expanded in y around inf
Applied rewrites97.3%
if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 4.9999999999999997e304Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites84.5%
Final simplification86.4%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* (- 1.0 y) x) (if (<= x 4.2e-63) (fma 1.0 y x) (* (- 1.0 x) y))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (1.0 - y) * x;
} else if (x <= 4.2e-63) {
tmp = fma(1.0, y, x);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(1.0 - y) * x); elseif (x <= 4.2e-63) tmp = fma(1.0, y, x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 4.2e-63], N[(1.0 * y + x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-63}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.4
Applied rewrites99.4%
if -1 < x < 4.2e-63Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
if 4.2e-63 < x Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6454.0
Applied rewrites54.0%
(FPCore (x y) :precision binary64 (if (<= y -9000000000.0) (* (- y) x) (if (<= y 0.49) (fma 1.0 y x) (* (- 1.0 x) y))))
double code(double x, double y) {
double tmp;
if (y <= -9000000000.0) {
tmp = -y * x;
} else if (y <= 0.49) {
tmp = fma(1.0, y, x);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -9000000000.0) tmp = Float64(Float64(-y) * x); elseif (y <= 0.49) tmp = fma(1.0, y, x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := If[LessEqual[y, -9000000000.0], N[((-y) * x), $MachinePrecision], If[LessEqual[y, 0.49], N[(1.0 * y + x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9000000000:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq 0.49:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if y < -9e9Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6457.2
Applied rewrites57.2%
Taylor expanded in y around inf
Applied rewrites56.7%
if -9e9 < y < 0.48999999999999999Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.1%
if 0.48999999999999999 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.4
Applied rewrites99.4%
(FPCore (x y) :precision binary64 (fma 1.0 y x))
double code(double x, double y) {
return fma(1.0, y, x);
}
function code(x, y) return fma(1.0, y, x) end
code[x_, y_] := N[(1.0 * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites73.2%
(FPCore (x y) :precision binary64 (* 1.0 y))
double code(double x, double y) {
return 1.0 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * y
end function
public static double code(double x, double y) {
return 1.0 * y;
}
def code(x, y): return 1.0 * y
function code(x, y) return Float64(1.0 * y) end
function tmp = code(x, y) tmp = 1.0 * y; end
code[x_, y_] := N[(1.0 * y), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.2
Applied rewrites63.2%
Taylor expanded in x around 0
Applied rewrites36.9%
herbie shell --seed 2024337
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))