Logistic function

Percentage Accurate: 99.8% → 99.8%
Time: 10.2s
Alternatives: 10
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 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.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, 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. Add Preprocessing
  3. Final simplification99.8%

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

Alternative 2: 81.4% accurate, 4.0× speedup?

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

\mathbf{elif}\;x \leq -2.000000047484456 \cdot 10^{-33}:\\
\;\;\;\;\frac{1}{\frac{4 - x \cdot \frac{\frac{x}{s}}{s}}{2 + \frac{x}{s}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4e3

    1. Initial program 100.0%

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

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

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

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

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

      \[\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/60.5%

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

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

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

    if -4e3 < x < -2.00000005e-33

    1. Initial program 99.4%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Step-by-step derivation
      1. sub-neg47.0%

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{4 - \frac{x}{-s} \cdot \frac{x}{-s}}{2 - \color{blue}{\frac{x}{-s}}}} \]
    7. Applied egg-rr58.3%

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

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

        \[\leadsto \frac{1}{\frac{4 - \frac{\frac{x}{-s} \cdot x}{\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}}}{2 - \frac{x}{-s}}} \]
      3. sqrt-unprod64.2%

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

        \[\leadsto \frac{1}{\frac{4 - \frac{\frac{x}{-s} \cdot x}{\sqrt{\color{blue}{s \cdot s}}}}{2 - \frac{x}{-s}}} \]
      5. sqrt-unprod56.6%

        \[\leadsto \frac{1}{\frac{4 - \frac{\frac{x}{-s} \cdot x}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}}{2 - \frac{x}{-s}}} \]
      6. add-sqr-sqrt56.6%

        \[\leadsto \frac{1}{\frac{4 - \frac{\frac{x}{-s} \cdot x}{\color{blue}{s}}}{2 - \frac{x}{-s}}} \]
      7. remove-double-neg56.6%

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

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

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

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\left(-\frac{x}{-s}\right) \cdot \frac{x}{-s}}}{2 - \frac{x}{-s}}} \]
      11. distribute-frac-neg256.6%

        \[\leadsto \frac{1}{\frac{4 - \left(-\color{blue}{\left(-\frac{x}{s}\right)}\right) \cdot \frac{x}{-s}}{2 - \frac{x}{-s}}} \]
      12. remove-double-neg56.6%

        \[\leadsto \frac{1}{\frac{4 - \color{blue}{\frac{x}{s}} \cdot \frac{x}{-s}}{2 - \frac{x}{-s}}} \]
      13. distribute-frac-neg256.6%

        \[\leadsto \frac{1}{\frac{4 - \frac{x}{s} \cdot \color{blue}{\left(-\frac{x}{s}\right)}}{2 - \frac{x}{-s}}} \]
      14. distribute-frac-neg56.6%

        \[\leadsto \frac{1}{\frac{4 - \frac{x}{s} \cdot \color{blue}{\frac{-x}{s}}}{2 - \frac{x}{-s}}} \]
      15. associate-*r/56.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{4 - \frac{\sqrt{\color{blue}{x \cdot x}}}{1} \cdot \frac{\frac{x}{s}}{s}}{2 - \frac{x}{-s}}} \]
      7. sqrt-unprod-0.0%

        \[\leadsto \frac{1}{\frac{4 - \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{1} \cdot \frac{\frac{x}{s}}{s}}{2 - \frac{x}{-s}}} \]
      8. add-sqr-sqrt65.7%

        \[\leadsto \frac{1}{\frac{4 - \frac{\color{blue}{x}}{1} \cdot \frac{\frac{x}{s}}{s}}{2 - \frac{x}{-s}}} \]
    11. Applied egg-rr65.7%

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

    if -2.00000005e-33 < 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-neg99.9%

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

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

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

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

