Logistic function

Percentage Accurate: 99.8% → 99.9%
Time: 12.4s
Alternatives: 23
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 23 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^{0 - \frac{x}{s}}\right)} \end{array} \]
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (- 0.0 (/ x s)))))))
float code(float x, float s) {
	return expf(-log1pf(expf((0.0f - (x / s)))));
}
function code(x, s)
	return exp(Float32(-log1p(exp(Float32(Float32(0.0) - Float32(x / s))))))
end
\begin{array}{l}

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

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. inv-powN/A

      \[\leadsto {\left(1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}^{\color{blue}{-1}} \]
    2. pow-to-expN/A

      \[\leadsto e^{\log \left(1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right) \cdot -1} \]
    3. *-commutativeN/A

      \[\leadsto e^{-1 \cdot \log \left(1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)} \]
    4. log-powN/A

      \[\leadsto e^{\log \left({\left(1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}^{-1}\right)} \]
    5. inv-powN/A

      \[\leadsto e^{\log \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)} \]
    6. exp-lowering-exp.f32N/A

      \[\leadsto \mathsf{exp.f32}\left(\log \left(\frac{1}{1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
    7. log-recN/A

      \[\leadsto \mathsf{exp.f32}\left(\left(\mathsf{neg}\left(\log \left(1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)\right)\right) \]
    8. neg-lowering-neg.f32N/A

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\log \left(1 + e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)\right) \]
    9. log1p-defineN/A

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\left(\mathsf{log1p}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)\right)\right) \]
    10. log1p-lowering-log1p.f32N/A

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\mathsf{log1p.f32}\left(\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)\right)\right) \]
    11. exp-lowering-exp.f32N/A

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\mathsf{log1p.f32}\left(\mathsf{exp.f32}\left(\left(\frac{\mathsf{neg}\left(x\right)}{s}\right)\right)\right)\right)\right) \]
    12. distribute-frac-negN/A

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\mathsf{log1p.f32}\left(\mathsf{exp.f32}\left(\left(\mathsf{neg}\left(\frac{x}{s}\right)\right)\right)\right)\right)\right) \]
    13. distribute-frac-neg2N/A

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\mathsf{log1p.f32}\left(\mathsf{exp.f32}\left(\left(\frac{x}{\mathsf{neg}\left(s\right)}\right)\right)\right)\right)\right) \]
    14. /-lowering-/.f32N/A

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\mathsf{log1p.f32}\left(\mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right)\right)\right) \]
    15. neg-lowering-neg.f3299.9%

      \[\leadsto \mathsf{exp.f32}\left(\mathsf{neg.f32}\left(\mathsf{log1p.f32}\left(\mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, \mathsf{neg.f32}\left(s\right)\right)\right)\right)\right)\right) \]
  4. Applied egg-rr99.9%

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

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

Alternative 2: 99.8% accurate, 1.0× speedup?

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

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

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. metadata-evalN/A

      \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
    2. associate--r-N/A

      \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
    3. unsub-negN/A

      \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
    4. associate--r+N/A

      \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
    6. --lowering--.f32N/A

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
    7. distribute-frac-negN/A

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
    8. exp-negN/A

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
    9. distribute-neg-fracN/A

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
    10. metadata-evalN/A

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
    11. /-lowering-/.f32N/A

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
    12. exp-lowering-exp.f32N/A

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
    13. /-lowering-/.f3299.9%

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
  4. Applied egg-rr99.9%

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

Alternative 3: 99.8% accurate, 1.0× speedup?

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

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

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

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

Alternative 4: 93.3% accurate, 3.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \left(x \cdot \left(-0.16666666666666666 \cdot \frac{\frac{x}{s}}{s \cdot s} + \frac{0.5}{s \cdot s}\right) + \frac{-1}{s}\right)}\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \left(\frac{\frac{x}{s}}{s \cdot s}\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \mathsf{/.f32}\left(\left(\frac{x}{s}\right), \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \mathsf{/.f32}\left(\mathsf{/.f32}\left(x, s\right), \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. *-lowering-*.f3290.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \mathsf{/.f32}\left(\mathsf{/.f32}\left(x, s\right), \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Applied egg-rr90.8%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + -1 \cdot \frac{-1 \cdot x + -1 \cdot \frac{\frac{1}{6} \cdot \frac{{x}^{3}}{s} + \frac{1}{2} \cdot {x}^{2}}{s}}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 + \left(\mathsf{neg}\left(\frac{-1 \cdot x + -1 \cdot \frac{\frac{1}{6} \cdot \frac{{x}^{3}}{s} + \frac{1}{2} \cdot {x}^{2}}{s}}{s}\right)\right)\right)\right)\right)\right) \]
      2. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 - \color{blue}{\frac{-1 \cdot x + -1 \cdot \frac{\frac{1}{6} \cdot \frac{{x}^{3}}{s} + \frac{1}{2} \cdot {x}^{2}}{s}}{s}}\right)\right)\right)\right) \]
      3. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\frac{-1 \cdot x + -1 \cdot \frac{\frac{1}{6} \cdot \frac{{x}^{3}}{s} + \frac{1}{2} \cdot {x}^{2}}{s}}{s}\right)}\right)\right)\right)\right) \]
      4. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(-1 \cdot x + -1 \cdot \frac{\frac{1}{6} \cdot \frac{{x}^{3}}{s} + \frac{1}{2} \cdot {x}^{2}}{s}\right), \color{blue}{s}\right)\right)\right)\right)\right) \]
    7. Simplified96.2%

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

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

