
(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%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.2e+140)
(* x y)
(if (<= y -6.8e-65)
y
(if (<= y 1.35e-59) (- x) (if (<= y 2.05e+176) y (* x y))))))
double code(double x, double y) {
double tmp;
if (y <= -1.2e+140) {
tmp = x * y;
} else if (y <= -6.8e-65) {
tmp = y;
} else if (y <= 1.35e-59) {
tmp = -x;
} else if (y <= 2.05e+176) {
tmp = y;
} 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 <= (-1.2d+140)) then
tmp = x * y
else if (y <= (-6.8d-65)) then
tmp = y
else if (y <= 1.35d-59) then
tmp = -x
else if (y <= 2.05d+176) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.2e+140) {
tmp = x * y;
} else if (y <= -6.8e-65) {
tmp = y;
} else if (y <= 1.35e-59) {
tmp = -x;
} else if (y <= 2.05e+176) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.2e+140: tmp = x * y elif y <= -6.8e-65: tmp = y elif y <= 1.35e-59: tmp = -x elif y <= 2.05e+176: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.2e+140) tmp = Float64(x * y); elseif (y <= -6.8e-65) tmp = y; elseif (y <= 1.35e-59) tmp = Float64(-x); elseif (y <= 2.05e+176) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.2e+140) tmp = x * y; elseif (y <= -6.8e-65) tmp = y; elseif (y <= 1.35e-59) tmp = -x; elseif (y <= 2.05e+176) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.2e+140], N[(x * y), $MachinePrecision], If[LessEqual[y, -6.8e-65], y, If[LessEqual[y, 1.35e-59], (-x), If[LessEqual[y, 2.05e+176], y, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+140}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -6.8 \cdot 10^{-65}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-59}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+176}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.2e140 or 2.05e176 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 68.8%
if -1.2e140 < y < -6.79999999999999973e-65 or 1.3499999999999999e-59 < y < 2.05e176Initial program 100.0%
Taylor expanded in x around 0 61.5%
if -6.79999999999999973e-65 < y < 1.3499999999999999e-59Initial program 100.0%
Taylor expanded in y around 0 81.9%
neg-mul-181.9%
Simplified81.9%
Final simplification71.9%
(FPCore (x y) :precision binary64 (if (or (<= x -12500.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -12500.0) || !(x <= 1.0)) {
tmp = x * (y + -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 ((x <= (-12500.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (y + (-1.0d0))
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -12500.0) || !(x <= 1.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -12500.0) or not (x <= 1.0): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -12500.0) || !(x <= 1.0)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -12500.0) || ~((x <= 1.0))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -12500.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -12500 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -12500 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.9%
if -12500 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around 0 99.8%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= y -5.5e+137) (not (<= y 1.35e+175))) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -5.5e+137) || !(y <= 1.35e+175)) {
tmp = x * y;
} 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 <= (-5.5d+137)) .or. (.not. (y <= 1.35d+175))) then
tmp = x * y
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -5.5e+137) || !(y <= 1.35e+175)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5.5e+137) or not (y <= 1.35e+175): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5.5e+137) || !(y <= 1.35e+175)) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -5.5e+137) || ~((y <= 1.35e+175))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5.5e+137], N[Not[LessEqual[y, 1.35e+175]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+137} \lor \neg \left(y \leq 1.35 \cdot 10^{+175}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -5.5000000000000002e137 or 1.35e175 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 68.8%
if -5.5000000000000002e137 < y < 1.35e175Initial program 100.0%
Taylor expanded in x around 0 88.2%
Taylor expanded in y around 0 88.2%
Final simplification83.9%
(FPCore (x y) :precision binary64 (if (<= y -8.8e-66) y (if (<= y 2.2e-59) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -8.8e-66) {
tmp = y;
} else if (y <= 2.2e-59) {
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 <= (-8.8d-66)) then
tmp = y
else if (y <= 2.2d-59) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -8.8e-66) {
tmp = y;
} else if (y <= 2.2e-59) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.8e-66: tmp = y elif y <= 2.2e-59: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -8.8e-66) tmp = y; elseif (y <= 2.2e-59) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8.8e-66) tmp = y; elseif (y <= 2.2e-59) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.8e-66], y, If[LessEqual[y, 2.2e-59], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-66}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-59}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -8.8000000000000004e-66 or 2.1999999999999999e-59 < y Initial program 100.0%
Taylor expanded in x around 0 50.9%
if -8.8000000000000004e-66 < y < 2.1999999999999999e-59Initial program 100.0%
Taylor expanded in y around 0 81.9%
neg-mul-181.9%
Simplified81.9%
(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 37.8%
herbie shell --seed 2024157
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))