
(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 1.0) y (- x)))
double code(double x, double y) {
return fma((x + 1.0), y, -x);
}
function code(x, y) return fma(Float64(x + 1.0), y, Float64(-x)) end
code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] * y + (-x)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + 1, y, -x\right)
\end{array}
Initial program 100.0%
fma-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -2.6e+214)
(- x)
(if (<= x -7.5e+67)
(* x y)
(if (<= x -3.4e-16)
(- x)
(if (<= x 3.6e-94) y (if (<= x 30000000000.0) (- x) (* x y)))))))
double code(double x, double y) {
double tmp;
if (x <= -2.6e+214) {
tmp = -x;
} else if (x <= -7.5e+67) {
tmp = x * y;
} else if (x <= -3.4e-16) {
tmp = -x;
} else if (x <= 3.6e-94) {
tmp = y;
} else if (x <= 30000000000.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 (x <= (-2.6d+214)) then
tmp = -x
else if (x <= (-7.5d+67)) then
tmp = x * y
else if (x <= (-3.4d-16)) then
tmp = -x
else if (x <= 3.6d-94) then
tmp = y
else if (x <= 30000000000.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 (x <= -2.6e+214) {
tmp = -x;
} else if (x <= -7.5e+67) {
tmp = x * y;
} else if (x <= -3.4e-16) {
tmp = -x;
} else if (x <= 3.6e-94) {
tmp = y;
} else if (x <= 30000000000.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.6e+214: tmp = -x elif x <= -7.5e+67: tmp = x * y elif x <= -3.4e-16: tmp = -x elif x <= 3.6e-94: tmp = y elif x <= 30000000000.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.6e+214) tmp = Float64(-x); elseif (x <= -7.5e+67) tmp = Float64(x * y); elseif (x <= -3.4e-16) tmp = Float64(-x); elseif (x <= 3.6e-94) tmp = y; elseif (x <= 30000000000.0) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.6e+214) tmp = -x; elseif (x <= -7.5e+67) tmp = x * y; elseif (x <= -3.4e-16) tmp = -x; elseif (x <= 3.6e-94) tmp = y; elseif (x <= 30000000000.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.6e+214], (-x), If[LessEqual[x, -7.5e+67], N[(x * y), $MachinePrecision], If[LessEqual[x, -3.4e-16], (-x), If[LessEqual[x, 3.6e-94], y, If[LessEqual[x, 30000000000.0], (-x), N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+214}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -7.5 \cdot 10^{+67}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -3.4 \cdot 10^{-16}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{-94}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 30000000000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.59999999999999993e214 or -7.5000000000000005e67 < x < -3.4e-16 or 3.6e-94 < x < 3e10Initial program 100.0%
Taylor expanded in y around 0 78.8%
neg-mul-178.8%
Simplified78.8%
if -2.59999999999999993e214 < x < -7.5000000000000005e67 or 3e10 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 59.9%
if -3.4e-16 < x < 3.6e-94Initial program 100.0%
Taylor expanded in x around 0 80.6%
Final simplification72.6%
(FPCore (x y) :precision binary64 (if (or (<= x -5e-16) (not (<= x 1.6e-94))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -5e-16) || !(x <= 1.6e-94)) {
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 <= (-5d-16)) .or. (.not. (x <= 1.6d-94))) 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 <= -5e-16) || !(x <= 1.6e-94)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5e-16) or not (x <= 1.6e-94): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -5e-16) || !(x <= 1.6e-94)) 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 <= -5e-16) || ~((x <= 1.6e-94))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5e-16], N[Not[LessEqual[x, 1.6e-94]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-16} \lor \neg \left(x \leq 1.6 \cdot 10^{-94}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -5.0000000000000004e-16 or 1.59999999999999998e-94 < x Initial program 100.0%
Taylor expanded in x around inf 96.2%
if -5.0000000000000004e-16 < x < 1.59999999999999998e-94Initial program 100.0%
Taylor expanded in x around 0 80.6%
Final simplification89.3%
(FPCore (x y) :precision binary64 (if (or (<= x -620.0) (not (<= x 3.7e-94))) (* x (+ y -1.0)) (* (+ x 1.0) y)))
double code(double x, double y) {
double tmp;
if ((x <= -620.0) || !(x <= 3.7e-94)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-620.0d0)) .or. (.not. (x <= 3.7d-94))) then
tmp = x * (y + (-1.0d0))
else
tmp = (x + 1.0d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -620.0) || !(x <= 3.7e-94)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -620.0) or not (x <= 3.7e-94): tmp = x * (y + -1.0) else: tmp = (x + 1.0) * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -620.0) || !(x <= 3.7e-94)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(Float64(x + 1.0) * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -620.0) || ~((x <= 3.7e-94))) tmp = x * (y + -1.0); else tmp = (x + 1.0) * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -620.0], N[Not[LessEqual[x, 3.7e-94]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -620 \lor \neg \left(x \leq 3.7 \cdot 10^{-94}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\end{array}
\end{array}
if x < -620 or 3.6999999999999998e-94 < x Initial program 100.0%
Taylor expanded in x around inf 97.3%
if -620 < x < 3.6999999999999998e-94Initial program 100.0%
Taylor expanded in y around inf 80.3%
+-commutative80.3%
Simplified80.3%
Final simplification89.5%
(FPCore (x y) :precision binary64 (if (<= y -6e-35) y (if (<= y 8.2e-126) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -6e-35) {
tmp = y;
} else if (y <= 8.2e-126) {
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 <= (-6d-35)) then
tmp = y
else if (y <= 8.2d-126) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6e-35) {
tmp = y;
} else if (y <= 8.2e-126) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e-35: tmp = y elif y <= 8.2e-126: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -6e-35) tmp = y; elseif (y <= 8.2e-126) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6e-35) tmp = y; elseif (y <= 8.2e-126) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e-35], y, If[LessEqual[y, 8.2e-126], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-35}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{-126}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.99999999999999978e-35 or 8.1999999999999995e-126 < y Initial program 100.0%
Taylor expanded in x around 0 53.4%
if -5.99999999999999978e-35 < y < 8.1999999999999995e-126Initial program 100.0%
Taylor expanded in y around 0 86.1%
neg-mul-186.1%
Simplified86.1%
Final simplification65.8%
(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}
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 39.4%
Final simplification39.4%
herbie shell --seed 2024059
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))