Average Error: 12.7 → 0.6
Time: 15.3s
Precision: binary32
Cost: 7072
\[\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(alphax \cdot \left(alphay \cdot \left(alphax \cdot alphay\right)\right)\right) \cdot \frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(cos2phi, alphay \cdot alphay, alphax \cdot \left(alphax \cdot sin2phi\right)\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
 (*
  (* alphax (* alphay (* alphax alphay)))
  (/
   (- (log1p (- u0)))
   (fma cos2phi (* alphay alphay) (* alphax (* alphax sin2phi))))))
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 (alphax * (alphay * (alphax * alphay))) * (-log1pf(-u0) / fmaf(cos2phi, (alphay * alphay), (alphax * (alphax * sin2phi))));
}
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(alphax * Float32(alphay * Float32(alphax * alphay))) * Float32(Float32(-log1p(Float32(-u0))) / fma(cos2phi, Float32(alphay * alphay), Float32(alphax * Float32(alphax * sin2phi)))))
end
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\left(alphax \cdot \left(alphay \cdot \left(alphax \cdot alphay\right)\right)\right) \cdot \frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(cos2phi, alphay \cdot alphay, alphax \cdot \left(alphax \cdot sin2phi\right)\right)}

Error

Derivation

  1. Initial program 12.7

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Applied egg-rr0.7

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

    \[\leadsto \color{blue}{{\left(alphax \cdot alphay\right)}^{2} \cdot \frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(cos2phi, alphay \cdot alphay, alphax \cdot \left(alphax \cdot sin2phi\right)\right)}} \]
    Proof
    (*.f32 (pow.f32 (*.f32 alphax alphay) 2) (/.f32 (neg.f32 (log1p.f32 (neg.f32 u0))) (fma.f32 cos2phi (*.f32 alphay alphay) (*.f32 alphax (*.f32 alphax sin2phi))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (pow.f32 (*.f32 alphax alphay) 2) (/.f32 (Rewrite<= mul-1-neg_binary32 (*.f32 -1 (log1p.f32 (neg.f32 u0)))) (fma.f32 cos2phi (*.f32 alphay alphay) (*.f32 alphax (*.f32 alphax sin2phi))))): 0 points increase in error, 5 points decrease in error
    (*.f32 (pow.f32 (*.f32 alphax alphay) 2) (Rewrite<= associate-*l/_binary32 (*.f32 (/.f32 -1 (fma.f32 cos2phi (*.f32 alphay alphay) (*.f32 alphax (*.f32 alphax sin2phi)))) (log1p.f32 (neg.f32 u0))))): 5 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary32 (*.f32 (*.f32 (/.f32 -1 (fma.f32 cos2phi (*.f32 alphay alphay) (*.f32 alphax (*.f32 alphax sin2phi)))) (log1p.f32 (neg.f32 u0))) (pow.f32 (*.f32 alphax alphay) 2))): 0 points increase in error, 5 points decrease in error
    (Rewrite<= associate-*r*_binary32 (*.f32 (/.f32 -1 (fma.f32 cos2phi (*.f32 alphay alphay) (*.f32 alphax (*.f32 alphax sin2phi)))) (*.f32 (log1p.f32 (neg.f32 u0)) (pow.f32 (*.f32 alphax alphay) 2)))): 5 points increase in error, 0 points decrease in error
  4. Applied egg-rr0.6

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

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

Alternatives

Alternative 1
Error0.6
Cost7072
\[\frac{\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(cos2phi, alphay \cdot alphay, alphax \cdot \left(alphax \cdot sin2phi\right)\right)} \cdot \left(alphay \cdot \left(alphay \cdot \left(alphax \cdot \left(-alphax\right)\right)\right)\right) \]
Alternative 2
Error0.5
Cost3680
\[\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
Alternative 3
Error2.3
Cost3556
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 3.9999998989515007 \cdot 10^{-5}:\\ \;\;\;\;\frac{u0 + \left(u0 \cdot u0\right) \cdot 0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(-u0\right) \cdot \frac{alphay \cdot \left(-alphay\right)}{sin2phi}\\ \end{array} \]
Alternative 4
Error3.9
Cost1440
\[\begin{array}{l} t_0 := alphax \cdot \left(sin2phi \cdot \frac{-alphax}{alphay}\right) - alphay \cdot cos2phi\\ \frac{\left(u0 \cdot u0\right) \cdot \left(alphax \cdot \left(\left(alphax \cdot alphay\right) \cdot -0.5\right)\right)}{t_0} - \left(alphay \cdot \left(alphax \cdot alphax\right)\right) \cdot \frac{u0}{t_0} \end{array} \]
Alternative 5
Error5.3
Cost644
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.999999901276418 \cdot 10^{-11}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{\left(sin2phi \cdot 0.5 - \frac{sin2phi}{u0}\right) + u0 \cdot \left(sin2phi \cdot 0.08333333333333333\right)}\\ \end{array} \]
Alternative 6
Error3.9
Cost608
\[\frac{u0 + \left(u0 \cdot u0\right) \cdot 0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
Alternative 7
Error8.1
Cost580
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 2.20000002915631 \cdot 10^{-13}:\\ \;\;\;\;\frac{alphax \cdot \left(alphax \cdot u0\right)}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{sin2phi \cdot 0.5 - \frac{sin2phi}{u0}}\\ \end{array} \]
Alternative 8
Error5.9
Cost548
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.999999901276418 \cdot 10^{-11}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{sin2phi \cdot 0.5 - \frac{sin2phi}{u0}}\\ \end{array} \]
Alternative 9
Error5.9
Cost484
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.999999901276418 \cdot 10^{-11}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{sin2phi \cdot 0.5 - \frac{sin2phi}{u0}}\\ \end{array} \]
Alternative 10
Error10.5
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;\frac{alphax}{\frac{\frac{cos2phi}{u0}}{alphax}}\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 11
Error10.5
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;\frac{alphax \cdot \left(alphax \cdot u0\right)}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 12
Error10.5
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;\frac{alphax \cdot \left(alphax \cdot u0\right)}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(alphay \cdot u0\right)}{sin2phi}\\ \end{array} \]
Alternative 13
Error10.5
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 1.9999999920083944 \cdot 10^{-12}:\\ \;\;\;\;\frac{alphax \cdot \left(alphax \cdot u0\right)}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;\frac{u0 \cdot \left(alphay \cdot alphay\right)}{sin2phi}\\ \end{array} \]
Alternative 14
Error10.6
Cost292
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.000000033724767 \cdot 10^{-16}:\\ \;\;\;\;u0 \cdot \left(alphax \cdot \frac{alphax}{cos2phi}\right)\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \left(alphay \cdot \frac{alphay}{sin2phi}\right)\\ \end{array} \]
Alternative 15
Error10.6
Cost292
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.000000033724767 \cdot 10^{-16}:\\ \;\;\;\;u0 \cdot \left(alphax \cdot \frac{alphax}{cos2phi}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\ \end{array} \]
Alternative 16
Error10.6
Cost292
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.000000033724767 \cdot 10^{-16}:\\ \;\;\;\;u0 \cdot \frac{alphax \cdot alphax}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\ \end{array} \]
Alternative 17
Error10.6
Cost292
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.000000033724767 \cdot 10^{-16}:\\ \;\;\;\;u0 \cdot \frac{alphax \cdot alphax}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 18
Error13.1
Cost224
\[u0 \cdot \left(alphay \cdot \frac{alphay}{sin2phi}\right) \]

Error

Reproduce

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