Logistic function

Percentage Accurate: 99.8% → 99.8%
Time: 9.0s
Alternatives: 20
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 20 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.8% accurate, 0.3× speedup?

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

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

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. 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}}}}} \]
  3. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  4. Step-by-step derivation
    1. add-exp-log99.8%

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

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

      \[\leadsto \frac{1}{1 + e^{\color{blue}{-1 \cdot \log \left(e^{\frac{x}{s}}\right)}}} \]
    4. add-log-exp99.8%

      \[\leadsto \frac{1}{1 + e^{-1 \cdot \color{blue}{\frac{x}{s}}}} \]
    5. pow-exp99.8%

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

      \[\leadsto \frac{1}{1 + {\color{blue}{\left(\sqrt{e^{-1}} \cdot \sqrt{e^{-1}}\right)}}^{\left(\frac{x}{s}\right)}} \]
    7. unpow-prod-down99.8%

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

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

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

      \[\leadsto \frac{1}{1 + {\left(\sqrt{e^{-1}}\right)}^{\color{blue}{\left(\frac{x}{s} + \frac{x}{s}\right)}}} \]
    3. *-rgt-identity99.8%

      \[\leadsto \frac{1}{1 + {\left(\sqrt{e^{-1}}\right)}^{\left(\color{blue}{\frac{x}{s} \cdot 1} + \frac{x}{s}\right)}} \]
    4. *-rgt-identity99.8%

      \[\leadsto \frac{1}{1 + {\left(\sqrt{e^{-1}}\right)}^{\left(\frac{x}{s} \cdot 1 + \color{blue}{\frac{x}{s} \cdot 1}\right)}} \]
    5. distribute-lft-out99.8%

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

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

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

    \[\leadsto \frac{1}{1 + {\left(\sqrt{e^{-1}}\right)}^{\left(\frac{x}{s} \cdot 2\right)}} \]

Alternative 2: 99.8% accurate, 0.5× speedup?

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

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

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. 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}}}}} \]
  3. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  4. Step-by-step derivation
    1. add-exp-log99.8%

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

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

      \[\leadsto \frac{1}{1 + e^{\color{blue}{-1 \cdot \log \left(e^{\frac{x}{s}}\right)}}} \]
    4. add-log-exp99.8%

      \[\leadsto \frac{1}{1 + e^{-1 \cdot \color{blue}{\frac{x}{s}}}} \]
    5. pow-exp99.8%

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{1 + {\left(e^{-2}\right)}^{\left(\frac{x}{s} \cdot 0.5\right)}} \]

Alternative 3: 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. 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}}}}} \]
  3. Applied egg-rr99.8%

    \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
  4. Final simplification99.8%

    \[\leadsto \frac{1}{1 + \frac{1}{e^{\frac{x}{s}}}} \]

Alternative 4: 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}
Derivation
  1. Initial program 99.8%

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

    \[\leadsto \frac{1}{1 + e^{\frac{-x}{s}}} \]

Alternative 5: 88.9% accurate, 5.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(0.5 \cdot \left(\left(x \cdot x\right) \cdot \frac{1}{s \cdot s}\right) - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -8.999999840607448e-23)
   (/ 1.0 (+ 2.0 (- (* 0.5 (* (* x x) (/ 1.0 (* s s)))) (/ x s))))
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -8.999999840607448e-23f) {
		tmp = 1.0f / (2.0f + ((0.5f * ((x * x) * (1.0f / (s * s)))) - (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 <= (-8.999999840607448e-23)) then
        tmp = 1.0e0 / (2.0e0 + ((0.5e0 * ((x * x) * (1.0e0 / (s * s)))) - (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(-8.999999840607448e-23))
		tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x * x) * Float32(Float32(1.0) / Float32(s * s)))) - 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(-8.999999840607448e-23))
		tmp = single(1.0) / (single(2.0) + ((single(0.5) * ((x * x) * (single(1.0) / (s * s)))) - (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 -8.999999840607448 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \left(\left(x \cdot x\right) \cdot \frac{1}{s \cdot s}\right) - \frac{x}{s}\right)}\\

\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 < -8.99999984e-23

    1. Initial program 99.6%

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + -1 \cdot \frac{x}{s}\right)}} \]
    3. Step-by-step derivation
      1. mul-1-neg80.5%

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + \color{blue}{\left(-\frac{x}{s}\right)}\right)} \]
      2. unsub-neg80.5%

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac75.6%

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

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

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

      \[\leadsto \frac{1}{2 + \left(0.5 \cdot \color{blue}{\frac{x \cdot x}{s \cdot s}} - \frac{x}{s}\right)} \]
    7. Step-by-step derivation
      1. div-inv81.1%

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

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

    if -8.99999984e-23 < x

    1. Initial program 99.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(0.5 \cdot \left(\left(x \cdot x\right) \cdot \frac{1}{s \cdot s}\right) - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]

