Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B

Percentage Accurate: 100.0% → 100.0%
Time: 2.1s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot y + x\right) + y \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot y + x\right) + y \end{array} \]
(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}

Alternative 1: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ y + \mathsf{fma}\left(x, y, x\right) \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (+ y (fma x y x)))
assert(x < y);
double code(double x, double y) {
	return y + fma(x, y, x);
}
x, y = sort([x, y])
function code(x, y)
	return Float64(y + fma(x, y, x))
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(y + N[(x * y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + \mathsf{fma}\left(x, y, x\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot y + x\right) + y \]
  2. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto \color{blue}{y + \left(x \cdot y + x\right)} \]
    2. fma-def100.0%

      \[\leadsto y + \color{blue}{\mathsf{fma}\left(x, y, x\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{y + \mathsf{fma}\left(x, y, x\right)} \]
  4. Final simplification100.0%

    \[\leadsto y + \mathsf{fma}\left(x, y, x\right) \]

Alternative 2: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ x + \mathsf{fma}\left(x, y, y\right) \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (+ x (fma x y y)))
assert(x < y);
double code(double x, double y) {
	return x + fma(x, y, y);
}
x, y = sort([x, y])
function code(x, y)
	return Float64(x + fma(x, y, y))
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(x + N[(x * y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + \mathsf{fma}\left(x, y, y\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot y + x\right) + y \]
  2. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
    2. associate-+l+100.0%

      \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
    3. fma-def100.0%

      \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
  4. Final simplification100.0%

    \[\leadsto x + \mathsf{fma}\left(x, y, y\right) \]

Alternative 3: 87.4% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} t_0 := y \cdot \left(x + 1\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-182}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-114}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* y (+ x 1.0))))
   (if (<= y -1.0)
     (* y x)
     (if (<= y 2.05e-182)
       x
       (if (<= y 3.8e-166)
         t_0
         (if (<= y 3e-130)
           x
           (if (<= y 6.6e-114) y (if (<= y 7.6e-52) x t_0))))))))
