Average Error: 12.5 → 0.5
Time: 13.8s
Precision: binary32
\[\left(\left(\left(\left(0.0001 \leq alphax \land alphax \leq 1\right) \land \left(0.0001 \leq alphay \land alphay \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\right) \land \left(0 \leq cos2phi \land cos2phi \leq 1\right)\right) \land 0 \leq sin2phi\]
\[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
\[\left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)}{\mathsf{fma}\left(sin2phi, alphax \cdot alphax, \left(alphay \cdot alphay\right) \cdot cos2phi\right)} \]
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)}{\mathsf{fma}\left(sin2phi, alphax \cdot alphax, \left(alphay \cdot alphay\right) \cdot cos2phi\right)}
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/
  (- (log (- 1.0 u0)))
  (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (*
  (- (log1p (- u0)))
  (/
   (* (* alphax alphax) (* alphay alphay))
   (fma sin2phi (* alphax alphax) (* (* alphay alphay) cos2phi)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -logf(1.0f - u0) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -log1pf(-u0) * (((alphax * alphax) * (alphay * alphay)) / fmaf(sin2phi, (alphax * alphax), ((alphay * alphay) * cos2phi)));
}

Error

Bits error versus alphax

Bits error versus alphay

Bits error versus u0

Bits error versus cos2phi

Bits error versus sin2phi

Derivation

  1. Initial program 12.5

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Simplified0.5

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]
  3. Applied frac-add_binary320.6

    \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\frac{cos2phi \cdot \left(alphay \cdot alphay\right) + \left(alphax \cdot alphax\right) \cdot sin2phi}{\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)}}} \]
  4. Applied associate-/r/_binary320.5

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{cos2phi \cdot \left(alphay \cdot alphay\right) + \left(alphax \cdot alphax\right) \cdot sin2phi} \cdot \left(\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)\right)} \]
  5. Applied div-inv_binary320.6

    \[\leadsto \color{blue}{\left(\left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{1}{cos2phi \cdot \left(alphay \cdot alphay\right) + \left(alphax \cdot alphax\right) \cdot sin2phi}\right)} \cdot \left(\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)\right) \]
  6. Applied associate-*l*_binary320.6

    \[\leadsto \color{blue}{\left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \left(\frac{1}{cos2phi \cdot \left(alphay \cdot alphay\right) + \left(alphax \cdot alphax\right) \cdot sin2phi} \cdot \left(\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)\right)\right)} \]
  7. Simplified0.5

    \[\leadsto \left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \color{blue}{\frac{\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)}{\mathsf{fma}\left(sin2phi, alphax \cdot alphax, cos2phi \cdot \left(alphay \cdot alphay\right)\right)}} \]
  8. Final simplification0.5

    \[\leadsto \left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)}{\mathsf{fma}\left(sin2phi, alphax \cdot alphax, \left(alphay \cdot alphay\right) \cdot cos2phi\right)} \]

Reproduce

herbie shell --seed 2021280 
(FPCore (alphax alphay u0 cos2phi sin2phi)
  :name "Beckmann Distribution sample, tan2theta, alphax != alphay, u1 <= 0.5"
  :precision binary32
  :pre (and (and (and (and (and (<= 0.0001 alphax) (<= alphax 1.0)) (and (<= 0.0001 alphay) (<= alphay 1.0))) (and (<= 2.328306437e-10 u0) (<= u0 1.0))) (and (<= 0.0 cos2phi) (<= cos2phi 1.0))) (<= 0.0 sin2phi))
  (/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))