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

Percentage Accurate: 100.0% → 100.0%
Time: 7.1s
Alternatives: 7
Speedup: 1.2×

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 7 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, 1.2× speedup?

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

    \[\left(x \cdot y + x\right) + y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(x \cdot y + x\right) + y} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{y + \left(x \cdot y + x\right)} \]
    3. lift-+.f64N/A

      \[\leadsto y + \color{blue}{\left(x \cdot y + x\right)} \]
    4. associate-+r+N/A

      \[\leadsto \color{blue}{\left(y + x \cdot y\right) + x} \]
    5. lift-*.f64N/A

      \[\leadsto \left(y + \color{blue}{x \cdot y}\right) + x \]
    6. distribute-rgt1-inN/A

      \[\leadsto \color{blue}{\left(x + 1\right) \cdot y} + x \]
    7. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(x + 1, y, x\right)} \]
    8. lower-+.f64100.0

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

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

    \[\leadsto \mathsf{fma}\left(1 + x, y, x\right) \]
  6. Add Preprocessing

Alternative 2: 96.7% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(y \cdot x + x\right) + y \leq -5 \cdot 10^{-184}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\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 (<= (+ (+ (* y x) x) y) -5e-184) (fma y x x) (fma y x y)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if ((((y * x) + x) + y) <= -5e-184) {
		tmp = fma(y, x, x);
	} else {
		tmp = fma(y, x, y);
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(Float64(y * x) + x) + y) <= -5e-184)
		tmp = fma(y, x, x);
	else
		tmp = fma(y, x, y);
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[N[(N[(N[(y * x), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -5e-184], N[(y * x + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(y \cdot x + x\right) + y \leq -5 \cdot 10^{-184}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -5.00000000000000003e-184

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto y \cdot x + \color{blue}{y} \]
      4. lower-fma.f6464.9

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
    5. Applied rewrites64.9%

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

      \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
      2. distribute-rgt-inN/A

        \[\leadsto \color{blue}{y \cdot x + 1 \cdot x} \]
      3. *-lft-identityN/A

        \[\leadsto y \cdot x + \color{blue}{x} \]
      4. lower-fma.f6458.9

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
    8. Applied rewrites58.9%

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

    if -5.00000000000000003e-184 < (+.f64 (+.f64 (*.f64 x y) x) y)

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto y \cdot x + \color{blue}{y} \]
      4. lower-fma.f6464.2

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
    5. Applied rewrites64.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot x + x\right) + y \leq -5 \cdot 10^{-184}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.3% accurate, 0.6× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -2.65 \cdot 10^{-9}:\\ \;\;\;\;\left(y + 1\right) \cdot x\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\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 (<= y -2.65e-9)
   (* (+ y 1.0) x)
   (if (<= y 1.3e-7) (fma 1.0 y x) (fma y x y))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= -2.65e-9) {
		tmp = (y + 1.0) * x;
	} else if (y <= 1.3e-7) {
		tmp = fma(1.0, y, x);
	} else {
		tmp = fma(y, x, y);
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (y <= -2.65e-9)
		tmp = Float64(Float64(y + 1.0) * x);
	elseif (y <= 1.3e-7)
		tmp = fma(1.0, y, x);
	else
		tmp = fma(y, x, y);
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[y, -2.65e-9], N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 1.3e-7], N[(1.0 * y + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{-9}:\\
\;\;\;\;\left(y + 1\right) \cdot x\\

\mathbf{elif}\;y \leq 1.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.65000000000000015e-9

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto y \cdot x + \color{blue}{y} \]
      4. lower-fma.f6495.7

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
    5. Applied rewrites95.7%

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

      \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
      2. distribute-rgt-inN/A

        \[\leadsto \color{blue}{y \cdot x + 1 \cdot x} \]
      3. *-lft-identityN/A

        \[\leadsto y \cdot x + \color{blue}{x} \]
      4. lower-fma.f6444.2

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
    8. Applied rewrites44.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
    9. Step-by-step derivation
      1. Applied rewrites44.2%

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

      if -2.65000000000000015e-9 < y < 1.29999999999999999e-7

      1. Initial program 100.0%

        \[\left(x \cdot y + x\right) + y \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \color{blue}{\left(x \cdot y + x\right) + y} \]
        2. +-commutativeN/A

          \[\leadsto \color{blue}{y + \left(x \cdot y + x\right)} \]
        3. lift-+.f64N/A

          \[\leadsto y + \color{blue}{\left(x \cdot y + x\right)} \]
        4. associate-+r+N/A

          \[\leadsto \color{blue}{\left(y + x \cdot y\right) + x} \]
        5. lift-*.f64N/A

          \[\leadsto \left(y + \color{blue}{x \cdot y}\right) + x \]
        6. distribute-rgt1-inN/A

          \[\leadsto \color{blue}{\left(x + 1\right) \cdot y} + x \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(x + 1, y, x\right)} \]
        8. lower-+.f64100.0

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{1}, y, x\right) \]
      6. Step-by-step derivation
        1. Applied rewrites100.0%

          \[\leadsto \mathsf{fma}\left(\color{blue}{1}, y, x\right) \]

        if 1.29999999999999999e-7 < y

        1. Initial program 100.0%

          \[\left(x \cdot y + x\right) + y \]
        2. Add Preprocessing
        3. Taylor expanded in y around inf

          \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
        4. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
          2. distribute-lft-inN/A

            \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
          3. *-rgt-identityN/A

            \[\leadsto y \cdot x + \color{blue}{y} \]
          4. lower-fma.f6499.6

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
        5. Applied rewrites99.6%

          \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
      7. Recombined 3 regimes into one program.
      8. Final simplification84.6%

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.65 \cdot 10^{-9}:\\ \;\;\;\;\left(y + 1\right) \cdot x\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\right)\\ \end{array} \]
      9. Add Preprocessing

      Alternative 4: 99.3% accurate, 0.6× speedup?

      \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -2.65 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\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 (<= y -2.65e-9) (fma y x x) (if (<= y 1.3e-7) (fma 1.0 y x) (fma y x y))))
      assert(x < y);
      double code(double x, double y) {
      	double tmp;
      	if (y <= -2.65e-9) {
      		tmp = fma(y, x, x);
      	} else if (y <= 1.3e-7) {
      		tmp = fma(1.0, y, x);
      	} else {
      		tmp = fma(y, x, y);
      	}
      	return tmp;
      }
      
      x, y = sort([x, y])
      function code(x, y)
      	tmp = 0.0
      	if (y <= -2.65e-9)
      		tmp = fma(y, x, x);
      	elseif (y <= 1.3e-7)
      		tmp = fma(1.0, y, x);
      	else
      		tmp = fma(y, x, y);
      	end
      	return tmp
      end
      
      NOTE: x and y should be sorted in increasing order before calling this function.
      code[x_, y_] := If[LessEqual[y, -2.65e-9], N[(y * x + x), $MachinePrecision], If[LessEqual[y, 1.3e-7], N[(1.0 * y + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
      
      \begin{array}{l}
      [x, y] = \mathsf{sort}([x, y])\\
      \\
      \begin{array}{l}
      \mathbf{if}\;y \leq -2.65 \cdot 10^{-9}:\\
      \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
      
      \mathbf{elif}\;y \leq 1.3 \cdot 10^{-7}:\\
      \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if y < -2.65000000000000015e-9

        1. Initial program 100.0%

          \[\left(x \cdot y + x\right) + y \]
        2. Add Preprocessing
        3. Taylor expanded in y around inf

          \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
        4. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
          2. distribute-lft-inN/A

            \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
          3. *-rgt-identityN/A

            \[\leadsto y \cdot x + \color{blue}{y} \]
          4. lower-fma.f6495.7

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
        5. Applied rewrites95.7%

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

          \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
        7. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
          2. distribute-rgt-inN/A

            \[\leadsto \color{blue}{y \cdot x + 1 \cdot x} \]
          3. *-lft-identityN/A

            \[\leadsto y \cdot x + \color{blue}{x} \]
          4. lower-fma.f6444.2

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
        8. Applied rewrites44.2%

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

        if -2.65000000000000015e-9 < y < 1.29999999999999999e-7

        1. Initial program 100.0%

          \[\left(x \cdot y + x\right) + y \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{\left(x \cdot y + x\right) + y} \]
          2. +-commutativeN/A

            \[\leadsto \color{blue}{y + \left(x \cdot y + x\right)} \]
          3. lift-+.f64N/A

            \[\leadsto y + \color{blue}{\left(x \cdot y + x\right)} \]
          4. associate-+r+N/A

            \[\leadsto \color{blue}{\left(y + x \cdot y\right) + x} \]
          5. lift-*.f64N/A

            \[\leadsto \left(y + \color{blue}{x \cdot y}\right) + x \]
          6. distribute-rgt1-inN/A

            \[\leadsto \color{blue}{\left(x + 1\right) \cdot y} + x \]
          7. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(x + 1, y, x\right)} \]
          8. lower-+.f64100.0

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{1}, y, x\right) \]
        6. Step-by-step derivation
          1. Applied rewrites100.0%

            \[\leadsto \mathsf{fma}\left(\color{blue}{1}, y, x\right) \]

          if 1.29999999999999999e-7 < y

          1. Initial program 100.0%

            \[\left(x \cdot y + x\right) + y \]
          2. Add Preprocessing
          3. Taylor expanded in y around inf

            \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
            2. distribute-lft-inN/A

              \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
            3. *-rgt-identityN/A

              \[\leadsto y \cdot x + \color{blue}{y} \]
            4. lower-fma.f6499.6

              \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
          5. Applied rewrites99.6%

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
        7. Recombined 3 regimes into one program.
        8. Add Preprocessing

        Alternative 5: 62.3% accurate, 0.7× speedup?

        \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 \cdot x\\ \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 (<= y -1.0) (* y x) (if (<= y 1.0) (* 1.0 x) (* y x))))
        assert(x < y);
        double code(double x, double y) {
        	double tmp;
        	if (y <= -1.0) {
        		tmp = y * x;
        	} else if (y <= 1.0) {
        		tmp = 1.0 * x;
        	} 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 (y <= (-1.0d0)) then
                tmp = y * x
            else if (y <= 1.0d0) then
                tmp = 1.0d0 * x
            else
                tmp = y * x
            end if
            code = tmp
        end function
        
        assert x < y;
        public static double code(double x, double y) {
        	double tmp;
        	if (y <= -1.0) {
        		tmp = y * x;
        	} else if (y <= 1.0) {
        		tmp = 1.0 * x;
        	} else {
        		tmp = y * x;
        	}
        	return tmp;
        }
        
        [x, y] = sort([x, y])
        def code(x, y):
        	tmp = 0
        	if y <= -1.0:
        		tmp = y * x
        	elif y <= 1.0:
        		tmp = 1.0 * x
        	else:
        		tmp = y * x
        	return tmp
        
        x, y = sort([x, y])
        function code(x, y)
        	tmp = 0.0
        	if (y <= -1.0)
        		tmp = Float64(y * x);
        	elseif (y <= 1.0)
        		tmp = Float64(1.0 * x);
        	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 (y <= -1.0)
        		tmp = y * x;
        	elseif (y <= 1.0)
        		tmp = 1.0 * x;
        	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[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.0], N[(1.0 * x), $MachinePrecision], N[(y * x), $MachinePrecision]]]
        
        \begin{array}{l}
        [x, y] = \mathsf{sort}([x, y])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -1:\\
        \;\;\;\;y \cdot x\\
        
        \mathbf{elif}\;y \leq 1:\\
        \;\;\;\;1 \cdot x\\
        
        \mathbf{else}:\\
        \;\;\;\;y \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -1 or 1 < y

          1. Initial program 100.0%

            \[\left(x \cdot y + x\right) + y \]
          2. Add Preprocessing
          3. Taylor expanded in y around inf

            \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
            2. distribute-lft-inN/A

              \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
            3. *-rgt-identityN/A

              \[\leadsto y \cdot x + \color{blue}{y} \]
            4. lower-fma.f6498.3

              \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
          5. Applied rewrites98.3%

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

            \[\leadsto x \cdot \color{blue}{y} \]
          7. Step-by-step derivation
            1. Applied rewrites42.6%

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

            if -1 < y < 1

            1. Initial program 100.0%

              \[\left(x \cdot y + x\right) + y \]
            2. Add Preprocessing
            3. Taylor expanded in y around inf

              \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
            4. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
              2. distribute-lft-inN/A

                \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
              3. *-rgt-identityN/A

                \[\leadsto y \cdot x + \color{blue}{y} \]
              4. lower-fma.f6428.6

                \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
            5. Applied rewrites28.6%

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

              \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
            7. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
              2. distribute-rgt-inN/A

                \[\leadsto \color{blue}{y \cdot x + 1 \cdot x} \]
              3. *-lft-identityN/A

                \[\leadsto y \cdot x + \color{blue}{x} \]
              4. lower-fma.f6473.1

                \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
            8. Applied rewrites73.1%

              \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
            9. Step-by-step derivation
              1. Applied rewrites73.1%

                \[\leadsto \left(1 + y\right) \cdot \color{blue}{x} \]
              2. Taylor expanded in y around 0

                \[\leadsto 1 \cdot x \]
              3. Step-by-step derivation
                1. Applied rewrites72.7%

                  \[\leadsto 1 \cdot x \]
              4. Recombined 2 regimes into one program.
              5. Add Preprocessing

              Alternative 6: 63.4% accurate, 1.7× speedup?

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

                \[\left(x \cdot y + x\right) + y \]
              2. Add Preprocessing
              3. Taylor expanded in y around inf

                \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
              4. Step-by-step derivation
                1. +-commutativeN/A

                  \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
                2. distribute-lft-inN/A

                  \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
                3. *-rgt-identityN/A

                  \[\leadsto y \cdot x + \color{blue}{y} \]
                4. lower-fma.f6464.5

                  \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
              5. Applied rewrites64.5%

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

                \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
              7. Step-by-step derivation
                1. +-commutativeN/A

                  \[\leadsto x \cdot \color{blue}{\left(y + 1\right)} \]
                2. distribute-rgt-inN/A

                  \[\leadsto \color{blue}{y \cdot x + 1 \cdot x} \]
                3. *-lft-identityN/A

                  \[\leadsto y \cdot x + \color{blue}{x} \]
                4. lower-fma.f6458.0

                  \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
              8. Applied rewrites58.0%

                \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
              9. Add Preprocessing

              Alternative 7: 27.0% accurate, 2.0× speedup?

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

                \[\left(x \cdot y + x\right) + y \]
              2. Add Preprocessing
              3. Taylor expanded in y around inf

                \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
              4. Step-by-step derivation
                1. +-commutativeN/A

                  \[\leadsto y \cdot \color{blue}{\left(x + 1\right)} \]
                2. distribute-lft-inN/A

                  \[\leadsto \color{blue}{y \cdot x + y \cdot 1} \]
                3. *-rgt-identityN/A

                  \[\leadsto y \cdot x + \color{blue}{y} \]
                4. lower-fma.f6464.5

                  \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y\right)} \]
              5. Applied rewrites64.5%

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

                \[\leadsto x \cdot \color{blue}{y} \]
              7. Step-by-step derivation
                1. Applied rewrites23.7%

                  \[\leadsto y \cdot \color{blue}{x} \]
                2. Add Preprocessing

                Reproduce

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