\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}
\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux - ux \cdot maxCos\right) \cdot \log \left(e \cdot \left(\frac{e}{e^{ux}} \cdot e^{ux \cdot maxCos}\right)\right)}
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* (* uy 2.0) PI))
(sqrt
(*
(- ux (* ux maxCos))
(log (* E (* (/ E (exp ux)) (exp (* ux maxCos)))))))))float code(float ux, float uy, float maxCos) {
return sinf((uy * 2.0f) * ((float) M_PI)) * sqrtf(1.0f - (((1.0f - ux) + (ux * maxCos)) * ((1.0f - ux) + (ux * maxCos))));
}
float code(float ux, float uy, float maxCos) {
return sinf((uy * 2.0f) * ((float) M_PI)) * sqrtf((ux - (ux * maxCos)) * logf(((float) M_E) * ((((float) M_E) / expf(ux)) * expf(ux * maxCos))));
}



Bits error versus ux



Bits error versus uy



Bits error versus maxCos
Results
Initial program 13.5
Simplified0.5
rmApplied add-log-exp_binary320.5
Applied add-log-exp_binary320.5
Applied add-log-exp_binary320.5
Applied add-log-exp_binary320.5
Applied diff-log_binary320.5
Applied sum-log_binary320.5
Applied sum-log_binary320.5
Final simplification0.5
herbie shell --seed 2021204
(FPCore (ux uy maxCos)
:name "UniformSampleCone, y"
:precision binary32
:pre (and (<= 2.328306437e-10 ux 1.0) (<= 2.328306437e-10 uy 1.0) (<= 0.0 maxCos 1.0))
(* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))