Alternative 6: 88.0% accurate, 5.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{s \cdot s} - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -8.999999840607448e-23)
   (/ 1.0 (+ 2.0 (- (* 0.5 (/ (* x x) (* s s))) (/ x s))))
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -8.999999840607448e-23f) {
		tmp = 1.0f / (2.0f + ((0.5f * ((x * x) / (s * s))) - (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 <= (-8.999999840607448e-23)) then
        tmp = 1.0e0 / (2.0e0 + ((0.5e0 * ((x * x) / (s * s))) - (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(-8.999999840607448e-23))
		tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) * Float32(Float32(x * x) / Float32(s * s))) - 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(-8.999999840607448e-23))
		tmp = single(1.0) / (single(2.0) + ((single(0.5) * ((x * x) / (s * s))) - (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 -8.999999840607448 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{s \cdot s} - \frac{x}{s}\right)}\\

\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 < -8.99999984e-23

    1. Initial program 99.6%

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + -1 \cdot \frac{x}{s}\right)}} \]
    3. Step-by-step derivation
      1. mul-1-neg80.5%

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + \color{blue}{\left(-\frac{x}{s}\right)}\right)} \]
      2. unsub-neg80.5%

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac75.6%

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

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

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

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

    if -8.99999984e-23 < x

    1. Initial program 99.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{s \cdot s} - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]

