
(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 5 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 (<= x -1.0) (- (* y x) x) (if (<= x 1.0) (- (* 1.0 y) x) (* (- y 1.0) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (y * x) - x;
} else if (x <= 1.0) {
tmp = (1.0 * y) - 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 (x <= (-1.0d0)) then
tmp = (y * x) - x
else if (x <= 1.0d0) then
tmp = (1.0d0 * y) - x
else
tmp = (y - 1.0d0) * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (y * x) - x;
} else if (x <= 1.0) {
tmp = (1.0 * y) - x;
} else {
tmp = (y - 1.0) * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = (y * x) - x elif x <= 1.0: tmp = (1.0 * y) - x else: tmp = (y - 1.0) * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(y * x) - x); elseif (x <= 1.0) tmp = Float64(Float64(1.0 * y) - x); else tmp = Float64(Float64(y - 1.0) * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = (y * x) - x; elseif (x <= 1.0) tmp = (1.0 * y) - x; else tmp = (y - 1.0) * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 1.0], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision], N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;y \cdot x - x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;\left(y - 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.6%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= y -3.4e-84) (not (<= y 4.4e-16))) (fma x y y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -3.4e-84) || !(y <= 4.4e-16)) {
tmp = fma(x, y, y);
} else {
tmp = -x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -3.4e-84) || !(y <= 4.4e-16)) tmp = fma(x, y, y); else tmp = Float64(-x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -3.4e-84], N[Not[LessEqual[y, 4.4e-16]], $MachinePrecision]], N[(x * y + y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-84} \lor \neg \left(y \leq 4.4 \cdot 10^{-16}\right):\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -3.40000000000000021e-84 or 4.40000000000000001e-16 < 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
associate-*r*N/A
distribute-rgt-out--N/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
mul-1-negN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites96.2%
if -3.40000000000000021e-84 < y < 4.40000000000000001e-16Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6479.4
Applied rewrites79.4%
Final simplification89.5%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.00093))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.00093)) {
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 <= 0.00093d0))) 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 <= 0.00093)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 0.00093): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.00093)) 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 <= 0.00093))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.00093]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.00093\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1 or 9.3000000000000005e-4 < 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
associate-*r*N/A
distribute-rgt-out--N/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
mul-1-negN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites98.6%
Taylor expanded in x around inf
Applied rewrites53.6%
if -1 < y < 9.3000000000000005e-4Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6471.0
Applied rewrites71.0%
Final simplification61.8%
(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.f6435.0
Applied rewrites35.0%
Final simplification35.0%
herbie shell --seed 2024343
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))