Logistic function

Percentage Accurate: 99.8% → 99.9%
Time: 9.0s
Alternatives: 21
Speedup: 1.0×

Specification

?
\[0 \leq s \land s \leq 1.0651631\]
\[\begin{array}{l} \\ \frac{1}{1 + e^{\frac{-x}{s}}} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
	return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + exp((-x / s)));
end
\begin{array}{l}

\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}

Sampling outcomes in binary32 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 21 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.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{1 + e^{\frac{-x}{s}}} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
float code(float x, float s) {
	return 1.0f / (1.0f + expf((-x / s)));
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 1.0e0 / (1.0e0 + exp((-x / s)))
end function
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + exp((-x / s)));
end
\begin{array}{l}

\\
\frac{1}{1 + e^{\frac{-x}{s}}}
\end{array}

Alternative 1: 99.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)} \end{array} \]
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (- (/ x s)))))))
float code(float x, float s) {
	return expf(-log1pf(expf(-(x / s))));
}
function code(x, s)
	return exp(Float32(-log1p(exp(Float32(-Float32(x / s))))))
end
\begin{array}{l}

\\
e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. div-inv99.8%

      \[\leadsto \frac{1}{1 + e^{\color{blue}{\left(-x\right) \cdot \frac{1}{s}}}} \]
    2. exp-prod83.2%

      \[\leadsto \frac{1}{1 + \color{blue}{{\left(e^{-x}\right)}^{\left(\frac{1}{s}\right)}}} \]
    3. neg-mul-183.2%

      \[\leadsto \frac{1}{1 + {\left(e^{\color{blue}{-1 \cdot x}}\right)}^{\left(\frac{1}{s}\right)}} \]
    4. exp-prod83.2%

      \[\leadsto \frac{1}{1 + {\color{blue}{\left({\left(e^{-1}\right)}^{x}\right)}}^{\left(\frac{1}{s}\right)}} \]
    5. pow-pow99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{{\left(e^{-1}\right)}^{\left(x \cdot \frac{1}{s}\right)}}} \]
    6. div-inv99.8%

      \[\leadsto \frac{1}{1 + {\left(e^{-1}\right)}^{\color{blue}{\left(\frac{x}{s}\right)}}} \]
  4. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \color{blue}{{\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}} \]
  5. Applied egg-rr99.8%

    \[\leadsto \color{blue}{e^{-\mathsf{log1p}\left(e^{\frac{x}{-s}}\right)}} \]
  6. Final simplification99.8%

    \[\leadsto e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)} \]
  7. Add Preprocessing

Alternative 2: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{1 + \frac{1}{{e}^{\left(\frac{x}{s}\right)}}} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (/ 1.0 (pow E (/ x s))))))
float code(float x, float s) {
	return 1.0f / (1.0f + (1.0f / powf(((float) M_E), (x / s))));
}
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / (Float32(exp(1)) ^ Float32(x / s)))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(2.71828182845904523536) ^ (x / s))));
end
\begin{array}{l}

\\
\frac{1}{1 + \frac{1}{{e}^{\left(\frac{x}{s}\right)}}}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-frac-neg99.8%

      \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
    2. exp-neg99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  4. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  5. Step-by-step derivation
    1. *-un-lft-identity99.8%

      \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
    2. exp-prod99.8%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
  6. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
  7. Final simplification99.8%

    \[\leadsto \frac{1}{1 + \frac{1}{{e}^{\left(\frac{x}{s}\right)}}} \]
  8. Add Preprocessing

Alternative 3: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{1 + {e}^{\left(-\frac{x}{s}\right)}} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (pow E (- (/ x s))))))
float code(float x, float s) {
	return 1.0f / (1.0f + powf(((float) M_E), -(x / s)));
}
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(-Float32(x / s)))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + (single(2.71828182845904523536) ^ -(x / s)));
end
\begin{array}{l}

\\
\frac{1}{1 + {e}^{\left(-\frac{x}{s}\right)}}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-frac-neg99.8%

      \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
    2. exp-neg99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  4. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  5. Step-by-step derivation
    1. *-un-lft-identity99.8%

      \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
    2. exp-prod99.8%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
  6. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
  7. Step-by-step derivation
    1. pow-flip99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{{\left(e^{1}\right)}^{\left(-\frac{x}{s}\right)}}} \]
    2. exp-1-e99.8%

      \[\leadsto \frac{1}{1 + {\color{blue}{e}}^{\left(-\frac{x}{s}\right)}} \]
    3. distribute-neg-frac299.8%

      \[\leadsto \frac{1}{1 + {e}^{\color{blue}{\left(\frac{x}{-s}\right)}}} \]
  8. Applied egg-rr99.8%

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

    \[\leadsto \frac{1}{1 + {e}^{\left(-\frac{x}{s}\right)}} \]
  10. Add Preprocessing

Alternative 4: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{1 + \frac{1}{e^{\frac{x}{s}}}} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (/ 1.0 (exp (/ x s))))))
float code(float x, float s) {
	return 1.0f / (1.0f + (1.0f / expf((x / s))));
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 1.0e0 / (1.0e0 + (1.0e0 / exp((x / s))))
end function
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / exp(Float32(x / s)))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + (single(1.0) / exp((x / s))));
end
\begin{array}{l}

\\
\frac{1}{1 + \frac{1}{e^{\frac{x}{s}}}}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-frac-neg99.8%

      \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
    2. exp-neg99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  4. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  5. Add Preprocessing

Alternative 5: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{1 + e^{\frac{x}{-s}}} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ x (- s))))))
float code(float x, float s) {
	return 1.0f / (1.0f + expf((x / -s)));
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 1.0e0 / (1.0e0 + exp((x / -s)))
end function
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(x / Float32(-s)))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(1.0) + exp((x / -s)));
end
\begin{array}{l}

\\
\frac{1}{1 + e^{\frac{x}{-s}}}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Final simplification99.8%

    \[\leadsto \frac{1}{1 + e^{\frac{x}{-s}}} \]
  4. Add Preprocessing

Alternative 6: 89.4% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-s}\\ \mathbf{if}\;t\_0 \leq 40:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \mathbf{elif}\;t\_0 \leq 19999999961012896000:\\ \;\;\;\;\frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \frac{s + s}{s \cdot s}\right)\right)}\\ \mathbf{elif}\;t\_0 \leq 9.999999680285692 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{s}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (/ x (- s))))
   (if (<= t_0 40.0)
     (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
     (if (<= t_0 19999999961012896000.0)
       (/ 1.0 (* x (+ (/ 2.0 x) (+ (/ 1.0 s) (/ (+ s s) (* s s))))))
       (if (<= t_0 9.999999680285692e+37)
         (/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
         (/ 1.0 (/ x s)))))))
float code(float x, float s) {
	float t_0 = x / -s;
	float tmp;
	if (t_0 <= 40.0f) {
		tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
	} else if (t_0 <= 19999999961012896000.0f) {
		tmp = 1.0f / (x * ((2.0f / x) + ((1.0f / s) + ((s + s) / (s * s)))));
	} else if (t_0 <= 9.999999680285692e+37f) {
		tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
	} else {
		tmp = 1.0f / (x / s);
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: tmp
    t_0 = x / -s
    if (t_0 <= 40.0e0) then
        tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
    else if (t_0 <= 19999999961012896000.0e0) then
        tmp = 1.0e0 / (x * ((2.0e0 / x) + ((1.0e0 / s) + ((s + s) / (s * s)))))
    else if (t_0 <= 9.999999680285692e+37) then
        tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
    else
        tmp = 1.0e0 / (x / s)
    end if
    code = tmp
end function
function code(x, s)
	t_0 = Float32(x / Float32(-s))
	tmp = Float32(0.0)
	if (t_0 <= Float32(40.0))
		tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))));
	elseif (t_0 <= Float32(19999999961012896000.0))
		tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(Float32(2.0) / x) + Float32(Float32(Float32(1.0) / s) + Float32(Float32(s + s) / Float32(s * s))))));
	elseif (t_0 <= Float32(9.999999680285692e+37))
		tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(x / s) + Float32(2.0))));
	else
		tmp = Float32(Float32(1.0) / Float32(x / s));
	end
	return tmp
