Quotient of sum of exps

Percentage Accurate: 98.8% → 99.0%
Time: 8.0s
Alternatives: 10
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{e^{a}}{e^{a} + e^{b}} \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{a}}{e^{a} + e^{b}}
\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: 98.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e^{a}}{e^{a} + e^{b}} \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}

Alternative 1: 99.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ e^{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)} \end{array} \]
(FPCore (a b) :precision binary64 (exp (fma (log (+ (exp a) (exp b))) -1.0 a)))
double code(double a, double b) {
	return exp(fma(log((exp(a) + exp(b))), -1.0, a));
}
function code(a, b)
	return exp(fma(log(Float64(exp(a) + exp(b))), -1.0, a))
end
code[a_, b_] := N[Exp[N[(N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -1.0 + a), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}
\end{array}
Derivation
  1. Initial program 98.8%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \frac{\color{blue}{e^{a}}}{e^{a} + e^{b}} \]
    2. lift-exp.f64N/A

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a}} + e^{b}} \]
    3. lift-exp.f64N/A

      \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{e^{b}}} \]
    4. lift-+.f64N/A

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + e^{b}}} \]
    5. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{a} + e^{b}}{e^{a}}}} \]
    6. associate-/r/N/A

      \[\leadsto \color{blue}{\frac{1}{e^{a} + e^{b}} \cdot e^{a}} \]
    7. inv-powN/A

      \[\leadsto \color{blue}{{\left(e^{a} + e^{b}\right)}^{-1}} \cdot e^{a} \]
    8. pow-to-expN/A

      \[\leadsto \color{blue}{e^{\log \left(e^{a} + e^{b}\right) \cdot -1}} \cdot e^{a} \]
    9. lift-exp.f64N/A

      \[\leadsto e^{\log \left(e^{a} + e^{b}\right) \cdot -1} \cdot \color{blue}{e^{a}} \]
    10. prod-expN/A

      \[\leadsto \color{blue}{e^{\log \left(e^{a} + e^{b}\right) \cdot -1 + a}} \]
    11. lower-exp.f64N/A

      \[\leadsto \color{blue}{e^{\log \left(e^{a} + e^{b}\right) \cdot -1 + a}} \]
    12. lower-fma.f64N/A

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}} \]
    13. lower-log.f6498.8

      \[\leadsto e^{\mathsf{fma}\left(\color{blue}{\log \left(e^{a} + e^{b}\right)}, -1, a\right)} \]
  4. Applied rewrites98.8%

    \[\leadsto \color{blue}{e^{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}} \]
  5. Add Preprocessing

Alternative 2: 98.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.02:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;e^{-\mathsf{log1p}\left(e^{b}\right)}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 0.02) (/ 1.0 (+ 1.0 (exp (- a)))) (exp (- (log1p (exp b))))))
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 0.02) {
		tmp = 1.0 / (1.0 + exp(-a));
	} else {
		tmp = exp(-log1p(exp(b)));
	}
	return tmp;
}
public static double code(double a, double b) {
	double tmp;
	if (Math.exp(a) <= 0.02) {
		tmp = 1.0 / (1.0 + Math.exp(-a));
	} else {
		tmp = Math.exp(-Math.log1p(Math.exp(b)));
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if math.exp(a) <= 0.02:
		tmp = 1.0 / (1.0 + math.exp(-a))
	else:
		tmp = math.exp(-math.log1p(math.exp(b)))
	return tmp
function code(a, b)
	tmp = 0.0
	if (exp(a) <= 0.02)
		tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a))));
	else
		tmp = exp(Float64(-log1p(exp(b))));
	end
	return tmp
