log(exp(x+y)/(exp(x)+exp(y)))

Percentage Accurate: 99.9% → 99.9%
Time: 5.0s
Alternatives: 10
Speedup: 1.3×

Specification

?
\[\left(-2 \leq x \land x \leq 2\right) \land \left(-2 \leq y \land y \leq 2\right)\]
\[\begin{array}{l} \\ \log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \end{array} \]
(FPCore (x y) :precision binary64 (log (/ (exp (+ x y)) (+ (exp x) (exp y)))))
double code(double x, double y) {
	return log((exp((x + y)) / (exp(x) + exp(y))));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = log((exp((x + y)) / (exp(x) + exp(y))))
end function
public static double code(double x, double y) {
	return Math.log((Math.exp((x + y)) / (Math.exp(x) + Math.exp(y))));
}
def code(x, y):
	return math.log((math.exp((x + y)) / (math.exp(x) + math.exp(y))))
function code(x, y)
	return log(Float64(exp(Float64(x + y)) / Float64(exp(x) + exp(y))))
end
function tmp = code(x, y)
	tmp = log((exp((x + y)) / (exp(x) + exp(y))));
end
code[x_, y_] := N[Log[N[(N[Exp[N[(x + y), $MachinePrecision]], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + N[Exp[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)
\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 10 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: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \end{array} \]
(FPCore (x y) :precision binary64 (log (/ (exp (+ x y)) (+ (exp x) (exp y)))))
double code(double x, double y) {
	return log((exp((x + y)) / (exp(x) + exp(y))));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = log((exp((x + y)) / (exp(x) + exp(y))))
end function
public static double code(double x, double y) {
	return Math.log((Math.exp((x + y)) / (Math.exp(x) + Math.exp(y))));
}
def code(x, y):
	return math.log((math.exp((x + y)) / (math.exp(x) + math.exp(y))))
function code(x, y)
	return log(Float64(exp(Float64(x + y)) / Float64(exp(x) + exp(y))))
end
function tmp = code(x, y)
	tmp = log((exp((x + y)) / (exp(x) + exp(y))));
end
code[x_, y_] := N[Log[N[(N[Exp[N[(x + y), $MachinePrecision]], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + N[Exp[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)
\end{array}

Alternative 1: 99.9% accurate, 0.8× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\frac{e^{x + y}}{e^{x} + e^{y}} \leq 0.49999999999999994:\\ \;\;\;\;x - \mathsf{log1p}\left(e^{x}\right)\\ \mathbf{else}:\\ \;\;\;\;y - \mathsf{log1p}\left(e^{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 (<= (/ (exp (+ x y)) (+ (exp x) (exp y))) 0.49999999999999994)
   (- x (log1p (exp x)))
   (- y (log1p (exp y)))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if ((exp((x + y)) / (exp(x) + exp(y))) <= 0.49999999999999994) {
		tmp = x - log1p(exp(x));
	} else {
		tmp = y - log1p(exp(y));
	}
	return tmp;
}
assert x < y;
public static double code(double x, double y) {
	double tmp;
	if ((Math.exp((x + y)) / (Math.exp(x) + Math.exp(y))) <= 0.49999999999999994) {
		tmp = x - Math.log1p(Math.exp(x));
	} else {
		tmp = y - Math.log1p(Math.exp(y));
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if (math.exp((x + y)) / (math.exp(x) + math.exp(y))) <= 0.49999999999999994:
		tmp = x - math.log1p(math.exp(x))
	else:
		tmp = y - math.log1p(math.exp(y))
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (Float64(exp(Float64(x + y)) / Float64(exp(x) + exp(y))) <= 0.49999999999999994)
		tmp = Float64(x - log1p(exp(x)));
	else
		tmp = Float64(y - log1p(exp(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[Exp[N[(x + y), $MachinePrecision]], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + N[Exp[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.49999999999999994], N[(x - N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(y - N[Log[1 + N[Exp[y], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{x + y}}{e^{x} + e^{y}} \leq 0.49999999999999994:\\
\;\;\;\;x - \mathsf{log1p}\left(e^{x}\right)\\

\mathbf{else}:\\
\;\;\;\;y - \mathsf{log1p}\left(e^{y}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (exp.f64 (+.f64 x y)) (+.f64 (exp.f64 x) (exp.f64 y))) < 0.499999999999999944

    1. Initial program 99.3%

      \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
      2. lift-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
      3. frac-2negN/A

        \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\mathsf{neg}\left(\left(e^{x} + e^{y}\right)\right)}\right)} \]
      4. neg-mul-1N/A

        \[\leadsto \log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\color{blue}{-1 \cdot \left(e^{x} + e^{y}\right)}}\right) \]
      5. associate-/r*N/A

        \[\leadsto \log \color{blue}{\left(\frac{\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}}{e^{x} + e^{y}}\right)} \]
      6. log-divN/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
      7. lower--.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
      8. lower-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
      9. lower-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
      10. lower-neg.f64N/A

        \[\leadsto \log \left(\frac{\color{blue}{-e^{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      11. lift-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      12. +-commutativeN/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      13. lower-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      14. lower-log.f6499.4

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \color{blue}{\log \left(e^{x} + e^{y}\right)} \]
      15. lift-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{x} + e^{y}\right)} \]
      16. +-commutativeN/A

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
      17. lower-+.f6499.4

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
    4. Applied rewrites99.4%

      \[\leadsto \color{blue}{\log \left(\frac{-e^{y + x}}{-1}\right) - \log \left(e^{y} + e^{x}\right)} \]
    5. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \log \left(1 + e^{x}\right)} \]
    6. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \color{blue}{x - \log \left(1 + e^{x}\right)} \]
      2. lower-log1p.f64N/A

        \[\leadsto x - \color{blue}{\mathsf{log1p}\left(e^{x}\right)} \]
      3. lower-exp.f6459.4

        \[\leadsto x - \mathsf{log1p}\left(\color{blue}{e^{x}}\right) \]
    7. Applied rewrites59.4%

      \[\leadsto \color{blue}{x - \mathsf{log1p}\left(e^{x}\right)} \]

    if 0.499999999999999944 < (/.f64 (exp.f64 (+.f64 x y)) (+.f64 (exp.f64 x) (exp.f64 y)))

    1. Initial program 100.0%

      \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
      2. lift-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
      3. frac-2negN/A

        \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\mathsf{neg}\left(\left(e^{x} + e^{y}\right)\right)}\right)} \]
      4. neg-mul-1N/A

        \[\leadsto \log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\color{blue}{-1 \cdot \left(e^{x} + e^{y}\right)}}\right) \]
      5. associate-/r*N/A

        \[\leadsto \log \color{blue}{\left(\frac{\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}}{e^{x} + e^{y}}\right)} \]
      6. log-divN/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
      7. lower--.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
      8. lower-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
      9. lower-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
      10. lower-neg.f64N/A

        \[\leadsto \log \left(\frac{\color{blue}{-e^{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      11. lift-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      12. +-commutativeN/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      13. lower-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      14. lower-log.f64100.0

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \color{blue}{\log \left(e^{x} + e^{y}\right)} \]
      15. lift-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{x} + e^{y}\right)} \]
      16. +-commutativeN/A

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
      17. lower-+.f64100.0

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
    4. Applied rewrites100.0%

      \[\leadsto \color{blue}{\log \left(\frac{-e^{y + x}}{-1}\right) - \log \left(e^{y} + e^{x}\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{y - \log \left(1 + e^{y}\right)} \]
    6. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \color{blue}{y - \log \left(1 + e^{y}\right)} \]
      2. lower-log1p.f64N/A

        \[\leadsto y - \color{blue}{\mathsf{log1p}\left(e^{y}\right)} \]
      3. lower-exp.f6498.8

        \[\leadsto y - \mathsf{log1p}\left(\color{blue}{e^{y}}\right) \]
    7. Applied rewrites98.8%

      \[\leadsto \color{blue}{y - \mathsf{log1p}\left(e^{y}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.9% accurate, 0.8× speedup?

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

    \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
    2. clear-numN/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{e^{x} + e^{y}}{e^{x + y}}}\right)} \]
    3. frac-2negN/A

      \[\leadsto \log \left(\frac{1}{\color{blue}{\frac{\mathsf{neg}\left(\left(e^{x} + e^{y}\right)\right)}{\mathsf{neg}\left(e^{x + y}\right)}}}\right) \]
    4. associate-/r/N/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\left(e^{x} + e^{y}\right)\right)} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right)} \]
    5. lower-*.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\left(e^{x} + e^{y}\right)\right)} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right)} \]
    6. neg-mul-1N/A

      \[\leadsto \log \left(\frac{1}{\color{blue}{-1 \cdot \left(e^{x} + e^{y}\right)}} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right) \]
    7. associate-/r*N/A

      \[\leadsto \log \left(\color{blue}{\frac{\frac{1}{-1}}{e^{x} + e^{y}}} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \log \left(\frac{\color{blue}{-1}}{e^{x} + e^{y}} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right) \]
    9. lower-/.f64N/A

      \[\leadsto \log \left(\color{blue}{\frac{-1}{e^{x} + e^{y}}} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right) \]
    10. lift-+.f64N/A

      \[\leadsto \log \left(\frac{-1}{\color{blue}{e^{x} + e^{y}}} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right) \]
    11. +-commutativeN/A

      \[\leadsto \log \left(\frac{-1}{\color{blue}{e^{y} + e^{x}}} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right) \]
    12. lower-+.f64N/A

      \[\leadsto \log \left(\frac{-1}{\color{blue}{e^{y} + e^{x}}} \cdot \left(\mathsf{neg}\left(e^{x + y}\right)\right)\right) \]
    13. lower-neg.f6499.9

      \[\leadsto \log \left(\frac{-1}{e^{y} + e^{x}} \cdot \color{blue}{\left(-e^{x + y}\right)}\right) \]
    14. lift-+.f64N/A

      \[\leadsto \log \left(\frac{-1}{e^{y} + e^{x}} \cdot \left(-e^{\color{blue}{x + y}}\right)\right) \]
    15. +-commutativeN/A

      \[\leadsto \log \left(\frac{-1}{e^{y} + e^{x}} \cdot \left(-e^{\color{blue}{y + x}}\right)\right) \]
    16. lower-+.f6499.9

      \[\leadsto \log \left(\frac{-1}{e^{y} + e^{x}} \cdot \left(-e^{\color{blue}{y + x}}\right)\right) \]
  4. Applied rewrites99.9%

    \[\leadsto \log \color{blue}{\left(\frac{-1}{e^{y} + e^{x}} \cdot \left(-e^{y + x}\right)\right)} \]
  5. Final simplification99.9%

    \[\leadsto \log \left({\left(e^{y} + e^{x}\right)}^{-1} \cdot e^{y + x}\right) \]
  6. Add Preprocessing

Alternative 3: 99.9% accurate, 1.0× speedup?

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

    \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
    3. frac-2negN/A

      \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\mathsf{neg}\left(\left(e^{x} + e^{y}\right)\right)}\right)} \]
    4. neg-mul-1N/A

      \[\leadsto \log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\color{blue}{-1 \cdot \left(e^{x} + e^{y}\right)}}\right) \]
    5. associate-/r*N/A

      \[\leadsto \log \color{blue}{\left(\frac{\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}}{e^{x} + e^{y}}\right)} \]
    6. log-divN/A

      \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
    7. lower--.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
    8. lower-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
    9. lower-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
    10. lower-neg.f64N/A

      \[\leadsto \log \left(\frac{\color{blue}{-e^{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
    11. lift-+.f64N/A

      \[\leadsto \log \left(\frac{-e^{\color{blue}{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
    12. +-commutativeN/A

      \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
    13. lower-+.f64N/A

      \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
    14. lower-log.f6499.9

      \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \color{blue}{\log \left(e^{x} + e^{y}\right)} \]
    15. lift-+.f64N/A

      \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{x} + e^{y}\right)} \]
    16. +-commutativeN/A

      \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
    17. lower-+.f6499.9

      \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\log \left(\frac{-e^{y + x}}{-1}\right) - \log \left(e^{y} + e^{x}\right)} \]
  5. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{-e^{y + x}}{-1}\right) - \log \left(e^{y} + e^{x}\right)} \]
    2. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{-e^{y + x}}{-1}\right)} - \log \left(e^{y} + e^{x}\right) \]
    3. lift-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{-e^{y + x}}{-1}\right)} - \log \left(e^{y} + e^{x}\right) \]
    4. lift-neg.f64N/A

      \[\leadsto \log \left(\frac{\color{blue}{\mathsf{neg}\left(e^{y + x}\right)}}{-1}\right) - \log \left(e^{y} + e^{x}\right) \]
    5. metadata-evalN/A

      \[\leadsto \log \left(\frac{\mathsf{neg}\left(e^{y + x}\right)}{\color{blue}{\mathsf{neg}\left(1\right)}}\right) - \log \left(e^{y} + e^{x}\right) \]
    6. frac-2negN/A

      \[\leadsto \log \color{blue}{\left(\frac{e^{y + x}}{1}\right)} - \log \left(e^{y} + e^{x}\right) \]
    7. /-rgt-identityN/A

      \[\leadsto \log \color{blue}{\left(e^{y + x}\right)} - \log \left(e^{y} + e^{x}\right) \]
    8. lift-log.f64N/A

      \[\leadsto \log \left(e^{y + x}\right) - \color{blue}{\log \left(e^{y} + e^{x}\right)} \]
    9. diff-logN/A

      \[\leadsto \color{blue}{\log \left(\frac{e^{y + x}}{e^{y} + e^{x}}\right)} \]
    10. lift-exp.f64N/A

      \[\leadsto \log \left(\frac{\color{blue}{e^{y + x}}}{e^{y} + e^{x}}\right) \]
    11. lift-+.f64N/A

      \[\leadsto \log \left(\frac{e^{\color{blue}{y + x}}}{e^{y} + e^{x}}\right) \]
    12. +-commutativeN/A

      \[\leadsto \log \left(\frac{e^{\color{blue}{x + y}}}{e^{y} + e^{x}}\right) \]
    13. lift-+.f64N/A

      \[\leadsto \log \left(\frac{e^{x + y}}{\color{blue}{e^{y} + e^{x}}}\right) \]
    14. +-commutativeN/A

      \[\leadsto \log \left(\frac{e^{x + y}}{\color{blue}{e^{x} + e^{y}}}\right) \]
    15. lift-exp.f64N/A

      \[\leadsto \log \left(\frac{e^{x + y}}{\color{blue}{e^{x}} + e^{y}}\right) \]
    16. lift-exp.f64N/A

      \[\leadsto \log \left(\frac{e^{x + y}}{e^{x} + \color{blue}{e^{y}}}\right) \]
    17. clear-numN/A

      \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{e^{x} + e^{y}}{e^{x + y}}}\right)} \]
  6. Applied rewrites99.9%

    \[\leadsto \color{blue}{-\log \left(\frac{\frac{e^{x} + e^{y}}{e^{x + y}}}{1}\right)} \]
  7. Final simplification99.9%

    \[\leadsto -\log \left(\frac{e^{x} + e^{y}}{e^{x + y}}\right) \]
  8. Add Preprocessing