Alternative 7: 88.0% accurate, 5.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(\frac{0.5}{\frac{s \cdot s}{x \cdot x}} - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -8.999999840607448e-23)
   (/ 1.0 (+ 2.0 (- (/ 0.5 (/ (* s s) (* x x))) (/ x s))))
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -8.999999840607448e-23f) {
		tmp = 1.0f / (2.0f + ((0.5f / ((s * s) / (x * 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 <= (-8.999999840607448e-23)) then
        tmp = 1.0e0 / (2.0e0 + ((0.5e0 / ((s * s) / (x * 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(-8.999999840607448e-23))
		tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(0.5) / Float32(Float32(s * s) / Float32(x * 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(-8.999999840607448e-23))
		tmp = single(1.0) / (single(2.0) + ((single(0.5) / ((s * s) / (x * 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 -8.999999840607448 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{2 + \left(\frac{0.5}{\frac{s \cdot s}{x \cdot x}} - \frac{x}{s}\right)}\\

\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 < -8.99999984e-23

    1. Initial program 99.6%

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + -1 \cdot \frac{x}{s}\right)}} \]
    3. Step-by-step derivation
      1. mul-1-neg80.5%

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + \color{blue}{\left(-\frac{x}{s}\right)}\right)} \]
      2. unsub-neg80.5%

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac75.6%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \left(\color{blue}{\frac{0.5}{\frac{\frac{s}{x}}{\frac{x}{s}}}} - \frac{x}{s}\right)} \]
      2. associate-/r*75.0%

        \[\leadsto \frac{1}{2 + \left(\frac{0.5}{\color{blue}{\frac{s}{x \cdot \frac{x}{s}}}} - \frac{x}{s}\right)} \]
      3. associate-*r/75.0%

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

        \[\leadsto \frac{1}{2 + \left(\frac{0.5}{\frac{s}{\frac{\color{blue}{{x}^{2}}}{s}}} - \frac{x}{s}\right)} \]
      5. associate-/l*80.5%

        \[\leadsto \frac{1}{2 + \left(\frac{0.5}{\color{blue}{\frac{s \cdot s}{{x}^{2}}}} - \frac{x}{s}\right)} \]
      6. unpow280.5%

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

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

    if -8.99999984e-23 < x

    1. Initial program 99.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(\frac{0.5}{\frac{s \cdot s}{x \cdot x}} - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]

Alternative 8: 88.0% accurate, 5.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{\left(2 - \frac{x}{s}\right) - \frac{\left(x \cdot x\right) \cdot -0.5}{s \cdot s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -8.999999840607448e-23)
   (/ 1.0 (- (- 2.0 (/ x s)) (/ (* (* x x) -0.5) (* s s))))
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -8.999999840607448e-23f) {
		tmp = 1.0f / ((2.0f - (x / s)) - (((x * x) * -0.5f) / (s * 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 <= (-8.999999840607448e-23)) then
        tmp = 1.0e0 / ((2.0e0 - (x / s)) - (((x * x) * (-0.5e0)) / (s * 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(-8.999999840607448e-23))
		tmp = Float32(Float32(1.0) / Float32(Float32(Float32(2.0) - Float32(x / s)) - Float32(Float32(Float32(x * x) * Float32(-0.5)) / Float32(s * 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(-8.999999840607448e-23))
		tmp = single(1.0) / ((single(2.0) - (x / s)) - (((x * x) * single(-0.5)) / (s * 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 -8.999999840607448 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{\left(2 - \frac{x}{s}\right) - \frac{\left(x \cdot x\right) \cdot -0.5}{s \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 < -8.99999984e-23

    1. Initial program 99.6%

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

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

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

      \[\leadsto \frac{1}{1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}} \]
    4. Taylor expanded in s around inf 45.3%

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{0.5 \cdot {x}^{2} + -1 \cdot {x}^{2}}{{s}^{2}} + \left(2 + -1 \cdot \frac{x}{s}\right)}} \]
    5. Step-by-step derivation
      1. +-commutative45.3%

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(2 - \frac{x}{s}\right)} + -1 \cdot \frac{0.5 \cdot {x}^{2} + -1 \cdot {x}^{2}}{{s}^{2}}} \]
      4. mul-1-neg45.3%

        \[\leadsto \frac{1}{\left(2 - \frac{x}{s}\right) + \color{blue}{\left(-\frac{0.5 \cdot {x}^{2} + -1 \cdot {x}^{2}}{{s}^{2}}\right)}} \]
      5. unsub-neg45.3%

        \[\leadsto \frac{1}{\color{blue}{\left(2 - \frac{x}{s}\right) - \frac{0.5 \cdot {x}^{2} + -1 \cdot {x}^{2}}{{s}^{2}}}} \]
      6. distribute-rgt-out80.5%

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

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

        \[\leadsto \frac{1}{\left(2 - \frac{x}{s}\right) - \frac{{x}^{2} \cdot -0.5}{\color{blue}{s \cdot s}}} \]
      9. times-frac75.0%

        \[\leadsto \frac{1}{\left(2 - \frac{x}{s}\right) - \color{blue}{\frac{{x}^{2}}{s} \cdot \frac{-0.5}{s}}} \]
      10. unpow275.0%

        \[\leadsto \frac{1}{\left(2 - \frac{x}{s}\right) - \frac{\color{blue}{x \cdot x}}{s} \cdot \frac{-0.5}{s}} \]
    6. Simplified75.0%

      \[\leadsto \frac{1}{\color{blue}{\left(2 - \frac{x}{s}\right) - \frac{x \cdot x}{s} \cdot \frac{-0.5}{s}}} \]
    7. Step-by-step derivation
      1. frac-times80.5%

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

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

    if -8.99999984e-23 < x

    1. Initial program 99.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{\left(2 - \frac{x}{s}\right) - \frac{\left(x \cdot x\right) \cdot -0.5}{s \cdot s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]

Alternative 9: 87.9% accurate, 6.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(\frac{x \cdot x}{s \cdot s} - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -8.999999840607448e-23)
   (/ 1.0 (+ 2.0 (- (/ (* x x) (* s s)) (/ x s))))
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -8.999999840607448e-23f) {
		tmp = 1.0f / (2.0f + (((x * x) / (s * s)) - (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 <= (-8.999999840607448e-23)) then
        tmp = 1.0e0 / (2.0e0 + (((x * x) / (s * s)) - (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(-8.999999840607448e-23))
		tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(Float32(Float32(x * x) / Float32(s * s)) - 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(-8.999999840607448e-23))
		tmp = single(1.0) / (single(2.0) + (((x * x) / (s * s)) - (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 -8.999999840607448 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{2 + \left(\frac{x \cdot x}{s \cdot s} - \frac{x}{s}\right)}\\

\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 < -8.99999984e-23

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \left(\frac{x \cdot x}{s \cdot s} + \color{blue}{\left(-\frac{x}{s}\right)}\right)} \]
      4. distribute-neg-frac80.4%

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

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

    if -8.99999984e-23 < x

    1. Initial program 99.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.999999840607448 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{2 + \left(\frac{x \cdot x}{s \cdot s} - \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]

Alternative 10: 84.8% accurate, 8.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.0000000843119176 \cdot 10^{-17}:\\ \;\;\;\;\frac{\frac{2 \cdot \left(s \cdot s\right)}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -5.0000000843119176e-17)
   (/ (/ (* 2.0 (* s s)) x) x)
   (/ 1.0 (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -5.0000000843119176e-17f) {
		tmp = ((2.0f * (s * s)) / x) / x;
	} 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.0000000843119176e-17)) then
        tmp = ((2.0e0 * (s * s)) / x) / x
    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.0000000843119176e-17))
		tmp = Float32(Float32(Float32(Float32(2.0) * Float32(s * s)) / x) / x);
	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.0000000843119176e-17))
		tmp = ((single(2.0) * (s * s)) / x) / x;
	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.0000000843119176 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{2 \cdot \left(s \cdot s\right)}{x}}{x}\\

\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.00000008e-17

    1. Initial program 99.8%

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + -1 \cdot \frac{x}{s}\right)}} \]
    3. Step-by-step derivation
      1. mul-1-neg80.5%

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + \color{blue}{\left(-\frac{x}{s}\right)}\right)} \]
      2. unsub-neg80.5%

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac75.9%

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{{s}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. unpow278.3%

        \[\leadsto 2 \cdot \frac{{s}^{2}}{\color{blue}{x \cdot x}} \]
      2. unpow278.3%

        \[\leadsto 2 \cdot \frac{\color{blue}{s \cdot s}}{x \cdot x} \]
    7. Simplified78.3%

      \[\leadsto \color{blue}{2 \cdot \frac{s \cdot s}{x \cdot x}} \]
    8. Taylor expanded in s around 0 78.3%

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

        \[\leadsto \color{blue}{\frac{2 \cdot {s}^{2}}{{x}^{2}}} \]
      2. unpow278.3%

        \[\leadsto \frac{2 \cdot {s}^{2}}{\color{blue}{x \cdot x}} \]
      3. unpow278.3%

        \[\leadsto \frac{2 \cdot \color{blue}{\left(s \cdot s\right)}}{x \cdot x} \]
      4. associate-/r*78.3%

        \[\leadsto \color{blue}{\frac{\frac{2 \cdot \left(s \cdot s\right)}{x}}{x}} \]
    10. Simplified78.3%

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

    if -5.00000008e-17 < x

    1. Initial program 99.7%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.0000000843119176 \cdot 10^{-17}:\\ \;\;\;\;\frac{\frac{2 \cdot \left(s \cdot s\right)}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{1 + \frac{x}{s}}}\\ \end{array} \]

Alternative 11: 66.9% accurate, 9.6× speedup?

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

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

\mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    7. Simplified40.3%

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    8. Step-by-step derivation
      1. div-inv40.3%

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

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

    if -3.99999993e-14 < x < 1.60000005e-21

    1. Initial program 99.4%

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

      \[\leadsto \color{blue}{0.5 + 0.25 \cdot \frac{x}{s}} \]
    3. Step-by-step derivation
      1. *-commutative71.2%

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

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

    if 1.60000005e-21 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 88.4%

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

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

        \[\leadsto \color{blue}{\frac{-s}{x}} + 1 \]
      3. +-commutative88.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.99999992980668 \cdot 10^{-14}:\\ \;\;\;\;s \cdot \frac{-1}{x}\\ \mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\ \;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{s}{x}\\ \end{array} \]

Alternative 12: 67.4% accurate, 9.6× speedup?

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

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

\mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    7. Simplified40.3%

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    8. Step-by-step derivation
      1. div-inv40.3%

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

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

    if -3.99999993e-14 < x < 1.60000005e-21

    1. Initial program 99.4%

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

      \[\leadsto \color{blue}{0.5 + 0.25 \cdot \frac{x}{s}} \]
    3. Step-by-step derivation
      1. *-commutative71.2%

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

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

    if 1.60000005e-21 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 89.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.99999992980668 \cdot 10^{-14}:\\ \;\;\;\;s \cdot \frac{-1}{x}\\ \mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\ \;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{s}{x}}\\ \end{array} \]

Alternative 13: 79.2% accurate, 9.6× speedup?

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

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

\mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + -1 \cdot \frac{x}{s}\right)}} \]
    3. Step-by-step derivation
      1. mul-1-neg79.7%

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

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac77.8%

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{{s}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. unpow278.7%

        \[\leadsto 2 \cdot \frac{{s}^{2}}{\color{blue}{x \cdot x}} \]
      2. unpow278.7%

        \[\leadsto 2 \cdot \frac{\color{blue}{s \cdot s}}{x \cdot x} \]
      3. times-frac76.5%

        \[\leadsto 2 \cdot \color{blue}{\left(\frac{s}{x} \cdot \frac{s}{x}\right)} \]
    7. Simplified76.5%

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

    if -3.99999993e-14 < x < 1.60000005e-21

    1. Initial program 99.4%

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

      \[\leadsto \color{blue}{0.5 + 0.25 \cdot \frac{x}{s}} \]
    3. Step-by-step derivation
      1. *-commutative71.2%

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

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

    if 1.60000005e-21 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 89.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.99999992980668 \cdot 10^{-14}:\\ \;\;\;\;2 \cdot \left(\frac{s}{x} \cdot \frac{s}{x}\right)\\ \mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\ \;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{s}{x}}\\ \end{array} \]