end
function tmp_2 = code(x, s)
	t_0 = x / -s;
	tmp = single(0.0);
	if (t_0 <= single(40.0))
		tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s))));
	elseif (t_0 <= single(19999999961012896000.0))
		tmp = single(1.0) / (x * ((single(2.0) / x) + ((single(1.0) / s) + ((s + s) / (s * s)))));
	elseif (t_0 <= single(9.999999680285692e+37))
		tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((x / s) + single(2.0)));
	else
		tmp = single(1.0) / (x / s);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 40:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\

\mathbf{elif}\;t\_0 \leq 19999999961012896000:\\
\;\;\;\;\frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \frac{s + s}{s \cdot s}\right)\right)}\\

\mathbf{elif}\;t\_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f32 (neg.f32 x) s) < 40

    1. Initial program 99.8%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg99.8%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg99.8%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Taylor expanded in x around 0 93.8%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    6. Step-by-step derivation
      1. +-commutative93.8%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]
    7. Simplified93.8%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]

    if 40 < (/.f32 (neg.f32 x) s) < 2e19

    1. Initial program 99.5%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 7.8%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-17.8%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg7.8%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified7.8%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 7.8%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(2 \cdot \frac{1}{x} - \frac{1}{s}\right)}} \]
    7. Step-by-step derivation
      1. associate-*r/7.8%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} - \frac{1}{s}\right)} \]
      2. metadata-eval7.8%

        \[\leadsto \frac{1}{x \cdot \left(\frac{\color{blue}{2}}{x} - \frac{1}{s}\right)} \]
    8. Simplified7.8%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{2}{x} - \frac{1}{s}\right)}} \]
    9. Step-by-step derivation
      1. *-un-lft-identity7.8%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} - \color{blue}{1 \cdot \frac{1}{s}}\right)} \]
      2. add-sqr-sqrt-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}}} - 1 \cdot \frac{1}{s}\right)} \]
      3. prod-diff-0.0%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\frac{1}{s} \cdot 1\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)}} \]
      4. associate-/r/-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{\frac{s}{1}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      5. clear-num-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      6. distribute-frac-neg2-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \color{blue}{\frac{1}{-s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      7. add-sqr-sqrt-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      8. sqrt-unprod-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      9. sqr-neg-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\sqrt{\color{blue}{s \cdot s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      10. sqrt-unprod-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      11. add-sqr-sqrt-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      12. fma-define-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\left(\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}} + \frac{1}{s}\right)} + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      13. add-sqr-sqrt7.6%

        \[\leadsto \frac{1}{x \cdot \left(\left(\color{blue}{\frac{2}{x}} + \frac{1}{s}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    10. Applied egg-rr7.6%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\left(\frac{2}{x} + \frac{1}{s}\right) + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)}} \]
    11. Step-by-step derivation
      1. associate-+l+7.6%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)\right)}} \]
      2. fma-undefine7.6%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \color{blue}{\left(\frac{1}{s} \cdot 1 + \frac{1}{s}\right)}\right)\right)} \]
      3. *-rgt-identity7.6%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \left(\color{blue}{\frac{1}{s}} + \frac{1}{s}\right)\right)\right)} \]
    12. Simplified7.6%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \left(\frac{1}{s} + \frac{1}{s}\right)\right)\right)}} \]
    13. Step-by-step derivation
      1. frac-2neg7.6%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \left(\frac{1}{s} + \color{blue}{\frac{-1}{-s}}\right)\right)\right)} \]
      2. metadata-eval7.6%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \left(\frac{1}{s} + \frac{\color{blue}{-1}}{-s}\right)\right)\right)} \]
      3. frac-add52.0%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \color{blue}{\frac{1 \cdot \left(-s\right) + s \cdot -1}{s \cdot \left(-s\right)}}\right)\right)} \]
      4. *-un-lft-identity52.0%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \frac{\color{blue}{\left(-s\right)} + s \cdot -1}{s \cdot \left(-s\right)}\right)\right)} \]
    14. Applied egg-rr52.0%

      \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \color{blue}{\frac{\left(-s\right) + s \cdot -1}{s \cdot \left(-s\right)}}\right)\right)} \]

    if 2e19 < (/.f32 (neg.f32 x) s) < 9.99999968e37

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 14.7%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-114.7%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg14.7%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified14.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Step-by-step derivation
      1. *-un-lft-identity14.7%

        \[\leadsto \frac{1}{2 - \color{blue}{1 \cdot \frac{x}{s}}} \]
      2. cancel-sign-sub-inv14.7%

        \[\leadsto \frac{1}{\color{blue}{2 + \left(-1\right) \cdot \frac{x}{s}}} \]
      3. metadata-eval14.7%

        \[\leadsto \frac{1}{2 + \color{blue}{-1} \cdot \frac{x}{s}} \]
      4. add-log-exp100.0%

        \[\leadsto \frac{1}{2 + \color{blue}{\log \left(e^{-1 \cdot \frac{x}{s}}\right)}} \]
      5. pow-exp100.0%

        \[\leadsto \frac{1}{2 + \log \color{blue}{\left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      6. flip-+-0.0%

        \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot 2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right) \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}}} \]
      7. metadata-eval-0.0%

        \[\leadsto \frac{1}{\frac{\color{blue}{4} - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right) \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      8. pow-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \log \color{blue}{\left(e^{-1 \cdot \frac{x}{s}}\right)} \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      9. add-log-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\left(-1 \cdot \frac{x}{s}\right)} \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      10. neg-mul-1-0.0%

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\left(-\frac{x}{s}\right)} \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      11. pow-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \left(-\frac{x}{s}\right) \cdot \log \color{blue}{\left(e^{-1 \cdot \frac{x}{s}}\right)}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      12. add-log-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \left(-\frac{x}{s}\right) \cdot \color{blue}{\left(-1 \cdot \frac{x}{s}\right)}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      13. neg-mul-1-0.0%

        \[\leadsto \frac{1}{\frac{4 - \left(-\frac{x}{s}\right) \cdot \color{blue}{\left(-\frac{x}{s}\right)}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      14. distribute-neg-frac2-0.0%

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\frac{x}{-s}} \cdot \left(-\frac{x}{s}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      15. distribute-neg-frac2-0.0%

        \[\leadsto \frac{1}{\frac{4 - \frac{x}{-s} \cdot \color{blue}{\frac{x}{-s}}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      16. pow-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \frac{x}{-s} \cdot \frac{x}{-s}}{2 - \log \color{blue}{\left(e^{-1 \cdot \frac{x}{s}}\right)}}} \]
    7. Applied egg-rr100.0%

      \[\leadsto \frac{1}{\color{blue}{\frac{4 - \frac{x}{-s} \cdot \frac{x}{-s}}{2 - \frac{x}{-s}}}} \]

    if 9.99999968e37 < (/.f32 (neg.f32 x) s)

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 100.0%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg100.0%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified100.0%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 94.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{s}{x}} \]
    7. Step-by-step derivation
      1. associate-*r/94.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot s}{x}} \]
      2. neg-mul-194.1%

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    8. Simplified94.1%

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    9. Step-by-step derivation
      1. clear-num100.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{-s}}} \]
      2. inv-pow100.0%

        \[\leadsto \color{blue}{{\left(\frac{x}{-s}\right)}^{-1}} \]
      3. add-sqr-sqrt-0.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}\right)}^{-1} \]
      4. sqrt-unprod100.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}}\right)}^{-1} \]
      5. sqr-neg100.0%

        \[\leadsto {\left(\frac{x}{\sqrt{\color{blue}{s \cdot s}}}\right)}^{-1} \]
      6. sqrt-unprod100.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}\right)}^{-1} \]
      7. add-sqr-sqrt100.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{s}}\right)}^{-1} \]
    10. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{x}{s}\right)}^{-1}} \]
    11. Step-by-step derivation
      1. unpow-1100.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{s}}} \]
    12. Simplified100.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{s}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification91.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq 40:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \mathbf{elif}\;\frac{x}{-s} \leq 19999999961012896000:\\ \;\;\;\;\frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \frac{s + s}{s \cdot s}\right)\right)}\\ \mathbf{elif}\;\frac{x}{-s} \leq 9.999999680285692 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{s}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 88.9% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-s}\\ \mathbf{if}\;t\_0 \leq 40:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \mathbf{elif}\;t\_0 \leq 19999999961012896000:\\ \;\;\;\;\frac{1}{x \cdot \left(\left(x - s \cdot 2\right) \cdot \frac{-1}{x \cdot s}\right)}\\ \mathbf{elif}\;t\_0 \leq 9.999999680285692 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{s}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (/ x (- s))))
   (if (<= t_0 40.0)
     (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
     (if (<= t_0 19999999961012896000.0)
       (/ 1.0 (* x (* (- x (* s 2.0)) (/ -1.0 (* x s)))))
       (if (<= t_0 9.999999680285692e+37)
         (/ 1.0 (/ (- 4.0 (* (/ x s) (/ x s))) (+ (/ x s) 2.0)))
         (/ 1.0 (/ x s)))))))
