
(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 (- y x)))
double code(double x, double y) {
return fma(x, y, (y - x));
}
function code(x, y) return fma(x, y, Float64(y - x)) end
code[x_, y_] := N[(x * y + N[(y - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, y - x\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
associate--l+100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -2.25e+163)
(* x y)
(if (<= x -3.15e+59)
(- x)
(if (<= x -25000000.0)
(* x y)
(if (<= x -2.05e-108)
(- x)
(if (<= x 0.125) y (if (<= x 7e+143) (* x y) (- x))))))))
double code(double x, double y) {
double tmp;
if (x <= -2.25e+163) {
tmp = x * y;
} else if (x <= -3.15e+59) {
tmp = -x;
} else if (x <= -25000000.0) {
tmp = x * y;
} else if (x <= -2.05e-108) {
tmp = -x;
} else if (x <= 0.125) {
tmp = y;
} else if (x <= 7e+143) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.25d+163)) then
tmp = x * y
else if (x <= (-3.15d+59)) then
tmp = -x
else if (x <= (-25000000.0d0)) then
tmp = x * y
else if (x <= (-2.05d-108)) then
tmp = -x
else if (x <= 0.125d0) then
tmp = y
else if (x <= 7d+143) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.25e+163) {
tmp = x * y;
} else if (x <= -3.15e+59) {
tmp = -x;
} else if (x <= -25000000.0) {
tmp = x * y;
} else if (x <= -2.05e-108) {
tmp = -x;
} else if (x <= 0.125) {
tmp = y;
} else if (x <= 7e+143) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.25e+163: tmp = x * y elif x <= -3.15e+59: tmp = -x elif x <= -25000000.0: tmp = x * y elif x <= -2.05e-108: tmp = -x elif x <= 0.125: tmp = y elif x <= 7e+143: tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.25e+163) tmp = Float64(x * y); elseif (x <= -3.15e+59) tmp = Float64(-x); elseif (x <= -25000000.0) tmp = Float64(x * y); elseif (x <= -2.05e-108) tmp = Float64(-x); elseif (x <= 0.125) tmp = y; elseif (x <= 7e+143) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.25e+163) tmp = x * y; elseif (x <= -3.15e+59) tmp = -x; elseif (x <= -25000000.0) tmp = x * y; elseif (x <= -2.05e-108) tmp = -x; elseif (x <= 0.125) tmp = y; elseif (x <= 7e+143) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.25e+163], N[(x * y), $MachinePrecision], If[LessEqual[x, -3.15e+59], (-x), If[LessEqual[x, -25000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.05e-108], (-x), If[LessEqual[x, 0.125], y, If[LessEqual[x, 7e+143], N[(x * y), $MachinePrecision], (-x)]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.25 \cdot 10^{+163}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -3.15 \cdot 10^{+59}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -25000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{-108}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 0.125:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+143}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -2.24999999999999994e163 or -3.15e59 < x < -2.5e7 or 0.125 < x < 7.00000000000000017e143Initial program 99.9%
Taylor expanded in x around inf 97.7%
Taylor expanded in y around inf 69.1%
if -2.24999999999999994e163 < x < -3.15e59 or -2.5e7 < x < -2.05000000000000018e-108 or 7.00000000000000017e143 < x Initial program 100.0%
Taylor expanded in y around 0 63.8%
neg-mul-163.8%
Simplified63.8%
if -2.05000000000000018e-108 < x < 0.125Initial program 100.0%
Taylor expanded in x around 0 81.8%
Final simplification72.4%
(FPCore (x y) :precision binary64 (if (or (<= x -2.05e-108) (not (<= x 1.8e-65))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -2.05e-108) || !(x <= 1.8e-65)) {
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 <= (-2.05d-108)) .or. (.not. (x <= 1.8d-65))) 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 <= -2.05e-108) || !(x <= 1.8e-65)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.05e-108) or not (x <= 1.8e-65): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.05e-108) || !(x <= 1.8e-65)) 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 <= -2.05e-108) || ~((x <= 1.8e-65))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.05e-108], N[Not[LessEqual[x, 1.8e-65]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-108} \lor \neg \left(x \leq 1.8 \cdot 10^{-65}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.05000000000000018e-108 or 1.7999999999999999e-65 < x Initial program 100.0%
Taylor expanded in x around inf 89.5%
if -2.05000000000000018e-108 < x < 1.7999999999999999e-65Initial program 100.0%
Taylor expanded in x around 0 87.2%
Final simplification88.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.9e-13) (not (<= y 1.8e-112))) (* y (+ x 1.0)) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -1.9e-13) || !(y <= 1.8e-112)) {
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 <= (-1.9d-13)) .or. (.not. (y <= 1.8d-112))) 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 <= -1.9e-13) || !(y <= 1.8e-112)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.9e-13) or not (y <= 1.8e-112): tmp = y * (x + 1.0) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.9e-13) || !(y <= 1.8e-112)) 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 <= -1.9e-13) || ~((y <= 1.8e-112))) tmp = y * (x + 1.0); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.9e-13], N[Not[LessEqual[y, 1.8e-112]], $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 -1.9 \cdot 10^{-13} \lor \neg \left(y \leq 1.8 \cdot 10^{-112}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -1.9e-13 or 1.8e-112 < y Initial program 100.0%
Taylor expanded in y around inf 93.1%
if -1.9e-13 < y < 1.8e-112Initial program 100.0%
Taylor expanded in x around inf 82.7%
Final simplification89.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.3e-13) (not (<= y 1.8e-112))) (* y (+ x 1.0)) (- (* x y) x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.3e-13) || !(y <= 1.8e-112)) {
tmp = y * (x + 1.0);
} else {
tmp = (x * 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.3d-13)) .or. (.not. (y <= 1.8d-112))) then
tmp = y * (x + 1.0d0)
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.3e-13) || !(y <= 1.8e-112)) {
tmp = y * (x + 1.0);
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.3e-13) or not (y <= 1.8e-112): tmp = y * (x + 1.0) else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.3e-13) || !(y <= 1.8e-112)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.3e-13) || ~((y <= 1.8e-112))) tmp = y * (x + 1.0); else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.3e-13], N[Not[LessEqual[y, 1.8e-112]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-13} \lor \neg \left(y \leq 1.8 \cdot 10^{-112}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if y < -1.3e-13 or 1.8e-112 < y Initial program 100.0%
Taylor expanded in y around inf 93.1%
if -1.3e-13 < y < 1.8e-112Initial program 100.0%
Taylor expanded in x around inf 82.7%
distribute-rgt-out--82.7%
*-lft-identity82.7%
Simplified82.7%
Final simplification89.0%
(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 (if (<= y -1.8e-13) y (if (<= y 1.8e-112) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.8e-13) {
tmp = y;
} else if (y <= 1.8e-112) {
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 <= (-1.8d-13)) then
tmp = y
else if (y <= 1.8d-112) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.8e-13) {
tmp = y;
} else if (y <= 1.8e-112) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.8e-13: tmp = y elif y <= 1.8e-112: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.8e-13) tmp = y; elseif (y <= 1.8e-112) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.8e-13) tmp = y; elseif (y <= 1.8e-112) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.8e-13], y, If[LessEqual[y, 1.8e-112], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-13}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-112}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.7999999999999999e-13 or 1.8e-112 < y Initial program 100.0%
Taylor expanded in x around 0 51.1%
if -1.7999999999999999e-13 < y < 1.8e-112Initial program 100.0%
Taylor expanded in y around 0 82.5%
neg-mul-182.5%
Simplified82.5%
Final simplification63.6%
(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.4%
Final simplification38.4%
herbie shell --seed 2023271
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))