Logistic function

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

\[\begin{array}{l} \\ \frac{1}{1 + {\left(e^{\sqrt[3]{\frac{x \cdot \frac{x}{s}}{s}}}\right)}^{\left(-\sqrt[3]{\frac{x}{s}}\right)}} \end{array} \]
(FPCore (x s)
 :precision binary32
 (/ 1.0 (+ 1.0 (pow (exp (cbrt (/ (* x (/ x s)) s))) (- (cbrt (/ x s)))))))
float code(float x, float s) {
	return 1.0f / (1.0f + powf(expf(cbrtf(((x * (x / s)) / s))), -cbrtf((x / s))));
}
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + (exp(cbrt(Float32(Float32(x * Float32(x / s)) / s))) ^ Float32(-cbrt(Float32(x / s))))))
end
\begin{array}{l}

\\
\frac{1}{1 + {\left(e^{\sqrt[3]{\frac{x \cdot \frac{x}{s}}{s}}}\right)}^{\left(-\sqrt[3]{\frac{x}{s}}\right)}}
\end{array}
Derivation
  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. div-inv99.8%

      \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{x \cdot \frac{1}{s}}}}} \]
    4. add-sqr-sqrt53.1%

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

      \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{\sqrt{x \cdot x}} \cdot \frac{1}{s}}}} \]
    6. sqr-neg61.7%

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

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

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

      \[\leadsto \frac{1}{1 + \frac{1}{e^{\color{blue}{\frac{-x}{s}}}}} \]
    10. add-cube-cbrt26.8%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{{\left(e^{\sqrt[3]{\frac{-x}{s}} \cdot \sqrt[3]{\frac{-x}{s}}}\right)}^{\left(\sqrt[3]{\frac{-x}{s}}\right)}}}} \]
    12. pow-flip26.8%

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

    \[\leadsto \frac{1}{1 + \color{blue}{{\left(e^{\sqrt[3]{{\left(\frac{s}{x}\right)}^{-2}}}\right)}^{\left(-\sqrt[3]{\frac{x}{s}}\right)}}} \]
  4. Step-by-step derivation
    1. metadata-eval99.9%

      \[\leadsto \frac{1}{1 + {\left(e^{\sqrt[3]{{\left(\frac{s}{x}\right)}^{\color{blue}{\left(-1 + -1\right)}}}}\right)}^{\left(-\sqrt[3]{\frac{x}{s}}\right)}} \]
    2. pow-prod-up99.9%

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

      \[\leadsto \frac{1}{1 + {\left(e^{\sqrt[3]{\color{blue}{\frac{1}{\frac{s}{x}}} \cdot {\left(\frac{s}{x}\right)}^{-1}}}\right)}^{\left(-\sqrt[3]{\frac{x}{s}}\right)}} \]
    4. clear-num99.9%

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

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

      \[\leadsto \frac{1}{1 + {\left(e^{\sqrt[3]{\frac{x}{s} \cdot \color{blue}{\frac{x}{s}}}}\right)}^{\left(-\sqrt[3]{\frac{x}{s}}\right)}} \]
    7. associate-*r/99.9%

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

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

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

Alternative 2: 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.9%

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

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

Alternative 3: 65.9% accurate, 3.5× speedup?

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

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