Alternative 5: 93.2% accurate, 3.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \left(x \cdot \left(-0.16666666666666666 \cdot \frac{\frac{x}{s}}{s \cdot s} + \frac{0.5}{s \cdot s}\right) + \frac{-1}{s}\right)}\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \left(\frac{\frac{x}{s}}{s \cdot s}\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \mathsf{/.f32}\left(\left(\frac{x}{s}\right), \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \mathsf{/.f32}\left(\mathsf{/.f32}\left(x, s\right), \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. *-lowering-*.f3290.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(\frac{-1}{6}, \mathsf{/.f32}\left(\mathsf{/.f32}\left(x, s\right), \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Applied egg-rr90.8%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + -1 \cdot \frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 + \left(\mathsf{neg}\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)\right)\right)\right)\right)\right) \]
      2. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 - \color{blue}{\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}}\right)\right)\right)\right) \]
      3. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right)\right) \]
      4. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + -1 \cdot x\right), s\right)\right)\right)\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + \left(\mathsf{neg}\left(x\right)\right)\right), s\right)\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} - x\right), s\right)\right)\right)\right)\right) \]
      8. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\frac{-1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \frac{-1}{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \left(-1 + \frac{1}{2}\right)}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      12. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      14. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \left(-1 + \frac{1}{2}\right)\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      15. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({x}^{2}\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(x \cdot x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f3295.5%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
    7. Simplified95.5%

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

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

Alternative 6: 93.1% accurate, 3.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \left(\frac{-1}{s} + x \cdot \frac{\frac{0.5}{s} - \frac{\frac{x \cdot 0.16666666666666666}{s}}{s}}{s}\right)}\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2}}{s \cdot s} + \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. div-invN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{1}{2} \cdot \frac{1}{s \cdot s} + \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. fma-defineN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{-1}{6} \cdot x}{s \cdot \left(s \cdot s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      5. associate-/l/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{s}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      6. remove-double-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(s\right)\right)\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      7. distribute-frac-neg2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \mathsf{neg}\left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      8. fmm-undefN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{1}{2} \cdot \frac{1}{s \cdot s} - \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      9. div-invN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      10. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\left(\frac{\frac{1}{2}}{s \cdot s}\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      12. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\left(\frac{\frac{-1}{6} \cdot x}{s \cdot s}\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      14. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(\frac{-1}{6} \cdot x\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      15. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(x \cdot \frac{-1}{6}\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      17. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \mathsf{*.f32}\left(s, s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      18. neg-lowering-neg.f3290.0%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \mathsf{*.f32}\left(s, s\right)\right), \mathsf{neg.f32}\left(s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Applied egg-rr90.0%

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

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{\frac{1}{2}}{s}}{s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. distribute-frac-neg2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{\frac{1}{2}}{s}}{s} - \left(\mathsf{neg}\left(\frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{s}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{\frac{1}{2}}{s}}{s} - \frac{\mathsf{neg}\left(\frac{x \cdot \frac{-1}{6}}{s \cdot s}\right)}{s}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. sub-divN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{\frac{1}{2}}{s} - \left(\mathsf{neg}\left(\frac{x \cdot \frac{-1}{6}}{s \cdot s}\right)\right)}{s}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      5. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{\frac{1}{2}}{s} - \left(\mathsf{neg}\left(\frac{x \cdot \frac{-1}{6}}{s \cdot s}\right)\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\frac{1}{2}}{s}\right), \left(\mathsf{neg}\left(\frac{x \cdot \frac{-1}{6}}{s \cdot s}\right)\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      7. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \left(\mathsf{neg}\left(\frac{x \cdot \frac{-1}{6}}{s \cdot s}\right)\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      8. associate-/r*N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \left(\mathsf{neg}\left(\frac{\frac{x \cdot \frac{-1}{6}}{s}}{s}\right)\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      9. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \left(\frac{\mathsf{neg}\left(\frac{x \cdot \frac{-1}{6}}{s}\right)}{s}\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      10. distribute-frac-neg2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \left(\frac{\frac{x \cdot \frac{-1}{6}}{\mathsf{neg}\left(s\right)}}{s}\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \mathsf{/.f32}\left(\left(\frac{x \cdot \frac{-1}{6}}{\mathsf{neg}\left(s\right)}\right), s\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      12. frac-2negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \mathsf{/.f32}\left(\left(\frac{\mathsf{neg}\left(x \cdot \frac{-1}{6}\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(s\right)\right)\right)}\right), s\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \mathsf{/.f32}\left(\left(\frac{\mathsf{neg}\left(x \cdot \frac{-1}{6}\right)}{s}\right), s\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      14. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(\mathsf{neg}\left(x \cdot \frac{-1}{6}\right)\right), s\right), s\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      15. distribute-rgt-neg-inN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(x \cdot \left(\mathsf{neg}\left(\frac{-1}{6}\right)\right)\right), s\right), s\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{neg}\left(\frac{-1}{6}\right)\right)\right), s\right), s\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      17. metadata-eval90.0%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, s\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{1}{6}\right), s\right), s\right)\right), s\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    8. Applied egg-rr90.0%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + -1 \cdot \frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 + \left(\mathsf{neg}\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)\right)\right)\right)\right)\right) \]
      2. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 - \color{blue}{\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}}\right)\right)\right)\right) \]
      3. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right)\right) \]
      4. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + -1 \cdot x\right), s\right)\right)\right)\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + \left(\mathsf{neg}\left(x\right)\right)\right), s\right)\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} - x\right), s\right)\right)\right)\right)\right) \]
      8. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\frac{-1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \frac{-1}{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \left(-1 + \frac{1}{2}\right)}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      12. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      14. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \left(-1 + \frac{1}{2}\right)\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      15. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({x}^{2}\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(x \cdot x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f3295.5%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
    7. Simplified95.5%

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

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

Alternative 7: 93.1% accurate, 3.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \left(\frac{-1}{s} + x \cdot \frac{0.5 + \frac{x \cdot -0.16666666666666666}{s}}{s \cdot s}\right)}\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2} + \frac{-1}{6} \cdot \frac{x}{s}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} + \frac{-1}{6} \cdot \frac{x}{s}\right), \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{+.f32}\left(\frac{1}{2}, \left(\frac{-1}{6} \cdot \frac{x}{s}\right)\right), \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{+.f32}\left(\frac{1}{2}, \left(\frac{\frac{-1}{6} \cdot x}{s}\right)\right), \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{+.f32}\left(\frac{1}{2}, \mathsf{/.f32}\left(\left(\frac{-1}{6} \cdot x\right), s\right)\right), \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{+.f32}\left(\frac{1}{2}, \mathsf{/.f32}\left(\left(x \cdot \frac{-1}{6}\right), s\right)\right), \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      6. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{+.f32}\left(\frac{1}{2}, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), s\right)\right), \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{+.f32}\left(\frac{1}{2}, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), s\right)\right), \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      8. *-lowering-*.f3290.0%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{+.f32}\left(\frac{1}{2}, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), s\right)\right), \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified90.0%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + -1 \cdot \frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 + \left(\mathsf{neg}\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)\right)\right)\right)\right)\right) \]
      2. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 - \color{blue}{\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}}\right)\right)\right)\right) \]
      3. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right)\right) \]
      4. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + -1 \cdot x\right), s\right)\right)\right)\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + \left(\mathsf{neg}\left(x\right)\right)\right), s\right)\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} - x\right), s\right)\right)\right)\right)\right) \]
      8. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\frac{-1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \frac{-1}{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \left(-1 + \frac{1}{2}\right)}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      12. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      14. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \left(-1 + \frac{1}{2}\right)\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      15. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({x}^{2}\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(x \cdot x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f3295.5%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
    7. Simplified95.5%

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

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

Alternative 8: 92.8% accurate, 4.1× speedup?

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

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

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


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

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{-1}{6} \cdot x}{{s}^{3}}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{x \cdot \frac{-1}{6}}{{s}^{3}}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. associate-/l*N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(x \cdot \frac{\frac{-1}{6}}{{s}^{3}}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(x \cdot \frac{\mathsf{neg}\left(\frac{1}{6}\right)}{{s}^{3}}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      5. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(x \cdot \left(\mathsf{neg}\left(\frac{\frac{1}{6}}{{s}^{3}}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(x \cdot \left(\mathsf{neg}\left(\frac{\frac{1}{6} \cdot 1}{{s}^{3}}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      7. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(x \cdot \left(\mathsf{neg}\left(\frac{1}{6} \cdot \frac{1}{{s}^{3}}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      8. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \left(\mathsf{neg}\left(\frac{1}{6} \cdot \frac{1}{{s}^{3}}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \left(\mathsf{neg}\left(\frac{\frac{1}{6} \cdot 1}{{s}^{3}}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \left(\mathsf{neg}\left(\frac{\frac{1}{6}}{{s}^{3}}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      11. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \left(\frac{\mathsf{neg}\left(\frac{1}{6}\right)}{{s}^{3}}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \left(\frac{\frac{-1}{6}}{{s}^{3}}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{-1}{6}, \left({s}^{3}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      14. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{-1}{6}, \left(s \cdot \left(s \cdot s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      15. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{-1}{6}, \left(s \cdot {s}^{2}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{-1}{6}, \mathsf{*.f32}\left(s, \left({s}^{2}\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{-1}{6}, \mathsf{*.f32}\left(s, \left(s \cdot s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f3286.6%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{-1}{6}, \mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified86.6%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + -1 \cdot \frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 + \left(\mathsf{neg}\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)\right)\right)\right)\right)\right) \]
      2. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 - \color{blue}{\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}}\right)\right)\right)\right) \]
      3. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right)\right) \]
      4. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + -1 \cdot x\right), s\right)\right)\right)\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + \left(\mathsf{neg}\left(x\right)\right)\right), s\right)\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} - x\right), s\right)\right)\right)\right)\right) \]
      8. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\frac{-1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \frac{-1}{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \left(-1 + \frac{1}{2}\right)}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      12. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      14. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \left(-1 + \frac{1}{2}\right)\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      15. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({x}^{2}\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(x \cdot x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f3295.5%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
    7. Simplified95.5%

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

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

Alternative 9: 90.9% accurate, 4.3× speedup?

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

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

\mathbf{elif}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{x \cdot 0.5 - s}{s \cdot 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 < -1.99999996e-14

    1. Initial program 100.0%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified88.2%

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

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2}}{s \cdot s} + \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. div-invN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{1}{2} \cdot \frac{1}{s \cdot s} + \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. fma-defineN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{-1}{6} \cdot x}{s \cdot \left(s \cdot s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      5. associate-/l/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{s}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      6. remove-double-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(s\right)\right)\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      7. distribute-frac-neg2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \mathsf{neg}\left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      8. fmm-undefN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{1}{2} \cdot \frac{1}{s \cdot s} - \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      9. div-invN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      10. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\left(\frac{\frac{1}{2}}{s \cdot s}\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      12. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\left(\frac{\frac{-1}{6} \cdot x}{s \cdot s}\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      14. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(\frac{-1}{6} \cdot x\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      15. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(x \cdot \frac{-1}{6}\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      17. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \mathsf{*.f32}\left(s, s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      18. neg-lowering-neg.f3287.2%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \mathsf{*.f32}\left(s, s\right)\right), \mathsf{neg.f32}\left(s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Applied egg-rr87.2%

      \[\leadsto \frac{1}{2 + x \cdot \left(x \cdot \color{blue}{\left(\frac{0.5}{s \cdot s} - \frac{\frac{x \cdot -0.16666666666666666}{s \cdot s}}{-s}\right)} + \frac{-1}{s}\right)} \]
    7. Step-by-step derivation
      1. distribute-lft-inN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right) + \color{blue}{x \cdot \frac{-1}{s}}\right)\right)\right) \]
      2. frac-2negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right) + x \cdot \frac{\mathsf{neg}\left(-1\right)}{\color{blue}{\mathsf{neg}\left(s\right)}}\right)\right)\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right) + x \cdot \frac{1}{\mathsf{neg}\left(\color{blue}{s}\right)}\right)\right)\right) \]
      4. div-invN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right) + \frac{x}{\color{blue}{\mathsf{neg}\left(s\right)}}\right)\right)\right) \]
      5. associate-+r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(2 + x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right) + \color{blue}{\frac{x}{\mathsf{neg}\left(s\right)}}\right)\right) \]
      6. distribute-frac-neg2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(2 + x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right) + \left(\mathsf{neg}\left(\frac{x}{s}\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(2 + x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right) - \color{blue}{\frac{x}{s}}\right)\right) \]
      8. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(\left(2 + x \cdot \left(x \cdot \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{x \cdot \frac{-1}{6}}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \color{blue}{\left(\frac{x}{s}\right)}\right)\right) \]
    8. Applied egg-rr87.2%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(\frac{-1}{6} \cdot \frac{{x}^{3}}{{s}^{3}}\right)}\right) \]
    10. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\frac{\frac{-1}{6} \cdot {x}^{3}}{\color{blue}{{s}^{3}}}\right)\right) \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{6} \cdot {x}^{3}\right), \color{blue}{\left({s}^{3}\right)}\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\left({x}^{3} \cdot \frac{-1}{6}\right), \left({\color{blue}{s}}^{3}\right)\right)\right) \]
      4. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\left(\left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{-1}{6}\right), \left({s}^{3}\right)\right)\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\left(\left(x \cdot {x}^{2}\right) \cdot \frac{-1}{6}\right), \left({s}^{3}\right)\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\left(x \cdot \left({x}^{2} \cdot \frac{-1}{6}\right)\right), \left({\color{blue}{s}}^{3}\right)\right)\right) \]
      7. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \left({x}^{2} \cdot \frac{-1}{6}\right)\right), \left({\color{blue}{s}}^{3}\right)\right)\right) \]
      8. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\left({x}^{2}\right), \frac{-1}{6}\right)\right), \left({s}^{3}\right)\right)\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\left(x \cdot x\right), \frac{-1}{6}\right)\right), \left({s}^{3}\right)\right)\right) \]
      10. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{6}\right)\right), \left({s}^{3}\right)\right)\right) \]
      11. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{6}\right)\right), \left(s \cdot \color{blue}{\left(s \cdot s\right)}\right)\right)\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{6}\right)\right), \left(s \cdot {s}^{\color{blue}{2}}\right)\right)\right) \]
      13. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{6}\right)\right), \mathsf{*.f32}\left(s, \color{blue}{\left({s}^{2}\right)}\right)\right)\right) \]
      14. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{6}\right)\right), \mathsf{*.f32}\left(s, \left(s \cdot \color{blue}{s}\right)\right)\right)\right) \]
      15. *-lowering-*.f3288.2%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{6}\right)\right), \mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, \color{blue}{s}\right)\right)\right)\right) \]
    11. Simplified88.2%

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

    if -1.99999996e-14 < x < -1.00000002e-25

    1. Initial program 99.3%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified81.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3299.1%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified99.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \color{blue}{\left(\frac{-1 \cdot s + \frac{1}{2} \cdot x}{{s}^{2}}\right)}\right)\right)\right) \]
    9. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(-1 \cdot s + \frac{1}{2} \cdot x\right), \color{blue}{\left({s}^{2}\right)}\right)\right)\right)\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x + -1 \cdot s\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      3. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x + \left(\mathsf{neg}\left(s\right)\right)\right), \left({s}^{2}\right)\right)\right)\right)\right) \]
      4. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x - s\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      5. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{1}{2} \cdot x\right), s\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      6. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), s\right), \left({s}^{2}\right)\right)\right)\right)\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), s\right), \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      8. *-lowering-*.f3295.4%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), s\right), \mathsf{*.f32}\left(s, \color{blue}{s}\right)\right)\right)\right)\right) \]
    10. Simplified95.4%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + \frac{x}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(\frac{x}{s} + \color{blue}{1}\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\left(\frac{x}{s}\right), \color{blue}{1}\right)\right)\right)\right) \]
      3. /-lowering-/.f3293.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\mathsf{/.f32}\left(x, s\right), 1\right)\right)\right)\right) \]
    7. Simplified93.8%

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

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

