Quotient of sum of exps

Percentage Accurate: 99.0% → 99.0%
Time: 7.1s
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: 99.0% 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, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e^{a}}{\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(Float64(1.0 / exp(Float64(-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[(N[(1.0 / N[Exp[(-a)], $MachinePrecision]), $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{a}}{\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. unpow1N/A

      \[\leadsto \frac{e^{a}}{\color{blue}{{\left(e^{a}\right)}^{1}} + e^{b}} \]
    2. metadata-evalN/A

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

      \[\leadsto \frac{e^{a}}{\color{blue}{{\left({\left(e^{a}\right)}^{-1}\right)}^{-1}} + e^{b}} \]
    4. inv-powN/A

      \[\leadsto \frac{e^{a}}{{\color{blue}{\left(\frac{1}{e^{a}}\right)}}^{-1} + e^{b}} \]
    5. unpow-1N/A

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

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

      \[\leadsto \frac{e^{a}}{\frac{1}{\frac{1}{\color{blue}{e^{a}}}} + e^{b}} \]
    8. rec-expN/A

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

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

      \[\leadsto \frac{e^{a}}{\frac{1}{e^{\color{blue}{-a}}} + e^{b}} \]
  4. Applied rewrites98.8%

    \[\leadsto \frac{e^{a}}{\color{blue}{\frac{1}{e^{-a}}} + e^{b}} \]
  5. Add Preprocessing

Alternative 2: 48.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0:\\ \;\;\;\;b \cdot \left(0.0625 \cdot \left(a \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.25, a, 0.5\right)\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.0)
   (* b (* 0.0625 (* a a)))
   (fma 0.25 a 0.5)))
double code(double a, double b) {
	double tmp;
	if ((exp(a) / (exp(a) + exp(b))) <= 0.0) {
		tmp = b * (0.0625 * (a * a));
	} else {
		tmp = fma(0.25, a, 0.5);
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.0)
		tmp = Float64(b * Float64(0.0625 * Float64(a * a)));
	else
		tmp = fma(0.25, a, 0.5);
	end
	return tmp
end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(b * N[(0.0625 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.25 * a + 0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0:\\
\;\;\;\;b \cdot \left(0.0625 \cdot \left(a \cdot a\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.25, a, 0.5\right)\\


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b \cdot e^{a}}{{\left(1 + e^{a}\right)}^{2}} + \frac{e^{a}}{1 + e^{a}}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot b}{1 + e^{a}} \cdot \frac{e^{a}}{1 + e^{a}}} + \frac{e^{a}}{1 + e^{a}} \]
      5. distribute-lft1-inN/A

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

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

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

      \[\leadsto \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \color{blue}{a \cdot \left(\left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) + a \cdot \left(\frac{1}{2} \cdot \left(\frac{-1}{8} \cdot b + \left(\frac{1}{8} \cdot b + \left(\frac{1}{4} \cdot b + \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right) - \left(\frac{1}{8} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)} \]
    7. Applied rewrites2.0%

      \[\leadsto \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0 - b \cdot -0.0625, 0.25\right)}, \mathsf{fma}\left(b, -0.25, 0.5\right)\right) \]
    8. Taylor expanded in a around inf

      \[\leadsto \frac{1}{16} \cdot \left({a}^{2} \cdot \color{blue}{b}\right) \]
    9. Step-by-step derivation
      1. Applied rewrites19.2%

        \[\leadsto b \cdot \left(0.0625 \cdot \color{blue}{\left(a \cdot a\right)}\right) \]

      if 0.0 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b)))

      1. Initial program 97.6%

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

        \[\leadsto \color{blue}{-1 \cdot \frac{b \cdot e^{a}}{{\left(1 + e^{a}\right)}^{2}} + \frac{e^{a}}{1 + e^{a}}} \]
      4. Step-by-step derivation
        1. associate-*r/N/A

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

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

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

          \[\leadsto \color{blue}{\frac{-1 \cdot b}{1 + e^{a}} \cdot \frac{e^{a}}{1 + e^{a}}} + \frac{e^{a}}{1 + e^{a}} \]
        5. distribute-lft1-inN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \color{blue}{a \cdot \left(\left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) + a \cdot \left(\frac{1}{2} \cdot \left(\frac{-1}{8} \cdot b + \left(\frac{1}{8} \cdot b + \left(\frac{1}{4} \cdot b + \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right) - \left(\frac{1}{8} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)} \]
      7. Applied rewrites63.9%

        \[\leadsto \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0 - b \cdot -0.0625, 0.25\right)}, \mathsf{fma}\left(b, -0.25, 0.5\right)\right) \]
      8. Taylor expanded in b around 0

        \[\leadsto \frac{1}{2} + \frac{1}{4} \cdot \color{blue}{a} \]
      9. Step-by-step derivation
        1. Applied rewrites67.3%

          \[\leadsto \mathsf{fma}\left(0.25, a, 0.5\right) \]
      10. Recombined 2 regimes into one program.
      11. Add Preprocessing

      Alternative 3: 99.0% 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 4: 98.6% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{e^{a}}{1 + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \end{array} \]
      (FPCore (a b)
       :precision binary64
       (if (<= (exp a) 0.0) (/ (exp a) (+ 1.0 1.0)) (/ 1.0 (+ 1.0 (exp b)))))
      double code(double a, double b) {
      	double tmp;
      	if (exp(a) <= 0.0) {
      		tmp = exp(a) / (1.0 + 1.0);
      	} else {
      		tmp = 1.0 / (1.0 + exp(b));
      	}
      	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.0d0) then
              tmp = exp(a) / (1.0d0 + 1.0d0)
          else
              tmp = 1.0d0 / (1.0d0 + exp(b))
          end if
          code = tmp
      end function
      
      public static double code(double a, double b) {
      	double tmp;
      	if (Math.exp(a) <= 0.0) {
      		tmp = Math.exp(a) / (1.0 + 1.0);
      	} else {
      		tmp = 1.0 / (1.0 + Math.exp(b));
      	}
      	return tmp;
      }
      
      def code(a, b):
      	tmp = 0
      	if math.exp(a) <= 0.0:
      		tmp = math.exp(a) / (1.0 + 1.0)
      	else:
      		tmp = 1.0 / (1.0 + math.exp(b))
      	return tmp
      
      function code(a, b)
      	tmp = 0.0
      	if (exp(a) <= 0.0)
      		tmp = Float64(exp(a) / Float64(1.0 + 1.0));
      	else
      		tmp = Float64(1.0 / Float64(1.0 + exp(b)));
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b)
      	tmp = 0.0;
      	if (exp(a) <= 0.0)
      		tmp = exp(a) / (1.0 + 1.0);
      	else
      		tmp = 1.0 / (1.0 + exp(b));
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / N[(1.0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;e^{a} \leq 0:\\
      \;\;\;\;\frac{e^{a}}{1 + 1}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{1}{1 + e^{b}}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (exp.f64 a) < 0.0

        1. Initial program 100.0%

          \[\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 rewrites100.0%

            \[\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 rewrites100.0%

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

            if 0.0 < (exp.f64 a)

            1. Initial program 98.3%

              \[\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.f6497.8

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

              \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
          4. Recombined 2 regimes into one program.
          5. Add Preprocessing

          Alternative 5: 82.3% accurate, 2.5× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{1 + e^{b}}\\ \mathbf{if}\;a \leq -3.5 \cdot 10^{+203}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;a \leq -8.6 \cdot 10^{+141}:\\ \;\;\;\;-0.0020833333333333333 \cdot {b}^{5}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (a b)
           :precision binary64
           (let* ((t_0 (/ 1.0 (+ 1.0 (exp b)))))
             (if (<= a -3.5e+203)
               t_0
               (if (<= a -8.6e+141) (* -0.0020833333333333333 (pow b 5.0)) t_0))))
          double code(double a, double b) {
          	double t_0 = 1.0 / (1.0 + exp(b));
          	double tmp;
          	if (a <= -3.5e+203) {
          		tmp = t_0;
          	} else if (a <= -8.6e+141) {
          		tmp = -0.0020833333333333333 * pow(b, 5.0);
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          real(8) function code(a, b)
              real(8), intent (in) :: a
              real(8), intent (in) :: b
              real(8) :: t_0
              real(8) :: tmp
              t_0 = 1.0d0 / (1.0d0 + exp(b))
              if (a <= (-3.5d+203)) then
                  tmp = t_0
              else if (a <= (-8.6d+141)) then
                  tmp = (-0.0020833333333333333d0) * (b ** 5.0d0)
              else
                  tmp = t_0
              end if
              code = tmp
          end function
          
          public static double code(double a, double b) {
          	double t_0 = 1.0 / (1.0 + Math.exp(b));
          	double tmp;
          	if (a <= -3.5e+203) {
          		tmp = t_0;
          	} else if (a <= -8.6e+141) {
          		tmp = -0.0020833333333333333 * Math.pow(b, 5.0);
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          def code(a, b):
          	t_0 = 1.0 / (1.0 + math.exp(b))
          	tmp = 0
          	if a <= -3.5e+203:
          		tmp = t_0
          	elif a <= -8.6e+141:
          		tmp = -0.0020833333333333333 * math.pow(b, 5.0)
          	else:
          		tmp = t_0
          	return tmp
          
          function code(a, b)
          	t_0 = Float64(1.0 / Float64(1.0 + exp(b)))
          	tmp = 0.0
          	if (a <= -3.5e+203)
          		tmp = t_0;
          	elseif (a <= -8.6e+141)
          		tmp = Float64(-0.0020833333333333333 * (b ^ 5.0));
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          function tmp_2 = code(a, b)
          	t_0 = 1.0 / (1.0 + exp(b));
          	tmp = 0.0;
          	if (a <= -3.5e+203)
          		tmp = t_0;
          	elseif (a <= -8.6e+141)
          		tmp = -0.0020833333333333333 * (b ^ 5.0);
          	else
          		tmp = t_0;
          	end
          	tmp_2 = tmp;
          end
          
          code[a_, b_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -3.5e+203], t$95$0, If[LessEqual[a, -8.6e+141], N[(-0.0020833333333333333 * N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision], t$95$0]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := \frac{1}{1 + e^{b}}\\
          \mathbf{if}\;a \leq -3.5 \cdot 10^{+203}:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;a \leq -8.6 \cdot 10^{+141}:\\
          \;\;\;\;-0.0020833333333333333 \cdot {b}^{5}\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if a < -3.50000000000000031e203 or -8.5999999999999997e141 < a

            1. Initial program 98.7%

              \[\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.f6487.3

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

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

            if -3.50000000000000031e203 < a < -8.5999999999999997e141

            1. Initial program 100.0%

              \[\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.f6428.6

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(b, \color{blue}{\mathsf{fma}\left(b \cdot b, \mathsf{fma}\left(b, b \cdot -0.0020833333333333333, 0.020833333333333332\right), -0.25\right)}, 0.5\right) \]
                2. Taylor expanded in b around inf

                  \[\leadsto \frac{-1}{480} \cdot {b}^{\color{blue}{5}} \]
                3. Step-by-step derivation
                  1. Applied rewrites74.1%

                    \[\leadsto -0.0020833333333333333 \cdot {b}^{\color{blue}{5}} \]
                4. Recombined 2 regimes into one program.
                5. Add Preprocessing

                Alternative 6: 59.2% accurate, 2.8× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -8.6 \cdot 10^{+141}:\\ \;\;\;\;-0.0020833333333333333 \cdot {b}^{5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right), 2\right)}\\ \end{array} \end{array} \]
                (FPCore (a b)
                 :precision binary64
                 (if (<= a -8.6e+141)
                   (* -0.0020833333333333333 (pow b 5.0))
                   (/ 1.0 (fma b (fma b (fma b 0.16666666666666666 0.5) 1.0) 2.0))))
                double code(double a, double b) {
                	double tmp;
                	if (a <= -8.6e+141) {
                		tmp = -0.0020833333333333333 * pow(b, 5.0);
                	} else {
                		tmp = 1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0);
                	}
                	return tmp;
                }
                
                function code(a, b)
                	tmp = 0.0
                	if (a <= -8.6e+141)
                		tmp = Float64(-0.0020833333333333333 * (b ^ 5.0));
                	else
                		tmp = Float64(1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0));
                	end
                	return tmp
                end
                
                code[a_, b_] := If[LessEqual[a, -8.6e+141], N[(-0.0020833333333333333 * N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;a \leq -8.6 \cdot 10^{+141}:\\
                \;\;\;\;-0.0020833333333333333 \cdot {b}^{5}\\
                
                \mathbf{else}:\\
                \;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right), 2\right)}\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if a < -8.5999999999999997e141

                  1. Initial program 100.0%

                    \[\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.f6446.0

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

                    \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
                  6. Step-by-step derivation
                    1. Applied rewrites46.0%

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

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

                        \[\leadsto \mathsf{fma}\left(b, \color{blue}{\mathsf{fma}\left(b \cdot b, \mathsf{fma}\left(b, b \cdot -0.0020833333333333333, 0.020833333333333332\right), -0.25\right)}, 0.5\right) \]
                      2. Taylor expanded in b around inf

                        \[\leadsto \frac{-1}{480} \cdot {b}^{\color{blue}{5}} \]
                      3. Step-by-step derivation
                        1. Applied rewrites50.5%

                          \[\leadsto -0.0020833333333333333 \cdot {b}^{\color{blue}{5}} \]

                        if -8.5999999999999997e141 < a

                        1. Initial program 98.5%

                          \[\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.f6492.4

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

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

                          \[\leadsto \frac{1}{2 + \color{blue}{b \cdot \left(1 + b \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot b\right)\right)}} \]
                        7. Step-by-step derivation
                          1. Applied rewrites59.8%

                            \[\leadsto \frac{1}{\mathsf{fma}\left(b, \color{blue}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right)}, 2\right)} \]
                        8. Recombined 2 regimes into one program.
                        9. Add Preprocessing

                        Alternative 7: 60.1% accurate, 7.5× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 60000000000:\\ \;\;\;\;\mathsf{fma}\left(0.25, a, 0.5\right)\\ \mathbf{elif}\;b \leq 3.75 \cdot 10^{+102}:\\ \;\;\;\;b \cdot \left(0.0625 \cdot \left(a \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right), 2\right)}\\ \end{array} \end{array} \]
                        (FPCore (a b)
                         :precision binary64
                         (if (<= b 60000000000.0)
                           (fma 0.25 a 0.5)
                           (if (<= b 3.75e+102)
                             (* b (* 0.0625 (* a a)))
                             (/ 1.0 (fma b (fma b (fma b 0.16666666666666666 0.5) 1.0) 2.0)))))
                        double code(double a, double b) {
                        	double tmp;
                        	if (b <= 60000000000.0) {
                        		tmp = fma(0.25, a, 0.5);
                        	} else if (b <= 3.75e+102) {
                        		tmp = b * (0.0625 * (a * a));
                        	} else {
                        		tmp = 1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0);
                        	}
                        	return tmp;
                        }
                        
                        function code(a, b)
                        	tmp = 0.0
                        	if (b <= 60000000000.0)
                        		tmp = fma(0.25, a, 0.5);
                        	elseif (b <= 3.75e+102)
                        		tmp = Float64(b * Float64(0.0625 * Float64(a * a)));
                        	else
                        		tmp = Float64(1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0));
                        	end
                        	return tmp
                        end
                        
                        code[a_, b_] := If[LessEqual[b, 60000000000.0], N[(0.25 * a + 0.5), $MachinePrecision], If[LessEqual[b, 3.75e+102], N[(b * N[(0.0625 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;b \leq 60000000000:\\
                        \;\;\;\;\mathsf{fma}\left(0.25, a, 0.5\right)\\
                        
                        \mathbf{elif}\;b \leq 3.75 \cdot 10^{+102}:\\
                        \;\;\;\;b \cdot \left(0.0625 \cdot \left(a \cdot a\right)\right)\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right), 2\right)}\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 3 regimes
                        2. if b < 6e10

                          1. Initial program 98.2%

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

                            \[\leadsto \color{blue}{-1 \cdot \frac{b \cdot e^{a}}{{\left(1 + e^{a}\right)}^{2}} + \frac{e^{a}}{1 + e^{a}}} \]
                          4. Step-by-step derivation
                            1. associate-*r/N/A

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

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

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

                              \[\leadsto \color{blue}{\frac{-1 \cdot b}{1 + e^{a}} \cdot \frac{e^{a}}{1 + e^{a}}} + \frac{e^{a}}{1 + e^{a}} \]
                            5. distribute-lft1-inN/A

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

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

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

                            \[\leadsto \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \color{blue}{a \cdot \left(\left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) + a \cdot \left(\frac{1}{2} \cdot \left(\frac{-1}{8} \cdot b + \left(\frac{1}{8} \cdot b + \left(\frac{1}{4} \cdot b + \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right) - \left(\frac{1}{8} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)} \]
                          7. Applied rewrites48.2%

                            \[\leadsto \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0 - b \cdot -0.0625, 0.25\right)}, \mathsf{fma}\left(b, -0.25, 0.5\right)\right) \]
                          8. Taylor expanded in b around 0

                            \[\leadsto \frac{1}{2} + \frac{1}{4} \cdot \color{blue}{a} \]
                          9. Step-by-step derivation
                            1. Applied rewrites50.7%

                              \[\leadsto \mathsf{fma}\left(0.25, a, 0.5\right) \]

                            if 6e10 < b < 3.75e102

                            1. Initial program 100.0%

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

                              \[\leadsto \color{blue}{-1 \cdot \frac{b \cdot e^{a}}{{\left(1 + e^{a}\right)}^{2}} + \frac{e^{a}}{1 + e^{a}}} \]
                            4. Step-by-step derivation
                              1. associate-*r/N/A

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

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

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

                                \[\leadsto \color{blue}{\frac{-1 \cdot b}{1 + e^{a}} \cdot \frac{e^{a}}{1 + e^{a}}} + \frac{e^{a}}{1 + e^{a}} \]
                              5. distribute-lft1-inN/A

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

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

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

                              \[\leadsto \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \color{blue}{a \cdot \left(\left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) + a \cdot \left(\frac{1}{2} \cdot \left(\frac{-1}{8} \cdot b + \left(\frac{1}{8} \cdot b + \left(\frac{1}{4} \cdot b + \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right) - \left(\frac{1}{8} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)} \]
                            7. Applied rewrites2.5%

                              \[\leadsto \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0 - b \cdot -0.0625, 0.25\right)}, \mathsf{fma}\left(b, -0.25, 0.5\right)\right) \]
                            8. Taylor expanded in a around inf

                              \[\leadsto \frac{1}{16} \cdot \left({a}^{2} \cdot \color{blue}{b}\right) \]
                            9. Step-by-step derivation
                              1. Applied rewrites31.7%

                                \[\leadsto b \cdot \left(0.0625 \cdot \color{blue}{\left(a \cdot a\right)}\right) \]

                              if 3.75e102 < b

                              1. Initial program 100.0%

                                \[\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.f64100.0

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

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

                                \[\leadsto \frac{1}{2 + \color{blue}{b \cdot \left(1 + b \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot b\right)\right)}} \]
                              7. Step-by-step derivation
                                1. Applied rewrites98.5%

                                  \[\leadsto \frac{1}{\mathsf{fma}\left(b, \color{blue}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right)}, 2\right)} \]
                              8. Recombined 3 regimes into one program.
                              9. Add Preprocessing

                              Alternative 8: 57.2% accurate, 8.7× speedup?

                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 60000000000:\\ \;\;\;\;\mathsf{fma}\left(0.25, a, 0.5\right)\\ \mathbf{elif}\;b \leq 1.05 \cdot 10^{+153}:\\ \;\;\;\;b \cdot \left(0.0625 \cdot \left(a \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.5, 1\right), 2\right)}\\ \end{array} \end{array} \]
                              (FPCore (a b)
                               :precision binary64
                               (if (<= b 60000000000.0)
                                 (fma 0.25 a 0.5)
                                 (if (<= b 1.05e+153)
                                   (* b (* 0.0625 (* a a)))
                                   (/ 1.0 (fma b (fma b 0.5 1.0) 2.0)))))
                              double code(double a, double b) {
                              	double tmp;
                              	if (b <= 60000000000.0) {
                              		tmp = fma(0.25, a, 0.5);
                              	} else if (b <= 1.05e+153) {
                              		tmp = b * (0.0625 * (a * a));
                              	} else {
                              		tmp = 1.0 / fma(b, fma(b, 0.5, 1.0), 2.0);
                              	}
                              	return tmp;
                              }
                              
                              function code(a, b)
                              	tmp = 0.0
                              	if (b <= 60000000000.0)
                              		tmp = fma(0.25, a, 0.5);
                              	elseif (b <= 1.05e+153)
                              		tmp = Float64(b * Float64(0.0625 * Float64(a * a)));
                              	else
                              		tmp = Float64(1.0 / fma(b, fma(b, 0.5, 1.0), 2.0));
                              	end
                              	return tmp
                              end
                              
                              code[a_, b_] := If[LessEqual[b, 60000000000.0], N[(0.25 * a + 0.5), $MachinePrecision], If[LessEqual[b, 1.05e+153], N[(b * N[(0.0625 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(b * N[(b * 0.5 + 1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]]
                              
                              \begin{array}{l}
                              
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;b \leq 60000000000:\\
                              \;\;\;\;\mathsf{fma}\left(0.25, a, 0.5\right)\\
                              
                              \mathbf{elif}\;b \leq 1.05 \cdot 10^{+153}:\\
                              \;\;\;\;b \cdot \left(0.0625 \cdot \left(a \cdot a\right)\right)\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.5, 1\right), 2\right)}\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 3 regimes
                              2. if b < 6e10

                                1. Initial program 98.2%

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

                                  \[\leadsto \color{blue}{-1 \cdot \frac{b \cdot e^{a}}{{\left(1 + e^{a}\right)}^{2}} + \frac{e^{a}}{1 + e^{a}}} \]
                                4. Step-by-step derivation
                                  1. associate-*r/N/A

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

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

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

                                    \[\leadsto \color{blue}{\frac{-1 \cdot b}{1 + e^{a}} \cdot \frac{e^{a}}{1 + e^{a}}} + \frac{e^{a}}{1 + e^{a}} \]
                                  5. distribute-lft1-inN/A

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

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

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

                                  \[\leadsto \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \color{blue}{a \cdot \left(\left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) + a \cdot \left(\frac{1}{2} \cdot \left(\frac{-1}{8} \cdot b + \left(\frac{1}{8} \cdot b + \left(\frac{1}{4} \cdot b + \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right) - \left(\frac{1}{8} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)} \]
                                7. Applied rewrites48.2%

                                  \[\leadsto \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0 - b \cdot -0.0625, 0.25\right)}, \mathsf{fma}\left(b, -0.25, 0.5\right)\right) \]
                                8. Taylor expanded in b around 0

                                  \[\leadsto \frac{1}{2} + \frac{1}{4} \cdot \color{blue}{a} \]
                                9. Step-by-step derivation
                                  1. Applied rewrites50.7%

                                    \[\leadsto \mathsf{fma}\left(0.25, a, 0.5\right) \]

                                  if 6e10 < b < 1.05000000000000008e153

                                  1. Initial program 100.0%

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

                                    \[\leadsto \color{blue}{-1 \cdot \frac{b \cdot e^{a}}{{\left(1 + e^{a}\right)}^{2}} + \frac{e^{a}}{1 + e^{a}}} \]
                                  4. Step-by-step derivation
                                    1. associate-*r/N/A

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

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

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

                                      \[\leadsto \color{blue}{\frac{-1 \cdot b}{1 + e^{a}} \cdot \frac{e^{a}}{1 + e^{a}}} + \frac{e^{a}}{1 + e^{a}} \]
                                    5. distribute-lft1-inN/A

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

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

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

                                    \[\leadsto \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \color{blue}{a \cdot \left(\left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) + a \cdot \left(\frac{1}{2} \cdot \left(\frac{-1}{8} \cdot b + \left(\frac{1}{8} \cdot b + \left(\frac{1}{4} \cdot b + \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right) - \left(\frac{1}{8} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)} \]
                                  7. Applied rewrites2.3%

                                    \[\leadsto \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0 - b \cdot -0.0625, 0.25\right)}, \mathsf{fma}\left(b, -0.25, 0.5\right)\right) \]
                                  8. Taylor expanded in a around inf

                                    \[\leadsto \frac{1}{16} \cdot \left({a}^{2} \cdot \color{blue}{b}\right) \]
                                  9. Step-by-step derivation
                                    1. Applied rewrites27.6%

                                      \[\leadsto b \cdot \left(0.0625 \cdot \color{blue}{\left(a \cdot a\right)}\right) \]

                                    if 1.05000000000000008e153 < b

                                    1. Initial program 100.0%

                                      \[\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.f64100.0

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

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

                                      \[\leadsto \frac{1}{2 + \color{blue}{b \cdot \left(1 + \frac{1}{2} \cdot b\right)}} \]
                                    7. Step-by-step derivation
                                      1. Applied rewrites97.6%

                                        \[\leadsto \frac{1}{\mathsf{fma}\left(b, \color{blue}{\mathsf{fma}\left(b, 0.5, 1\right)}, 2\right)} \]
                                    8. Recombined 3 regimes into one program.
                                    9. Add Preprocessing

                                    Alternative 9: 40.2% accurate, 45.0× speedup?

                                    \[\begin{array}{l} \\ \mathsf{fma}\left(0.25, a, 0.5\right) \end{array} \]
                                    (FPCore (a b) :precision binary64 (fma 0.25 a 0.5))
                                    double code(double a, double b) {
                                    	return fma(0.25, a, 0.5);
                                    }
                                    
                                    function code(a, b)
                                    	return fma(0.25, a, 0.5)
                                    end
                                    
                                    code[a_, b_] := N[(0.25 * a + 0.5), $MachinePrecision]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \mathsf{fma}\left(0.25, a, 0.5\right)
                                    \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 \color{blue}{-1 \cdot \frac{b \cdot e^{a}}{{\left(1 + e^{a}\right)}^{2}} + \frac{e^{a}}{1 + e^{a}}} \]
                                    4. Step-by-step derivation
                                      1. associate-*r/N/A

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

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

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

                                        \[\leadsto \color{blue}{\frac{-1 \cdot b}{1 + e^{a}} \cdot \frac{e^{a}}{1 + e^{a}}} + \frac{e^{a}}{1 + e^{a}} \]
                                      5. distribute-lft1-inN/A

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

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

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

                                      \[\leadsto \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \color{blue}{a \cdot \left(\left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) + a \cdot \left(\frac{1}{2} \cdot \left(\frac{-1}{8} \cdot b + \left(\frac{1}{8} \cdot b + \left(\frac{1}{4} \cdot b + \frac{1}{2} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right) - \left(\frac{1}{8} \cdot \left(1 + \frac{-1}{2} \cdot b\right) + \frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left(1 + \left(\frac{-1}{2} \cdot b + \frac{1}{4} \cdot b\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)\right)\right)\right) - \frac{1}{4} \cdot \left(1 + \frac{-1}{2} \cdot b\right)\right)} \]
                                    7. Applied rewrites33.2%

                                      \[\leadsto \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(a, 0 - b \cdot -0.0625, 0.25\right)}, \mathsf{fma}\left(b, -0.25, 0.5\right)\right) \]
                                    8. Taylor expanded in b around 0

                                      \[\leadsto \frac{1}{2} + \frac{1}{4} \cdot \color{blue}{a} \]
                                    9. Step-by-step derivation
                                      1. Applied rewrites35.2%

                                        \[\leadsto \mathsf{fma}\left(0.25, a, 0.5\right) \]
                                      2. Add Preprocessing

                                      Alternative 10: 40.1% accurate, 315.0× speedup?

                                      \[\begin{array}{l} \\ 0.5 \end{array} \]
                                      (FPCore (a b) :precision binary64 0.5)
                                      double code(double a, double b) {
                                      	return 0.5;
                                      }
                                      
                                      real(8) function code(a, b)
                                          real(8), intent (in) :: a
                                          real(8), intent (in) :: b
                                          code = 0.5d0
                                      end function
                                      
                                      public static double code(double a, double b) {
                                      	return 0.5;
                                      }
                                      
                                      def code(a, b):
                                      	return 0.5
                                      
                                      function code(a, b)
                                      	return 0.5
                                      end
                                      
                                      function tmp = code(a, b)
                                      	tmp = 0.5;
                                      end
                                      
                                      code[a_, b_] := 0.5
                                      
                                      \begin{array}{l}
                                      
                                      \\
                                      0.5
                                      \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.0

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

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

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

                                          \[\leadsto 0.5 \]
                                        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 2024231 
                                        (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))))