float code(float x, float s) {
	float t_0 = x / -s;
	float tmp;
	if (t_0 <= 40.0f) {
		tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
	} else if (t_0 <= 19999999961012896000.0f) {
		tmp = 1.0f / (x * ((x - (s * 2.0f)) * (-1.0f / (x * s))));
	} else if (t_0 <= 9.999999680285692e+37f) {
		tmp = 1.0f / ((4.0f - ((x / s) * (x / s))) / ((x / s) + 2.0f));
	} else {
		tmp = 1.0f / (x / s);
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: tmp
    t_0 = x / -s
    if (t_0 <= 40.0e0) then
        tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
    else if (t_0 <= 19999999961012896000.0e0) then
        tmp = 1.0e0 / (x * ((x - (s * 2.0e0)) * ((-1.0e0) / (x * s))))
    else if (t_0 <= 9.999999680285692e+37) then
        tmp = 1.0e0 / ((4.0e0 - ((x / s) * (x / s))) / ((x / s) + 2.0e0))
    else
        tmp = 1.0e0 / (x / s)
    end if
    code = tmp
end function
function code(x, s)
	t_0 = Float32(x / Float32(-s))
	tmp = Float32(0.0)
	if (t_0 <= Float32(40.0))
		tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))));
	elseif (t_0 <= Float32(19999999961012896000.0))
		tmp = Float32(Float32(1.0) / Float32(x * Float32(Float32(x - Float32(s * Float32(2.0))) * Float32(Float32(-1.0) / Float32(x * s)))));
	elseif (t_0 <= Float32(9.999999680285692e+37))
		tmp = Float32(Float32(1.0) / Float32(Float32(Float32(4.0) - Float32(Float32(x / s) * Float32(x / s))) / Float32(Float32(x / s) + Float32(2.0))));
	else
		tmp = Float32(Float32(1.0) / Float32(x / s));
	end
	return tmp
end
function tmp_2 = code(x, s)
	t_0 = x / -s;
	tmp = single(0.0);
	if (t_0 <= single(40.0))
		tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s))));
	elseif (t_0 <= single(19999999961012896000.0))
		tmp = single(1.0) / (x * ((x - (s * single(2.0))) * (single(-1.0) / (x * s))));
	elseif (t_0 <= single(9.999999680285692e+37))
		tmp = single(1.0) / ((single(4.0) - ((x / s) * (x / s))) / ((x / s) + single(2.0)));
	else
		tmp = single(1.0) / (x / s);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq 40:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\

\mathbf{elif}\;t\_0 \leq 19999999961012896000:\\
\;\;\;\;\frac{1}{x \cdot \left(\left(x - s \cdot 2\right) \cdot \frac{-1}{x \cdot s}\right)}\\

\mathbf{elif}\;t\_0 \leq 9.999999680285692 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f32 (neg.f32 x) s) < 40

    1. Initial program 99.8%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg99.8%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg99.8%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Taylor expanded in x around 0 93.8%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    6. Step-by-step derivation
      1. +-commutative93.8%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]
    7. Simplified93.8%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]

    if 40 < (/.f32 (neg.f32 x) s) < 2e19

    1. Initial program 99.5%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 7.8%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-17.8%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg7.8%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified7.8%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 7.8%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(2 \cdot \frac{1}{x} - \frac{1}{s}\right)}} \]
    7. Step-by-step derivation
      1. associate-*r/7.8%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} - \frac{1}{s}\right)} \]
      2. metadata-eval7.8%

        \[\leadsto \frac{1}{x \cdot \left(\frac{\color{blue}{2}}{x} - \frac{1}{s}\right)} \]
    8. Simplified7.8%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{2}{x} - \frac{1}{s}\right)}} \]
    9. Step-by-step derivation
      1. frac-sub44.0%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\frac{2 \cdot s - x \cdot 1}{x \cdot s}}} \]
      2. div-inv47.9%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\left(2 \cdot s - x \cdot 1\right) \cdot \frac{1}{x \cdot s}\right)}} \]
      3. *-rgt-identity47.9%

        \[\leadsto \frac{1}{x \cdot \left(\left(2 \cdot s - \color{blue}{x}\right) \cdot \frac{1}{x \cdot s}\right)} \]
      4. *-commutative47.9%

        \[\leadsto \frac{1}{x \cdot \left(\left(\color{blue}{s \cdot 2} - x\right) \cdot \frac{1}{x \cdot s}\right)} \]
    10. Applied egg-rr47.9%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\left(s \cdot 2 - x\right) \cdot \frac{1}{x \cdot s}\right)}} \]

    if 2e19 < (/.f32 (neg.f32 x) s) < 9.99999968e37

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 14.7%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-114.7%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg14.7%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified14.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Step-by-step derivation
      1. *-un-lft-identity14.7%

        \[\leadsto \frac{1}{2 - \color{blue}{1 \cdot \frac{x}{s}}} \]
      2. cancel-sign-sub-inv14.7%

        \[\leadsto \frac{1}{\color{blue}{2 + \left(-1\right) \cdot \frac{x}{s}}} \]
      3. metadata-eval14.7%

        \[\leadsto \frac{1}{2 + \color{blue}{-1} \cdot \frac{x}{s}} \]
      4. add-log-exp100.0%

        \[\leadsto \frac{1}{2 + \color{blue}{\log \left(e^{-1 \cdot \frac{x}{s}}\right)}} \]
      5. pow-exp100.0%

        \[\leadsto \frac{1}{2 + \log \color{blue}{\left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      6. flip-+-0.0%

        \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot 2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right) \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}}} \]
      7. metadata-eval-0.0%

        \[\leadsto \frac{1}{\frac{\color{blue}{4} - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right) \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      8. pow-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \log \color{blue}{\left(e^{-1 \cdot \frac{x}{s}}\right)} \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      9. add-log-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\left(-1 \cdot \frac{x}{s}\right)} \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      10. neg-mul-1-0.0%

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\left(-\frac{x}{s}\right)} \cdot \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      11. pow-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \left(-\frac{x}{s}\right) \cdot \log \color{blue}{\left(e^{-1 \cdot \frac{x}{s}}\right)}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      12. add-log-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \left(-\frac{x}{s}\right) \cdot \color{blue}{\left(-1 \cdot \frac{x}{s}\right)}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      13. neg-mul-1-0.0%

        \[\leadsto \frac{1}{\frac{4 - \left(-\frac{x}{s}\right) \cdot \color{blue}{\left(-\frac{x}{s}\right)}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      14. distribute-neg-frac2-0.0%

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\frac{x}{-s}} \cdot \left(-\frac{x}{s}\right)}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      15. distribute-neg-frac2-0.0%

        \[\leadsto \frac{1}{\frac{4 - \frac{x}{-s} \cdot \color{blue}{\frac{x}{-s}}}{2 - \log \left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}} \]
      16. pow-exp-0.0%

        \[\leadsto \frac{1}{\frac{4 - \frac{x}{-s} \cdot \frac{x}{-s}}{2 - \log \color{blue}{\left(e^{-1 \cdot \frac{x}{s}}\right)}}} \]
    7. Applied egg-rr100.0%

      \[\leadsto \frac{1}{\color{blue}{\frac{4 - \frac{x}{-s} \cdot \frac{x}{-s}}{2 - \frac{x}{-s}}}} \]

    if 9.99999968e37 < (/.f32 (neg.f32 x) s)

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 100.0%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-1100.0%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg100.0%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified100.0%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 94.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{s}{x}} \]
    7. Step-by-step derivation
      1. associate-*r/94.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot s}{x}} \]
      2. neg-mul-194.1%

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    8. Simplified94.1%

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    9. Step-by-step derivation
      1. clear-num100.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{-s}}} \]
      2. inv-pow100.0%

        \[\leadsto \color{blue}{{\left(\frac{x}{-s}\right)}^{-1}} \]
      3. add-sqr-sqrt-0.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}\right)}^{-1} \]
      4. sqrt-unprod100.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}}\right)}^{-1} \]
      5. sqr-neg100.0%

        \[\leadsto {\left(\frac{x}{\sqrt{\color{blue}{s \cdot s}}}\right)}^{-1} \]
      6. sqrt-unprod100.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}\right)}^{-1} \]
      7. add-sqr-sqrt100.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{s}}\right)}^{-1} \]
    10. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(\frac{x}{s}\right)}^{-1}} \]
    11. Step-by-step derivation
      1. unpow-1100.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{s}}} \]
    12. Simplified100.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{s}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification91.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq 40:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \mathbf{elif}\;\frac{x}{-s} \leq 19999999961012896000:\\ \;\;\;\;\frac{1}{x \cdot \left(\left(x - s \cdot 2\right) \cdot \frac{-1}{x \cdot s}\right)}\\ \mathbf{elif}\;\frac{x}{-s} \leq 9.999999680285692 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\frac{4 - \frac{x}{s} \cdot \frac{x}{s}}{\frac{x}{s} + 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{s}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 54.0% accurate, 4.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-s}\\ \mathbf{if}\;t\_0 \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{elif}\;t\_0 \leq 0.5:\\ \;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x}{s}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (/ x (- s))))
   (if (<= t_0 -10.0)
     0.9583333333333334
     (if (<= t_0 0.5) (+ 0.5 (/ (* x 0.25) s)) (/ -1.0 (/ x s))))))