assert(x < y);
double code(double x, double y) {
	double t_0 = y * (x + 1.0);
	double tmp;
	if (y <= -1.0) {
		tmp = y * x;
	} else if (y <= 2.05e-182) {
		tmp = x;
	} else if (y <= 3.8e-166) {
		tmp = t_0;
	} else if (y <= 3e-130) {
		tmp = x;
	} else if (y <= 6.6e-114) {
		tmp = y;
	} else if (y <= 7.6e-52) {
		tmp = x;
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = y * (x + 1.0d0)
    if (y <= (-1.0d0)) then
        tmp = y * x
    else if (y <= 2.05d-182) then
        tmp = x
    else if (y <= 3.8d-166) then
        tmp = t_0
    else if (y <= 3d-130) then
        tmp = x
    else if (y <= 6.6d-114) then
        tmp = y
    else if (y <= 7.6d-52) then
        tmp = x
    else
        tmp = t_0
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y) {
	double t_0 = y * (x + 1.0);
	double tmp;
	if (y <= -1.0) {
		tmp = y * x;
	} else if (y <= 2.05e-182) {
		tmp = x;
	} else if (y <= 3.8e-166) {
		tmp = t_0;
	} else if (y <= 3e-130) {
		tmp = x;
	} else if (y <= 6.6e-114) {
		tmp = y;
	} else if (y <= 7.6e-52) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	t_0 = y * (x + 1.0)
	tmp = 0
	if y <= -1.0:
		tmp = y * x
	elif y <= 2.05e-182:
		tmp = x
	elif y <= 3.8e-166:
		tmp = t_0
	elif y <= 3e-130:
		tmp = x
	elif y <= 6.6e-114:
		tmp = y
	elif y <= 7.6e-52:
		tmp = x
	else:
		tmp = t_0
	return tmp
x, y = sort([x, y])
function code(x, y)
	t_0 = Float64(y * Float64(x + 1.0))
	tmp = 0.0
	if (y <= -1.0)
		tmp = Float64(y * x);
	elseif (y <= 2.05e-182)
		tmp = x;
	elseif (y <= 3.8e-166)
		tmp = t_0;
	elseif (y <= 3e-130)
		tmp = x;
	elseif (y <= 6.6e-114)
		tmp = y;
	elseif (y <= 7.6e-52)
		tmp = x;
	else
		tmp = t_0;
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
	t_0 = y * (x + 1.0);
	tmp = 0.0;
	if (y <= -1.0)
		tmp = y * x;
	elseif (y <= 2.05e-182)
		tmp = x;
	elseif (y <= 3.8e-166)
		tmp = t_0;
	elseif (y <= 3e-130)
		tmp = x;
	elseif (y <= 6.6e-114)
		tmp = y;
	elseif (y <= 7.6e-52)
		tmp = x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.05e-182], x, If[LessEqual[y, 3.8e-166], t$95$0, If[LessEqual[y, 3e-130], x, If[LessEqual[y, 6.6e-114], y, If[LessEqual[y, 7.6e-52], x, t$95$0]]]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(x + 1\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 2.05 \cdot 10^{-182}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 3.8 \cdot 10^{-166}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 3 \cdot 10^{-130}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 6.6 \cdot 10^{-114}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 7.6 \cdot 10^{-52}:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -1

    1. Initial program 99.9%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+99.9%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in y around inf 98.9%

      \[\leadsto \color{blue}{\left(1 + x\right) \cdot y} \]
    5. Taylor expanded in x around inf 54.8%

      \[\leadsto \color{blue}{y \cdot x} \]

    if -1 < y < 2.0500000000000001e-182 or 3.79999999999999982e-166 < y < 2.99999999999999986e-130 or 6.60000000000000069e-114 < y < 7.6000000000000007e-52

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+100.0%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in y around 0 83.4%

      \[\leadsto \color{blue}{x} \]

    if 2.0500000000000001e-182 < y < 3.79999999999999982e-166 or 7.6000000000000007e-52 < y

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+100.0%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in y around inf 91.8%

      \[\leadsto \color{blue}{\left(1 + x\right) \cdot y} \]

    if 2.99999999999999986e-130 < y < 6.60000000000000069e-114

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+100.0%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in x around 0 68.5%

      \[\leadsto \color{blue}{y} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification78.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-182}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-166}:\\ \;\;\;\;y \cdot \left(x + 1\right)\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-114}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + 1\right)\\ \end{array} \]

Alternative 4: 69.5% accurate, 0.6× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{+78}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{+62}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -1.22 \cdot 10^{-46}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= x -7.2e+78)
   x
   (if (<= x -2.15e+62)
     (* y x)
     (if (<= x -1.22e-46) x (if (<= x 1.0) y (* y x))))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (x <= -7.2e+78) {
		tmp = x;
	} else if (x <= -2.15e+62) {
		tmp = y * x;
	} else if (x <= -1.22e-46) {
		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 <= (-7.2d+78)) then
        tmp = x
    else if (x <= (-2.15d+62)) then
        tmp = y * x
    else if (x <= (-1.22d-46)) 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 <= -7.2e+78) {
		tmp = x;
	} else if (x <= -2.15e+62) {
		tmp = y * x;
	} else if (x <= -1.22e-46) {
		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 <= -7.2e+78:
		tmp = x
	elif x <= -2.15e+62:
		tmp = y * x
	elif x <= -1.22e-46:
		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 <= -7.2e+78)
		tmp = x;
	elseif (x <= -2.15e+62)
		tmp = Float64(y * x);
	elseif (x <= -1.22e-46)
		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 <= -7.2e+78)
		tmp = x;
	elseif (x <= -2.15e+62)
		tmp = y * x;
	elseif (x <= -1.22e-46)
		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, -7.2e+78], x, If[LessEqual[x, -2.15e+62], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.22e-46], 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 -7.2 \cdot 10^{+78}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq -2.15 \cdot 10^{+62}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;x \leq -1.22 \cdot 10^{-46}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\