Alternative 3: 48.9% accurate, 6.3× speedup?

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

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

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


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

    1. Initial program 99.9%

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

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

    if -1e-28 < (neg.f32 x)

    1. Initial program 99.7%

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

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

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

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

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

      \[\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/60.5%

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

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

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

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

Alternative 4: 75.2% accurate, 6.7× speedup?

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

    1. Initial program 99.7%

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

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

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

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

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

      \[\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/52.6%

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

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

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

    if -1e-28 < x

    1. Initial program 99.9%

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

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

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

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

Alternative 5: 49.1% accurate, 8.3× speedup?

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

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

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


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

    1. Initial program 99.9%

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

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

    if -1e-28 < (neg.f32 x)

    1. Initial program 99.7%

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

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

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

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

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

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

Alternative 6: 48.1% accurate, 9.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;-x \leq 1:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{s}}\\ \end{array} \end{array} \]
(FPCore (x s) :precision binary32 (if (<= (- x) 1.0) 0.5 (/ 1.0 (/ x s))))
float code(float x, float s) {
	float tmp;
	if (-x <= 1.0f) {
		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) :: tmp
    if (-x <= 1.0e0) then
        tmp = 0.5e0
    else
        tmp = 1.0e0 / (x / s)
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (Float32(-x) <= Float32(1.0))
		tmp = Float32(0.5);
	else
		tmp = 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.0))
		tmp = single(0.5);
	else
		tmp = single(1.0) / (x / s);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;-x \leq 1:\\
\;\;\;\;0.5\\

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


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

    1. Initial program 99.8%

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

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

    if 1 < (neg.f32 x)

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    8. Simplified47.7%

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

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

        \[\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-unprod62.9%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{s}}} \]
    12. Simplified55.3%

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

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

Alternative 7: 48.1% accurate, 9.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;-x \leq 3.9999998989515007 \cdot 10^{-5}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x}{s}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= (- x) 3.9999998989515007e-5) 0.5 (/ -1.0 (/ x s))))
float code(float x, float s) {
	float tmp;
	if (-x <= 3.9999998989515007e-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) :: tmp
    if (-x <= 3.9999998989515007e-5) then
        tmp = 0.5e0
    else
        tmp = (-1.0e0) / (x / s)
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (Float32(-x) <= Float32(3.9999998989515007e-5))
		tmp = Float32(0.5);
	else
		tmp = Float32(Float32(-1.0) / Float32(x / s));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (-x <= single(3.9999998989515007e-5))
		tmp = single(0.5);
	else
		tmp = single(-1.0) / (x / s);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (neg.f32 x) < 3.9999999e-5

    1. Initial program 99.8%

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

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

    if 3.9999999e-5 < (neg.f32 x)

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

Alternative 8: 46.8% accurate, 12.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.00019999999494757503:\\ \;\;\;\;\frac{s}{-x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x -0.00019999999494757503) (/ s (- x)) 0.5))
float code(float x, float s) {
	float tmp;
	if (x <= -0.00019999999494757503f) {
		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 <= (-0.00019999999494757503e0)) 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(-0.00019999999494757503))
		tmp = Float32(s / Float32(-x));
	else
		tmp = Float32(0.5);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(-0.00019999999494757503))
		tmp = s / -x;
	else
		tmp = single(0.5);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    8. Simplified44.7%

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

    if -1.99999995e-4 < x

    1. Initial program 99.8%

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

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

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

Alternative 9: 46.7% accurate, 13.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{s}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \end{array} \]
(FPCore (x s) :precision binary32 (if (<= x -1.0) (/ s x) 0.5))
float code(float x, float s) {
	float tmp;
	if (x <= -1.0f) {
		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 <= (-1.0e0)) 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(-1.0))
		tmp = 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(-1.0))
		tmp = s / x;
	else
		tmp = single(0.5);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-s}}{x} \]
    8. Simplified47.7%

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

        \[\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-unprod61.1%

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

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

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

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

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

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

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

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

    if -1 < x

    1. Initial program 99.8%

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

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

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

Alternative 10: 35.6% 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 35.3%

    \[\leadsto \color{blue}{0.5} \]
  4. Final simplification35.3%

    \[\leadsto 0.5 \]
  5. Add Preprocessing

Reproduce

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