Alternative 14: 80.7% accurate, 9.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.0000000843119176 \cdot 10^{-17}:\\
\;\;\;\;2 \cdot \frac{s \cdot s}{x \cdot x}\\

\mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + -1 \cdot \frac{x}{s}\right)}} \]
    3. Step-by-step derivation
      1. mul-1-neg80.5%

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + \color{blue}{\left(-\frac{x}{s}\right)}\right)} \]
      2. unsub-neg80.5%

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac75.9%

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{{s}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. unpow278.3%

        \[\leadsto 2 \cdot \frac{{s}^{2}}{\color{blue}{x \cdot x}} \]
      2. unpow278.3%

        \[\leadsto 2 \cdot \frac{\color{blue}{s \cdot s}}{x \cdot x} \]
    7. Simplified78.3%

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

    if -5.00000008e-17 < x < 1.60000005e-21

    1. Initial program 99.4%

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

      \[\leadsto \color{blue}{0.5 + 0.25 \cdot \frac{x}{s}} \]
    3. Step-by-step derivation
      1. *-commutative74.8%

        \[\leadsto 0.5 + \color{blue}{\frac{x}{s} \cdot 0.25} \]
    4. Simplified74.8%

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

    if 1.60000005e-21 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 89.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.0000000843119176 \cdot 10^{-17}:\\ \;\;\;\;2 \cdot \frac{s \cdot s}{x \cdot x}\\ \mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\ \;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{s}{x}}\\ \end{array} \]

