
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
(FPCore (x y) :precision binary64 (fma y x (- y x)))
double code(double x, double y) {
return fma(y, x, (y - x));
}
function code(x, y) return fma(y, x, Float64(y - x)) end
code[x_, y_] := N[(y * x + N[(y - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, y - x\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.6e+15) (not (<= y 9.8e-25))) (fma y x y) (- (* 1.0 y) x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.6e+15) || !(y <= 9.8e-25)) {
tmp = fma(y, x, y);
} else {
tmp = (1.0 * y) - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -1.6e+15) || !(y <= 9.8e-25)) tmp = fma(y, x, y); else tmp = Float64(Float64(1.0 * y) - x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -1.6e+15], N[Not[LessEqual[y, 9.8e-25]], $MachinePrecision]], N[(y * x + y), $MachinePrecision], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+15} \lor \neg \left(y \leq 9.8 \cdot 10^{-25}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y - x\\
\end{array}
\end{array}
if y < -1.6e15 or 9.7999999999999998e-25 < y Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
sub-negN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6499.6
Applied rewrites99.6%
if -1.6e15 < y < 9.7999999999999998e-25Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.1%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (or (<= y -6e-9) (not (<= y 1.7e-25))) (fma y x y) (fma y x (- x))))
double code(double x, double y) {
double tmp;
if ((y <= -6e-9) || !(y <= 1.7e-25)) {
tmp = fma(y, x, y);
} else {
tmp = fma(y, x, -x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -6e-9) || !(y <= 1.7e-25)) tmp = fma(y, x, y); else tmp = fma(y, x, Float64(-x)); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -6e-9], N[Not[LessEqual[y, 1.7e-25]], $MachinePrecision]], N[(y * x + y), $MachinePrecision], N[(y * x + (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-9} \lor \neg \left(y \leq 1.7 \cdot 10^{-25}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, -x\right)\\
\end{array}
\end{array}
if y < -5.99999999999999996e-9 or 1.70000000000000001e-25 < y Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
sub-negN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6499.0
Applied rewrites99.0%
if -5.99999999999999996e-9 < y < 1.70000000000000001e-25Initial program 100.0%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f6477.6
Applied rewrites77.6%
Final simplification88.8%
(FPCore (x y) :precision binary64 (if (or (<= y -8.6e-99) (not (<= y 1.7e-25))) (fma y x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -8.6e-99) || !(y <= 1.7e-25)) {
tmp = fma(y, x, y);
} else {
tmp = -x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -8.6e-99) || !(y <= 1.7e-25)) tmp = fma(y, x, y); else tmp = Float64(-x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -8.6e-99], N[Not[LessEqual[y, 1.7e-25]], $MachinePrecision]], N[(y * x + y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{-99} \lor \neg \left(y \leq 1.7 \cdot 10^{-25}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -8.5999999999999998e-99 or 1.70000000000000001e-25 < y Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
sub-negN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6491.3
Applied rewrites91.3%
if -8.5999999999999998e-99 < y < 1.70000000000000001e-25Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6484.2
Applied rewrites84.2%
Final simplification88.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = -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)) .or. (.not. (y <= 1.0d0))) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
+-commutativeN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
sub-negN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lower-fma.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
Applied rewrites39.0%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6475.1
Applied rewrites75.1%
Final simplification56.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 Float64(-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
mul-1-negN/A
lower-neg.f6438.6
Applied rewrites38.6%
herbie shell --seed 2024324
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))