Logistic distribution

Percentage Accurate: 99.5% → 99.6%
Time: 10.2s
Alternatives: 10
Speedup: 1.2×

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.5% 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.2× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{\left|x\right|}{-s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{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. Step-by-step derivation
    1. *-lft-identity99.4%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.4%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-/l*99.4%

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 1.5× speedup?

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

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

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

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

Alternative 3: 97.3% accurate, 2.0× speedup?

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

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

    \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{-s}} + \left(e^{\frac{\left|x\right|}{s}} + 2\right)}} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt-0.0%

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{s}}{e^{\color{blue}{\frac{-\left|x\right|}{s}}} + \left(e^{\frac{\left|x\right|}{s}} + 2\right)} \]
    9. distribute-frac-neg98.7%

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

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{1}{e^{\frac{\left|x\right|}{s}}}} + \left(e^{\frac{\left|x\right|}{s}} + 2\right)} \]
    11. div-inv98.7%

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

      \[\leadsto \frac{\frac{1}{s}}{\frac{1}{\color{blue}{{\left(e^{\left|x\right|}\right)}^{\left(\frac{1}{s}\right)}}} + \left(e^{\frac{\left|x\right|}{s}} + 2\right)} \]
    13. add-sqr-sqrt96.2%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 60.8% accurate, 5.7× speedup?

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

\\
\frac{1}{s \cdot \left(3 + e^{\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. Simplified98.7%

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

    \[\leadsto \frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \color{blue}{3}} \]
  4. Step-by-step derivation
    1. expm1-log1p-u93.9%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + 3}\right)\right)} \]
    2. expm1-udef93.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + 3}\right)} - 1} \]
    3. div-inv93.8%

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

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{\color{blue}{{\left(e^{\left|x\right|}\right)}^{\left(\frac{1}{s}\right)}} + 3}\right)} - 1 \]
    5. add-sqr-sqrt38.9%

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{{\left(e^{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}\right)}^{\left(\frac{1}{s}\right)} + 3}\right)} - 1 \]
    6. fabs-sqr38.9%

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

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{{\left(e^{\color{blue}{x}}\right)}^{\left(\frac{1}{s}\right)} + 3}\right)} - 1 \]
    8. exp-prod61.5%

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{\color{blue}{e^{x \cdot \frac{1}{s}}} + 3}\right)} - 1 \]
    9. div-inv61.5%

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\color{blue}{\frac{x}{s}}} + 3}\right)} - 1 \]
  5. Applied egg-rr61.5%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{x}{s}} + 3}\right)} - 1} \]
  6. Step-by-step derivation
    1. expm1-def61.5%

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{x}{s}} + 3}} \]
    3. associate-/l/63.5%

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

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

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

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

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

Alternative 5: 72.6% accurate, 29.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{s \cdot 4 + \frac{x}{\frac{s}{x}}}\\

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


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

    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. Step-by-step derivation
      1. *-lft-identity99.2%

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.2%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, -\color{blue}{\left(-\frac{{\left(\left|x\right|\right)}^{2}}{s}\right)}\right) + \left(2 \cdot \left|x\right| + -2 \cdot \left|x\right|\right)} \]
      10. remove-double-neg72.2%

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

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

        \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, \frac{\color{blue}{x \cdot x}}{s}\right) + \left(2 \cdot \left|x\right| + -2 \cdot \left|x\right|\right)} \]
      13. distribute-rgt-out72.2%

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

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

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

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

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

    if 2e-23 < x

    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. Simplified98.8%

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

      \[\leadsto \frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \color{blue}{3}} \]
    4. Step-by-step derivation
      1. expm1-log1p-u95.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + 3}\right)\right)} \]
      2. expm1-udef95.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + 3}\right)} - 1} \]
      3. div-inv95.9%

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{{\left(e^{\color{blue}{x}}\right)}^{\left(\frac{1}{s}\right)} + 3}\right)} - 1 \]
      8. exp-prod95.9%

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{x}{s}} + 3}\right)} - 1} \]
    6. Step-by-step derivation
      1. expm1-def95.9%

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

        \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{x}{s}} + 3}} \]
      3. associate-/l/97.5%

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

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

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

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

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

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

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

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

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

Alternative 6: 65.6% accurate, 56.4× speedup?

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

\\
\frac{1}{s \cdot 4 + \frac{x}{\frac{s}{x}}}
\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. Step-by-step derivation
    1. *-lft-identity99.4%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.4%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-/l*99.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, \color{blue}{-\frac{{\left(\left|x\right|\right)}^{2} + -2 \cdot {\left(\left|x\right|\right)}^{2}}{s}}\right) + \left(2 \cdot \left|x\right| + -2 \cdot \left|x\right|\right)} \]
    6. distribute-rgt1-in67.0%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, \frac{\color{blue}{x \cdot x}}{s}\right) + \left(2 \cdot \left|x\right| + -2 \cdot \left|x\right|\right)} \]
    13. distribute-rgt-out67.4%

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

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

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

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

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

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

Alternative 7: 45.4% accurate, 67.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 7.9999998e-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. Taylor expanded in s around inf 39.0%

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

    if 7.9999998e-5 < 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. Step-by-step derivation
      1. *-lft-identity100.0%

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, \frac{\color{blue}{x \cdot x}}{s}\right) + \left(2 \cdot \left|x\right| + -2 \cdot \left|x\right|\right)} \]
      13. distribute-rgt-out76.1%

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

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

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

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    9. Simplified72.6%

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

        \[\leadsto \color{blue}{\frac{\frac{s}{x}}{x}} \]
      2. div-inv72.6%

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

      \[\leadsto \color{blue}{\frac{s}{x} \cdot \frac{1}{x}} \]
    12. Step-by-step derivation
      1. clear-num72.6%

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

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

        \[\leadsto \frac{\color{blue}{1}}{\frac{x}{s} \cdot x} \]
    13. Applied egg-rr76.1%

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

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

Alternative 8: 45.4% accurate, 67.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 7.9999998e-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. Taylor expanded in s around inf 39.0%

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

    if 7.9999998e-5 < 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. Step-by-step derivation
      1. *-lft-identity100.0%

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{x \cdot x}}{s}} \]
    8. Simplified76.1%

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

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

Alternative 9: 44.8% accurate, 87.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 7.999999797903001 \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 7.999999797903001e-5) (/ 0.25 s) (/ s (* x x))))
float code(float x, float s) {
	float tmp;
	if (x <= 7.999999797903001e-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 <= 7.999999797903001e-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(7.999999797903001e-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(7.999999797903001e-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 7.999999797903001 \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 < 7.9999998e-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. Taylor expanded in s around inf 39.0%

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

    if 7.9999998e-5 < 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. Step-by-step derivation
      1. *-lft-identity100.0%

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{fma}\left(s, 4, \frac{\color{blue}{x \cdot x}}{s}\right) + \left(2 \cdot \left|x\right| + -2 \cdot \left|x\right|\right)} \]
      13. distribute-rgt-out76.1%

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

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

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

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    9. Simplified72.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7.999999797903001 \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. Taylor expanded in s around inf 30.8%

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  3. Final simplification30.8%

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

Reproduce

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