
(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 (* (+ y 1.0) x)))
double code(double x, double y) {
return y + ((y + 1.0) * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + ((y + 1.0d0) * x)
end function
public static double code(double x, double y) {
return y + ((y + 1.0) * x);
}
def code(x, y): return y + ((y + 1.0) * x)
function code(x, y) return Float64(y + Float64(Float64(y + 1.0) * x)) end
function tmp = code(x, y) tmp = y + ((y + 1.0) * x); end
code[x_, y_] := N[(y + N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(y + 1\right) \cdot x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -30500000000.0) (* y x) (if (<= y 8.5e-13) (+ y x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -30500000000.0) {
tmp = y * x;
} else if (y <= 8.5e-13) {
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 (y <= (-30500000000.0d0)) then
tmp = y * x
else if (y <= 8.5d-13) 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 (y <= -30500000000.0) {
tmp = y * x;
} else if (y <= 8.5e-13) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -30500000000.0: tmp = y * x elif y <= 8.5e-13: tmp = y + x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -30500000000.0) tmp = Float64(y * x); elseif (y <= 8.5e-13) 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 (y <= -30500000000.0) tmp = y * x; elseif (y <= 8.5e-13) tmp = y + x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -30500000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 8.5e-13], N[(y + x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -30500000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-13}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -3.05e10Initial program 100.0%
Taylor expanded in y around inf 99.7%
Taylor expanded in x around inf 53.7%
*-commutative53.7%
Simplified53.7%
if -3.05e10 < y < 8.5000000000000001e-13Initial program 100.0%
Taylor expanded in y around 0 98.9%
if 8.5000000000000001e-13 < y Initial program 100.0%
Taylor expanded in y around inf 99.7%
Final simplification86.1%
(FPCore (x y) :precision binary64 (if (or (<= x -3.1) (not (<= x 1.0))) (* y x) y))
double code(double x, double y) {
double tmp;
if ((x <= -3.1) || !(x <= 1.0)) {
tmp = y * 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.1d0)) .or. (.not. (x <= 1.0d0))) then
tmp = y * x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3.1) || !(x <= 1.0)) {
tmp = y * x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.1) or not (x <= 1.0): tmp = y * x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.1) || !(x <= 1.0)) tmp = Float64(y * x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.1) || ~((x <= 1.0))) tmp = y * x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.1], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.10000000000000009 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 55.0%
Taylor expanded in x around inf 54.8%
*-commutative54.8%
Simplified54.8%
if -3.10000000000000009 < x < 1Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 74.2%
Final simplification64.4%
(FPCore (x y) :precision binary64 (if (or (<= y -720000.0) (not (<= y 2.7e+249))) (* y x) (+ y x)))
double code(double x, double y) {
double tmp;
if ((y <= -720000.0) || !(y <= 2.7e+249)) {
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 ((y <= (-720000.0d0)) .or. (.not. (y <= 2.7d+249))) 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 ((y <= -720000.0) || !(y <= 2.7e+249)) {
tmp = y * x;
} else {
tmp = y + x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -720000.0) or not (y <= 2.7e+249): tmp = y * x else: tmp = y + x return tmp
function code(x, y) tmp = 0.0 if ((y <= -720000.0) || !(y <= 2.7e+249)) tmp = Float64(y * x); else tmp = Float64(y + x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -720000.0) || ~((y <= 2.7e+249))) tmp = y * x; else tmp = y + x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -720000.0], N[Not[LessEqual[y, 2.7e+249]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -720000 \lor \neg \left(y \leq 2.7 \cdot 10^{+249}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if y < -7.2e5 or 2.70000000000000018e249 < y Initial program 100.0%
Taylor expanded in y around inf 99.7%
Taylor expanded in x around inf 54.6%
*-commutative54.6%
Simplified54.6%
if -7.2e5 < y < 2.70000000000000018e249Initial program 100.0%
Taylor expanded in y around 0 85.1%
Final simplification75.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%
associate-+l+100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 38.2%
Final simplification38.2%
herbie shell --seed 2023310
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))