
(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 -5e+213)
(- x)
(if (<= x -2.6e+67)
(* x y)
(if (<= x -6.5e-16)
(- x)
(if (<= x 3.7e-94) y (if (<= x 30000000000.0) (- x) (* x y)))))))
double code(double x, double y) {
double tmp;
if (x <= -5e+213) {
tmp = -x;
} else if (x <= -2.6e+67) {
tmp = x * y;
} else if (x <= -6.5e-16) {
tmp = -x;
} else if (x <= 3.7e-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 <= (-5d+213)) then
tmp = -x
else if (x <= (-2.6d+67)) then
tmp = x * y
else if (x <= (-6.5d-16)) then
tmp = -x
else if (x <= 3.7d-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 <= -5e+213) {
tmp = -x;
} else if (x <= -2.6e+67) {
tmp = x * y;
} else if (x <= -6.5e-16) {
tmp = -x;
} else if (x <= 3.7e-94) {
tmp = y;
} else if (x <= 30000000000.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+213: tmp = -x elif x <= -2.6e+67: tmp = x * y elif x <= -6.5e-16: tmp = -x elif x <= 3.7e-94: tmp = y elif x <= 30000000000.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+213) tmp = Float64(-x); elseif (x <= -2.6e+67) tmp = Float64(x * y); elseif (x <= -6.5e-16) tmp = Float64(-x); elseif (x <= 3.7e-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 <= -5e+213) tmp = -x; elseif (x <= -2.6e+67) tmp = x * y; elseif (x <= -6.5e-16) tmp = -x; elseif (x <= 3.7e-94) tmp = y; elseif (x <= 30000000000.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+213], (-x), If[LessEqual[x, -2.6e+67], N[(x * y), $MachinePrecision], If[LessEqual[x, -6.5e-16], (-x), If[LessEqual[x, 3.7e-94], y, If[LessEqual[x, 30000000000.0], (-x), N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+213}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{+67}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -6.5 \cdot 10^{-16}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-94}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 30000000000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.9999999999999998e213 or -2.6e67 < x < -6.50000000000000011e-16 or 3.6999999999999998e-94 < x < 3e10Initial program 100.0%
Taylor expanded in y around 0 78.7%
neg-mul-178.7%
Simplified78.7%
if -4.9999999999999998e213 < x < -2.6e67 or 3e10 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 61.3%
if -6.50000000000000011e-16 < x < 3.6999999999999998e-94Initial program 100.0%
Taylor expanded in x around 0 81.3%
Final simplification73.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.6e-16) (not (<= x 3.7e-94))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.6e-16) || !(x <= 3.7e-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 <= (-1.6d-16)) .or. (.not. (x <= 3.7d-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 <= -1.6e-16) || !(x <= 3.7e-94)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.6e-16) or not (x <= 3.7e-94): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.6e-16) || !(x <= 3.7e-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 <= -1.6e-16) || ~((x <= 3.7e-94))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.6e-16], N[Not[LessEqual[x, 3.7e-94]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-16} \lor \neg \left(x \leq 3.7 \cdot 10^{-94}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.60000000000000011e-16 or 3.6999999999999998e-94 < x Initial program 100.0%
Taylor expanded in x around inf 96.9%
if -1.60000000000000011e-16 < x < 3.6999999999999998e-94Initial program 100.0%
Taylor expanded in x around 0 81.3%
Final simplification90.0%
(FPCore (x y) :precision binary64 (if (or (<= x -9500.0) (not (<= x 1.15e-94))) (* x (+ y -1.0)) (* (+ x 1.0) y)))
double code(double x, double y) {
double tmp;
if ((x <= -9500.0) || !(x <= 1.15e-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 <= (-9500.0d0)) .or. (.not. (x <= 1.15d-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 <= -9500.0) || !(x <= 1.15e-94)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -9500.0) or not (x <= 1.15e-94): tmp = x * (y + -1.0) else: tmp = (x + 1.0) * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -9500.0) || !(x <= 1.15e-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 <= -9500.0) || ~((x <= 1.15e-94))) tmp = x * (y + -1.0); else tmp = (x + 1.0) * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -9500.0], N[Not[LessEqual[x, 1.15e-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 -9500 \lor \neg \left(x \leq 1.15 \cdot 10^{-94}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\end{array}
\end{array}
if x < -9500 or 1.15e-94 < x Initial program 100.0%
Taylor expanded in x around inf 98.0%
if -9500 < x < 1.15e-94Initial program 100.0%
Taylor expanded in y around inf 80.9%
+-commutative80.9%
Simplified80.9%
Final simplification90.3%
(FPCore (x y) :precision binary64 (if (or (<= x -8.2e-16) (not (<= x 3.8e-95))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -8.2e-16) || !(x <= 3.8e-95)) {
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 ((x <= (-8.2d-16)) .or. (.not. (x <= 3.8d-95))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -8.2e-16) || !(x <= 3.8e-95)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -8.2e-16) or not (x <= 3.8e-95): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -8.2e-16) || !(x <= 3.8e-95)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -8.2e-16) || ~((x <= 3.8e-95))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -8.2e-16], N[Not[LessEqual[x, 3.8e-95]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-16} \lor \neg \left(x \leq 3.8 \cdot 10^{-95}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -8.20000000000000012e-16 or 3.7999999999999997e-95 < x Initial program 100.0%
Taylor expanded in y around 0 51.6%
neg-mul-151.6%
Simplified51.6%
if -8.20000000000000012e-16 < x < 3.7999999999999997e-95Initial program 100.0%
Taylor expanded in x around 0 81.3%
Final simplification64.7%
(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.0%
Final simplification39.0%
herbie shell --seed 2024059
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))