| Alternative 1 | |
|---|---|
| Error | 0.42% |
| Cost | 6880 |
\[\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\frac{1}{\left(1 + t_0\right) \cdot \left(s + \frac{s}{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 (/ 1.0 (* s (* (+ 1.0 (exp (/ (- x) s))) (+ 1.0 (exp (/ x s)))))))
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) {
return 1.0f / (s * ((1.0f + expf((-x / s))) * (1.0f + expf((x / s)))));
}
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
code = 1.0e0 / (s * ((1.0e0 + exp((-x / s))) * (1.0e0 + exp((x / s)))))
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) return Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))) * Float32(Float32(1.0) + exp(Float32(x / s)))))) 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) tmp = single(1.0) / (s * ((single(1.0) + exp((-x / s))) * (single(1.0) + exp((x / s))))); 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)}
\frac{1}{s \cdot \left(\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(1 + e^{\frac{x}{s}}\right)\right)}
Results
Initial program 0.44
Simplified0.44
[Start]0.44 | \[ \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.42 | \[ \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.42 | \[ \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.42 | \[ \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.42 | \[ \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.42 | \[ \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.48 | \[ \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.48 | \[ \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-rr37.06
Simplified0.42
[Start]37.06 | \[ \frac{1}{s + \left(\frac{s}{e^{\frac{x}{s}}} \cdot \left(e^{\frac{x}{s}} + 1\right) + s \cdot e^{\frac{x}{s}}\right)}
\] |
|---|---|
+-commutative [=>]37.06 | \[ \frac{1}{s + \color{blue}{\left(s \cdot e^{\frac{x}{s}} + \frac{s}{e^{\frac{x}{s}}} \cdot \left(e^{\frac{x}{s}} + 1\right)\right)}}
\] |
distribute-rgt-in [=>]72.73 | \[ \frac{1}{s + \left(s \cdot e^{\frac{x}{s}} + \color{blue}{\left(e^{\frac{x}{s}} \cdot \frac{s}{e^{\frac{x}{s}}} + 1 \cdot \frac{s}{e^{\frac{x}{s}}}\right)}\right)}
\] |
*-lft-identity [=>]72.73 | \[ \frac{1}{s + \left(s \cdot e^{\frac{x}{s}} + \left(e^{\frac{x}{s}} \cdot \frac{s}{e^{\frac{x}{s}}} + \color{blue}{\frac{s}{e^{\frac{x}{s}}}}\right)\right)}
\] |
associate-+r+ [=>]72.73 | \[ \frac{1}{s + \color{blue}{\left(\left(s \cdot e^{\frac{x}{s}} + e^{\frac{x}{s}} \cdot \frac{s}{e^{\frac{x}{s}}}\right) + \frac{s}{e^{\frac{x}{s}}}\right)}}
\] |
*-commutative [<=]72.73 | \[ \frac{1}{s + \left(\left(\color{blue}{e^{\frac{x}{s}} \cdot s} + e^{\frac{x}{s}} \cdot \frac{s}{e^{\frac{x}{s}}}\right) + \frac{s}{e^{\frac{x}{s}}}\right)}
\] |
distribute-lft-in [<=]36.05 | \[ \frac{1}{s + \left(\color{blue}{e^{\frac{x}{s}} \cdot \left(s + \frac{s}{e^{\frac{x}{s}}}\right)} + \frac{s}{e^{\frac{x}{s}}}\right)}
\] |
*-rgt-identity [<=]36.05 | \[ \frac{1}{s + \left(\color{blue}{\left(e^{\frac{x}{s}} \cdot \left(s + \frac{s}{e^{\frac{x}{s}}}\right)\right) \cdot 1} + \frac{s}{e^{\frac{x}{s}}}\right)}
\] |
+-commutative [<=]36.05 | \[ \frac{1}{s + \color{blue}{\left(\frac{s}{e^{\frac{x}{s}}} + \left(e^{\frac{x}{s}} \cdot \left(s + \frac{s}{e^{\frac{x}{s}}}\right)\right) \cdot 1\right)}}
\] |
Taylor expanded in s around 0 0.44
Applied egg-rr0.44
Final simplification0.44
| Alternative 1 | |
|---|---|
| Error | 0.42% |
| Cost | 6880 |
| Alternative 2 | |
|---|---|
| Error | 3.9% |
| Cost | 6688 |
| Alternative 3 | |
|---|---|
| Error | 5.15% |
| Cost | 6656 |
| Alternative 4 | |
|---|---|
| Error | 3.9% |
| Cost | 3684 |
| Alternative 5 | |
|---|---|
| Error | 4.32% |
| Cost | 3652 |
| Alternative 6 | |
|---|---|
| Error | 4.41% |
| Cost | 3556 |
| Alternative 7 | |
|---|---|
| Error | 12.99% |
| Cost | 3492 |
| Alternative 8 | |
|---|---|
| Error | 19.28% |
| Cost | 3364 |
| Alternative 9 | |
|---|---|
| Error | 29.34% |
| Cost | 804 |
| Alternative 10 | |
|---|---|
| Error | 47.65% |
| Cost | 361 |
| Alternative 11 | |
|---|---|
| Error | 48.5% |
| Cost | 352 |
| Alternative 12 | |
|---|---|
| Error | 48.63% |
| Cost | 288 |
| Alternative 13 | |
|---|---|
| Error | 72.71% |
| Cost | 96 |
| Alternative 14 | |
|---|---|
| Error | 91.71% |
| Cost | 32 |
herbie shell --seed 2023089
(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))))))