Logistic distribution

Percentage Accurate: 99.6% → 99.6%
Time: 9.9s
Alternatives: 10
Speedup: 1.0×

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 10 alternatives:

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

Initial Program: 99.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{t_0}{\left(t_0 + 1\right) \cdot \left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\right)} \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (fabs x) (- s)))))
   (/ t_0 (* (+ t_0 1.0) (+ s (/ s (exp (/ (fabs x) s))))))))
float code(float x, float s) {
	float t_0 = expf((fabsf(x) / -s));
	return t_0 / ((t_0 + 1.0f) * (s + (s / expf((fabsf(x) / s)))));
}
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 / ((t_0 + 1.0e0) * (s + (s / exp((abs(x) / s)))))
end function
function code(x, s)
	t_0 = exp(Float32(abs(x) / Float32(-s)))
	return Float32(t_0 / Float32(Float32(t_0 + Float32(1.0)) * Float32(s + Float32(s / exp(Float32(abs(x) / s))))))
end
function tmp = code(x, s)
	t_0 = exp((abs(x) / -s));
	tmp = t_0 / ((t_0 + single(1.0)) * (s + (s / exp((abs(x) / s)))));
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\frac{\left|x\right|}{-s}}\\
\frac{t_0}{\left(t_0 + 1\right) \cdot \left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\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.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. Final simplification99.4%

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

Alternative 2: 62.9% accurate, 1.9× speedup?

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

\\
\frac{\frac{1}{e^{\frac{\left|x\right|}{-s}} + 1}}{\left(s \cdot e^{\frac{x}{s}} - s\right) + \left(s + 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.2%

    \[\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. Step-by-step derivation
    1. add-sqr-sqrt98.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}}} \]
    2. pow298.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}\right)}^{2}}} \]
    3. add-sqr-sqrt53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}, s\right)}\right)}^{2}} \]
    4. fabs-sqr53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}, s\right)}\right)}^{2}} \]
    5. add-sqr-sqrt64.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{x}}{s}}, s\right)}\right)}^{2}} \]
  4. Applied egg-rr64.1%

    \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}\right)}^{2}}} \]
  5. Step-by-step derivation
    1. unpow264.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}}} \]
    2. add-sqr-sqrt64.5%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    3. add-sqr-sqrt64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s} \cdot \sqrt{s}}\right)} \]
    4. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s \cdot s}}\right)} \]
    5. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \sqrt{\color{blue}{\left(-s\right) \cdot \left(-s\right)}}\right)} \]
    6. sqrt-unprod-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{-s} \cdot \sqrt{-s}}\right)} \]
    7. add-sqr-sqrt42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{-s}\right)} \]
    8. fma-neg42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{s \cdot e^{\frac{x}{s}} - s}} \]
    9. *-un-lft-identity42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{s \cdot e^{\frac{x}{s}} - \color{blue}{1 \cdot s}} \]
    10. prod-diff42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(-s, 1, s \cdot 1\right)}} \]
    11. add-sqr-sqrt-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}, 1, s \cdot 1\right)} \]
    12. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}, 1, s \cdot 1\right)} \]
    13. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\sqrt{\color{blue}{s \cdot s}}, 1, s \cdot 1\right)} \]
    14. sqrt-unprod64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{s} \cdot \sqrt{s}}, 1, s \cdot 1\right)} \]
    15. add-sqr-sqrt64.5%

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

    \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(s, 1, s \cdot 1\right)}} \]
  7. Step-by-step derivation
    1. *-rgt-identity64.5%

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

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\left(s \cdot e^{\frac{x}{s}} - s\right)} + \mathsf{fma}\left(s, 1, s \cdot 1\right)} \]
    3. fma-udef64.5%

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

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

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

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

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

Alternative 3: 63.0% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \frac{\frac{1}{e^{\frac{\left|x\right|}{-s}} + 1}}{\left(s + s\right) + s \cdot \mathsf{expm1}\left(\frac{x}{s}\right)} \end{array} \]
(FPCore (x s)
 :precision binary32
 (/
  (/ 1.0 (+ (exp (/ (fabs x) (- s))) 1.0))
  (+ (+ s s) (* s (expm1 (/ x s))))))
