
(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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ x (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
return x + (y * (x + 1.0));
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (y * (x + 1.0d0))
end function
assert x < y;
public static double code(double x, double y) {
return x + (y * (x + 1.0));
}
[x, y] = sort([x, y]) def code(x, y): return x + (y * (x + 1.0))
x, y = sort([x, y]) function code(x, y) return Float64(x + Float64(y * Float64(x + 1.0))) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x + (y * (x + 1.0));
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x + N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
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%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -1.62e-9) (+ x (* x y)) (if (<= y 1.3e-8) (+ x y) (* y (+ x 1.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1.62e-9) {
tmp = x + (x * y);
} else if (y <= 1.3e-8) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.62d-9)) then
tmp = x + (x * y)
else if (y <= 1.3d-8) then
tmp = x + y
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -1.62e-9) {
tmp = x + (x * y);
} else if (y <= 1.3e-8) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -1.62e-9: tmp = x + (x * y) elif y <= 1.3e-8: tmp = x + y else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -1.62e-9) tmp = Float64(x + Float64(x * y)); elseif (y <= 1.3e-8) tmp = Float64(x + y); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -1.62e-9)
tmp = x + (x * y);
elseif (y <= 1.3e-8)
tmp = x + y;
else
tmp = y * (x + 1.0);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, -1.62e-9], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.3e-8], N[(x + y), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.62 \cdot 10^{-9}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -1.61999999999999999e-9Initial 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
*-commutativeN/A
*-lowering-*.f6450.2%
Simplified50.2%
if -1.61999999999999999e-9 < y < 1.3000000000000001e-8Initial 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
Simplified99.8%
if 1.3000000000000001e-8 < y 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-+.f6498.0%
Simplified98.0%
Final simplification86.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -1.08e+18) (* x y) (if (<= y 1.3e-8) (+ x y) (* y (+ x 1.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1.08e+18) {
tmp = x * y;
} else if (y <= 1.3e-8) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.08d+18)) then
tmp = x * y
else if (y <= 1.3d-8) then
tmp = x + y
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -1.08e+18) {
tmp = x * y;
} else if (y <= 1.3e-8) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -1.08e+18: tmp = x * y elif y <= 1.3e-8: tmp = x + y else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -1.08e+18) tmp = Float64(x * y); elseif (y <= 1.3e-8) tmp = Float64(x + y); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -1.08e+18)
tmp = x * y;
elseif (y <= 1.3e-8)
tmp = x + y;
else
tmp = y * (x + 1.0);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, -1.08e+18], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.3e-8], N[(x + y), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.08 \cdot 10^{+18}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -1.08e18Initial 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-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6451.7%
Simplified51.7%
if -1.08e18 < y < 1.3000000000000001e-8Initial 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
Simplified98.3%
if 1.3000000000000001e-8 < y 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-+.f6498.0%
Simplified98.0%
Final simplification86.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -8e-95) x (if (<= x 1.0) y (* x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -8e-95) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-8d-95)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -8e-95) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -8e-95: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -8e-95) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -8e-95)
tmp = x;
elseif (x <= 1.0)
tmp = y;
else
tmp = x * y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -8e-95], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-95}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -7.99999999999999992e-95Initial 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
Simplified51.6%
if -7.99999999999999992e-95 < x < 1Initial 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
Simplified82.3%
if 1 < 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-+.f6452.8%
Simplified52.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6451.6%
Simplified51.6%
Final simplification64.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x 155.0) (+ x y) (* x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= 155.0) {
tmp = x + y;
} else {
tmp = x * y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 155.0d0) then
tmp = x + y
else
tmp = x * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= 155.0) {
tmp = x + y;
} else {
tmp = x * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= 155.0: tmp = x + y else: tmp = x * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= 155.0) tmp = Float64(x + y); else tmp = Float64(x * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= 155.0)
tmp = x + y;
else
tmp = x * y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, 155.0], N[(x + y), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 155:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < 155Initial 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.0%
if 155 < 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-+.f6452.8%
Simplified52.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6451.6%
Simplified51.6%
Final simplification77.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -8e-95) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -8e-95) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-8d-95)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -8e-95) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -8e-95: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -8e-95) tmp = x; else tmp = y; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -8e-95)
tmp = x;
else
tmp = y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -8e-95], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-95}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -7.99999999999999992e-95Initial 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
Simplified51.6%
if -7.99999999999999992e-95 < 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 0
Simplified53.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 x)
assert(x < y);
double code(double x, double y) {
return x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
assert x < y;
public static double code(double x, double y) {
return x;
}
[x, y] = sort([x, y]) def code(x, y): return x
x, y = sort([x, y]) function code(x, y) return x end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := x
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
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
Simplified37.3%
herbie shell --seed 2024158
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))