Average Error: 13.4 → 0.5
Time: 25.3s
Precision: binary32
\[\left(\left(2.328306437 \cdot 10^{-10} \leq ux \land ux \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq uy \land uy \leq 1\right)\right) \land \left(0 \leq maxCos \land maxCos \leq 1\right)\]
\[\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)} \]
\[\sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\right) \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(2 + maxCos \cdot ux\right)\right)\right)}^{1.5}} \]
\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)}
\sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\right) \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(2 + maxCos \cdot ux\right)\right)\right)}^{1.5}}
(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
 (cbrt
  (*
   (*
    (log1p (expm1 (pow (sin (* 2.0 (* uy PI))) 2.0)))
    (sin (* PI (* 2.0 uy))))
   (pow
    (-
     (* 2.0 (fma maxCos (* ux ux) ux))
     (fma ux ux (* (* maxCos ux) (+ 2.0 (* maxCos ux)))))
    1.5))))
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 cbrtf((log1pf(expm1f(powf(sinf(2.0f * (uy * ((float) M_PI))), 2.0f))) * sinf(((float) M_PI) * (2.0f * uy))) * powf(((2.0f * fmaf(maxCos, (ux * ux), ux)) - fmaf(ux, ux, ((maxCos * ux) * (2.0f + (maxCos * ux))))), 1.5f));
}

Error

Bits error versus ux

Bits error versus uy

Bits error versus maxCos

Derivation

  1. Initial program 13.4

    \[\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)} \]
  2. Taylor expanded in ux around 0 0.5

    \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{\left(2 \cdot \left(maxCos \cdot {ux}^{2}\right) + 2 \cdot ux\right) - \left({ux}^{2} + \left({maxCos}^{2} \cdot {ux}^{2} + 2 \cdot \left(maxCos \cdot ux\right)\right)\right)}} \]
  3. Simplified0.5

    \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}} \]
  4. Applied add-cbrt-cube_binary320.5

    \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \color{blue}{\sqrt[3]{\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right) \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}}} \]
  5. Applied add-cbrt-cube_binary320.5

    \[\leadsto \color{blue}{\sqrt[3]{\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)}} \cdot \sqrt[3]{\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right) \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}} \]
  6. Applied cbrt-unprod_binary320.6

    \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right) \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right)}} \]
  7. Applied log1p-expm1-u_binary320.6

    \[\leadsto \sqrt[3]{\left(\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right)\right)} \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right) \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right)} \]
  8. Simplified0.6

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)}\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right) \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right)} \]
  9. Applied pow1_binary320.6

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right) \cdot \sqrt{\color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{1}}}\right)} \]
  10. Applied sqrt-pow1_binary320.6

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)}\right) \cdot \color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}}\right)} \]
  11. Applied pow1_binary320.6

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \sqrt{\color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{1}}}\right) \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}\right)} \]
  12. Applied sqrt-pow1_binary320.6

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)} \cdot \color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}}\right) \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}\right)} \]
  13. Applied pow1_binary320.6

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\sqrt{\color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{1}}} \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}\right) \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}\right)} \]
  14. Applied sqrt-pow1_binary320.6

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\left(\color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}} \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}\right) \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}\right)} \]
  15. Applied pow-sqr_binary320.5

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \left(\color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(2 \cdot \frac{1}{2}\right)}} \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(\frac{1}{2}\right)}\right)} \]
  16. Applied pow-prod-up_binary320.5

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot \color{blue}{{\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux + 2\right)\right)\right)}^{\left(2 \cdot \frac{1}{2} + \frac{1}{2}\right)}}} \]
  17. Final simplification0.5

    \[\leadsto \sqrt[3]{\left(\mathsf{log1p}\left(\mathsf{expm1}\left({\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{2}\right)\right) \cdot \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\right) \cdot {\left(2 \cdot \mathsf{fma}\left(maxCos, ux \cdot ux, ux\right) - \mathsf{fma}\left(ux, ux, \left(maxCos \cdot ux\right) \cdot \left(2 + maxCos \cdot ux\right)\right)\right)}^{1.5}} \]

Reproduce

herbie shell --seed 2022004 
(FPCore (ux uy maxCos)
  :name "UniformSampleCone, y"
  :precision binary32
  :pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
  (* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))