Average Error: 12.7 → 0.5
Time: 12.9s
Precision: binary32
Cost: 3680
\[\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)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
(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)))
  (+ (/ cos2phi (* alphax alphax)) (/ 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) / ((cos2phi / (alphax * alphax)) + (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))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + 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)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 12.7

    \[\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}}} \]
    Proof
    (/.f32 (neg.f32 (log1p.f32 (neg.f32 u0))) (+.f32 (/.f32 cos2phi (*.f32 alphax alphax)) (/.f32 sin2phi (*.f32 alphay alphay)))): 0 points increase in error, 0 points decrease in error
    (/.f32 (neg.f32 (Rewrite<= log1p-def_binary32 (log.f32 (+.f32 1 (neg.f32 u0))))) (+.f32 (/.f32 cos2phi (*.f32 alphax alphax)) (/.f32 sin2phi (*.f32 alphay alphay)))): 222 points increase in error, 1 points decrease in error
    (/.f32 (neg.f32 (log.f32 (Rewrite<= sub-neg_binary32 (-.f32 1 u0)))) (+.f32 (/.f32 cos2phi (*.f32 alphax alphax)) (/.f32 sin2phi (*.f32 alphay alphay)))): 0 points increase in error, 0 points decrease in error
    (/.f32 (Rewrite<= *-rgt-identity_binary32 (*.f32 (neg.f32 (log.f32 (-.f32 1 u0))) 1)) (+.f32 (/.f32 cos2phi (*.f32 alphax alphax)) (/.f32 sin2phi (*.f32 alphay alphay)))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-/l*_binary32 (/.f32 (neg.f32 (log.f32 (-.f32 1 u0))) (/.f32 (+.f32 (/.f32 cos2phi (*.f32 alphax alphax)) (/.f32 sin2phi (*.f32 alphay alphay))) 1))): 0 points increase in error, 0 points decrease in error
    (/.f32 (neg.f32 (log.f32 (-.f32 1 u0))) (Rewrite=> /-rgt-identity_binary32 (+.f32 (/.f32 cos2phi (*.f32 alphax alphax)) (/.f32 sin2phi (*.f32 alphay alphay))))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.5

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

Alternatives

Alternative 1
Error2.4
Cost3684
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 1.2000000424450263 \cdot 10^{-5}:\\ \;\;\;\;\frac{u0 + u0 \cdot \left(u0 \cdot 0.5\right)}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 2
Error5.2
Cost772
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 6.000000212225132 \cdot 10^{-7}:\\ \;\;\;\;\frac{u0}{t_0 + \frac{cos2phi}{alphax} \cdot \frac{1}{alphax}}\\ \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 3
Error5.8
Cost676
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 1.2000000424450263 \cdot 10^{-5}:\\ \;\;\;\;\frac{u0}{t_0 + \frac{cos2phi}{alphax} \cdot \frac{1}{alphax}}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{sin2phi \cdot 0.5 - \frac{sin2phi}{u0}}\\ \end{array} \]
Alternative 4
Error5.8
Cost612
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 1.2000000424450263 \cdot 10^{-5}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{sin2phi \cdot 0.5 - \frac{sin2phi}{u0}}\\ \end{array} \]
Alternative 5
Error3.9
Cost608
\[\frac{u0 + u0 \cdot \left(u0 \cdot 0.5\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
Alternative 6
Error8.0
Cost580
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 3.500000025931118 \cdot 10^{-17}:\\ \;\;\;\;\left(alphax \cdot alphax\right) \cdot \left(u0 \cdot \frac{1}{cos2phi}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{sin2phi \cdot 0.5 - \frac{sin2phi}{u0}}\\ \end{array} \]
Alternative 7
Error10.5
Cost484
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 3.500000025931118 \cdot 10^{-17}:\\ \;\;\;\;\left(alphax \cdot alphax\right) \cdot \left(u0 \cdot \frac{1}{cos2phi}\right)\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 8
Error10.5
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 3.500000025931118 \cdot 10^{-17}:\\ \;\;\;\;\left(alphax \cdot alphax\right) \cdot \frac{u0}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 9
Error10.5
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 3.500000025931118 \cdot 10^{-17}:\\ \;\;\;\;\frac{u0 \cdot alphax}{\frac{cos2phi}{alphax}}\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 10
Error10.5
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 3.500000025931118 \cdot 10^{-17}:\\ \;\;\;\;alphax \cdot \frac{u0}{\frac{cos2phi}{alphax}}\\ \mathbf{else}:\\ \;\;\;\;u0 \cdot \frac{alphay \cdot alphay}{sin2phi}\\ \end{array} \]
Alternative 11
Error10.5
Cost292
\[\begin{array}{l} \mathbf{if}\;sin2phi \leq 2.5000001145342624 \cdot 10^{-19}:\\ \;\;\;\;\left(alphax \cdot alphax\right) \cdot \frac{u0}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\ \end{array} \]
Alternative 12
Error24.4
Cost224
\[alphax \cdot \frac{alphax}{\frac{cos2phi}{u0}} \]
Alternative 13
Error24.4
Cost224
\[u0 \cdot \left(alphax \cdot \frac{alphax}{cos2phi}\right) \]
Alternative 14
Error24.4
Cost224
\[\left(alphax \cdot alphax\right) \cdot \frac{u0}{cos2phi} \]

Error

Reproduce

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