Logistic distribution

Percentage Accurate: 99.6% → 99.5%
Time: 15.7s
Alternatives: 10
Speedup: N/A×

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.5% accurate, 1.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{1}{\mathsf{fma}\left(s, e^{-\frac{x_m}{s}}, s\right) \cdot \left(1 + {e}^{\left(\frac{x_m}{s}\right)}\right)} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (/ 1.0 (* (fma s (exp (- (/ x_m s))) s) (+ 1.0 (pow E (/ x_m s))))))
x_m = fabs(x);
float code(float x_m, float s) {
	return 1.0f / (fmaf(s, expf(-(x_m / s)), s) * (1.0f + powf(((float) M_E), (x_m / s))));
}
x_m = abs(x)
function code(x_m, s)
	return Float32(Float32(1.0) / Float32(fma(s, exp(Float32(-Float32(x_m / s))), s) * Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(x_m / s)))))
end
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{1}{\mathsf{fma}\left(s, e^{-\frac{x_m}{s}}, s\right) \cdot \left(1 + {e}^{\left(\frac{x_m}{s}\right)}\right)}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(s, \color{blue}{e^{-\frac{x}{s}}}, s\right) \cdot \left(1 + {e}^{\left(\frac{x}{s}\right)}\right)} \]
  15. Final simplification99.7%

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

Alternative 2: 99.6% accurate, 2.0× speedup?

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

\\
\frac{1}{\mathsf{fma}\left(s, e^{-\frac{x_m}{s}}, s\right) \cdot \left(1 + e^{\frac{x_m}{s}}\right)}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(s, \color{blue}{e^{-\frac{x}{s}}}, s\right) \cdot \left(1 + e^{\frac{x}{s}}\right)} \]
  11. Final simplification99.7%

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

Alternative 3: 99.6% accurate, 2.9× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(s, \color{blue}{e^{-\frac{x}{s}}}, s\right) \cdot \left(1 + e^{\frac{x}{s}}\right)} \]
  11. Taylor expanded in x around inf 99.7%

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

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

Alternative 4: 94.9% accurate, 2.9× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{x_m}{s}}\right) \cdot \mathsf{fma}\left(s, 1, s\right)}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(s, \color{blue}{1}, s\right) \cdot \left(1 + e^{\frac{x}{s}}\right)} \]
  8. Final simplification59.5%

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

Alternative 5: 94.3% accurate, 3.0× speedup?

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

\\
\frac{1}{s \cdot {\left(1 + e^{\frac{x_m}{s}}\right)}^{2}}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) \cdot e^{\frac{x}{s}}}} \]
  9. Step-by-step derivation
    1. *-commutative59.3%

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \color{blue}{e^{\frac{x}{s}} \cdot \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    2. distribute-rgt1-in59.3%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 73.3% accurate, 5.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{1}{s \cdot {\left(\frac{x_m}{s} + 2\right)}^{2}} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s) :precision binary32 (/ 1.0 (* s (pow (+ (/ x_m s) 2.0) 2.0))))
x_m = fabs(x);
float code(float x_m, float s) {
	return 1.0f / (s * powf(((x_m / s) + 2.0f), 2.0f));
}
x_m = abs(x)
real(4) function code(x_m, s)
    real(4), intent (in) :: x_m
    real(4), intent (in) :: s
    code = 1.0e0 / (s * (((x_m / s) + 2.0e0) ** 2.0e0))
end function
x_m = abs(x)
function code(x_m, s)
	return Float32(Float32(1.0) / Float32(s * (Float32(Float32(x_m / s) + Float32(2.0)) ^ Float32(2.0))))
end
x_m = abs(x);
function tmp = code(x_m, s)
	tmp = single(1.0) / (s * (((x_m / s) + single(2.0)) ^ single(2.0)));
