
(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 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%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -195000.0) y (if (<= y 1.0) (- x) (if (<= y 4.7e+76) (* x y) y))))
double code(double x, double y) {
double tmp;
if (y <= -195000.0) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} else if (y <= 4.7e+76) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-195000.0d0)) then
tmp = y
else if (y <= 1.0d0) then
tmp = -x
else if (y <= 4.7d+76) then
tmp = x * y
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -195000.0) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} else if (y <= 4.7e+76) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -195000.0: tmp = y elif y <= 1.0: tmp = -x elif y <= 4.7e+76: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -195000.0) tmp = y; elseif (y <= 1.0) tmp = Float64(-x); elseif (y <= 4.7e+76) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -195000.0) tmp = y; elseif (y <= 1.0) tmp = -x; elseif (y <= 4.7e+76) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -195000.0], y, If[LessEqual[y, 1.0], (-x), If[LessEqual[y, 4.7e+76], N[(x * y), $MachinePrecision], y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -195000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+76}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -195000 or 4.7000000000000003e76 < y Initial program 100.0%
Taylor expanded in x around 0 57.1%
if -195000 < y < 1Initial program 100.0%
Taylor expanded in y around 0 80.4%
neg-mul-180.4%
Simplified80.4%
if 1 < y < 4.7000000000000003e76Initial program 99.9%
Taylor expanded in x around inf 70.7%
Taylor expanded in y around inf 64.4%
Final simplification69.9%
(FPCore (x y) :precision binary64 (if (or (<= x -6.2e-41) (not (<= x 1.65e-53))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -6.2e-41) || !(x <= 1.65e-53)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-6.2d-41)) .or. (.not. (x <= 1.65d-53))) then
tmp = x * (y + (-1.0d0))
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -6.2e-41) || !(x <= 1.65e-53)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6.2e-41) or not (x <= 1.65e-53): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -6.2e-41) || !(x <= 1.65e-53)) tmp = Float64(x * Float64(y + -1.0)); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -6.2e-41) || ~((x <= 1.65e-53))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6.2e-41], N[Not[LessEqual[x, 1.65e-53]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-41} \lor \neg \left(x \leq 1.65 \cdot 10^{-53}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.20000000000000001e-41 or 1.65000000000000002e-53 < x Initial program 100.0%
Taylor expanded in x around inf 96.5%
if -6.20000000000000001e-41 < x < 1.65000000000000002e-53Initial program 100.0%
Taylor expanded in x around 0 79.1%
Final simplification89.3%
(FPCore (x y) :precision binary64 (if (or (<= y -256000.0) (not (<= y 1.25e+14))) (* y (+ x 1.0)) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -256000.0) || !(y <= 1.25e+14)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-256000.0d0)) .or. (.not. (y <= 1.25d+14))) then
tmp = y * (x + 1.0d0)
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -256000.0) || !(y <= 1.25e+14)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -256000.0) or not (y <= 1.25e+14): tmp = y * (x + 1.0) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -256000.0) || !(y <= 1.25e+14)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -256000.0) || ~((y <= 1.25e+14))) tmp = y * (x + 1.0); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -256000.0], N[Not[LessEqual[y, 1.25e+14]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -256000 \lor \neg \left(y \leq 1.25 \cdot 10^{+14}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -256000 or 1.25e14 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
if -256000 < y < 1.25e14Initial program 100.0%
Taylor expanded in x around inf 83.4%
Final simplification91.1%
(FPCore (x y) :precision binary64 (if (<= y -195000.0) y (if (<= y 1.05e-8) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -195000.0) {
tmp = y;
} else if (y <= 1.05e-8) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-195000.0d0)) then
tmp = y
else if (y <= 1.05d-8) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -195000.0) {
tmp = y;
} else if (y <= 1.05e-8) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -195000.0: tmp = y elif y <= 1.05e-8: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -195000.0) tmp = y; elseif (y <= 1.05e-8) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -195000.0) tmp = y; elseif (y <= 1.05e-8) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -195000.0], y, If[LessEqual[y, 1.05e-8], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -195000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-8}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -195000 or 1.04999999999999997e-8 < y Initial program 100.0%
Taylor expanded in x around 0 53.6%
if -195000 < y < 1.04999999999999997e-8Initial program 100.0%
Taylor expanded in y around 0 80.4%
neg-mul-180.4%
Simplified80.4%
Final simplification67.7%
(FPCore (x y) :precision binary64 (- (* y (+ x 1.0)) x))
double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (x + 1.0d0)) - x
end function
public static double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
def code(x, y): return (y * (x + 1.0)) - x
function code(x, y) return Float64(Float64(y * Float64(x + 1.0)) - x) end
function tmp = code(x, y) tmp = (y * (x + 1.0)) - x; end
code[x_, y_] := N[(N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x + 1\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 36.0%
Final simplification36.0%
herbie shell --seed 2024095
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))