Average Error: 13.8 → 0.3
Time: 18.8s
Precision: binary32
Cost: 51808
\[\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 \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
\[\begin{array}{l} t_0 := \sin \left(\pi \cdot u2\right)\\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \left(\sqrt[3]{\pi} \cdot \left(u2 \cdot {\left(\sqrt[3]{\pi}\right)}^{2}\right)\right), t_0, {t_0}^{2}\right)\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (sin (* PI u2))))
   (*
    (sqrt (- (log1p (- u1))))
    (+
     (cos (* PI (* u2 2.0)))
     (fma
      (- (sin (* (cbrt PI) (* u2 (pow (cbrt PI) 2.0)))))
      t_0
      (pow t_0 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) {
	float t_0 = sinf((((float) M_PI) * u2));
	return sqrtf(-log1pf(-u1)) * (cosf((((float) M_PI) * (u2 * 2.0f))) + fmaf(-sinf((cbrtf(((float) M_PI)) * (u2 * powf(cbrtf(((float) M_PI)), 2.0f)))), t_0, powf(t_0, 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)
	t_0 = sin(Float32(Float32(pi) * u2))
	return Float32(sqrt(Float32(-log1p(Float32(-u1)))) * Float32(cos(Float32(Float32(pi) * Float32(u2 * Float32(2.0)))) + fma(Float32(-sin(Float32(cbrt(Float32(pi)) * Float32(u2 * (cbrt(Float32(pi)) ^ Float32(2.0)))))), t_0, (t_0 ^ Float32(2.0)))))
end
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\begin{array}{l}
t_0 := \sin \left(\pi \cdot u2\right)\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \left(\sqrt[3]{\pi} \cdot \left(u2 \cdot {\left(\sqrt[3]{\pi}\right)}^{2}\right)\right), t_0, {t_0}^{2}\right)\right)
\end{array}

Error

Derivation

  1. Initial program 13.8

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Simplified0.3

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
    Proof
    (*.f32 (sqrt.f32 (neg.f32 (log1p.f32 (neg.f32 u1)))) (cos.f32 (*.f32 2 (*.f32 (PI.f32) u2)))): 0 points increase in error, 0 points decrease in error
    (*.f32 (sqrt.f32 (neg.f32 (Rewrite<= log1p-def_binary32 (log.f32 (+.f32 1 (neg.f32 u1)))))) (cos.f32 (*.f32 2 (*.f32 (PI.f32) u2)))): 226 points increase in error, 4 points decrease in error
    (*.f32 (sqrt.f32 (neg.f32 (log.f32 (Rewrite<= sub-neg_binary32 (-.f32 1 u1))))) (cos.f32 (*.f32 2 (*.f32 (PI.f32) u2)))): 0 points increase in error, 0 points decrease in error
    (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 1 u1)))) (cos.f32 (Rewrite<= associate-*l*_binary32 (*.f32 (*.f32 2 (PI.f32)) u2)))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.3

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), {\sin \left(\pi \cdot u2\right)}^{2}\right)\right)} \]
  4. Applied egg-rr0.3

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \color{blue}{\left({\left(\sqrt{\pi \cdot u2}\right)}^{2}\right)}, \sin \left(\pi \cdot u2\right), {\sin \left(\pi \cdot u2\right)}^{2}\right)\right) \]
  5. Applied egg-rr0.3

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \color{blue}{\left(\left(u2 \cdot {\left(\sqrt[3]{\pi}\right)}^{2}\right) \cdot \sqrt[3]{\pi}\right)}, \sin \left(\pi \cdot u2\right), {\sin \left(\pi \cdot u2\right)}^{2}\right)\right) \]
  6. Final simplification0.3

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \left(\sqrt[3]{\pi} \cdot \left(u2 \cdot {\left(\sqrt[3]{\pi}\right)}^{2}\right)\right), \sin \left(\pi \cdot u2\right), {\sin \left(\pi \cdot u2\right)}^{2}\right)\right) \]

Alternatives

Alternative 1
Error0.3
Cost48768
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \left(\sqrt[3]{\pi} \cdot \left(u2 \cdot {\left(\sqrt[3]{\pi}\right)}^{2}\right)\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right)\right)\right) \]
Alternative 2
Error0.3
Cost45376
\[\begin{array}{l} t_0 := \sin \left(\pi \cdot u2\right)\\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-\sin \left({\left(\sqrt{\pi \cdot u2}\right)}^{2}\right), t_0, {t_0}^{2}\right)\right) \end{array} \]
Alternative 3
Error0.3
Cost38944
\[\begin{array}{l} t_0 := \sin \left(\pi \cdot u2\right)\\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\cos \left(\pi \cdot \left(u2 \cdot 2\right)\right) + \mathsf{fma}\left(-t_0, t_0, {t_0}^{2}\right)\right) \end{array} \]
Alternative 4
Error3.0
Cost16356
\[\begin{array}{l} t_0 := \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right)\\ \mathbf{if}\;t_0 \leq 0.9999499917030334:\\ \;\;\;\;t_0 \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
Alternative 5
Error1.2
Cost13476
\[\begin{array}{l} t_0 := u2 \cdot \left(\pi \cdot 2\right)\\ \mathbf{if}\;t_0 \leq 0.0016299999551847577:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(u1 \cdot -0.3333333333333333 + -0.5\right)} \cdot \cos t_0\\ \end{array} \]
Alternative 6
Error0.3
Cost13056
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \]
Alternative 7
Error6.5
Cost6496
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \]
Alternative 8
Error11.2
Cost3232
\[\sqrt{u1} \]

Error

Reproduce

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