end
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{1}{s \cdot {\left(\frac{x_m}{s} + 2\right)}^{2}}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) \cdot e^{\frac{x}{s}}}} \]
  9. Step-by-step derivation
    1. *-commutative59.3%

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \color{blue}{e^{\frac{x}{s}} \cdot \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    2. distribute-rgt1-in59.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{s \cdot {\color{blue}{\left(\frac{x}{s} + 2\right)}}^{2}} \]
  13. Simplified71.3%

    \[\leadsto \frac{1}{s \cdot {\color{blue}{\left(\frac{x}{s} + 2\right)}}^{2}} \]
  14. Final simplification71.3%

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

Alternative 7: 62.6% accurate, 5.8× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 9.999999747378752 \cdot 10^{-6}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{s}{{x_m}^{2}}\\ \end{array} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (if (<= x_m 9.999999747378752e-6) (/ 0.25 s) (/ s (pow x_m 2.0))))
x_m = fabs(x);
float code(float x_m, float s) {
	float tmp;
	if (x_m <= 9.999999747378752e-6f) {
		tmp = 0.25f / s;
	} else {
		tmp = s / powf(x_m, 2.0f);
	}
	return tmp;
}
x_m = abs(x)
real(4) function code(x_m, s)
    real(4), intent (in) :: x_m
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x_m <= 9.999999747378752e-6) then
        tmp = 0.25e0 / s
    else
        tmp = s / (x_m ** 2.0e0)
    end if
    code = tmp
end function
x_m = abs(x)
function code(x_m, s)
	tmp = Float32(0.0)
	if (x_m <= Float32(9.999999747378752e-6))
		tmp = Float32(Float32(0.25) / s);
	else
		tmp = Float32(s / (x_m ^ Float32(2.0)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, s)
	tmp = single(0.0);
	if (x_m <= single(9.999999747378752e-6))
		tmp = single(0.25) / s;
	else
		tmp = s / (x_m ^ single(2.0));
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x_m = \left|x\right|

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

\mathbf{else}:\\
\;\;\;\;\frac{s}{{x_m}^{2}}\\


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

    1. Initial program 99.5%

      \[\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. Step-by-step derivation
      1. *-commutative99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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)}} \]
    4. Taylor expanded in s around inf 95.6%

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

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

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

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

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

    if 9.99999975e-6 < 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{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
    3. Taylor expanded in s around -inf 24.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)}} \]
    4. Step-by-step derivation
      1. +-commutative24.6%

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 51.7% accurate, 56.4× speedup?

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

\\
\frac{1}{s \cdot \left(4 + \frac{x_m \cdot 4}{s}\right)}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) \cdot e^{\frac{x}{s}}}} \]
  9. Step-by-step derivation
    1. *-commutative59.3%

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \color{blue}{e^{\frac{x}{s}} \cdot \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    2. distribute-rgt1-in59.3%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{s \cdot \left(4 + \frac{\color{blue}{x \cdot 4}}{s}\right)} \]
  13. Simplified49.8%

    \[\leadsto \frac{1}{s \cdot \color{blue}{\left(4 + \frac{x \cdot 4}{s}\right)}} \]
  14. Final simplification49.8%

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

Alternative 9: 30.0% accurate, 88.6× speedup?

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

\\
\frac{1}{4 \cdot \left(s + x_m\right)}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) \cdot e^{\frac{x}{s}}}} \]
  9. Step-by-step derivation
    1. *-commutative59.3%

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right) + \color{blue}{e^{\frac{x}{s}} \cdot \mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
    2. distribute-rgt1-in59.3%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{4 \cdot s + 4 \cdot x}} \]
  12. Step-by-step derivation
    1. distribute-lft-out29.8%

      \[\leadsto \frac{1}{\color{blue}{4 \cdot \left(s + x\right)}} \]
  13. Simplified29.8%

    \[\leadsto \frac{1}{\color{blue}{4 \cdot \left(s + x\right)}} \]
  14. Final simplification29.8%

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

Alternative 10: 27.6% accurate, 206.7× speedup?

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

\\
\frac{0.25}{s}
\end{array}
Derivation
  1. Initial program 99.6%

    \[\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. Step-by-step derivation
    1. *-commutative99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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)}} \]
  4. Taylor expanded in s around inf 96.4%

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

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

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

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

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  8. Final simplification27.7%

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

Reproduce

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