
(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%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
+-commutative100.0%
neg-mul-1100.0%
*-commutative100.0%
distribute-lft-out100.0%
*-lft-identity100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -2.3e+238) (* x y) (if (<= y 1.1e+62) (- y x) (if (<= y 1.15e+126) (* x y) y))))
double code(double x, double y) {
double tmp;
if (y <= -2.3e+238) {
tmp = x * y;
} else if (y <= 1.1e+62) {
tmp = y - x;
} else if (y <= 1.15e+126) {
tmp = x * y;
} 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 <= (-2.3d+238)) then
tmp = x * y
else if (y <= 1.1d+62) then
tmp = y - x
else if (y <= 1.15d+126) then
tmp = x * y
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.3e+238) {
tmp = x * y;
} else if (y <= 1.1e+62) {
tmp = y - x;
} else if (y <= 1.15e+126) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e+238: tmp = x * y elif y <= 1.1e+62: tmp = y - x elif y <= 1.15e+126: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e+238) tmp = Float64(x * y); elseif (y <= 1.1e+62) tmp = Float64(y - x); elseif (y <= 1.15e+126) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.3e+238) tmp = x * y; elseif (y <= 1.1e+62) tmp = y - x; elseif (y <= 1.15e+126) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e+238], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.1e+62], N[(y - x), $MachinePrecision], If[LessEqual[y, 1.15e+126], N[(x * y), $MachinePrecision], y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+238}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+62}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+126}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.30000000000000003e238 or 1.10000000000000007e62 < y < 1.15e126Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 73.0%
*-commutative73.0%
Simplified73.0%
if -2.30000000000000003e238 < y < 1.10000000000000007e62Initial program 100.0%
Taylor expanded in x around 0 84.7%
if 1.15e126 < y Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 55.6%
Final simplification78.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.075))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.075)) {
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 <= 0.075d0))) 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 <= 0.075)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.075): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.075)) 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 <= 0.075))) 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, 0.075]], $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 0.075\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 0.0749999999999999972 < x Initial program 100.0%
Taylor expanded in x around inf 99.6%
if -1 < x < 0.0749999999999999972Initial program 100.0%
Taylor expanded in x around 0 98.0%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (<= y -2.6e+238) (* x y) (if (<= y -33000000000.0) y (if (<= y 2.7e-11) (- x) y))))
double code(double x, double y) {
double tmp;
if (y <= -2.6e+238) {
tmp = x * y;
} else if (y <= -33000000000.0) {
tmp = y;
} else if (y <= 2.7e-11) {
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 <= (-2.6d+238)) then
tmp = x * y
else if (y <= (-33000000000.0d0)) then
tmp = y
else if (y <= 2.7d-11) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.6e+238) {
tmp = x * y;
} else if (y <= -33000000000.0) {
tmp = y;
} else if (y <= 2.7e-11) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.6e+238: tmp = x * y elif y <= -33000000000.0: tmp = y elif y <= 2.7e-11: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.6e+238) tmp = Float64(x * y); elseif (y <= -33000000000.0) tmp = y; elseif (y <= 2.7e-11) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.6e+238) tmp = x * y; elseif (y <= -33000000000.0) tmp = y; elseif (y <= 2.7e-11) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.6e+238], N[(x * y), $MachinePrecision], If[LessEqual[y, -33000000000.0], y, If[LessEqual[y, 2.7e-11], (-x), y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+238}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -33000000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-11}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.6e238Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 77.9%
*-commutative77.9%
Simplified77.9%
if -2.6e238 < y < -3.3e10 or 2.70000000000000005e-11 < y Initial program 99.9%
*-commutative99.9%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 54.6%
if -3.3e10 < y < 2.70000000000000005e-11Initial program 100.0%
Taylor expanded in y around 0 76.6%
mul-1-neg76.6%
Simplified76.6%
Final simplification66.6%
(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-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -33000000000.0) y (if (<= y 5.5e-15) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -33000000000.0) {
tmp = y;
} else if (y <= 5.5e-15) {
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 <= (-33000000000.0d0)) then
tmp = y
else if (y <= 5.5d-15) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -33000000000.0) {
tmp = y;
} else if (y <= 5.5e-15) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -33000000000.0: tmp = y elif y <= 5.5e-15: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -33000000000.0) tmp = y; elseif (y <= 5.5e-15) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -33000000000.0) tmp = y; elseif (y <= 5.5e-15) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -33000000000.0], y, If[LessEqual[y, 5.5e-15], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -33000000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-15}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3.3e10 or 5.5000000000000002e-15 < y Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 50.3%
if -3.3e10 < y < 5.5000000000000002e-15Initial program 100.0%
Taylor expanded in y around 0 76.6%
mul-1-neg76.6%
Simplified76.6%
Final simplification62.2%
(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%
*-commutative100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 38.5%
Final simplification38.5%
herbie shell --seed 2023326
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))