\mathbf{else}:\\
\;\;\;\;y \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -7.20000000000000039e78 or -2.1499999999999998e62 < x < -1.22e-46

    1. Initial program 99.9%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+99.9%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in y around 0 52.9%

      \[\leadsto \color{blue}{x} \]

    if -7.20000000000000039e78 < x < -2.1499999999999998e62 or 1 < x

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+100.0%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in y around inf 61.8%

      \[\leadsto \color{blue}{\left(1 + x\right) \cdot y} \]
    5. Taylor expanded in x around inf 61.0%

      \[\leadsto \color{blue}{y \cdot x} \]

    if -1.22e-46 < x < 1

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+100.0%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in x around 0 73.4%

      \[\leadsto \color{blue}{y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification64.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{+78}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{+62}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -1.22 \cdot 10^{-46}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]

Alternative 5: 88.2% accurate, 1.0× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-47}:\\ \;\;\;\;x \cdot \left(y + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + 1\right)\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= x -4.6e-47) (* x (+ y 1.0)) (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (x <= -4.6e-47) {
		tmp = x * (y + 1.0);
	} 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 (x <= (-4.6d-47)) then
        tmp = x * (y + 1.0d0)
    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 (x <= -4.6e-47) {
		tmp = x * (y + 1.0);
	} else {
		tmp = y * (x + 1.0);
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if x <= -4.6e-47:
		tmp = x * (y + 1.0)
	else:
		tmp = y * (x + 1.0)
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (x <= -4.6e-47)
		tmp = Float64(x * Float64(y + 1.0));
	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 (x <= -4.6e-47)
		tmp = x * (y + 1.0);
	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[x, -4.6e-47], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-47}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.59999999999999964e-47

    1. Initial program 99.9%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+99.9%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in x around inf 94.3%

      \[\leadsto \color{blue}{\left(1 + y\right) \cdot x} \]

    if -4.59999999999999964e-47 < x

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+100.0%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in y around inf 69.2%

      \[\leadsto \color{blue}{\left(1 + x\right) \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-47}:\\ \;\;\;\;x \cdot \left(y + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + 1\right)\\ \end{array} \]

Alternative 6: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ y + \left(x + y \cdot x\right) \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (+ y (+ x (* y x))))
assert(x < y);
double code(double x, double y) {
	return y + (x + (y * 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 = y + (x + (y * x))
end function
assert x < y;
public static double code(double x, double y) {
	return y + (x + (y * x));
}
[x, y] = sort([x, y])
def code(x, y):
	return y + (x + (y * x))
x, y = sort([x, y])
function code(x, y)
	return Float64(y + Float64(x + Float64(y * x)))
end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
	tmp = y + (x + (y * x));
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(y + N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + \left(x + y \cdot x\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot y + x\right) + y \]
  2. Final simplification100.0%

    \[\leadsto y + \left(x + y \cdot x\right) \]

Alternative 7: 64.3% accurate, 2.3× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1.12 \cdot 10^{-45}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (if (<= x -1.12e-45) x y))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (x <= -1.12e-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 <= (-1.12d-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 <= -1.12e-45) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if x <= -1.12e-45:
		tmp = x
	else:
		tmp = y
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (x <= -1.12e-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 <= -1.12e-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, -1.12e-45], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{-45}:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.1199999999999999e-45

    1. Initial program 99.9%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+99.9%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in y around 0 50.3%

      \[\leadsto \color{blue}{x} \]

    if -1.1199999999999999e-45 < x

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
      2. associate-+l+100.0%

        \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
      3. fma-def100.0%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
    4. Taylor expanded in x around 0 49.9%

      \[\leadsto \color{blue}{y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.12 \cdot 10^{-45}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternative 8: 38.7% accurate, 7.0× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ x \end{array} \]
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}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot y + x\right) + y \]
  2. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto \color{blue}{\left(x + x \cdot y\right)} + y \]
    2. associate-+l+100.0%

      \[\leadsto \color{blue}{x + \left(x \cdot y + y\right)} \]
    3. fma-def100.0%

      \[\leadsto x + \color{blue}{\mathsf{fma}\left(x, y, y\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{x + \mathsf{fma}\left(x, y, y\right)} \]
  4. Taylor expanded in y around 0 37.2%

    \[\leadsto \color{blue}{x} \]
  5. Final simplification37.2%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023181 
(FPCore (x y)
  :name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
  :precision binary64
  (+ (+ (* x y) x) y))