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

Percentage Accurate: 100.0% → 100.0%
Time: 4.6s
Alternatives: 6
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 6 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.0× speedup?

\[\begin{array}{l} \\ y + \left(x + x \cdot y\right) \end{array} \]
(FPCore (x y) :precision binary64 (+ y (+ x (* x y))))
double code(double x, double y) {
	return y + (x + (x * y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = y + (x + (x * y))
end function
public static double code(double x, double y) {
	return y + (x + (x * y));
}
def code(x, y):
	return y + (x + (x * y))
function code(x, y)
	return Float64(y + Float64(x + Float64(x * y)))
end
function tmp = code(x, y)
	tmp = y + (x + (x * y));
end
code[x_, y_] := N[(y + N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
y + \left(x + x \cdot y\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

    \[\leadsto y + \left(x + x \cdot y\right) \]
  4. Add Preprocessing

Alternative 2: 60.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+273}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{+179}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1 \cdot 10^{+130}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+103}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.18 \cdot 10^{-110}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -2.2e+273)
   x
   (if (<= x -1.2e+179)
     (* x y)
     (if (<= x -1e+130)
       x
       (if (<= x -2.1e+103)
         (* x y)
         (if (<= x -1.18e-110) x (if (<= x 1.0) y (* x y))))))))
double code(double x, double y) {
	double tmp;
	if (x <= -2.2e+273) {
		tmp = x;
	} else if (x <= -1.2e+179) {
		tmp = x * y;
	} else if (x <= -1e+130) {
		tmp = x;
	} else if (x <= -2.1e+103) {
		tmp = x * y;
	} else if (x <= -1.18e-110) {
		tmp = x;
	} else if (x <= 1.0) {
		tmp = 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 <= (-2.2d+273)) then
        tmp = x
    else if (x <= (-1.2d+179)) then
        tmp = x * y
    else if (x <= (-1d+130)) then
        tmp = x
    else if (x <= (-2.1d+103)) then
        tmp = x * y
    else if (x <= (-1.18d-110)) then
        tmp = x
    else if (x <= 1.0d0) then
        tmp = y
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -2.2e+273) {
		tmp = x;
	} else if (x <= -1.2e+179) {
		tmp = x * y;
	} else if (x <= -1e+130) {
		tmp = x;
	} else if (x <= -2.1e+103) {
		tmp = x * y;
	} else if (x <= -1.18e-110) {
		tmp = x;
	} else if (x <= 1.0) {
		tmp = y;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -2.2e+273:
		tmp = x
	elif x <= -1.2e+179:
		tmp = x * y
	elif x <= -1e+130:
		tmp = x
	elif x <= -2.1e+103:
		tmp = x * y
	elif x <= -1.18e-110:
		tmp = x
	elif x <= 1.0:
		tmp = y
	else:
		tmp = x * y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -2.2e+273)
		tmp = x;
	elseif (x <= -1.2e+179)
		tmp = Float64(x * y);
	elseif (x <= -1e+130)
		tmp = x;
	elseif (x <= -2.1e+103)
		tmp = Float64(x * y);
	elseif (x <= -1.18e-110)
		tmp = x;
	elseif (x <= 1.0)
		tmp = y;
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -2.2e+273)
		tmp = x;
	elseif (x <= -1.2e+179)
		tmp = x * y;
	elseif (x <= -1e+130)
		tmp = x;
	elseif (x <= -2.1e+103)
		tmp = x * y;
	elseif (x <= -1.18e-110)
		tmp = x;
	elseif (x <= 1.0)
		tmp = y;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -2.2e+273], x, If[LessEqual[x, -1.2e+179], N[(x * y), $MachinePrecision], If[LessEqual[x, -1e+130], x, If[LessEqual[x, -2.1e+103], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.18e-110], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+273}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq -1.2 \cdot 10^{+179}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq -1 \cdot 10^{+130}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq -2.1 \cdot 10^{+103}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq -1.18 \cdot 10^{-110}:\\
\;\;\;\;x\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.1999999999999999e273 or -1.20000000000000006e179 < x < -1.0000000000000001e130 or -2.1000000000000002e103 < x < -1.18e-110

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt98.3%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\left(x \cdot y + x\right) + y} \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}\right) \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}} \]
      2. pow398.3%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{\left(x \cdot y + x\right) + y}\right)}^{3}} \]
      3. +-commutative98.3%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(x + x \cdot y\right)} + y}\right)}^{3} \]
      4. *-un-lft-identity98.3%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{1 \cdot x} + x \cdot y\right) + y}\right)}^{3} \]
      5. *-commutative98.3%

        \[\leadsto {\left(\sqrt[3]{\left(1 \cdot x + \color{blue}{y \cdot x}\right) + y}\right)}^{3} \]
      6. distribute-rgt-out98.2%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{x \cdot \left(1 + y\right)} + y}\right)}^{3} \]
      7. fma-define98.2%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\mathsf{fma}\left(x, 1 + y, y\right)}}\right)}^{3} \]
    4. Applied egg-rr98.2%

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

      \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot x} \]
    6. Step-by-step derivation
      1. pow-base-155.1%

        \[\leadsto \color{blue}{1} \cdot x \]
      2. *-lft-identity55.1%

        \[\leadsto \color{blue}{x} \]
    7. Simplified55.1%

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

    if -2.1999999999999999e273 < x < -1.20000000000000006e179 or -1.0000000000000001e130 < x < -2.1000000000000002e103 or 1 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} + y \]
    4. Taylor expanded in x around inf 60.9%

      \[\leadsto \color{blue}{x \cdot y} \]
    5. Step-by-step derivation
      1. *-commutative60.9%

        \[\leadsto \color{blue}{y \cdot x} \]
    6. Simplified60.9%

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

    if -1.18e-110 < x < 1

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+273}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{+179}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1 \cdot 10^{+130}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+103}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.18 \cdot 10^{-110}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 74.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{+273}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6 \cdot 10^{+178}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{+129}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+97} \lor \neg \left(x \leq 3300\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.2e+273)
   x
   (if (<= x -6e+178)
     (* x y)
     (if (<= x -6.6e+129)
       x
       (if (or (<= x -1.4e+97) (not (<= x 3300.0))) (* x y) (+ x y))))))
