
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(+ 1.0 c)
(*
(* (/ 1.0 (sqrt (PI))) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta))
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(+ 1.0 c)
(*
(* (/ 1.0 (sqrt (PI))) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta))
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(*
(exp (* (- cosTheta) cosTheta))
(/ (sqrt (* (- (- 1.0 cosTheta) cosTheta) (PI))) (* cosTheta (PI))))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \frac{\sqrt{\left(\left(1 - cosTheta\right) - cosTheta\right) \cdot \mathsf{PI}\left(\right)}}{cosTheta \cdot \mathsf{PI}\left(\right)} + \left(c + 1\right)}
\end{array}
Initial program 97.9%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
clear-numN/A
lower-/.f32N/A
*-rgt-identityN/A
times-fracN/A
lift-/.f32N/A
clear-numN/A
clear-numN/A
lift-/.f32N/A
times-fracN/A
*-lft-identityN/A
lower-/.f32N/A
Applied rewrites98.1%
lift-sqrt.f32N/A
lift-/.f32N/A
lift--.f32N/A
lift--.f32N/A
lift-PI.f32N/A
lift--.f32N/A
lift-PI.f32N/A
div-subN/A
frac-subN/A
lift-PI.f32N/A
lift-PI.f32N/A
sqrt-divN/A
lift-PI.f32N/A
lift-PI.f32N/A
sqrt-unprodN/A
rem-square-sqrtN/A
Applied rewrites98.3%
lift-/.f32N/A
lift-/.f32N/A
clear-numN/A
lift-/.f32N/A
associate-/l/N/A
*-commutativeN/A
lift-*.f32N/A
lower-/.f3298.8
Applied rewrites98.8%
Final simplification98.8%
(FPCore (cosTheta c) :precision binary32 (* (- (sqrt (PI)) (* (- (+ c 1.0) (sqrt (/ 1.0 (PI)))) (* cosTheta (PI)))) cosTheta))
\begin{array}{l}
\\
\left(\sqrt{\mathsf{PI}\left(\right)} - \left(\left(c + 1\right) - \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right) \cdot \left(cosTheta \cdot \mathsf{PI}\left(\right)\right)\right) \cdot cosTheta
\end{array}
Initial program 97.9%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
*-lft-identityN/A
lower-/.f32N/A
*-commutativeN/A
lower-*.f3298.4
Applied rewrites98.4%
lift-PI.f32N/A
add-log-expN/A
*-un-lft-identityN/A
lift-PI.f32N/A
exp-prodN/A
log-powN/A
lower-*.f32N/A
lower-log.f32N/A
exp-1-eN/A
lower-E.f3298.6
Applied rewrites98.6%
Taylor expanded in cosTheta around 0
*-commutativeN/A
Applied rewrites95.7%
Final simplification95.7%
(FPCore (cosTheta c) :precision binary32 (* (sqrt (PI)) cosTheta))
\begin{array}{l}
\\
\sqrt{\mathsf{PI}\left(\right)} \cdot cosTheta
\end{array}
Initial program 97.9%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-PI.f3293.2
Applied rewrites93.2%
(FPCore (cosTheta c) :precision binary32 (/ 1.0 c))
float code(float cosTheta, float c) {
return 1.0f / c;
}
real(4) function code(costheta, c)
real(4), intent (in) :: costheta
real(4), intent (in) :: c
code = 1.0e0 / c
end function
function code(cosTheta, c) return Float32(Float32(1.0) / c) end
function tmp = code(cosTheta, c) tmp = single(1.0) / c; end
\begin{array}{l}
\\
\frac{1}{c}
\end{array}
Initial program 97.9%
Taylor expanded in c around inf
lower-/.f324.9
Applied rewrites4.9%
herbie shell --seed 2024304
(FPCore (cosTheta c)
:name "Beckmann Sample, normalization factor"
:precision binary32
:pre (and (and (< 0.0 cosTheta) (< cosTheta 0.9999)) (and (< -1.0 c) (< c 1.0)))
(/ 1.0 (+ (+ 1.0 c) (* (* (/ 1.0 (sqrt (PI))) (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta)) (exp (* (- cosTheta) cosTheta))))))