float code(float x, float s) {
	return (1.0f / (expf((fabsf(x) / -s)) + 1.0f)) / ((s + s) + (s * expm1f((x / s))));
}
function code(x, s)
	return Float32(Float32(Float32(1.0) / Float32(exp(Float32(abs(x) / Float32(-s))) + Float32(1.0))) / Float32(Float32(s + s) + Float32(s * expm1(Float32(x / s)))))
end
\begin{array}{l}

\\
\frac{\frac{1}{e^{\frac{\left|x\right|}{-s}} + 1}}{\left(s + s\right) + s \cdot \mathsf{expm1}\left(\frac{x}{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.2%

    \[\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. Step-by-step derivation
    1. add-sqr-sqrt98.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}}} \]
    2. pow298.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}\right)}^{2}}} \]
    3. add-sqr-sqrt53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}, s\right)}\right)}^{2}} \]
    4. fabs-sqr53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}, s\right)}\right)}^{2}} \]
    5. add-sqr-sqrt64.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{x}}{s}}, s\right)}\right)}^{2}} \]
  4. Applied egg-rr64.1%

    \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}\right)}^{2}}} \]
  5. Step-by-step derivation
    1. unpow264.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}}} \]
    2. add-sqr-sqrt64.5%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    3. add-sqr-sqrt64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s} \cdot \sqrt{s}}\right)} \]
    4. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s \cdot s}}\right)} \]
    5. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \sqrt{\color{blue}{\left(-s\right) \cdot \left(-s\right)}}\right)} \]
    6. sqrt-unprod-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{-s} \cdot \sqrt{-s}}\right)} \]
    7. add-sqr-sqrt42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{-s}\right)} \]
    8. fma-neg42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{s \cdot e^{\frac{x}{s}} - s}} \]
    9. *-un-lft-identity42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{s \cdot e^{\frac{x}{s}} - \color{blue}{1 \cdot s}} \]
    10. prod-diff42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(-s, 1, s \cdot 1\right)}} \]
    11. add-sqr-sqrt-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}, 1, s \cdot 1\right)} \]
    12. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}, 1, s \cdot 1\right)} \]
    13. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\sqrt{\color{blue}{s \cdot s}}, 1, s \cdot 1\right)} \]
    14. sqrt-unprod64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{s} \cdot \sqrt{s}}, 1, s \cdot 1\right)} \]
    15. add-sqr-sqrt64.5%

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

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

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

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\left(s \cdot 1 + s \cdot 1\right)} + \mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right)} \]
    3. *-rgt-identity64.5%

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

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

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\left(s + s\right) + \mathsf{fma}\left(s, e^{\frac{x}{s}}, -\color{blue}{s}\right)} \]
    6. fma-neg64.5%

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

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

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

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

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

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

Alternative 4: 63.0% accurate, 2.0× speedup?

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

\\
\frac{1}{s \cdot \left(\left(1 + e^{\frac{x}{s}}\right) \cdot \left(1 + e^{\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.2%

    \[\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. Step-by-step derivation
    1. add-sqr-sqrt98.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}}} \]
    2. pow298.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}\right)}^{2}}} \]
    3. add-sqr-sqrt53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}, s\right)}\right)}^{2}} \]
    4. fabs-sqr53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}, s\right)}\right)}^{2}} \]
    5. add-sqr-sqrt64.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{x}}{s}}, s\right)}\right)}^{2}} \]
  4. Applied egg-rr64.1%

    \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}\right)}^{2}}} \]
  5. Step-by-step derivation
    1. unpow264.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}}} \]
    2. add-sqr-sqrt64.5%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    3. add-sqr-sqrt64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s} \cdot \sqrt{s}}\right)} \]
    4. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s \cdot s}}\right)} \]
    5. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \sqrt{\color{blue}{\left(-s\right) \cdot \left(-s\right)}}\right)} \]
    6. sqrt-unprod-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{-s} \cdot \sqrt{-s}}\right)} \]
    7. add-sqr-sqrt42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{-s}\right)} \]
    8. fma-neg42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{s \cdot e^{\frac{x}{s}} - s}} \]
    9. *-un-lft-identity42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{s \cdot e^{\frac{x}{s}} - \color{blue}{1 \cdot s}} \]
    10. prod-diff42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(-s, 1, s \cdot 1\right)}} \]
    11. add-sqr-sqrt-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}, 1, s \cdot 1\right)} \]
    12. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}, 1, s \cdot 1\right)} \]
    13. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\sqrt{\color{blue}{s \cdot s}}, 1, s \cdot 1\right)} \]
    14. sqrt-unprod64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{s} \cdot \sqrt{s}}, 1, s \cdot 1\right)} \]
    15. add-sqr-sqrt64.5%

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

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

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

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\left(s \cdot 1 + s \cdot 1\right)} + \mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right)} \]
    3. *-rgt-identity64.5%

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

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

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\left(s + s\right) + \mathsf{fma}\left(s, e^{\frac{x}{s}}, -\color{blue}{s}\right)} \]
    6. fma-neg64.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 70.0% accurate, 4.6× speedup?

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

