
(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 8 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%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -4.1e+260)
(* x y)
(if (<= y -3.2e+241)
y
(if (<= y -1.0)
(* x y)
(if (<= y 2.8e-20) (- x) (if (<= y 2.85e+107) y (* x y)))))))
double code(double x, double y) {
double tmp;
if (y <= -4.1e+260) {
tmp = x * y;
} else if (y <= -3.2e+241) {
tmp = y;
} else if (y <= -1.0) {
tmp = x * y;
} else if (y <= 2.8e-20) {
tmp = -x;
} else if (y <= 2.85e+107) {
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 <= (-4.1d+260)) then
tmp = x * y
else if (y <= (-3.2d+241)) then
tmp = y
else if (y <= (-1.0d0)) then
tmp = x * y
else if (y <= 2.8d-20) then
tmp = -x
else if (y <= 2.85d+107) 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 <= -4.1e+260) {
tmp = x * y;
} else if (y <= -3.2e+241) {
tmp = y;
} else if (y <= -1.0) {
tmp = x * y;
} else if (y <= 2.8e-20) {
tmp = -x;
} else if (y <= 2.85e+107) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.1e+260: tmp = x * y elif y <= -3.2e+241: tmp = y elif y <= -1.0: tmp = x * y elif y <= 2.8e-20: tmp = -x elif y <= 2.85e+107: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.1e+260) tmp = Float64(x * y); elseif (y <= -3.2e+241) tmp = y; elseif (y <= -1.0) tmp = Float64(x * y); elseif (y <= 2.8e-20) tmp = Float64(-x); elseif (y <= 2.85e+107) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.1e+260) tmp = x * y; elseif (y <= -3.2e+241) tmp = y; elseif (y <= -1.0) tmp = x * y; elseif (y <= 2.8e-20) tmp = -x; elseif (y <= 2.85e+107) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.1e+260], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.2e+241], y, If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.8e-20], (-x), If[LessEqual[y, 2.85e+107], y, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+260}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{+241}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-20}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 2.85 \cdot 10^{+107}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -4.10000000000000025e260 or -3.20000000000000004e241 < y < -1 or 2.84999999999999986e107 < y Initial program 100.0%
Taylor expanded in x around inf 60.3%
Taylor expanded in y around inf 59.0%
if -4.10000000000000025e260 < y < -3.20000000000000004e241 or 2.8000000000000003e-20 < y < 2.84999999999999986e107Initial program 100.0%
Taylor expanded in y around inf 100.0%
associate-+r+100.0%
+-commutative100.0%
associate-+l+100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 73.2%
if -1 < y < 2.8000000000000003e-20Initial program 100.0%
Taylor expanded in y around 0 78.0%
neg-mul-178.0%
Simplified78.0%
Final simplification69.7%
(FPCore (x y)
:precision binary64
(if (<= y -6.8e+261)
(* x y)
(if (<= y -3.8e+239)
y
(if (or (<= y -1.85e+34) (not (<= y 2.1e+108))) (* x y) (- y x)))))
double code(double x, double y) {
double tmp;
if (y <= -6.8e+261) {
tmp = x * y;
} else if (y <= -3.8e+239) {
tmp = y;
} else if ((y <= -1.85e+34) || !(y <= 2.1e+108)) {
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 <= (-6.8d+261)) then
tmp = x * y
else if (y <= (-3.8d+239)) then
tmp = y
else if ((y <= (-1.85d+34)) .or. (.not. (y <= 2.1d+108))) 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 <= -6.8e+261) {
tmp = x * y;
} else if (y <= -3.8e+239) {
tmp = y;
} else if ((y <= -1.85e+34) || !(y <= 2.1e+108)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.8e+261: tmp = x * y elif y <= -3.8e+239: tmp = y elif (y <= -1.85e+34) or not (y <= 2.1e+108): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (y <= -6.8e+261) tmp = Float64(x * y); elseif (y <= -3.8e+239) tmp = y; elseif ((y <= -1.85e+34) || !(y <= 2.1e+108)) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.8e+261) tmp = x * y; elseif (y <= -3.8e+239) tmp = y; elseif ((y <= -1.85e+34) || ~((y <= 2.1e+108))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.8e+261], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.8e+239], y, If[Or[LessEqual[y, -1.85e+34], N[Not[LessEqual[y, 2.1e+108]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+261}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.8 \cdot 10^{+239}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -1.85 \cdot 10^{+34} \lor \neg \left(y \leq 2.1 \cdot 10^{+108}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -6.8e261 or -3.8000000000000001e239 < y < -1.85000000000000004e34 or 2.1000000000000001e108 < y Initial program 100.0%
Taylor expanded in x around inf 60.9%
Taylor expanded in y around inf 60.9%
if -6.8e261 < y < -3.8000000000000001e239Initial program 100.0%
Taylor expanded in y around inf 100.0%
associate-+r+100.0%
+-commutative100.0%
associate-+l+100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if -1.85000000000000004e34 < y < 2.1000000000000001e108Initial program 100.0%
Taylor expanded in x around 0 92.5%
Final simplification80.7%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.9e-39))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.9e-39)) {
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 <= (-1.0d0)) .or. (.not. (x <= 1.9d-39))) 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 <= -1.0) || !(x <= 1.9e-39)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 1.9e-39): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.9e-39)) 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 <= -1.0) || ~((x <= 1.9e-39))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.9e-39]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1.9 \cdot 10^{-39}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 1.9000000000000001e-39 < x Initial program 100.0%
Taylor expanded in x around inf 98.3%
if -1 < x < 1.9000000000000001e-39Initial program 100.0%
Taylor expanded in x around 0 99.3%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (or (<= y -225.0) (not (<= y 4.5e-20))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -225.0) || !(y <= 4.5e-20)) {
tmp = y * (x + 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 ((y <= (-225.0d0)) .or. (.not. (y <= 4.5d-20))) then
tmp = y * (x + 1.0d0)
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -225.0) || !(y <= 4.5e-20)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -225.0) or not (y <= 4.5e-20): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -225.0) || !(y <= 4.5e-20)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -225.0) || ~((y <= 4.5e-20))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -225.0], N[Not[LessEqual[y, 4.5e-20]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -225 \lor \neg \left(y \leq 4.5 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -225 or 4.5000000000000001e-20 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
associate-+r+100.0%
+-commutative100.0%
associate-+l+100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 98.8%
+-commutative98.8%
Simplified98.8%
if -225 < y < 4.5000000000000001e-20Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.4e-47) (not (<= x 9e-40))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.4e-47) || !(x <= 9e-40)) {
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 <= (-1.4d-47)) .or. (.not. (x <= 9d-40))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.4e-47) || !(x <= 9e-40)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.4e-47) or not (x <= 9e-40): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.4e-47) || !(x <= 9e-40)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.4e-47) || ~((x <= 9e-40))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.4e-47], N[Not[LessEqual[x, 9e-40]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-47} \lor \neg \left(x \leq 9 \cdot 10^{-40}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.39999999999999996e-47 or 9.0000000000000002e-40 < x Initial program 100.0%
Taylor expanded in y around 0 51.5%
neg-mul-151.5%
Simplified51.5%
if -1.39999999999999996e-47 < x < 9.0000000000000002e-40Initial program 100.0%
Taylor expanded in y around inf 99.9%
associate-+r+99.9%
+-commutative99.9%
associate-+l+99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 81.5%
Final simplification63.5%
(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 y around inf 87.2%
associate-+r+87.2%
+-commutative87.2%
associate-+l+87.2%
mul-1-neg87.2%
unsub-neg87.2%
Simplified87.2%
Taylor expanded in x around 0 36.0%
Final simplification36.0%
herbie shell --seed 2024115
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))