
(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 8 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 (* cosTheta (sqrt (PI)))) (sqrt (- (- 1.0 cosTheta) cosTheta)))
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \left(\frac{1}{cosTheta \cdot \sqrt{\mathsf{PI}\left(\right)}} \cdot \sqrt{\left(1 - cosTheta\right) - cosTheta}\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lift-/.f32N/A
clear-numN/A
div-invN/A
associate-/r/N/A
*-rgt-identityN/A
times-fracN/A
un-div-invN/A
lift-/.f32N/A
Applied rewrites98.8%
(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.8
Applied rewrites98.8%
(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.2%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(+ 1.0 c)
(*
(* (/ 1.0 (* cosTheta (sqrt (PI)))) (- 1.0 cosTheta))
(exp (* (- cosTheta) cosTheta))))))\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \left(\frac{1}{cosTheta \cdot \sqrt{\mathsf{PI}\left(\right)}} \cdot \left(1 - cosTheta\right)\right) \cdot e^{\left(-cosTheta\right) \cdot cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lift-/.f32N/A
clear-numN/A
div-invN/A
associate-/r/N/A
*-rgt-identityN/A
times-fracN/A
un-div-invN/A
lift-/.f32N/A
Applied rewrites98.8%
lift--.f32N/A
sub-negN/A
lift--.f32N/A
lift-neg.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3298.7
Applied rewrites98.7%
Taylor expanded in cosTheta around 0
mul-1-negN/A
unsub-negN/A
lower--.f3297.1
Applied rewrites97.1%
(FPCore (cosTheta c)
:precision binary32
(let* ((t_0 (sqrt (PI))))
(/
1.0
(+
(+ 1.0 c)
(/
1.0
(/
(* (- (* (* cosTheta cosTheta) (PI)) (PI)) cosTheta)
(- (* t_0 cosTheta) t_0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
\frac{1}{\left(1 + c\right) + \frac{1}{\frac{\left(\left(cosTheta \cdot cosTheta\right) \cdot \mathsf{PI}\left(\right) - \mathsf{PI}\left(\right)\right) \cdot cosTheta}{t\_0 \cdot cosTheta - t\_0}}}
\end{array}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
div-invN/A
associate-*l/N/A
clear-numN/A
lower-/.f32N/A
lower-/.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites98.5%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-sqrt.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
lower-PI.f3294.2
Applied rewrites93.9%
Applied rewrites96.8%
(FPCore (cosTheta c) :precision binary32 (/ 1.0 (+ (+ 1.0 c) (/ 1.0 (* (* (+ cosTheta 1.0) (sqrt (PI))) cosTheta)))))
\begin{array}{l}
\\
\frac{1}{\left(1 + c\right) + \frac{1}{\left(\left(cosTheta + 1\right) \cdot \sqrt{\mathsf{PI}\left(\right)}\right) \cdot cosTheta}}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
div-invN/A
associate-*l/N/A
clear-numN/A
lower-/.f32N/A
lower-/.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites98.5%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-sqrt.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
lower-PI.f3294.2
Applied rewrites93.9%
Applied rewrites96.6%
(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.f3294.4
Applied rewrites94.4%
(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 2024318
(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))))))