\\
\begin{array}{l}
t_0 := 1 + \frac{x}{\frac{s}{x}}\\
\mathbf{if}\;\left|x\right| \leq 15000000512:\\
\;\;\;\;\frac{1}{\frac{t_0 \cdot t_0 + -1}{1 + t_0} + s \cdot 4}\\

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


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

    1. Initial program 99.0%

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)} \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
      2. associate-*r/98.6%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left(\left(\left(-\frac{\color{blue}{-1} \cdot {\left(\left|x\right|\right)}^{2}}{s}\right) + 2 \cdot \left|x\right|\right) + 4 \cdot s\right) + -2 \cdot \left|x\right|} \]
      6. associate-*r/45.7%

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

        \[\leadsto \frac{1}{\left(\left(\left(-\color{blue}{\left(-\frac{{\left(\left|x\right|\right)}^{2}}{s}\right)}\right) + 2 \cdot \left|x\right|\right) + 4 \cdot s\right) + -2 \cdot \left|x\right|} \]
      8. remove-double-neg45.7%

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x}{s} + \left(s \cdot 4 + 0\right)}} \]
    9. Step-by-step derivation
      1. expm1-log1p-u45.7%

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} - 1\right)} + \left(s \cdot 4 + 0\right)} \]
    11. Step-by-step derivation
      1. flip--53.7%

        \[\leadsto \frac{1}{\color{blue}{\frac{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} \cdot e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} - 1 \cdot 1}{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} + 1}} + \left(s \cdot 4 + 0\right)} \]
      2. log1p-udef53.7%

        \[\leadsto \frac{1}{\frac{e^{\color{blue}{\log \left(1 + \frac{x \cdot x}{s}\right)}} \cdot e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} - 1 \cdot 1}{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} + 1} + \left(s \cdot 4 + 0\right)} \]
      3. add-exp-log53.7%

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

        \[\leadsto \frac{1}{\frac{\left(1 + \color{blue}{\frac{x}{\frac{s}{x}}}\right) \cdot e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} - 1 \cdot 1}{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} + 1} + \left(s \cdot 4 + 0\right)} \]
      5. log1p-udef53.7%

        \[\leadsto \frac{1}{\frac{\left(1 + \frac{x}{\frac{s}{x}}\right) \cdot e^{\color{blue}{\log \left(1 + \frac{x \cdot x}{s}\right)}} - 1 \cdot 1}{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} + 1} + \left(s \cdot 4 + 0\right)} \]
      6. add-exp-log53.7%

        \[\leadsto \frac{1}{\frac{\left(1 + \frac{x}{\frac{s}{x}}\right) \cdot \color{blue}{\left(1 + \frac{x \cdot x}{s}\right)} - 1 \cdot 1}{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} + 1} + \left(s \cdot 4 + 0\right)} \]
      7. associate-/l*53.7%

        \[\leadsto \frac{1}{\frac{\left(1 + \frac{x}{\frac{s}{x}}\right) \cdot \left(1 + \color{blue}{\frac{x}{\frac{s}{x}}}\right) - 1 \cdot 1}{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} + 1} + \left(s \cdot 4 + 0\right)} \]
      8. metadata-eval53.7%

        \[\leadsto \frac{1}{\frac{\left(1 + \frac{x}{\frac{s}{x}}\right) \cdot \left(1 + \frac{x}{\frac{s}{x}}\right) - \color{blue}{1}}{e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} + 1} + \left(s \cdot 4 + 0\right)} \]
      9. log1p-udef53.7%

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

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

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

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

    if 15000000500 < (fabs.f32 x)

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)} \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
      2. associate-*r/100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left(\left(\left(-\frac{\color{blue}{-1} \cdot {\left(\left|x\right|\right)}^{2}}{s}\right) + 2 \cdot \left|x\right|\right) + 4 \cdot s\right) + -2 \cdot \left|x\right|} \]
      6. associate-*r/92.0%

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

        \[\leadsto \frac{1}{\left(\left(\left(-\color{blue}{\left(-\frac{{\left(\left|x\right|\right)}^{2}}{s}\right)}\right) + 2 \cdot \left|x\right|\right) + 4 \cdot s\right) + -2 \cdot \left|x\right|} \]
      8. remove-double-neg92.0%

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x}{s} + \left(s \cdot 4 + 0\right)}} \]
    9. Step-by-step derivation
      1. expm1-log1p-u92.0%

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

        \[\leadsto \frac{1}{\color{blue}{\left(e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} - 1\right)} + \left(s \cdot 4 + 0\right)} \]
    10. Applied egg-rr92.0%

      \[\leadsto \frac{1}{\color{blue}{\left(e^{\mathsf{log1p}\left(\frac{x \cdot x}{s}\right)} - 1\right)} + \left(s \cdot 4 + 0\right)} \]
    11. Step-by-step derivation
      1. expm1-def92.0%

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

        \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x}{s}} + \left(s \cdot 4 + 0\right)} \]
      3. clear-num92.0%

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

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

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

