
(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 (or (<= y -4.1e+18) (and (not (<= y 1.3e+108)) (<= y 9.2e+137))) (* x y) (+ x y)))
double code(double x, double y) {
double tmp;
if ((y <= -4.1e+18) || (!(y <= 1.3e+108) && (y <= 9.2e+137))) {
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 <= (-4.1d+18)) .or. (.not. (y <= 1.3d+108)) .and. (y <= 9.2d+137)) 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 <= -4.1e+18) || (!(y <= 1.3e+108) && (y <= 9.2e+137))) {
tmp = x * y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.1e+18) or (not (y <= 1.3e+108) and (y <= 9.2e+137)): tmp = x * y else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.1e+18) || (!(y <= 1.3e+108) && (y <= 9.2e+137))) tmp = Float64(x * y); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.1e+18) || (~((y <= 1.3e+108)) && (y <= 9.2e+137))) tmp = x * y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.1e+18], And[N[Not[LessEqual[y, 1.3e+108]], $MachinePrecision], LessEqual[y, 9.2e+137]]], N[(x * y), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+18} \lor \neg \left(y \leq 1.3 \cdot 10^{+108}\right) \land y \leq 9.2 \cdot 10^{+137}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -4.1e18 or 1.3000000000000001e108 < y < 9.19999999999999997e137Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 50.9%
*-commutative50.9%
Simplified50.9%
if -4.1e18 < y < 1.3000000000000001e108 or 9.19999999999999997e137 < y Initial program 100.0%
Taylor expanded in y around 0 88.8%
Final simplification79.1%
(FPCore (x y) :precision binary64 (if (<= y -720000.0) (* x y) (if (<= y 1.0) (+ x y) (* y (+ x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -720000.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = 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 <= (-720000.0d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = 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 <= -720000.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -720000.0: tmp = x * y elif y <= 1.0: tmp = x + y else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -720000.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = 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 <= -720000.0) tmp = x * y; elseif (y <= 1.0) tmp = x + y; else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -720000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], N[(x + y), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -720000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -7.2e5Initial program 100.0%
Taylor expanded in y around inf 99.9%
Taylor expanded in x around inf 46.9%
*-commutative46.9%
Simplified46.9%
if -7.2e5 < y < 1Initial program 100.0%
Taylor expanded in y around 0 98.5%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 96.6%
Final simplification85.6%
(FPCore (x y) :precision binary64 (if (or (<= x -0.225) (not (<= x 1.0))) (* x y) y))
double code(double x, double y) {
double tmp;
if ((x <= -0.225) || !(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 <= (-0.225d0)) .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 <= -0.225) || !(x <= 1.0)) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.225) or not (x <= 1.0): tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.225) || !(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 <= -0.225) || ~((x <= 1.0))) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.225], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.225 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -0.225000000000000006 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 46.4%
Taylor expanded in x around inf 46.1%
*-commutative46.1%
Simplified46.1%
if -0.225000000000000006 < x < 1Initial program 100.0%
Taylor expanded in x around 0 71.5%
Final simplification60.3%
(FPCore (x y) :precision binary64 (+ y (* x (+ y 1.0))))
double code(double x, double y) {
return y + (x * (y + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x * (y + 1.0d0))
end function
public static double code(double x, double y) {
return y + (x * (y + 1.0));
}
def code(x, y): return y + (x * (y + 1.0))
function code(x, y) return Float64(y + Float64(x * Float64(y + 1.0))) end
function tmp = code(x, y) tmp = y + (x * (y + 1.0)); end
code[x_, y_] := N[(y + N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(y + 1\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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 x around 0 41.2%
Final simplification41.2%
herbie shell --seed 2024040
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))