Alternative 10: 90.8% accurate, 4.3× speedup?

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

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

\mathbf{elif}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{x \cdot 0.5 - s}{s \cdot 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 < -1.99999996e-14

    1. Initial program 100.0%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified88.2%

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

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

        \[\leadsto \frac{-6 \cdot {s}^{3}}{\color{blue}{{x}^{3}}} \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\left(-6 \cdot {s}^{3}\right), \color{blue}{\left({x}^{3}\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{3} \cdot -6\right), \left({\color{blue}{x}}^{3}\right)\right) \]
      4. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({s}^{3}\right), -6\right), \left({\color{blue}{x}}^{3}\right)\right) \]
      5. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(s \cdot \left(s \cdot s\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(s \cdot {s}^{2}\right), -6\right), \left({x}^{3}\right)\right) \]
      7. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \left({s}^{2}\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \left(s \cdot s\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      9. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      10. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \left(x \cdot {x}^{\color{blue}{2}}\right)\right) \]
      12. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \mathsf{*.f32}\left(x, \color{blue}{\left({x}^{2}\right)}\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \mathsf{*.f32}\left(x, \left(x \cdot \color{blue}{x}\right)\right)\right) \]
      14. *-lowering-*.f3288.2%

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \color{blue}{x}\right)\right)\right) \]
    7. Simplified88.2%

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

    if -1.99999996e-14 < x < -1.00000002e-25

    1. Initial program 99.3%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified81.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3299.1%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified99.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \color{blue}{\left(\frac{-1 \cdot s + \frac{1}{2} \cdot x}{{s}^{2}}\right)}\right)\right)\right) \]
    9. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(-1 \cdot s + \frac{1}{2} \cdot x\right), \color{blue}{\left({s}^{2}\right)}\right)\right)\right)\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x + -1 \cdot s\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      3. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x + \left(\mathsf{neg}\left(s\right)\right)\right), \left({s}^{2}\right)\right)\right)\right)\right) \]
      4. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x - s\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      5. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{1}{2} \cdot x\right), s\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      6. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), s\right), \left({s}^{2}\right)\right)\right)\right)\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), s\right), \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      8. *-lowering-*.f3295.4%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), s\right), \mathsf{*.f32}\left(s, \color{blue}{s}\right)\right)\right)\right)\right) \]
    10. Simplified95.4%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + \frac{x}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(\frac{x}{s} + \color{blue}{1}\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\left(\frac{x}{s}\right), \color{blue}{1}\right)\right)\right)\right) \]
      3. /-lowering-/.f3293.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\mathsf{/.f32}\left(x, s\right), 1\right)\right)\right)\right) \]
    7. Simplified93.8%

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

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

Alternative 11: 90.8% accurate, 4.5× speedup?

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

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

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


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

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3284.2%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified84.2%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + -1 \cdot \frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 + \left(\mathsf{neg}\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)\right)\right)\right)\right)\right) \]
      2. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(1 - \color{blue}{\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}}\right)\right)\right)\right) \]
      3. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\frac{-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}}{s}\right)}\right)\right)\right)\right) \]
      4. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(-1 \cdot x + \frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + -1 \cdot x\right), s\right)\right)\right)\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} + \left(\mathsf{neg}\left(x\right)\right)\right), s\right)\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s} - x\right), s\right)\right)\right)\right)\right) \]
      8. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1}{2} \cdot \frac{{x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\frac{-1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \frac{-1}{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{{x}^{2} \cdot \left(-1 + \frac{1}{2}\right)}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      12. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}}{s}\right), x\right), s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(-1 \cdot {x}^{2} + \frac{1}{2} \cdot {x}^{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      14. distribute-rgt-outN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \left(-1 + \frac{1}{2}\right)\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      15. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({x}^{2} \cdot \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({x}^{2}\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      17. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(x \cdot x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f3295.5%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(x, x\right), \frac{-1}{2}\right), s\right), x\right), s\right)\right)\right)\right)\right) \]
    7. Simplified95.5%

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

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

Alternative 12: 90.4% accurate, 4.7× speedup?

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

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

