
(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 7 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 Float64(fma(y, x, y) - x) end
code[x_, y_] := N[(N[(y * x + y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, y\right) - x
\end{array}
Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma y x (- x)))) (if (<= x -8.8e+36) t_0 (if (<= x 1.0) (- (* 1.0 y) x) t_0))))
double code(double x, double y) {
double t_0 = fma(y, x, -x);
double tmp;
if (x <= -8.8e+36) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = (1.0 * y) - x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(y, x, Float64(-x)) tmp = 0.0 if (x <= -8.8e+36) tmp = t_0; elseif (x <= 1.0) tmp = Float64(Float64(1.0 * y) - x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * x + (-x)), $MachinePrecision]}, If[LessEqual[x, -8.8e+36], t$95$0, If[LessEqual[x, 1.0], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, x, -x\right)\\
\mathbf{if}\;x \leq -8.8 \cdot 10^{+36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.80000000000000002e36 or 1 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
cancel-sign-sub-invN/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
if -8.80000000000000002e36 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma y x (- x)))) (if (<= x -1.06e-28) t_0 (if (<= x 1.6e-33) (fma y x y) t_0))))
double code(double x, double y) {
double t_0 = fma(y, x, -x);
double tmp;
if (x <= -1.06e-28) {
tmp = t_0;
} else if (x <= 1.6e-33) {
tmp = fma(y, x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(y, x, Float64(-x)) tmp = 0.0 if (x <= -1.06e-28) tmp = t_0; elseif (x <= 1.6e-33) tmp = fma(y, x, y); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * x + (-x)), $MachinePrecision]}, If[LessEqual[x, -1.06e-28], t$95$0, If[LessEqual[x, 1.6e-33], N[(y * x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, x, -x\right)\\
\mathbf{if}\;x \leq -1.06 \cdot 10^{-28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.06e-28 or 1.59999999999999988e-33 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
cancel-sign-sub-invN/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-neg.f6497.0
Applied rewrites97.0%
if -1.06e-28 < x < 1.59999999999999988e-33Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6482.2
Applied rewrites82.2%
(FPCore (x y) :precision binary64 (if (<= y -1.8e-38) (fma y x y) (if (<= y 8e-10) (- x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.8e-38) {
tmp = fma(y, x, y);
} else if (y <= 8e-10) {
tmp = -x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.8e-38) tmp = fma(y, x, y); elseif (y <= 8e-10) tmp = Float64(-x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.8e-38], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 8e-10], (-x), N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-38}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-10}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -1.8e-38 or 8.00000000000000029e-10 < y Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6494.4
Applied rewrites94.4%
if -1.8e-38 < y < 8.00000000000000029e-10Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6479.3
Applied rewrites79.3%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 1.0) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = -x;
} else {
tmp = x * 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.0d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = -x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 1.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
sub-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6496.2
Applied rewrites96.2%
Taylor expanded in x around inf
Applied rewrites42.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6475.7
Applied rewrites75.7%
Final simplification60.3%
(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.f6441.6
Applied rewrites41.6%
(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
mul-1-negN/A
lower-neg.f6441.6
Applied rewrites41.6%
Applied rewrites2.5%
herbie shell --seed 2024331
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))