
(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 10 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
(let* ((t_0 (sqrt (PI))) (t_1 (/ 1.0 (+ c 1.0))))
(/
1.0
(/
(+
(*
(/
(/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta)
(pow (exp cosTheta) cosTheta))
t_1)
t_0)
(* t_1 t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
t_1 := \frac{1}{c + 1}\\
\frac{1}{\frac{\frac{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}{{\left(e^{cosTheta}\right)}^{cosTheta}} \cdot t\_1 + t\_0}{t\_1 \cdot t\_0}}
\end{array}
\end{array}
Initial program 98.1%
lift-+.f32N/A
lift-+.f32N/A
flip3-+N/A
clear-numN/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
div-invN/A
associate-*l/N/A
Applied rewrites98.6%
Final simplification98.6%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(*
(exp (* (- cosTheta) cosTheta))
(/ (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta) (sqrt (PI))))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \frac{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}{\sqrt{\mathsf{PI}\left(\right)}} + \left(c + 1\right)}
\end{array}
Initial program 98.1%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
div-invN/A
lower-/.f3298.6
Applied rewrites98.6%
Final simplification98.6%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(*
(/ (sqrt (- (- 1.0 cosTheta) cosTheta)) (* cosTheta (sqrt (PI))))
(exp (* (- cosTheta) cosTheta)))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta \cdot \sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} + \left(c + 1\right)}
\end{array}
Initial program 98.1%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
*-lft-identityN/A
lower-/.f32N/A
*-commutativeN/A
lower-*.f3298.5
Applied rewrites98.5%
Final simplification98.5%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(*
(/ (sqrt (/ (- (- 1.0 cosTheta) cosTheta) (PI))) cosTheta)
(exp (* (- cosTheta) cosTheta)))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{\frac{\sqrt{\frac{\left(1 - cosTheta\right) - cosTheta}{\mathsf{PI}\left(\right)}}}{cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} + \left(c + 1\right)}
\end{array}
Initial program 98.1%
lift-*.f32N/A
lift-/.f32N/A
associate-*r/N/A
lower-/.f32N/A
lift-/.f32N/A
associate-*l/N/A
*-lft-identityN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
sqrt-undivN/A
lower-sqrt.f32N/A
lower-/.f3297.9
Applied rewrites97.9%
Final simplification97.9%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(*
(/ (/ (- 1.0 cosTheta) cosTheta) (sqrt (PI)))
(exp (* (- cosTheta) cosTheta)))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{\frac{\frac{1 - cosTheta}{cosTheta}}{\sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} + \left(c + 1\right)}
\end{array}
Initial program 98.1%
Taylor expanded in cosTheta around 0
associate-*r*N/A
lower-/.f32N/A
mul-1-negN/A
cancel-sign-sub-invN/A
*-lft-identityN/A
distribute-rgt-out--N/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-/.f32N/A
lower-PI.f32N/A
lower--.f3295.9
Applied rewrites95.9%
Applied rewrites96.7%
Applied rewrites96.7%
Final simplification96.7%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(*
(/ (- 1.0 cosTheta) (* cosTheta (sqrt (PI))))
(exp (* (- cosTheta) cosTheta)))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{\frac{1 - cosTheta}{cosTheta \cdot \sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} + \left(c + 1\right)}
\end{array}
Initial program 98.1%
Taylor expanded in cosTheta around 0
associate-*r*N/A
lower-/.f32N/A
mul-1-negN/A
cancel-sign-sub-invN/A
*-lft-identityN/A
distribute-rgt-out--N/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-/.f32N/A
lower-PI.f32N/A
lower--.f3295.9
Applied rewrites95.9%
Applied rewrites96.7%
Applied rewrites96.7%
Final simplification96.7%
(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 98.1%
Taylor expanded in c around inf
lower-/.f325.0
Applied rewrites5.0%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites96.6%
Final simplification96.6%
(FPCore (cosTheta c) :precision binary32 (/ (* (* (+ c 1.0) cosTheta) (sqrt (PI))) (+ c 1.0)))
\begin{array}{l}
\\
\frac{\left(\left(c + 1\right) \cdot cosTheta\right) \cdot \sqrt{\mathsf{PI}\left(\right)}}{c + 1}
\end{array}
Initial program 98.1%
lift-+.f32N/A
lift-+.f32N/A
flip3-+N/A
clear-numN/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
div-invN/A
associate-*l/N/A
Applied rewrites98.6%
Taylor expanded in cosTheta around 0
lower-/.f3293.8
Applied rewrites93.8%
lift-/.f32N/A
lift-/.f32N/A
associate-/r/N/A
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-+.f32N/A
div-invN/A
Applied rewrites93.8%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
lower-+.f3294.2
Applied rewrites94.2%
Final simplification94.2%
(FPCore (cosTheta c) :precision binary32 (* cosTheta (sqrt (PI))))
\begin{array}{l}
\\
cosTheta \cdot \sqrt{\mathsf{PI}\left(\right)}
\end{array}
Initial program 98.1%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-PI.f3294.2
Applied rewrites94.2%
Final simplification94.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 98.1%
Taylor expanded in c around inf
lower-/.f325.0
Applied rewrites5.0%
herbie shell --seed 2024295
(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))))))