| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 19520 |
\[\sqrt[3]{{\sin \left(2 \cdot \left(\pi \cdot u2\right)\right)}^{3} \cdot {\left(-\mathsf{log1p}\left(-u1\right)\right)}^{1.5}}
\]

(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2) :precision binary32 (cbrt (* (pow (sin (* 2.0 (* PI u2))) 3.0) (pow (- (log1p (- u1))) 1.5))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(-logf((1.0f - u1))) * sinf(((2.0f * ((float) M_PI)) * u2));
}
float code(float cosTheta_i, float u1, float u2) {
return cbrtf((powf(sinf((2.0f * (((float) M_PI) * u2))), 3.0f) * powf(-log1pf(-u1), 1.5f)));
}
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(-log(Float32(Float32(1.0) - u1)))) * sin(Float32(Float32(Float32(2.0) * Float32(pi)) * u2))) end
function code(cosTheta_i, u1, u2) return cbrt(Float32((sin(Float32(Float32(2.0) * Float32(Float32(pi) * u2))) ^ Float32(3.0)) * (Float32(-log1p(Float32(-u1))) ^ Float32(1.5)))) end
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\begin{array}{l}
\\
\sqrt[3]{{\sin \left(2 \cdot \left(\pi \cdot u2\right)\right)}^{3} \cdot {\left(-\mathsf{log1p}\left(-u1\right)\right)}^{1.5}}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 60.4%
Simplified98.4%
[Start]60.4% | \[ \sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\] |
|---|---|
sub-neg [=>]60.4% | \[ \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\] |
log1p-def [=>]98.4% | \[ \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\] |
associate-*l* [=>]98.4% | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)}
\] |
Applied egg-rr98.4%
[Start]98.4% | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)
\] |
|---|---|
log1p-expm1-u [=>]98.4% | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot u2\right)\right)}\right)
\] |
Applied egg-rr98.6%
[Start]98.4% | \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot u2\right)\right)\right)
\] |
|---|---|
*-commutative [=>]98.4% | \[ \color{blue}{\sin \left(2 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot u2\right)\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}}
\] |
log1p-expm1-u [<=]98.4% | \[ \sin \left(2 \cdot \color{blue}{\left(\pi \cdot u2\right)}\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}
\] |
add-cbrt-cube [=>]98.4% | \[ \color{blue}{\sqrt[3]{\left(\sin \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)\right) \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)}} \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}
\] |
add-cbrt-cube [=>]98.3% | \[ \sqrt[3]{\left(\sin \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)\right) \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)} \cdot \color{blue}{\sqrt[3]{\left(\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}}}
\] |
cbrt-unprod [=>]98.4% | \[ \color{blue}{\sqrt[3]{\left(\left(\sin \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)\right) \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)\right) \cdot \left(\left(\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right)}}
\] |
pow3 [=>]98.4% | \[ \sqrt[3]{\color{blue}{{\sin \left(2 \cdot \left(\pi \cdot u2\right)\right)}^{3}} \cdot \left(\left(\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right)}
\] |
Final simplification98.6%
| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 19520 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 19456 |
| Alternative 3 | |
|---|---|
| Accuracy | 94.2% |
| Cost | 13348 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.3% |
| Cost | 13220 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 13056 |
| Alternative 6 | |
|---|---|
| Accuracy | 83.6% |
| Cost | 9860 |
| Alternative 7 | |
|---|---|
| Accuracy | 74.0% |
| Cost | 6784 |
| Alternative 8 | |
|---|---|
| Accuracy | 66.0% |
| Cost | 6592 |
| Alternative 9 | |
|---|---|
| Accuracy | 7.1% |
| Cost | 32 |
herbie shell --seed 2023167
(FPCore (cosTheta_i u1 u2)
:name "Beckmann Sample, near normal, slope_y"
: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)))) (sin (* (* 2.0 PI) u2))))