float code(float x, float s) {
	float t_0 = x / -s;
	float tmp;
	if (t_0 <= -10.0f) {
		tmp = 0.9583333333333334f;
	} else if (t_0 <= 0.5f) {
		tmp = 0.5f + ((x * 0.25f) / s);
	} else {
		tmp = -1.0f / (x / s);
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: tmp
    t_0 = x / -s
    if (t_0 <= (-10.0e0)) then
        tmp = 0.9583333333333334e0
    else if (t_0 <= 0.5e0) then
        tmp = 0.5e0 + ((x * 0.25e0) / s)
    else
        tmp = (-1.0e0) / (x / s)
    end if
    code = tmp
end function
function code(x, s)
	t_0 = Float32(x / Float32(-s))
	tmp = Float32(0.0)
	if (t_0 <= Float32(-10.0))
		tmp = Float32(0.9583333333333334);
	elseif (t_0 <= Float32(0.5))
		tmp = Float32(Float32(0.5) + Float32(Float32(x * Float32(0.25)) / s));
	else
		tmp = Float32(Float32(-1.0) / Float32(x / s));
	end
	return tmp
end
function tmp_2 = code(x, s)
	t_0 = x / -s;
	tmp = single(0.0);
	if (t_0 <= single(-10.0))
		tmp = single(0.9583333333333334);
	elseif (t_0 <= single(0.5))
		tmp = single(0.5) + ((x * single(0.25)) / s);
	else
		tmp = single(-1.0) / (x / s);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -10:\\
\;\;\;\;0.9583333333333334\\

\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f32 (neg.f32 x) s) < -10

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 0.4%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.3%

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

    if -10 < (/.f32 (neg.f32 x) s) < 0.5

    1. Initial program 99.8%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 97.2%

      \[\leadsto \color{blue}{0.5 + 0.25 \cdot \frac{x}{s}} \]
    4. Step-by-step derivation
      1. associate-*r/97.2%

        \[\leadsto 0.5 + \color{blue}{\frac{0.25 \cdot x}{s}} \]
    5. Simplified97.2%

      \[\leadsto \color{blue}{0.5 + \frac{0.25 \cdot x}{s}} \]

    if 0.5 < (/.f32 (neg.f32 x) s)

    1. Initial program 99.6%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 37.4%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-137.4%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg37.4%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified37.4%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 37.4%

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{x}{s}}} \]
    7. Step-by-step derivation
      1. mul-1-neg37.4%

        \[\leadsto \frac{1}{\color{blue}{-\frac{x}{s}}} \]
      2. distribute-frac-neg237.4%

        \[\leadsto \frac{1}{\color{blue}{\frac{x}{-s}}} \]
    8. Simplified37.4%

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{-s}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification51.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{elif}\;\frac{x}{-s} \leq 0.5:\\ \;\;\;\;0.5 + \frac{x \cdot 0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x}{s}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 51.8% accurate, 5.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-s}\\ \mathbf{if}\;t\_0 \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{elif}\;t\_0 \leq 0.5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x}{s}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (/ x (- s))))
   (if (<= t_0 -10.0)
     0.9583333333333334
     (if (<= t_0 0.5) 0.5 (/ -1.0 (/ x s))))))
float code(float x, float s) {
	float t_0 = x / -s;
	float tmp;
	if (t_0 <= -10.0f) {
		tmp = 0.9583333333333334f;
	} else if (t_0 <= 0.5f) {
		tmp = 0.5f;
	} else {
		tmp = -1.0f / (x / s);
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: tmp
    t_0 = x / -s
    if (t_0 <= (-10.0e0)) then
        tmp = 0.9583333333333334e0
    else if (t_0 <= 0.5e0) then
        tmp = 0.5e0
    else
        tmp = (-1.0e0) / (x / s)
    end if
    code = tmp
end function
function code(x, s)
	t_0 = Float32(x / Float32(-s))
	tmp = Float32(0.0)
	if (t_0 <= Float32(-10.0))
		tmp = Float32(0.9583333333333334);
	elseif (t_0 <= Float32(0.5))
		tmp = Float32(0.5);
	else
		tmp = Float32(Float32(-1.0) / Float32(x / s));
	end
	return tmp
end
function tmp_2 = code(x, s)
	t_0 = x / -s;
	tmp = single(0.0);
	if (t_0 <= single(-10.0))
		tmp = single(0.9583333333333334);
	elseif (t_0 <= single(0.5))
		tmp = single(0.5);
	else
		tmp = single(-1.0) / (x / s);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{-s}\\
\mathbf{if}\;t\_0 \leq -10:\\
\;\;\;\;0.9583333333333334\\

\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{x}{s}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f32 (neg.f32 x) s) < -10

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 0.4%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.3%

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

    if -10 < (/.f32 (neg.f32 x) s) < 0.5

    1. Initial program 99.8%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 90.5%

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

    if 0.5 < (/.f32 (neg.f32 x) s)

    1. Initial program 99.6%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 37.4%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-137.4%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg37.4%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified37.4%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 37.4%

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{x}{s}}} \]
    7. Step-by-step derivation
      1. mul-1-neg37.4%

        \[\leadsto \frac{1}{\color{blue}{-\frac{x}{s}}} \]
      2. distribute-frac-neg237.4%

        \[\leadsto \frac{1}{\color{blue}{\frac{x}{-s}}} \]
    8. Simplified37.4%

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{-s}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification49.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{elif}\;\frac{x}{-s} \leq 0.5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x}{s}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 73.9% accurate, 5.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq 50:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-4 + x \cdot \left(x \cdot -0.16666666666666666\right)}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= (/ x (- s)) 50.0)
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))
   (/ 1.0 (+ -4.0 (* x (* x -0.16666666666666666))))))
