
(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 10 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 x (+ y -1.0) y))
double code(double x, double y) {
return fma(x, (y + -1.0), y);
}
function code(x, y) return fma(x, Float64(y + -1.0), y) end
code[x_, y_] := N[(x * N[(y + -1.0), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + -1, y\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft-inN/A
*-rgt-identityN/A
associate--l+N/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
associate-+r-N/A
+-commutativeN/A
associate--l+N/A
lift--.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
lower-fma.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y (+ x 1.0)) x))) (if (<= t_0 -2e+290) (* x y) (if (<= t_0 4e+307) (- y x) (* x y)))))
double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -2e+290) {
tmp = x * y;
} else if (t_0 <= 4e+307) {
tmp = y - 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) :: t_0
real(8) :: tmp
t_0 = (y * (x + 1.0d0)) - x
if (t_0 <= (-2d+290)) then
tmp = x * y
else if (t_0 <= 4d+307) then
tmp = y - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * (x + 1.0)) - x;
double tmp;
if (t_0 <= -2e+290) {
tmp = x * y;
} else if (t_0 <= 4e+307) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): t_0 = (y * (x + 1.0)) - x tmp = 0 if t_0 <= -2e+290: tmp = x * y elif t_0 <= 4e+307: tmp = y - x else: tmp = x * y return tmp
function code(x, y) t_0 = Float64(Float64(y * Float64(x + 1.0)) - x) tmp = 0.0 if (t_0 <= -2e+290) tmp = Float64(x * y); elseif (t_0 <= 4e+307) tmp = Float64(y - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) t_0 = (y * (x + 1.0)) - x; tmp = 0.0; if (t_0 <= -2e+290) tmp = x * y; elseif (t_0 <= 4e+307) tmp = y - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+290], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, 4e+307], N[(y - x), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + 1\right) - x\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+290}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+307}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < -2.00000000000000012e290 or 3.99999999999999994e307 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6493.2
Applied rewrites93.2%
Taylor expanded in x around inf
lower-*.f6489.6
Applied rewrites89.6%
if -2.00000000000000012e290 < (-.f64 (*.f64 (+.f64 x #s(literal 1 binary64)) y) x) < 3.99999999999999994e307Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites90.0%
*-lft-identity90.0
Applied rewrites90.0%
Final simplification90.0%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (fma y x (- x)) (if (<= x 1.6e-11) (- y x) (- (* x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = fma(y, x, -x);
} else if (x <= 1.6e-11) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = fma(y, x, Float64(-x)); elseif (x <= 1.6e-11) tmp = Float64(y - x); else tmp = Float64(Float64(x * y) - x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.0], N[(y * x + (-x)), $MachinePrecision], If[LessEqual[x, 1.6e-11], N[(y - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{fma}\left(y, x, -x\right)\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-11}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
lift-neg.f64N/A
lower-fma.f6498.8
Applied rewrites98.8%
if -1 < x < 1.59999999999999997e-11Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.8%
*-lft-identity99.8
Applied rewrites99.8%
if 1.59999999999999997e-11 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6499.5
Applied rewrites99.5%
Final simplification99.5%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x (+ y -1.0)) (if (<= x 1.6e-11) (- y x) (- (* x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 1.6e-11) {
tmp = y - x;
} else {
tmp = (x * 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 <= (-1.0d0)) then
tmp = x * (y + (-1.0d0))
else if (x <= 1.6d-11) then
tmp = y - x
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 1.6e-11) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x * (y + -1.0) elif x <= 1.6e-11: tmp = y - x else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * Float64(y + -1.0)); elseif (x <= 1.6e-11) tmp = Float64(y - x); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = x * (y + -1.0); elseif (x <= 1.6e-11) tmp = y - x; else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.6e-11], N[(y - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-11}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-+.f6498.8
Applied rewrites98.8%
if -1 < x < 1.59999999999999997e-11Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.8%
*-lft-identity99.8
Applied rewrites99.8%
if 1.59999999999999997e-11 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6499.5
Applied rewrites99.5%
Final simplification99.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (+ y -1.0)))) (if (<= x -1.0) t_0 (if (<= x 1.6e-11) (- y x) t_0))))
double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.6e-11) {
tmp = y - x;
} else {
tmp = t_0;
}
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 = x * (y + (-1.0d0))
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 1.6d-11) then
tmp = y - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.6e-11) {
tmp = y - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y + -1.0) tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 1.6e-11: tmp = y - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(y + -1.0)) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.6e-11) tmp = Float64(y - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y + -1.0); tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 1.6e-11) tmp = y - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.6e-11], N[(y - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + -1\right)\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-11}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1.59999999999999997e-11 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6499.1
Applied rewrites99.1%
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-+.f6499.1
Applied rewrites99.1%
if -1 < x < 1.59999999999999997e-11Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.8%
*-lft-identity99.8
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (fma y x y) (if (<= y 1.0) (- y x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = fma(y, x, y);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = fma(y, x, y); elseif (y <= 1.0) tmp = Float64(y - x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y * x + y), $MachinePrecision], If[LessEqual[y, 1.0], N[(y - x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6499.6
Applied rewrites99.6%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites96.8%
*-lft-identity96.8
Applied rewrites96.8%
(FPCore (x y) :precision binary64 (if (<= y -4.8e-74) (+ x y) (if (<= y 2.6e-17) (- x) (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -4.8e-74) {
tmp = x + y;
} else if (y <= 2.6e-17) {
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 <= (-4.8d-74)) then
tmp = x + y
else if (y <= 2.6d-17) 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 <= -4.8e-74) {
tmp = x + y;
} else if (y <= 2.6e-17) {
tmp = -x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.8e-74: tmp = x + y elif y <= 2.6e-17: tmp = -x else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.8e-74) tmp = Float64(x + y); elseif (y <= 2.6e-17) tmp = Float64(-x); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.8e-74) tmp = x + y; elseif (y <= 2.6e-17) tmp = -x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.8e-74], N[(x + y), $MachinePrecision], If[LessEqual[y, 2.6e-17], (-x), N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-74}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-17}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -4.7999999999999998e-74 or 2.60000000000000003e-17 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites61.4%
*-lft-identity61.4
Applied rewrites61.4%
Applied rewrites55.4%
if -4.7999999999999998e-74 < y < 2.60000000000000003e-17Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6487.4
Applied rewrites87.4%
Final simplification68.8%
(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 (- y x))
double code(double x, double y) {
return y - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y - x
end function
public static double code(double x, double y) {
return y - x;
}
def code(x, y): return y - x
function code(x, y) return Float64(y - x) end
function tmp = code(x, y) tmp = y - x; end
code[x_, y_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites77.5%
*-lft-identity77.5
Applied rewrites77.5%
(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%
herbie shell --seed 2024214
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))