
(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-lft-in100.0%
*-rgt-identity100.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 -7.1e+258)
(* x y)
(if (<= y -1.6e+190)
y
(if (<= y -6.8e+31)
(* x y)
(if (<= y -4.8e-93) y (if (<= y 8.2e-7) (- x) y))))))
double code(double x, double y) {
double tmp;
if (y <= -7.1e+258) {
tmp = x * y;
} else if (y <= -1.6e+190) {
tmp = y;
} else if (y <= -6.8e+31) {
tmp = x * y;
} else if (y <= -4.8e-93) {
tmp = y;
} else if (y <= 8.2e-7) {
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 <= (-7.1d+258)) then
tmp = x * y
else if (y <= (-1.6d+190)) then
tmp = y
else if (y <= (-6.8d+31)) then
tmp = x * y
else if (y <= (-4.8d-93)) then
tmp = y
else if (y <= 8.2d-7) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -7.1e+258) {
tmp = x * y;
} else if (y <= -1.6e+190) {
tmp = y;
} else if (y <= -6.8e+31) {
tmp = x * y;
} else if (y <= -4.8e-93) {
tmp = y;
} else if (y <= 8.2e-7) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.1e+258: tmp = x * y elif y <= -1.6e+190: tmp = y elif y <= -6.8e+31: tmp = x * y elif y <= -4.8e-93: tmp = y elif y <= 8.2e-7: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.1e+258) tmp = Float64(x * y); elseif (y <= -1.6e+190) tmp = y; elseif (y <= -6.8e+31) tmp = Float64(x * y); elseif (y <= -4.8e-93) tmp = y; elseif (y <= 8.2e-7) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.1e+258) tmp = x * y; elseif (y <= -1.6e+190) tmp = y; elseif (y <= -6.8e+31) tmp = x * y; elseif (y <= -4.8e-93) tmp = y; elseif (y <= 8.2e-7) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.1e+258], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.6e+190], y, If[LessEqual[y, -6.8e+31], N[(x * y), $MachinePrecision], If[LessEqual[y, -4.8e-93], y, If[LessEqual[y, 8.2e-7], (-x), y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.1 \cdot 10^{+258}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{+190}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -6.8 \cdot 10^{+31}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -4.8 \cdot 10^{-93}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{-7}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -7.1e258 or -1.6e190 < y < -6.7999999999999996e31Initial program 100.0%
Taylor expanded in x around inf 66.9%
Taylor expanded in y around inf 66.9%
if -7.1e258 < y < -1.6e190 or -6.7999999999999996e31 < y < -4.8000000000000002e-93 or 8.1999999999999998e-7 < y Initial program 100.0%
Taylor expanded in x around 0 63.7%
if -4.8000000000000002e-93 < y < 8.1999999999999998e-7Initial program 100.0%
Taylor expanded in y around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification72.1%
(FPCore (x y) :precision binary64 (if (or (<= x -5e-38) (not (<= x 1.08e-14))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -5e-38) || !(x <= 1.08e-14)) {
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-38)) .or. (.not. (x <= 1.08d-14))) 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-38) || !(x <= 1.08e-14)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5e-38) or not (x <= 1.08e-14): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -5e-38) || !(x <= 1.08e-14)) 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-38) || ~((x <= 1.08e-14))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5e-38], N[Not[LessEqual[x, 1.08e-14]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-38} \lor \neg \left(x \leq 1.08 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -5.00000000000000033e-38 or 1.08000000000000004e-14 < x Initial program 100.0%
Taylor expanded in x around inf 97.3%
if -5.00000000000000033e-38 < x < 1.08000000000000004e-14Initial program 100.0%
Taylor expanded in x around 0 78.8%
Final simplification88.5%
(FPCore (x y) :precision binary64 (if (or (<= y -1.18e-92) (not (<= y 1450000.0))) (* y (+ x 1.0)) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -1.18e-92) || !(y <= 1450000.0)) {
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 <= (-1.18d-92)) .or. (.not. (y <= 1450000.0d0))) 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 <= -1.18e-92) || !(y <= 1450000.0)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.18e-92) or not (y <= 1450000.0): tmp = y * (x + 1.0) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.18e-92) || !(y <= 1450000.0)) 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 <= -1.18e-92) || ~((y <= 1450000.0))) tmp = y * (x + 1.0); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.18e-92], N[Not[LessEqual[y, 1450000.0]], $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 -1.18 \cdot 10^{-92} \lor \neg \left(y \leq 1450000\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -1.18e-92 or 1.45e6 < y Initial program 100.0%
Taylor expanded in y around inf 96.9%
if -1.18e-92 < y < 1.45e6Initial program 100.0%
Taylor expanded in x around inf 82.6%
Final simplification90.9%
(FPCore (x y) :precision binary64 (if (<= y -1.18e-92) y (if (<= y 1.9e-9) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.18e-92) {
tmp = y;
} else if (y <= 1.9e-9) {
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 <= (-1.18d-92)) then
tmp = y
else if (y <= 1.9d-9) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.18e-92) {
tmp = y;
} else if (y <= 1.9e-9) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.18e-92: tmp = y elif y <= 1.9e-9: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.18e-92) tmp = y; elseif (y <= 1.9e-9) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.18e-92) tmp = y; elseif (y <= 1.9e-9) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.18e-92], y, If[LessEqual[y, 1.9e-9], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.18 \cdot 10^{-92}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-9}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.18e-92 or 1.90000000000000006e-9 < y Initial program 100.0%
Taylor expanded in x around 0 54.3%
if -1.18e-92 < y < 1.90000000000000006e-9Initial program 100.0%
Taylor expanded in y around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification66.0%
(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 40.1%
Final simplification40.1%
herbie shell --seed 2024043
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))