\mathbf{elif}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{x \cdot 0.5}{s \cdot s}}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified88.2%

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

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

        \[\leadsto \frac{-6 \cdot {s}^{3}}{\color{blue}{{x}^{3}}} \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\left(-6 \cdot {s}^{3}\right), \color{blue}{\left({x}^{3}\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{3} \cdot -6\right), \left({\color{blue}{x}}^{3}\right)\right) \]
      4. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({s}^{3}\right), -6\right), \left({\color{blue}{x}}^{3}\right)\right) \]
      5. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(s \cdot \left(s \cdot s\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(s \cdot {s}^{2}\right), -6\right), \left({x}^{3}\right)\right) \]
      7. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \left({s}^{2}\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \left(s \cdot s\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      9. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \left({x}^{3}\right)\right) \]
      10. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \left(x \cdot {x}^{\color{blue}{2}}\right)\right) \]
      12. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \mathsf{*.f32}\left(x, \color{blue}{\left({x}^{2}\right)}\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \mathsf{*.f32}\left(x, \left(x \cdot \color{blue}{x}\right)\right)\right) \]
      14. *-lowering-*.f3288.2%

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, s\right)\right), -6\right), \mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \color{blue}{x}\right)\right)\right) \]
    7. Simplified88.2%

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

    if -1.99999996e-14 < x < -1.00000002e-25

    1. Initial program 99.3%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified81.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3299.1%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified99.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \color{blue}{\left(\frac{1}{2} \cdot \frac{x}{{s}^{2}}\right)}\right)\right)\right) \]
    9. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2} \cdot x}{\color{blue}{{s}^{2}}}\right)\right)\right)\right) \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{\left({s}^{2}\right)}\right)\right)\right)\right) \]
      3. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f3291.3%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \mathsf{*.f32}\left(s, \color{blue}{s}\right)\right)\right)\right)\right) \]
    10. Simplified91.3%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + \frac{x}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(\frac{x}{s} + \color{blue}{1}\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\left(\frac{x}{s}\right), \color{blue}{1}\right)\right)\right)\right) \]
      3. /-lowering-/.f3293.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\mathsf{/.f32}\left(x, s\right), 1\right)\right)\right)\right) \]
    7. Simplified93.8%

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

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

Alternative 13: 90.4% accurate, 4.7× speedup?

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

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

\mathbf{elif}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{x \cdot 0.5}{s \cdot s}}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified88.2%

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

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2}}{s \cdot s} + \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. div-invN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{1}{2} \cdot \frac{1}{s \cdot s} + \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. fma-defineN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{-1}{6} \cdot \frac{x}{s \cdot \left(s \cdot s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      4. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{-1}{6} \cdot x}{s \cdot \left(s \cdot s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      5. associate-/l/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{s}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      6. remove-double-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(s\right)\right)\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      7. distribute-frac-neg2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\mathsf{fma}\left(\frac{1}{2}, \frac{1}{s \cdot s}, \mathsf{neg}\left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      8. fmm-undefN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{1}{2} \cdot \frac{1}{s \cdot s} - \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      9. div-invN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2}}{s \cdot s} - \frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      10. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\left(\frac{\frac{1}{2}}{s \cdot s}\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      12. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \left(\frac{\frac{\frac{-1}{6} \cdot x}{s \cdot s}}{\mathsf{neg}\left(s\right)}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\left(\frac{\frac{-1}{6} \cdot x}{s \cdot s}\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      14. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(\frac{-1}{6} \cdot x\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      15. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(x \cdot \frac{-1}{6}\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      16. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \left(s \cdot s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      17. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \mathsf{*.f32}\left(s, s\right)\right), \left(\mathsf{neg}\left(s\right)\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      18. neg-lowering-neg.f3287.2%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{\_.f32}\left(\mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right), \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(x, \frac{-1}{6}\right), \mathsf{*.f32}\left(s, s\right)\right), \mathsf{neg.f32}\left(s\right)\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Applied egg-rr87.2%

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

      \[\leadsto \color{blue}{-6 \cdot \frac{{s}^{3}}{{x}^{3}}} \]
    8. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{-6 \cdot {s}^{3}}{\color{blue}{{x}^{3}}} \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\left(-6 \cdot {s}^{3}\right), \color{blue}{\left({x}^{3}\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{3} \cdot -6\right), \left({\color{blue}{x}}^{3}\right)\right) \]
      4. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(\left(\left(s \cdot \left(s \cdot s\right)\right) \cdot -6\right), \left({x}^{3}\right)\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\left(\left(s \cdot {s}^{2}\right) \cdot -6\right), \left({x}^{3}\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{/.f32}\left(\left(s \cdot \left({s}^{2} \cdot -6\right)\right), \left({\color{blue}{x}}^{3}\right)\right) \]
      7. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \left({s}^{2} \cdot -6\right)\right), \left({\color{blue}{x}}^{3}\right)\right) \]
      8. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\left({s}^{2}\right), -6\right)\right), \left({x}^{3}\right)\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\left(s \cdot s\right), -6\right)\right), \left({x}^{3}\right)\right) \]
      10. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -6\right)\right), \left({x}^{3}\right)\right) \]
      11. cube-multN/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -6\right)\right), \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -6\right)\right), \left(x \cdot {x}^{\color{blue}{2}}\right)\right) \]
      13. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -6\right)\right), \mathsf{*.f32}\left(x, \color{blue}{\left({x}^{2}\right)}\right)\right) \]
      14. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -6\right)\right), \mathsf{*.f32}\left(x, \left(x \cdot \color{blue}{x}\right)\right)\right) \]
      15. *-lowering-*.f3287.1%

        \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -6\right)\right), \mathsf{*.f32}\left(x, \mathsf{*.f32}\left(x, \color{blue}{x}\right)\right)\right) \]
    9. Simplified87.1%

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

    if -1.99999996e-14 < x < -1.00000002e-25

    1. Initial program 99.3%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified81.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3299.1%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified99.1%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \color{blue}{\left(\frac{1}{2} \cdot \frac{x}{{s}^{2}}\right)}\right)\right)\right) \]
    9. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2} \cdot x}{\color{blue}{{s}^{2}}}\right)\right)\right)\right) \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{\left({s}^{2}\right)}\right)\right)\right)\right) \]
      3. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f3291.3%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \mathsf{*.f32}\left(s, \color{blue}{s}\right)\right)\right)\right)\right) \]
    10. Simplified91.3%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + \frac{x}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(\frac{x}{s} + \color{blue}{1}\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\left(\frac{x}{s}\right), \color{blue}{1}\right)\right)\right)\right) \]
      3. /-lowering-/.f3293.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\mathsf{/.f32}\left(x, s\right), 1\right)\right)\right)\right) \]
    7. Simplified93.8%

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

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

Alternative 14: 90.0% accurate, 4.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\ \;\;\;\;\frac{1}{2 + x \cdot \left(\frac{-1}{s} + x \cdot \frac{0.5}{s \cdot 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.0000000195414814e-25)
   (/ 1.0 (+ 2.0 (* x (+ (/ -1.0 s) (* x (/ 0.5 (* s s)))))))
   (/ 1.0 (+ 1.0 (/ -1.0 (- -1.0 (/ x s)))))))
float code(float x, float s) {
	float tmp;
	if (x <= -1.0000000195414814e-25f) {
		tmp = 1.0f / (2.0f + (x * ((-1.0f / s) + (x * (0.5f / (s * s))))));
	} else {
		tmp = 1.0f / (1.0f + (-1.0f / (-1.0f - (x / s))));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= (-1.0000000195414814e-25)) then
        tmp = 1.0e0 / (2.0e0 + (x * (((-1.0e0) / s) + (x * (0.5e0 / (s * s))))))
    else
        tmp = 1.0e0 / (1.0e0 + ((-1.0e0) / ((-1.0e0) - (x / s))))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(-1.0000000195414814e-25))
		tmp = Float32(Float32(1.0) / Float32(Float32(2.0) + Float32(x * Float32(Float32(Float32(-1.0) / s) + Float32(x * Float32(Float32(0.5) / Float32(s * s)))))));
	else
		tmp = Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(Float32(-1.0) / Float32(Float32(-1.0) - Float32(x / s)))));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(-1.0000000195414814e-25))
		tmp = single(1.0) / (single(2.0) + (x * ((single(-1.0) / s) + (x * (single(0.5) / (s * s))))));
	else
		tmp = single(1.0) / (single(1.0) + (single(-1.0) / (single(-1.0) - (x / s))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \left(\frac{-1}{s} + x \cdot \frac{0.5}{s \cdot 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 < -1.00000002e-25

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3284.2%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified84.2%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + \frac{x}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(\frac{x}{s} + \color{blue}{1}\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\left(\frac{x}{s}\right), \color{blue}{1}\right)\right)\right)\right) \]
      3. /-lowering-/.f3293.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\mathsf{/.f32}\left(x, s\right), 1\right)\right)\right)\right) \]
    7. Simplified93.8%

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

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

