Logistic distribution

Percentage Accurate: 99.6% → 99.6%
Time: 12.0s
Alternatives: 13
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 13 alternatives:

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

Initial Program: 99.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{\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. +-commutative99.7%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\left(e^{\frac{x}{-s}} + 1\right) \cdot \left(s + \frac{s}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}\right)} \]
    11. rem-square-sqrt96.9%

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

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

Alternative 2: 99.3% accurate, 1.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := e^{\frac{x\_m}{s}}\\ \mathbf{if}\;\left|x\_m\right| \leq 0.0007999999797903001:\\ \;\;\;\;\frac{1}{s} \cdot e^{\frac{x\_m}{s} - 2 \cdot \mathsf{log1p}\left(t\_0\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{x\_m}{-s}}}{s + \frac{s}{t\_0}}\\ \end{array} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (let* ((t_0 (exp (/ x_m s))))
   (if (<= (fabs x_m) 0.0007999999797903001)
     (* (/ 1.0 s) (exp (- (/ x_m s) (* 2.0 (log1p t_0)))))
     (/ (exp (/ x_m (- s))) (+ s (/ s t_0))))))
x_m = fabs(x);
float code(float x_m, float s) {
	float t_0 = expf((x_m / s));
	float tmp;
	if (fabsf(x_m) <= 0.0007999999797903001f) {
		tmp = (1.0f / s) * expf(((x_m / s) - (2.0f * log1pf(t_0))));
	} else {
		tmp = expf((x_m / -s)) / (s + (s / t_0));
	}
	return tmp;
}
x_m = abs(x)
function code(x_m, s)
	t_0 = exp(Float32(x_m / s))
	tmp = Float32(0.0)
	if (abs(x_m) <= Float32(0.0007999999797903001))
		tmp = Float32(Float32(Float32(1.0) / s) * exp(Float32(Float32(x_m / s) - Float32(Float32(2.0) * log1p(t_0)))));
	else
		tmp = Float32(exp(Float32(x_m / Float32(-s))) / Float32(s + Float32(s / t_0)));
	end
	return tmp
end
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
t_0 := e^{\frac{x\_m}{s}}\\
\mathbf{if}\;\left|x\_m\right| \leq 0.0007999999797903001:\\
\;\;\;\;\frac{1}{s} \cdot e^{\frac{x\_m}{s} - 2 \cdot \mathsf{log1p}\left(t\_0\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{x\_m}{-s}}}{s + \frac{s}{t\_0}}\\


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

    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. fabs-neg99.4%

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

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. clear-num99.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{s} \cdot e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}} \]

    if 7.9999998e-4 < (fabs.f32 x)

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{e^{\frac{x}{-s}} + 1}}{s + \frac{s}{\color{blue}{1 + \frac{x}{s}}}} \]
    9. Taylor expanded in x around inf 48.8%

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

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

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

        \[\leadsto \frac{e^{\frac{x}{-s}}}{\color{blue}{1 \cdot s + e^{-1 \cdot \frac{x}{s}} \cdot s}} \]
      4. *-lft-identity48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{\color{blue}{s} + e^{-1 \cdot \frac{x}{s}} \cdot s} \]
      5. *-commutative48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + \color{blue}{s \cdot e^{-1 \cdot \frac{x}{s}}}} \]
      6. mul-1-neg48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + s \cdot e^{\color{blue}{-\frac{x}{s}}}} \]
      7. distribute-frac-neg248.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + s \cdot e^{\color{blue}{\frac{x}{-s}}}} \]
      8. rem-exp-log48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + \color{blue}{e^{\log s}} \cdot e^{\frac{x}{-s}}} \]
      9. exp-sum48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + \color{blue}{e^{\log s + \frac{x}{-s}}}} \]
      10. distribute-frac-neg248.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + e^{\log s + \color{blue}{\left(-\frac{x}{s}\right)}}} \]
      11. sub-neg48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + e^{\color{blue}{\log s - \frac{x}{s}}}} \]
      12. exp-diff48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + \color{blue}{\frac{e^{\log s}}{e^{\frac{x}{s}}}}} \]
      13. rem-exp-log48.8%

        \[\leadsto \frac{e^{\frac{x}{-s}}}{s + \frac{\color{blue}{s}}{e^{\frac{x}{s}}}} \]
    11. Simplified48.8%

      \[\leadsto \color{blue}{\frac{e^{\frac{x}{-s}}}{s + \frac{s}{e^{\frac{x}{s}}}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 99.5% accurate, 1.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} t_0 := e^{\frac{x\_m}{s}}\\ \mathbf{if}\;\left|x\_m\right| \leq 3:\\ \;\;\;\;\frac{e^{\frac{x\_m}{s} - 2 \cdot \mathsf{log1p}\left(t\_0\right)}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.25}{s}}{t\_0}\\ \end{array} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (let* ((t_0 (exp (/ x_m s))))
   (if (<= (fabs x_m) 3.0)
     (/ (exp (- (/ x_m s) (* 2.0 (log1p t_0)))) s)
     (/ (/ 0.25 s) t_0))))
