Average Error: 12.7 → 0.6
Time: 29.0s
Precision: binary32
\[0.0001 \leq alphax \land alphax \leq 1 \land 0.0001 \leq alphay \land alphay \leq 1 \land 2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1 \land 0 \leq cos2phi \land cos2phi \leq 1 \land 0 \leq sin2phi\]
\[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\]
\[\begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9537093043327332:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(alphay \cdot alphay\right) \cdot cos2phi + sin2phi \cdot \left(alphax \cdot alphax\right)} \cdot \left(\left(alphay \cdot alphay\right) \cdot \left(alphax \cdot alphax\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{u0}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}} + \left(\left(0.5 \cdot \left(\left(u0 \cdot u0\right) \cdot \frac{1}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.3333333333333333 \cdot \frac{{u0}^{3}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.25 \cdot \frac{{u0}^{4}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right)\\ \end{array}\]
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\begin{array}{l}
\mathbf{if}\;1 - u0 \leq 0.9537093043327332:\\
\;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(alphay \cdot alphay\right) \cdot cos2phi + sin2phi \cdot \left(alphax \cdot alphax\right)} \cdot \left(\left(alphay \cdot alphay\right) \cdot \left(alphax \cdot alphax\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{u0}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}} + \left(\left(0.5 \cdot \left(\left(u0 \cdot u0\right) \cdot \frac{1}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.3333333333333333 \cdot \frac{{u0}^{3}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.25 \cdot \frac{{u0}^{4}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right)\\

\end{array}
(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
 (if (<= (- 1.0 u0) 0.9537093043327332)
   (*
    (/
     (- (log (- 1.0 u0)))
     (+ (* (* alphay alphay) cos2phi) (* sin2phi (* alphax alphax))))
    (* (* alphay alphay) (* alphax alphax)))
   (+
    (/ u0 (+ (/ sin2phi (* alphay alphay)) (/ cos2phi (* alphax alphax))))
    (+
     (+
      (*
       0.5
       (*
        (* u0 u0)
        (/
         1.0
         (+ (/ sin2phi (* alphay alphay)) (/ cos2phi (* alphax alphax))))))
      (*
       0.3333333333333333
       (/
        (pow u0 3.0)
        (+ (/ sin2phi (* alphay alphay)) (/ cos2phi (* alphax alphax))))))
     (*
      0.25
      (/
       (pow u0 4.0)
       (+ (/ sin2phi (* alphay alphay)) (/ cos2phi (* alphax alphax)))))))))
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) {
	float tmp;
	if ((1.0f - u0) <= 0.9537093043327332f) {
		tmp = (-logf(1.0f - u0) / (((alphay * alphay) * cos2phi) + (sin2phi * (alphax * alphax)))) * ((alphay * alphay) * (alphax * alphax));
	} else {
		tmp = (u0 / ((sin2phi / (alphay * alphay)) + (cos2phi / (alphax * alphax)))) + (((0.5f * ((u0 * u0) * (1.0f / ((sin2phi / (alphay * alphay)) + (cos2phi / (alphax * alphax)))))) + (0.3333333333333333f * (powf(u0, 3.0f) / ((sin2phi / (alphay * alphay)) + (cos2phi / (alphax * alphax)))))) + (0.25f * (powf(u0, 4.0f) / ((sin2phi / (alphay * alphay)) + (cos2phi / (alphax * alphax))))));
	}
	return tmp;
}

Error

Bits error versus alphax

Bits error versus alphay

Bits error versus u0

Bits error versus cos2phi

Bits error versus sin2phi

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (-.f32 1 u0) < 0.953709304

    1. Initial program 1.7

      \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\]
    2. Using strategy rm
    3. Applied frac-add_binary321.7

      \[\leadsto \frac{-\log \left(1 - 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/_binary321.1

      \[\leadsto \color{blue}{\frac{-\log \left(1 - 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. Simplified1.1

      \[\leadsto \color{blue}{\frac{-\log \left(1 - u0\right)}{\left(alphay \cdot alphay\right) \cdot cos2phi + sin2phi \cdot \left(alphax \cdot alphax\right)}} \cdot \left(\left(alphax \cdot alphax\right) \cdot \left(alphay \cdot alphay\right)\right)\]

    if 0.953709304 < (-.f32 1 u0)

    1. Initial program 14.5

      \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\]
    2. Taylor expanded around 0 0.5

      \[\leadsto \color{blue}{\frac{u0}{\frac{sin2phi}{{alphay}^{2}} + \frac{cos2phi}{{alphax}^{2}}} + \left(0.25 \cdot \frac{{u0}^{4}}{\frac{sin2phi}{{alphay}^{2}} + \frac{cos2phi}{{alphax}^{2}}} + \left(0.3333333333333333 \cdot \frac{{u0}^{3}}{\frac{sin2phi}{{alphay}^{2}} + \frac{cos2phi}{{alphax}^{2}}} + 0.5 \cdot \frac{{u0}^{2}}{\frac{sin2phi}{{alphay}^{2}} + \frac{cos2phi}{{alphax}^{2}}}\right)\right)}\]
    3. Simplified0.5

      \[\leadsto \color{blue}{\frac{u0}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}} + \left(\left(0.5 \cdot \frac{u0 \cdot u0}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}} + 0.3333333333333333 \cdot \frac{{u0}^{3}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.25 \cdot \frac{{u0}^{4}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right)}\]
    4. Using strategy rm
    5. Applied div-inv_binary320.5

      \[\leadsto \frac{u0}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}} + \left(\left(0.5 \cdot \color{blue}{\left(\left(u0 \cdot u0\right) \cdot \frac{1}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right)} + 0.3333333333333333 \cdot \frac{{u0}^{3}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.25 \cdot \frac{{u0}^{4}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9537093043327332:\\ \;\;\;\;\frac{-\log \left(1 - u0\right)}{\left(alphay \cdot alphay\right) \cdot cos2phi + sin2phi \cdot \left(alphax \cdot alphax\right)} \cdot \left(\left(alphay \cdot alphay\right) \cdot \left(alphax \cdot alphax\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{u0}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}} + \left(\left(0.5 \cdot \left(\left(u0 \cdot u0\right) \cdot \frac{1}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.3333333333333333 \cdot \frac{{u0}^{3}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right) + 0.25 \cdot \frac{{u0}^{4}}{\frac{sin2phi}{alphay \cdot alphay} + \frac{cos2phi}{alphax \cdot alphax}}\right)\\ \end{array}\]

Reproduce

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