Alternative 15: 80.7% accurate, 9.6× speedup?

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

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

\mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\
\;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + -1 \cdot \frac{x}{s}\right)}} \]
    3. Step-by-step derivation
      1. mul-1-neg80.5%

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{{x}^{2}}{{s}^{2}} + \color{blue}{\left(-\frac{x}{s}\right)}\right)} \]
      2. unsub-neg80.5%

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac75.9%

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{{s}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. unpow278.3%

        \[\leadsto 2 \cdot \frac{{s}^{2}}{\color{blue}{x \cdot x}} \]
      2. unpow278.3%

        \[\leadsto 2 \cdot \frac{\color{blue}{s \cdot s}}{x \cdot x} \]
    7. Simplified78.3%

      \[\leadsto \color{blue}{2 \cdot \frac{s \cdot s}{x \cdot x}} \]
    8. Taylor expanded in s around 0 78.3%

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

        \[\leadsto \color{blue}{\frac{2 \cdot {s}^{2}}{{x}^{2}}} \]
      2. unpow278.3%

        \[\leadsto \frac{2 \cdot {s}^{2}}{\color{blue}{x \cdot x}} \]
      3. unpow278.3%

        \[\leadsto \frac{2 \cdot \color{blue}{\left(s \cdot s\right)}}{x \cdot x} \]
      4. associate-/r*78.3%

        \[\leadsto \color{blue}{\frac{\frac{2 \cdot \left(s \cdot s\right)}{x}}{x}} \]
    10. Simplified78.3%

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

    if -5.00000008e-17 < x < 1.60000005e-21

    1. Initial program 99.4%

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

      \[\leadsto \color{blue}{0.5 + 0.25 \cdot \frac{x}{s}} \]
    3. Step-by-step derivation
      1. *-commutative74.8%

        \[\leadsto 0.5 + \color{blue}{\frac{x}{s} \cdot 0.25} \]
    4. Simplified74.8%

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

    if 1.60000005e-21 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 89.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.0000000843119176 \cdot 10^{-17}:\\ \;\;\;\;\frac{\frac{2 \cdot \left(s \cdot s\right)}{x}}{x}\\ \mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\ \;\;\;\;0.5 + \frac{x}{s} \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{s}{x}}\\ \end{array} \]

