| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 23040 |
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\left(0.5 - {\sin \left(u2 \cdot \pi\right)}^{2}\right) - \cos \left(\left(u2 \cdot \left(\pi \cdot 2\right) + 1\right) + -1\right) \cdot -0.5\right)
\]
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log1p (- u1)))) (+ (* 0.5 (cos (expm1 (log1p (* u2 (* PI 2.0)))))) (- 0.5 (pow (sin (* u2 PI)) 2.0)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(-logf((1.0f - u1))) * cosf(((2.0f * ((float) M_PI)) * u2));
}
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(-log1pf(-u1)) * ((0.5f * cosf(expm1f(log1pf((u2 * (((float) M_PI) * 2.0f)))))) + (0.5f - powf(sinf((u2 * ((float) M_PI))), 2.0f)));
}
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(-log(Float32(Float32(1.0) - u1)))) * cos(Float32(Float32(Float32(2.0) * Float32(pi)) * u2))) end
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(-log1p(Float32(-u1)))) * Float32(Float32(Float32(0.5) * cos(expm1(log1p(Float32(u2 * Float32(Float32(pi) * Float32(2.0))))))) + Float32(Float32(0.5) - (sin(Float32(u2 * Float32(pi))) ^ Float32(2.0))))) end
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \left(\mathsf{expm1}\left(\mathsf{log1p}\left(u2 \cdot \left(\pi \cdot 2\right)\right)\right)\right) + \left(0.5 - {\sin \left(u2 \cdot \pi\right)}^{2}\right)\right)
Results
Initial program 13.6
Simplified0.3
[Start]13.6 | \[ \sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\] |
|---|---|
sub-neg [=>]13.6 | \[ \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\] |
log1p-def [=>]0.3 | \[ \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\] |
associate-*l* [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)}
\] |
Applied egg-rr0.3
Simplified0.3
[Start]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 \cdot \cos \left(\pi \cdot \left(u2 + u2\right)\right) + \left(-{\sin \left(\pi \cdot u2\right)}^{2}\right)\right)\right)
\] |
|---|---|
+-commutative [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(\left(0.5 \cdot \cos \left(\pi \cdot \left(u2 + u2\right)\right) + \left(-{\sin \left(\pi \cdot u2\right)}^{2}\right)\right) + 0.5\right)}
\] |
sub-neg [<=]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\color{blue}{\left(0.5 \cdot \cos \left(\pi \cdot \left(u2 + u2\right)\right) - {\sin \left(\pi \cdot u2\right)}^{2}\right)} + 0.5\right)
\] |
associate-+l- [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(0.5 \cdot \cos \left(\pi \cdot \left(u2 + u2\right)\right) - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)}
\] |
*-commutative [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \color{blue}{\left(\left(u2 + u2\right) \cdot \pi\right)} - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)
\] |
count-2 [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \left(\color{blue}{\left(2 \cdot u2\right)} \cdot \pi\right) - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)
\] |
associate-*r* [<=]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \color{blue}{\left(2 \cdot \left(u2 \cdot \pi\right)\right)} - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)
\] |
*-commutative [<=]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \left(2 \cdot \color{blue}{\left(\pi \cdot u2\right)}\right) - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)
\] |
*-commutative [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \color{blue}{\left(\left(\pi \cdot u2\right) \cdot 2\right)} - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)
\] |
*-commutative [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \left(\color{blue}{\left(u2 \cdot \pi\right)} \cdot 2\right) - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)
\] |
associate-*l* [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \color{blue}{\left(u2 \cdot \left(\pi \cdot 2\right)\right)} - \left({\sin \left(\pi \cdot u2\right)}^{2} - 0.5\right)\right)
\] |
*-commutative [=>]0.3 | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 \cdot \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right) - \left({\sin \color{blue}{\left(u2 \cdot \pi\right)}}^{2} - 0.5\right)\right)
\] |
Applied egg-rr0.3
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 23040 |
| Alternative 2 | |
|---|---|
| Error | 0.3 |
| Cost | 22912 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 22720 |
| Alternative 4 | |
|---|---|
| Error | 0.3 |
| Cost | 20000 |
| Alternative 5 | |
|---|---|
| Error | 2.9 |
| Cost | 16356 |
| Alternative 6 | |
|---|---|
| Error | 1.8 |
| Cost | 13412 |
| Alternative 7 | |
|---|---|
| Error | 0.3 |
| Cost | 13056 |
| Alternative 8 | |
|---|---|
| Error | 2.5 |
| Cost | 10112 |
| Alternative 9 | |
|---|---|
| Error | 6.4 |
| Cost | 6496 |
| Alternative 10 | |
|---|---|
| Error | 7.6 |
| Cost | 3680 |
| Alternative 11 | |
|---|---|
| Error | 8.0 |
| Cost | 3552 |
| Alternative 12 | |
|---|---|
| Error | 8.7 |
| Cost | 3424 |
| Alternative 13 | |
|---|---|
| Error | 11.3 |
| Cost | 3232 |
| Alternative 14 | |
|---|---|
| Error | 32.0 |
| Cost | 96 |
herbie shell --seed 2023025
(FPCore (cosTheta_i u1 u2)
:name "Beckmann Sample, near normal, slope_x"
:precision binary32
:pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
(* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))