float code(float x, float s) {
	float tmp;
	if ((x / -s) <= 50.0f) {
		tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
	} else {
		tmp = 1.0f / (-4.0f + (x * (x * -0.16666666666666666f)));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x / -s) <= 50.0e0) then
        tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
    else
        tmp = 1.0e0 / ((-4.0e0) + (x * (x * (-0.16666666666666666e0))))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (Float32(x / Float32(-s)) <= Float32(50.0))
		tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))));
	else
		tmp = Float32(Float32(1.0) / Float32(Float32(-4.0) + Float32(x * Float32(x * Float32(-0.16666666666666666)))));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x / -s) <= single(50.0))
		tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s))));
	else
		tmp = single(1.0) / (single(-4.0) + (x * (x * single(-0.16666666666666666))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq 50:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{-4 + x \cdot \left(x \cdot -0.16666666666666666\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f32 (neg.f32 x) s) < 50

    1. Initial program 99.7%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg99.7%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg99.7%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr99.7%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Taylor expanded in x around 0 93.3%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    6. Step-by-step derivation
      1. +-commutative93.3%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]
    7. Simplified93.3%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]

    if 50 < (/.f32 (neg.f32 x) s)

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in x around 0 95.1%

      \[\leadsto \frac{1}{\color{blue}{2 + x \cdot \left(x \cdot \left(-0.16666666666666666 \cdot \frac{x}{{s}^{3}} + 0.5 \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)}} \]
    8. Simplified43.7%

      \[\leadsto \frac{1}{\color{blue}{-4 + x \cdot \left(x \cdot -0.16666666666666666\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq 50:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-4 + x \cdot \left(x \cdot -0.16666666666666666\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 78.7% accurate, 6.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.999999936531045 \cdot 10^{-21}:\\ \;\;\;\;\frac{1}{\frac{x \cdot \left(s \cdot 2 - x\right)}{x \cdot s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -1.999999936531045e-21)
   (/ 1.0 (/ (* x (- (* s 2.0) x)) (* x s)))
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -1.999999936531045e-21f) {
		tmp = 1.0f / ((x * ((s * 2.0f) - x)) / (x * s));
	} else {
		tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= (-1.999999936531045e-21)) then
        tmp = 1.0e0 / ((x * ((s * 2.0e0) - x)) / (x * s))
    else
        tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(-1.999999936531045e-21))
		tmp = Float32(Float32(1.0) / Float32(Float32(x * Float32(Float32(s * Float32(2.0)) - x)) / Float32(x * s)));
	else
		tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(-1.999999936531045e-21))
		tmp = single(1.0) / ((x * ((s * single(2.0)) - x)) / (x * s));
	else
		tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.999999936531045 \cdot 10^{-21}:\\
\;\;\;\;\frac{1}{\frac{x \cdot \left(s \cdot 2 - x\right)}{x \cdot s}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\


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

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 41.8%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-141.8%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg41.8%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified41.8%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 41.8%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(2 \cdot \frac{1}{x} - \frac{1}{s}\right)}} \]
    7. Step-by-step derivation
      1. associate-*r/41.8%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} - \frac{1}{s}\right)} \]
      2. metadata-eval41.8%

        \[\leadsto \frac{1}{x \cdot \left(\frac{\color{blue}{2}}{x} - \frac{1}{s}\right)} \]
    8. Simplified41.8%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{2}{x} - \frac{1}{s}\right)}} \]
    9. Step-by-step derivation
      1. *-commutative41.8%

        \[\leadsto \frac{1}{\color{blue}{\left(\frac{2}{x} - \frac{1}{s}\right) \cdot x}} \]
      2. frac-sub45.9%

        \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot s - x \cdot 1}{x \cdot s}} \cdot x} \]
      3. associate-*l/60.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{\left(2 \cdot s - x \cdot 1\right) \cdot x}{x \cdot s}}} \]
      4. *-rgt-identity60.6%

        \[\leadsto \frac{1}{\frac{\left(2 \cdot s - \color{blue}{x}\right) \cdot x}{x \cdot s}} \]
      5. *-commutative60.6%

        \[\leadsto \frac{1}{\frac{\left(\color{blue}{s \cdot 2} - x\right) \cdot x}{x \cdot s}} \]
    10. Applied egg-rr60.6%

      \[\leadsto \frac{1}{\color{blue}{\frac{\left(s \cdot 2 - x\right) \cdot x}{x \cdot s}}} \]

    if -1.9999999e-21 < x

    1. Initial program 99.8%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg99.8%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg99.8%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Taylor expanded in x around 0 91.5%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    6. Step-by-step derivation
      1. +-commutative91.5%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]
    7. Simplified91.5%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.999999936531045 \cdot 10^{-21}:\\ \;\;\;\;\frac{1}{\frac{x \cdot \left(s \cdot 2 - x\right)}{x \cdot s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 76.5% accurate, 6.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.000000229068525 \cdot 10^{-19}:\\ \;\;\;\;\left(x \cdot s\right) \cdot \frac{\frac{-1}{x}}{x - s \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -5.000000229068525e-19)
   (* (* x s) (/ (/ -1.0 x) (- x (* s 2.0))))
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -5.000000229068525e-19f) {
		tmp = (x * s) * ((-1.0f / x) / (x - (s * 2.0f)));
	} else {
		tmp = 1.0f / (1.0f + (1.0f / (1.0f + (x / s))));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= (-5.000000229068525e-19)) then
        tmp = (x * s) * (((-1.0e0) / x) / (x - (s * 2.0e0)))
    else
        tmp = 1.0e0 / (1.0e0 + (1.0e0 / (1.0e0 + (x / s))))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(-5.000000229068525e-19))
		tmp = Float32(Float32(x * s) * Float32(Float32(Float32(-1.0) / x) / Float32(x - Float32(s * Float32(2.0)))));
	else
		tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(-5.000000229068525e-19))
		tmp = (x * s) * ((single(-1.0) / x) / (x - (s * single(2.0))));
	else
		tmp = single(1.0) / (single(1.0) + (single(1.0) / (single(1.0) + (x / s))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000229068525 \cdot 10^{-19}:\\
\;\;\;\;\left(x \cdot s\right) \cdot \frac{\frac{-1}{x}}{x - s \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\


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

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 41.7%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-141.7%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg41.7%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified41.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 41.7%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(2 \cdot \frac{1}{x} - \frac{1}{s}\right)}} \]
    7. Step-by-step derivation
      1. associate-*r/41.7%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} - \frac{1}{s}\right)} \]
      2. metadata-eval41.7%

        \[\leadsto \frac{1}{x \cdot \left(\frac{\color{blue}{2}}{x} - \frac{1}{s}\right)} \]
    8. Simplified41.7%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{2}{x} - \frac{1}{s}\right)}} \]
    9. Step-by-step derivation
      1. associate-/r*39.8%

        \[\leadsto \color{blue}{\frac{\frac{1}{x}}{\frac{2}{x} - \frac{1}{s}}} \]
      2. frac-sub40.9%

        \[\leadsto \frac{\frac{1}{x}}{\color{blue}{\frac{2 \cdot s - x \cdot 1}{x \cdot s}}} \]
      3. associate-/r/53.5%

        \[\leadsto \color{blue}{\frac{\frac{1}{x}}{2 \cdot s - x \cdot 1} \cdot \left(x \cdot s\right)} \]
      4. *-rgt-identity53.5%

        \[\leadsto \frac{\frac{1}{x}}{2 \cdot s - \color{blue}{x}} \cdot \left(x \cdot s\right) \]
      5. *-commutative53.5%

        \[\leadsto \frac{\frac{1}{x}}{\color{blue}{s \cdot 2} - x} \cdot \left(x \cdot s\right) \]
    10. Applied egg-rr53.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{s \cdot 2 - x} \cdot \left(x \cdot s\right)} \]

    if -5.00000023e-19 < x

    1. Initial program 99.7%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg99.7%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg99.8%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr99.8%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Taylor expanded in x around 0 90.1%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    6. Step-by-step derivation
      1. +-commutative90.1%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]
    7. Simplified90.1%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{\frac{x}{s} + 1}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.000000229068525 \cdot 10^{-19}:\\ \;\;\;\;\left(x \cdot s\right) \cdot \frac{\frac{-1}{x}}{x - s \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 53.2% accurate, 6.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= (/ x (- s)) -10.0)
   0.9583333333333334
   (/ 1.0 (+ -1.0 (- 3.0 (/ x s))))))