end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.02], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Exp[(-N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.02:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (exp.f64 a) < 0.0200000000000000004

    1. Initial program 96.5%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto \frac{\color{blue}{e^{a}}}{e^{a} + e^{b}} \]
      2. lift-exp.f64N/A

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a}} + e^{b}} \]
      3. lift-exp.f64N/A

        \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{e^{b}}} \]
      4. lift-+.f64N/A

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + e^{b}}} \]
      5. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{e^{a} + e^{b}}{e^{a}}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{e^{a} + e^{b}}{e^{a}}}} \]
      7. div-invN/A

        \[\leadsto \frac{1}{\color{blue}{\left(e^{a} + e^{b}\right) \cdot \frac{1}{e^{a}}}} \]
      8. lower-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\left(e^{a} + e^{b}\right) \cdot \frac{1}{e^{a}}}} \]
      9. lift-exp.f64N/A

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot \frac{1}{\color{blue}{e^{a}}}} \]
      10. rec-expN/A

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot \color{blue}{e^{\mathsf{neg}\left(a\right)}}} \]
      11. lower-exp.f64N/A

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot \color{blue}{e^{\mathsf{neg}\left(a\right)}}} \]
      12. lower-neg.f6496.6

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot e^{\color{blue}{-a}}} \]
    4. Applied rewrites96.6%

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

      \[\leadsto \frac{1}{\color{blue}{e^{\mathsf{neg}\left(a\right)} \cdot \left(1 + e^{a}\right)}} \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{1}{e^{\mathsf{neg}\left(a\right)} \cdot \color{blue}{\left(e^{a} + 1\right)}} \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{1}{\color{blue}{e^{\mathsf{neg}\left(a\right)} \cdot e^{a} + e^{\mathsf{neg}\left(a\right)} \cdot 1}} \]
      3. exp-negN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{e^{a}}} \cdot e^{a} + e^{\mathsf{neg}\left(a\right)} \cdot 1} \]
      4. lft-mult-inverseN/A

        \[\leadsto \frac{1}{\color{blue}{1} + e^{\mathsf{neg}\left(a\right)} \cdot 1} \]
      5. *-rgt-identityN/A

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

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

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-1 \cdot a}}} \]
      8. lower-exp.f64N/A

        \[\leadsto \frac{1}{1 + \color{blue}{e^{-1 \cdot a}}} \]
      9. neg-mul-1N/A

        \[\leadsto \frac{1}{1 + e^{\color{blue}{\mathsf{neg}\left(a\right)}}} \]
      10. lower-neg.f6496.7

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-a}}} \]
    7. Applied rewrites96.7%

      \[\leadsto \frac{1}{\color{blue}{1 + e^{-a}}} \]

    if 0.0200000000000000004 < (exp.f64 a)

    1. Initial program 99.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto \frac{\color{blue}{e^{a}}}{e^{a} + e^{b}} \]
      2. lift-exp.f64N/A

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a}} + e^{b}} \]
      3. lift-exp.f64N/A

        \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{e^{b}}} \]
      4. lift-+.f64N/A

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + e^{b}}} \]
      5. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{e^{a} + e^{b}}{e^{a}}}} \]
      6. associate-/r/N/A

        \[\leadsto \color{blue}{\frac{1}{e^{a} + e^{b}} \cdot e^{a}} \]
      7. inv-powN/A

        \[\leadsto \color{blue}{{\left(e^{a} + e^{b}\right)}^{-1}} \cdot e^{a} \]
      8. pow-to-expN/A

        \[\leadsto \color{blue}{e^{\log \left(e^{a} + e^{b}\right) \cdot -1}} \cdot e^{a} \]
      9. lift-exp.f64N/A

        \[\leadsto e^{\log \left(e^{a} + e^{b}\right) \cdot -1} \cdot \color{blue}{e^{a}} \]
      10. prod-expN/A

        \[\leadsto \color{blue}{e^{\log \left(e^{a} + e^{b}\right) \cdot -1 + a}} \]
      11. lower-exp.f64N/A

        \[\leadsto \color{blue}{e^{\log \left(e^{a} + e^{b}\right) \cdot -1 + a}} \]
      12. lower-fma.f64N/A

        \[\leadsto e^{\color{blue}{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}} \]
      13. lower-log.f6499.5

        \[\leadsto e^{\mathsf{fma}\left(\color{blue}{\log \left(e^{a} + e^{b}\right)}, -1, a\right)} \]
    4. Applied rewrites99.5%

      \[\leadsto \color{blue}{e^{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}} \]
    5. Taylor expanded in a around 0

      \[\leadsto e^{\color{blue}{-1 \cdot \log \left(1 + e^{b}\right)}} \]
    6. Step-by-step derivation
      1. mul-1-negN/A

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

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

        \[\leadsto e^{\mathsf{neg}\left(\color{blue}{\mathsf{log1p}\left(e^{b}\right)}\right)} \]
      4. lower-exp.f6499.1

        \[\leadsto e^{-\mathsf{log1p}\left(\color{blue}{e^{b}}\right)} \]
    7. Applied rewrites99.1%

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