double code(double x, double y) {
	double tmp;
	if (x <= -1.2e+273) {
		tmp = x;
	} else if (x <= -6e+178) {
		tmp = x * y;
	} else if (x <= -6.6e+129) {
		tmp = x;
	} else if ((x <= -1.4e+97) || !(x <= 3300.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 <= (-1.2d+273)) then
        tmp = x
    else if (x <= (-6d+178)) then
        tmp = x * y
    else if (x <= (-6.6d+129)) then
        tmp = x
    else if ((x <= (-1.4d+97)) .or. (.not. (x <= 3300.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 <= -1.2e+273) {
		tmp = x;
	} else if (x <= -6e+178) {
		tmp = x * y;
	} else if (x <= -6.6e+129) {
		tmp = x;
	} else if ((x <= -1.4e+97) || !(x <= 3300.0)) {
		tmp = x * y;
	} else {
		tmp = x + y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.2e+273:
		tmp = x
	elif x <= -6e+178:
		tmp = x * y
	elif x <= -6.6e+129:
		tmp = x
	elif (x <= -1.4e+97) or not (x <= 3300.0):
		tmp = x * y
	else:
		tmp = x + y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.2e+273)
		tmp = x;
	elseif (x <= -6e+178)
		tmp = Float64(x * y);
	elseif (x <= -6.6e+129)
		tmp = x;
	elseif ((x <= -1.4e+97) || !(x <= 3300.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 <= -1.2e+273)
		tmp = x;
	elseif (x <= -6e+178)
		tmp = x * y;
	elseif (x <= -6.6e+129)
		tmp = x;
	elseif ((x <= -1.4e+97) || ~((x <= 3300.0)))
		tmp = x * y;
	else
		tmp = x + y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.2e+273], x, If[LessEqual[x, -6e+178], N[(x * y), $MachinePrecision], If[LessEqual[x, -6.6e+129], x, If[Or[LessEqual[x, -1.4e+97], N[Not[LessEqual[x, 3300.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x + y), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+273}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq -6 \cdot 10^{+178}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq -6.6 \cdot 10^{+129}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq -1.4 \cdot 10^{+97} \lor \neg \left(x \leq 3300\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.2000000000000001e273 or -6.00000000000000031e178 < x < -6.5999999999999998e129

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt99.2%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\left(x \cdot y + x\right) + y} \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}\right) \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}} \]
      2. pow399.2%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{\left(x \cdot y + x\right) + y}\right)}^{3}} \]
      3. +-commutative99.2%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(x + x \cdot y\right)} + y}\right)}^{3} \]
      4. *-un-lft-identity99.2%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{1 \cdot x} + x \cdot y\right) + y}\right)}^{3} \]
      5. *-commutative99.2%

        \[\leadsto {\left(\sqrt[3]{\left(1 \cdot x + \color{blue}{y \cdot x}\right) + y}\right)}^{3} \]
      6. distribute-rgt-out99.2%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{x \cdot \left(1 + y\right)} + y}\right)}^{3} \]
      7. fma-define99.2%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\mathsf{fma}\left(x, 1 + y, y\right)}}\right)}^{3} \]
    4. Applied egg-rr99.2%

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

      \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot x} \]
    6. Step-by-step derivation
      1. pow-base-154.6%

        \[\leadsto \color{blue}{1} \cdot x \]
      2. *-lft-identity54.6%

        \[\leadsto \color{blue}{x} \]
    7. Simplified54.6%

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

    if -1.2000000000000001e273 < x < -6.00000000000000031e178 or -6.5999999999999998e129 < x < -1.4e97 or 3300 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} + y \]
    4. Taylor expanded in x around inf 60.9%

      \[\leadsto \color{blue}{x \cdot y} \]
    5. Step-by-step derivation
      1. *-commutative60.9%

        \[\leadsto \color{blue}{y \cdot x} \]
    6. Simplified60.9%

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

    if -1.4e97 < x < 3300

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{+273}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6 \cdot 10^{+178}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{+129}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+97} \lor \neg \left(x \leq 3300\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 87.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -44000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-6}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;y + x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -44000000000.0) (* x y) (if (<= y 2.3e-6) (+ x y) (+ y (* x y)))))
double code(double x, double y) {
	double tmp;
	if (y <= -44000000000.0) {
		tmp = x * y;
	} else if (y <= 2.3e-6) {
		tmp = x + y;
	} else {
		tmp = y + (x * y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-44000000000.0d0)) then
        tmp = x * y
    else if (y <= 2.3d-6) then
        tmp = x + y
    else
        tmp = y + (x * y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -44000000000.0) {
		tmp = x * y;
	} else if (y <= 2.3e-6) {
		tmp = x + y;
	} else {
		tmp = y + (x * y);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -44000000000.0:
		tmp = x * y
	elif y <= 2.3e-6:
		tmp = x + y
	else:
		tmp = y + (x * y)
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -44000000000.0)
		tmp = Float64(x * y);
	elseif (y <= 2.3e-6)
		tmp = Float64(x + y);
	else
		tmp = Float64(y + Float64(x * y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -44000000000.0)
		tmp = x * y;
	elseif (y <= 2.3e-6)
		tmp = x + y;
	else
		tmp = y + (x * y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -44000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.3e-6], N[(x + y), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -44000000000:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 2.3 \cdot 10^{-6}:\\
\;\;\;\;x + y\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} + y \]
    4. Taylor expanded in x around inf 57.5%

      \[\leadsto \color{blue}{x \cdot y} \]
    5. Step-by-step derivation
      1. *-commutative57.5%

        \[\leadsto \color{blue}{y \cdot x} \]
    6. Simplified57.5%

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

    if -4.4e10 < y < 2.3e-6

    1. Initial program 100.0%

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

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

    if 2.3e-6 < y

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} + y \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -44000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-6}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;y + x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 49.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.18 \cdot 10^{-110}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= x -1.18e-110) x y))
double code(double x, double y) {
	double tmp;
	if (x <= -1.18e-110) {
		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 (x <= (-1.18d-110)) then
        tmp = x
    else
        tmp = y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.18e-110) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.18e-110:
		tmp = x
	else:
		tmp = y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.18e-110)
		tmp = x;
	else
		tmp = y;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.18e-110)
		tmp = x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.18e-110], x, y]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.18 \cdot 10^{-110}:\\
