
(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 (fma x y y)))
double code(double x, double y) {
return x + fma(x, y, y);
}
function code(x, y) return Float64(x + fma(x, y, y)) end
code[x_, y_] := N[(x + N[(x * y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \mathsf{fma}\left(x, y, y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.0)
(* x y)
(if (<= y 3.8e-114)
x
(if (<= y 2.6e+16)
y
(if (<= y 2.2e+34)
(* x y)
(if (<= y 5.2e+93)
y
(if (<= y 1.8e+141) (* x y) (if (<= y 9.6e+200) y (* x y)))))))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 3.8e-114) {
tmp = x;
} else if (y <= 2.6e+16) {
tmp = y;
} else if (y <= 2.2e+34) {
tmp = x * y;
} else if (y <= 5.2e+93) {
tmp = y;
} else if (y <= 1.8e+141) {
tmp = x * y;
} else if (y <= 9.6e+200) {
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 <= 3.8d-114) then
tmp = x
else if (y <= 2.6d+16) then
tmp = y
else if (y <= 2.2d+34) then
tmp = x * y
else if (y <= 5.2d+93) then
tmp = y
else if (y <= 1.8d+141) then
tmp = x * y
else if (y <= 9.6d+200) 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 <= 3.8e-114) {
tmp = x;
} else if (y <= 2.6e+16) {
tmp = y;
} else if (y <= 2.2e+34) {
tmp = x * y;
} else if (y <= 5.2e+93) {
tmp = y;
} else if (y <= 1.8e+141) {
tmp = x * y;
} else if (y <= 9.6e+200) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 3.8e-114: tmp = x elif y <= 2.6e+16: tmp = y elif y <= 2.2e+34: tmp = x * y elif y <= 5.2e+93: tmp = y elif y <= 1.8e+141: tmp = x * y elif y <= 9.6e+200: 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 <= 3.8e-114) tmp = x; elseif (y <= 2.6e+16) tmp = y; elseif (y <= 2.2e+34) tmp = Float64(x * y); elseif (y <= 5.2e+93) tmp = y; elseif (y <= 1.8e+141) tmp = Float64(x * y); elseif (y <= 9.6e+200) 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 <= 3.8e-114) tmp = x; elseif (y <= 2.6e+16) tmp = y; elseif (y <= 2.2e+34) tmp = x * y; elseif (y <= 5.2e+93) tmp = y; elseif (y <= 1.8e+141) tmp = x * y; elseif (y <= 9.6e+200) 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, 3.8e-114], x, If[LessEqual[y, 2.6e+16], y, If[LessEqual[y, 2.2e+34], N[(x * y), $MachinePrecision], If[LessEqual[y, 5.2e+93], y, If[LessEqual[y, 1.8e+141], N[(x * y), $MachinePrecision], If[LessEqual[y, 9.6e+200], y, N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-114}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+16}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+34}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+93}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+141}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{+200}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 2.6e16 < y < 2.2000000000000002e34 or 5.19999999999999999e93 < y < 1.8000000000000001e141 or 9.6000000000000003e200 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 53.6%
Taylor expanded in y around inf 52.0%
if -1 < y < 3.7999999999999998e-114Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 78.2%
if 3.7999999999999998e-114 < y < 2.6e16 or 2.2000000000000002e34 < y < 5.19999999999999999e93 or 1.8000000000000001e141 < y < 9.6000000000000003e200Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 55.4%
Final simplification62.7%
(FPCore (x y) :precision binary64 (if (or (<= x -6.2e-83) (not (<= x 4e-8))) (* x (+ y 1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -6.2e-83) || !(x <= 4e-8)) {
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 <= (-6.2d-83)) .or. (.not. (x <= 4d-8))) 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 <= -6.2e-83) || !(x <= 4e-8)) {
tmp = x * (y + 1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6.2e-83) or not (x <= 4e-8): tmp = x * (y + 1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -6.2e-83) || !(x <= 4e-8)) 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 <= -6.2e-83) || ~((x <= 4e-8))) tmp = x * (y + 1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6.2e-83], N[Not[LessEqual[x, 4e-8]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-83} \lor \neg \left(x \leq 4 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.19999999999999985e-83 or 4.0000000000000001e-8 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 91.5%
if -6.19999999999999985e-83 < x < 4.0000000000000001e-8Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 78.7%
Final simplification85.9%
(FPCore (x y) :precision binary64 (if (<= y 1.65e-118) (* x (+ y 1.0)) (+ y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 1.65e-118) {
tmp = x * (y + 1.0);
} 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 <= 1.65d-118) then
tmp = x * (y + 1.0d0)
else
tmp = y + (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.65e-118) {
tmp = x * (y + 1.0);
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.65e-118: tmp = x * (y + 1.0) else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.65e-118) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.65e-118) tmp = x * (y + 1.0); else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.65e-118], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-118}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if y < 1.65e-118Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 64.3%
if 1.65e-118 < y Initial program 100.0%
Taylor expanded in y around inf 87.6%
Final simplification72.4%
(FPCore (x y) :precision binary64 (+ x (* y (+ x 1.0))))
double code(double x, double y) {
return x + (y * (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (y * (x + 1.0d0))
end function
public static double code(double x, double y) {
return x + (y * (x + 1.0));
}
def code(x, y): return x + (y * (x + 1.0))
function code(x, y) return Float64(x + Float64(y * Float64(x + 1.0))) end
function tmp = code(x, y) tmp = x + (y * (x + 1.0)); end
code[x_, y_] := N[(x + N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x + 1\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y 3.5e-114) x y))
double code(double x, double y) {
double tmp;
if (y <= 3.5e-114) {
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 <= 3.5d-114) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.5e-114) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.5e-114: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 3.5e-114) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.5e-114) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.5e-114], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.5 \cdot 10^{-114}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 3.5e-114Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 45.8%
if 3.5e-114 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 45.6%
Final simplification45.7%
(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%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 34.9%
Final simplification34.9%
herbie shell --seed 2023257
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))