
(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 -3.3e+84)
y
(if (<= y -4.4e+17)
(* x y)
(if (<= y -900.0) y (if (<= y 5.5e-7) (- x) y)))))
double code(double x, double y) {
double tmp;
if (y <= -3.3e+84) {
tmp = y;
} else if (y <= -4.4e+17) {
tmp = x * y;
} else if (y <= -900.0) {
tmp = y;
} else if (y <= 5.5e-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 <= (-3.3d+84)) then
tmp = y
else if (y <= (-4.4d+17)) then
tmp = x * y
else if (y <= (-900.0d0)) then
tmp = y
else if (y <= 5.5d-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 <= -3.3e+84) {
tmp = y;
} else if (y <= -4.4e+17) {
tmp = x * y;
} else if (y <= -900.0) {
tmp = y;
} else if (y <= 5.5e-7) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.3e+84: tmp = y elif y <= -4.4e+17: tmp = x * y elif y <= -900.0: tmp = y elif y <= 5.5e-7: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -3.3e+84) tmp = y; elseif (y <= -4.4e+17) tmp = Float64(x * y); elseif (y <= -900.0) tmp = y; elseif (y <= 5.5e-7) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.3e+84) tmp = y; elseif (y <= -4.4e+17) tmp = x * y; elseif (y <= -900.0) tmp = y; elseif (y <= 5.5e-7) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.3e+84], y, If[LessEqual[y, -4.4e+17], N[(x * y), $MachinePrecision], If[LessEqual[y, -900.0], y, If[LessEqual[y, 5.5e-7], (-x), y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+84}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -4.4 \cdot 10^{+17}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -900:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-7}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3.30000000000000017e84 or -4.4e17 < y < -900 or 5.5000000000000003e-7 < y Initial program 100.0%
Taylor expanded in x around 0 62.7%
if -3.30000000000000017e84 < y < -4.4e17Initial program 100.0%
Taylor expanded in y around inf 100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 66.1%
*-commutative66.1%
Simplified66.1%
if -900 < y < 5.5000000000000003e-7Initial program 100.0%
Taylor expanded in y around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification72.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.75e-6))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.75e-6)) {
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.75d-6))) 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.75e-6)) {
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.75e-6): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.75e-6)) 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.75e-6))) 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.75e-6]], $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.75 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 1.74999999999999997e-6 < x Initial program 100.0%
Taylor expanded in x around inf 97.8%
if -1 < x < 1.74999999999999997e-6Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 99.5%
Final simplification98.7%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- (* x y) x) (if (<= x 1.75e-6) (- y x) (* x (+ y -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (x * y) - x;
} else if (x <= 1.75e-6) {
tmp = y - x;
} 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 (x <= (-1.0d0)) then
tmp = (x * y) - x
else if (x <= 1.75d-6) then
tmp = y - x
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (x * y) - x;
} else if (x <= 1.75e-6) {
tmp = y - x;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = (x * y) - x elif x <= 1.75e-6: tmp = y - x else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(x * y) - x); elseif (x <= 1.75e-6) tmp = Float64(y - x); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = (x * y) - x; elseif (x <= 1.75e-6) tmp = y - x; else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 1.75e-6], N[(y - x), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot y - x\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{-6}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 98.9%
*-commutative98.9%
Simplified98.9%
if -1 < x < 1.74999999999999997e-6Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 99.5%
if 1.74999999999999997e-6 < x Initial program 99.9%
Taylor expanded in x around inf 96.4%
Final simplification98.7%
(FPCore (x y) :precision binary64 (if (or (<= x 3.35e+53) (not (<= x 3.05e+122))) (- y x) (* x y)))
double code(double x, double y) {
double tmp;
if ((x <= 3.35e+53) || !(x <= 3.05e+122)) {
tmp = y - 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 <= 3.35d+53) .or. (.not. (x <= 3.05d+122))) then
tmp = y - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= 3.35e+53) || !(x <= 3.05e+122)) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= 3.35e+53) or not (x <= 3.05e+122): tmp = y - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if ((x <= 3.35e+53) || !(x <= 3.05e+122)) tmp = Float64(y - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= 3.35e+53) || ~((x <= 3.05e+122))) tmp = y - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, 3.35e+53], N[Not[LessEqual[x, 3.05e+122]], $MachinePrecision]], N[(y - x), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.35 \cdot 10^{+53} \lor \neg \left(x \leq 3.05 \cdot 10^{+122}\right):\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 3.3499999999999999e53 or 3.0499999999999999e122 < x Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 79.6%
if 3.3499999999999999e53 < x < 3.0499999999999999e122Initial program 100.0%
Taylor expanded in y around inf 77.8%
distribute-lft-in77.8%
*-rgt-identity77.8%
+-commutative77.8%
Applied egg-rr77.8%
Taylor expanded in x around inf 77.8%
*-commutative77.8%
Simplified77.8%
Final simplification79.5%
(FPCore (x y) :precision binary64 (if (<= y -900.0) y (if (<= y 5e-7) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -900.0) {
tmp = y;
} else if (y <= 5e-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 <= (-900.0d0)) then
tmp = y
else if (y <= 5d-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 <= -900.0) {
tmp = y;
} else if (y <= 5e-7) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -900.0: tmp = y elif y <= 5e-7: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -900.0) tmp = y; elseif (y <= 5e-7) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -900.0) tmp = y; elseif (y <= 5e-7) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -900.0], y, If[LessEqual[y, 5e-7], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -900:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-7}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -900 or 4.99999999999999977e-7 < y Initial program 100.0%
Taylor expanded in x around 0 59.0%
if -900 < y < 4.99999999999999977e-7Initial program 100.0%
Taylor expanded in y around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification69.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)
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.0%
Final simplification40.0%
herbie shell --seed 2024076
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))