Alternative 15: 88.7% accurate, 6.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.0000000195414814 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{2 + x \cdot \frac{x \cdot 0.5}{s \cdot s}}\\

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


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

    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified86.6%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3284.2%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified84.2%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \color{blue}{\left(\frac{1}{2} \cdot \frac{x}{{s}^{2}}\right)}\right)\right)\right) \]
    9. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \left(\frac{\frac{1}{2} \cdot x}{\color{blue}{{s}^{2}}}\right)\right)\right)\right) \]
      2. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{\left({s}^{2}\right)}\right)\right)\right)\right) \]
      3. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \left({\color{blue}{s}}^{2}\right)\right)\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f3280.6%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\mathsf{*.f32}\left(\frac{1}{2}, x\right), \mathsf{*.f32}\left(s, \color{blue}{s}\right)\right)\right)\right)\right) \]
    10. Simplified80.6%

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

    if -1.00000002e-25 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + \frac{x}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(\frac{x}{s} + \color{blue}{1}\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\left(\frac{x}{s}\right), \color{blue}{1}\right)\right)\right)\right) \]
      3. /-lowering-/.f3293.8%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\mathsf{/.f32}\left(x, s\right), 1\right)\right)\right)\right) \]
    7. Simplified93.8%

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

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

Alternative 16: 84.7% accurate, 6.7× speedup?

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

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

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


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

    1. Initial program 99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified88.3%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3283.0%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified83.0%

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

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

        \[\leadsto \frac{2 \cdot {s}^{2}}{\color{blue}{{x}^{2}}} \]
      2. unpow2N/A

        \[\leadsto \frac{2 \cdot {s}^{2}}{x \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{2 \cdot {s}^{2}}{x}}{\color{blue}{x}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\frac{{s}^{2} \cdot 2}{x}}{x} \]
      5. associate-*r/N/A

        \[\leadsto \frac{{s}^{2} \cdot \frac{2}{x}}{x} \]
      6. metadata-evalN/A

        \[\leadsto \frac{{s}^{2} \cdot \frac{2 \cdot 1}{x}}{x} \]
      7. associate-*r/N/A

        \[\leadsto \frac{{s}^{2} \cdot \left(2 \cdot \frac{1}{x}\right)}{x} \]
      8. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{2} \cdot \left(2 \cdot \frac{1}{x}\right)\right), \color{blue}{x}\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{2} \cdot \frac{2 \cdot 1}{x}\right), x\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{2} \cdot \frac{2}{x}\right), x\right) \]
      11. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(\left(\frac{{s}^{2} \cdot 2}{x}\right), x\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(\left(\frac{2 \cdot {s}^{2}}{x}\right), x\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(2 \cdot {s}^{2}\right), x\right), x\right) \]
      14. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(2, \left({s}^{2}\right)\right), x\right), x\right) \]
      15. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(2, \left(s \cdot s\right)\right), x\right), x\right) \]
      16. *-lowering-*.f3273.5%

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(2, \mathsf{*.f32}\left(s, s\right)\right), x\right), x\right) \]
    10. Simplified73.5%

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

    if -1.00000003e-22 < x

    1. Initial program 99.9%

      \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) + e^{\color{blue}{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right) \]
      2. associate--r-N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \color{blue}{\left(-1 - e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(0 - \left(-1 + \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right)\right) \]
      4. associate--r+N/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(\left(0 - -1\right) - \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \left(1 - \left(\mathsf{neg}\left(\color{blue}{e^{\frac{\mathsf{neg}\left(x\right)}{s}}}\right)\right)\right)\right) \]
      6. --lowering--.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \color{blue}{\left(\mathsf{neg}\left(e^{\frac{\mathsf{neg}\left(x\right)}{s}}\right)\right)}\right)\right) \]
      7. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(e^{\mathsf{neg}\left(\frac{x}{s}\right)}\right)\right)\right)\right) \]
      8. exp-negN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\mathsf{neg}\left(\frac{1}{e^{\frac{x}{s}}}\right)\right)\right)\right) \]
      9. distribute-neg-fracN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{\mathsf{neg}\left(1\right)}{\color{blue}{e^{\frac{x}{s}}}}\right)\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \left(\frac{-1}{e^{\color{blue}{\frac{x}{s}}}}\right)\right)\right) \]
      11. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(e^{\frac{x}{s}}\right)}\right)\right)\right) \]
      12. exp-lowering-exp.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\left(\frac{x}{s}\right)\right)\right)\right)\right) \]
      13. /-lowering-/.f3299.9%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{exp.f32}\left(\mathsf{/.f32}\left(x, s\right)\right)\right)\right)\right) \]
    4. Applied egg-rr99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \color{blue}{\left(1 + \frac{x}{s}\right)}\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \left(\frac{x}{s} + \color{blue}{1}\right)\right)\right)\right) \]
      2. +-lowering-+.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\left(\frac{x}{s}\right), \color{blue}{1}\right)\right)\right)\right) \]
      3. /-lowering-/.f3292.3%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(1, \mathsf{/.f32}\left(-1, \mathsf{+.f32}\left(\mathsf{/.f32}\left(x, s\right), 1\right)\right)\right)\right) \]
    7. Simplified92.3%

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

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