float code(float x, float s) {
	float tmp;
	if ((x / -s) <= -10.0f) {
		tmp = 0.9583333333333334f;
	} else {
		tmp = 1.0f / (-1.0f + (3.0f - (x / s)));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x / -s) <= (-10.0e0)) then
        tmp = 0.9583333333333334e0
    else
        tmp = 1.0e0 / ((-1.0e0) + (3.0e0 - (x / s)))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (Float32(x / Float32(-s)) <= Float32(-10.0))
		tmp = Float32(0.9583333333333334);
	else
		tmp = Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(3.0) - Float32(x / s))));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x / -s) <= single(-10.0))
		tmp = single(0.9583333333333334);
	else
		tmp = single(1.0) / (single(-1.0) + (single(3.0) - (x / s)));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -10:\\
\;\;\;\;0.9583333333333334\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f32 (neg.f32 x) s) < -10

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 0.4%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.3%

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

    if -10 < (/.f32 (neg.f32 x) s)

    1. Initial program 99.7%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 58.8%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-158.8%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg58.8%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified58.8%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u58.7%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 - \frac{x}{s}\right)\right)}} \]
    7. Applied egg-rr58.7%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 - \frac{x}{s}\right)\right)}} \]
    8. Step-by-step derivation
      1. expm1-undefine58.7%

        \[\leadsto \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(2 - \frac{x}{s}\right)} - 1}} \]
      2. sub-neg58.7%

        \[\leadsto \frac{1}{\color{blue}{e^{\mathsf{log1p}\left(2 - \frac{x}{s}\right)} + \left(-1\right)}} \]
      3. log1p-undefine58.7%

        \[\leadsto \frac{1}{e^{\color{blue}{\log \left(1 + \left(2 - \frac{x}{s}\right)\right)}} + \left(-1\right)} \]
      4. rem-exp-log58.8%

        \[\leadsto \frac{1}{\color{blue}{\left(1 + \left(2 - \frac{x}{s}\right)\right)} + \left(-1\right)} \]
      5. associate-+r-58.8%

        \[\leadsto \frac{1}{\color{blue}{\left(\left(1 + 2\right) - \frac{x}{s}\right)} + \left(-1\right)} \]
      6. metadata-eval58.8%

        \[\leadsto \frac{1}{\left(\color{blue}{3} - \frac{x}{s}\right) + \left(-1\right)} \]
      7. metadata-eval58.8%

        \[\leadsto \frac{1}{\left(3 - \frac{x}{s}\right) + \color{blue}{-1}} \]
    9. Simplified58.8%

      \[\leadsto \frac{1}{\color{blue}{\left(3 - \frac{x}{s}\right) + -1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-1 + \left(3 - \frac{x}{s}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 53.2% accurate, 7.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 - \frac{x}{s}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= (/ x (- s)) -10.0) 0.9583333333333334 (/ 1.0 (- 2.0 (/ x s)))))
float code(float x, float s) {
	float tmp;
	if ((x / -s) <= -10.0f) {
		tmp = 0.9583333333333334f;
	} else {
		tmp = 1.0f / (2.0f - (x / s));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x / -s) <= (-10.0e0)) then
        tmp = 0.9583333333333334e0
    else
        tmp = 1.0e0 / (2.0e0 - (x / s))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (Float32(x / Float32(-s)) <= Float32(-10.0))
		tmp = Float32(0.9583333333333334);
	else
		tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s)));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x / -s) <= single(-10.0))
		tmp = single(0.9583333333333334);
	else
		tmp = single(1.0) / (single(2.0) - (x / s));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{-s} \leq -10:\\
\;\;\;\;0.9583333333333334\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f32 (neg.f32 x) s) < -10

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 0.4%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.3%

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

    if -10 < (/.f32 (neg.f32 x) s)

    1. Initial program 99.7%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 58.8%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-158.8%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg58.8%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified58.8%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{-s} \leq -10:\\ \;\;\;\;0.9583333333333334\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 - \frac{x}{s}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 50.3% accurate, 9.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\ \;\;\;\;\frac{1}{\frac{x}{s}}\\ \mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0.9583333333333334\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -4.999999969612645e-9)
   (/ 1.0 (/ x s))
   (if (<= x 1.9999999920083944e-12) 0.5 0.9583333333333334)))
float code(float x, float s) {
	float tmp;
	if (x <= -4.999999969612645e-9f) {
		tmp = 1.0f / (x / s);
	} else if (x <= 1.9999999920083944e-12f) {
		tmp = 0.5f;
	} else {
		tmp = 0.9583333333333334f;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= (-4.999999969612645e-9)) then
        tmp = 1.0e0 / (x / s)
    else if (x <= 1.9999999920083944e-12) then
        tmp = 0.5e0
    else
        tmp = 0.9583333333333334e0
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(-4.999999969612645e-9))
		tmp = Float32(Float32(1.0) / Float32(x / s));
	elseif (x <= Float32(1.9999999920083944e-12))
		tmp = Float32(0.5);
	else
		tmp = Float32(0.9583333333333334);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(-4.999999969612645e-9))
		tmp = single(1.0) / (x / s);
	elseif (x <= single(1.9999999920083944e-12))
		tmp = single(0.5);
	else
		tmp = single(0.9583333333333334);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;\frac{1}{\frac{x}{s}}\\

\mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;0.9583333333333334\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.99999997e-9

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 45.7%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-145.7%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg45.7%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified45.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 43.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{s}{x}} \]
    7. Step-by-step derivation
      1. associate-*r/43.5%

        \[\leadsto \color{blue}{\frac{-1 \cdot s}{x}} \]
      2. neg-mul-143.5%

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    8. Simplified43.5%

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    9. Step-by-step derivation
      1. clear-num45.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{-s}}} \]
      2. inv-pow45.7%

        \[\leadsto \color{blue}{{\left(\frac{x}{-s}\right)}^{-1}} \]
      3. add-sqr-sqrt-0.0%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}\right)}^{-1} \]
      4. sqrt-unprod59.6%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}}\right)}^{-1} \]
      5. sqr-neg59.6%

        \[\leadsto {\left(\frac{x}{\sqrt{\color{blue}{s \cdot s}}}\right)}^{-1} \]
      6. sqrt-unprod45.7%

        \[\leadsto {\left(\frac{x}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}\right)}^{-1} \]
      7. add-sqr-sqrt45.7%

        \[\leadsto {\left(\frac{x}{\color{blue}{s}}\right)}^{-1} \]
    10. Applied egg-rr45.7%

      \[\leadsto \color{blue}{{\left(\frac{x}{s}\right)}^{-1}} \]
    11. Step-by-step derivation
      1. unpow-145.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{s}}} \]
    12. Simplified45.7%

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{s}}} \]

    if -4.99999997e-9 < x < 1.99999999e-12

    1. Initial program 99.4%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 61.1%

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

    if 1.99999999e-12 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 1.5%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.2%

      \[\leadsto \color{blue}{0.9583333333333334} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 16: 49.3% accurate, 9.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{s}{x}\\ \mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0.9583333333333334\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -4.999999969612645e-9)
   (* 0.3333333333333333 (/ s x))
   (if (<= x 1.9999999920083944e-12) 0.5 0.9583333333333334)))
float code(float x, float s) {
	float tmp;
	if (x <= -4.999999969612645e-9f) {
		tmp = 0.3333333333333333f * (s / x);
	} else if (x <= 1.9999999920083944e-12f) {
		tmp = 0.5f;
	} else {
		tmp = 0.9583333333333334f;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= (-4.999999969612645e-9)) then
        tmp = 0.3333333333333333e0 * (s / x)
    else if (x <= 1.9999999920083944e-12) then
        tmp = 0.5e0
    else
        tmp = 0.9583333333333334e0
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(-4.999999969612645e-9))
		tmp = Float32(Float32(0.3333333333333333) * Float32(s / x));
	elseif (x <= Float32(1.9999999920083944e-12))
		tmp = Float32(0.5);
	else
		tmp = Float32(0.9583333333333334);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(-4.999999969612645e-9))
		tmp = single(0.3333333333333333) * (s / x);
	elseif (x <= single(1.9999999920083944e-12))
		tmp = single(0.5);
	else
		tmp = single(0.9583333333333334);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;0.3333333333333333 \cdot \frac{s}{x}\\

\mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;0.9583333333333334\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.99999997e-9

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 45.7%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-145.7%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg45.7%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified45.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 45.7%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(2 \cdot \frac{1}{x} - \frac{1}{s}\right)}} \]
    7. Step-by-step derivation
      1. associate-*r/45.7%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} - \frac{1}{s}\right)} \]
      2. metadata-eval45.7%

        \[\leadsto \frac{1}{x \cdot \left(\frac{\color{blue}{2}}{x} - \frac{1}{s}\right)} \]
    8. Simplified45.7%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{2}{x} - \frac{1}{s}\right)}} \]
    9. Step-by-step derivation
      1. *-un-lft-identity45.7%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} - \color{blue}{1 \cdot \frac{1}{s}}\right)} \]
      2. add-sqr-sqrt-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}}} - 1 \cdot \frac{1}{s}\right)} \]
      3. prod-diff-0.0%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\frac{1}{s} \cdot 1\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)}} \]
      4. associate-/r/-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{\frac{s}{1}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      5. clear-num-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      6. distribute-frac-neg2-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \color{blue}{\frac{1}{-s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      7. add-sqr-sqrt-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      8. sqrt-unprod-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      9. sqr-neg-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\sqrt{\color{blue}{s \cdot s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      10. sqrt-unprod-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      11. add-sqr-sqrt-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      12. fma-define-0.0%

        \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\left(\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}} + \frac{1}{s}\right)} + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
      13. add-sqr-sqrt45.7%

        \[\leadsto \frac{1}{x \cdot \left(\left(\color{blue}{\frac{2}{x}} + \frac{1}{s}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    10. Applied egg-rr46.1%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\left(\frac{2}{x} + \frac{1}{s}\right) + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)}} \]
    11. Step-by-step derivation
      1. associate-+l+46.1%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)\right)}} \]
      2. fma-undefine46.1%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \color{blue}{\left(\frac{1}{s} \cdot 1 + \frac{1}{s}\right)}\right)\right)} \]
      3. *-rgt-identity46.1%

        \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \left(\color{blue}{\frac{1}{s}} + \frac{1}{s}\right)\right)\right)} \]
    12. Simplified46.1%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \left(\frac{1}{s} + \frac{1}{s}\right)\right)\right)}} \]
    13. Taylor expanded in x around inf 44.2%

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{s}{x}} \]

    if -4.99999997e-9 < x < 1.99999999e-12

    1. Initial program 99.4%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 61.1%

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

    if 1.99999999e-12 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 1.5%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.2%

      \[\leadsto \color{blue}{0.9583333333333334} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 17: 49.0% accurate, 9.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\ \;\;\;\;\frac{s}{x}\\ \mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0.9583333333333334\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -4.999999969612645e-9)
   (/ s x)
   (if (<= x 1.9999999920083944e-12) 0.5 0.9583333333333334)))
float code(float x, float s) {
	float tmp;
	if (x <= -4.999999969612645e-9f) {
		tmp = s / x;
	} else if (x <= 1.9999999920083944e-12f) {
		tmp = 0.5f;
	} else {
		tmp = 0.9583333333333334f;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= (-4.999999969612645e-9)) then
        tmp = s / x
    else if (x <= 1.9999999920083944e-12) then
        tmp = 0.5e0
    else
        tmp = 0.9583333333333334e0
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(-4.999999969612645e-9))
		tmp = Float32(s / x);
	elseif (x <= Float32(1.9999999920083944e-12))
		tmp = Float32(0.5);
	else
		tmp = Float32(0.9583333333333334);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(-4.999999969612645e-9))
		tmp = s / x;
	elseif (x <= single(1.9999999920083944e-12))
		tmp = single(0.5);
	else
		tmp = single(0.9583333333333334);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\
\;\;\;\;\frac{s}{x}\\

\mathbf{elif}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;0.9583333333333334\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.99999997e-9

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 45.7%

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    4. Step-by-step derivation
      1. neg-mul-145.7%

        \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
      2. unsub-neg45.7%

        \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    5. Simplified45.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 43.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{s}{x}} \]
    7. Step-by-step derivation
      1. associate-*r/43.5%

        \[\leadsto \color{blue}{\frac{-1 \cdot s}{x}} \]
      2. neg-mul-143.5%

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    8. Simplified43.5%

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    9. Step-by-step derivation
      1. div-inv43.5%

        \[\leadsto \color{blue}{\left(-s\right) \cdot \frac{1}{x}} \]
      2. add-sqr-sqrt-0.0%

        \[\leadsto \color{blue}{\left(\sqrt{-s} \cdot \sqrt{-s}\right)} \cdot \frac{1}{x} \]
      3. sqrt-unprod57.4%

        \[\leadsto \color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}} \cdot \frac{1}{x} \]
      4. sqr-neg57.4%

        \[\leadsto \sqrt{\color{blue}{s \cdot s}} \cdot \frac{1}{x} \]
      5. sqrt-unprod43.5%

        \[\leadsto \color{blue}{\left(\sqrt{s} \cdot \sqrt{s}\right)} \cdot \frac{1}{x} \]
      6. add-sqr-sqrt43.5%

        \[\leadsto \color{blue}{s} \cdot \frac{1}{x} \]
    10. Applied egg-rr43.5%

      \[\leadsto \color{blue}{s \cdot \frac{1}{x}} \]
    11. Step-by-step derivation
      1. associate-*r/43.5%

        \[\leadsto \color{blue}{\frac{s \cdot 1}{x}} \]
      2. *-rgt-identity43.5%

        \[\leadsto \frac{\color{blue}{s}}{x} \]
    12. Simplified43.5%

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

    if -4.99999997e-9 < x < 1.99999999e-12

    1. Initial program 99.4%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 61.1%

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

    if 1.99999999e-12 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 1.5%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.2%

      \[\leadsto \color{blue}{0.9583333333333334} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 18: 37.3% accurate, 17.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0.9583333333333334\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x 1.9999999920083944e-12) 0.5 0.9583333333333334))
