
(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 (+ 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 -4.5e+27)
(* x y)
(if (or (<= y 6.4e+157) (and (not (<= y 7.8e+201)) (<= y 6e+240)))
(+ x y)
(* x y))))
double code(double x, double y) {
double tmp;
if (y <= -4.5e+27) {
tmp = x * y;
} else if ((y <= 6.4e+157) || (!(y <= 7.8e+201) && (y <= 6e+240))) {
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.5d+27)) then
tmp = x * y
else if ((y <= 6.4d+157) .or. (.not. (y <= 7.8d+201)) .and. (y <= 6d+240)) 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.5e+27) {
tmp = x * y;
} else if ((y <= 6.4e+157) || (!(y <= 7.8e+201) && (y <= 6e+240))) {
tmp = x + y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.5e+27: tmp = x * y elif (y <= 6.4e+157) or (not (y <= 7.8e+201) and (y <= 6e+240)): tmp = x + y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.5e+27) tmp = Float64(x * y); elseif ((y <= 6.4e+157) || (!(y <= 7.8e+201) && (y <= 6e+240))) 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.5e+27) tmp = x * y; elseif ((y <= 6.4e+157) || (~((y <= 7.8e+201)) && (y <= 6e+240))) tmp = x + y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.5e+27], N[(x * y), $MachinePrecision], If[Or[LessEqual[y, 6.4e+157], And[N[Not[LessEqual[y, 7.8e+201]], $MachinePrecision], LessEqual[y, 6e+240]]], N[(x + y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+27}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+157} \lor \neg \left(y \leq 7.8 \cdot 10^{+201}\right) \land y \leq 6 \cdot 10^{+240}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -4.4999999999999999e27 or 6.3999999999999999e157 < y < 7.8000000000000001e201 or 5.9999999999999997e240 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 60.4%
if -4.4999999999999999e27 < y < 6.3999999999999999e157 or 7.8000000000000001e201 < y < 5.9999999999999997e240Initial program 100.0%
Taylor expanded in y around 0 89.9%
Final simplification81.8%
(FPCore (x y) :precision binary64 (if (<= y -2.4e+24) (* x y) (if (<= y 1.0) (+ x y) (+ y (* x y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.4e+24) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = 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.4d+24)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = 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.4e+24) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x + y;
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.4e+24: tmp = x * y elif y <= 1.0: tmp = x + y else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.4e+24) tmp = Float64(x * y); elseif (y <= 1.0) tmp = 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.4e+24) tmp = x * y; elseif (y <= 1.0) tmp = x + y; else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.4e+24], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], N[(x + y), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+24}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if y < -2.4000000000000001e24Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 55.2%
if -2.4000000000000001e24 < y < 1Initial program 100.0%
Taylor expanded in y around 0 97.3%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 97.6%
Final simplification88.5%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x y) (if (<= x 1.0) y (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * y;
} else if (x <= 1.0) {
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 (x <= (-1.0d0)) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x * y elif x <= 1.0: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * y); elseif (x <= 1.0) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = x * y; elseif (x <= 1.0) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 51.0%
Taylor expanded in x around inf 50.3%
if -1 < x < 1Initial program 100.0%
Taylor expanded in y around inf 73.5%
Taylor expanded in x around 0 73.2%
Final simplification62.5%
(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 y around inf 63.0%
Taylor expanded in x around 0 40.7%
Final simplification40.7%
herbie shell --seed 2023185
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))