
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (- (log (- 1.0 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)));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = -log((1.0e0 - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
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 tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = -log((single(1.0) - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (- (log (- 1.0 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)));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = -log((1.0e0 - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
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 tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = -log((single(1.0) - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (* (* alphax alphay) (/ (log1p (- u0)) (- (* sin2phi (/ (- alphax) alphay)) (* (/ alphay alphax) cos2phi)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (alphax * alphay) * (log1pf(-u0) / ((sin2phi * (-alphax / alphay)) - ((alphay / alphax) * cos2phi)));
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(alphax * alphay) * Float32(log1p(Float32(-u0)) / Float32(Float32(sin2phi * Float32(Float32(-alphax) / alphay)) - Float32(Float32(alphay / alphax) * cos2phi)))) end
\begin{array}{l}
\\
\left(alphax \cdot alphay\right) \cdot \frac{\mathsf{log1p}\left(-u0\right)}{sin2phi \cdot \frac{-alphax}{alphay} - \frac{alphay}{alphax} \cdot cos2phi}
\end{array}
Initial program 62.1%
sub-neg62.1%
log1p-def98.7%
Simplified98.7%
associate-/r*98.5%
associate-/r*98.5%
frac-2neg98.5%
frac-add98.4%
distribute-neg-frac98.4%
Applied egg-rr98.4%
+-commutative98.4%
*-commutative98.4%
distribute-lft-neg-out98.4%
unsub-neg98.4%
associate-*r/98.5%
associate-/l*98.4%
associate-*r/98.4%
associate-/l*98.5%
Simplified98.5%
associate-/r/98.7%
associate-/r/98.7%
associate-/r/98.7%
Applied egg-rr98.7%
Final simplification98.7%
(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 -log1pf(-u0) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
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
\begin{array}{l}
\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 62.1%
sub-neg62.1%
log1p-def98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* alphax (* u0 (- alphay))) (- (/ (- alphax) (/ alphay sin2phi)) (* (/ alphay alphax) cos2phi))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (alphax * (u0 * -alphay)) / ((-alphax / (alphay / sin2phi)) - ((alphay / alphax) * cos2phi));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = (alphax * (u0 * -alphay)) / ((-alphax / (alphay / sin2phi)) - ((alphay / alphax) * cos2phi))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(alphax * Float32(u0 * Float32(-alphay))) / Float32(Float32(Float32(-alphax) / Float32(alphay / sin2phi)) - Float32(Float32(alphay / alphax) * cos2phi))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (alphax * (u0 * -alphay)) / ((-alphax / (alphay / sin2phi)) - ((alphay / alphax) * cos2phi)); end
\begin{array}{l}
\\
\frac{alphax \cdot \left(u0 \cdot \left(-alphay\right)\right)}{\frac{-alphax}{\frac{alphay}{sin2phi}} - \frac{alphay}{alphax} \cdot cos2phi}
\end{array}
Initial program 62.1%
sub-neg62.1%
log1p-def98.7%
Simplified98.7%
associate-/r*98.5%
associate-/r*98.5%
frac-2neg98.5%
frac-add98.4%
distribute-neg-frac98.4%
Applied egg-rr98.4%
+-commutative98.4%
*-commutative98.4%
distribute-lft-neg-out98.4%
unsub-neg98.4%
associate-*r/98.5%
associate-/l*98.4%
associate-*r/98.4%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in u0 around 0 75.0%
mul-1-neg75.0%
mul-1-neg75.0%
associate-/l*75.0%
associate-*l/75.0%
*-commutative75.0%
Simplified75.0%
Final simplification75.0%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* alphax (* u0 (- alphay))) (- (/ (- alphax) (/ alphay sin2phi)) (/ (* alphay cos2phi) alphax))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (alphax * (u0 * -alphay)) / ((-alphax / (alphay / sin2phi)) - ((alphay * cos2phi) / alphax));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = (alphax * (u0 * -alphay)) / ((-alphax / (alphay / sin2phi)) - ((alphay * cos2phi) / alphax))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(alphax * Float32(u0 * Float32(-alphay))) / Float32(Float32(Float32(-alphax) / Float32(alphay / sin2phi)) - Float32(Float32(alphay * cos2phi) / alphax))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (alphax * (u0 * -alphay)) / ((-alphax / (alphay / sin2phi)) - ((alphay * cos2phi) / alphax)); end
\begin{array}{l}
\\
\frac{alphax \cdot \left(u0 \cdot \left(-alphay\right)\right)}{\frac{-alphax}{\frac{alphay}{sin2phi}} - \frac{alphay \cdot cos2phi}{alphax}}
\end{array}
Initial program 62.1%
sub-neg62.1%
log1p-def98.7%
Simplified98.7%
associate-/r*98.5%
associate-/r*98.5%
frac-2neg98.5%
frac-add98.4%
distribute-neg-frac98.4%
Applied egg-rr98.4%
+-commutative98.4%
*-commutative98.4%
distribute-lft-neg-out98.4%
unsub-neg98.4%
associate-*r/98.5%
associate-/l*98.4%
associate-*r/98.4%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in u0 around 0 75.0%
associate-*r/75.0%
mul-1-neg75.0%
mul-1-neg75.0%
associate-/l*75.0%
distribute-neg-frac75.0%
*-commutative75.0%
Simplified75.0%
Final simplification75.0%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* alphax (* u0 (- alphay))) (- (+ (/ (* alphax sin2phi) alphay) (/ (* alphay cos2phi) alphax)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (alphax * (u0 * -alphay)) / -(((alphax * sin2phi) / alphay) + ((alphay * cos2phi) / alphax));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = (alphax * (u0 * -alphay)) / -(((alphax * sin2phi) / alphay) + ((alphay * cos2phi) / alphax))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(alphax * Float32(u0 * Float32(-alphay))) / Float32(-Float32(Float32(Float32(alphax * sin2phi) / alphay) + Float32(Float32(alphay * cos2phi) / alphax)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (alphax * (u0 * -alphay)) / -(((alphax * sin2phi) / alphay) + ((alphay * cos2phi) / alphax)); end
\begin{array}{l}
\\
\frac{alphax \cdot \left(u0 \cdot \left(-alphay\right)\right)}{-\left(\frac{alphax \cdot sin2phi}{alphay} + \frac{alphay \cdot cos2phi}{alphax}\right)}
\end{array}
Initial program 62.1%
sub-neg62.1%
log1p-def98.7%
Simplified98.7%
associate-/r*98.5%
associate-/r*98.5%
frac-2neg98.5%
frac-add98.4%
distribute-neg-frac98.4%
Applied egg-rr98.4%
+-commutative98.4%
*-commutative98.4%
distribute-lft-neg-out98.4%
unsub-neg98.4%
associate-*r/98.5%
associate-/l*98.4%
associate-*r/98.4%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in u0 around 0 75.0%
Final simplification75.0%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ u0 (+ (* (/ cos2phi alphax) (/ 1.0 alphax)) (/ (/ sin2phi alphay) alphay))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return u0 / (((cos2phi / alphax) * (1.0f / alphax)) + ((sin2phi / alphay) / alphay));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = u0 / (((cos2phi / alphax) * (1.0e0 / alphax)) + ((sin2phi / alphay) / alphay))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(u0 / Float32(Float32(Float32(cos2phi / alphax) * Float32(Float32(1.0) / alphax)) + Float32(Float32(sin2phi / alphay) / alphay))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = u0 / (((cos2phi / alphax) * (single(1.0) / alphax)) + ((sin2phi / alphay) / alphay)); end
\begin{array}{l}
\\
\frac{u0}{\frac{cos2phi}{alphax} \cdot \frac{1}{alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}}
\end{array}
Initial program 62.1%
associate-/r*62.1%
Simplified62.1%
Taylor expanded in u0 around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
associate-/r*74.9%
div-inv74.9%
Applied egg-rr74.9%
Final simplification74.9%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ u0 (+ (/ cos2phi (* alphax alphax)) (/ (/ sin2phi alphay) alphay))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return u0 / ((cos2phi / (alphax * alphax)) + ((sin2phi / alphay) / alphay));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = u0 / ((cos2phi / (alphax * alphax)) + ((sin2phi / alphay) / alphay))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(u0 / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(Float32(sin2phi / alphay) / alphay))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = u0 / ((cos2phi / (alphax * alphax)) + ((sin2phi / alphay) / alphay)); end
\begin{array}{l}
\\
\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}}
\end{array}
Initial program 62.1%
associate-/r*62.1%
Simplified62.1%
Taylor expanded in u0 around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
Final simplification74.9%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ u0 (+ (/ (/ sin2phi alphay) alphay) (/ (/ cos2phi alphax) alphax))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return u0 / (((sin2phi / alphay) / alphay) + ((cos2phi / alphax) / alphax));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = u0 / (((sin2phi / alphay) / alphay) + ((cos2phi / alphax) / alphax))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(u0 / Float32(Float32(Float32(sin2phi / alphay) / alphay) + Float32(Float32(cos2phi / alphax) / alphax))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = u0 / (((sin2phi / alphay) / alphay) + ((cos2phi / alphax) / alphax)); end
\begin{array}{l}
\\
\frac{u0}{\frac{\frac{sin2phi}{alphay}}{alphay} + \frac{\frac{cos2phi}{alphax}}{alphax}}
\end{array}
Initial program 62.1%
sqr-neg62.1%
sub-neg62.1%
log1p-def98.7%
sqr-neg98.7%
associate-/r*98.5%
Simplified98.5%
clear-num98.4%
associate-/r/98.4%
pow298.4%
pow-flip98.5%
metadata-eval98.5%
Applied egg-rr98.5%
*-commutative98.5%
metadata-eval98.5%
pow-flip98.4%
pow298.4%
div-inv98.5%
associate-/r*98.5%
Applied egg-rr98.5%
Taylor expanded in u0 around 0 74.9%
mul-1-neg74.9%
Simplified74.9%
Final simplification74.9%
herbie shell --seed 2023310
(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)))))