
(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 (<= y -1.0)
(* x y)
(if (<= y 2.9e-174)
x
(if (<= y 8.5e-162)
y
(if (<= y 2.95e-46) x (if (<= y 5.6e+266) y (* x y)))))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 2.9e-174) {
tmp = x;
} else if (y <= 8.5e-162) {
tmp = y;
} else if (y <= 2.95e-46) {
tmp = x;
} else if (y <= 5.6e+266) {
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 (y <= (-1.0d0)) then
tmp = x * y
else if (y <= 2.9d-174) then
tmp = x
else if (y <= 8.5d-162) then
tmp = y
else if (y <= 2.95d-46) then
tmp = x
else if (y <= 5.6d+266) then
tmp = y
else
tmp = x * 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 <= 2.9e-174) {
tmp = x;
} else if (y <= 8.5e-162) {
tmp = y;
} else if (y <= 2.95e-46) {
tmp = x;
} else if (y <= 5.6e+266) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 2.9e-174: tmp = x elif y <= 8.5e-162: tmp = y elif y <= 2.95e-46: tmp = x elif y <= 5.6e+266: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 2.9e-174) tmp = x; elseif (y <= 8.5e-162) tmp = y; elseif (y <= 2.95e-46) tmp = x; elseif (y <= 5.6e+266) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 2.9e-174) tmp = x; elseif (y <= 8.5e-162) tmp = y; elseif (y <= 2.95e-46) tmp = x; elseif (y <= 5.6e+266) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.9e-174], x, If[LessEqual[y, 8.5e-162], y, If[LessEqual[y, 2.95e-46], x, If[LessEqual[y, 5.6e+266], y, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-174}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-162}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{-46}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{+266}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 5.5999999999999999e266 < y Initial program 100.0%
Taylor expanded in x around inf 51.4%
+-commutative51.4%
Simplified51.4%
Taylor expanded in y around inf 49.6%
if -1 < y < 2.9000000000000001e-174 or 8.49999999999999955e-162 < y < 2.95e-46Initial program 100.0%
Taylor expanded in y around 0 78.2%
if 2.9000000000000001e-174 < y < 8.49999999999999955e-162 or 2.95e-46 < y < 5.5999999999999999e266Initial program 100.0%
Taylor expanded in x around 0 50.2%
(FPCore (x y) :precision binary64 (if (or (<= y 2.9e-174) (and (not (<= y 8.5e-162)) (<= y 1.6e-59))) (+ x (* x y)) (+ y (* x y))))
double code(double x, double y) {
double tmp;
if ((y <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 1.6e-59))) {
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 <= 2.9d-174) .or. (.not. (y <= 8.5d-162)) .and. (y <= 1.6d-59)) 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 <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 1.6e-59))) {
tmp = x + (x * y);
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 2.9e-174) or (not (y <= 8.5e-162) and (y <= 1.6e-59)): tmp = x + (x * y) else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if ((y <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 1.6e-59))) 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 <= 2.9e-174) || (~((y <= 8.5e-162)) && (y <= 1.6e-59))) tmp = x + (x * y); else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 2.9e-174], And[N[Not[LessEqual[y, 8.5e-162]], $MachinePrecision], LessEqual[y, 1.6e-59]]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-174} \lor \neg \left(y \leq 8.5 \cdot 10^{-162}\right) \land y \leq 1.6 \cdot 10^{-59}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if y < 2.9000000000000001e-174 or 8.49999999999999955e-162 < y < 1.6e-59Initial program 100.0%
Taylor expanded in x around inf 68.6%
+-commutative68.6%
Simplified68.6%
distribute-lft-in68.6%
*-rgt-identity68.6%
Applied egg-rr68.6%
if 2.9000000000000001e-174 < y < 8.49999999999999955e-162 or 1.6e-59 < y Initial program 100.0%
Taylor expanded in y around inf 89.4%
+-commutative89.4%
distribute-rgt-in89.3%
*-un-lft-identity89.3%
Applied egg-rr89.3%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (or (<= y 2.9e-174) (and (not (<= y 8.5e-162)) (<= y 1.6e-59))) (+ x (* x y)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 1.6e-59))) {
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.9d-174) .or. (.not. (y <= 8.5d-162)) .and. (y <= 1.6d-59)) 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.9e-174) || (!(y <= 8.5e-162) && (y <= 1.6e-59))) {
tmp = x + (x * y);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 2.9e-174) or (not (y <= 8.5e-162) and (y <= 1.6e-59)): tmp = x + (x * y) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 1.6e-59))) 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.9e-174) || (~((y <= 8.5e-162)) && (y <= 1.6e-59))) tmp = x + (x * y); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 2.9e-174], And[N[Not[LessEqual[y, 8.5e-162]], $MachinePrecision], LessEqual[y, 1.6e-59]]], 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.9 \cdot 10^{-174} \lor \neg \left(y \leq 8.5 \cdot 10^{-162}\right) \land y \leq 1.6 \cdot 10^{-59}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 2.9000000000000001e-174 or 8.49999999999999955e-162 < y < 1.6e-59Initial program 100.0%
Taylor expanded in x around inf 68.6%
+-commutative68.6%
Simplified68.6%
distribute-lft-in68.6%
*-rgt-identity68.6%
Applied egg-rr68.6%
if 2.9000000000000001e-174 < y < 8.49999999999999955e-162 or 1.6e-59 < y Initial program 100.0%
Taylor expanded in y around inf 89.4%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (or (<= y 2.9e-174) (and (not (<= y 8.5e-162)) (<= y 8e-60))) (* x (+ y 1.0)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 8e-60))) {
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 <= 2.9d-174) .or. (.not. (y <= 8.5d-162)) .and. (y <= 8d-60)) 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 <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 8e-60))) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 2.9e-174) or (not (y <= 8.5e-162) and (y <= 8e-60)): tmp = x * (y + 1.0) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= 2.9e-174) || (!(y <= 8.5e-162) && (y <= 8e-60))) 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 <= 2.9e-174) || (~((y <= 8.5e-162)) && (y <= 8e-60))) tmp = x * (y + 1.0); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 2.9e-174], And[N[Not[LessEqual[y, 8.5e-162]], $MachinePrecision], LessEqual[y, 8e-60]]], 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 2.9 \cdot 10^{-174} \lor \neg \left(y \leq 8.5 \cdot 10^{-162}\right) \land y \leq 8 \cdot 10^{-60}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 2.9000000000000001e-174 or 8.49999999999999955e-162 < y < 7.9999999999999998e-60Initial program 100.0%
Taylor expanded in x around inf 68.6%
+-commutative68.6%
Simplified68.6%
if 2.9000000000000001e-174 < y < 8.49999999999999955e-162 or 7.9999999999999998e-60 < y Initial program 100.0%
Taylor expanded in y around inf 89.4%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (or (<= x -3.4e-19) (not (<= x 0.046))) (* x (+ y 1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -3.4e-19) || !(x <= 0.046)) {
tmp = x * (y + 1.0);
} 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 <= (-3.4d-19)) .or. (.not. (x <= 0.046d0))) then
tmp = x * (y + 1.0d0)
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3.4e-19) || !(x <= 0.046)) {
tmp = x * (y + 1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.4e-19) or not (x <= 0.046): tmp = x * (y + 1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.4e-19) || !(x <= 0.046)) tmp = Float64(x * Float64(y + 1.0)); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.4e-19) || ~((x <= 0.046))) tmp = x * (y + 1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.4e-19], N[Not[LessEqual[x, 0.046]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-19} \lor \neg \left(x \leq 0.046\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.4000000000000002e-19 or 0.045999999999999999 < x Initial program 100.0%
Taylor expanded in x around inf 94.4%
+-commutative94.4%
Simplified94.4%
if -3.4000000000000002e-19 < x < 0.045999999999999999Initial program 100.0%
Taylor expanded in x around 0 75.9%
Final simplification85.5%
(FPCore (x y) :precision binary64 (if (<= x -3.9e-19) x y))
double code(double x, double y) {
double tmp;
if (x <= -3.9e-19) {
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 <= (-3.9d-19)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.9e-19) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.9e-19: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.9e-19) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.9e-19) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.9e-19], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.89999999999999995e-19Initial program 100.0%
Taylor expanded in y around 0 43.1%
if -3.89999999999999995e-19 < x Initial program 100.0%
Taylor expanded in x around 0 52.8%
(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%
herbie shell --seed 2024103
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))