Alternative 17: 58.0% accurate, 7.7× speedup?

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

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

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


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

    1. Initial program 99.9%

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

      \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + x \cdot \left(x \cdot \left(\frac{-1}{6} \cdot \frac{x}{{s}^{3}} + \frac{1}{2} \cdot \frac{1}{{s}^{2}}\right) - \frac{1}{s}\right)\right)}\right) \]
    4. Simplified88.3%

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

      \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \color{blue}{\left(\frac{\frac{1}{2}}{{s}^{2}}\right)}\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left({s}^{2}\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \left(s \cdot s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
      3. *-lowering-*.f3283.0%

        \[\leadsto \mathsf{/.f32}\left(1, \mathsf{+.f32}\left(2, \mathsf{*.f32}\left(x, \mathsf{+.f32}\left(\mathsf{*.f32}\left(x, \mathsf{/.f32}\left(\frac{1}{2}, \mathsf{*.f32}\left(s, s\right)\right)\right), \mathsf{/.f32}\left(-1, s\right)\right)\right)\right)\right) \]
    7. Simplified83.0%

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

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

        \[\leadsto \frac{2 \cdot {s}^{2}}{\color{blue}{{x}^{2}}} \]
      2. unpow2N/A

        \[\leadsto \frac{2 \cdot {s}^{2}}{x \cdot \color{blue}{x}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{2 \cdot {s}^{2}}{x}}{\color{blue}{x}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\frac{{s}^{2} \cdot 2}{x}}{x} \]
      5. associate-*r/N/A

        \[\leadsto \frac{{s}^{2} \cdot \frac{2}{x}}{x} \]
      6. metadata-evalN/A

        \[\leadsto \frac{{s}^{2} \cdot \frac{2 \cdot 1}{x}}{x} \]
      7. associate-*r/N/A

        \[\leadsto \frac{{s}^{2} \cdot \left(2 \cdot \frac{1}{x}\right)}{x} \]
      8. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{2} \cdot \left(2 \cdot \frac{1}{x}\right)\right), \color{blue}{x}\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{2} \cdot \frac{2 \cdot 1}{x}\right), x\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{/.f32}\left(\left({s}^{2} \cdot \frac{2}{x}\right), x\right) \]
      11. associate-*r/N/A

        \[\leadsto \mathsf{/.f32}\left(\left(\frac{{s}^{2} \cdot 2}{x}\right), x\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{/.f32}\left(\left(\frac{2 \cdot {s}^{2}}{x}\right), x\right) \]
      13. /-lowering-/.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(2 \cdot {s}^{2}\right), x\right), x\right) \]
      14. *-lowering-*.f32N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(2, \left({s}^{2}\right)\right), x\right), x\right) \]
      15. unpow2N/A

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(2, \left(s \cdot s\right)\right), x\right), x\right) \]
      16. *-lowering-*.f3273.5%

        \[\leadsto \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(2, \mathsf{*.f32}\left(s, s\right)\right), x\right), x\right) \]
    10. Simplified73.5%

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

    if -1.00000003e-22 < x

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\frac{1}{2}} \]
    4. Step-by-step derivation
      1. Simplified49.3%

        \[\leadsto \color{blue}{0.5} \]
    5. Recombined 2 regimes into one program.
    6. Add Preprocessing

    Alternative 18: 57.4% accurate, 7.7× speedup?

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

      1. Initial program 99.9%

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

        \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + -1 \cdot \frac{x}{s}\right)}\right) \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(\mathsf{neg}\left(\frac{x}{s}\right)\right)\right)\right) \]
        2. unsub-negN/A

          \[\leadsto \mathsf{/.f32}\left(1, \left(2 - \color{blue}{\frac{x}{s}}\right)\right) \]
        3. --lowering--.f32N/A

          \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \color{blue}{\left(\frac{x}{s}\right)}\right)\right) \]
        4. /-lowering-/.f3242.3%

          \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \mathsf{/.f32}\left(x, \color{blue}{s}\right)\right)\right) \]
      5. Simplified42.3%

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

        \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{s}^{2}}{x} + -1 \cdot s}{x}} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \frac{-1 \cdot s + -2 \cdot \frac{{s}^{2}}{x}}{x} \]
        2. metadata-evalN/A

          \[\leadsto \frac{-1 \cdot s + \left(\mathsf{neg}\left(2\right)\right) \cdot \frac{{s}^{2}}{x}}{x} \]
        3. cancel-sign-sub-invN/A

          \[\leadsto \frac{-1 \cdot s - 2 \cdot \frac{{s}^{2}}{x}}{x} \]
        4. /-lowering-/.f32N/A

          \[\leadsto \mathsf{/.f32}\left(\left(-1 \cdot s - 2 \cdot \frac{{s}^{2}}{x}\right), \color{blue}{x}\right) \]
        5. cancel-sign-sub-invN/A

          \[\leadsto \mathsf{/.f32}\left(\left(-1 \cdot s + \left(\mathsf{neg}\left(2\right)\right) \cdot \frac{{s}^{2}}{x}\right), x\right) \]
        6. metadata-evalN/A

          \[\leadsto \mathsf{/.f32}\left(\left(-1 \cdot s + -2 \cdot \frac{{s}^{2}}{x}\right), x\right) \]
        7. +-commutativeN/A

          \[\leadsto \mathsf{/.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x} + -1 \cdot s\right), x\right) \]
        8. mul-1-negN/A

          \[\leadsto \mathsf{/.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x} + \left(\mathsf{neg}\left(s\right)\right)\right), x\right) \]
        9. unsub-negN/A

          \[\leadsto \mathsf{/.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x} - s\right), x\right) \]
        10. --lowering--.f32N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x}\right), s\right), x\right) \]
        11. associate-*r/N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-2 \cdot {s}^{2}}{x}\right), s\right), x\right) \]
        12. metadata-evalN/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\left(\mathsf{neg}\left(2\right)\right) \cdot {s}^{2}}{x}\right), s\right), x\right) \]
        13. /-lowering-/.f32N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(\left(\mathsf{neg}\left(2\right)\right) \cdot {s}^{2}\right), x\right), s\right), x\right) \]
        14. metadata-evalN/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(-2 \cdot {s}^{2}\right), x\right), s\right), x\right) \]
        15. *-commutativeN/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({s}^{2} \cdot -2\right), x\right), s\right), x\right) \]
        16. *-lowering-*.f32N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({s}^{2}\right), -2\right), x\right), s\right), x\right) \]
        17. unpow2N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(s \cdot s\right), -2\right), x\right), s\right), x\right) \]
        18. *-lowering-*.f3232.0%

          \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -2\right), x\right), s\right), x\right) \]
      8. Simplified32.0%

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

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

          \[\leadsto \frac{-2 \cdot {s}^{2}}{\color{blue}{{x}^{2}}} \]
        2. /-lowering-/.f32N/A

          \[\leadsto \mathsf{/.f32}\left(\left(-2 \cdot {s}^{2}\right), \color{blue}{\left({x}^{2}\right)}\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{/.f32}\left(\left({s}^{2} \cdot -2\right), \left({\color{blue}{x}}^{2}\right)\right) \]
        4. unpow2N/A

          \[\leadsto \mathsf{/.f32}\left(\left(\left(s \cdot s\right) \cdot -2\right), \left({x}^{2}\right)\right) \]
        5. associate-*l*N/A

          \[\leadsto \mathsf{/.f32}\left(\left(s \cdot \left(s \cdot -2\right)\right), \left({\color{blue}{x}}^{2}\right)\right) \]
        6. *-commutativeN/A

          \[\leadsto \mathsf{/.f32}\left(\left(s \cdot \left(-2 \cdot s\right)\right), \left({x}^{2}\right)\right) \]
        7. *-lowering-*.f32N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \left(-2 \cdot s\right)\right), \left({\color{blue}{x}}^{2}\right)\right) \]
        8. *-commutativeN/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \left(s \cdot -2\right)\right), \left({x}^{2}\right)\right) \]
        9. *-lowering-*.f32N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, -2\right)\right), \left({x}^{2}\right)\right) \]
        10. unpow2N/A

          \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, -2\right)\right), \left(x \cdot \color{blue}{x}\right)\right) \]
        11. *-lowering-*.f3272.8%

          \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{*.f32}\left(s, -2\right)\right), \mathsf{*.f32}\left(x, \color{blue}{x}\right)\right) \]
      11. Simplified72.8%

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

      if -1.00000003e-22 < x

      1. Initial program 99.9%

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

        \[\leadsto \color{blue}{\frac{1}{2}} \]
      4. Step-by-step derivation
        1. Simplified49.3%

          \[\leadsto \color{blue}{0.5} \]
      5. Recombined 2 regimes into one program.
      6. Add Preprocessing

      Alternative 19: 57.5% accurate, 7.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.000000031374395 \cdot 10^{-22}:\\ \;\;\;\;-2 \cdot \frac{\frac{s \cdot s}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \end{array} \]
      (FPCore (x s)
       :precision binary32
       (if (<= x -1.000000031374395e-22) (* -2.0 (/ (/ (* s s) x) x)) 0.5))
      float code(float x, float s) {
      	float tmp;
      	if (x <= -1.000000031374395e-22f) {
      		tmp = -2.0f * (((s * s) / x) / 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.000000031374395e-22)) then
              tmp = (-2.0e0) * (((s * s) / x) / x)
          else
              tmp = 0.5e0
          end if
          code = tmp
      end function
      
      function code(x, s)
      	tmp = Float32(0.0)
      	if (x <= Float32(-1.000000031374395e-22))
      		tmp = Float32(Float32(-2.0) * Float32(Float32(Float32(s * s) / x) / x));
      	else
      		tmp = Float32(0.5);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, s)
      	tmp = single(0.0);
      	if (x <= single(-1.000000031374395e-22))
      		tmp = single(-2.0) * (((s * s) / x) / x);
      	else
      		tmp = single(0.5);
      	end
      	tmp_2 = tmp;
      end
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq -1.000000031374395 \cdot 10^{-22}:\\
      \;\;\;\;-2 \cdot \frac{\frac{s \cdot s}{x}}{x}\\
      
      \mathbf{else}:\\
      \;\;\;\;0.5\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -1.00000003e-22

        1. Initial program 99.9%

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

          \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + -1 \cdot \frac{x}{s}\right)}\right) \]
        4. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(\mathsf{neg}\left(\frac{x}{s}\right)\right)\right)\right) \]
          2. unsub-negN/A

            \[\leadsto \mathsf{/.f32}\left(1, \left(2 - \color{blue}{\frac{x}{s}}\right)\right) \]
          3. --lowering--.f32N/A

            \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \color{blue}{\left(\frac{x}{s}\right)}\right)\right) \]
          4. /-lowering-/.f3242.3%

            \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \mathsf{/.f32}\left(x, \color{blue}{s}\right)\right)\right) \]
        5. Simplified42.3%

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

          \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{s}^{2}}{x} + -1 \cdot s}{x}} \]
        7. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \frac{-1 \cdot s + -2 \cdot \frac{{s}^{2}}{x}}{x} \]
          2. metadata-evalN/A

            \[\leadsto \frac{-1 \cdot s + \left(\mathsf{neg}\left(2\right)\right) \cdot \frac{{s}^{2}}{x}}{x} \]
          3. cancel-sign-sub-invN/A

            \[\leadsto \frac{-1 \cdot s - 2 \cdot \frac{{s}^{2}}{x}}{x} \]
          4. /-lowering-/.f32N/A

            \[\leadsto \mathsf{/.f32}\left(\left(-1 \cdot s - 2 \cdot \frac{{s}^{2}}{x}\right), \color{blue}{x}\right) \]
          5. cancel-sign-sub-invN/A

            \[\leadsto \mathsf{/.f32}\left(\left(-1 \cdot s + \left(\mathsf{neg}\left(2\right)\right) \cdot \frac{{s}^{2}}{x}\right), x\right) \]
          6. metadata-evalN/A

            \[\leadsto \mathsf{/.f32}\left(\left(-1 \cdot s + -2 \cdot \frac{{s}^{2}}{x}\right), x\right) \]
          7. +-commutativeN/A

            \[\leadsto \mathsf{/.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x} + -1 \cdot s\right), x\right) \]
          8. mul-1-negN/A

            \[\leadsto \mathsf{/.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x} + \left(\mathsf{neg}\left(s\right)\right)\right), x\right) \]
          9. unsub-negN/A

            \[\leadsto \mathsf{/.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x} - s\right), x\right) \]
          10. --lowering--.f32N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(-2 \cdot \frac{{s}^{2}}{x}\right), s\right), x\right) \]
          11. associate-*r/N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{-2 \cdot {s}^{2}}{x}\right), s\right), x\right) \]
          12. metadata-evalN/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\left(\frac{\left(\mathsf{neg}\left(2\right)\right) \cdot {s}^{2}}{x}\right), s\right), x\right) \]
          13. /-lowering-/.f32N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(\left(\mathsf{neg}\left(2\right)\right) \cdot {s}^{2}\right), x\right), s\right), x\right) \]
          14. metadata-evalN/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left(-2 \cdot {s}^{2}\right), x\right), s\right), x\right) \]
          15. *-commutativeN/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\left({s}^{2} \cdot -2\right), x\right), s\right), x\right) \]
          16. *-lowering-*.f32N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left({s}^{2}\right), -2\right), x\right), s\right), x\right) \]
          17. unpow2N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\left(s \cdot s\right), -2\right), x\right), s\right), x\right) \]
          18. *-lowering-*.f3232.0%

            \[\leadsto \mathsf{/.f32}\left(\mathsf{\_.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(\mathsf{*.f32}\left(s, s\right), -2\right), x\right), s\right), x\right) \]
        8. Simplified32.0%

          \[\leadsto \color{blue}{\frac{\frac{\left(s \cdot s\right) \cdot -2}{x} - s}{x}} \]
        9. Step-by-step derivation
          1. sub-negN/A

            \[\leadsto \mathsf{/.f32}\left(\left(\frac{\left(s \cdot s\right) \cdot -2}{x} + \left(\mathsf{neg}\left(s\right)\right)\right), x\right) \]
          2. associate-*l*N/A

            \[\leadsto \mathsf{/.f32}\left(\left(\frac{s \cdot \left(s \cdot -2\right)}{x} + \left(\mathsf{neg}\left(s\right)\right)\right), x\right) \]
          3. associate-/l*N/A

            \[\leadsto \mathsf{/.f32}\left(\left(s \cdot \frac{s \cdot -2}{x} + \left(\mathsf{neg}\left(s\right)\right)\right), x\right) \]
          4. neg-mul-1N/A

            \[\leadsto \mathsf{/.f32}\left(\left(s \cdot \frac{s \cdot -2}{x} + -1 \cdot s\right), x\right) \]
          5. *-commutativeN/A

            \[\leadsto \mathsf{/.f32}\left(\left(s \cdot \frac{s \cdot -2}{x} + s \cdot -1\right), x\right) \]
          6. distribute-lft-outN/A

            \[\leadsto \mathsf{/.f32}\left(\left(s \cdot \left(\frac{s \cdot -2}{x} + -1\right)\right), x\right) \]
          7. *-lowering-*.f32N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \left(\frac{s \cdot -2}{x} + -1\right)\right), x\right) \]
          8. +-lowering-+.f32N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\left(\frac{s \cdot -2}{x}\right), -1\right)\right), x\right) \]
          9. div-invN/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\left(\left(s \cdot -2\right) \cdot \frac{1}{x}\right), -1\right)\right), x\right) \]
          10. associate-*r*N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\left(s \cdot \left(-2 \cdot \frac{1}{x}\right)\right), -1\right)\right), x\right) \]
          11. div-invN/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\left(s \cdot \frac{-2}{x}\right), -1\right)\right), x\right) \]
          12. clear-numN/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\left(s \cdot \frac{1}{\frac{x}{-2}}\right), -1\right)\right), x\right) \]
          13. un-div-invN/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\left(\frac{s}{\frac{x}{-2}}\right), -1\right)\right), x\right) \]
          14. /-lowering-/.f32N/A

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\mathsf{/.f32}\left(s, \left(\frac{x}{-2}\right)\right), -1\right)\right), x\right) \]
          15. /-lowering-/.f3232.0%

            \[\leadsto \mathsf{/.f32}\left(\mathsf{*.f32}\left(s, \mathsf{+.f32}\left(\mathsf{/.f32}\left(s, \mathsf{/.f32}\left(x, -2\right)\right), -1\right)\right), x\right) \]
        10. Applied egg-rr32.0%

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

          \[\leadsto \color{blue}{-2 \cdot \frac{{s}^{2}}{{x}^{2}}} \]
        12. Step-by-step derivation
          1. *-lowering-*.f32N/A

            \[\leadsto \mathsf{*.f32}\left(-2, \color{blue}{\left(\frac{{s}^{2}}{{x}^{2}}\right)}\right) \]
          2. unpow2N/A

            \[\leadsto \mathsf{*.f32}\left(-2, \left(\frac{{s}^{2}}{x \cdot \color{blue}{x}}\right)\right) \]
          3. associate-/r*N/A

            \[\leadsto \mathsf{*.f32}\left(-2, \left(\frac{\frac{{s}^{2}}{x}}{\color{blue}{x}}\right)\right) \]
          4. /-lowering-/.f32N/A

            \[\leadsto \mathsf{*.f32}\left(-2, \mathsf{/.f32}\left(\left(\frac{{s}^{2}}{x}\right), \color{blue}{x}\right)\right) \]
          5. /-lowering-/.f32N/A

            \[\leadsto \mathsf{*.f32}\left(-2, \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left({s}^{2}\right), x\right), x\right)\right) \]
          6. unpow2N/A

            \[\leadsto \mathsf{*.f32}\left(-2, \mathsf{/.f32}\left(\mathsf{/.f32}\left(\left(s \cdot s\right), x\right), x\right)\right) \]
          7. *-lowering-*.f3272.7%

            \[\leadsto \mathsf{*.f32}\left(-2, \mathsf{/.f32}\left(\mathsf{/.f32}\left(\mathsf{*.f32}\left(s, s\right), x\right), x\right)\right) \]
        13. Simplified72.7%

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

        if -1.00000003e-22 < x

        1. Initial program 99.9%

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

          \[\leadsto \color{blue}{\frac{1}{2}} \]
        4. Step-by-step derivation
          1. Simplified49.3%

            \[\leadsto \color{blue}{0.5} \]
        5. Recombined 2 regimes into one program.
        6. Add Preprocessing

        Alternative 20: 48.8% accurate, 9.0× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.9999999593223797 \cdot 10^{-31}:\\ \;\;\;\;\frac{1}{2 - \frac{x}{s}}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \end{array} \]
        (FPCore (x s)
         :precision binary32
         (if (<= x 1.9999999593223797e-31) (/ 1.0 (- 2.0 (/ x s))) 0.5))
        float code(float x, float s) {
        	float tmp;
        	if (x <= 1.9999999593223797e-31f) {
        		tmp = 1.0f / (2.0f - (x / s));
        	} 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.9999999593223797e-31) then
                tmp = 1.0e0 / (2.0e0 - (x / s))
            else
                tmp = 0.5e0
            end if
            code = tmp
        end function
        
        function code(x, s)
        	tmp = Float32(0.0)
        	if (x <= Float32(1.9999999593223797e-31))
        		tmp = Float32(Float32(1.0) / Float32(Float32(2.0) - Float32(x / s)));
        	else
        		tmp = Float32(0.5);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, s)
        	tmp = single(0.0);
        	if (x <= single(1.9999999593223797e-31))
        		tmp = single(1.0) / (single(2.0) - (x / s));
        	else
        		tmp = single(0.5);
        	end
        	tmp_2 = tmp;
        end
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq 1.9999999593223797 \cdot 10^{-31}:\\
        \;\;\;\;\frac{1}{2 - \frac{x}{s}}\\
        
        \mathbf{else}:\\
        \;\;\;\;0.5\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < 1.99999996e-31

          1. Initial program 99.8%

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

            \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + -1 \cdot \frac{x}{s}\right)}\right) \]
          4. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(\mathsf{neg}\left(\frac{x}{s}\right)\right)\right)\right) \]
            2. unsub-negN/A

              \[\leadsto \mathsf{/.f32}\left(1, \left(2 - \color{blue}{\frac{x}{s}}\right)\right) \]
            3. --lowering--.f32N/A

              \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \color{blue}{\left(\frac{x}{s}\right)}\right)\right) \]
            4. /-lowering-/.f3254.2%

              \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \mathsf{/.f32}\left(x, \color{blue}{s}\right)\right)\right) \]
          5. Simplified54.2%

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

          if 1.99999996e-31 < x

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{\frac{1}{2}} \]
          4. Step-by-step derivation
            1. Simplified38.5%

              \[\leadsto \color{blue}{0.5} \]
          5. Recombined 2 regimes into one program.
          6. Add Preprocessing

          Alternative 21: 46.9% accurate, 10.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.99999996490334 \cdot 10^{-14}:\\ \;\;\;\;\frac{-1}{\frac{x}{s}}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \end{array} \]
          (FPCore (x s)
           :precision binary32
           (if (<= x -1.99999996490334e-14) (/ -1.0 (/ x s)) 0.5))
          float code(float x, float s) {
          	float tmp;
          	if (x <= -1.99999996490334e-14f) {
          		tmp = -1.0f / (x / s);
          	} 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.99999996490334e-14)) then
                  tmp = (-1.0e0) / (x / s)
              else
                  tmp = 0.5e0
              end if
              code = tmp
          end function
          
          function code(x, s)
          	tmp = Float32(0.0)
          	if (x <= Float32(-1.99999996490334e-14))
          		tmp = Float32(Float32(-1.0) / Float32(x / s));
          	else
          		tmp = Float32(0.5);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, s)
          	tmp = single(0.0);
          	if (x <= single(-1.99999996490334e-14))
          		tmp = single(-1.0) / (x / s);
          	else
          		tmp = single(0.5);
          	end
          	tmp_2 = tmp;
          end
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;x \leq -1.99999996490334 \cdot 10^{-14}:\\
          \;\;\;\;\frac{-1}{\frac{x}{s}}\\
          
          \mathbf{else}:\\
          \;\;\;\;0.5\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < -1.99999996e-14

            1. Initial program 100.0%

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

              \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + -1 \cdot \frac{x}{s}\right)}\right) \]
            4. Step-by-step derivation
              1. mul-1-negN/A

                \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(\mathsf{neg}\left(\frac{x}{s}\right)\right)\right)\right) \]
              2. unsub-negN/A

                \[\leadsto \mathsf{/.f32}\left(1, \left(2 - \color{blue}{\frac{x}{s}}\right)\right) \]
              3. --lowering--.f32N/A

                \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \color{blue}{\left(\frac{x}{s}\right)}\right)\right) \]
              4. /-lowering-/.f3241.9%

                \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \mathsf{/.f32}\left(x, \color{blue}{s}\right)\right)\right) \]
            5. Simplified41.9%

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

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

                \[\leadsto \mathsf{neg}\left(\frac{s}{x}\right) \]
              2. neg-sub0N/A

                \[\leadsto 0 - \color{blue}{\frac{s}{x}} \]
              3. --lowering--.f32N/A

                \[\leadsto \mathsf{\_.f32}\left(0, \color{blue}{\left(\frac{s}{x}\right)}\right) \]
              4. /-lowering-/.f3237.4%

                \[\leadsto \mathsf{\_.f32}\left(0, \mathsf{/.f32}\left(s, \color{blue}{x}\right)\right) \]
            8. Simplified37.4%

              \[\leadsto \color{blue}{0 - \frac{s}{x}} \]
            9. Step-by-step derivation
              1. sub0-negN/A

                \[\leadsto \mathsf{neg}\left(\frac{s}{x}\right) \]
              2. clear-numN/A

                \[\leadsto \mathsf{neg}\left(\frac{1}{\frac{x}{s}}\right) \]
              3. distribute-neg-fracN/A

                \[\leadsto \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\frac{x}{s}}} \]
              4. metadata-evalN/A

                \[\leadsto \frac{-1}{\frac{\color{blue}{x}}{s}} \]
              5. /-lowering-/.f32N/A

                \[\leadsto \mathsf{/.f32}\left(-1, \color{blue}{\left(\frac{x}{s}\right)}\right) \]
              6. /-lowering-/.f3241.9%

                \[\leadsto \mathsf{/.f32}\left(-1, \mathsf{/.f32}\left(x, \color{blue}{s}\right)\right) \]
            10. Applied egg-rr41.9%

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

            if -1.99999996e-14 < x

            1. Initial program 99.8%

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

              \[\leadsto \color{blue}{\frac{1}{2}} \]
            4. Step-by-step derivation
              1. Simplified48.4%

                \[\leadsto \color{blue}{0.5} \]
            5. Recombined 2 regimes into one program.
            6. Add Preprocessing

            Alternative 22: 45.6% accurate, 12.0× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.99999996490334 \cdot 10^{-14}:\\ \;\;\;\;\frac{s}{-x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \end{array} \]
            (FPCore (x s)
             :precision binary32
             (if (<= x -1.99999996490334e-14) (/ s (- x)) 0.5))
            float code(float x, float s) {
            	float tmp;
            	if (x <= -1.99999996490334e-14f) {
            		tmp = s / -x;
            	} else {
            		tmp = 0.5f;
            	}
            	return tmp;
            }
            
            real(4) function code(x, s)
                real(4), intent (in) :: x
                real(4), intent (in) :: s
                real(4) :: tmp
                if (x <= (-1.99999996490334e-14)) then
                    tmp = s / -x
                else
                    tmp = 0.5e0
                end if
                code = tmp
            end function
            
            function code(x, s)
            	tmp = Float32(0.0)
            	if (x <= Float32(-1.99999996490334e-14))
            		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(-1.99999996490334e-14))
            		tmp = s / -x;
            	else
            		tmp = single(0.5);
            	end
            	tmp_2 = tmp;
            end
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;x \leq -1.99999996490334 \cdot 10^{-14}:\\
            \;\;\;\;\frac{s}{-x}\\
            
            \mathbf{else}:\\
            \;\;\;\;0.5\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if x < -1.99999996e-14

              1. Initial program 100.0%

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

                \[\leadsto \mathsf{/.f32}\left(1, \color{blue}{\left(2 + -1 \cdot \frac{x}{s}\right)}\right) \]
              4. Step-by-step derivation
                1. mul-1-negN/A

                  \[\leadsto \mathsf{/.f32}\left(1, \left(2 + \left(\mathsf{neg}\left(\frac{x}{s}\right)\right)\right)\right) \]
                2. unsub-negN/A

                  \[\leadsto \mathsf{/.f32}\left(1, \left(2 - \color{blue}{\frac{x}{s}}\right)\right) \]
                3. --lowering--.f32N/A

                  \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \color{blue}{\left(\frac{x}{s}\right)}\right)\right) \]
                4. /-lowering-/.f3241.9%

                  \[\leadsto \mathsf{/.f32}\left(1, \mathsf{\_.f32}\left(2, \mathsf{/.f32}\left(x, \color{blue}{s}\right)\right)\right) \]
              5. Simplified41.9%

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

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

                  \[\leadsto \mathsf{neg}\left(\frac{s}{x}\right) \]
                2. neg-sub0N/A

                  \[\leadsto 0 - \color{blue}{\frac{s}{x}} \]
                3. --lowering--.f32N/A

                  \[\leadsto \mathsf{\_.f32}\left(0, \color{blue}{\left(\frac{s}{x}\right)}\right) \]
                4. /-lowering-/.f3237.4%

                  \[\leadsto \mathsf{\_.f32}\left(0, \mathsf{/.f32}\left(s, \color{blue}{x}\right)\right) \]
              8. Simplified37.4%

                \[\leadsto \color{blue}{0 - \frac{s}{x}} \]
              9. Step-by-step derivation
                1. sub0-negN/A

                  \[\leadsto \mathsf{neg}\left(\frac{s}{x}\right) \]
                2. distribute-frac-negN/A

                  \[\leadsto \frac{\mathsf{neg}\left(s\right)}{\color{blue}{x}} \]
                3. /-lowering-/.f32N/A

                  \[\leadsto \mathsf{/.f32}\left(\left(\mathsf{neg}\left(s\right)\right), \color{blue}{x}\right) \]
                4. neg-lowering-neg.f3237.4%

                  \[\leadsto \mathsf{/.f32}\left(\mathsf{neg.f32}\left(s\right), x\right) \]
              10. Applied egg-rr37.4%

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

              if -1.99999996e-14 < x

              1. Initial program 99.8%

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

                \[\leadsto \color{blue}{\frac{1}{2}} \]
              4. Step-by-step derivation
                1. Simplified48.4%

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

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

              Alternative 23: 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. Add Preprocessing
              3. Taylor expanded in x around 0

                \[\leadsto \color{blue}{\frac{1}{2}} \]
              4. Step-by-step derivation
                1. Simplified35.0%

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

                Reproduce

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