
(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 6 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}
(FPCore (x y) :precision binary64 (+ y (+ x (* x y))))
double code(double x, double y) {
return y + (x + (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x + (x * y))
end function
public static double code(double x, double y) {
return y + (x + (x * y));
}
def code(x, y): return y + (x + (x * y))
function code(x, y) return Float64(y + Float64(x + Float64(x * y))) end
function tmp = code(x, y) tmp = y + (x + (x * y)); end
code[x_, y_] := N[(y + N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(x + x \cdot y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.0)
(* x y)
(if (<= y 1.1e-216)
x
(if (<= y 5e+112) y (if (<= y 2.25e+278) (* x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.1e-216) {
tmp = x;
} else if (y <= 5e+112) {
tmp = y;
} else if (y <= 2.25e+278) {
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.0d0)) then
tmp = x * y
else if (y <= 1.1d-216) then
tmp = x
else if (y <= 5d+112) then
tmp = y
else if (y <= 2.25d+278) 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.0) {
tmp = x * y;
} else if (y <= 1.1e-216) {
tmp = x;
} else if (y <= 5e+112) {
tmp = y;
} else if (y <= 2.25e+278) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.1e-216: tmp = x elif y <= 5e+112: tmp = y elif y <= 2.25e+278: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1.1e-216) tmp = x; elseif (y <= 5e+112) tmp = y; elseif (y <= 2.25e+278) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 1.1e-216) tmp = x; elseif (y <= 5e+112) tmp = y; elseif (y <= 2.25e+278) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.1e-216], x, If[LessEqual[y, 5e+112], y, If[LessEqual[y, 2.25e+278], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-216}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+112}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{+278}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 5e112 < y < 2.25000000000000004e278Initial program 100.0%
Taylor expanded in x around inf 57.9%
+-commutative57.9%
Simplified57.9%
Taylor expanded in y around inf 56.8%
if -1 < y < 1.09999999999999995e-216Initial program 100.0%
Taylor expanded in y around 0 78.7%
if 1.09999999999999995e-216 < y < 5e112 or 2.25000000000000004e278 < y Initial program 100.0%
Taylor expanded in x around 0 53.4%
Final simplification63.3%
(FPCore (x y) :precision binary64 (if (<= x -1.4e-63) (* x (+ y 1.0)) (if (<= x -8e-156) y (if (<= x -2.4e-178) x (if (<= x 1.0) y (* x y))))))
double code(double x, double y) {
double tmp;
if (x <= -1.4e-63) {
tmp = x * (y + 1.0);
} else if (x <= -8e-156) {
tmp = y;
} else if (x <= -2.4e-178) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} 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 <= (-1.4d-63)) then
tmp = x * (y + 1.0d0)
else if (x <= (-8d-156)) then
tmp = y
else if (x <= (-2.4d-178)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.4e-63) {
tmp = x * (y + 1.0);
} else if (x <= -8e-156) {
tmp = y;
} else if (x <= -2.4e-178) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.4e-63: tmp = x * (y + 1.0) elif x <= -8e-156: tmp = y elif x <= -2.4e-178: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.4e-63) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= -8e-156) tmp = y; elseif (x <= -2.4e-178) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.4e-63) tmp = x * (y + 1.0); elseif (x <= -8e-156) tmp = y; elseif (x <= -2.4e-178) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.4e-63], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -8e-156], y, If[LessEqual[x, -2.4e-178], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-63}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq -8 \cdot 10^{-156}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{-178}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.4000000000000001e-63Initial program 100.0%
Taylor expanded in x around inf 92.8%
+-commutative92.8%
Simplified92.8%
if -1.4000000000000001e-63 < x < -8.00000000000000032e-156 or -2.40000000000000005e-178 < x < 1Initial program 100.0%
Taylor expanded in x around 0 81.6%
if -8.00000000000000032e-156 < x < -2.40000000000000005e-178Initial program 100.0%
Taylor expanded in y around 0 67.3%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in y around inf 48.2%
Final simplification76.6%
(FPCore (x y) :precision binary64 (if (<= y 1.1e-216) (* x (+ y 1.0)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1.1e-216) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 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.1d-216) then
tmp = x * (y + 1.0d0)
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.1e-216) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.1e-216: tmp = x * (y + 1.0) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.1e-216) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.1e-216) tmp = x * (y + 1.0); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.1e-216], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.1 \cdot 10^{-216}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 1.09999999999999995e-216Initial program 100.0%
Taylor expanded in x around inf 67.4%
+-commutative67.4%
Simplified67.4%
if 1.09999999999999995e-216 < y Initial program 100.0%
Taylor expanded in y around inf 78.2%
Final simplification71.6%
(FPCore (x y) :precision binary64 (if (<= y 1.1e-216) x y))
double code(double x, double y) {
double tmp;
if (y <= 1.1e-216) {
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.1d-216) 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.1e-216) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.1e-216: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.1e-216) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.1e-216) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.1e-216], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.1 \cdot 10^{-216}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.09999999999999995e-216Initial program 100.0%
Taylor expanded in y around 0 44.0%
if 1.09999999999999995e-216 < y Initial program 100.0%
Taylor expanded in x around 0 48.0%
Final simplification45.6%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 36.8%
Final simplification36.8%
herbie shell --seed 2024054
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))