\mathbf{elif}\;t_0 \leq 4:\\
\;\;\;\;0.5 + \left(\frac{x}{s} \cdot 0.25 + -0.020833333333333332 \cdot \frac{x \cdot \frac{x}{s}}{s \cdot \frac{s}{x}}\right)\\

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


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

    1. Initial program 100.0%

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

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

    if -5 < (/.f32 (neg.f32 x) s) < 4

    1. Initial program 99.5%

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

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

        \[\leadsto 0.5 + \left(0.25 \cdot \frac{x}{s} + -0.020833333333333332 \cdot \frac{\color{blue}{\left(x \cdot x\right) \cdot x}}{{s}^{3}}\right) \]
      2. cube-mult63.4%

        \[\leadsto 0.5 + \left(0.25 \cdot \frac{x}{s} + -0.020833333333333332 \cdot \frac{\left(x \cdot x\right) \cdot x}{\color{blue}{s \cdot \left(s \cdot s\right)}}\right) \]
      3. times-frac82.8%

        \[\leadsto 0.5 + \left(0.25 \cdot \frac{x}{s} + -0.020833333333333332 \cdot \color{blue}{\left(\frac{x \cdot x}{s} \cdot \frac{x}{s \cdot s}\right)}\right) \]
    4. Applied egg-rr82.8%

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

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

        \[\leadsto 0.5 + \left(0.25 \cdot \frac{x}{s} + -0.020833333333333332 \cdot \left(\frac{x}{\frac{s}{x}} \cdot \color{blue}{\frac{\frac{x}{s}}{s}}\right)\right) \]
      3. frac-times96.1%

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

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

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

    1. Initial program 100.0%

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

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

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

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

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

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

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

      \[\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 77.2%

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

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

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

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

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

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

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

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

        \[\leadsto 2 \cdot \color{blue}{\frac{1 \cdot 1}{\frac{x}{s \cdot s} \cdot x}} \]
      3. metadata-eval80.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq -5:\\ \;\;\;\;0.5\\ \mathbf{elif}\;\frac{-x}{s} \leq 4:\\ \;\;\;\;0.5 + \left(\frac{x}{s} \cdot 0.25 + -0.020833333333333332 \cdot \frac{x \cdot \frac{x}{s}}{s \cdot \frac{s}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{x \cdot \frac{x}{s \cdot s}}\\ \end{array} \]

Alternative 4: 62.7% accurate, 6.7× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac70.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. Simplified70.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. Taylor expanded in x around inf 76.6%

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

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

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

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

        \[\leadsto 2 \cdot \color{blue}{\frac{\frac{s \cdot s}{x}}{x}} \]
      2. div-inv79.8%

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

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

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

Alternative 5: 63.3% accurate, 6.7× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac70.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. Simplified70.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. Taylor expanded in x around inf 76.6%

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

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

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

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

        \[\leadsto 2 \cdot \color{blue}{\frac{\frac{s \cdot s}{x}}{x}} \]
      2. div-inv79.8%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 0.20000000298023224:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{x \cdot \frac{x}{s \cdot s}}\\ \end{array} \]

Alternative 6: 58.5% accurate, 7.6× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac70.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. Simplified70.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. Taylor expanded in x around inf 76.6%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 0.20000000298023224:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\frac{s}{x} \cdot \frac{s}{x}\right)\\ \end{array} \]

Alternative 7: 61.2% accurate, 7.6× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

    if 2e4 < (/.f32 (neg.f32 x) s)

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac73.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. Simplified73.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 80.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 20000:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{s \cdot s}{x \cdot x}\\ \end{array} \]

Alternative 8: 62.9% accurate, 7.6× speedup?

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

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

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


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

    1. Initial program 99.8%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \frac{1}{2 + \left(0.5 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \frac{x}{s}\right)} \]
      5. times-frac70.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. Simplified70.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. Taylor expanded in x around inf 76.6%

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

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

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

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

        \[\leadsto 2 \cdot \color{blue}{\frac{\frac{s \cdot s}{x}}{x}} \]
      2. div-inv79.8%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{2 \cdot \frac{1}{x}}{\frac{x}{s \cdot s}}} \]
      5. un-div-inv79.8%

        \[\leadsto \frac{\color{blue}{\frac{2}{x}}}{\frac{x}{s \cdot s}} \]
    11. Applied egg-rr79.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 0.20000000298023224:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{x}}{\frac{x}{s \cdot s}}\\ \end{array} \]

Alternative 9: 49.4% accurate, 8.9× speedup?

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

\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 99.9%

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

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

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

    1. Initial program 99.8%

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

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

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

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

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

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

Alternative 10: 47.9% accurate, 9.7× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0}\\


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

    1. Initial program 99.8%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 46.2% accurate, 21.1× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-s}{x}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u46.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-s}{x}\right)\right)} \]
      2. expm1-udef96.4%

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{-\left(-s\right)}{-x}}\right)} - 1 \]
      4. remove-double-neg96.4%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{s}}{-x}\right)} - 1 \]
      5. add-sqr-sqrt96.4%

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{s}{\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}}}\right)} - 1 \]
      7. sqr-neg96.4%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{s}{\sqrt{\color{blue}{x \cdot x}}}\right)} - 1 \]
      8. sqrt-prod-0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{s}{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}\right)} - 1 \]
      9. add-sqr-sqrt96.4%

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{s}{x}\right)} - 1} \]
    10. Step-by-step derivation
      1. expm1-def46.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{s}{x}\right)\right)} \]
      2. expm1-log1p46.8%

        \[\leadsto \color{blue}{\frac{s}{x}} \]
    11. Simplified46.8%

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

    if -1.00000001e-7 < x

    1. Initial program 99.8%

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

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

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

Alternative 12: 34.8% 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.9%

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

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

    \[\leadsto 0.5 \]

Reproduce

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