
(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 (<= x -2.2e+273)
x
(if (<= x -1.2e+179)
(* x y)
(if (<= x -1e+130)
x
(if (<= x -2.1e+103)
(* x y)
(if (<= x -1.18e-110) x (if (<= x 1.0) y (* x y))))))))
double code(double x, double y) {
double tmp;
if (x <= -2.2e+273) {
tmp = x;
} else if (x <= -1.2e+179) {
tmp = x * y;
} else if (x <= -1e+130) {
tmp = x;
} else if (x <= -2.1e+103) {
tmp = x * y;
} else if (x <= -1.18e-110) {
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 <= (-2.2d+273)) then
tmp = x
else if (x <= (-1.2d+179)) then
tmp = x * y
else if (x <= (-1d+130)) then
tmp = x
else if (x <= (-2.1d+103)) then
tmp = x * y
else if (x <= (-1.18d-110)) 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 <= -2.2e+273) {
tmp = x;
} else if (x <= -1.2e+179) {
tmp = x * y;
} else if (x <= -1e+130) {
tmp = x;
} else if (x <= -2.1e+103) {
tmp = x * y;
} else if (x <= -1.18e-110) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.2e+273: tmp = x elif x <= -1.2e+179: tmp = x * y elif x <= -1e+130: tmp = x elif x <= -2.1e+103: tmp = x * y elif x <= -1.18e-110: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.2e+273) tmp = x; elseif (x <= -1.2e+179) tmp = Float64(x * y); elseif (x <= -1e+130) tmp = x; elseif (x <= -2.1e+103) tmp = Float64(x * y); elseif (x <= -1.18e-110) 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 <= -2.2e+273) tmp = x; elseif (x <= -1.2e+179) tmp = x * y; elseif (x <= -1e+130) tmp = x; elseif (x <= -2.1e+103) tmp = x * y; elseif (x <= -1.18e-110) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.2e+273], x, If[LessEqual[x, -1.2e+179], N[(x * y), $MachinePrecision], If[LessEqual[x, -1e+130], x, If[LessEqual[x, -2.1e+103], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.18e-110], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+273}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -1.2 \cdot 10^{+179}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1 \cdot 10^{+130}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.1 \cdot 10^{+103}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.18 \cdot 10^{-110}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.1999999999999999e273 or -1.20000000000000006e179 < x < -1.0000000000000001e130 or -2.1000000000000002e103 < x < -1.18e-110Initial program 100.0%
add-cube-cbrt98.3%
pow398.3%
+-commutative98.3%
*-un-lft-identity98.3%
*-commutative98.3%
distribute-rgt-out98.2%
fma-define98.2%
Applied egg-rr98.2%
Taylor expanded in y around 0 55.1%
pow-base-155.1%
*-lft-identity55.1%
Simplified55.1%
if -2.1999999999999999e273 < x < -1.20000000000000006e179 or -1.0000000000000001e130 < x < -2.1000000000000002e103 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 62.0%
Taylor expanded in x around inf 60.9%
*-commutative60.9%
Simplified60.9%
if -1.18e-110 < x < 1Initial program 100.0%
Taylor expanded in x around 0 77.1%
Final simplification67.4%
(FPCore (x y)
:precision binary64
(if (<= x -1.2e+273)
x
(if (<= x -6e+178)
(* x y)
(if (<= x -6.6e+129)
x
(if (or (<= x -1.4e+97) (not (<= x 3300.0))) (* x y) (+ x y))))))
double code(double x, double y) {
double tmp;
if (x <= -1.2e+273) {
tmp = x;
} else if (x <= -6e+178) {
tmp = x * y;
} else if (x <= -6.6e+129) {
tmp = x;
} else if ((x <= -1.4e+97) || !(x <= 3300.0)) {
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 (x <= (-1.2d+273)) then
tmp = x
else if (x <= (-6d+178)) then
tmp = x * y
else if (x <= (-6.6d+129)) then
tmp = x
else if ((x <= (-1.4d+97)) .or. (.not. (x <= 3300.0d0))) 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 (x <= -1.2e+273) {
tmp = x;
} else if (x <= -6e+178) {
tmp = x * y;
} else if (x <= -6.6e+129) {
tmp = x;
} else if ((x <= -1.4e+97) || !(x <= 3300.0)) {
tmp = x * y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.2e+273: tmp = x elif x <= -6e+178: tmp = x * y elif x <= -6.6e+129: tmp = x elif (x <= -1.4e+97) or not (x <= 3300.0): tmp = x * y else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.2e+273) tmp = x; elseif (x <= -6e+178) tmp = Float64(x * y); elseif (x <= -6.6e+129) tmp = x; elseif ((x <= -1.4e+97) || !(x <= 3300.0)) tmp = Float64(x * y); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.2e+273) tmp = x; elseif (x <= -6e+178) tmp = x * y; elseif (x <= -6.6e+129) tmp = x; elseif ((x <= -1.4e+97) || ~((x <= 3300.0))) tmp = x * y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.2e+273], x, If[LessEqual[x, -6e+178], N[(x * y), $MachinePrecision], If[LessEqual[x, -6.6e+129], x, If[Or[LessEqual[x, -1.4e+97], N[Not[LessEqual[x, 3300.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x + y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+273}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -6 \cdot 10^{+178}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -6.6 \cdot 10^{+129}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -1.4 \cdot 10^{+97} \lor \neg \left(x \leq 3300\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if x < -1.2000000000000001e273 or -6.00000000000000031e178 < x < -6.5999999999999998e129Initial program 100.0%
add-cube-cbrt99.2%
pow399.2%
+-commutative99.2%
*-un-lft-identity99.2%
*-commutative99.2%
distribute-rgt-out99.2%
fma-define99.2%
Applied egg-rr99.2%
Taylor expanded in y around 0 54.6%
pow-base-154.6%
*-lft-identity54.6%
Simplified54.6%
if -1.2000000000000001e273 < x < -6.00000000000000031e178 or -6.5999999999999998e129 < x < -1.4e97 or 3300 < x Initial program 100.0%
Taylor expanded in y around inf 62.0%
Taylor expanded in x around inf 60.9%
*-commutative60.9%
Simplified60.9%
if -1.4e97 < x < 3300Initial program 100.0%
Taylor expanded in y around 0 95.5%
Final simplification81.7%
(FPCore (x y) :precision binary64 (if (<= y -44000000000.0) (* x y) (if (<= y 2.3e-6) (+ x y) (+ y (* x y)))))
double code(double x, double y) {
double tmp;
if (y <= -44000000000.0) {
tmp = x * y;
} else if (y <= 2.3e-6) {
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 <= (-44000000000.0d0)) then
tmp = x * y
else if (y <= 2.3d-6) 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 <= -44000000000.0) {
tmp = x * y;
} else if (y <= 2.3e-6) {
tmp = x + y;
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -44000000000.0: tmp = x * y elif y <= 2.3e-6: tmp = x + y else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= -44000000000.0) tmp = Float64(x * y); elseif (y <= 2.3e-6) 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 <= -44000000000.0) tmp = x * y; elseif (y <= 2.3e-6) tmp = x + y; else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -44000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.3e-6], N[(x + y), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -44000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-6}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if y < -4.4e10Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 57.5%
*-commutative57.5%
Simplified57.5%
if -4.4e10 < y < 2.3e-6Initial program 100.0%
Taylor expanded in y around 0 98.5%
if 2.3e-6 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Final simplification88.3%
(FPCore (x y) :precision binary64 (if (<= x -1.18e-110) x y))
double code(double x, double y) {
double tmp;
if (x <= -1.18e-110) {
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 <= (-1.18d-110)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.18e-110) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.18e-110: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.18e-110) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.18e-110) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.18e-110], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.18 \cdot 10^{-110}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.18e-110Initial program 100.0%
add-cube-cbrt98.5%
pow398.5%
+-commutative98.5%
*-un-lft-identity98.5%
*-commutative98.5%
distribute-rgt-out98.5%
fma-define98.5%
Applied egg-rr98.5%
Taylor expanded in y around 0 48.6%
pow-base-148.6%
*-lft-identity48.6%
Simplified48.6%
if -1.18e-110 < x Initial program 100.0%
Taylor expanded in x around 0 51.4%
Final simplification50.6%
(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%
add-cube-cbrt98.2%
pow398.2%
+-commutative98.2%
*-un-lft-identity98.2%
*-commutative98.2%
distribute-rgt-out98.2%
fma-define98.2%
Applied egg-rr98.2%
Taylor expanded in y around 0 35.1%
pow-base-135.1%
*-lft-identity35.1%
Simplified35.1%
Final simplification35.1%
herbie shell --seed 2024041
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))