
(FPCore (x y) :precision binary64 (+ (+ (* x y) x) y))
double code(double x, double y) {
return ((x * y) + x) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * y) + x) + y
end function
public static double code(double x, double y) {
return ((x * y) + x) + y;
}
def code(x, y): return ((x * y) + x) + y
function code(x, y) return Float64(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x y) x) y))
double code(double x, double y) {
return ((x * y) + x) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * y) + x) + y
end function
public static double code(double x, double y) {
return ((x * y) + x) + y;
}
def code(x, y): return ((x * y) + x) + y
function code(x, y) return Float64(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + y
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ x (fma x y y)))
assert(x < y);
double code(double x, double y) {
return x + fma(x, y, y);
}
x, y = sort([x, y]) function code(x, y) return Float64(x + fma(x, y, y)) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x + N[(x * y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + \mathsf{fma}\left(x, y, y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= y -1.0)
(* x y)
(if (<= y 1.8e-119)
x
(if (or (<= y 7.5e-76) (not (<= y 8.2e-45))) (* y (+ x 1.0)) x))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.8e-119) {
tmp = x;
} else if ((y <= 7.5e-76) || !(y <= 8.2e-45)) {
tmp = y * (x + 1.0);
} else {
tmp = x;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.0d0)) then
tmp = x * y
else if (y <= 1.8d-119) then
tmp = x
else if ((y <= 7.5d-76) .or. (.not. (y <= 8.2d-45))) then
tmp = y * (x + 1.0d0)
else
tmp = x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.8e-119) {
tmp = x;
} else if ((y <= 7.5e-76) || !(y <= 8.2e-45)) {
tmp = y * (x + 1.0);
} else {
tmp = x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.8e-119: tmp = x elif (y <= 7.5e-76) or not (y <= 8.2e-45): tmp = y * (x + 1.0) else: tmp = x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1.8e-119) tmp = x; elseif ((y <= 7.5e-76) || !(y <= 8.2e-45)) tmp = Float64(y * Float64(x + 1.0)); else tmp = x; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -1.0)
tmp = x * y;
elseif (y <= 1.8e-119)
tmp = x;
elseif ((y <= 7.5e-76) || ~((y <= 8.2e-45)))
tmp = y * (x + 1.0);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.8e-119], x, If[Or[LessEqual[y, 7.5e-76], N[Not[LessEqual[y, 8.2e-45]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], x]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-119}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-76} \lor \neg \left(y \leq 8.2 \cdot 10^{-45}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 98.2%
Taylor expanded in x around inf 37.6%
if -1 < y < 1.8e-119 or 7.4999999999999997e-76 < y < 8.1999999999999998e-45Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 81.1%
if 1.8e-119 < y < 7.4999999999999997e-76 or 8.1999999999999998e-45 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 83.7%
Final simplification73.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -9.5e-154) x (if (<= x 1.0) y (* x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-9.5d-154)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -9.5e-154: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -9.5e-154) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -9.5e-154)
tmp = x;
elseif (x <= 1.0)
tmp = y;
else
tmp = x * y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -9.5e-154], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-154}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -9.50000000000000057e-154Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 57.5%
if -9.50000000000000057e-154 < x < 1Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 78.2%
if 1 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 44.9%
Taylor expanded in x around inf 43.3%
Final simplification62.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -9.5e-154) (* x (+ y 1.0)) (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-9.5d-154)) then
tmp = x * (y + 1.0d0)
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -9.5e-154: tmp = x * (y + 1.0) else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -9.5e-154) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -9.5e-154)
tmp = x * (y + 1.0);
else
tmp = y * (x + 1.0);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -9.5e-154], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-154}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -9.50000000000000057e-154Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 86.0%
if -9.50000000000000057e-154 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 66.2%
Final simplification73.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -9.5e-154) (+ x (* x y)) (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x + (x * y);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-9.5d-154)) then
tmp = x + (x * y)
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x + (x * y);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -9.5e-154: tmp = x + (x * y) else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -9.5e-154) tmp = Float64(x + Float64(x * y)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -9.5e-154)
tmp = x + (x * y);
else
tmp = y * (x + 1.0);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -9.5e-154], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-154}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -9.50000000000000057e-154Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 86.0%
Taylor expanded in y around 0 86.0%
if -9.50000000000000057e-154 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 66.2%
Final simplification73.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ y (+ x (* x y))))
assert(x < y);
double code(double x, double y) {
return y + (x + (x * y));
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x + (x * y))
end function
assert x < y;
public static double code(double x, double y) {
return y + (x + (x * y));
}
[x, y] = sort([x, y]) def code(x, y): return y + (x + (x * y))
x, y = sort([x, y]) function code(x, y) return Float64(y + Float64(x + Float64(x * y))) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y + (x + (x * y));
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + \left(x + x \cdot y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -9.5e-154) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-9.5d-154)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e-154) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -9.5e-154: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -9.5e-154) tmp = x; else tmp = y; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -9.5e-154)
tmp = x;
else
tmp = y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -9.5e-154], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-154}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -9.50000000000000057e-154Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 57.5%
if -9.50000000000000057e-154 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 50.3%
Final simplification52.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 x)
assert(x < y);
double code(double x, double y) {
return x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
assert x < y;
public static double code(double x, double y) {
return x;
}
[x, y] = sort([x, y]) def code(x, y): return x
x, y = sort([x, y]) function code(x, y) return x end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := x
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 42.5%
Final simplification42.5%
herbie shell --seed 2023278
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))