| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 22848 |
\[\frac{1}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(cosTheta, -2, 1\right)}, \frac{{\left(e^{cosTheta}\right)}^{\left(-cosTheta\right)}}{cosTheta \cdot \sqrt{\pi}}, 1 + c\right)}
\]
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(+ 1.0 c)
(*
(* (/ 1.0 (sqrt PI)) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta))
(exp (* (- cosTheta) cosTheta))))))(FPCore (cosTheta c)
:precision binary32
(if (<= cosTheta 2.4999999292951713e-10)
(* cosTheta (sqrt PI))
(/
1.0
(+
c
(+
1.0
(/
(sqrt (/ (+ -1.0 (* cosTheta 2.0)) (* cosTheta (* (- cosTheta) PI))))
(exp (* cosTheta cosTheta))))))))float code(float cosTheta, float c) {
return 1.0f / ((1.0f + c) + (((1.0f / sqrtf(((float) M_PI))) * (sqrtf(((1.0f - cosTheta) - cosTheta)) / cosTheta)) * expf((-cosTheta * cosTheta))));
}
float code(float cosTheta, float c) {
float tmp;
if (cosTheta <= 2.4999999292951713e-10f) {
tmp = cosTheta * sqrtf(((float) M_PI));
} else {
tmp = 1.0f / (c + (1.0f + (sqrtf(((-1.0f + (cosTheta * 2.0f)) / (cosTheta * (-cosTheta * ((float) M_PI))))) / expf((cosTheta * cosTheta)))));
}
return tmp;
}
function code(cosTheta, c) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + c) + Float32(Float32(Float32(Float32(1.0) / sqrt(Float32(pi))) * Float32(sqrt(Float32(Float32(Float32(1.0) - cosTheta) - cosTheta)) / cosTheta)) * exp(Float32(Float32(-cosTheta) * cosTheta))))) end
function code(cosTheta, c) tmp = Float32(0.0) if (cosTheta <= Float32(2.4999999292951713e-10)) tmp = Float32(cosTheta * sqrt(Float32(pi))); else tmp = Float32(Float32(1.0) / Float32(c + Float32(Float32(1.0) + Float32(sqrt(Float32(Float32(Float32(-1.0) + Float32(cosTheta * Float32(2.0))) / Float32(cosTheta * Float32(Float32(-cosTheta) * Float32(pi))))) / exp(Float32(cosTheta * cosTheta)))))); end return tmp end
function tmp = code(cosTheta, c) tmp = single(1.0) / ((single(1.0) + c) + (((single(1.0) / sqrt(single(pi))) * (sqrt(((single(1.0) - cosTheta) - cosTheta)) / cosTheta)) * exp((-cosTheta * cosTheta)))); end
function tmp_2 = code(cosTheta, c) tmp = single(0.0); if (cosTheta <= single(2.4999999292951713e-10)) tmp = cosTheta * sqrt(single(pi)); else tmp = single(1.0) / (c + (single(1.0) + (sqrt(((single(-1.0) + (cosTheta * single(2.0))) / (cosTheta * (-cosTheta * single(pi))))) / exp((cosTheta * cosTheta))))); end tmp_2 = tmp; end
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\begin{array}{l}
\mathbf{if}\;cosTheta \leq 2.4999999292951713 \cdot 10^{-10}:\\
\;\;\;\;cosTheta \cdot \sqrt{\pi}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c + \left(1 + \frac{\sqrt{\frac{-1 + cosTheta \cdot 2}{cosTheta \cdot \left(\left(-cosTheta\right) \cdot \pi\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}\\
\end{array}
Results
if cosTheta < 2.49999993e-10Initial program 0.7
Simplified0.5
[Start]0.7 | \[ \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\] |
|---|---|
+-commutative [=>]0.7 | \[ \frac{1}{\color{blue}{\left(c + 1\right)} + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\] |
associate-+l+ [=>]0.7 | \[ \frac{1}{\color{blue}{c + \left(1 + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}\right)}}
\] |
distribute-lft-neg-out [=>]0.7 | \[ \frac{1}{c + \left(1 + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\color{blue}{-cosTheta \cdot cosTheta}}\right)}
\] |
exp-neg [=>]0.7 | \[ \frac{1}{c + \left(1 + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}\right)}
\] |
associate-*r/ [=>]0.7 | \[ \frac{1}{c + \left(1 + \color{blue}{\frac{\left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot 1}{e^{cosTheta \cdot cosTheta}}}\right)}
\] |
associate-/l* [=>]0.7 | \[ \frac{1}{c + \left(1 + \color{blue}{\frac{\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}{\frac{e^{cosTheta \cdot cosTheta}}{1}}}\right)}
\] |
associate-*l/ [=>]0.5 | \[ \frac{1}{c + \left(1 + \frac{\color{blue}{\frac{1 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}{\sqrt{\pi}}}}{\frac{e^{cosTheta \cdot cosTheta}}{1}}\right)}
\] |
*-lft-identity [=>]0.5 | \[ \frac{1}{c + \left(1 + \frac{\frac{\color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}}{\sqrt{\pi}}}{\frac{e^{cosTheta \cdot cosTheta}}{1}}\right)}
\] |
Taylor expanded in cosTheta around 0 0.4
if 2.49999993e-10 < cosTheta Initial program 0.7
Simplified0.6
[Start]0.7 | \[ \frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\] |
|---|---|
+-commutative [=>]0.7 | \[ \frac{1}{\color{blue}{\left(c + 1\right)} + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\] |
associate-+l+ [=>]0.7 | \[ \frac{1}{\color{blue}{c + \left(1 + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}\right)}}
\] |
distribute-lft-neg-out [=>]0.7 | \[ \frac{1}{c + \left(1 + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\color{blue}{-cosTheta \cdot cosTheta}}\right)}
\] |
exp-neg [=>]0.7 | \[ \frac{1}{c + \left(1 + \left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot \color{blue}{\frac{1}{e^{cosTheta \cdot cosTheta}}}\right)}
\] |
associate-*r/ [=>]0.7 | \[ \frac{1}{c + \left(1 + \color{blue}{\frac{\left(\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot 1}{e^{cosTheta \cdot cosTheta}}}\right)}
\] |
associate-/l* [=>]0.7 | \[ \frac{1}{c + \left(1 + \color{blue}{\frac{\frac{1}{\sqrt{\pi}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}{\frac{e^{cosTheta \cdot cosTheta}}{1}}}\right)}
\] |
associate-*l/ [=>]0.6 | \[ \frac{1}{c + \left(1 + \frac{\color{blue}{\frac{1 \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}{\sqrt{\pi}}}}{\frac{e^{cosTheta \cdot cosTheta}}{1}}\right)}
\] |
*-lft-identity [=>]0.6 | \[ \frac{1}{c + \left(1 + \frac{\frac{\color{blue}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}}{\sqrt{\pi}}}{\frac{e^{cosTheta \cdot cosTheta}}{1}}\right)}
\] |
Applied egg-rr0.4
Applied egg-rr0.5
Simplified0.4
[Start]0.5 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\left(-1 - cosTheta \cdot -2\right) \cdot \frac{1}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
|---|---|
*-commutative [<=]0.5 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\color{blue}{\frac{1}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)} \cdot \left(-1 - cosTheta \cdot -2\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
associate-*l/ [=>]0.4 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\color{blue}{\frac{1 \cdot \left(-1 - cosTheta \cdot -2\right)}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)}}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
*-lft-identity [=>]0.4 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\frac{\color{blue}{-1 - cosTheta \cdot -2}}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
cancel-sign-sub-inv [=>]0.4 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\frac{\color{blue}{-1 + \left(-cosTheta\right) \cdot -2}}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
distribute-lft-neg-in [<=]0.4 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\frac{-1 + \color{blue}{\left(-cosTheta \cdot -2\right)}}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
distribute-rgt-neg-in [=>]0.4 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\frac{-1 + \color{blue}{cosTheta \cdot \left(--2\right)}}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
metadata-eval [=>]0.4 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\frac{-1 + cosTheta \cdot \color{blue}{2}}{\left(cosTheta \cdot \pi\right) \cdot \left(-cosTheta\right)}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
associate-*l* [=>]0.4 | \[ \frac{1}{c + \left(1 + \frac{\sqrt{\frac{-1 + cosTheta \cdot 2}{\color{blue}{cosTheta \cdot \left(\pi \cdot \left(-cosTheta\right)\right)}}}}{e^{cosTheta \cdot cosTheta}}\right)}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 22848 |
| Alternative 2 | |
|---|---|
| Error | 0.5 |
| Cost | 13376 |
| Alternative 3 | |
|---|---|
| Error | 0.6 |
| Cost | 10272 |
| Alternative 4 | |
|---|---|
| Error | 1.2 |
| Cost | 6976 |
| Alternative 5 | |
|---|---|
| Error | 1.7 |
| Cost | 6848 |
| Alternative 6 | |
|---|---|
| Error | 2.3 |
| Cost | 6464 |
| Alternative 7 | |
|---|---|
| Error | 28.5 |
| Cost | 96 |
| Alternative 8 | |
|---|---|
| Error | 28.5 |
| Cost | 32 |
herbie shell --seed 2023027
(FPCore (cosTheta c)
:name "Beckmann Sample, normalization factor"
:precision binary32
:pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999)) (and (< -1.0 c) (< c 1.0)))
(/ 1.0 (+ (+ 1.0 c) (* (* (/ 1.0 (sqrt PI)) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta)) (exp (* (- cosTheta) cosTheta))))))