
(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 7 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 (+ x (* y (+ x 1.0))))
double code(double x, double y) {
return x + (y * (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (y * (x + 1.0d0))
end function
public static double code(double x, double y) {
return x + (y * (x + 1.0));
}
def code(x, y): return x + (y * (x + 1.0))
function code(x, y) return Float64(x + Float64(y * Float64(x + 1.0))) end
function tmp = code(x, y) tmp = x + (y * (x + 1.0)); end
code[x_, y_] := N[(x + N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x + 1\right)
\end{array}
Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 7e-93) x (if (<= y 3.7e+32) y (if (<= y 1.14e+232) (* x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 7e-93) {
tmp = x;
} else if (y <= 3.7e+32) {
tmp = y;
} else if (y <= 1.14e+232) {
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 <= 7d-93) then
tmp = x
else if (y <= 3.7d+32) then
tmp = y
else if (y <= 1.14d+232) 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 <= 7e-93) {
tmp = x;
} else if (y <= 3.7e+32) {
tmp = y;
} else if (y <= 1.14e+232) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 7e-93: tmp = x elif y <= 3.7e+32: tmp = y elif y <= 1.14e+232: 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 <= 7e-93) tmp = x; elseif (y <= 3.7e+32) tmp = y; elseif (y <= 1.14e+232) 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 <= 7e-93) tmp = x; elseif (y <= 3.7e+32) tmp = y; elseif (y <= 1.14e+232) 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, 7e-93], x, If[LessEqual[y, 3.7e+32], y, If[LessEqual[y, 1.14e+232], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+32}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.14 \cdot 10^{+232}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 3.7e32 < y < 1.14e232Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6457.5%
Simplified57.5%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6457.1%
Simplified57.1%
if -1 < y < 7e-93Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
Simplified77.2%
if 7e-93 < y < 3.7e32 or 1.14e232 < y Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified58.1%
Final simplification65.3%
(FPCore (x y) :precision binary64 (if (<= x -265000.0) (* x (+ y 1.0)) (if (<= x 3.2e-67) (+ x y) (* y (+ x 1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -265000.0) {
tmp = x * (y + 1.0);
} else if (x <= 3.2e-67) {
tmp = x + y;
} 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 (x <= (-265000.0d0)) then
tmp = x * (y + 1.0d0)
else if (x <= 3.2d-67) then
tmp = x + y
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -265000.0) {
tmp = x * (y + 1.0);
} else if (x <= 3.2e-67) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -265000.0: tmp = x * (y + 1.0) elif x <= 3.2e-67: tmp = x + y else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -265000.0) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 3.2e-67) tmp = Float64(x + y); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -265000.0) tmp = x * (y + 1.0); elseif (x <= 3.2e-67) tmp = x + y; else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -265000.0], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.2e-67], N[(x + y), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -265000:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-67}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -265000Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0%
Simplified100.0%
if -265000 < x < 3.20000000000000021e-67Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified97.8%
if 3.20000000000000021e-67 < x Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6456.6%
Simplified56.6%
(FPCore (x y) :precision binary64 (if (<= x -265000.0) (* x (+ y 1.0)) (if (<= x 3900.0) (+ x y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -265000.0) {
tmp = x * (y + 1.0);
} else if (x <= 3900.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 <= (-265000.0d0)) then
tmp = x * (y + 1.0d0)
else if (x <= 3900.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 <= -265000.0) {
tmp = x * (y + 1.0);
} else if (x <= 3900.0) {
tmp = x + y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -265000.0: tmp = x * (y + 1.0) elif x <= 3900.0: tmp = x + y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -265000.0) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 3900.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 <= -265000.0) tmp = x * (y + 1.0); elseif (x <= 3900.0) tmp = x + y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -265000.0], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3900.0], N[(x + y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -265000:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 3900:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -265000Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0%
Simplified100.0%
if -265000 < x < 3900Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified97.4%
if 3900 < x Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6497.5%
Simplified97.5%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6457.1%
Simplified57.1%
Final simplification88.5%
(FPCore (x y) :precision binary64 (if (<= x -2e+204) (* x y) (if (<= x 3900.0) (+ x y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -2e+204) {
tmp = x * y;
} else if (x <= 3900.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 <= (-2d+204)) then
tmp = x * y
else if (x <= 3900.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 <= -2e+204) {
tmp = x * y;
} else if (x <= 3900.0) {
tmp = x + y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2e+204: tmp = x * y elif x <= 3900.0: tmp = x + y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -2e+204) tmp = Float64(x * y); elseif (x <= 3900.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 <= -2e+204) tmp = x * y; elseif (x <= 3900.0) tmp = x + y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2e+204], N[(x * y), $MachinePrecision], If[LessEqual[x, 3900.0], N[(x + y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+204}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3900:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.99999999999999998e204 or 3900 < x Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6498.2%
Simplified98.2%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6459.2%
Simplified59.2%
if -1.99999999999999998e204 < x < 3900Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified86.8%
Final simplification77.8%
(FPCore (x y) :precision binary64 (if (<= y 7.1e-93) x y))
double code(double x, double y) {
double tmp;
if (y <= 7.1e-93) {
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 <= 7.1d-93) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 7.1e-93) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 7.1e-93: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 7.1e-93) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 7.1e-93) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 7.1e-93], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.1 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 7.1e-93Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
Simplified47.4%
if 7.1e-93 < y Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified48.1%
(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%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
Simplified36.5%
herbie shell --seed 2024164
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))