
(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}
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%
Simplified0
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -1.15e+290)
x
(if (<= x -2.8e+249)
(* y x)
(if (<= x -1.85e-45) x (if (<= x 1.0) y (* y x))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.15e+290) {
tmp = x;
} else if (x <= -2.8e+249) {
tmp = y * x;
} else if (x <= -1.85e-45) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
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 <= (-1.15d+290)) then
tmp = x
else if (x <= (-2.8d+249)) then
tmp = y * x
else if (x <= (-1.85d-45)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -1.15e+290) {
tmp = x;
} else if (x <= -2.8e+249) {
tmp = y * x;
} else if (x <= -1.85e-45) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -1.15e+290: tmp = x elif x <= -2.8e+249: tmp = y * x elif x <= -1.85e-45: tmp = x elif x <= 1.0: tmp = y else: tmp = y * x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.15e+290) tmp = x; elseif (x <= -2.8e+249) tmp = Float64(y * x); elseif (x <= -1.85e-45) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(y * x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -1.15e+290)
tmp = x;
elseif (x <= -2.8e+249)
tmp = y * x;
elseif (x <= -1.85e-45)
tmp = x;
elseif (x <= 1.0)
tmp = y;
else
tmp = y * x;
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, -1.15e+290], x, If[LessEqual[x, -2.8e+249], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.85e-45], x, If[LessEqual[x, 1.0], y, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+290}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.8 \cdot 10^{+249}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.85 \cdot 10^{-45}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.15000000000000003e290 or -2.80000000000000018e249 < x < -1.85e-45Initial program 100.0%
Simplified0
Taylor expanded in y around 0 0
Simplified0
if -1.15000000000000003e290 < x < -2.80000000000000018e249 or 1 < x Initial program 100.0%
Simplified0
Taylor expanded in y around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -1.85e-45 < x < 1Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -1.15e+290) x (if (<= x -1.16e+223) (* y x) (if (<= x 1800000.0) (+ x y) (* y x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.15e+290) {
tmp = x;
} else if (x <= -1.16e+223) {
tmp = y * x;
} else if (x <= 1800000.0) {
tmp = x + y;
} else {
tmp = y * x;
}
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 <= (-1.15d+290)) then
tmp = x
else if (x <= (-1.16d+223)) then
tmp = y * x
else if (x <= 1800000.0d0) then
tmp = x + y
else
tmp = y * x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -1.15e+290) {
tmp = x;
} else if (x <= -1.16e+223) {
tmp = y * x;
} else if (x <= 1800000.0) {
tmp = x + y;
} else {
tmp = y * x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -1.15e+290: tmp = x elif x <= -1.16e+223: tmp = y * x elif x <= 1800000.0: tmp = x + y else: tmp = y * x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.15e+290) tmp = x; elseif (x <= -1.16e+223) tmp = Float64(y * x); elseif (x <= 1800000.0) tmp = Float64(x + y); else tmp = Float64(y * x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -1.15e+290)
tmp = x;
elseif (x <= -1.16e+223)
tmp = y * x;
elseif (x <= 1800000.0)
tmp = x + y;
else
tmp = y * x;
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, -1.15e+290], x, If[LessEqual[x, -1.16e+223], N[(y * x), $MachinePrecision], If[LessEqual[x, 1800000.0], N[(x + y), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+290}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -1.16 \cdot 10^{+223}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1800000:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.15000000000000003e290Initial program 100.0%
Simplified0
Taylor expanded in y around 0 0
Simplified0
if -1.15000000000000003e290 < x < -1.15999999999999993e223 or 1.8e6 < x Initial program 100.0%
Simplified0
Taylor expanded in y around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -1.15999999999999993e223 < x < 1.8e6Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -340.0) (* y x) (if (<= y 1.0) (+ x y) (* y (+ 1.0 x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -340.0) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = x + y;
} else {
tmp = y * (1.0 + x);
}
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 <= (-340.0d0)) then
tmp = y * x
else if (y <= 1.0d0) then
tmp = x + y
else
tmp = y * (1.0d0 + x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -340.0) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = x + y;
} else {
tmp = y * (1.0 + x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -340.0: tmp = y * x elif y <= 1.0: tmp = x + y else: tmp = y * (1.0 + x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -340.0) tmp = Float64(y * x); elseif (y <= 1.0) tmp = Float64(x + y); else tmp = Float64(y * Float64(1.0 + x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -340.0)
tmp = y * x;
elseif (y <= 1.0)
tmp = x + y;
else
tmp = y * (1.0 + x);
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, -340.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.0], N[(x + y), $MachinePrecision], N[(y * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -340:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + x\right)\\
\end{array}
\end{array}
if y < -340Initial program 100.0%
Simplified0
Taylor expanded in y around inf 0
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -340 < y < 1Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
if 1 < y Initial program 100.0%
Simplified0
Taylor expanded in y around inf 0
Simplified0
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -2.2e-45) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.2e-45) {
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 <= (-2.2d-45)) 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 <= -2.2e-45) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.2e-45: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.2e-45) 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 <= -2.2e-45)
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, -2.2e-45], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{-45}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.19999999999999993e-45Initial program 100.0%
Simplified0
Taylor expanded in y around 0 0
Simplified0
if -2.19999999999999993e-45 < x Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
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%
Simplified0
Taylor expanded in y around 0 0
Simplified0
herbie shell --seed 2024110
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))