Logistic function

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

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

Initial Program: 99.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{1 + \color{blue}{{\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}} \]
  5. Step-by-step derivation
    1. add-exp-log99.9%

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

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

      \[\leadsto e^{-\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(1 + {\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)\right)\right)}} \]
    4. log1p-define99.9%

      \[\leadsto e^{-\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left({\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}\right)}\right)\right)} \]
    5. expm1-log1p-u99.9%

      \[\leadsto e^{-\mathsf{log1p}\left(\color{blue}{{\left(e^{-1}\right)}^{\left(\frac{x}{s}\right)}}\right)} \]
    6. pow-exp99.9%

      \[\leadsto e^{-\mathsf{log1p}\left(\color{blue}{e^{-1 \cdot \frac{x}{s}}}\right)} \]
    7. neg-mul-199.9%

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

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

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

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

Alternative 2: 99.8% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.8% accurate, 1.0× speedup?

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

\\
\frac{1}{e^{\frac{-x}{s}} + 1}
\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}{e^{\frac{-x}{s}} + 1} \]
  4. Add Preprocessing

Alternative 4: 59.1% accurate, 3.3× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    if -1 < (/.f32 (neg.f32 x) s) < 4.99999997e36

    1. Initial program 99.7%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \color{blue}{-1 \cdot \frac{x}{s}}} \]
      3. rem-log-exp96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999997e36 < (/.f32 (neg.f32 x) s)

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{2 - \frac{x}{s}}} \]
    6. Taylor expanded in x around inf 91.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/91.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{x}}{\frac{s \cdot 2 - x}{x \cdot s}}} \]
      2. un-div-inv82.4%

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

        \[\leadsto \color{blue}{\frac{1}{x \cdot \left(\left(s \cdot 2 - x\right) \cdot \frac{1}{x \cdot s}\right)}} \]
      4. un-div-inv91.5%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\frac{s \cdot 2 - x}{x \cdot s}}} \]
    12. Applied egg-rr91.5%

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{x \cdot s}}{x \cdot \left(s \cdot 2 - x\right)} \]
      7. associate-/l*100.0%

        \[\leadsto \color{blue}{x \cdot \frac{s}{x \cdot \left(s \cdot 2 - x\right)}} \]
    14. Simplified100.0%

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

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

Alternative 5: 51.9% accurate, 5.7× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

    if 2e-23 < (neg.f32 x)

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 48.3% accurate, 6.3× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.8%

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot s - x}{s}}} \]
    7. Step-by-step derivation
      1. *-commutative66.3%

        \[\leadsto \frac{1}{\frac{\color{blue}{s \cdot 2} - x}{s}} \]
    8. Simplified66.3%

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

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

Alternative 7: 50.9% accurate, 6.3× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

    if 2e-23 < (neg.f32 x)

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{x \cdot \left(\left(s \cdot 2 - x\right) \cdot \frac{1}{x \cdot s}\right)}} \]
      4. un-div-inv54.2%

        \[\leadsto \frac{1}{x \cdot \color{blue}{\frac{s \cdot 2 - x}{x \cdot s}}} \]
    12. Applied egg-rr54.2%

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{x \cdot s}}{x \cdot \left(s \cdot 2 - x\right)} \]
      7. associate-/l*61.1%

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

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

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

Alternative 8: 46.9% accurate, 7.2× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 48.3% accurate, 7.2× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.8%

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

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

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

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

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

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

Alternative 10: 46.8% accurate, 8.3× speedup?

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

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


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

    1. Initial program 99.8%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 45.4% accurate, 12.0× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if -9.99999975e-5 < x

    1. Initial program 99.8%

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

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

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

Alternative 12: 34.4% 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 39.1%

    \[\leadsto \color{blue}{0.5} \]
  4. Final simplification39.1%

    \[\leadsto 0.5 \]
  5. Add Preprocessing

Reproduce

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