
(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%
*-commutative100.0%
*-commutative100.0%
distribute-rgt1-in100.0%
associate-+l+100.0%
+-commutative100.0%
neg-mul-1100.0%
*-commutative100.0%
distribute-lft-out100.0%
fma-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -2.3e-14)
y
(if (<= y 1.7e-54)
(- x)
(if (<= y 6.6e+134) y (if (<= y 2.5e+203) (* x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.3e-14) {
tmp = y;
} else if (y <= 1.7e-54) {
tmp = -x;
} else if (y <= 6.6e+134) {
tmp = y;
} else if (y <= 2.5e+203) {
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 <= (-2.3d-14)) then
tmp = y
else if (y <= 1.7d-54) then
tmp = -x
else if (y <= 6.6d+134) then
tmp = y
else if (y <= 2.5d+203) 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 <= -2.3e-14) {
tmp = y;
} else if (y <= 1.7e-54) {
tmp = -x;
} else if (y <= 6.6e+134) {
tmp = y;
} else if (y <= 2.5e+203) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e-14: tmp = y elif y <= 1.7e-54: tmp = -x elif y <= 6.6e+134: tmp = y elif y <= 2.5e+203: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e-14) tmp = y; elseif (y <= 1.7e-54) tmp = Float64(-x); elseif (y <= 6.6e+134) tmp = y; elseif (y <= 2.5e+203) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.3e-14) tmp = y; elseif (y <= 1.7e-54) tmp = -x; elseif (y <= 6.6e+134) tmp = y; elseif (y <= 2.5e+203) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e-14], y, If[LessEqual[y, 1.7e-54], (-x), If[LessEqual[y, 6.6e+134], y, If[LessEqual[y, 2.5e+203], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-14}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-54}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{+134}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+203}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.29999999999999998e-14 or 1.69999999999999994e-54 < y < 6.6e134 or 2.49999999999999997e203 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 65.5%
if -2.29999999999999998e-14 < y < 1.69999999999999994e-54Initial program 100.0%
Taylor expanded in y around 0 86.2%
neg-mul-186.2%
Simplified86.2%
if 6.6e134 < y < 2.49999999999999997e203Initial program 100.0%
Taylor expanded in x around inf 73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in y around inf 73.4%
Final simplification75.5%
(FPCore (x y) :precision binary64 (if (or (<= y -14500000000.0) (not (<= y 0.025))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -14500000000.0) || !(y <= 0.025)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-14500000000.0d0)) .or. (.not. (y <= 0.025d0))) then
tmp = y * (x + 1.0d0)
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -14500000000.0) || !(y <= 0.025)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -14500000000.0) or not (y <= 0.025): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -14500000000.0) || !(y <= 0.025)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -14500000000.0) || ~((y <= 0.025))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -14500000000.0], N[Not[LessEqual[y, 0.025]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -14500000000 \lor \neg \left(y \leq 0.025\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.45e10 or 0.025000000000000001 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
Simplified99.8%
if -1.45e10 < y < 0.025000000000000001Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification99.6%
(FPCore (x y) :precision binary64 (if (or (<= y 8.5e+135) (not (<= y 5.2e+202))) (- y x) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= 8.5e+135) || !(y <= 5.2e+202)) {
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) :: tmp
if ((y <= 8.5d+135) .or. (.not. (y <= 5.2d+202))) then
tmp = y - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 8.5e+135) || !(y <= 5.2e+202)) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 8.5e+135) or not (y <= 5.2e+202): tmp = y - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if ((y <= 8.5e+135) || !(y <= 5.2e+202)) tmp = Float64(y - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 8.5e+135) || ~((y <= 5.2e+202))) tmp = y - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 8.5e+135], N[Not[LessEqual[y, 5.2e+202]], $MachinePrecision]], N[(y - x), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.5 \cdot 10^{+135} \lor \neg \left(y \leq 5.2 \cdot 10^{+202}\right):\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < 8.49999999999999992e135 or 5.2000000000000004e202 < y Initial program 100.0%
Taylor expanded in x around 0 84.6%
if 8.49999999999999992e135 < y < 5.2000000000000004e202Initial program 100.0%
Taylor expanded in x around inf 73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in y around inf 73.4%
Final simplification83.9%
(FPCore (x y) :precision binary64 (if (<= y -9.5e-14) y (if (<= y 6.8e-53) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -9.5e-14) {
tmp = y;
} else if (y <= 6.8e-53) {
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 <= (-9.5d-14)) then
tmp = y
else if (y <= 6.8d-53) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -9.5e-14) {
tmp = y;
} else if (y <= 6.8e-53) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9.5e-14: tmp = y elif y <= 6.8e-53: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -9.5e-14) tmp = y; elseif (y <= 6.8e-53) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9.5e-14) tmp = y; elseif (y <= 6.8e-53) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9.5e-14], y, If[LessEqual[y, 6.8e-53], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-14}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-53}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -9.4999999999999999e-14 or 6.8e-53 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 61.1%
if -9.4999999999999999e-14 < y < 6.8e-53Initial program 100.0%
Taylor expanded in y around 0 86.2%
neg-mul-186.2%
Simplified86.2%
Final simplification72.7%
(FPCore (x y) :precision binary64 (+ y (* x (+ y -1.0))))
double code(double x, double y) {
return y + (x * (y + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x * (y + (-1.0d0)))
end function
public static double code(double x, double y) {
return y + (x * (y + -1.0));
}
def code(x, y): return y + (x * (y + -1.0))
function code(x, y) return Float64(y + Float64(x * Float64(y + -1.0))) end
function tmp = code(x, y) tmp = y + (x * (y + -1.0)); end
code[x_, y_] := N[(y + N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(y + -1\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 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 100.0%
Taylor expanded in x around 0 40.0%
Final simplification40.0%
herbie shell --seed 2024046
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))