Alternative 16: 66.1% accurate, 11.7× speedup?

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

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

\mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\
\;\;\;\;0.5\\

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    7. Simplified40.3%

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

    if -3.99999993e-14 < x < 1.60000005e-21

    1. Initial program 99.4%

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

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

    if 1.60000005e-21 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 88.4%

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

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

        \[\leadsto \color{blue}{\frac{-s}{x}} + 1 \]
      3. +-commutative88.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.99999992980668 \cdot 10^{-14}:\\ \;\;\;\;\frac{-s}{x}\\ \mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{s}{x}\\ \end{array} \]

Alternative 17: 66.1% accurate, 11.7× speedup?

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

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

\mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\
\;\;\;\;0.5\\

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    7. Simplified40.3%

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    8. Step-by-step derivation
      1. div-inv40.3%

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

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

    if -3.99999993e-14 < x < 1.60000005e-21

    1. Initial program 99.4%

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

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

    if 1.60000005e-21 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 88.4%

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

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

        \[\leadsto \color{blue}{\frac{-s}{x}} + 1 \]
      3. +-commutative88.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.99999992980668 \cdot 10^{-14}:\\ \;\;\;\;s \cdot \frac{-1}{x}\\ \mathbf{elif}\;x \leq 1.600000050199032 \cdot 10^{-21}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{s}{x}\\ \end{array} \]

Alternative 18: 68.3% accurate, 11.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.000000136226006 \cdot 10^{-28}:\\
\;\;\;\;\frac{1}{2 - \frac{x}{s}}\\

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


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

    1. Initial program 99.6%

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

      \[\leadsto \frac{1}{\color{blue}{2 + -1 \cdot \frac{x}{s}}} \]
    3. Step-by-step derivation
      1. mul-1-neg54.8%

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

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

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

    if 5.00000014e-28 < x

    1. Initial program 100.0%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. 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}}}}} \]
    3. Applied egg-rr100.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + \frac{x}{s}}}} \]
    5. Taylor expanded in x around inf 85.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.000000136226006 \cdot 10^{-28}:\\ \;\;\;\;\frac{1}{2 - \frac{x}{s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{s}{x}}\\ \end{array} \]

Alternative 19: 44.9% accurate, 17.6× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0.5\\


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    7. Simplified40.3%

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

    if -3.99999993e-14 < x

    1. Initial program 99.7%

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

      \[\leadsto \color{blue}{0.5} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification44.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.99999992980668 \cdot 10^{-14}:\\ \;\;\;\;\frac{-s}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]

Alternative 20: 34.0% 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. Taylor expanded in x around 0 33.6%

    \[\leadsto \color{blue}{0.5} \]
  3. Final simplification33.6%

    \[\leadsto 0.5 \]

Reproduce

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