Alternative 6: 60.8% accurate, 5.7× speedup?

\[\begin{array}{l} \\ \frac{0.5}{s \cdot \left(\mathsf{expm1}\left(\frac{x}{s}\right) + 2\right)} \end{array} \]
(FPCore (x s) :precision binary32 (/ 0.5 (* s (+ (expm1 (/ x s)) 2.0))))
float code(float x, float s) {
	return 0.5f / (s * (expm1f((x / s)) + 2.0f));
}
function code(x, s)
	return Float32(Float32(0.5) / Float32(s * Float32(expm1(Float32(x / s)) + Float32(2.0))))
end
\begin{array}{l}

\\
\frac{0.5}{s \cdot \left(\mathsf{expm1}\left(\frac{x}{s}\right) + 2\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.2%

    \[\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. Step-by-step derivation
    1. add-sqr-sqrt98.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}}} \]
    2. pow298.8%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}\right)}^{2}}} \]
    3. add-sqr-sqrt53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}, s\right)}\right)}^{2}} \]
    4. fabs-sqr53.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}, s\right)}\right)}^{2}} \]
    5. add-sqr-sqrt64.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{\color{blue}{x}}{s}}, s\right)}\right)}^{2}} \]
  4. Applied egg-rr64.1%

    \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{{\left(\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}\right)}^{2}}} \]
  5. Step-by-step derivation
    1. unpow264.1%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)} \cdot \sqrt{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}}} \]
    2. add-sqr-sqrt64.5%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    3. add-sqr-sqrt64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s} \cdot \sqrt{s}}\right)} \]
    4. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{s \cdot s}}\right)} \]
    5. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \sqrt{\color{blue}{\left(-s\right) \cdot \left(-s\right)}}\right)} \]
    6. sqrt-unprod-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{\sqrt{-s} \cdot \sqrt{-s}}\right)} \]
    7. add-sqr-sqrt42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, \color{blue}{-s}\right)} \]
    8. fma-neg42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{s \cdot e^{\frac{x}{s}} - s}} \]
    9. *-un-lft-identity42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{s \cdot e^{\frac{x}{s}} - \color{blue}{1 \cdot s}} \]
    10. prod-diff42.7%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(-s, 1, s \cdot 1\right)}} \]
    11. add-sqr-sqrt-0.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{-s} \cdot \sqrt{-s}}, 1, s \cdot 1\right)} \]
    12. sqrt-unprod61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{\left(-s\right) \cdot \left(-s\right)}}, 1, s \cdot 1\right)} \]
    13. sqr-neg61.0%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\sqrt{\color{blue}{s \cdot s}}, 1, s \cdot 1\right)} \]
    14. sqrt-unprod64.4%

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right) + \mathsf{fma}\left(\color{blue}{\sqrt{s} \cdot \sqrt{s}}, 1, s \cdot 1\right)} \]
    15. add-sqr-sqrt64.5%

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

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

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

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\color{blue}{\left(s \cdot 1 + s \cdot 1\right)} + \mathsf{fma}\left(s, e^{\frac{x}{s}}, -s \cdot 1\right)} \]
    3. *-rgt-identity64.5%

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

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

      \[\leadsto \frac{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\left(s + s\right) + \mathsf{fma}\left(s, e^{\frac{x}{s}}, -\color{blue}{s}\right)} \]
    6. fma-neg64.5%

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

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

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

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

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

    \[\leadsto \frac{\frac{1}{1 + \color{blue}{1}}}{\left(s + s\right) + s \cdot \mathsf{expm1}\left(\frac{x}{s}\right)} \]
  10. Taylor expanded in x around inf 61.4%

    \[\leadsto \color{blue}{\frac{0.5}{2 \cdot s + s \cdot \left(e^{\frac{x}{s}} - 1\right)}} \]
  11. Step-by-step derivation
    1. count-261.4%

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

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

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

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

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

      \[\leadsto \frac{0.5}{s \cdot \left(\color{blue}{\mathsf{expm1}\left(\frac{x}{s}\right)} + 2\right)} \]
  12. Simplified61.4%

    \[\leadsto \color{blue}{\frac{0.5}{s \cdot \left(\mathsf{expm1}\left(\frac{x}{s}\right) + 2\right)}} \]
  13. Final simplification61.4%

    \[\leadsto \frac{0.5}{s \cdot \left(\mathsf{expm1}\left(\frac{x}{s}\right) + 2\right)} \]

