
(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 9 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))) (fma alphay (/ cos2phi alphax) (* alphax (/ sin2phi alphay)))) (* alphay alphax)))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (-log1pf(-u0) / fmaf(alphay, (cos2phi / alphax), (alphax * (sin2phi / alphay)))) * (alphay * alphax);
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(Float32(-log1p(Float32(-u0))) / fma(alphay, Float32(cos2phi / alphax), Float32(alphax * Float32(sin2phi / alphay)))) * Float32(alphay * alphax)) end
\begin{array}{l}
\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(alphay, \frac{cos2phi}{alphax}, alphax \cdot \frac{sin2phi}{alphay}\right)} \cdot \left(alphay \cdot alphax\right)
\end{array}
Initial program 58.8%
sub-neg58.8%
log1p-def97.9%
Simplified97.9%
clear-num97.9%
associate-/r/97.9%
pow297.9%
pow-flip98.2%
metadata-eval98.2%
Applied egg-rr98.2%
*-commutative98.2%
add-sqr-sqrt97.6%
pow297.6%
sqr-pow97.3%
pow297.3%
unpow-prod-down97.3%
metadata-eval97.3%
inv-pow97.3%
div-inv97.4%
div-inv97.3%
div-inv97.3%
fma-def97.3%
pow297.3%
pow-flip97.4%
metadata-eval97.4%
Applied egg-rr98.1%
fma-udef98.0%
*-rgt-identity98.0%
metadata-eval98.0%
pow-sqr97.9%
inv-pow97.9%
inv-pow97.9%
frac-times98.0%
metadata-eval98.0%
div-inv98.0%
frac-times98.0%
*-commutative98.0%
metadata-eval98.0%
pow-flip97.8%
div-inv97.8%
pow297.8%
+-commutative97.8%
associate-/r*97.8%
un-div-inv97.9%
frac-add97.7%
Applied egg-rr97.7%
expm1-log1p-u96.4%
expm1-udef50.5%
un-div-inv50.6%
+-commutative50.6%
fma-def50.6%
*-commutative50.6%
Applied egg-rr50.6%
expm1-def96.4%
expm1-log1p97.8%
associate-/r/98.5%
*-commutative98.5%
Simplified98.5%
Final simplification98.5%
(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 58.8%
sub-neg58.8%
log1p-def97.9%
Simplified97.9%
clear-num97.9%
associate-/r/97.9%
pow297.9%
pow-flip98.2%
metadata-eval98.2%
Applied egg-rr98.2%
Final simplification98.2%
(FPCore (alphax alphay u0 cos2phi sin2phi)
:precision binary32
(if (<= (- 1.0 u0) 0.9959999918937683)
(/ (* (* alphay alphay) (- (log (- 1.0 u0)))) sin2phi)
(/
(* alphax (* u0 alphay))
(+ (/ (* alphax sin2phi) alphay) (/ (* alphay cos2phi) alphax)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
float tmp;
if ((1.0f - u0) <= 0.9959999918937683f) {
tmp = ((alphay * alphay) * -logf((1.0f - u0))) / sin2phi;
} else {
tmp = (alphax * (u0 * alphay)) / (((alphax * sin2phi) / alphay) + ((alphay * cos2phi) / alphax));
}
return tmp;
}
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
real(4) :: tmp
if ((1.0e0 - u0) <= 0.9959999918937683e0) then
tmp = ((alphay * alphay) * -log((1.0e0 - u0))) / sin2phi
else
tmp = (alphax * (u0 * alphay)) / (((alphax * sin2phi) / alphay) + ((alphay * cos2phi) / alphax))
end if
code = tmp
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) tmp = Float32(0.0) if (Float32(Float32(1.0) - u0) <= Float32(0.9959999918937683)) tmp = Float32(Float32(Float32(alphay * alphay) * Float32(-log(Float32(Float32(1.0) - u0)))) / sin2phi); else tmp = Float32(Float32(alphax * Float32(u0 * alphay)) / Float32(Float32(Float32(alphax * sin2phi) / alphay) + Float32(Float32(alphay * cos2phi) / alphax))); end return tmp end
function tmp_2 = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = single(0.0); if ((single(1.0) - u0) <= single(0.9959999918937683)) tmp = ((alphay * alphay) * -log((single(1.0) - u0))) / sin2phi; else tmp = (alphax * (u0 * alphay)) / (((alphax * sin2phi) / alphay) + ((alphay * cos2phi) / alphax)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u0 \leq 0.9959999918937683:\\
\;\;\;\;\frac{\left(alphay \cdot alphay\right) \cdot \left(-\log \left(1 - u0\right)\right)}{sin2phi}\\
\mathbf{else}:\\
\;\;\;\;\frac{alphax \cdot \left(u0 \cdot alphay\right)}{\frac{alphax \cdot sin2phi}{alphay} + \frac{alphay \cdot cos2phi}{alphax}}\\
\end{array}
\end{array}
if (-.f32 1 u0) < 0.995999992Initial program 92.5%
Taylor expanded in cos2phi around 0 67.9%
pow231.7%
Applied egg-rr67.9%
if 0.995999992 < (-.f32 1 u0) Initial program 50.9%
sub-neg50.9%
log1p-def98.4%
Simplified98.4%
clear-num98.4%
associate-/r/98.5%
pow298.5%
pow-flip98.7%
metadata-eval98.7%
Applied egg-rr98.7%
*-commutative98.7%
add-sqr-sqrt98.1%
pow298.1%
sqr-pow97.8%
pow297.8%
unpow-prod-down97.8%
metadata-eval97.8%
inv-pow97.8%
div-inv98.0%
div-inv97.8%
div-inv97.8%
fma-def97.8%
pow297.8%
pow-flip97.9%
metadata-eval97.9%
Applied egg-rr98.6%
fma-udef98.5%
*-rgt-identity98.5%
metadata-eval98.5%
pow-sqr98.4%
inv-pow98.4%
inv-pow98.4%
frac-times98.5%
metadata-eval98.5%
div-inv98.5%
frac-times98.5%
*-commutative98.5%
metadata-eval98.5%
pow-flip98.3%
div-inv98.3%
pow298.3%
+-commutative98.3%
associate-/r*98.3%
un-div-inv98.4%
frac-add98.3%
Applied egg-rr98.3%
Taylor expanded in u0 around 0 86.8%
Final simplification83.2%
(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 58.8%
sub-neg58.8%
log1p-def97.9%
Simplified97.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(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 58.8%
sub-neg58.8%
log1p-def97.9%
Simplified97.9%
clear-num97.9%
associate-/r/97.9%
pow297.9%
pow-flip98.2%
metadata-eval98.2%
Applied egg-rr98.2%
*-commutative77.7%
metadata-eval77.7%
pow-flip77.7%
pow277.7%
div-inv77.6%
associate-/r*77.7%
Applied egg-rr98.0%
Final simplification98.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 * alphay)) / 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 alphay\right)}{\frac{alphax \cdot sin2phi}{alphay} + \frac{alphay \cdot cos2phi}{alphax}}
\end{array}
Initial program 58.8%
sub-neg58.8%
log1p-def97.9%
Simplified97.9%
clear-num97.9%
associate-/r/97.9%
pow297.9%
pow-flip98.2%
metadata-eval98.2%
Applied egg-rr98.2%
*-commutative98.2%
add-sqr-sqrt97.6%
pow297.6%
sqr-pow97.3%
pow297.3%
unpow-prod-down97.3%
metadata-eval97.3%
inv-pow97.3%
div-inv97.4%
div-inv97.3%
div-inv97.3%
fma-def97.3%
pow297.3%
pow-flip97.4%
metadata-eval97.4%
Applied egg-rr98.1%
fma-udef98.0%
*-rgt-identity98.0%
metadata-eval98.0%
pow-sqr97.9%
inv-pow97.9%
inv-pow97.9%
frac-times98.0%
metadata-eval98.0%
div-inv98.0%
frac-times98.0%
*-commutative98.0%
metadata-eval98.0%
pow-flip97.8%
div-inv97.8%
pow297.8%
+-commutative97.8%
associate-/r*97.8%
un-div-inv97.9%
frac-add97.7%
Applied egg-rr97.7%
Taylor expanded in u0 around 0 77.9%
Final simplification77.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 58.8%
Taylor expanded in u0 around 0 77.6%
mul-1-neg77.6%
Simplified77.6%
Final simplification77.6%
(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 58.8%
Taylor expanded in u0 around 0 77.6%
mul-1-neg77.6%
Simplified77.6%
clear-num97.9%
associate-/r/97.9%
pow297.9%
pow-flip98.2%
metadata-eval98.2%
Applied egg-rr77.7%
*-commutative77.7%
metadata-eval77.7%
pow-flip77.7%
pow277.7%
div-inv77.6%
associate-/r*77.7%
Applied egg-rr77.7%
Final simplification77.7%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (* u0 (/ (* alphay alphay) sin2phi)))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return u0 * ((alphay * alphay) / sin2phi);
}
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 * ((alphay * alphay) / sin2phi)
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(u0 * Float32(Float32(alphay * alphay) / sin2phi)) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = u0 * ((alphay * alphay) / sin2phi); end
\begin{array}{l}
\\
u0 \cdot \frac{alphay \cdot alphay}{sin2phi}
\end{array}
Initial program 58.8%
Taylor expanded in u0 around 0 77.6%
mul-1-neg77.6%
Simplified77.6%
Taylor expanded in cos2phi around 0 61.4%
associate-/l*60.5%
associate-/r/61.4%
Simplified61.4%
pow261.4%
Applied egg-rr61.4%
Final simplification61.4%
herbie shell --seed 2024019
(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)))))