
(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 7 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
(*
(log1p (- u0))
(*
alphax
(/
(- alphay)
(fma alphay (/ cos2phi alphax) (* alphax (/ sin2phi alphay)))))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return log1pf(-u0) * (alphax * (-alphay / fmaf(alphay, (cos2phi / alphax), (alphax * (sin2phi / alphay)))));
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(log1p(Float32(-u0)) * Float32(alphax * Float32(Float32(-alphay) / fma(alphay, Float32(cos2phi / alphax), Float32(alphax * Float32(sin2phi / alphay)))))) end
\begin{array}{l}
\\
\mathsf{log1p}\left(-u0\right) \cdot \left(alphax \cdot \frac{-alphay}{\mathsf{fma}\left(alphay, \frac{cos2phi}{alphax}, alphax \cdot \frac{sin2phi}{alphay}\right)}\right)
\end{array}
Initial program 61.2%
sub-neg61.2%
log1p-def97.8%
Simplified97.8%
clear-num97.8%
associate-/r/97.7%
pow297.7%
pow-flip98.0%
metadata-eval98.0%
Applied egg-rr98.0%
div-inv97.9%
div-inv97.9%
fma-def97.9%
pow297.9%
pow-flip98.0%
metadata-eval98.0%
Applied egg-rr98.0%
metadata-eval98.0%
pow-flip97.9%
pow297.9%
fma-def97.9%
div-inv97.9%
+-commutative97.9%
*-commutative97.9%
fma-def97.9%
metadata-eval97.9%
pow-flip97.7%
pow297.7%
fma-def97.6%
div-inv97.8%
associate-/r*97.8%
associate-/r*97.8%
frac-add97.8%
Applied egg-rr97.8%
expm1-log1p-u94.9%
expm1-udef61.1%
associate-/r/61.1%
+-commutative61.1%
fma-def61.1%
*-commutative61.1%
Applied egg-rr61.1%
expm1-def95.4%
expm1-log1p98.2%
associate-*l/98.4%
*-lft-identity98.4%
associate-/l*98.6%
associate-/r/98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (- (log1p (- u0))) (+ (/ cos2phi (* alphax alphax)) (* sin2phi (pow alphay -2.0)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return -log1pf(-u0) / ((cos2phi / (alphax * alphax)) + (sin2phi * powf(alphay, -2.0f)));
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(-log1p(Float32(-u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi * (alphay ^ Float32(-2.0))))) end
\begin{array}{l}
\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + sin2phi \cdot {alphay}^{-2}}
\end{array}
Initial program 61.2%
sub-neg61.2%
log1p-def97.8%
Simplified97.8%
clear-num97.8%
associate-/r/97.7%
pow297.7%
pow-flip98.0%
metadata-eval98.0%
Applied egg-rr98.0%
Final simplification98.0%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (- (log1p (- u0))) (+ (/ cos2phi (* alphax alphax)) (* (/ sin2phi alphay) (/ 1.0 alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return -log1pf(-u0) / ((cos2phi / (alphax * alphax)) + ((sin2phi / alphay) * (1.0f / alphay)));
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(-log1p(Float32(-u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(Float32(sin2phi / alphay) * Float32(Float32(1.0) / alphay)))) end
\begin{array}{l}
\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay} \cdot \frac{1}{alphay}}
\end{array}
Initial program 61.2%
sub-neg61.2%
log1p-def97.8%
Simplified97.8%
associate-/r*97.9%
div-inv97.9%
Applied egg-rr97.9%
Final simplification97.9%
(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 61.2%
sub-neg61.2%
log1p-def97.8%
Simplified97.8%
Final simplification97.8%
(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(Float32(sin2phi / alphay) / alphay))) end
\begin{array}{l}
\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}}
\end{array}
Initial program 61.2%
sub-neg61.2%
log1p-def97.8%
Simplified97.8%
clear-num97.8%
associate-/r/97.7%
pow297.7%
pow-flip98.0%
metadata-eval98.0%
Applied egg-rr98.0%
*-commutative75.4%
metadata-eval75.4%
pow-flip75.3%
pow275.3%
div-inv75.4%
associate-/r*75.4%
Applied egg-rr97.9%
Final simplification97.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(sin2phi / Float32(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{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 61.2%
Taylor expanded in u0 around 0 75.4%
mul-1-neg75.4%
Simplified75.4%
Final simplification75.4%
(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 61.2%
Taylor expanded in u0 around 0 75.4%
mul-1-neg75.4%
Simplified75.4%
clear-num97.8%
associate-/r/97.7%
pow297.7%
pow-flip98.0%
metadata-eval98.0%
Applied egg-rr75.4%
*-commutative75.4%
metadata-eval75.4%
pow-flip75.3%
pow275.3%
div-inv75.4%
associate-/r*75.4%
Applied egg-rr75.4%
Final simplification75.4%
herbie shell --seed 2023332
(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)))))