
(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 y) x))
double code(double x, double y) {
return fma(x, y, y) - x;
}
function code(x, y) return Float64(fma(x, y, y) - x) end
code[x_, y_] := N[(N[(x * y + y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, y\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
fma-def100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -18500000.0)
(* x y)
(if (<= x -1.05e-60)
(- x)
(if (<= x 1.6e-28) y (if (<= x 1.3e+195) (- x) (* x y))))))
double code(double x, double y) {
double tmp;
if (x <= -18500000.0) {
tmp = x * y;
} else if (x <= -1.05e-60) {
tmp = -x;
} else if (x <= 1.6e-28) {
tmp = y;
} else if (x <= 1.3e+195) {
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 <= (-18500000.0d0)) then
tmp = x * y
else if (x <= (-1.05d-60)) then
tmp = -x
else if (x <= 1.6d-28) then
tmp = y
else if (x <= 1.3d+195) 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 <= -18500000.0) {
tmp = x * y;
} else if (x <= -1.05e-60) {
tmp = -x;
} else if (x <= 1.6e-28) {
tmp = y;
} else if (x <= 1.3e+195) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -18500000.0: tmp = x * y elif x <= -1.05e-60: tmp = -x elif x <= 1.6e-28: tmp = y elif x <= 1.3e+195: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -18500000.0) tmp = Float64(x * y); elseif (x <= -1.05e-60) tmp = Float64(-x); elseif (x <= 1.6e-28) tmp = y; elseif (x <= 1.3e+195) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -18500000.0) tmp = x * y; elseif (x <= -1.05e-60) tmp = -x; elseif (x <= 1.6e-28) tmp = y; elseif (x <= 1.3e+195) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -18500000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.05e-60], (-x), If[LessEqual[x, 1.6e-28], y, If[LessEqual[x, 1.3e+195], (-x), N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -18500000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{-60}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-28}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{+195}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.85e7 or 1.30000000000000001e195 < x Initial program 100.0%
Taylor expanded in y around inf 64.4%
Taylor expanded in x around 0 64.4%
Taylor expanded in x around inf 63.9%
if -1.85e7 < x < -1.04999999999999996e-60 or 1.59999999999999991e-28 < x < 1.30000000000000001e195Initial program 100.0%
Taylor expanded in y around 0 57.4%
neg-mul-157.4%
Simplified57.4%
if -1.04999999999999996e-60 < x < 1.59999999999999991e-28Initial program 100.0%
Taylor expanded in x around 0 79.7%
Final simplification69.3%
(FPCore (x y) :precision binary64 (if (or (<= y -2.2e-14) (not (<= y 4.8e-36))) (* y (+ x 1.0)) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -2.2e-14) || !(y <= 4.8e-36)) {
tmp = y * (x + 1.0);
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2.2d-14)) .or. (.not. (y <= 4.8d-36))) then
tmp = y * (x + 1.0d0)
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.2e-14) || !(y <= 4.8e-36)) {
tmp = y * (x + 1.0);
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.2e-14) or not (y <= 4.8e-36): tmp = y * (x + 1.0) else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.2e-14) || !(y <= 4.8e-36)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.2e-14) || ~((y <= 4.8e-36))) tmp = y * (x + 1.0); else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.2e-14], N[Not[LessEqual[y, 4.8e-36]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-14} \lor \neg \left(y \leq 4.8 \cdot 10^{-36}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -2.2000000000000001e-14 or 4.8e-36 < y Initial program 100.0%
Taylor expanded in y around inf 96.2%
if -2.2000000000000001e-14 < y < 4.8e-36Initial program 100.0%
Taylor expanded in y around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification88.2%
(FPCore (x y) :precision binary64 (if (or (<= y -31000000000000.0) (not (<= y 3.6e-33))) (* y (+ x 1.0)) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -31000000000000.0) || !(y <= 3.6e-33)) {
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 <= (-31000000000000.0d0)) .or. (.not. (y <= 3.6d-33))) 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 <= -31000000000000.0) || !(y <= 3.6e-33)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -31000000000000.0) or not (y <= 3.6e-33): tmp = y * (x + 1.0) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -31000000000000.0) || !(y <= 3.6e-33)) 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 <= -31000000000000.0) || ~((y <= 3.6e-33))) tmp = y * (x + 1.0); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -31000000000000.0], N[Not[LessEqual[y, 3.6e-33]], $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 -31000000000000 \lor \neg \left(y \leq 3.6 \cdot 10^{-33}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -3.1e13 or 3.60000000000000034e-33 < y Initial program 100.0%
Taylor expanded in y around inf 97.5%
if -3.1e13 < y < 3.60000000000000034e-33Initial program 100.0%
Taylor expanded in x around inf 78.1%
Final simplification89.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 (if (<= y -31000000000000.0) y (if (<= y 5.5e-87) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -31000000000000.0) {
tmp = y;
} else if (y <= 5.5e-87) {
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 <= (-31000000000000.0d0)) then
tmp = y
else if (y <= 5.5d-87) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -31000000000000.0) {
tmp = y;
} else if (y <= 5.5e-87) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -31000000000000.0: tmp = y elif y <= 5.5e-87: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -31000000000000.0) tmp = y; elseif (y <= 5.5e-87) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -31000000000000.0) tmp = y; elseif (y <= 5.5e-87) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -31000000000000.0], y, If[LessEqual[y, 5.5e-87], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -31000000000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-87}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3.1e13 or 5.5000000000000004e-87 < y Initial program 100.0%
Taylor expanded in x around 0 51.6%
if -3.1e13 < y < 5.5000000000000004e-87Initial program 100.0%
Taylor expanded in y around 0 74.9%
neg-mul-174.9%
Simplified74.9%
Final simplification61.3%
(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 38.6%
Final simplification38.6%
herbie shell --seed 2023257
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))