
(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 6 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 1.9e-96)
x
(if (<= y 32500000000000.0)
y
(if (or (<= y 1.15e+49)
(and (not (<= y 3.5e+104))
(or (<= y 2.85e+152)
(and (not (<= y 5.6e+161))
(or (<= y 4.7e+214)
(and (not (<= y 4.2e+247))
(<= y 3.8e+260)))))))
(* x y)
y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.9e-96) {
tmp = x;
} else if (y <= 32500000000000.0) {
tmp = y;
} else if ((y <= 1.15e+49) || (!(y <= 3.5e+104) && ((y <= 2.85e+152) || (!(y <= 5.6e+161) && ((y <= 4.7e+214) || (!(y <= 4.2e+247) && (y <= 3.8e+260))))))) {
tmp = x * y;
} 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 <= (-1.0d0)) then
tmp = x * y
else if (y <= 1.9d-96) then
tmp = x
else if (y <= 32500000000000.0d0) then
tmp = y
else if ((y <= 1.15d+49) .or. (.not. (y <= 3.5d+104)) .and. (y <= 2.85d+152) .or. (.not. (y <= 5.6d+161)) .and. (y <= 4.7d+214) .or. (.not. (y <= 4.2d+247)) .and. (y <= 3.8d+260)) then
tmp = x * y
else
tmp = 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 <= 1.9e-96) {
tmp = x;
} else if (y <= 32500000000000.0) {
tmp = y;
} else if ((y <= 1.15e+49) || (!(y <= 3.5e+104) && ((y <= 2.85e+152) || (!(y <= 5.6e+161) && ((y <= 4.7e+214) || (!(y <= 4.2e+247) && (y <= 3.8e+260))))))) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.9e-96: tmp = x elif y <= 32500000000000.0: tmp = y elif (y <= 1.15e+49) or (not (y <= 3.5e+104) and ((y <= 2.85e+152) or (not (y <= 5.6e+161) and ((y <= 4.7e+214) or (not (y <= 4.2e+247) and (y <= 3.8e+260)))))): tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1.9e-96) tmp = x; elseif (y <= 32500000000000.0) tmp = y; elseif ((y <= 1.15e+49) || (!(y <= 3.5e+104) && ((y <= 2.85e+152) || (!(y <= 5.6e+161) && ((y <= 4.7e+214) || (!(y <= 4.2e+247) && (y <= 3.8e+260))))))) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 1.9e-96) tmp = x; elseif (y <= 32500000000000.0) tmp = y; elseif ((y <= 1.15e+49) || (~((y <= 3.5e+104)) && ((y <= 2.85e+152) || (~((y <= 5.6e+161)) && ((y <= 4.7e+214) || (~((y <= 4.2e+247)) && (y <= 3.8e+260))))))) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.9e-96], x, If[LessEqual[y, 32500000000000.0], y, If[Or[LessEqual[y, 1.15e+49], And[N[Not[LessEqual[y, 3.5e+104]], $MachinePrecision], Or[LessEqual[y, 2.85e+152], And[N[Not[LessEqual[y, 5.6e+161]], $MachinePrecision], Or[LessEqual[y, 4.7e+214], And[N[Not[LessEqual[y, 4.2e+247]], $MachinePrecision], LessEqual[y, 3.8e+260]]]]]]], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-96}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 32500000000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+49} \lor \neg \left(y \leq 3.5 \cdot 10^{+104}\right) \land \left(y \leq 2.85 \cdot 10^{+152} \lor \neg \left(y \leq 5.6 \cdot 10^{+161}\right) \land \left(y \leq 4.7 \cdot 10^{+214} \lor \neg \left(y \leq 4.2 \cdot 10^{+247}\right) \land y \leq 3.8 \cdot 10^{+260}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 3.25e13 < y < 1.15000000000000001e49 or 3.5000000000000002e104 < y < 2.85000000000000003e152 or 5.60000000000000041e161 < y < 4.7e214 or 4.2e247 < y < 3.7999999999999997e260Initial program 100.0%
Taylor expanded in x around inf 61.9%
+-commutative61.9%
Simplified61.9%
Taylor expanded in y around inf 61.3%
if -1 < y < 1.9e-96Initial program 100.0%
Taylor expanded in y around 0 74.3%
if 1.9e-96 < y < 3.25e13 or 1.15000000000000001e49 < y < 3.5000000000000002e104 or 2.85000000000000003e152 < y < 5.60000000000000041e161 or 4.7e214 < y < 4.2e247 or 3.7999999999999997e260 < y Initial program 100.0%
Taylor expanded in x around 0 66.3%
Final simplification67.7%
(FPCore (x y) :precision binary64 (if (<= x -5.2e-14) (* x (+ y 1.0)) (if (<= x -2.05e-44) y (if (<= x -3.4e-142) x (if (<= x 1.0) y (* x y))))))
double code(double x, double y) {
double tmp;
if (x <= -5.2e-14) {
tmp = x * (y + 1.0);
} else if (x <= -2.05e-44) {
tmp = y;
} else if (x <= -3.4e-142) {
tmp = x;
} 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 <= (-5.2d-14)) then
tmp = x * (y + 1.0d0)
else if (x <= (-2.05d-44)) then
tmp = y
else if (x <= (-3.4d-142)) then
tmp = x
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 <= -5.2e-14) {
tmp = x * (y + 1.0);
} else if (x <= -2.05e-44) {
tmp = y;
} else if (x <= -3.4e-142) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.2e-14: tmp = x * (y + 1.0) elif x <= -2.05e-44: tmp = y elif x <= -3.4e-142: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -5.2e-14) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= -2.05e-44) tmp = y; elseif (x <= -3.4e-142) tmp = x; 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 <= -5.2e-14) tmp = x * (y + 1.0); elseif (x <= -2.05e-44) tmp = y; elseif (x <= -3.4e-142) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.2e-14], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2.05e-44], y, If[LessEqual[x, -3.4e-142], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{-14}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{-44}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -3.4 \cdot 10^{-142}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.19999999999999993e-14Initial program 100.0%
Taylor expanded in x around inf 97.1%
+-commutative97.1%
Simplified97.1%
if -5.19999999999999993e-14 < x < -2.04999999999999996e-44 or -3.40000000000000029e-142 < x < 1Initial program 100.0%
Taylor expanded in x around 0 82.7%
if -2.04999999999999996e-44 < x < -3.40000000000000029e-142Initial program 100.0%
Taylor expanded in y around 0 49.7%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 55.8%
Final simplification77.5%
(FPCore (x y) :precision binary64 (if (<= y 1.35e-96) (* x (+ y 1.0)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= 1.35e-96) {
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 <= 1.35d-96) 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 <= 1.35e-96) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.35e-96: tmp = x * (y + 1.0) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.35e-96) 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 <= 1.35e-96) tmp = x * (y + 1.0); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.35e-96], 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 1.35 \cdot 10^{-96}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 1.35e-96Initial program 100.0%
Taylor expanded in x around inf 69.6%
+-commutative69.6%
Simplified69.6%
if 1.35e-96 < y Initial program 100.0%
Taylor expanded in y around inf 92.3%
Final simplification77.0%
(FPCore (x y) :precision binary64 (if (<= y 1.8e-96) x y))
double code(double x, double y) {
double tmp;
if (y <= 1.8e-96) {
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 <= 1.8d-96) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.8e-96) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.8e-96: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.8e-96) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.8e-96) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.8e-96], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.8 \cdot 10^{-96}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.80000000000000004e-96Initial program 100.0%
Taylor expanded in y around 0 47.0%
if 1.80000000000000004e-96 < y Initial program 100.0%
Taylor expanded in x around 0 52.8%
Final simplification48.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 35.1%
Final simplification35.1%
herbie shell --seed 2023322
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))