
(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 9 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%
associate-+r+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x y) (if (<= x 4.8e-42) y (if (<= x 2.4e+62) (- x) (* x y)))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * y;
} else if (x <= 4.8e-42) {
tmp = y;
} else if (x <= 2.4e+62) {
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 <= (-1.0d0)) then
tmp = x * y
else if (x <= 4.8d-42) then
tmp = y
else if (x <= 2.4d+62) 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 <= -1.0) {
tmp = x * y;
} else if (x <= 4.8e-42) {
tmp = y;
} else if (x <= 2.4e+62) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x * y elif x <= 4.8e-42: tmp = y elif x <= 2.4e+62: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * y); elseif (x <= 4.8e-42) tmp = y; elseif (x <= 2.4e+62) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = x * y; elseif (x <= 4.8e-42) tmp = y; elseif (x <= 2.4e+62) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.8e-42], y, If[LessEqual[x, 2.4e+62], (-x), N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-42}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{+62}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1 or 2.4e62 < x Initial program 99.9%
Taylor expanded in y around inf 59.8%
distribute-lft-in59.8%
*-rgt-identity59.8%
+-commutative59.8%
Applied egg-rr59.8%
Taylor expanded in x around inf 59.8%
if -1 < x < 4.80000000000000005e-42Initial program 100.0%
Taylor expanded in x around 0 76.1%
if 4.80000000000000005e-42 < x < 2.4e62Initial program 99.9%
Taylor expanded in y around 0 64.4%
neg-mul-164.4%
Simplified64.4%
Final simplification68.0%
(FPCore (x y) :precision binary64 (if (or (<= x -4.2e-92) (not (<= x 8.6e-40))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -4.2e-92) || !(x <= 8.6e-40)) {
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 <= (-4.2d-92)) .or. (.not. (x <= 8.6d-40))) 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 <= -4.2e-92) || !(x <= 8.6e-40)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.2e-92) or not (x <= 8.6e-40): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.2e-92) || !(x <= 8.6e-40)) 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 <= -4.2e-92) || ~((x <= 8.6e-40))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.2e-92], N[Not[LessEqual[x, 8.6e-40]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-92} \lor \neg \left(x \leq 8.6 \cdot 10^{-40}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.2e-92 or 8.6000000000000005e-40 < x Initial program 99.9%
Taylor expanded in x around inf 91.3%
if -4.2e-92 < x < 8.6000000000000005e-40Initial program 100.0%
Taylor expanded in x around 0 84.6%
Final simplification88.6%
(FPCore (x y) :precision binary64 (if (or (<= y -4e-65) (not (<= y 45000000.0))) (* y (+ x 1.0)) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -4e-65) || !(y <= 45000000.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 <= (-4d-65)) .or. (.not. (y <= 45000000.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 <= -4e-65) || !(y <= 45000000.0)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4e-65) or not (y <= 45000000.0): tmp = y * (x + 1.0) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -4e-65) || !(y <= 45000000.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 <= -4e-65) || ~((y <= 45000000.0))) tmp = y * (x + 1.0); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4e-65], N[Not[LessEqual[y, 45000000.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 -4 \cdot 10^{-65} \lor \neg \left(y \leq 45000000\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -3.99999999999999969e-65 or 4.5e7 < y Initial program 99.9%
Taylor expanded in y around inf 95.7%
if -3.99999999999999969e-65 < y < 4.5e7Initial program 100.0%
Taylor expanded in x around inf 76.8%
Final simplification87.7%
(FPCore (x y) :precision binary64 (if (<= y -4e-65) (+ y (* x y)) (if (<= y 38000000.0) (* x (+ y -1.0)) (* y (+ x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -4e-65) {
tmp = y + (x * y);
} else if (y <= 38000000.0) {
tmp = x * (y + -1.0);
} else {
tmp = y * (x + 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 <= (-4d-65)) then
tmp = y + (x * y)
else if (y <= 38000000.0d0) then
tmp = x * (y + (-1.0d0))
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4e-65) {
tmp = y + (x * y);
} else if (y <= 38000000.0) {
tmp = x * (y + -1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4e-65: tmp = y + (x * y) elif y <= 38000000.0: tmp = x * (y + -1.0) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -4e-65) tmp = Float64(y + Float64(x * y)); elseif (y <= 38000000.0) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4e-65) tmp = y + (x * y); elseif (y <= 38000000.0) tmp = x * (y + -1.0); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4e-65], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 38000000.0], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-65}:\\
\;\;\;\;y + x \cdot y\\
\mathbf{elif}\;y \leq 38000000:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -3.99999999999999969e-65Initial program 100.0%
Taylor expanded in y around inf 93.2%
distribute-lft-in93.2%
*-rgt-identity93.2%
+-commutative93.2%
Applied egg-rr93.2%
if -3.99999999999999969e-65 < y < 3.8e7Initial program 100.0%
Taylor expanded in x around inf 76.8%
if 3.8e7 < y Initial program 99.9%
Taylor expanded in y around inf 98.8%
Final simplification87.7%
(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 (* x y)) x))
double code(double x, double y) {
return (y + (x * y)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + (x * y)) - x
end function
public static double code(double x, double y) {
return (y + (x * y)) - x;
}
def code(x, y): return (y + (x * y)) - x
function code(x, y) return Float64(Float64(y + Float64(x * y)) - x) end
function tmp = code(x, y) tmp = (y + (x * y)) - x; end
code[x_, y_] := N[(N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x \cdot y\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -6e-94) (not (<= x 8.5e-40))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -6e-94) || !(x <= 8.5e-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 <= (-6d-94)) .or. (.not. (x <= 8.5d-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 <= -6e-94) || !(x <= 8.5e-40)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6e-94) or not (x <= 8.5e-40): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -6e-94) || !(x <= 8.5e-40)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -6e-94) || ~((x <= 8.5e-40))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6e-94], N[Not[LessEqual[x, 8.5e-40]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-94} \lor \neg \left(x \leq 8.5 \cdot 10^{-40}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.0000000000000003e-94 or 8.4999999999999998e-40 < x Initial program 99.9%
Taylor expanded in y around 0 44.1%
neg-mul-144.1%
Simplified44.1%
if -6.0000000000000003e-94 < x < 8.4999999999999998e-40Initial program 100.0%
Taylor expanded in x around 0 84.6%
Final simplification59.9%
(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 2023320
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))