| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 6880 |
\[\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\frac{1}{\left(s + \frac{s}{t_0}\right) \cdot \left(1 + t_0\right)}
\end{array}
\]
(FPCore (x s) :precision binary32 (/ (exp (/ (- (fabs x)) s)) (* (* s (+ 1.0 (exp (/ (- (fabs x)) s)))) (+ 1.0 (exp (/ (- (fabs x)) s))))))
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x s)))) (/ 1.0 (+ s (+ (/ s t_0) (* s (+ 1.0 t_0)))))))
float code(float x, float s) {
return expf((-fabsf(x) / s)) / ((s * (1.0f + expf((-fabsf(x) / s)))) * (1.0f + expf((-fabsf(x) / s))));
}
float code(float x, float s) {
float t_0 = expf((x / s));
return 1.0f / (s + ((s / t_0) + (s * (1.0f + t_0))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = exp((-abs(x) / s)) / ((s * (1.0e0 + exp((-abs(x) / s)))) * (1.0e0 + exp((-abs(x) / s))))
end function
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((x / s))
code = 1.0e0 / (s + ((s / t_0) + (s * (1.0e0 + t_0))))
end function
function code(x, s) return Float32(exp(Float32(Float32(-abs(x)) / s)) / Float32(Float32(s * Float32(Float32(1.0) + exp(Float32(Float32(-abs(x)) / s)))) * Float32(Float32(1.0) + exp(Float32(Float32(-abs(x)) / s))))) end
function code(x, s) t_0 = exp(Float32(x / s)) return Float32(Float32(1.0) / Float32(s + Float32(Float32(s / t_0) + Float32(s * Float32(Float32(1.0) + t_0))))) end
function tmp = code(x, s) tmp = exp((-abs(x) / s)) / ((s * (single(1.0) + exp((-abs(x) / s)))) * (single(1.0) + exp((-abs(x) / s)))); end
function tmp = code(x, s) t_0 = exp((x / s)); tmp = single(1.0) / (s + ((s / t_0) + (s * (single(1.0) + t_0)))); end
\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)}
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\frac{1}{s + \left(\frac{s}{t_0} + s \cdot \left(1 + t_0\right)\right)}
\end{array}
Results
Initial program 0.2
Simplified0.2
[Start]0.2 | \[ \frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}
\] |
|---|---|
associate-/l/ [<=]0.2 | \[ \color{blue}{\frac{\frac{e^{\frac{-\left|x\right|}{s}}}{1 + e^{\frac{-\left|x\right|}{s}}}}{s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}}
\] |
*-lft-identity [<=]0.2 | \[ \frac{\color{blue}{1 \cdot \frac{e^{\frac{-\left|x\right|}{s}}}{1 + e^{\frac{-\left|x\right|}{s}}}}}{s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}
\] |
*-lft-identity [<=]0.2 | \[ \frac{1 \cdot \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{1 \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}}}{s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}
\] |
*-commutative [<=]0.2 | \[ \frac{1 \cdot \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot 1}}}{s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}
\] |
associate-*r/ [=>]0.2 | \[ \frac{\color{blue}{\frac{1 \cdot e^{\frac{-\left|x\right|}{s}}}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot 1}}}{s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}
\] |
associate-/l* [=>]0.2 | \[ \frac{\color{blue}{\frac{1}{\frac{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot 1}{e^{\frac{-\left|x\right|}{s}}}}}}{s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)}
\] |
associate-/l/ [=>]0.2 | \[ \color{blue}{\frac{1}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \frac{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot 1}{e^{\frac{-\left|x\right|}{s}}}}}
\] |
Applied egg-rr11.5
Taylor expanded in s around 0 11.6
Simplified0.1
[Start]11.6 | \[ \frac{1}{\left(\frac{s}{e^{\frac{x}{s}}} + e^{\frac{x}{s}} \cdot \left(s \cdot \left(1 + \frac{1}{e^{\frac{x}{s}}}\right)\right)\right) + s}
\] |
|---|---|
*-commutative [=>]11.6 | \[ \frac{1}{\left(\frac{s}{e^{\frac{x}{s}}} + \color{blue}{\left(s \cdot \left(1 + \frac{1}{e^{\frac{x}{s}}}\right)\right) \cdot e^{\frac{x}{s}}}\right) + s}
\] |
associate-*l* [=>]11.6 | \[ \frac{1}{\left(\frac{s}{e^{\frac{x}{s}}} + \color{blue}{s \cdot \left(\left(1 + \frac{1}{e^{\frac{x}{s}}}\right) \cdot e^{\frac{x}{s}}\right)}\right) + s}
\] |
*-commutative [<=]11.6 | \[ \frac{1}{\left(\frac{s}{e^{\frac{x}{s}}} + s \cdot \color{blue}{\left(e^{\frac{x}{s}} \cdot \left(1 + \frac{1}{e^{\frac{x}{s}}}\right)\right)}\right) + s}
\] |
distribute-lft-in [=>]23.3 | \[ \frac{1}{\left(\frac{s}{e^{\frac{x}{s}}} + s \cdot \color{blue}{\left(e^{\frac{x}{s}} \cdot 1 + e^{\frac{x}{s}} \cdot \frac{1}{e^{\frac{x}{s}}}\right)}\right) + s}
\] |
*-rgt-identity [=>]23.3 | \[ \frac{1}{\left(\frac{s}{e^{\frac{x}{s}}} + s \cdot \left(\color{blue}{e^{\frac{x}{s}}} + e^{\frac{x}{s}} \cdot \frac{1}{e^{\frac{x}{s}}}\right)\right) + s}
\] |
rgt-mult-inverse [=>]0.1 | \[ \frac{1}{\left(\frac{s}{e^{\frac{x}{s}}} + s \cdot \left(e^{\frac{x}{s}} + \color{blue}{1}\right)\right) + s}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 6880 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 6848 |
| Alternative 3 | |
|---|---|
| Error | 1.3 |
| Cost | 6688 |
| Alternative 4 | |
|---|---|
| Error | 1.7 |
| Cost | 6656 |
| Alternative 5 | |
|---|---|
| Error | 1.2 |
| Cost | 3684 |
| Alternative 6 | |
|---|---|
| Error | 1.3 |
| Cost | 3588 |
| Alternative 7 | |
|---|---|
| Error | 3.8 |
| Cost | 3556 |
| Alternative 8 | |
|---|---|
| Error | 7.8 |
| Cost | 416 |
| Alternative 9 | |
|---|---|
| Error | 7.3 |
| Cost | 416 |
| Alternative 10 | |
|---|---|
| Error | 11.5 |
| Cost | 361 |
| Alternative 11 | |
|---|---|
| Error | 12.0 |
| Cost | 360 |
| Alternative 12 | |
|---|---|
| Error | 11.5 |
| Cost | 360 |
| Alternative 13 | |
|---|---|
| Error | 11.0 |
| Cost | 352 |
| Alternative 14 | |
|---|---|
| Error | 11.9 |
| Cost | 297 |
| Alternative 15 | |
|---|---|
| Error | 12.0 |
| Cost | 296 |
| Alternative 16 | |
|---|---|
| Error | 23.3 |
| Cost | 96 |
herbie shell --seed 2023034
(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))))))