?

Average Error: 0.19% → 0.13%
Time: 14.2s
Precision: binary32
Cost: 9760

?

\[0 \leq s \land s \leq 1.0651631\]
\[\frac{1}{1 + e^{\frac{-x}{s}}} \]
\[e^{-\mathsf{log1p}\left(e^{\frac{-x}{s}}\right)} \]
(FPCore (x s) :precision binary32 (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))
(FPCore (x s) :precision binary32 (exp (- (log1p (exp (/ (- x) s))))))
float code(float x, float s) {
	return 1.0f / (1.0f + expf((-x / s)));
}
float code(float x, float s) {
	return expf(-log1pf(expf((-x / s))));
}
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))))
end
function code(x, s)
	return exp(Float32(-log1p(exp(Float32(Float32(-x) / s)))))
end
\frac{1}{1 + e^{\frac{-x}{s}}}
e^{-\mathsf{log1p}\left(e^{\frac{-x}{s}}\right)}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 0.19

    \[\frac{1}{1 + e^{\frac{-x}{s}}} \]
  2. Applied egg-rr0.23

    \[\leadsto \frac{1}{1 + \color{blue}{\frac{\frac{1}{\sqrt{e^{\frac{x}{s}}}}}{\sqrt{e^{\frac{x}{s}}}}}} \]
  3. Applied egg-rr0.13

    \[\leadsto \color{blue}{e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)}} \]
  4. Simplified0.13

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

    [Start]0.13

    \[ e^{-\mathsf{log1p}\left(e^{-\frac{x}{s}}\right)} \]

    distribute-neg-frac [=>]0.13

    \[ e^{-\mathsf{log1p}\left(e^{\color{blue}{\frac{-x}{s}}}\right)} \]
  5. Final simplification0.13

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

Alternatives

Alternative 1
Error0.19%
Cost6720
\[\frac{1}{1 + {\left(e^{-2}\right)}^{\left(\frac{\frac{x}{s}}{2}\right)}} \]
Alternative 2
Error0.19%
Cost3456
\[\frac{1}{e^{\frac{-x}{s}} + 1} \]
Alternative 3
Error33.56%
Cost1640
\[\begin{array}{l} t_0 := \frac{-x}{s}\\ t_1 := x \cdot \frac{0.5}{s}\\ t_2 := \frac{x}{s} \cdot \left(1 - t_1\right)\\ \mathbf{if}\;t_0 \leq -2:\\ \;\;\;\;0.5\\ \mathbf{elif}\;t_0 \leq 19999999961012896000:\\ \;\;\;\;\frac{1}{4 + \left(\frac{x}{s} \cdot \left(t_1 + -1\right)\right) \cdot t_2} \cdot \left(2 + t_2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{\frac{\frac{x \cdot x}{s}}{s}}\\ \end{array} \]
Alternative 4
Error36.31%
Cost708
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq -2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(2 - \frac{x}{s}\right) + x \cdot \left(\frac{x}{s} \cdot \frac{0.5}{s}\right)}\\ \end{array} \]
Alternative 5
Error36.31%
Cost708
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq -2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(2 + x \cdot \frac{0.5}{s \cdot \frac{s}{x}}\right) - \frac{x}{s}}\\ \end{array} \]
Alternative 6
Error36.9%
Cost612
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 0.5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + \frac{x}{\frac{s \cdot \left(-s\right)}{x}} \cdot -0.5}\\ \end{array} \]
Alternative 7
Error38.46%
Cost516
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{0.5 \cdot \frac{x \cdot x}{s \cdot s}}\\ \end{array} \]
Alternative 8
Error38.28%
Cost516
\[\begin{array}{l} \mathbf{if}\;-x \leq 9.999999998199587 \cdot 10^{-24}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + 0.5 \cdot \frac{x \cdot x}{s \cdot s}}\\ \end{array} \]
Alternative 9
Error41.63%
Cost452
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(s \cdot \frac{\frac{s}{x}}{x}\right)\\ \end{array} \]
Alternative 10
Error38.86%
Cost452
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{s \cdot s}{x \cdot x}\\ \end{array} \]
Alternative 11
Error50.34%
Cost388
\[\begin{array}{l} \mathbf{if}\;\frac{-x}{s} \leq -2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 - \frac{x}{s}}\\ \end{array} \]
Alternative 12
Error51.88%
Cost356
\[\begin{array}{l} t_0 := \frac{-x}{s}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0}\\ \end{array} \]
Alternative 13
Error53.7%
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq -4.999999969612645 \cdot 10^{-9}:\\ \;\;\;\;\frac{-s}{x}\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 14
Error64.86%
Cost32
\[0.5 \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (x s)
  :name "Logistic function"
  :precision binary32
  :pre (and (<= 0.0 s) (<= s 1.0651631))
  (/ 1.0 (+ 1.0 (exp (/ (- x) s)))))