?

Average Accuracy: 57.9% → 98.4%
Time: 16.1s
Precision: binary32
Cost: 19456

?

\[\left(\left(cosTheta_i > 0.9999 \land cosTheta_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot u2\right)\right)\right) \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log1p (- u1)))) (sin (* 2.0 (log1p (expm1 (* PI u2)))))))
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 sqrtf(-log1pf(-u1)) * sinf((2.0f * log1pf(expm1f((((float) M_PI) * u2)))));
}
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 Float32(sqrt(Float32(-log1p(Float32(-u1)))) * sin(Float32(Float32(2.0) * log1p(expm1(Float32(Float32(pi) * u2))))))
end
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot u2\right)\right)\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 55.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Simplified98.4%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
    Step-by-step derivation

    [Start]55.9

    \[ \sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    sub-neg [=>]55.9

    \[ \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)} \]
  3. Applied egg-rr98.4%

    \[\leadsto \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) \]
    Step-by-step derivation

    [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) \]
  4. Final simplification98.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot u2\right)\right)\right) \]

Alternatives

Alternative 1
Accuracy90.5%
Cost13220
\[\begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.017000000923871994:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\sin t_0 \cdot \sqrt{u1}\\ \end{array} \]
Alternative 2
Accuracy85.9%
Cost13156
\[\begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.017000000923871994:\\ \;\;\;\;t_0 \cdot \sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 + u1 \cdot -0.3333333333333333\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin t_0 \cdot \sqrt{u1}\\ \end{array} \]
Alternative 3
Accuracy98.4%
Cost13056
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \left(\pi \cdot u2\right)\right) \]
Alternative 4
Accuracy77.0%
Cost6912
\[\left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 + u1 \cdot -0.3333333333333333\right)} \]
Alternative 5
Accuracy74.3%
Cost6784
\[\left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)} \]
Alternative 6
Accuracy66.4%
Cost6656
\[2 \cdot \left(\pi \cdot \sqrt{u1 \cdot \left(u2 \cdot u2\right)}\right) \]
Alternative 7
Accuracy4.6%
Cost6592
\[\left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right) \cdot -2 \]
Alternative 8
Accuracy66.3%
Cost6592
\[2 \cdot \left(\pi \cdot \left(u2 \cdot \sqrt{u1}\right)\right) \]
Alternative 9
Accuracy66.4%
Cost6592
\[\left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1} \]

Error

Reproduce?

herbie shell --seed 2023159 
(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))))