Alternative 3: 98.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ e^{a} \cdot \frac{1}{e^{a} + e^{b}} \end{array} \]
(FPCore (a b) :precision binary64 (* (exp a) (/ 1.0 (+ (exp a) (exp b)))))
double code(double a, double b) {
	return exp(a) * (1.0 / (exp(a) + exp(b)));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp(a) * (1.0d0 / (exp(a) + exp(b)))
end function
public static double code(double a, double b) {
	return Math.exp(a) * (1.0 / (Math.exp(a) + Math.exp(b)));
}
def code(a, b):
	return math.exp(a) * (1.0 / (math.exp(a) + math.exp(b)))
function code(a, b)
	return Float64(exp(a) * Float64(1.0 / Float64(exp(a) + exp(b))))
end
function tmp = code(a, b)
	tmp = exp(a) * (1.0 / (exp(a) + exp(b)));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] * N[(1.0 / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
e^{a} \cdot \frac{1}{e^{a} + e^{b}}
\end{array}
Derivation
  1. Initial program 98.8%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \frac{\color{blue}{e^{a}}}{e^{a} + e^{b}} \]
    2. lift-exp.f64N/A

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a}} + e^{b}} \]
    3. lift-exp.f64N/A

      \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{e^{b}}} \]
    4. lift-+.f64N/A

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + e^{b}}} \]
    5. div-invN/A

      \[\leadsto \color{blue}{e^{a} \cdot \frac{1}{e^{a} + e^{b}}} \]
    6. lift-+.f64N/A

      \[\leadsto e^{a} \cdot \frac{1}{\color{blue}{e^{a} + e^{b}}} \]
    7. flip3-+N/A

      \[\leadsto e^{a} \cdot \frac{1}{\color{blue}{\frac{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}}{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}}} \]
    8. clear-numN/A

      \[\leadsto e^{a} \cdot \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}}} \]
    9. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}} \cdot e^{a}} \]
    10. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}} \cdot e^{a}} \]
  4. Applied rewrites98.8%

    \[\leadsto \color{blue}{\frac{1}{e^{a} + e^{b}} \cdot e^{a}} \]
  5. Final simplification98.8%

    \[\leadsto e^{a} \cdot \frac{1}{e^{a} + e^{b}} \]
  6. Add Preprocessing

