
(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 7 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 (+ x (+ y (* y x))))
double code(double x, double y) {
return x + (y + (y * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (y + (y * x))
end function
public static double code(double x, double y) {
return x + (y + (y * x));
}
def code(x, y): return x + (y + (y * x))
function code(x, y) return Float64(x + Float64(y + Float64(y * x))) end
function tmp = code(x, y) tmp = x + (y + (y * x)); end
code[x_, y_] := N[(x + N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y + y \cdot x\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-define100.0%
Simplified100.0%
fma-undefine100.0%
distribute-lft1-in100.0%
*-commutative100.0%
+-commutative100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* y x) (if (<= y 1.85e-59) x (if (<= y 3.4e+188) y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 1.85e-59) {
tmp = x;
} else if (y <= 3.4e+188) {
tmp = y;
} 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)) then
tmp = y * x
else if (y <= 1.85d-59) then
tmp = x
else if (y <= 3.4d+188) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 1.85e-59) {
tmp = x;
} else if (y <= 3.4e+188) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 1.85e-59: tmp = x elif y <= 3.4e+188: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * x); elseif (y <= 1.85e-59) tmp = x; elseif (y <= 3.4e+188) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = y * x; elseif (y <= 1.85e-59) tmp = x; elseif (y <= 3.4e+188) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.85e-59], x, If[LessEqual[y, 3.4e+188], y, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{-59}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+188}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 3.39999999999999995e188 < y Initial program 100.0%
Taylor expanded in x around inf 56.1%
+-commutative56.1%
Simplified56.1%
distribute-rgt-in56.1%
*-un-lft-identity56.1%
Applied egg-rr56.1%
Taylor expanded in y around inf 55.3%
if -1 < y < 1.85e-59Initial program 100.0%
Taylor expanded in y around 0 82.3%
if 1.85e-59 < y < 3.39999999999999995e188Initial program 100.0%
Taylor expanded in x around 0 51.8%
Final simplification66.5%
(FPCore (x y) :precision binary64 (if (<= x -7e-120) (+ x (* y x)) (if (<= x 1.0) y (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -7e-120) {
tmp = x + (y * x);
} else if (x <= 1.0) {
tmp = y;
} 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 <= (-7d-120)) then
tmp = x + (y * x)
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7e-120) {
tmp = x + (y * x);
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7e-120: tmp = x + (y * x) elif x <= 1.0: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -7e-120) tmp = Float64(x + Float64(y * x)); elseif (x <= 1.0) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7e-120) tmp = x + (y * x); elseif (x <= 1.0) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7e-120], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-120}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -7e-120Initial program 100.0%
Taylor expanded in x around inf 90.7%
+-commutative90.7%
Simplified90.7%
distribute-rgt-in90.7%
*-un-lft-identity90.7%
Applied egg-rr90.7%
if -7e-120 < x < 1Initial program 100.0%
Taylor expanded in x around 0 83.1%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.4%
+-commutative98.4%
Simplified98.4%
distribute-rgt-in98.4%
*-un-lft-identity98.4%
Applied egg-rr98.4%
Taylor expanded in y around inf 50.5%
Final simplification77.4%
(FPCore (x y) :precision binary64 (if (<= x -7e-120) (* x (+ y 1.0)) (if (<= x 1.0) y (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -7e-120) {
tmp = x * (y + 1.0);
} else if (x <= 1.0) {
tmp = y;
} 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 <= (-7d-120)) then
tmp = x * (y + 1.0d0)
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7e-120) {
tmp = x * (y + 1.0);
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7e-120: tmp = x * (y + 1.0) elif x <= 1.0: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -7e-120) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 1.0) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7e-120) tmp = x * (y + 1.0); elseif (x <= 1.0) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7e-120], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-120}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -7e-120Initial program 100.0%
Taylor expanded in x around inf 90.7%
+-commutative90.7%
Simplified90.7%
if -7e-120 < x < 1Initial program 100.0%
Taylor expanded in x around 0 83.1%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.4%
+-commutative98.4%
Simplified98.4%
distribute-rgt-in98.4%
*-un-lft-identity98.4%
Applied egg-rr98.4%
Taylor expanded in y around inf 50.5%
Final simplification77.4%
(FPCore (x y) :precision binary64 (if (<= y 1.45e-58) (* x (+ y 1.0)) (+ y (* y x))))
double code(double x, double y) {
double tmp;
if (y <= 1.45e-58) {
tmp = x * (y + 1.0);
} else {
tmp = y + (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.45d-58) then
tmp = x * (y + 1.0d0)
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.45e-58) {
tmp = x * (y + 1.0);
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.45e-58: tmp = x * (y + 1.0) else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.45e-58) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.45e-58) tmp = x * (y + 1.0); else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.45e-58], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-58}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < 1.44999999999999995e-58Initial program 100.0%
Taylor expanded in x around inf 71.3%
+-commutative71.3%
Simplified71.3%
if 1.44999999999999995e-58 < y Initial program 100.0%
Taylor expanded in y around inf 93.8%
*-commutative93.8%
Simplified93.8%
Final simplification78.4%
(FPCore (x y) :precision binary64 (if (<= x -6.8e-120) x y))
double code(double x, double y) {
double tmp;
if (x <= -6.8e-120) {
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 (x <= (-6.8d-120)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.8e-120) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.8e-120: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -6.8e-120) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.8e-120) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.8e-120], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-120}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.8000000000000002e-120Initial program 100.0%
Taylor expanded in y around 0 54.0%
if -6.8000000000000002e-120 < x Initial program 100.0%
Taylor expanded in x around 0 50.4%
(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 40.0%
herbie shell --seed 2024150
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))