float code(float x, float s) {
	float tmp;
	if (x <= 1.9999999920083944e-12f) {
		tmp = 0.5f;
	} else {
		tmp = 0.9583333333333334f;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= 1.9999999920083944e-12) then
        tmp = 0.5e0
    else
        tmp = 0.9583333333333334e0
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(1.9999999920083944e-12))
		tmp = Float32(0.5);
	else
		tmp = Float32(0.9583333333333334);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(1.9999999920083944e-12))
		tmp = single(0.5);
	else
		tmp = single(0.9583333333333334);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;0.9583333333333334\\


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

    1. Initial program 99.7%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 36.7%

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

    if 1.99999999e-12 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{1}{1 + e^{\color{blue}{-\frac{x}{s}}}} \]
      2. exp-neg100.0%

        \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    5. Step-by-step derivation
      1. *-un-lft-identity100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{1 \cdot \frac{x}{s}}}}} \]
      2. exp-prod100.0%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}}} \]
    7. Taylor expanded in s around inf 1.5%

      \[\leadsto \color{blue}{\left(0.5 + -1 \cdot \frac{-0.25 \cdot \left(-1 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + \left(-0.5 \cdot {x}^{3} + 0.16666666666666666 \cdot {x}^{3}\right)\right) + \left(-0.125 \cdot \left(x \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right)\right) + 0.5 \cdot \left(x \cdot \left(-0.25 \cdot \left(-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}\right) + -0.125 \cdot {x}^{2}\right)\right)\right)}{{s}^{3}}\right) - \left(-0.25 \cdot \frac{x}{s} + \left(-0.25 \cdot \frac{-1 \cdot {x}^{2} + 0.5 \cdot {x}^{2}}{{s}^{2}} + -0.125 \cdot \frac{{x}^{2}}{{s}^{2}}\right)\right)} \]
    8. Simplified39.2%

      \[\leadsto \color{blue}{0.9583333333333334} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 19: 34.2% accurate, 108.0× speedup?

\[\begin{array}{l} \\ 0.5 \end{array} \]
(FPCore (x s) :precision binary32 0.5)
float code(float x, float s) {
	return 0.5f;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 0.5e0
end function
function code(x, s)
	return Float32(0.5)
end
function tmp = code(x, s)
	tmp = single(0.5);
end
\begin{array}{l}

\\
0.5
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 33.8%

    \[\leadsto \color{blue}{0.5} \]
  4. Add Preprocessing

Alternative 20: 19.5% accurate, 108.0× speedup?

\[\begin{array}{l} \\ 0.3333333333333333 \end{array} \]
(FPCore (x s) :precision binary32 0.3333333333333333)
float code(float x, float s) {
	return 0.3333333333333333f;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 0.3333333333333333e0
end function
function code(x, s)
	return Float32(0.3333333333333333)
end
function tmp = code(x, s)
	tmp = single(0.3333333333333333);
end
\begin{array}{l}

\\
0.3333333333333333
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 36.7%

    \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
  4. Step-by-step derivation
    1. neg-mul-136.7%

      \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
    2. unsub-neg36.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
  5. Simplified36.7%

    \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
  6. Taylor expanded in x around inf 36.7%

    \[\leadsto \frac{1}{\color{blue}{x \cdot \left(2 \cdot \frac{1}{x} - \frac{1}{s}\right)}} \]
  7. Step-by-step derivation
    1. associate-*r/36.7%

      \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} - \frac{1}{s}\right)} \]
    2. metadata-eval36.7%

      \[\leadsto \frac{1}{x \cdot \left(\frac{\color{blue}{2}}{x} - \frac{1}{s}\right)} \]
  8. Simplified36.7%

    \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{2}{x} - \frac{1}{s}\right)}} \]
  9. Step-by-step derivation
    1. *-un-lft-identity36.7%

      \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} - \color{blue}{1 \cdot \frac{1}{s}}\right)} \]
    2. add-sqr-sqrt14.1%

      \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}}} - 1 \cdot \frac{1}{s}\right)} \]
    3. prod-diff14.0%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\frac{1}{s} \cdot 1\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)}} \]
    4. associate-/r/14.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{\frac{s}{1}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    5. clear-num14.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    6. distribute-frac-neg214.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \color{blue}{\frac{1}{-s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    7. add-sqr-sqrt-0.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    8. sqrt-unprod12.5%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    9. sqr-neg12.5%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\sqrt{\color{blue}{s \cdot s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    10. sqrt-unprod14.9%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    11. add-sqr-sqrt14.9%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    12. fma-define14.9%

      \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\left(\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}} + \frac{1}{s}\right)} + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    13. add-sqr-sqrt36.9%

      \[\leadsto \frac{1}{x \cdot \left(\left(\color{blue}{\frac{2}{x}} + \frac{1}{s}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
  10. Applied egg-rr36.7%

    \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\left(\frac{2}{x} + \frac{1}{s}\right) + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)}} \]
  11. Step-by-step derivation
    1. associate-+l+36.8%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)\right)}} \]
    2. fma-undefine36.8%

      \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \color{blue}{\left(\frac{1}{s} \cdot 1 + \frac{1}{s}\right)}\right)\right)} \]
    3. *-rgt-identity36.8%

      \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \left(\color{blue}{\frac{1}{s}} + \frac{1}{s}\right)\right)\right)} \]
  12. Simplified36.8%

    \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \left(\frac{1}{s} + \frac{1}{s}\right)\right)\right)}} \]
  13. Taylor expanded in x around inf 18.9%

    \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{s}{x}} \]
  14. Simplified19.7%

    \[\leadsto \color{blue}{0.3333333333333333} \]
  15. Add Preprocessing

Alternative 21: 17.1% accurate, 108.0× speedup?

\[\begin{array}{l} \\ 0.1111111111111111 \end{array} \]
(FPCore (x s) :precision binary32 0.1111111111111111)
float code(float x, float s) {
	return 0.1111111111111111f;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 0.1111111111111111e0
end function
function code(x, s)
	return Float32(0.1111111111111111)
end
function tmp = code(x, s)
	tmp = single(0.1111111111111111);
end
\begin{array}{l}

\\
0.1111111111111111
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 36.7%

    \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
  4. Step-by-step derivation
    1. neg-mul-136.7%

      \[\leadsto \frac{1}{2 + \color{blue}{\left(-\frac{x}{s}\right)}} \]
    2. unsub-neg36.7%

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
  5. Simplified36.7%

    \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
  6. Taylor expanded in x around inf 36.7%

    \[\leadsto \frac{1}{\color{blue}{x \cdot \left(2 \cdot \frac{1}{x} - \frac{1}{s}\right)}} \]
  7. Step-by-step derivation
    1. associate-*r/36.7%

      \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\frac{2 \cdot 1}{x}} - \frac{1}{s}\right)} \]
    2. metadata-eval36.7%

      \[\leadsto \frac{1}{x \cdot \left(\frac{\color{blue}{2}}{x} - \frac{1}{s}\right)} \]
  8. Simplified36.7%

    \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{2}{x} - \frac{1}{s}\right)}} \]
  9. Step-by-step derivation
    1. *-un-lft-identity36.7%

      \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} - \color{blue}{1 \cdot \frac{1}{s}}\right)} \]
    2. add-sqr-sqrt14.1%

      \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}}} - 1 \cdot \frac{1}{s}\right)} \]
    3. prod-diff14.0%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\frac{1}{s} \cdot 1\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)}} \]
    4. associate-/r/14.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{\frac{s}{1}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    5. clear-num14.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, -\color{blue}{\frac{1}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    6. distribute-frac-neg214.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \color{blue}{\frac{1}{-s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    7. add-sqr-sqrt-0.0%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    8. sqrt-unprod12.5%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    9. sqr-neg12.5%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\sqrt{\color{blue}{s \cdot s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    10. sqrt-unprod14.9%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    11. add-sqr-sqrt14.9%

      \[\leadsto \frac{1}{x \cdot \left(\mathsf{fma}\left(\sqrt{\frac{2}{x}}, \sqrt{\frac{2}{x}}, \frac{1}{\color{blue}{s}}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    12. fma-define14.9%

      \[\leadsto \frac{1}{x \cdot \left(\color{blue}{\left(\sqrt{\frac{2}{x}} \cdot \sqrt{\frac{2}{x}} + \frac{1}{s}\right)} + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
    13. add-sqr-sqrt36.9%

      \[\leadsto \frac{1}{x \cdot \left(\left(\color{blue}{\frac{2}{x}} + \frac{1}{s}\right) + \mathsf{fma}\left(-\frac{1}{s}, 1, \frac{1}{s} \cdot 1\right)\right)} \]
  10. Applied egg-rr36.7%

    \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\left(\frac{2}{x} + \frac{1}{s}\right) + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)}} \]
  11. Step-by-step derivation
    1. associate-+l+36.8%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \mathsf{fma}\left(\frac{1}{s}, 1, \frac{1}{s}\right)\right)\right)}} \]
    2. fma-undefine36.8%

      \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \color{blue}{\left(\frac{1}{s} \cdot 1 + \frac{1}{s}\right)}\right)\right)} \]
    3. *-rgt-identity36.8%

      \[\leadsto \frac{1}{x \cdot \left(\frac{2}{x} + \left(\frac{1}{s} + \left(\color{blue}{\frac{1}{s}} + \frac{1}{s}\right)\right)\right)} \]
  12. Simplified36.8%

    \[\leadsto \frac{1}{x \cdot \color{blue}{\left(\frac{2}{x} + \left(\frac{1}{s} + \left(\frac{1}{s} + \frac{1}{s}\right)\right)\right)}} \]
  13. Taylor expanded in s around 0 17.0%

    \[\leadsto \color{blue}{s \cdot \left(-0.2222222222222222 \cdot \frac{s}{{x}^{2}} + 0.3333333333333333 \cdot \frac{1}{x}\right)} \]
  14. Simplified17.3%

    \[\leadsto \color{blue}{0.1111111111111111} \]
  15. Add Preprocessing

Reproduce

?
herbie shell --seed 2024137 
(FPCore (x s)
  :name "Logistic function"
  :precision binary32
  :pre (and (<= 0.0 s) (<= s 1.0651631))
  (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))