
(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 7 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
(+
(+ 1.0 c)
(*
(/ 1.0 (* (sqrt (/ (PI) (- (- 1.0 cosTheta) cosTheta))) cosTheta))
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\left(1 - cosTheta\right) - cosTheta}} \cdot cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
clear-numN/A
lower-/.f32N/A
*-rgt-identityN/A
times-fracN/A
clear-numN/A
lift-/.f32N/A
lift-/.f32N/A
clear-numN/A
times-fracN/A
*-lft-identityN/A
lower-/.f32N/A
lift-/.f32N/A
Applied rewrites98.1%
lift-/.f32N/A
clear-numN/A
associate-/r/N/A
lower-*.f32N/A
metadata-evalN/A
lift-sqrt.f32N/A
sqrt-divN/A
lift-/.f32N/A
clear-numN/A
lower-sqrt.f32N/A
lower-/.f3298.6
Applied rewrites98.6%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(+ 1.0 c)
(*
(/ (sqrt (- (- 1.0 cosTheta) cosTheta)) (* cosTheta (sqrt (PI))))
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta \cdot \sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
*-lft-identityN/A
lower-/.f32N/A
*-commutativeN/A
lower-*.f3298.6
Applied rewrites98.6%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(+ 1.0 c)
(*
(/ (sqrt (/ (- (- 1.0 cosTheta) cosTheta) (PI))) cosTheta)
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \frac{\sqrt{\frac{\left(1 - cosTheta\right) - cosTheta}{\mathsf{PI}\left(\right)}}}{cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*r/N/A
lower-/.f32N/A
Applied rewrites98.1%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(+ 1.0 c)
(*
(/ (/ (- 1.0 cosTheta) cosTheta) (sqrt (PI)))
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \frac{\frac{1 - cosTheta}{cosTheta}}{\sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
div-invN/A
lower-/.f3298.5
Applied rewrites98.5%
Taylor expanded in cosTheta around 0
mul-1-negN/A
unsub-negN/A
lower--.f3295.7
Applied rewrites95.7%
(FPCore (cosTheta c) :precision binary32 (/ 1.0 (+ (+ 1.0 c) (/ (* (- 1.0 cosTheta) (sqrt (/ 1.0 (PI)))) cosTheta))))
\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \frac{\left(1 - cosTheta\right) \cdot \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}}{cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
*-lft-identityN/A
lower-/.f32N/A
*-commutativeN/A
lower-*.f3298.6
Applied rewrites98.6%
Taylor expanded in cosTheta around 0
*-commutativeN/A
associate-*r*N/A
lower-/.f32N/A
Applied rewrites94.8%
(FPCore (cosTheta c) :precision binary32 (* (sqrt (PI)) cosTheta))
\begin{array}{l}
\\
\sqrt{\mathsf{PI}\left(\right)} \cdot cosTheta
\end{array}
Initial program 97.8%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-PI.f3292.6
Applied rewrites92.6%
(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.8%
Taylor expanded in c around inf
lower-/.f325.0
Applied rewrites5.0%
herbie shell --seed 2024322
(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))))))