
(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 5 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 -900000000000.0) (* x y) (if (<= y 5.9e-6) (+ x y) (+ y (* x y)))))
double code(double x, double y) {
double tmp;
if (y <= -900000000000.0) {
tmp = x * y;
} else if (y <= 5.9e-6) {
tmp = 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 <= (-900000000000.0d0)) then
tmp = x * y
else if (y <= 5.9d-6) then
tmp = 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 <= -900000000000.0) {
tmp = x * y;
} else if (y <= 5.9e-6) {
tmp = x + y;
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -900000000000.0: tmp = x * y elif y <= 5.9e-6: tmp = x + y else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= -900000000000.0) tmp = Float64(x * y); elseif (y <= 5.9e-6) tmp = 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 <= -900000000000.0) tmp = x * y; elseif (y <= 5.9e-6) tmp = x + y; else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -900000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 5.9e-6], N[(x + y), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -900000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 5.9 \cdot 10^{-6}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if y < -9e11Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in x around inf 52.5%
*-commutative52.5%
Simplified52.5%
if -9e11 < y < 5.90000000000000026e-6Initial program 100.0%
Taylor expanded in y around 0 99.5%
if 5.90000000000000026e-6 < y Initial program 100.0%
Taylor expanded in y around inf 98.6%
Final simplification87.7%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x y) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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 ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * y
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 56.2%
Taylor expanded in x around inf 55.3%
*-commutative55.3%
Simplified55.3%
if -1 < x < 1Initial program 100.0%
Taylor expanded in y around inf 68.6%
Taylor expanded in x around 0 67.9%
Final simplification62.2%
(FPCore (x y) :precision binary64 (if (or (<= y -3.1e+17) (not (<= y 2.35e+184))) (* x y) (+ x y)))
double code(double x, double y) {
double tmp;
if ((y <= -3.1e+17) || !(y <= 2.35e+184)) {
tmp = x * 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 ((y <= (-3.1d+17)) .or. (.not. (y <= 2.35d+184))) then
tmp = x * y
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3.1e+17) || !(y <= 2.35e+184)) {
tmp = x * y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.1e+17) or not (y <= 2.35e+184): tmp = x * y else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.1e+17) || !(y <= 2.35e+184)) tmp = Float64(x * y); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.1e+17) || ~((y <= 2.35e+184))) tmp = x * y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.1e+17], N[Not[LessEqual[y, 2.35e+184]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+17} \lor \neg \left(y \leq 2.35 \cdot 10^{+184}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -3.1e17 or 2.3500000000000002e184 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 53.0%
*-commutative53.0%
Simplified53.0%
if -3.1e17 < y < 2.3500000000000002e184Initial program 100.0%
Taylor expanded in y around 0 89.2%
Final simplification77.1%
(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 y around inf 63.0%
Taylor expanded in x around 0 38.8%
Final simplification38.8%
herbie shell --seed 2023333
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))