\;\;\;\;x\\

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


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

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt98.5%

        \[\leadsto \color{blue}{\left(\sqrt[3]{\left(x \cdot y + x\right) + y} \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}\right) \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}} \]
      2. pow398.5%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{\left(x \cdot y + x\right) + y}\right)}^{3}} \]
      3. +-commutative98.5%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(x + x \cdot y\right)} + y}\right)}^{3} \]
      4. *-un-lft-identity98.5%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{1 \cdot x} + x \cdot y\right) + y}\right)}^{3} \]
      5. *-commutative98.5%

        \[\leadsto {\left(\sqrt[3]{\left(1 \cdot x + \color{blue}{y \cdot x}\right) + y}\right)}^{3} \]
      6. distribute-rgt-out98.5%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{x \cdot \left(1 + y\right)} + y}\right)}^{3} \]
      7. fma-define98.5%

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\mathsf{fma}\left(x, 1 + y, y\right)}}\right)}^{3} \]
    4. Applied egg-rr98.5%

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

      \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot x} \]
    6. Step-by-step derivation
      1. pow-base-148.6%

        \[\leadsto \color{blue}{1} \cdot x \]
      2. *-lft-identity48.6%

        \[\leadsto \color{blue}{x} \]
    7. Simplified48.6%

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

    if -1.18e-110 < x

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.18 \cdot 10^{-110}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 38.8% accurate, 7.0× speedup?

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

    \[\left(x \cdot y + x\right) + y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-cube-cbrt98.2%

      \[\leadsto \color{blue}{\left(\sqrt[3]{\left(x \cdot y + x\right) + y} \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}\right) \cdot \sqrt[3]{\left(x \cdot y + x\right) + y}} \]
    2. pow398.2%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\left(x \cdot y + x\right) + y}\right)}^{3}} \]
    3. +-commutative98.2%

      \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(x + x \cdot y\right)} + y}\right)}^{3} \]
    4. *-un-lft-identity98.2%

      \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{1 \cdot x} + x \cdot y\right) + y}\right)}^{3} \]
    5. *-commutative98.2%

      \[\leadsto {\left(\sqrt[3]{\left(1 \cdot x + \color{blue}{y \cdot x}\right) + y}\right)}^{3} \]
    6. distribute-rgt-out98.2%

      \[\leadsto {\left(\sqrt[3]{\color{blue}{x \cdot \left(1 + y\right)} + y}\right)}^{3} \]
    7. fma-define98.2%

      \[\leadsto {\left(\sqrt[3]{\color{blue}{\mathsf{fma}\left(x, 1 + y, y\right)}}\right)}^{3} \]
  4. Applied egg-rr98.2%

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

    \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot x} \]
  6. Step-by-step derivation
    1. pow-base-135.1%

      \[\leadsto \color{blue}{1} \cdot x \]
    2. *-lft-identity35.1%

      \[\leadsto \color{blue}{x} \]
  7. Simplified35.1%

    \[\leadsto \color{blue}{x} \]
  8. Final simplification35.1%

    \[\leadsto x \]
  9. Add Preprocessing

Reproduce

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