
(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 (fma x y x)))
double code(double x, double y) {
return y + fma(x, y, x);
}
function code(x, y) return Float64(y + fma(x, y, x)) end
code[x_, y_] := N[(y + N[(x * y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \mathsf{fma}\left(x, y, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -1.35e+276)
x
(if (<= x -2.05e+173)
(* y x)
(if (<= x -3.8e+41)
x
(if (<= x -6.8e+14)
(* y x)
(if (<= x -1.45e-130) x (if (<= x 1.0) y (* y x))))))))
double code(double x, double y) {
double tmp;
if (x <= -1.35e+276) {
tmp = x;
} else if (x <= -2.05e+173) {
tmp = y * x;
} else if (x <= -3.8e+41) {
tmp = x;
} else if (x <= -6.8e+14) {
tmp = y * x;
} else if (x <= -1.45e-130) {
tmp = 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 <= (-1.35d+276)) then
tmp = x
else if (x <= (-2.05d+173)) then
tmp = y * x
else if (x <= (-3.8d+41)) then
tmp = x
else if (x <= (-6.8d+14)) then
tmp = y * x
else if (x <= (-1.45d-130)) then
tmp = 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 <= -1.35e+276) {
tmp = x;
} else if (x <= -2.05e+173) {
tmp = y * x;
} else if (x <= -3.8e+41) {
tmp = x;
} else if (x <= -6.8e+14) {
tmp = y * x;
} else if (x <= -1.45e-130) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.35e+276: tmp = x elif x <= -2.05e+173: tmp = y * x elif x <= -3.8e+41: tmp = x elif x <= -6.8e+14: tmp = y * x elif x <= -1.45e-130: tmp = x elif x <= 1.0: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.35e+276) tmp = x; elseif (x <= -2.05e+173) tmp = Float64(y * x); elseif (x <= -3.8e+41) tmp = x; elseif (x <= -6.8e+14) tmp = Float64(y * x); elseif (x <= -1.45e-130) tmp = 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 <= -1.35e+276) tmp = x; elseif (x <= -2.05e+173) tmp = y * x; elseif (x <= -3.8e+41) tmp = x; elseif (x <= -6.8e+14) tmp = y * x; elseif (x <= -1.45e-130) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.35e+276], x, If[LessEqual[x, -2.05e+173], N[(y * x), $MachinePrecision], If[LessEqual[x, -3.8e+41], x, If[LessEqual[x, -6.8e+14], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.45e-130], x, If[LessEqual[x, 1.0], y, N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+276}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{+173}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -3.8 \cdot 10^{+41}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -6.8 \cdot 10^{+14}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-130}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.34999999999999998e276 or -2.04999999999999988e173 < x < -3.8000000000000001e41 or -6.8e14 < x < -1.45e-130Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 62.5%
if -1.34999999999999998e276 < x < -2.04999999999999988e173 or -3.8000000000000001e41 < x < -6.8e14 or 1 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 57.0%
if -1.45e-130 < x < 1Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 74.4%
Final simplification65.0%
(FPCore (x y)
:precision binary64
(if (<= x -6.6e+275)
x
(if (<= x -3.45e+174)
(* y x)
(if (<= x -2.05e+40)
x
(if (<= x -2.3e+15)
(* y x)
(if (<= x 12500000000.0) (+ y x) (* y x)))))))
double code(double x, double y) {
double tmp;
if (x <= -6.6e+275) {
tmp = x;
} else if (x <= -3.45e+174) {
tmp = y * x;
} else if (x <= -2.05e+40) {
tmp = x;
} else if (x <= -2.3e+15) {
tmp = y * x;
} else if (x <= 12500000000.0) {
tmp = y + x;
} 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 <= (-6.6d+275)) then
tmp = x
else if (x <= (-3.45d+174)) then
tmp = y * x
else if (x <= (-2.05d+40)) then
tmp = x
else if (x <= (-2.3d+15)) then
tmp = y * x
else if (x <= 12500000000.0d0) then
tmp = y + x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.6e+275) {
tmp = x;
} else if (x <= -3.45e+174) {
tmp = y * x;
} else if (x <= -2.05e+40) {
tmp = x;
} else if (x <= -2.3e+15) {
tmp = y * x;
} else if (x <= 12500000000.0) {
tmp = y + x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.6e+275: tmp = x elif x <= -3.45e+174: tmp = y * x elif x <= -2.05e+40: tmp = x elif x <= -2.3e+15: tmp = y * x elif x <= 12500000000.0: tmp = y + x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -6.6e+275) tmp = x; elseif (x <= -3.45e+174) tmp = Float64(y * x); elseif (x <= -2.05e+40) tmp = x; elseif (x <= -2.3e+15) tmp = Float64(y * x); elseif (x <= 12500000000.0) tmp = Float64(y + x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.6e+275) tmp = x; elseif (x <= -3.45e+174) tmp = y * x; elseif (x <= -2.05e+40) tmp = x; elseif (x <= -2.3e+15) tmp = y * x; elseif (x <= 12500000000.0) tmp = y + x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.6e+275], x, If[LessEqual[x, -3.45e+174], N[(y * x), $MachinePrecision], If[LessEqual[x, -2.05e+40], x, If[LessEqual[x, -2.3e+15], N[(y * x), $MachinePrecision], If[LessEqual[x, 12500000000.0], N[(y + x), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{+275}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -3.45 \cdot 10^{+174}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{+40}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{+15}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 12500000000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -6.60000000000000044e275 or -3.4500000000000001e174 < x < -2.0500000000000001e40Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 62.6%
if -6.60000000000000044e275 < x < -3.4500000000000001e174 or -2.0500000000000001e40 < x < -2.3e15 or 1.25e10 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 57.6%
if -2.3e15 < x < 1.25e10Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
fma-def100.0%
+-commutative100.0%
add-sqr-sqrt51.9%
pow251.9%
+-commutative51.9%
*-commutative51.9%
fma-def51.9%
Applied egg-rr51.9%
Taylor expanded in y around -inf 51.9%
mul-1-neg51.9%
unsub-neg51.9%
*-commutative51.9%
sub-neg51.9%
metadata-eval51.9%
+-commutative51.9%
mul-1-neg51.9%
unsub-neg51.9%
Simplified51.9%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
Simplified51.4%
Taylor expanded in x around 0 98.8%
Final simplification79.0%
(FPCore (x y) :precision binary64 (if (<= x -1950000000000.0) (* x (+ y 1.0)) (if (<= x 7e-57) (+ y x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (x <= -1950000000000.0) {
tmp = x * (y + 1.0);
} else if (x <= 7e-57) {
tmp = y + x;
} 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 (x <= (-1950000000000.0d0)) then
tmp = x * (y + 1.0d0)
else if (x <= 7d-57) then
tmp = y + x
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1950000000000.0) {
tmp = x * (y + 1.0);
} else if (x <= 7e-57) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1950000000000.0: tmp = x * (y + 1.0) elif x <= 7e-57: tmp = y + x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1950000000000.0) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 7e-57) tmp = Float64(y + x); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1950000000000.0) tmp = x * (y + 1.0); elseif (x <= 7e-57) tmp = y + x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1950000000000.0], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7e-57], N[(y + x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1950000000000:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-57}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if x < -1.95e12Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -1.95e12 < x < 6.99999999999999983e-57Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
fma-def100.0%
+-commutative100.0%
add-sqr-sqrt49.6%
pow249.6%
+-commutative49.6%
*-commutative49.6%
fma-def49.6%
Applied egg-rr49.6%
Taylor expanded in y around -inf 49.6%
mul-1-neg49.6%
unsub-neg49.6%
*-commutative49.6%
sub-neg49.6%
metadata-eval49.6%
+-commutative49.6%
mul-1-neg49.6%
unsub-neg49.6%
Simplified49.6%
Taylor expanded in x around 0 49.6%
neg-mul-149.6%
Simplified49.6%
Taylor expanded in x around 0 99.6%
if 6.99999999999999983e-57 < x Initial program 100.0%
Taylor expanded in y around inf 51.9%
Final simplification85.9%
(FPCore (x y) :precision binary64 (if (<= x -1950000000000.0) (* x (+ y 1.0)) (if (<= x 1900000000000.0) (+ y x) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -1950000000000.0) {
tmp = x * (y + 1.0);
} else if (x <= 1900000000000.0) {
tmp = y + x;
} 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 <= (-1950000000000.0d0)) then
tmp = x * (y + 1.0d0)
else if (x <= 1900000000000.0d0) then
tmp = y + x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1950000000000.0) {
tmp = x * (y + 1.0);
} else if (x <= 1900000000000.0) {
tmp = y + x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1950000000000.0: tmp = x * (y + 1.0) elif x <= 1900000000000.0: tmp = y + x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1950000000000.0) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 1900000000000.0) tmp = Float64(y + x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1950000000000.0) tmp = x * (y + 1.0); elseif (x <= 1900000000000.0) tmp = y + x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1950000000000.0], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1900000000000.0], N[(y + x), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1950000000000:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 1900000000000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.95e12Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -1.95e12 < x < 1.9e12Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
fma-def100.0%
+-commutative100.0%
add-sqr-sqrt51.9%
pow251.9%
+-commutative51.9%
*-commutative51.9%
fma-def51.9%
Applied egg-rr51.9%
Taylor expanded in y around -inf 51.9%
mul-1-neg51.9%
unsub-neg51.9%
*-commutative51.9%
sub-neg51.9%
metadata-eval51.9%
+-commutative51.9%
mul-1-neg51.9%
unsub-neg51.9%
Simplified51.9%
Taylor expanded in x around 0 51.4%
neg-mul-151.4%
Simplified51.4%
Taylor expanded in x around 0 98.8%
if 1.9e12 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 52.0%
Final simplification88.1%
(FPCore (x y) :precision binary64 (+ y (+ x (* y x))))
double code(double x, double y) {
return y + (x + (y * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x + (y * x))
end function
public static double code(double x, double y) {
return y + (x + (y * x));
}
def code(x, y): return y + (x + (y * x))
function code(x, y) return Float64(y + Float64(x + Float64(y * x))) end
function tmp = code(x, y) tmp = y + (x + (y * x)); end
code[x_, y_] := N[(y + N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(x + y \cdot x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -2.2e-129) x y))
double code(double x, double y) {
double tmp;
if (x <= -2.2e-129) {
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 <= (-2.2d-129)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.2e-129) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.2e-129: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.2e-129) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.2e-129) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.2e-129], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{-129}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.20000000000000003e-129Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 52.7%
if -2.20000000000000003e-129 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 47.1%
Final simplification49.3%
(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%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 42.5%
Final simplification42.5%
herbie shell --seed 2023253
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))