
(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-lft-in100.0%
*-rgt-identity100.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.9e-19)
y
(if (<= y 6.8e-73)
(- x)
(if (<= y 5.4e+14) y (if (<= y 2.2e+200) (* x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.9e-19) {
tmp = y;
} else if (y <= 6.8e-73) {
tmp = -x;
} else if (y <= 5.4e+14) {
tmp = y;
} else if (y <= 2.2e+200) {
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 <= (-1.9d-19)) then
tmp = y
else if (y <= 6.8d-73) then
tmp = -x
else if (y <= 5.4d+14) then
tmp = y
else if (y <= 2.2d+200) 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 <= -1.9e-19) {
tmp = y;
} else if (y <= 6.8e-73) {
tmp = -x;
} else if (y <= 5.4e+14) {
tmp = y;
} else if (y <= 2.2e+200) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.9e-19: tmp = y elif y <= 6.8e-73: tmp = -x elif y <= 5.4e+14: tmp = y elif y <= 2.2e+200: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.9e-19) tmp = y; elseif (y <= 6.8e-73) tmp = Float64(-x); elseif (y <= 5.4e+14) tmp = y; elseif (y <= 2.2e+200) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.9e-19) tmp = y; elseif (y <= 6.8e-73) tmp = -x; elseif (y <= 5.4e+14) tmp = y; elseif (y <= 2.2e+200) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.9e-19], y, If[LessEqual[y, 6.8e-73], (-x), If[LessEqual[y, 5.4e+14], y, If[LessEqual[y, 2.2e+200], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-19}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-73}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+14}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+200}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.9e-19 or 6.80000000000000042e-73 < y < 5.4e14 or 2.2e200 < y Initial program 100.0%
Taylor expanded in x around 0 62.8%
if -1.9e-19 < y < 6.80000000000000042e-73Initial program 100.0%
Taylor expanded in y around 0 83.3%
neg-mul-183.3%
Simplified83.3%
if 5.4e14 < y < 2.2e200Initial program 100.0%
Taylor expanded in y around inf 99.9%
Taylor expanded in x around inf 67.5%
Final simplification71.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 5.6e-5))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 5.6e-5)) {
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 <= (-1.0d0)) .or. (.not. (y <= 5.6d-5))) 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 <= -1.0) || !(y <= 5.6e-5)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 5.6e-5): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 5.6e-5)) 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 <= -1.0) || ~((y <= 5.6e-5))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 5.6e-5]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 5.6 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1 or 5.59999999999999992e-5 < y Initial program 100.0%
Taylor expanded in y around inf 98.5%
if -1 < y < 5.59999999999999992e-5Initial program 100.0%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around 0 99.8%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.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 <= (-1.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 <= -1.0) || !(x <= 1.0)) {
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.0): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.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 <= -1.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, -1.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 -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.3%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.8%
Taylor expanded in y around 0 98.8%
Final simplification98.6%
(FPCore (x y) :precision binary64 (if (or (<= y 8.5e+14) (not (<= y 2e+200))) (- y x) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= 8.5e+14) || !(y <= 2e+200)) {
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 ((y <= 8.5d+14) .or. (.not. (y <= 2d+200))) 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 ((y <= 8.5e+14) || !(y <= 2e+200)) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 8.5e+14) or not (y <= 2e+200): tmp = y - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if ((y <= 8.5e+14) || !(y <= 2e+200)) tmp = Float64(y - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 8.5e+14) || ~((y <= 2e+200))) tmp = y - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 8.5e+14], N[Not[LessEqual[y, 2e+200]], $MachinePrecision]], N[(y - x), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.5 \cdot 10^{+14} \lor \neg \left(y \leq 2 \cdot 10^{+200}\right):\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < 8.5e14 or 1.9999999999999999e200 < y Initial program 100.0%
Taylor expanded in x around 0 83.1%
Taylor expanded in y around 0 83.1%
if 8.5e14 < y < 1.9999999999999999e200Initial program 100.0%
Taylor expanded in y around inf 99.9%
Taylor expanded in x around inf 67.5%
Final simplification80.4%
(FPCore (x y) :precision binary64 (if (<= y -5.8e-19) y (if (<= y 2.85e-73) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -5.8e-19) {
tmp = y;
} else if (y <= 2.85e-73) {
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 <= (-5.8d-19)) then
tmp = y
else if (y <= 2.85d-73) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -5.8e-19) {
tmp = y;
} else if (y <= 2.85e-73) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.8e-19: tmp = y elif y <= 2.85e-73: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -5.8e-19) tmp = y; elseif (y <= 2.85e-73) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5.8e-19) tmp = y; elseif (y <= 2.85e-73) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.8e-19], y, If[LessEqual[y, 2.85e-73], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-19}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.85 \cdot 10^{-73}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.8e-19 or 2.8499999999999999e-73 < y Initial program 100.0%
Taylor expanded in x around 0 54.0%
if -5.8e-19 < y < 2.8499999999999999e-73Initial program 100.0%
Taylor expanded in y around 0 83.3%
neg-mul-183.3%
Simplified83.3%
(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%
herbie shell --seed 2024139
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))