Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 12.0s
Alternatives: 8
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 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.5% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{x\_m}{-s}}\\
\frac{\frac{t\_0}{t\_0 + 1}}{s + \frac{s}{e^{\frac{x\_m}{s}}}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.3%

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\right)\right)} \]
    5. 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 e^{\frac{-\left|-x\right|}{s}} + s \cdot 1\right)}} \]
    6. *-rgt-identity99.5%

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 2.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := e^{\frac{x\_m}{-s}}\\ \frac{t\_0}{s \cdot {\left(t\_0 + 1\right)}^{2}} \end{array} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (let* ((t_0 (exp (/ x_m (- s))))) (/ t_0 (* s (pow (+ t_0 1.0) 2.0)))))
x_m = fabs(x);
float code(float x_m, float s) {
	float t_0 = expf((x_m / -s));
	return t_0 / (s * powf((t_0 + 1.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
    real(4) :: t_0
    t_0 = exp((x_m / -s))
    code = t_0 / (s * ((t_0 + 1.0e0) ** 2.0e0))
end function
x_m = abs(x)
function code(x_m, s)
	t_0 = exp(Float32(x_m / Float32(-s)))
	return Float32(t_0 / Float32(s * (Float32(t_0 + Float32(1.0)) ^ Float32(2.0))))
end
x_m = abs(x);
function tmp = code(x_m, s)
	t_0 = exp((x_m / -s));
	tmp = t_0 / (s * ((t_0 + single(1.0)) ^ single(2.0)));
end
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
t_0 := e^{\frac{x\_m}{-s}}\\
\frac{t\_0}{s \cdot {\left(t\_0 + 1\right)}^{2}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.3%

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\right)\right)} \]
    5. 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 e^{\frac{-\left|-x\right|}{s}} + s \cdot 1\right)}} \]
    6. *-rgt-identity99.5%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{x}{-s}}}{s \cdot {\left(1 + e^{\color{blue}{-\frac{x}{s}}}\right)}^{2}} \]
    7. distribute-neg-frac265.0%

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

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

    \[\leadsto \frac{e^{\frac{x}{-s}}}{s \cdot {\left(e^{\frac{x}{-s}} + 1\right)}^{2}} \]
  12. Add Preprocessing

Alternative 3: 96.8% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{x\_m}{-s}}\\
\frac{\frac{t\_0}{t\_0 + 1}}{s + \frac{s}{1 + \frac{x\_m}{s}}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.3%

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\right)\right)} \]
    5. 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 e^{\frac{-\left|-x\right|}{s}} + s \cdot 1\right)}} \]
    6. *-rgt-identity99.5%

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

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

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

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

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

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

    \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{e^{\frac{x}{-s}} + 1}}{s + \frac{s}{\color{blue}{1 + \frac{x}{s}}}} \]
  9. Step-by-step derivation
    1. +-commutative61.7%

      \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{e^{\frac{x}{-s}} + 1}}{s + \frac{s}{\color{blue}{\frac{x}{s} + 1}}} \]
  10. Simplified61.7%

    \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{e^{\frac{x}{-s}} + 1}}{s + \frac{s}{\color{blue}{\frac{x}{s} + 1}}} \]
  11. Final simplification61.7%

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

Alternative 4: 96.2% accurate, 2.9× speedup?

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

\\
\frac{e^{\frac{x\_m}{-s}}}{s \cdot {\left(2 - \frac{x\_m}{s}\right)}^{2}}
\end{array}
Derivation
  1. Initial program 99.3%

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\right)\right)} \]
    5. 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 e^{\frac{-\left|-x\right|}{s}} + s \cdot 1\right)}} \]
    6. *-rgt-identity99.5%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{x}{-s}}}{s \cdot {\left(1 + e^{\color{blue}{-\frac{x}{s}}}\right)}^{2}} \]
    7. distribute-neg-frac265.0%

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

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

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

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

      \[\leadsto \frac{e^{\frac{x}{-s}}}{s \cdot {\color{blue}{\left(2 - \frac{x}{s}\right)}}^{2}} \]
  13. Simplified61.8%

    \[\leadsto \frac{e^{\frac{x}{-s}}}{s \cdot {\color{blue}{\left(2 - \frac{x}{s}\right)}}^{2}} \]
  14. Add Preprocessing

Alternative 5: 96.2% accurate, 5.3× speedup?

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