Alternative 7: 65.2% accurate, 47.7× speedup?

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

\\
\frac{1}{s \cdot 4 + \left(x \cdot x\right) \cdot \frac{1}{s}}
\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.2%

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)} \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    2. associate-*r/99.2%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(\left(\left(-\frac{\color{blue}{-1} \cdot {\left(\left|x\right|\right)}^{2}}{s}\right) + 2 \cdot \left|x\right|\right) + 4 \cdot s\right) + -2 \cdot \left|x\right|} \]
    6. associate-*r/63.1%

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x}{s} + \left(s \cdot 4 + 0\right)}} \]
  9. Step-by-step derivation
    1. div-inv63.4%

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

    \[\leadsto \frac{1}{\color{blue}{\left(x \cdot x\right) \cdot \frac{1}{s}} + \left(s \cdot 4 + 0\right)} \]
  11. Final simplification63.4%

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

Alternative 8: 65.6% accurate, 56.4× speedup?

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

\\
\frac{1}{\frac{x}{\frac{s}{x}} + 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.2%

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)} \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    2. associate-*r/99.2%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(\left(\left(-\frac{\color{blue}{-1} \cdot {\left(\left|x\right|\right)}^{2}}{s}\right) + 2 \cdot \left|x\right|\right) + 4 \cdot s\right) + -2 \cdot \left|x\right|} \]
    6. associate-*r/63.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}}} + \left(s \cdot 4 + 0\right)} \]
  11. Simplified63.4%

    \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}}} + \left(s \cdot 4 + 0\right)} \]
  12. Final simplification63.4%

    \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + s \cdot 4} \]

Alternative 9: 45.5% accurate, 87.0× speedup?

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

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

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


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

    1. Initial program 99.2%

      \[\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{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 35.8%

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

    if 9.99999975e-5 < 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.8%

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)} \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
      2. associate-*r/99.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left(\left(\left(-\frac{\color{blue}{-1} \cdot {\left(\left|x\right|\right)}^{2}}{s}\right) + 2 \cdot \left|x\right|\right) + 4 \cdot s\right) + -2 \cdot \left|x\right|} \]
      6. associate-*r/69.5%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x}{s} + \left(s \cdot 4 + 0\right)}} \]
    9. Taylor expanded in x around inf 68.2%

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

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    11. Simplified68.2%

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

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

Alternative 10: 27.4% accurate, 206.7× speedup?

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

\\
\frac{0.25}{s}
\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 26.9%

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  4. Final simplification26.9%

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

Reproduce

?
herbie shell --seed 2023271 
(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))))))