x_m = fabs(x);
float code(float x_m, float s) {
	float t_0 = expf((x_m / s));
	float tmp;
	if (fabsf(x_m) <= 3.0f) {
		tmp = expf(((x_m / s) - (2.0f * log1pf(t_0)))) / s;
	} else {
		tmp = (0.25f / s) / t_0;
	}
	return tmp;
}
x_m = abs(x)
function code(x_m, s)
	t_0 = exp(Float32(x_m / s))
	tmp = Float32(0.0)
	if (abs(x_m) <= Float32(3.0))
		tmp = Float32(exp(Float32(Float32(x_m / s) - Float32(Float32(2.0) * log1p(t_0)))) / s);
	else
		tmp = Float32(Float32(Float32(0.25) / s) / t_0);
	end
	return tmp
end
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
t_0 := e^{\frac{x\_m}{s}}\\
\mathbf{if}\;\left|x\_m\right| \leq 3:\\
\;\;\;\;\frac{e^{\frac{x\_m}{s} - 2 \cdot \mathsf{log1p}\left(t\_0\right)}}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.25}{s}}{t\_0}\\


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

    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. Step-by-step derivation
      1. clear-num99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{e^{\frac{x}{s}}}{e^{\color{blue}{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)} \cdot 2}} \cdot \frac{1}{s} \]
      8. *-commutative73.8%

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

        \[\leadsto \color{blue}{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}} \cdot \frac{1}{s} \]
      10. *-commutative98.7%

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

        \[\leadsto \color{blue}{\frac{1 \cdot e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}{s}} \]
      12. *-lft-identity99.5%

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

      \[\leadsto \color{blue}{\frac{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}{s}} \]

    if 3 < (fabs.f32 x)

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

      \[\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 s around inf 100.0%

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
    8. Step-by-step derivation
      1. clear-num100.0%

        \[\leadsto \frac{e^{\color{blue}{\frac{1}{\frac{s}{-\left|x\right|}}}}}{s \cdot 4} \]
      2. clear-num100.0%

        \[\leadsto \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{s \cdot 4} \]
      3. neg-mul-1100.0%

        \[\leadsto \frac{e^{\frac{\color{blue}{-1 \cdot \left|x\right|}}{s}}}{s \cdot 4} \]
      4. add-sqr-sqrt50.0%

        \[\leadsto \frac{e^{\frac{-1 \cdot \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}{s \cdot 4} \]
      5. fabs-sqr50.0%

        \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}{s}}}{s \cdot 4} \]
      6. add-sqr-sqrt51.6%

        \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{x}}{s}}}{s \cdot 4} \]
      7. *-un-lft-identity51.6%

        \[\leadsto \frac{e^{\frac{-1 \cdot x}{\color{blue}{1 \cdot s}}}}{s \cdot 4} \]
      8. times-frac51.6%

        \[\leadsto \frac{e^{\color{blue}{\frac{-1}{1} \cdot \frac{x}{s}}}}{s \cdot 4} \]
      9. metadata-eval51.6%

        \[\leadsto \frac{e^{\color{blue}{-1} \cdot \frac{x}{s}}}{s \cdot 4} \]
      10. metadata-eval51.6%

        \[\leadsto \frac{e^{\color{blue}{\frac{1}{-1}} \cdot \frac{x}{s}}}{s \cdot 4} \]
      11. times-frac51.6%

        \[\leadsto \frac{e^{\color{blue}{\frac{1 \cdot x}{-1 \cdot s}}}}{s \cdot 4} \]
      12. *-un-lft-identity51.6%

        \[\leadsto \frac{e^{\frac{\color{blue}{x}}{-1 \cdot s}}}{s \cdot 4} \]
      13. neg-mul-151.6%

        \[\leadsto \frac{e^{\frac{x}{\color{blue}{-s}}}}{s \cdot 4} \]
      14. distribute-frac-neg251.6%

        \[\leadsto \frac{e^{\color{blue}{-\frac{x}{s}}}}{s \cdot 4} \]
      15. rec-exp51.6%

        \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
    9. Applied egg-rr51.6%

      \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
    10. Taylor expanded in x around inf 51.6%

      \[\leadsto \color{blue}{\frac{0.25}{s \cdot e^{\frac{x}{s}}}} \]
    11. Step-by-step derivation
      1. associate-/r*51.6%

        \[\leadsto \color{blue}{\frac{\frac{0.25}{s}}{e^{\frac{x}{s}}}} \]
    12. Simplified51.6%

      \[\leadsto \color{blue}{\frac{\frac{0.25}{s}}{e^{\frac{x}{s}}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 99.6% 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.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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 s around 0 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 97.0% 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.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 95.0% accurate, 5.7× speedup?

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

\\
\frac{\frac{1}{e^{\frac{x\_m}{s}}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.7%

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

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

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

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

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

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

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

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

    \[\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 s around inf 94.1%

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

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

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

      \[\leadsto \frac{e^{\color{blue}{\frac{1}{\frac{s}{-\left|x\right|}}}}}{s \cdot 4} \]
    2. clear-num94.1%

      \[\leadsto \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{s \cdot 4} \]
    3. neg-mul-194.1%

      \[\leadsto \frac{e^{\frac{\color{blue}{-1 \cdot \left|x\right|}}{s}}}{s \cdot 4} \]
    4. add-sqr-sqrt47.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}{s \cdot 4} \]
    5. fabs-sqr47.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}{s}}}{s \cdot 4} \]
    6. add-sqr-sqrt60.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{x}}{s}}}{s \cdot 4} \]
    7. *-un-lft-identity60.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot x}{\color{blue}{1 \cdot s}}}}{s \cdot 4} \]
    8. times-frac60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{-1}{1} \cdot \frac{x}{s}}}}{s \cdot 4} \]
    9. metadata-eval60.2%

      \[\leadsto \frac{e^{\color{blue}{-1} \cdot \frac{x}{s}}}{s \cdot 4} \]
    10. metadata-eval60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{1}{-1}} \cdot \frac{x}{s}}}{s \cdot 4} \]
    11. times-frac60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{1 \cdot x}{-1 \cdot s}}}}{s \cdot 4} \]
    12. *-un-lft-identity60.2%

      \[\leadsto \frac{e^{\frac{\color{blue}{x}}{-1 \cdot s}}}{s \cdot 4} \]
    13. neg-mul-160.2%

      \[\leadsto \frac{e^{\frac{x}{\color{blue}{-s}}}}{s \cdot 4} \]
    14. distribute-frac-neg260.2%

      \[\leadsto \frac{e^{\color{blue}{-\frac{x}{s}}}}{s \cdot 4} \]
    15. rec-exp60.2%

      \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  9. Applied egg-rr60.2%

    \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  10. Add Preprocessing

