Logistic distribution

Percentage Accurate: 99.6% → 99.6%
Time: 14.5s
Alternatives: 15
Speedup: 1.5×

Specification

?
\[0 \leq s \land s \leq 1.0651631\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ t_1 := 1 + t_0\\ \frac{t_0}{\left(s \cdot t_1\right) \cdot t_1} \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0)))
   (/ t_0 (* (* s t_1) t_1))))
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	float t_1 = 1.0f + t_0;
	return t_0 / ((s * t_1) * t_1);
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: t_1
    t_0 = exp((-abs(x) / s))
    t_1 = 1.0e0 + t_0
    code = t_0 / ((s * t_1) * t_1)
end function
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	t_1 = Float32(Float32(1.0) + t_0)
	return Float32(t_0 / Float32(Float32(s * t_1) * t_1))
end
function tmp = code(x, s)
	t_0 = exp((-abs(x) / s));
	t_1 = single(1.0) + t_0;
	tmp = t_0 / ((s * t_1) * t_1);
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t_0\\
\frac{t_0}{\left(s \cdot t_1\right) \cdot t_1}
\end{array}
\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 15 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.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t_0\\
\frac{t_0}{\left(s \cdot t_1\right) \cdot t_1}
\end{array}
\end{array}

Alternative 1: 99.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{\frac{t_0}{s + s \cdot t_0}}{t_0 + 1}
\end{array}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.4%

    \[\leadsto \color{blue}{\frac{\frac{e^{-\frac{\left|x\right|}{s}}}{s + s \cdot e^{-\frac{\left|x\right|}{s}}}}{1 + e^{-\frac{\left|x\right|}{s}}}} \]
  3. Final simplification99.4%

    \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s + s \cdot e^{\frac{-\left|x\right|}{s}}}}{e^{\frac{-\left|x\right|}{s}} + 1} \]

