
(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}
(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 (<= x -5.7e+166)
x
(if (<= x -2.8e+99)
(* x y)
(if (<= x -1.9e-28)
x
(if (<= x -3.4e-76)
y
(if (<= x -5.4e-101) x (if (<= x 1.0) y (* x y))))))))
double code(double x, double y) {
double tmp;
if (x <= -5.7e+166) {
tmp = x;
} else if (x <= -2.8e+99) {
tmp = x * y;
} else if (x <= -1.9e-28) {
tmp = x;
} else if (x <= -3.4e-76) {
tmp = y;
} else if (x <= -5.4e-101) {
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 <= (-5.7d+166)) then
tmp = x
else if (x <= (-2.8d+99)) then
tmp = x * y
else if (x <= (-1.9d-28)) then
tmp = x
else if (x <= (-3.4d-76)) then
tmp = y
else if (x <= (-5.4d-101)) 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 <= -5.7e+166) {
tmp = x;
} else if (x <= -2.8e+99) {
tmp = x * y;
} else if (x <= -1.9e-28) {
tmp = x;
} else if (x <= -3.4e-76) {
tmp = y;
} else if (x <= -5.4e-101) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.7e+166: tmp = x elif x <= -2.8e+99: tmp = x * y elif x <= -1.9e-28: tmp = x elif x <= -3.4e-76: tmp = y elif x <= -5.4e-101: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -5.7e+166) tmp = x; elseif (x <= -2.8e+99) tmp = Float64(x * y); elseif (x <= -1.9e-28) tmp = x; elseif (x <= -3.4e-76) tmp = y; elseif (x <= -5.4e-101) 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 <= -5.7e+166) tmp = x; elseif (x <= -2.8e+99) tmp = x * y; elseif (x <= -1.9e-28) tmp = x; elseif (x <= -3.4e-76) tmp = y; elseif (x <= -5.4e-101) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.7e+166], x, If[LessEqual[x, -2.8e+99], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.9e-28], x, If[LessEqual[x, -3.4e-76], y, If[LessEqual[x, -5.4e-101], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.7 \cdot 10^{+166}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.8 \cdot 10^{+99}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{-28}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -3.4 \cdot 10^{-76}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -5.4 \cdot 10^{-101}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.69999999999999977e166 or -2.8e99 < x < -1.90000000000000005e-28 or -3.3999999999999999e-76 < x < -5.4000000000000003e-101Initial program 100.0%
Taylor expanded in y around 0 54.7%
if -5.69999999999999977e166 < x < -2.8e99 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in y around inf 54.6%
if -1.90000000000000005e-28 < x < -3.3999999999999999e-76 or -5.4000000000000003e-101 < x < 1Initial program 100.0%
Taylor expanded in x around 0 76.0%
Final simplification64.1%
(FPCore (x y) :precision binary64 (if (<= x -4.2e-27) (* x (+ y 1.0)) (if (<= x -1.4e-80) y (if (<= x -2.1e-99) x (if (<= x 1.0) y (* x y))))))
double code(double x, double y) {
double tmp;
if (x <= -4.2e-27) {
tmp = x * (y + 1.0);
} else if (x <= -1.4e-80) {
tmp = y;
} else if (x <= -2.1e-99) {
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 <= (-4.2d-27)) then
tmp = x * (y + 1.0d0)
else if (x <= (-1.4d-80)) then
tmp = y
else if (x <= (-2.1d-99)) 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 <= -4.2e-27) {
tmp = x * (y + 1.0);
} else if (x <= -1.4e-80) {
tmp = y;
} else if (x <= -2.1e-99) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.2e-27: tmp = x * (y + 1.0) elif x <= -1.4e-80: tmp = y elif x <= -2.1e-99: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -4.2e-27) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= -1.4e-80) tmp = y; elseif (x <= -2.1e-99) 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 <= -4.2e-27) tmp = x * (y + 1.0); elseif (x <= -1.4e-80) tmp = y; elseif (x <= -2.1e-99) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.2e-27], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.4e-80], y, If[LessEqual[x, -2.1e-99], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-27}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq -1.4 \cdot 10^{-80}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -2.1 \cdot 10^{-99}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.20000000000000031e-27Initial program 100.0%
Taylor expanded in x around inf 89.1%
+-commutative89.1%
Simplified89.1%
if -4.20000000000000031e-27 < x < -1.39999999999999995e-80 or -2.09999999999999984e-99 < x < 1Initial program 100.0%
Taylor expanded in x around 0 76.2%
if -1.39999999999999995e-80 < x < -2.09999999999999984e-99Initial program 100.0%
Taylor expanded in y around 0 44.7%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in y around inf 49.6%
Final simplification71.4%
(FPCore (x y) :precision binary64 (if (<= y 3.1e-142) (* x (+ y 1.0)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= 3.1e-142) {
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 <= 3.1d-142) 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 <= 3.1e-142) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.1e-142: tmp = x * (y + 1.0) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 3.1e-142) 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 <= 3.1e-142) tmp = x * (y + 1.0); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.1e-142], 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 3.1 \cdot 10^{-142}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 3.1e-142Initial program 100.0%
Taylor expanded in x around inf 67.5%
+-commutative67.5%
Simplified67.5%
if 3.1e-142 < y Initial program 100.0%
Taylor expanded in y around inf 80.7%
Final simplification73.1%
(FPCore (x y) :precision binary64 (if (<= y 2.1e-139) (+ x (* x y)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= 2.1e-139) {
tmp = x + (x * y);
} 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 <= 2.1d-139) then
tmp = x + (x * y)
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.1e-139) {
tmp = x + (x * y);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.1e-139: tmp = x + (x * y) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.1e-139) tmp = Float64(x + Float64(x * y)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.1e-139) tmp = x + (x * y); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.1e-139], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{-139}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 2.10000000000000008e-139Initial program 100.0%
Taylor expanded in x around inf 67.7%
+-commutative67.7%
Simplified67.7%
distribute-lft-in67.7%
*-rgt-identity67.7%
Applied egg-rr67.7%
if 2.10000000000000008e-139 < y Initial program 100.0%
Taylor expanded in y around inf 81.4%
Final simplification73.4%
(FPCore (x y) :precision binary64 (if (<= y 3.1e-142) (+ x (* x y)) (+ y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 3.1e-142) {
tmp = x + (x * y);
} else {
tmp = y + (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 <= 3.1d-142) then
tmp = x + (x * y)
else
tmp = y + (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.1e-142) {
tmp = x + (x * y);
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.1e-142: tmp = x + (x * y) else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 3.1e-142) tmp = Float64(x + Float64(x * y)); else tmp = Float64(y + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.1e-142) tmp = x + (x * y); else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.1e-142], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.1 \cdot 10^{-142}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if y < 3.1e-142Initial program 100.0%
Taylor expanded in x around inf 67.5%
+-commutative67.5%
Simplified67.5%
distribute-lft-in67.5%
*-rgt-identity67.5%
Applied egg-rr67.5%
if 3.1e-142 < y Initial program 100.0%
Taylor expanded in y around inf 80.7%
+-commutative80.7%
distribute-rgt-in80.7%
*-un-lft-identity80.7%
Applied egg-rr80.7%
Final simplification73.1%
(FPCore (x y) :precision binary64 (if (<= y 2.1e-139) x y))
double code(double x, double y) {
double tmp;
if (y <= 2.1e-139) {
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.1d-139) 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.1e-139) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.1e-139: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.1e-139) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.1e-139) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.1e-139], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{-139}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.10000000000000008e-139Initial program 100.0%
Taylor expanded in y around 0 51.6%
if 2.10000000000000008e-139 < y Initial program 100.0%
Taylor expanded in x around 0 45.9%
Final simplification49.3%
(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 38.7%
Final simplification38.7%
herbie shell --seed 2024044
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))