Alternative 8: 95.0% accurate, 5.7× speedup?

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

\\
\frac{e^{\frac{x\_m}{-s}} \cdot 0.25}{s}
\end{array}
Derivation
  1. Initial program 99.7%

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

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

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

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

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

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

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

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

    \[\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 s around inf 94.1%

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

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

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Taylor expanded in x around 0 94.1%

    \[\leadsto \color{blue}{0.25 \cdot \frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{s}} \]
  9. Step-by-step derivation
    1. associate-*r/94.1%

      \[\leadsto \color{blue}{\frac{0.25 \cdot e^{-1 \cdot \frac{\left|x\right|}{s}}}{s}} \]
    2. exp-prod94.1%

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

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

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

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

      \[\leadsto \frac{0.25 \cdot \color{blue}{e^{-1 \cdot \frac{x}{s}}}}{s} \]
    7. neg-mul-160.2%

      \[\leadsto \frac{0.25 \cdot e^{\color{blue}{-\frac{x}{s}}}}{s} \]
    8. distribute-neg-frac260.2%

      \[\leadsto \frac{0.25 \cdot e^{\color{blue}{\frac{x}{-s}}}}{s} \]
  10. Simplified60.2%

    \[\leadsto \color{blue}{\frac{0.25 \cdot e^{\frac{x}{-s}}}{s}} \]
  11. Final simplification60.2%

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

Alternative 9: 94.9% accurate, 5.8× speedup?

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

\\
\frac{\frac{0.25}{s}}{e^{\frac{x\_m}{s}}}
\end{array}
Derivation
  1. Initial program 99.7%

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

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

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

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

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

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

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

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

    \[\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 s around inf 94.1%

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

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

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

      \[\leadsto \frac{e^{\color{blue}{\frac{1}{\frac{s}{-\left|x\right|}}}}}{s \cdot 4} \]
    2. clear-num94.1%

      \[\leadsto \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{s \cdot 4} \]
    3. neg-mul-194.1%

      \[\leadsto \frac{e^{\frac{\color{blue}{-1 \cdot \left|x\right|}}{s}}}{s \cdot 4} \]
    4. add-sqr-sqrt47.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}{s \cdot 4} \]
    5. fabs-sqr47.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}{s}}}{s \cdot 4} \]
    6. add-sqr-sqrt60.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{x}}{s}}}{s \cdot 4} \]
    7. *-un-lft-identity60.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot x}{\color{blue}{1 \cdot s}}}}{s \cdot 4} \]
    8. times-frac60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{-1}{1} \cdot \frac{x}{s}}}}{s \cdot 4} \]
    9. metadata-eval60.2%

      \[\leadsto \frac{e^{\color{blue}{-1} \cdot \frac{x}{s}}}{s \cdot 4} \]
    10. metadata-eval60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{1}{-1}} \cdot \frac{x}{s}}}{s \cdot 4} \]
    11. times-frac60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{1 \cdot x}{-1 \cdot s}}}}{s \cdot 4} \]
    12. *-un-lft-identity60.2%

      \[\leadsto \frac{e^{\frac{\color{blue}{x}}{-1 \cdot s}}}{s \cdot 4} \]
    13. neg-mul-160.2%

      \[\leadsto \frac{e^{\frac{x}{\color{blue}{-s}}}}{s \cdot 4} \]
    14. distribute-frac-neg260.2%

      \[\leadsto \frac{e^{\color{blue}{-\frac{x}{s}}}}{s \cdot 4} \]
    15. rec-exp60.2%

      \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  9. Applied egg-rr60.2%

    \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  10. Taylor expanded in x around inf 60.2%

    \[\leadsto \color{blue}{\frac{0.25}{s \cdot e^{\frac{x}{s}}}} \]
  11. Step-by-step derivation
    1. associate-/r*60.2%

      \[\leadsto \color{blue}{\frac{\frac{0.25}{s}}{e^{\frac{x}{s}}}} \]
  12. Simplified60.2%

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

