Quotient of sum of exps

Percentage Accurate: 98.6% → 97.8%
Time: 5.7s
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.6% 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: 97.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.9999999999999:\\ \;\;\;\;\frac{e^{a}}{1 + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 0.9999999999999)
   (/ (exp a) (+ 1.0 (fma (fma (fma 0.16666666666666666 a 0.5) a 1.0) a 1.0)))
   (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 0.9999999999999) {
		tmp = exp(a) / (1.0 + fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0));
	} else {
		tmp = 1.0 / (1.0 + exp(b));
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (exp(a) <= 0.9999999999999)
		tmp = Float64(exp(a) / Float64(1.0 + fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0)));
	else
		tmp = Float64(1.0 / Float64(1.0 + exp(b)));
	end
	return tmp
end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.9999999999999], N[(N[Exp[a], $MachinePrecision] / N[(1.0 + N[(N[(N[(0.16666666666666666 * a + 0.5), $MachinePrecision] * a + 1.0), $MachinePrecision] * a + 1.0), $MachinePrecision]), $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.9999999999999:\\
\;\;\;\;\frac{e^{a}}{1 + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)}\\

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


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

    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}{\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)} + 1} \]
      3. Step-by-step derivation
        1. +-commutativeN/A

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

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

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

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

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

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

          \[\leadsto \frac{e^{a}}{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{1}{6} \cdot a + \frac{1}{2}}, a, 1\right), a, 1\right) + 1} \]
        8. lower-fma.f64100.0

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

        \[\leadsto \frac{e^{a}}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)} + 1} \]

      if 0.999999999999899969 < (exp.f64 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. +-commutativeN/A

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

          \[\leadsto \frac{1}{\color{blue}{e^{b} + 1}} \]
        4. lower-exp.f6498.8

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.9999999999999:\\ \;\;\;\;\frac{e^{a}}{1 + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
    7. Add Preprocessing

    Alternative 2: 98.6% accurate, 1.0× speedup?

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

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

      \[\leadsto \frac{e^{a}}{e^{b} + e^{a}} \]
    4. Add Preprocessing

    Alternative 3: 97.6% accurate, 1.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.999999999995:\\ \;\;\;\;\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.999999999995)
       (/ (exp a) (+ 1.0 1.0))
       (/ 1.0 (+ 1.0 (exp b)))))
    double code(double a, double b) {
    	double tmp;
    	if (exp(a) <= 0.999999999995) {
    		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.999999999995d0) 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.999999999995) {
    		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.999999999995:
    		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.999999999995)
    		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.999999999995)
    		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.999999999995], 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.999999999995:\\
    \;\;\;\;\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.999999999995

      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 rewrites99.6%

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

          if 0.999999999995 < (exp.f64 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. +-commutativeN/A

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

              \[\leadsto \frac{1}{\color{blue}{e^{b} + 1}} \]
            4. lower-exp.f6498.8

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

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

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

        Alternative 4: 92.7% accurate, 2.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -2.8 \cdot 10^{+94}:\\ \;\;\;\;\frac{1}{1 + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \end{array} \]
        (FPCore (a b)
         :precision binary64
         (if (<= a -2.8e+94)
           (/ 1.0 (+ 1.0 (fma (fma (fma 0.16666666666666666 a 0.5) a 1.0) a 1.0)))
           (/ 1.0 (+ 1.0 (exp b)))))
        double code(double a, double b) {
        	double tmp;
        	if (a <= -2.8e+94) {
        		tmp = 1.0 / (1.0 + fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0));
        	} else {
        		tmp = 1.0 / (1.0 + exp(b));
        	}
        	return tmp;
        }
        
        function code(a, b)
        	tmp = 0.0
        	if (a <= -2.8e+94)
        		tmp = Float64(1.0 / Float64(1.0 + fma(fma(fma(0.16666666666666666, a, 0.5), a, 1.0), a, 1.0)));
        	else
        		tmp = Float64(1.0 / Float64(1.0 + exp(b)));
        	end
        	return tmp
        end
        
        code[a_, b_] := If[LessEqual[a, -2.8e+94], N[(1.0 / N[(1.0 + N[(N[(N[(0.16666666666666666 * a + 0.5), $MachinePrecision] * a + 1.0), $MachinePrecision] * a + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;a \leq -2.8 \cdot 10^{+94}:\\
        \;\;\;\;\frac{1}{1 + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)}\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{1}{1 + e^{b}}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if a < -2.79999999999999998e94

          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}{\left(1 + a \cdot \left(1 + a \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot a\right)\right)\right)} + 1} \]
            3. Step-by-step derivation
              1. +-commutativeN/A

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

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

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

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

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

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

                \[\leadsto \frac{e^{a}}{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{1}{6} \cdot a + \frac{1}{2}}, a, 1\right), a, 1\right) + 1} \]
              8. lower-fma.f64100.0

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

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

              \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, a, \frac{1}{2}\right), a, 1\right), a, 1\right) + 1} \]
            6. Step-by-step derivation
              1. Applied rewrites95.6%

                \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right) + 1} \]

              if -2.79999999999999998e94 < a

              1. Initial program 98.6%

                \[\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. +-commutativeN/A

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

                  \[\leadsto \frac{1}{\color{blue}{e^{b} + 1}} \]
                4. lower-exp.f6494.7

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

                \[\leadsto \color{blue}{\frac{1}{e^{b} + 1}} \]
            7. Recombined 2 regimes into one program.
            8. Final simplification94.8%

              \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -2.8 \cdot 10^{+94}:\\ \;\;\;\;\frac{1}{1 + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
            9. Add Preprocessing

            Alternative 5: 69.8% accurate, 8.1× speedup?

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

              1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

                    \[\leadsto \frac{e^{a}}{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{1}{6} \cdot a + \frac{1}{2}}, a, 1\right), a, 1\right) + 1} \]
                  8. lower-fma.f6467.9

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

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

                  \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, a, \frac{1}{2}\right), a, 1\right), a, 1\right) + 1} \]
                6. Step-by-step derivation
                  1. Applied rewrites61.6%

                    \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right) + 1} \]

                  if 2.3000000000000001e101 < 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. +-commutativeN/A

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

                      \[\leadsto \frac{1}{\color{blue}{e^{b} + 1}} \]
                    4. lower-exp.f64100.0

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

                    \[\leadsto \color{blue}{\frac{1}{e^{b} + 1}} \]
                  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 rewrites94.6%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 2.3 \cdot 10^{+101}:\\ \;\;\;\;\frac{1}{1 + \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 2\right)}\\ \end{array} \]
                  10. Add Preprocessing

                  Alternative 6: 66.2% accurate, 8.7× speedup?

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

                    1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

                          \[\leadsto \frac{e^{a}}{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{1}{6} \cdot a + \frac{1}{2}}, a, 1\right), a, 1\right) + 1} \]
                        8. lower-fma.f6469.4

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

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

                        \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, a, \frac{1}{2}\right), a, 1\right), a, 1\right) + 1} \]
                      6. Step-by-step derivation
                        1. Applied rewrites63.7%

                          \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right) + 1} \]
                        2. 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} \]
                        3. 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} \]
                          2. *-commutativeN/A

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

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

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

                            \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(0.5, a, 1\right)}, a, 1\right) + 1} \]
                        4. Applied rewrites61.5%

                          \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, a, 1\right), a, 1\right)} + 1} \]

                        if 7.49999999999999939e69 < 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. +-commutativeN/A

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

                            \[\leadsto \frac{1}{\color{blue}{e^{b} + 1}} \]
                          4. lower-exp.f64100.0

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

                          \[\leadsto \color{blue}{\frac{1}{e^{b} + 1}} \]
                        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 rewrites72.1%

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

                        Alternative 7: 63.1% accurate, 9.5× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 7.6 \cdot 10^{+145}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, a, 1\right), a, 1\right) + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(b \cdot b\right) \cdot 0.5}\\ \end{array} \end{array} \]
                        (FPCore (a b)
                         :precision binary64
                         (if (<= b 7.6e+145)
                           (/ 1.0 (+ (fma (fma 0.5 a 1.0) a 1.0) 1.0))
                           (/ 1.0 (* (* b b) 0.5))))
                        double code(double a, double b) {
                        	double tmp;
                        	if (b <= 7.6e+145) {
                        		tmp = 1.0 / (fma(fma(0.5, a, 1.0), a, 1.0) + 1.0);
                        	} else {
                        		tmp = 1.0 / ((b * b) * 0.5);
                        	}
                        	return tmp;
                        }
                        
                        function code(a, b)
                        	tmp = 0.0
                        	if (b <= 7.6e+145)
                        		tmp = Float64(1.0 / Float64(fma(fma(0.5, a, 1.0), a, 1.0) + 1.0));
                        	else
                        		tmp = Float64(1.0 / Float64(Float64(b * b) * 0.5));
                        	end
                        	return tmp
                        end
                        
                        code[a_, b_] := If[LessEqual[b, 7.6e+145], N[(1.0 / N[(N[(N[(0.5 * a + 1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;b \leq 7.6 \cdot 10^{+145}:\\
                        \;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, a, 1\right), a, 1\right) + 1}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\frac{1}{\left(b \cdot b\right) \cdot 0.5}\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if b < 7.60000000000000025e145

                          1. Initial program 98.7%

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, a, \frac{1}{2}\right), a, 1\right), a, 1\right) + 1} \]
                            6. Step-by-step derivation
                              1. Applied rewrites59.3%

                                \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, a, 0.5\right), a, 1\right), a, 1\right) + 1} \]
                              2. 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} \]
                              3. 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} \]
                                2. *-commutativeN/A

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

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

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

                                  \[\leadsto \frac{1}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(0.5, a, 1\right)}, a, 1\right) + 1} \]
                              4. Applied rewrites56.5%

                                \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, a, 1\right), a, 1\right)} + 1} \]

                              if 7.60000000000000025e145 < 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. +-commutativeN/A

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

                                  \[\leadsto \frac{1}{\color{blue}{e^{b} + 1}} \]
                                4. lower-exp.f64100.0

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

                                \[\leadsto \color{blue}{\frac{1}{e^{b} + 1}} \]
                              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 rewrites84.1%

                                  \[\leadsto \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), \color{blue}{b}, 2\right)} \]
                                2. Taylor expanded in b around inf

                                  \[\leadsto \frac{1}{\frac{1}{2} \cdot {b}^{\color{blue}{2}}} \]
                                3. Step-by-step derivation
                                  1. Applied rewrites91.6%

                                    \[\leadsto \frac{1}{\left(b \cdot b\right) \cdot 0.5} \]
                                4. Recombined 2 regimes into one program.
                                5. Add Preprocessing

                                Alternative 8: 52.5% accurate, 11.2× speedup?

                                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 3.9 \cdot 10^{+48}:\\ \;\;\;\;\frac{1}{\left(1 + a\right) + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(b \cdot b\right) \cdot 0.5}\\ \end{array} \end{array} \]
                                (FPCore (a b)
                                 :precision binary64
                                 (if (<= b 3.9e+48) (/ 1.0 (+ (+ 1.0 a) 1.0)) (/ 1.0 (* (* b b) 0.5))))
                                double code(double a, double b) {
                                	double tmp;
                                	if (b <= 3.9e+48) {
                                		tmp = 1.0 / ((1.0 + a) + 1.0);
                                	} else {
                                		tmp = 1.0 / ((b * b) * 0.5);
                                	}
                                	return tmp;
                                }
                                
                                real(8) function code(a, b)
                                    real(8), intent (in) :: a
                                    real(8), intent (in) :: b
                                    real(8) :: tmp
                                    if (b <= 3.9d+48) then
                                        tmp = 1.0d0 / ((1.0d0 + a) + 1.0d0)
                                    else
                                        tmp = 1.0d0 / ((b * b) * 0.5d0)
                                    end if
                                    code = tmp
                                end function
                                
                                public static double code(double a, double b) {
                                	double tmp;
                                	if (b <= 3.9e+48) {
                                		tmp = 1.0 / ((1.0 + a) + 1.0);
                                	} else {
                                		tmp = 1.0 / ((b * b) * 0.5);
                                	}
                                	return tmp;
                                }
                                
                                def code(a, b):
                                	tmp = 0
                                	if b <= 3.9e+48:
                                		tmp = 1.0 / ((1.0 + a) + 1.0)
                                	else:
                                		tmp = 1.0 / ((b * b) * 0.5)
                                	return tmp
                                
                                function code(a, b)
                                	tmp = 0.0
                                	if (b <= 3.9e+48)
                                		tmp = Float64(1.0 / Float64(Float64(1.0 + a) + 1.0));
                                	else
                                		tmp = Float64(1.0 / Float64(Float64(b * b) * 0.5));
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(a, b)
                                	tmp = 0.0;
                                	if (b <= 3.9e+48)
                                		tmp = 1.0 / ((1.0 + a) + 1.0);
                                	else
                                		tmp = 1.0 / ((b * b) * 0.5);
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[a_, b_] := If[LessEqual[b, 3.9e+48], N[(1.0 / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]
                                
                                \begin{array}{l}
                                
                                \\
                                \begin{array}{l}
                                \mathbf{if}\;b \leq 3.9 \cdot 10^{+48}:\\
                                \;\;\;\;\frac{1}{\left(1 + a\right) + 1}\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\frac{1}{\left(b \cdot b\right) \cdot 0.5}\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 2 regimes
                                2. if b < 3.9000000000000001e48

                                  1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \frac{e^{a}}{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{1}{6} \cdot a + \frac{1}{2}}, a, 1\right), a, 1\right) + 1} \]
                                      8. lower-fma.f6469.4

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

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

                                      \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, a, \frac{1}{2}\right), a, 1\right), a, 1\right) + 1} \]
                                    6. Step-by-step derivation
                                      1. Applied rewrites63.7%

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

                                        \[\leadsto \frac{1}{\color{blue}{\left(1 + a\right)} + 1} \]
                                      3. Step-by-step derivation
                                        1. lower-+.f6448.7

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

                                        \[\leadsto \frac{1}{\color{blue}{\left(1 + a\right)} + 1} \]

                                      if 3.9000000000000001e48 < 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. +-commutativeN/A

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

                                          \[\leadsto \frac{1}{\color{blue}{e^{b} + 1}} \]
                                        4. lower-exp.f64100.0

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

                                        \[\leadsto \color{blue}{\frac{1}{e^{b} + 1}} \]
                                      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 rewrites44.1%

                                          \[\leadsto \frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), \color{blue}{b}, 2\right)} \]
                                        2. Taylor expanded in b around inf

                                          \[\leadsto \frac{1}{\frac{1}{2} \cdot {b}^{\color{blue}{2}}} \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites47.7%

                                            \[\leadsto \frac{1}{\left(b \cdot b\right) \cdot 0.5} \]
                                        4. Recombined 2 regimes into one program.
                                        5. Add Preprocessing

                                        Alternative 9: 39.5% accurate, 17.5× speedup?

                                        \[\begin{array}{l} \\ \frac{1}{\left(1 + a\right) + 1} \end{array} \]
                                        (FPCore (a b) :precision binary64 (/ 1.0 (+ (+ 1.0 a) 1.0)))
                                        double code(double a, double b) {
                                        	return 1.0 / ((1.0 + a) + 1.0);
                                        }
                                        
                                        real(8) function code(a, b)
                                            real(8), intent (in) :: a
                                            real(8), intent (in) :: b
                                            code = 1.0d0 / ((1.0d0 + a) + 1.0d0)
                                        end function
                                        
                                        public static double code(double a, double b) {
                                        	return 1.0 / ((1.0 + a) + 1.0);
                                        }
                                        
                                        def code(a, b):
                                        	return 1.0 / ((1.0 + a) + 1.0)
                                        
                                        function code(a, b)
                                        	return Float64(1.0 / Float64(Float64(1.0 + a) + 1.0))
                                        end
                                        
                                        function tmp = code(a, b)
                                        	tmp = 1.0 / ((1.0 + a) + 1.0);
                                        end
                                        
                                        code[a_, b_] := N[(1.0 / N[(N[(1.0 + a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \frac{1}{\left(1 + a\right) + 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 rewrites63.1%

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \frac{\color{blue}{1}}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, a, \frac{1}{2}\right), a, 1\right), a, 1\right) + 1} \]
                                          6. Step-by-step derivation
                                            1. Applied rewrites55.5%

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

                                              \[\leadsto \frac{1}{\color{blue}{\left(1 + a\right)} + 1} \]
                                            3. Step-by-step derivation
                                              1. lower-+.f6441.1

                                                \[\leadsto \frac{1}{\color{blue}{\left(1 + a\right)} + 1} \]
                                            4. Applied rewrites41.1%

                                              \[\leadsto \frac{1}{\color{blue}{\left(1 + a\right)} + 1} \]
                                            5. Add Preprocessing

                                            Alternative 10: 39.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. +-commutativeN/A

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

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

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

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

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

                                                \[\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 2024255 
                                              (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))))