Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 15.0s
Alternatives: 15
Speedup: N/A×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 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.2× speedup?

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

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

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

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

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

Alternative 2: 99.5% accurate, 2.9× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(\color{blue}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \cdot s\right)} \]
    11. *-un-lft-identity28.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 60.4% accurate, 5.5× speedup?

\[\begin{array}{l} \\ \frac{1}{2 \cdot \left(s \cdot \left(1 + {e}^{\left(\frac{x}{s}\right)}\right)\right)} \end{array} \]
(FPCore (x s)
 :precision binary32
 (/ 1.0 (* 2.0 (* s (+ 1.0 (pow E (/ x s)))))))
float code(float x, float s) {
	return 1.0f / (2.0f * (s * (1.0f + powf(((float) M_E), (x / s)))));
}
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(2.0) * Float32(s * Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(x / s))))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(2.0) * (s * (single(1.0) + (single(2.71828182845904523536) ^ (x / s)))));
end
\begin{array}{l}

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(\color{blue}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \cdot s\right)} \]
    11. *-un-lft-identity28.2%

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

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

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

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

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

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

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

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

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

Alternative 4: 60.4% accurate, 5.6× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(\color{blue}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \cdot s\right)} \]
    11. *-un-lft-identity28.2%

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

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

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

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

Alternative 5: 60.4% accurate, 5.7× speedup?

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

\\
\frac{\frac{0.5}{s}}{1 + e^{\frac{x}{s}}}
\end{array}
Derivation
  1. Initial program 99.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(\color{blue}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \cdot s\right)} \]
    11. *-un-lft-identity28.2%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{0.5}{s}}{1 + e^{\frac{x}{s}}}} \]
  9. Simplified62.6%

    \[\leadsto \color{blue}{\frac{\frac{0.5}{s}}{1 + e^{\frac{x}{s}}}} \]
  10. Final simplification62.6%

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

Alternative 6: 56.0% accurate, 10.0× speedup?

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

\\
\begin{array}{l}
t_0 := 4 + \frac{x \cdot 2}{s}\\
t_1 := \frac{x}{s} \cdot \left(\frac{x}{s} + 2\right)\\
\mathbf{if}\;x \leq 9.999999960041972 \cdot 10^{-12}:\\
\;\;\;\;\frac{1}{s \cdot \frac{t_1 \cdot t_1 - t_0 \cdot t_0}{t_1 - t_0}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot t_1 + s \cdot t_0}\\


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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
      3. associate-/l/47.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.99999996e-12 < 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. Simplified99.9%

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
      3. associate-/l/97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 9.999999960041972 \cdot 10^{-12}:\\ \;\;\;\;\frac{1}{s \cdot \frac{\left(\frac{x}{s} \cdot \left(\frac{x}{s} + 2\right)\right) \cdot \left(\frac{x}{s} \cdot \left(\frac{x}{s} + 2\right)\right) - \left(4 + \frac{x \cdot 2}{s}\right) \cdot \left(4 + \frac{x \cdot 2}{s}\right)}{\frac{x}{s} \cdot \left(\frac{x}{s} + 2\right) - \left(4 + \frac{x \cdot 2}{s}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s} \cdot \left(\frac{x}{s} + 2\right)\right) + s \cdot \left(4 + \frac{x \cdot 2}{s}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 61.0% accurate, 27.0× speedup?

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
    3. associate-/l/62.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(\frac{x}{s} \cdot \color{blue}{\left(\left(1 + 1\right) + \frac{x}{s}\right)}\right) \cdot s + \left(\left(\frac{x}{s} + 2\right) \cdot \left(1 + 1\right)\right) \cdot s} \]
    7. metadata-eval59.6%

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

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

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

Alternative 8: 50.0% accurate, 34.4× speedup?

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

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

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


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

    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. Simplified99.9%

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

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

    if 1.20000001e-17 < x

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
      3. associate-/l/97.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.2000000136174153 \cdot 10^{-17}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s} \cdot \left(\frac{x}{s} + 2\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 69.4% accurate, 34.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000002e-7 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.0000000233721948 \cdot 10^{-7}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x}{s} + s \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s} \cdot \left(\frac{x}{s} + 2\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 73.9% accurate, 41.3× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{s} + 2\\
\frac{1}{s \cdot \left(t_0 \cdot t_0\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
    3. associate-/l/62.2%

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{s \cdot \color{blue}{\left(\left(\frac{x}{s} + 2\right) \cdot \left(\frac{x}{s} + 2\right)\right)}} \]
  10. Final simplification72.5%

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

Alternative 11: 50.9% accurate, 56.4× speedup?

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
    3. associate-/l/62.2%

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

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

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

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

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

    \[\leadsto \frac{1}{s \cdot \color{blue}{\left(4 + \frac{x}{s} \cdot 4\right)}} \]
  10. Final simplification52.3%

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

Alternative 12: 28.3% accurate, 77.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{0.25}{x}\\


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

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

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

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

    if 3.99999999e-6 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 29.0% accurate, 88.6× speedup?

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
    3. associate-/l/62.2%

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

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

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

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

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

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

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

Alternative 14: 28.5% accurate, 124.0× speedup?

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

\\
\frac{0.25}{x + s}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{{\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
    3. associate-/l/62.2%

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

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

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

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

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

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

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

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

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\frac{1}{4}}{s + x}}\right)} - 1 \]
    4. metadata-eval60.6%

      \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{0.25}}{s + x}\right)} - 1 \]
    5. +-commutative60.6%

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.25}{x + s}\right)\right)} \]
    2. expm1-log1p31.5%

      \[\leadsto \color{blue}{\frac{0.25}{x + s}} \]
    3. +-commutative31.5%

      \[\leadsto \frac{0.25}{\color{blue}{s + x}} \]
  13. Simplified31.5%

    \[\leadsto \color{blue}{\frac{0.25}{s + x}} \]
  14. Final simplification31.5%

    \[\leadsto \frac{0.25}{x + s} \]
  15. Add Preprocessing

Alternative 15: 26.7% accurate, 206.7× speedup?

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

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

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

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

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  5. Final simplification30.7%

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

Reproduce

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