Alternative 10: 79.6% accurate, 47.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\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. Step-by-step derivation
    1. clear-num99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 76.9% accurate, 47.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\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. Step-by-step derivation
    1. clear-num99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{s \cdot \left(4 + \color{blue}{\frac{x}{s} \cdot \frac{x}{s}}\right)} \]
  14. Add Preprocessing

Alternative 12: 50.9% accurate, 56.4× speedup?

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

\\
\frac{\frac{1}{1 + \frac{x\_m}{s}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.7%

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

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

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

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

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

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

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

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

    \[\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 s around inf 94.1%

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

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

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

      \[\leadsto \frac{e^{\color{blue}{\frac{1}{\frac{s}{-\left|x\right|}}}}}{s \cdot 4} \]
    2. clear-num94.1%

      \[\leadsto \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{s \cdot 4} \]
    3. neg-mul-194.1%

      \[\leadsto \frac{e^{\frac{\color{blue}{-1 \cdot \left|x\right|}}{s}}}{s \cdot 4} \]
    4. add-sqr-sqrt47.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}{s \cdot 4} \]
    5. fabs-sqr47.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}{s}}}{s \cdot 4} \]
    6. add-sqr-sqrt60.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot \color{blue}{x}}{s}}}{s \cdot 4} \]
    7. *-un-lft-identity60.2%

      \[\leadsto \frac{e^{\frac{-1 \cdot x}{\color{blue}{1 \cdot s}}}}{s \cdot 4} \]
    8. times-frac60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{-1}{1} \cdot \frac{x}{s}}}}{s \cdot 4} \]
    9. metadata-eval60.2%

      \[\leadsto \frac{e^{\color{blue}{-1} \cdot \frac{x}{s}}}{s \cdot 4} \]
    10. metadata-eval60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{1}{-1}} \cdot \frac{x}{s}}}{s \cdot 4} \]
    11. times-frac60.2%

      \[\leadsto \frac{e^{\color{blue}{\frac{1 \cdot x}{-1 \cdot s}}}}{s \cdot 4} \]
    12. *-un-lft-identity60.2%

      \[\leadsto \frac{e^{\frac{\color{blue}{x}}{-1 \cdot s}}}{s \cdot 4} \]
    13. neg-mul-160.2%

      \[\leadsto \frac{e^{\frac{x}{\color{blue}{-s}}}}{s \cdot 4} \]
    14. distribute-frac-neg260.2%

      \[\leadsto \frac{e^{\color{blue}{-\frac{x}{s}}}}{s \cdot 4} \]
    15. rec-exp60.2%

      \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  9. Applied egg-rr60.2%

    \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  10. Taylor expanded in x around 0 55.6%

    \[\leadsto \frac{\frac{1}{\color{blue}{1 + \frac{x}{s}}}}{s \cdot 4} \]
  11. Add Preprocessing

Alternative 13: 27.4% 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.7%

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

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

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

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

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

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

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

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

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

    \[\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 s around inf 27.2%

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

Reproduce

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