
(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.3%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
*-commutativeN/A
lift-sqrt.f32N/A
pow1/2N/A
lift-PI.f32N/A
add-cube-cbrtN/A
unpow-prod-downN/A
pow2N/A
pow-powN/A
metadata-evalN/A
unpow1N/A
times-fracN/A
lower-*.f32N/A
Applied rewrites98.0%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
*-rgt-identityN/A
lift-/.f32N/A
lift-cbrt.f32N/A
pow1/3N/A
lift-pow.f32N/A
pow-prod-upN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f32N/A
associate-/r*N/A
lift-*.f32N/A
lower-/.f3297.9
lift-*.f32N/A
*-commutativeN/A
lower-*.f3297.9
Applied rewrites97.9%
lift-/.f32N/A
lift-*.f32N/A
associate-/r*N/A
Applied rewrites98.2%
Final simplification98.2%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
1.0
(*
(exp (* (- cosTheta) cosTheta))
(/ (sqrt (* (- (- 1.0 cosTheta) cosTheta) (PI))) (* cosTheta (PI)))))))\begin{array}{l}
\\
\frac{1}{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)}}
\end{array}
Initial program 97.3%
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.4
Applied rewrites97.4%
Taylor expanded in c around 0
Applied rewrites97.1%
lift-/.f32N/A
Applied rewrites97.9%
Final simplification97.9%
(FPCore (cosTheta c) :precision binary32 (* (sqrt (PI)) cosTheta))
\begin{array}{l}
\\
\sqrt{\mathsf{PI}\left(\right)} \cdot cosTheta
\end{array}
Initial program 97.3%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-PI.f3292.1
Applied rewrites92.1%
(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.3%
Taylor expanded in c around inf
lower-/.f325.1
Applied rewrites5.1%
herbie shell --seed 2024277
(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))))))