Alternative 4: 99.9% accurate, 1.0× speedup?

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

    \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 5: 99.9% accurate, 1.3× speedup?

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

    \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-log.f64N/A

      \[\leadsto \color{blue}{\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
    2. lift-/.f64N/A

      \[\leadsto \log \color{blue}{\left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
    3. log-divN/A

      \[\leadsto \color{blue}{\log \left(e^{x + y}\right) - \log \left(e^{x} + e^{y}\right)} \]
    4. lower--.f64N/A

      \[\leadsto \color{blue}{\log \left(e^{x + y}\right) - \log \left(e^{x} + e^{y}\right)} \]
    5. lift-exp.f64N/A

      \[\leadsto \log \color{blue}{\left(e^{x + y}\right)} - \log \left(e^{x} + e^{y}\right) \]
    6. rem-log-expN/A

      \[\leadsto \color{blue}{\left(x + y\right)} - \log \left(e^{x} + e^{y}\right) \]
    7. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(x + y\right)} - \log \left(e^{x} + e^{y}\right) \]
    8. +-commutativeN/A

      \[\leadsto \color{blue}{\left(y + x\right)} - \log \left(e^{x} + e^{y}\right) \]
    9. lower-+.f64N/A

      \[\leadsto \color{blue}{\left(y + x\right)} - \log \left(e^{x} + e^{y}\right) \]
    10. lower-log.f6499.9

      \[\leadsto \left(y + x\right) - \color{blue}{\log \left(e^{x} + e^{y}\right)} \]
    11. lift-+.f64N/A

      \[\leadsto \left(y + x\right) - \log \color{blue}{\left(e^{x} + e^{y}\right)} \]
    12. +-commutativeN/A

      \[\leadsto \left(y + x\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
    13. lower-+.f6499.9

      \[\leadsto \left(y + x\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\left(y + x\right) - \log \left(e^{y} + e^{x}\right)} \]
  5. Add Preprocessing

Alternative 6: 99.7% accurate, 2.0× speedup?

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

\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0020833333333333333, y \cdot y, -0.020833333333333332\right), y \cdot y, 0.25\right), y, 0.5\right)\right)\\


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

    1. Initial program 99.2%

      \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
      2. lift-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{e^{x + y}}{e^{x} + e^{y}}\right)} \]
      3. frac-2negN/A

        \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\mathsf{neg}\left(\left(e^{x} + e^{y}\right)\right)}\right)} \]
      4. neg-mul-1N/A

        \[\leadsto \log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{\color{blue}{-1 \cdot \left(e^{x} + e^{y}\right)}}\right) \]
      5. associate-/r*N/A

        \[\leadsto \log \color{blue}{\left(\frac{\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}}{e^{x} + e^{y}}\right)} \]
      6. log-divN/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
      7. lower--.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right) - \log \left(e^{x} + e^{y}\right)} \]
      8. lower-log.f64N/A

        \[\leadsto \color{blue}{\log \left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
      9. lower-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{\mathsf{neg}\left(e^{x + y}\right)}{-1}\right)} - \log \left(e^{x} + e^{y}\right) \]
      10. lower-neg.f64N/A

        \[\leadsto \log \left(\frac{\color{blue}{-e^{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      11. lift-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{x + y}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      12. +-commutativeN/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      13. lower-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{\color{blue}{y + x}}}{-1}\right) - \log \left(e^{x} + e^{y}\right) \]
      14. lower-log.f6499.2

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \color{blue}{\log \left(e^{x} + e^{y}\right)} \]
      15. lift-+.f64N/A

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{x} + e^{y}\right)} \]
      16. +-commutativeN/A

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
      17. lower-+.f6499.2

        \[\leadsto \log \left(\frac{-e^{y + x}}{-1}\right) - \log \color{blue}{\left(e^{y} + e^{x}\right)} \]
    4. Applied rewrites99.2%

      \[\leadsto \color{blue}{\log \left(\frac{-e^{y + x}}{-1}\right) - \log \left(e^{y} + e^{x}\right)} \]
    5. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \log \left(1 + e^{x}\right)} \]
    6. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \color{blue}{x - \log \left(1 + e^{x}\right)} \]
      2. lower-log1p.f64N/A

        \[\leadsto x - \color{blue}{\mathsf{log1p}\left(e^{x}\right)} \]
      3. lower-exp.f64100.0

        \[\leadsto x - \mathsf{log1p}\left(\color{blue}{e^{x}}\right) \]
    7. Applied rewrites100.0%

      \[\leadsto \color{blue}{x - \mathsf{log1p}\left(e^{x}\right)} \]

    if -1.1e-16 < x

    1. Initial program 99.9%

      \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
      2. lower-exp.f64N/A

        \[\leadsto \log \left(\frac{\color{blue}{e^{y}}}{1 + e^{y}}\right) \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(\frac{e^{y}}{\color{blue}{1 + e^{y}}}\right) \]
      4. lower-exp.f6498.8

        \[\leadsto \log \left(\frac{e^{y}}{1 + \color{blue}{e^{y}}}\right) \]
    5. Applied rewrites98.8%

      \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \log \left(\frac{1}{2} + \color{blue}{y \cdot \left(\frac{1}{4} + {y}^{2} \cdot \left(\frac{1}{480} \cdot {y}^{2} - \frac{1}{48}\right)\right)}\right) \]
    7. Step-by-step derivation
      1. Applied rewrites97.8%

        \[\leadsto \log \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0020833333333333333, y \cdot y, -0.020833333333333332\right), y \cdot y, 0.25\right), \color{blue}{y}, 0.5\right)\right) \]
    8. Recombined 2 regimes into one program.
    9. Add Preprocessing

    Alternative 7: 97.6% accurate, 3.2× speedup?

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

      \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
      2. lower-exp.f64N/A

        \[\leadsto \log \left(\frac{\color{blue}{e^{y}}}{1 + e^{y}}\right) \]
      3. lower-+.f64N/A

        \[\leadsto \log \left(\frac{e^{y}}{\color{blue}{1 + e^{y}}}\right) \]
      4. lower-exp.f6498.2

        \[\leadsto \log \left(\frac{e^{y}}{1 + \color{blue}{e^{y}}}\right) \]
    5. Applied rewrites98.2%

      \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
    6. Taylor expanded in y around 0

      \[\leadsto \log \left(\frac{1}{2} + \color{blue}{y \cdot \left(\frac{1}{4} + {y}^{2} \cdot \left(\frac{1}{480} \cdot {y}^{2} - \frac{1}{48}\right)\right)}\right) \]
    7. Step-by-step derivation
      1. Applied rewrites97.3%

        \[\leadsto \log \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0020833333333333333, y \cdot y, -0.020833333333333332\right), y \cdot y, 0.25\right), \color{blue}{y}, 0.5\right)\right) \]
      2. Add Preprocessing

      Alternative 8: 97.5% accurate, 3.5× speedup?

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

        \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
        2. lower-exp.f64N/A

          \[\leadsto \log \left(\frac{\color{blue}{e^{y}}}{1 + e^{y}}\right) \]
        3. lower-+.f64N/A

          \[\leadsto \log \left(\frac{e^{y}}{\color{blue}{1 + e^{y}}}\right) \]
        4. lower-exp.f6498.2

          \[\leadsto \log \left(\frac{e^{y}}{1 + \color{blue}{e^{y}}}\right) \]
      5. Applied rewrites98.2%

        \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
      6. Taylor expanded in y around 0

        \[\leadsto \log \left(\frac{1}{2} + \color{blue}{y \cdot \left(\frac{1}{4} + \frac{-1}{48} \cdot {y}^{2}\right)}\right) \]
      7. Step-by-step derivation
        1. Applied rewrites96.8%

          \[\leadsto \log \left(\mathsf{fma}\left(\mathsf{fma}\left(-0.020833333333333332, y \cdot y, 0.25\right), \color{blue}{y}, 0.5\right)\right) \]
        2. Add Preprocessing

        Alternative 9: 97.3% accurate, 3.9× speedup?

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

          \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
        4. Step-by-step derivation
          1. lower-/.f64N/A

            \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
          2. lower-exp.f64N/A

            \[\leadsto \log \left(\frac{\color{blue}{e^{y}}}{1 + e^{y}}\right) \]
          3. lower-+.f64N/A

            \[\leadsto \log \left(\frac{e^{y}}{\color{blue}{1 + e^{y}}}\right) \]
          4. lower-exp.f6498.2

            \[\leadsto \log \left(\frac{e^{y}}{1 + \color{blue}{e^{y}}}\right) \]
        5. Applied rewrites98.2%

          \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
        6. Taylor expanded in y around 0

          \[\leadsto \log \left(\frac{1}{2} + \color{blue}{\frac{1}{4} \cdot y}\right) \]
        7. Step-by-step derivation
          1. Applied rewrites96.3%

            \[\leadsto \log \left(\mathsf{fma}\left(0.25, \color{blue}{y}, 0.5\right)\right) \]
          2. Add Preprocessing

          Alternative 10: 95.9% accurate, 4.1× speedup?

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

            \[\log \left(\frac{e^{x + y}}{e^{x} + e^{y}}\right) \]
          2. Add Preprocessing
          3. Taylor expanded in x around 0

            \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
            2. lower-exp.f64N/A

              \[\leadsto \log \left(\frac{\color{blue}{e^{y}}}{1 + e^{y}}\right) \]
            3. lower-+.f64N/A

              \[\leadsto \log \left(\frac{e^{y}}{\color{blue}{1 + e^{y}}}\right) \]
            4. lower-exp.f6498.2

              \[\leadsto \log \left(\frac{e^{y}}{1 + \color{blue}{e^{y}}}\right) \]
          5. Applied rewrites98.2%

            \[\leadsto \log \color{blue}{\left(\frac{e^{y}}{1 + e^{y}}\right)} \]
          6. Taylor expanded in y around 0

            \[\leadsto \log \frac{1}{2} \]
          7. Step-by-step derivation
            1. Applied rewrites93.7%

              \[\leadsto \log 0.5 \]
            2. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 1 
            (FPCore (x y)
              :name "log(exp(x+y)/(exp(x)+exp(y)))"
              :precision binary64
              :pre (and (and (<= -2.0 x) (<= x 2.0)) (and (<= -2.0 y) (<= y 2.0)))
              (log (/ (exp (+ x y)) (+ (exp x) (exp y)))))