Alternative 2: 99.6% accurate, 1.5× speedup?

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

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

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Taylor expanded in s around 0 99.4%

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

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

      \[\leadsto \frac{1}{s \cdot \left(\left(1 + e^{\color{blue}{-\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)} \]
    3. distribute-frac-neg99.4%

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

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

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

Alternative 3: 99.6% accurate, 1.5× speedup?

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

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

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Taylor expanded in s around 0 99.4%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)}} \]
  4. Step-by-step derivation
    1. associate-*r*99.5%

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

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

      \[\leadsto \frac{1}{\left(s \cdot \left(1 + e^{\color{blue}{-\frac{\left|x\right|}{s}}}\right)\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    4. distribute-lft-in99.4%

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

      \[\leadsto \frac{1}{\left(\color{blue}{s} + s \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    6. rem-exp-log98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{e^{\log s}} \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    7. neg-mul-198.0%

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

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

      \[\leadsto \frac{1}{\left(s + e^{\log s + \color{blue}{\left(-\frac{\left|x\right|}{s}\right)}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    10. sub-neg97.9%

      \[\leadsto \frac{1}{\left(s + e^{\color{blue}{\log s - \frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    11. exp-diff98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{\frac{e^{\log s}}{e^{\frac{\left|x\right|}{s}}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    12. rem-exp-log99.4%

      \[\leadsto \frac{1}{\left(s + \frac{\color{blue}{s}}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  5. Simplified99.4%

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

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

      \[\leadsto \frac{1}{\left(s + s \cdot \color{blue}{e^{-\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    3. *-commutative99.4%

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

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

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

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

Alternative 4: 99.6% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{\left|x\right|}{s}}\\
\frac{1}{\left(1 + t_0\right) \cdot \left(s + \frac{s}{t_0}\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Taylor expanded in s around 0 99.4%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)}} \]
  4. Step-by-step derivation
    1. associate-*r*99.5%

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

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

      \[\leadsto \frac{1}{\left(s \cdot \left(1 + e^{\color{blue}{-\frac{\left|x\right|}{s}}}\right)\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    4. distribute-lft-in99.4%

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

      \[\leadsto \frac{1}{\left(\color{blue}{s} + s \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    6. rem-exp-log98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{e^{\log s}} \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    7. neg-mul-198.0%

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

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

      \[\leadsto \frac{1}{\left(s + e^{\log s + \color{blue}{\left(-\frac{\left|x\right|}{s}\right)}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    10. sub-neg97.9%

      \[\leadsto \frac{1}{\left(s + e^{\color{blue}{\log s - \frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    11. exp-diff98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{\frac{e^{\log s}}{e^{\frac{\left|x\right|}{s}}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    12. rem-exp-log99.4%

      \[\leadsto \frac{1}{\left(s + \frac{\color{blue}{s}}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  5. Simplified99.4%

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

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

Alternative 5: 97.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\left|x\right|}{s}\\
\frac{1}{\left(1 + e^{t_0}\right) \cdot \left(s + \frac{s}{t_0 + 1}\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Taylor expanded in s around 0 99.4%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)}} \]
  4. Step-by-step derivation
    1. associate-*r*99.5%

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

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

      \[\leadsto \frac{1}{\left(s \cdot \left(1 + e^{\color{blue}{-\frac{\left|x\right|}{s}}}\right)\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    4. distribute-lft-in99.4%

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

      \[\leadsto \frac{1}{\left(\color{blue}{s} + s \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    6. rem-exp-log98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{e^{\log s}} \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    7. neg-mul-198.0%

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

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

      \[\leadsto \frac{1}{\left(s + e^{\log s + \color{blue}{\left(-\frac{\left|x\right|}{s}\right)}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    10. sub-neg97.9%

      \[\leadsto \frac{1}{\left(s + e^{\color{blue}{\log s - \frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    11. exp-diff98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{\frac{e^{\log s}}{e^{\frac{\left|x\right|}{s}}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    12. rem-exp-log99.4%

      \[\leadsto \frac{1}{\left(s + \frac{\color{blue}{s}}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{\frac{1}{\left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  6. Taylor expanded in s around inf 97.4%

    \[\leadsto \frac{1}{\left(s + \frac{s}{\color{blue}{1 + \frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  7. Step-by-step derivation
    1. +-commutative95.7%

      \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{s \cdot 3}{\color{blue}{\frac{\left|x\right|}{s} + 1}}} \]
  8. Simplified97.4%

    \[\leadsto \frac{1}{\left(s + \frac{s}{\color{blue}{\frac{\left|x\right|}{s} + 1}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  9. Final simplification97.4%

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

Alternative 6: 95.7% accurate, 2.0× speedup?

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

\\
\frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{s \cdot 3}{\frac{\left|x\right|}{s} + 1}}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.4%

    \[\leadsto \color{blue}{\frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{s \cdot \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}{e^{\frac{\left|x\right|}{s}}}}} \]
  3. Taylor expanded in s around inf 96.2%

    \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{\color{blue}{3 \cdot s}}{e^{\frac{\left|x\right|}{s}}}} \]
  4. Step-by-step derivation
    1. *-commutative96.2%

      \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{\color{blue}{s \cdot 3}}{e^{\frac{\left|x\right|}{s}}}} \]
  5. Simplified96.2%

    \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{\color{blue}{s \cdot 3}}{e^{\frac{\left|x\right|}{s}}}} \]
  6. Taylor expanded in s around inf 95.7%

    \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{s \cdot 3}{\color{blue}{1 + \frac{\left|x\right|}{s}}}} \]
  7. Step-by-step derivation
    1. +-commutative95.7%

      \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{s \cdot 3}{\color{blue}{\frac{\left|x\right|}{s} + 1}}} \]
  8. Simplified95.7%

    \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s + \frac{s \cdot 3}{\color{blue}{\frac{\left|x\right|}{s} + 1}}} \]
  9. Final simplification95.7%

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

Alternative 7: 95.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \frac{1}{\left(s + s\right) \cdot \left(1 + {e}^{\left(\frac{\left|x\right|}{s}\right)}\right)} \end{array} \]
(FPCore (x s)
 :precision binary32
 (/ 1.0 (* (+ s s) (+ 1.0 (pow E (/ (fabs x) s))))))
float code(float x, float s) {
	return 1.0f / ((s + s) * (1.0f + powf(((float) M_E), (fabsf(x) / s))));
}
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(s + s) * Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(abs(x) / s)))))
end
function tmp = code(x, s)
	tmp = single(1.0) / ((s + s) * (single(1.0) + (single(2.71828182845904523536) ^ (abs(x) / s))));
end
\begin{array}{l}

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

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Taylor expanded in s around 0 99.4%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)}} \]
  4. Step-by-step derivation
    1. associate-*r*99.5%

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

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

      \[\leadsto \frac{1}{\left(s \cdot \left(1 + e^{\color{blue}{-\frac{\left|x\right|}{s}}}\right)\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    4. distribute-lft-in99.4%

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

      \[\leadsto \frac{1}{\left(\color{blue}{s} + s \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    6. rem-exp-log98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{e^{\log s}} \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    7. neg-mul-198.0%

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

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

      \[\leadsto \frac{1}{\left(s + e^{\log s + \color{blue}{\left(-\frac{\left|x\right|}{s}\right)}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    10. sub-neg97.9%

      \[\leadsto \frac{1}{\left(s + e^{\color{blue}{\log s - \frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    11. exp-diff98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{\frac{e^{\log s}}{e^{\frac{\left|x\right|}{s}}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    12. rem-exp-log99.4%

      \[\leadsto \frac{1}{\left(s + \frac{\color{blue}{s}}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{\frac{1}{\left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  6. Taylor expanded in s around inf 95.3%

    \[\leadsto \frac{1}{\left(s + \color{blue}{s}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  7. Step-by-step derivation
    1. *-un-lft-identity95.3%

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

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

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

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

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

Alternative 8: 88.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \frac{x}{s}\\ \mathbf{if}\;\left|x\right| \leq 1.3500000359991076 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(2, t_0, s \cdot 4\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{s \cdot e^{\frac{\left|x\right|}{s}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (* x (/ x s))))
   (if (<= (fabs x) 1.3500000359991076e-17)
     (/ 1.0 (- (fma 2.0 t_0 (* s 4.0)) t_0))
     (/ 0.5 (* s (exp (/ (fabs x) s)))))))
float code(float x, float s) {
	float t_0 = x * (x / s);
	float tmp;
	if (fabsf(x) <= 1.3500000359991076e-17f) {
		tmp = 1.0f / (fmaf(2.0f, t_0, (s * 4.0f)) - t_0);
	} else {
		tmp = 0.5f / (s * expf((fabsf(x) / s)));
	}
	return tmp;
}
function code(x, s)
	t_0 = Float32(x * Float32(x / s))
	tmp = Float32(0.0)
	if (abs(x) <= Float32(1.3500000359991076e-17))
		tmp = Float32(Float32(1.0) / Float32(fma(Float32(2.0), t_0, Float32(s * Float32(4.0))) - t_0));
	else
		tmp = Float32(Float32(0.5) / Float32(s * exp(Float32(abs(x) / s))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \frac{x}{s}\\
\mathbf{if}\;\left|x\right| \leq 1.3500000359991076 \cdot 10^{-17}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(2, t_0, s \cdot 4\right) - t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{s \cdot e^{\frac{\left|x\right|}{s}}}\\


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

    1. Initial program 97.9%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified97.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 98.2%

      \[\leadsto \color{blue}{\frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}} \]
    4. Taylor expanded in s around inf 80.3%

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u73.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}\right)\right)} \]
      2. expm1-udef73.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}\right)} - 1} \]
      3. associate-/l*73.9%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \color{blue}{\frac{x}{\frac{s}{x}}}, s \cdot 4\right) - \frac{x \cdot x}{s}}\right)} - 1 \]
      4. associate-/l*75.2%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \color{blue}{\frac{x}{\frac{s}{x}}}}\right)} - 1 \]
    7. Applied egg-rr75.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \frac{x}{\frac{s}{x}}}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-def75.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \frac{x}{\frac{s}{x}}}\right)\right)} \]
      2. expm1-log1p82.1%

        \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \frac{x}{\frac{s}{x}}}} \]
      3. associate-/r/82.1%

        \[\leadsto \frac{1}{\mathsf{fma}\left(2, \color{blue}{\frac{x}{s} \cdot x}, s \cdot 4\right) - \frac{x}{\frac{s}{x}}} \]
      4. associate-/r/82.1%

        \[\leadsto \frac{1}{\mathsf{fma}\left(2, \frac{x}{s} \cdot x, s \cdot 4\right) - \color{blue}{\frac{x}{s} \cdot x}} \]
    9. Simplified82.1%

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

    if 1.35000004e-17 < (fabs.f32 x)

    1. Initial program 99.9%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 99.9%

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

        \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\log \left(s \cdot e^{\frac{\left|x\right|}{s}}\right)}}\right)} \]
      2. *-commutative99.7%

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

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

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

      \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\frac{\left|x\right|}{s} + \log s}}\right)} \]
    6. Taylor expanded in s around inf 97.7%

      \[\leadsto \frac{1}{\left(\color{blue}{1} + 1\right) \cdot \left(s + e^{\frac{\left|x\right|}{s} + \log s}\right)} \]
    7. Taylor expanded in s around 0 93.1%

      \[\leadsto \color{blue}{\frac{0.5}{e^{\log s + \frac{\left|x\right|}{s}}}} \]
    8. Step-by-step derivation
      1. exp-sum93.1%

        \[\leadsto \frac{0.5}{\color{blue}{e^{\log s} \cdot e^{\frac{\left|x\right|}{s}}}} \]
      2. rem-exp-log93.1%

        \[\leadsto \frac{0.5}{\color{blue}{s} \cdot e^{\frac{\left|x\right|}{s}}} \]
    9. Simplified93.1%

      \[\leadsto \color{blue}{\frac{0.5}{s \cdot e^{\frac{\left|x\right|}{s}}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 1.3500000359991076 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(2, x \cdot \frac{x}{s}, s \cdot 4\right) - x \cdot \frac{x}{s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{s \cdot e^{\frac{\left|x\right|}{s}}}\\ \end{array} \]

Alternative 9: 86.3% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \frac{x}{s}\\ \mathbf{if}\;\left|x\right| \leq 5.0000000843119176 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(2, t_0, s \cdot 4\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (* x (/ x s))))
   (if (<= (fabs x) 5.0000000843119176e-17)
     (/ 1.0 (- (fma 2.0 t_0 (* s 4.0)) t_0))
     0.0)))
float code(float x, float s) {
	float t_0 = x * (x / s);
	float tmp;
	if (fabsf(x) <= 5.0000000843119176e-17f) {
		tmp = 1.0f / (fmaf(2.0f, t_0, (s * 4.0f)) - t_0);
	} else {
		tmp = 0.0f;
	}
	return tmp;
}
function code(x, s)
	t_0 = Float32(x * Float32(x / s))
	tmp = Float32(0.0)
	if (abs(x) <= Float32(5.0000000843119176e-17))
		tmp = Float32(Float32(1.0) / Float32(fma(Float32(2.0), t_0, Float32(s * Float32(4.0))) - t_0));
	else
		tmp = Float32(0.0);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \frac{x}{s}\\
\mathbf{if}\;\left|x\right| \leq 5.0000000843119176 \cdot 10^{-17}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(2, t_0, s \cdot 4\right) - t_0}\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 98.1%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified98.0%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 98.3%

      \[\leadsto \color{blue}{\frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}} \]
    4. Taylor expanded in s around inf 78.1%

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u71.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}\right)\right)} \]
      2. expm1-udef71.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}\right)} - 1} \]
      3. associate-/l*72.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \color{blue}{\frac{x}{\frac{s}{x}}}, s \cdot 4\right) - \frac{x \cdot x}{s}}\right)} - 1 \]
      4. associate-/l*73.2%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \color{blue}{\frac{x}{\frac{s}{x}}}}\right)} - 1 \]
    7. Applied egg-rr73.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \frac{x}{\frac{s}{x}}}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-def73.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \frac{x}{\frac{s}{x}}}\right)\right)} \]
      2. expm1-log1p79.8%

        \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(2, \frac{x}{\frac{s}{x}}, s \cdot 4\right) - \frac{x}{\frac{s}{x}}}} \]
      3. associate-/r/79.8%

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

        \[\leadsto \frac{1}{\mathsf{fma}\left(2, \frac{x}{s} \cdot x, s \cdot 4\right) - \color{blue}{\frac{x}{s} \cdot x}} \]
    9. Simplified79.8%

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

    if 5.00000008e-17 < (fabs.f32 x)

    1. Initial program 99.9%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 99.9%

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

        \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\log \left(s \cdot e^{\frac{\left|x\right|}{s}}\right)}}\right)} \]
      2. *-commutative99.7%

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

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

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

      \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\frac{\left|x\right|}{s} + \log s}}\right)} \]
    6. Taylor expanded in s around inf 97.6%

      \[\leadsto \frac{1}{\left(\color{blue}{1} + 1\right) \cdot \left(s + e^{\frac{\left|x\right|}{s} + \log s}\right)} \]
    7. Taylor expanded in s around inf 92.2%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.6%

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

