Average Error: 12.6 → 0.5
Time: 7.3s
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}} \]
\[\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(cos2phi, {alphax}^{-2}, \frac{sin2phi}{alphay \cdot alphay}\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)))
  (fma cos2phi (pow alphax -2.0) (/ sin2phi (* alphay alphay)))))
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) / fmaf(cos2phi, powf(alphax, -2.0f), (sin2phi / (alphay * alphay)));
}
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(-log(Float32(Float32(1.0) - u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay))))
end
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(-log1p(Float32(-u0))) / fma(cos2phi, (alphax ^ Float32(-2.0)), Float32(sin2phi / Float32(alphay * alphay))))
end
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(cos2phi, {alphax}^{-2}, \frac{sin2phi}{alphay \cdot alphay}\right)}

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.6

    \[\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 egg-rr0.5

    \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\mathsf{fma}\left(cos2phi, {alphax}^{-2}, sin2phi \cdot {alphay}^{-2}\right)}} \]
  4. Taylor expanded in sin2phi around 0 0.5

    \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(cos2phi, {alphax}^{-2}, \color{blue}{\frac{sin2phi}{{alphay}^{2}}}\right)} \]
  5. Simplified0.5

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

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

Reproduce

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