Alternative 4: 98.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e^{a}}{e^{a} + e^{b}} \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Derivation
  1. Initial program 98.8%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 5: 98.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.02:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 0.02) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 0.02) {
		tmp = 1.0 / (1.0 + exp(-a));
	} else {
		tmp = 1.0 / (exp(b) + 1.0);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (exp(a) <= 0.02d0) then
        tmp = 1.0d0 / (1.0d0 + exp(-a))
    else
        tmp = 1.0d0 / (exp(b) + 1.0d0)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (Math.exp(a) <= 0.02) {
		tmp = 1.0 / (1.0 + Math.exp(-a));
	} else {
		tmp = 1.0 / (Math.exp(b) + 1.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if math.exp(a) <= 0.02:
		tmp = 1.0 / (1.0 + math.exp(-a))
	else:
		tmp = 1.0 / (math.exp(b) + 1.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (exp(a) <= 0.02)
		tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a))));
	else
		tmp = Float64(1.0 / Float64(exp(b) + 1.0));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (exp(a) <= 0.02)
		tmp = 1.0 / (1.0 + exp(-a));
	else
		tmp = 1.0 / (exp(b) + 1.0);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.02], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.02:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (exp.f64 a) < 0.0200000000000000004

    1. Initial program 96.5%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-exp.f64N/A

        \[\leadsto \frac{\color{blue}{e^{a}}}{e^{a} + e^{b}} \]
      2. lift-exp.f64N/A

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a}} + e^{b}} \]
      3. lift-exp.f64N/A

        \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{e^{b}}} \]
      4. lift-+.f64N/A

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + e^{b}}} \]
      5. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{e^{a} + e^{b}}{e^{a}}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{e^{a} + e^{b}}{e^{a}}}} \]
      7. div-invN/A

        \[\leadsto \frac{1}{\color{blue}{\left(e^{a} + e^{b}\right) \cdot \frac{1}{e^{a}}}} \]
      8. lower-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\left(e^{a} + e^{b}\right) \cdot \frac{1}{e^{a}}}} \]
      9. lift-exp.f64N/A

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot \frac{1}{\color{blue}{e^{a}}}} \]
      10. rec-expN/A

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot \color{blue}{e^{\mathsf{neg}\left(a\right)}}} \]
      11. lower-exp.f64N/A

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot \color{blue}{e^{\mathsf{neg}\left(a\right)}}} \]
      12. lower-neg.f6496.6

        \[\leadsto \frac{1}{\left(e^{a} + e^{b}\right) \cdot e^{\color{blue}{-a}}} \]
    4. Applied rewrites96.6%

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

      \[\leadsto \frac{1}{\color{blue}{e^{\mathsf{neg}\left(a\right)} \cdot \left(1 + e^{a}\right)}} \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{1}{e^{\mathsf{neg}\left(a\right)} \cdot \color{blue}{\left(e^{a} + 1\right)}} \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{1}{\color{blue}{e^{\mathsf{neg}\left(a\right)} \cdot e^{a} + e^{\mathsf{neg}\left(a\right)} \cdot 1}} \]
      3. exp-negN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{e^{a}}} \cdot e^{a} + e^{\mathsf{neg}\left(a\right)} \cdot 1} \]
      4. lft-mult-inverseN/A

        \[\leadsto \frac{1}{\color{blue}{1} + e^{\mathsf{neg}\left(a\right)} \cdot 1} \]
      5. *-rgt-identityN/A

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

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

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-1 \cdot a}}} \]
      8. lower-exp.f64N/A

        \[\leadsto \frac{1}{1 + \color{blue}{e^{-1 \cdot a}}} \]
      9. neg-mul-1N/A

        \[\leadsto \frac{1}{1 + e^{\color{blue}{\mathsf{neg}\left(a\right)}}} \]
      10. lower-neg.f6496.7

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-a}}} \]
    7. Applied rewrites96.7%

      \[\leadsto \frac{1}{\color{blue}{1 + e^{-a}}} \]

    if 0.0200000000000000004 < (exp.f64 a)

    1. Initial program 99.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
      2. lower-+.f64N/A

        \[\leadsto \frac{1}{\color{blue}{1 + e^{b}}} \]
      3. lower-exp.f6499.1

        \[\leadsto \frac{1}{1 + \color{blue}{e^{b}}} \]
    5. Applied rewrites99.1%

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.02:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 98.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.02:\\ \;\;\;\;\frac{e^{a}}{1 + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 0.02) (/ (exp a) (+ 1.0 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 0.02) {
		tmp = exp(a) / (1.0 + 1.0);
	} else {
		tmp = 1.0 / (exp(b) + 1.0);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (exp(a) <= 0.02d0) then
        tmp = exp(a) / (1.0d0 + 1.0d0)
    else
        tmp = 1.0d0 / (exp(b) + 1.0d0)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (Math.exp(a) <= 0.02) {
		tmp = Math.exp(a) / (1.0 + 1.0);
	} else {
		tmp = 1.0 / (Math.exp(b) + 1.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if math.exp(a) <= 0.02:
		tmp = math.exp(a) / (1.0 + 1.0)
	else:
		tmp = 1.0 / (math.exp(b) + 1.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (exp(a) <= 0.02)
		tmp = Float64(exp(a) / Float64(1.0 + 1.0));
	else
		tmp = Float64(1.0 / Float64(exp(b) + 1.0));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (exp(a) <= 0.02)
		tmp = exp(a) / (1.0 + 1.0);
	else
		tmp = 1.0 / (exp(b) + 1.0);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.02], N[(N[Exp[a], $MachinePrecision] / N[(1.0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.02:\\
\;\;\;\;\frac{e^{a}}{1 + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (exp.f64 a) < 0.0200000000000000004

    1. Initial program 96.5%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0

      \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{1}} \]
    4. Step-by-step derivation
      1. Applied rewrites96.6%

        \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{1}} \]
      2. Taylor expanded in a around 0

        \[\leadsto \frac{e^{a}}{\color{blue}{1} + 1} \]
      3. Step-by-step derivation
        1. Applied rewrites93.9%

          \[\leadsto \frac{e^{a}}{\color{blue}{1} + 1} \]

        if 0.0200000000000000004 < (exp.f64 a)

        1. Initial program 99.4%

          \[\frac{e^{a}}{e^{a} + e^{b}} \]
        2. Add Preprocessing
        3. Taylor expanded in a around 0

          \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
        4. Step-by-step derivation
          1. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
          2. lower-+.f64N/A

            \[\leadsto \frac{1}{\color{blue}{1 + e^{b}}} \]
          3. lower-exp.f6499.1

            \[\leadsto \frac{1}{1 + \color{blue}{e^{b}}} \]
        5. Applied rewrites99.1%

          \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
      4. Recombined 2 regimes into one program.
      5. Final simplification97.9%

        \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.02:\\ \;\;\;\;\frac{e^{a}}{1 + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
      6. Add Preprocessing

      Alternative 7: 81.1% accurate, 2.7× speedup?

      \[\begin{array}{l} \\ \frac{1}{e^{b} + 1} \end{array} \]
      (FPCore (a b) :precision binary64 (/ 1.0 (+ (exp b) 1.0)))
      double code(double a, double b) {
      	return 1.0 / (exp(b) + 1.0);
      }
      
      real(8) function code(a, b)
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          code = 1.0d0 / (exp(b) + 1.0d0)
      end function
      
      public static double code(double a, double b) {
      	return 1.0 / (Math.exp(b) + 1.0);
      }
      
      def code(a, b):
      	return 1.0 / (math.exp(b) + 1.0)
      
      function code(a, b)
      	return Float64(1.0 / Float64(exp(b) + 1.0))
      end
      
      function tmp = code(a, b)
      	tmp = 1.0 / (exp(b) + 1.0);
      end
      
      code[a_, b_] := N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{1}{e^{b} + 1}
      \end{array}
      
      Derivation
      1. Initial program 98.8%

        \[\frac{e^{a}}{e^{a} + e^{b}} \]
      2. Add Preprocessing
      3. Taylor expanded in a around 0

        \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
        2. lower-+.f64N/A

          \[\leadsto \frac{1}{\color{blue}{1 + e^{b}}} \]
        3. lower-exp.f6483.9

          \[\leadsto \frac{1}{1 + \color{blue}{e^{b}}} \]
      5. Applied rewrites83.9%

        \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
      6. Final simplification83.9%

        \[\leadsto \frac{1}{e^{b} + 1} \]
      7. Add Preprocessing

      Alternative 8: 43.5% accurate, 6.3× speedup?

      \[\begin{array}{l} \\ \frac{1}{1 + \mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.16666666666666666, 0.5\right), 1\right), 1\right)} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right) \end{array} \]
      (FPCore (a b)
       :precision binary64
       (*
        (/ 1.0 (+ 1.0 (fma a (fma a (fma a 0.16666666666666666 0.5) 1.0) 1.0)))
        (fma a (fma a 0.5 1.0) 1.0)))
      double code(double a, double b) {
      	return (1.0 / (1.0 + fma(a, fma(a, fma(a, 0.16666666666666666, 0.5), 1.0), 1.0))) * fma(a, fma(a, 0.5, 1.0), 1.0);
      }
      
      function code(a, b)
      	return Float64(Float64(1.0 / Float64(1.0 + fma(a, fma(a, fma(a, 0.16666666666666666, 0.5), 1.0), 1.0))) * fma(a, fma(a, 0.5, 1.0), 1.0))
      end
      
      code[a_, b_] := N[(N[(1.0 / N[(1.0 + N[(a * N[(a * N[(a * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * N[(a * 0.5 + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{1}{1 + \mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.16666666666666666, 0.5\right), 1\right), 1\right)} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right)
      \end{array}
      
      Derivation
      1. Initial program 98.8%

        \[\frac{e^{a}}{e^{a} + e^{b}} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-exp.f64N/A

          \[\leadsto \frac{\color{blue}{e^{a}}}{e^{a} + e^{b}} \]
        2. lift-exp.f64N/A

          \[\leadsto \frac{e^{a}}{\color{blue}{e^{a}} + e^{b}} \]
        3. lift-exp.f64N/A

          \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{e^{b}}} \]
        4. lift-+.f64N/A

          \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + e^{b}}} \]
        5. div-invN/A

          \[\leadsto \color{blue}{e^{a} \cdot \frac{1}{e^{a} + e^{b}}} \]
        6. lift-+.f64N/A

          \[\leadsto e^{a} \cdot \frac{1}{\color{blue}{e^{a} + e^{b}}} \]
        7. flip3-+N/A

          \[\leadsto e^{a} \cdot \frac{1}{\color{blue}{\frac{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}}{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}}} \]
        8. clear-numN/A

          \[\leadsto e^{a} \cdot \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}}} \]
        9. *-commutativeN/A

          \[\leadsto \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}} \cdot e^{a}} \]
        10. lower-*.f64N/A

          \[\leadsto \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}} \cdot e^{a}} \]
      4. Applied rewrites98.8%

        \[\leadsto \color{blue}{\frac{1}{e^{a} + e^{b}} \cdot e^{a}} \]
      5. Taylor expanded in b around 0

        \[\leadsto \frac{1}{e^{a} + \color{blue}{1}} \cdot e^{a} \]
      6. Step-by-step derivation
        1. Applied rewrites61.6%

          \[\leadsto \frac{1}{e^{a} + \color{blue}{1}} \cdot e^{a} \]
        2. Taylor expanded in a around 0

          \[\leadsto \frac{1}{e^{a} + 1} \cdot \color{blue}{\left(1 + a \cdot \left(1 + \frac{1}{2} \cdot a\right)\right)} \]
        3. Step-by-step derivation
          1. +-commutativeN/A

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

            \[\leadsto \frac{1}{e^{a} + 1} \cdot \color{blue}{\mathsf{fma}\left(a, 1 + \frac{1}{2} \cdot a, 1\right)} \]
          3. +-commutativeN/A

            \[\leadsto \frac{1}{e^{a} + 1} \cdot \mathsf{fma}\left(a, \color{blue}{\frac{1}{2} \cdot a + 1}, 1\right) \]
          4. *-commutativeN/A

            \[\leadsto \frac{1}{e^{a} + 1} \cdot \mathsf{fma}\left(a, \color{blue}{a \cdot \frac{1}{2}} + 1, 1\right) \]
          5. lower-fma.f6440.3

            \[\leadsto \frac{1}{e^{a} + 1} \cdot \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0.5, 1\right)}, 1\right) \]
        4. Applied rewrites40.3%

          \[\leadsto \frac{1}{e^{a} + 1} \cdot \color{blue}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right)} \]
        5. Taylor expanded in a around 0

          \[\leadsto \frac{1}{\color{blue}{\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
        6. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right) + 1\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
          2. lower-fma.f64N/A

            \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(a, 1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right), 1\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
          3. +-commutativeN/A

            \[\leadsto \frac{1}{\mathsf{fma}\left(a, \color{blue}{a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right) + 1}, 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
          4. lower-fma.f64N/A

            \[\leadsto \frac{1}{\mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, \frac{1}{2} + \frac{1}{6} \cdot a, 1\right)}, 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
          5. +-commutativeN/A

            \[\leadsto \frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \color{blue}{\frac{1}{6} \cdot a + \frac{1}{2}}, 1\right), 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
          6. *-commutativeN/A

            \[\leadsto \frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \color{blue}{a \cdot \frac{1}{6}} + \frac{1}{2}, 1\right), 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
          7. lower-fma.f6443.1

            \[\leadsto \frac{1}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0.16666666666666666, 0.5\right)}, 1\right), 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right) \]
        7. Applied rewrites43.1%

          \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.16666666666666666, 0.5\right), 1\right), 1\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right) \]
        8. Final simplification43.1%

          \[\leadsto \frac{1}{1 + \mathsf{fma}\left(a, \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.16666666666666666, 0.5\right), 1\right), 1\right)} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right) \]
        9. Add Preprocessing

        Alternative 9: 39.9% accurate, 7.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right)\\ t\_0 \cdot \frac{1}{1 + t\_0} \end{array} \end{array} \]
        (FPCore (a b)
         :precision binary64
         (let* ((t_0 (fma a (fma a 0.5 1.0) 1.0))) (* t_0 (/ 1.0 (+ 1.0 t_0)))))
        double code(double a, double b) {
        	double t_0 = fma(a, fma(a, 0.5, 1.0), 1.0);
        	return t_0 * (1.0 / (1.0 + t_0));
        }
        
        function code(a, b)
        	t_0 = fma(a, fma(a, 0.5, 1.0), 1.0)
        	return Float64(t_0 * Float64(1.0 / Float64(1.0 + t_0)))
        end
        
        code[a_, b_] := Block[{t$95$0 = N[(a * N[(a * 0.5 + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]}, N[(t$95$0 * N[(1.0 / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right)\\
        t\_0 \cdot \frac{1}{1 + t\_0}
        \end{array}
        \end{array}
        
        Derivation
        1. Initial program 98.8%

          \[\frac{e^{a}}{e^{a} + e^{b}} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-exp.f64N/A

            \[\leadsto \frac{\color{blue}{e^{a}}}{e^{a} + e^{b}} \]
          2. lift-exp.f64N/A

            \[\leadsto \frac{e^{a}}{\color{blue}{e^{a}} + e^{b}} \]
          3. lift-exp.f64N/A

            \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{e^{b}}} \]
          4. lift-+.f64N/A

            \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + e^{b}}} \]
          5. div-invN/A

            \[\leadsto \color{blue}{e^{a} \cdot \frac{1}{e^{a} + e^{b}}} \]
          6. lift-+.f64N/A

            \[\leadsto e^{a} \cdot \frac{1}{\color{blue}{e^{a} + e^{b}}} \]
          7. flip3-+N/A

            \[\leadsto e^{a} \cdot \frac{1}{\color{blue}{\frac{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}}{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}}} \]
          8. clear-numN/A

            \[\leadsto e^{a} \cdot \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}}} \]
          9. *-commutativeN/A

            \[\leadsto \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}} \cdot e^{a}} \]
          10. lower-*.f64N/A

            \[\leadsto \color{blue}{\frac{e^{a} \cdot e^{a} + \left(e^{b} \cdot e^{b} - e^{a} \cdot e^{b}\right)}{{\left(e^{a}\right)}^{3} + {\left(e^{b}\right)}^{3}} \cdot e^{a}} \]
        4. Applied rewrites98.8%

          \[\leadsto \color{blue}{\frac{1}{e^{a} + e^{b}} \cdot e^{a}} \]
        5. Taylor expanded in b around 0

          \[\leadsto \frac{1}{e^{a} + \color{blue}{1}} \cdot e^{a} \]
        6. Step-by-step derivation
          1. Applied rewrites61.6%

            \[\leadsto \frac{1}{e^{a} + \color{blue}{1}} \cdot e^{a} \]
          2. Taylor expanded in a around 0

            \[\leadsto \frac{1}{e^{a} + 1} \cdot \color{blue}{\left(1 + a \cdot \left(1 + \frac{1}{2} \cdot a\right)\right)} \]
          3. Step-by-step derivation
            1. +-commutativeN/A

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

              \[\leadsto \frac{1}{e^{a} + 1} \cdot \color{blue}{\mathsf{fma}\left(a, 1 + \frac{1}{2} \cdot a, 1\right)} \]
            3. +-commutativeN/A

              \[\leadsto \frac{1}{e^{a} + 1} \cdot \mathsf{fma}\left(a, \color{blue}{\frac{1}{2} \cdot a + 1}, 1\right) \]
            4. *-commutativeN/A

              \[\leadsto \frac{1}{e^{a} + 1} \cdot \mathsf{fma}\left(a, \color{blue}{a \cdot \frac{1}{2}} + 1, 1\right) \]
            5. lower-fma.f6440.3

              \[\leadsto \frac{1}{e^{a} + 1} \cdot \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0.5, 1\right)}, 1\right) \]
          4. Applied rewrites40.3%

            \[\leadsto \frac{1}{e^{a} + 1} \cdot \color{blue}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right)} \]
          5. Taylor expanded in a around 0

            \[\leadsto \frac{1}{\color{blue}{\left(1 + a \cdot \left(1 + \frac{1}{2} \cdot a\right)\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
          6. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \frac{1}{\color{blue}{\left(a \cdot \left(1 + \frac{1}{2} \cdot a\right) + 1\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
            2. lower-fma.f64N/A

              \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(a, 1 + \frac{1}{2} \cdot a, 1\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
            3. +-commutativeN/A

              \[\leadsto \frac{1}{\mathsf{fma}\left(a, \color{blue}{\frac{1}{2} \cdot a + 1}, 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
            4. *-commutativeN/A

              \[\leadsto \frac{1}{\mathsf{fma}\left(a, \color{blue}{a \cdot \frac{1}{2}} + 1, 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, \frac{1}{2}, 1\right), 1\right) \]
            5. lower-fma.f6441.2

              \[\leadsto \frac{1}{\mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0.5, 1\right)}, 1\right) + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right) \]
          7. Applied rewrites41.2%

            \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right)} + 1} \cdot \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right) \]
          8. Final simplification41.2%

            \[\leadsto \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right) \cdot \frac{1}{1 + \mathsf{fma}\left(a, \mathsf{fma}\left(a, 0.5, 1\right), 1\right)} \]
          9. Add Preprocessing

          Alternative 10: 39.3% accurate, 21.0× speedup?

          \[\begin{array}{l} \\ \frac{1}{1 + 1} \end{array} \]
          (FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 1.0)))
          double code(double a, double b) {
          	return 1.0 / (1.0 + 1.0);
          }
          
          real(8) function code(a, b)
              real(8), intent (in) :: a
              real(8), intent (in) :: b
              code = 1.0d0 / (1.0d0 + 1.0d0)
          end function
          
          public static double code(double a, double b) {
          	return 1.0 / (1.0 + 1.0);
          }
          
          def code(a, b):
          	return 1.0 / (1.0 + 1.0)
          
          function code(a, b)
          	return Float64(1.0 / Float64(1.0 + 1.0))
          end
          
          function tmp = code(a, b)
          	tmp = 1.0 / (1.0 + 1.0);
          end
          
          code[a_, b_] := N[(1.0 / N[(1.0 + 1.0), $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{1}{1 + 1}
          \end{array}
          
          Derivation
          1. Initial program 98.8%

            \[\frac{e^{a}}{e^{a} + e^{b}} \]
          2. Add Preprocessing
          3. Taylor expanded in b around 0

            \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{1}} \]
          4. Step-by-step derivation
            1. Applied rewrites61.6%

              \[\leadsto \frac{e^{a}}{e^{a} + \color{blue}{1}} \]
            2. Taylor expanded in a around 0

              \[\leadsto \frac{e^{a}}{\color{blue}{1} + 1} \]
            3. Step-by-step derivation
              1. Applied rewrites60.6%

                \[\leadsto \frac{e^{a}}{\color{blue}{1} + 1} \]
              2. Taylor expanded in a around 0

                \[\leadsto \frac{\color{blue}{1}}{1 + 1} \]
              3. Step-by-step derivation
                1. Applied rewrites40.3%

                  \[\leadsto \frac{\color{blue}{1}}{1 + 1} \]
                2. Add Preprocessing

                Developer Target 1: 100.0% accurate, 2.7× speedup?

                \[\begin{array}{l} \\ \frac{1}{1 + e^{b - a}} \end{array} \]
                (FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
                double code(double a, double b) {
                	return 1.0 / (1.0 + exp((b - a)));
                }
                
                real(8) function code(a, b)
                    real(8), intent (in) :: a
                    real(8), intent (in) :: b
                    code = 1.0d0 / (1.0d0 + exp((b - a)))
                end function
                
                public static double code(double a, double b) {
                	return 1.0 / (1.0 + Math.exp((b - a)));
                }
                
                def code(a, b):
                	return 1.0 / (1.0 + math.exp((b - a)))
                
                function code(a, b)
                	return Float64(1.0 / Float64(1.0 + exp(Float64(b - a))))
                end
                
                function tmp = code(a, b)
                	tmp = 1.0 / (1.0 + exp((b - a)));
                end
                
                code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
                
                \begin{array}{l}
                
                \\
                \frac{1}{1 + e^{b - a}}
                \end{array}
                

                Reproduce

                ?
                herbie shell --seed 2024212 
                (FPCore (a b)
                  :name "Quotient of sum of exps"
                  :precision binary64
                
                  :alt
                  (! :herbie-platform default (/ 1 (+ 1 (exp (- b a)))))
                
                  (/ (exp a) (+ (exp a) (exp b))))