Alternative 10: 86.3% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 5.0000000843119176 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(s, 4, \frac{x}{\frac{s}{x}}\right)}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= (fabs x) 5.0000000843119176e-17)
   (/ 1.0 (fma s 4.0 (/ x (/ s x))))
   0.0))
float code(float x, float s) {
	float tmp;
	if (fabsf(x) <= 5.0000000843119176e-17f) {
		tmp = 1.0f / fmaf(s, 4.0f, (x / (s / x)));
	} else {
		tmp = 0.0f;
	}
	return tmp;
}
function code(x, s)
	tmp = Float32(0.0)
	if (abs(x) <= Float32(5.0000000843119176e-17))
		tmp = Float32(Float32(1.0) / fma(s, Float32(4.0), Float32(x / Float32(s / x))));
	else
		tmp = Float32(0.0);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 5.0000000843119176 \cdot 10^{-17}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(s, 4, \frac{x}{\frac{s}{x}}\right)}\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 98.1%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified98.0%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 98.3%

      \[\leadsto \color{blue}{\frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}} \]
    4. Taylor expanded in s around inf 78.1%

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}} \]
    6. Taylor expanded in x around 0 78.1%

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

        \[\leadsto \frac{1}{\color{blue}{s \cdot 4} + \frac{{x}^{2}}{s}} \]
      2. fma-def78.1%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(s, 4, \frac{{x}^{2}}{s}\right)}} \]
      3. unpow278.1%

        \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, \frac{\color{blue}{x \cdot x}}{s}\right)} \]
      4. associate-/l*79.8%

        \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, \color{blue}{\frac{x}{\frac{s}{x}}}\right)} \]
    8. Simplified79.8%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(s, 4, \frac{x}{\frac{s}{x}}\right)}} \]

    if 5.00000008e-17 < (fabs.f32 x)

    1. Initial program 99.9%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 99.9%

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

        \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\log \left(s \cdot e^{\frac{\left|x\right|}{s}}\right)}}\right)} \]
      2. *-commutative99.7%

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

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

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

      \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\frac{\left|x\right|}{s} + \log s}}\right)} \]
    6. Taylor expanded in s around inf 97.6%

      \[\leadsto \frac{1}{\left(\color{blue}{1} + 1\right) \cdot \left(s + e^{\frac{\left|x\right|}{s} + \log s}\right)} \]
    7. Taylor expanded in s around inf 92.2%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 5.0000000843119176 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(s, 4, \frac{x}{\frac{s}{x}}\right)}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 11: 95.4% accurate, 3.0× speedup?

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

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

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Taylor expanded in s around 0 99.4%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)}} \]
  4. Step-by-step derivation
    1. associate-*r*99.5%

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

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

      \[\leadsto \frac{1}{\left(s \cdot \left(1 + e^{\color{blue}{-\frac{\left|x\right|}{s}}}\right)\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    4. distribute-lft-in99.4%

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

      \[\leadsto \frac{1}{\left(\color{blue}{s} + s \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    6. rem-exp-log98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{e^{\log s}} \cdot e^{-\frac{\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    7. neg-mul-198.0%

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

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

      \[\leadsto \frac{1}{\left(s + e^{\log s + \color{blue}{\left(-\frac{\left|x\right|}{s}\right)}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    10. sub-neg97.9%

      \[\leadsto \frac{1}{\left(s + e^{\color{blue}{\log s - \frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    11. exp-diff98.0%

      \[\leadsto \frac{1}{\left(s + \color{blue}{\frac{e^{\log s}}{e^{\frac{\left|x\right|}{s}}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
    12. rem-exp-log99.4%

      \[\leadsto \frac{1}{\left(s + \frac{\color{blue}{s}}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{\frac{1}{\left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  6. Taylor expanded in s around inf 95.3%

    \[\leadsto \frac{1}{\left(s + \color{blue}{s}\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]
  7. Taylor expanded in s around 0 95.3%

    \[\leadsto \color{blue}{\frac{0.5}{s \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  8. Final simplification95.3%

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

Alternative 12: 95.1% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \frac{e^{\frac{\left|x\right|}{-s}}}{s \cdot 4} \end{array} \]
(FPCore (x s) :precision binary32 (/ (exp (/ (fabs x) (- s))) (* s 4.0)))
float code(float x, float s) {
	return expf((fabsf(x) / -s)) / (s * 4.0f);
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = exp((abs(x) / -s)) / (s * 4.0e0)
end function
function code(x, s)
	return Float32(exp(Float32(abs(x) / Float32(-s))) / Float32(s * Float32(4.0)))
end
function tmp = code(x, s)
	tmp = exp((abs(x) / -s)) / (s * single(4.0));
end
\begin{array}{l}

\\
\frac{e^{\frac{\left|x\right|}{-s}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.4%

    \[\leadsto \color{blue}{\frac{e^{\frac{\left|x\right|}{-s}}}{\left(1 + e^{\frac{\left|x\right|}{-s}}\right) \cdot \left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\right)}} \]
  3. Taylor expanded in s around inf 94.9%

    \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{\color{blue}{4 \cdot s}} \]
  4. Step-by-step derivation
    1. *-commutative94.9%

      \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{\color{blue}{s \cdot 4}} \]
  5. Simplified94.9%

    \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{\color{blue}{s \cdot 4}} \]
  6. Final simplification94.9%

    \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{s \cdot 4} \]

Alternative 13: 86.0% accurate, 5.1× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 98.1%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified98.0%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 98.3%

      \[\leadsto \color{blue}{\frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}} \]
    4. Taylor expanded in s around inf 78.1%

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{x \cdot x}{s}}} \]
    6. Step-by-step derivation
      1. fma-udef78.1%

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

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

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

    if 5.00000008e-17 < (fabs.f32 x)

    1. Initial program 99.9%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 99.9%

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

        \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\log \left(s \cdot e^{\frac{\left|x\right|}{s}}\right)}}\right)} \]
      2. *-commutative99.7%

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

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

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

      \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\frac{\left|x\right|}{s} + \log s}}\right)} \]
    6. Taylor expanded in s around inf 97.6%

      \[\leadsto \frac{1}{\left(\color{blue}{1} + 1\right) \cdot \left(s + e^{\frac{\left|x\right|}{s} + \log s}\right)} \]
    7. Taylor expanded in s around inf 92.2%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.1%

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

Alternative 14: 55.9% accurate, 121.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 99.1%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified99.1%

      \[\leadsto \color{blue}{\frac{e^{\frac{\left|x\right|}{-s}}}{\left(1 + e^{\frac{\left|x\right|}{-s}}\right) \cdot \left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\right)}} \]
    3. Taylor expanded in s around inf 42.6%

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

    if 1.35000004e-17 < x

    1. Initial program 99.8%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 99.9%

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

        \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\log \left(s \cdot e^{\frac{\left|x\right|}{s}}\right)}}\right)} \]
      2. *-commutative99.7%

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

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

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

      \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\frac{\left|x\right|}{s} + \log s}}\right)} \]
    6. Taylor expanded in s around inf 97.7%

      \[\leadsto \frac{1}{\left(\color{blue}{1} + 1\right) \cdot \left(s + e^{\frac{\left|x\right|}{s} + \log s}\right)} \]
    7. Taylor expanded in s around inf 91.4%

      \[\leadsto \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.3500000359991076 \cdot 10^{-17}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 15: 74.7% accurate, 620.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x s) :precision binary32 0.0)
float code(float x, float s) {
	return 0.0f;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 0.0e0
end function
function code(x, s)
	return Float32(0.0)
end
function tmp = code(x, s)
	tmp = single(0.0);
end
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.3%

    \[\leadsto \color{blue}{\frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Taylor expanded in x around 0 99.4%

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

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

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

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

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

    \[\leadsto \frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + \color{blue}{e^{\frac{\left|x\right|}{s} + \log s}}\right)} \]
  6. Taylor expanded in s around inf 94.4%

    \[\leadsto \frac{1}{\left(\color{blue}{1} + 1\right) \cdot \left(s + e^{\frac{\left|x\right|}{s} + \log s}\right)} \]
  7. Taylor expanded in s around inf 71.1%

    \[\leadsto \color{blue}{0} \]
  8. Final simplification71.1%

    \[\leadsto 0 \]

Reproduce

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