\\
\begin{array}{l}
t_0 := 2 - \frac{x\_m}{s}\\
\frac{\frac{e^{\frac{x\_m}{-s}}}{s}}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 99.3%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.3%

      \[\leadsto \frac{e^{\color{blue}{-\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. distribute-frac-neg299.3%

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.3%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.3%

      \[\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)}} \]
    6. fabs-neg99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{s}}{{\left(\color{blue}{{\left(e^{-1}\right)}^{\left(\frac{\left|x\right|}{s}\right)}} + 1\right)}^{2}} \]
    11. rem-square-sqrt51.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{s}}{{\left(2 + \color{blue}{\frac{x}{-s}}\right)}^{2}} \]
  10. Simplified61.8%

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

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

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

      \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{s}}{\left(\frac{x}{-s} + 2\right) \cdot \color{blue}{\left(\frac{x}{-s} + 2\right)}} \]
  12. Applied egg-rr61.8%

    \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{s}}{\color{blue}{\left(\frac{x}{-s} + 2\right) \cdot \left(\frac{x}{-s} + 2\right)}} \]
  13. Final simplification61.8%

    \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{s}}{\left(2 - \frac{x}{s}\right) \cdot \left(2 - \frac{x}{s}\right)} \]
  14. Add Preprocessing

Alternative 6: 95.6% accurate, 5.4× speedup?

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

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

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

      \[\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)}} \]
  3. Simplified99.3%

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(4 + -4 \cdot \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}\right)} \]
    3. rem-square-sqrt94.6%

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

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

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}{s \cdot \left(4 + -4 \cdot \frac{x}{s}\right)} \]
    3. add-sqr-sqrt61.8%

      \[\leadsto \frac{e^{\frac{-\color{blue}{x}}{s}}}{s \cdot \left(4 + -4 \cdot \frac{x}{s}\right)} \]
    4. *-un-lft-identity61.8%

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

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

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

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

    \[\leadsto \frac{e^{\frac{x}{-s}}}{s \cdot \left(4 + \frac{x}{s} \cdot -4\right)} \]
  13. Add Preprocessing

Alternative 7: 38.7% accurate, 29.5× speedup?

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

\\
\frac{0.5 + \frac{x\_m}{s} \cdot -0.25}{s + \left(s + x\_m \cdot \left(\frac{x\_m}{s} \cdot 0.5 + -1\right)\right)}
\end{array}
Derivation
  1. Initial program 99.3%

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\right)\right)} \]
    5. 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 e^{\frac{-\left|-x\right|}{s}} + s \cdot 1\right)}} \]
    6. *-rgt-identity99.5%

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

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{0.5 + -0.25 \cdot \frac{x}{s}}}{s + \frac{s}{e^{\frac{x}{s}}}} \]
  9. Taylor expanded in x around 0 41.4%

    \[\leadsto \frac{0.5 + -0.25 \cdot \frac{x}{s}}{s + \color{blue}{\left(s + x \cdot \left(0.5 \cdot \frac{x}{s} - 1\right)\right)}} \]
  10. Final simplification41.4%

    \[\leadsto \frac{0.5 + \frac{x}{s} \cdot -0.25}{s + \left(s + x \cdot \left(\frac{x}{s} \cdot 0.5 + -1\right)\right)} \]
  11. Add Preprocessing

Alternative 8: 27.1% 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.3%

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\right)\right)} \]
    5. 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 e^{\frac{-\left|-x\right|}{s}} + s \cdot 1\right)}} \]
    6. *-rgt-identity99.5%

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

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{0.5 + -0.25 \cdot \frac{x}{s}}}{s + \frac{s}{e^{\frac{x}{s}}}} \]
  9. Taylor expanded in x around 0 29.7%

    \[\leadsto \frac{0.5 + -0.25 \cdot \frac{x}{s}}{\color{blue}{-1 \cdot x + 2 \cdot s}} \]
  10. Step-by-step derivation
    1. +-commutative29.7%

      \[\leadsto \frac{0.5 + -0.25 \cdot \frac{x}{s}}{\color{blue}{2 \cdot s + -1 \cdot x}} \]
    2. mul-1-neg29.7%

      \[\leadsto \frac{0.5 + -0.25 \cdot \frac{x}{s}}{2 \cdot s + \color{blue}{\left(-x\right)}} \]
    3. unsub-neg29.7%

      \[\leadsto \frac{0.5 + -0.25 \cdot \frac{x}{s}}{\color{blue}{2 \cdot s - x}} \]
  11. Simplified29.7%

    \[\leadsto \frac{0.5 + -0.25 \cdot \frac{x}{s}}{\color{blue}{2 \cdot s - x}} \]
  12. Taylor expanded in x around 0 30.0%

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  13. Add Preprocessing

Reproduce

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