
(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
(-
(*
(exp (* (- cosTheta) cosTheta))
(*
(/ 1.0 (pow (PI) 0.16666666666666666))
(/ (/ (sqrt (- (- 1.0 cosTheta) cosTheta)) cosTheta) (cbrt (PI)))))
(- -1.0 c))))\begin{array}{l}
\\
\frac{1}{e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \left(\frac{1}{{\mathsf{PI}\left(\right)}^{0.16666666666666666}} \cdot \frac{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{cosTheta}}{\sqrt[3]{\mathsf{PI}\left(\right)}}\right) - \left(-1 - c\right)}
\end{array}
Initial program 97.6%
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.3%
Final simplification98.3%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(-
(*
(/
(sqrt (- (- 1.0 cosTheta) cosTheta))
(* (sqrt (* (log (E)) (PI))) cosTheta))
(exp (* (- cosTheta) cosTheta)))
(- -1.0 c))))\begin{array}{l}
\\
\frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\log \mathsf{E}\left(\right) \cdot \mathsf{PI}\left(\right)} \cdot cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} - \left(-1 - c\right)}
\end{array}
Initial program 97.6%
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.3%
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-/l/N/A
lower-/.f32N/A
lower-*.f3298.2
Applied rewrites98.2%
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.2
Applied rewrites98.2%
Final simplification98.2%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(-
(*
(/ (sqrt (- (- 1.0 cosTheta) cosTheta)) (* (sqrt (PI)) cosTheta))
(exp (* (- cosTheta) cosTheta)))
(- -1.0 c))))\begin{array}{l}
\\
\frac{1}{\frac{\sqrt{\left(1 - cosTheta\right) - cosTheta}}{\sqrt{\mathsf{PI}\left(\right)} \cdot cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} - \left(-1 - c\right)}
\end{array}
Initial program 97.6%
lift-*.f32N/A
lift-/.f32N/A
lift-/.f32N/A
frac-timesN/A
*-lft-identityN/A
lower-/.f32N/A
*-commutativeN/A
lower-*.f3298.2
Applied rewrites98.2%
Final simplification98.2%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(-
(*
(/ (sqrt (/ (- 1.0 (+ cosTheta cosTheta)) (PI))) cosTheta)
(exp (* (- cosTheta) cosTheta)))
(- -1.0 c))))\begin{array}{l}
\\
\frac{1}{\frac{\sqrt{\frac{1 - \left(cosTheta + cosTheta\right)}{\mathsf{PI}\left(\right)}}}{cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} - \left(-1 - c\right)}
\end{array}
Initial program 97.6%
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.8
Applied rewrites97.8%
lift--.f32N/A
sub-negN/A
lift--.f32N/A
lift-neg.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3297.8
Applied rewrites97.8%
Final simplification97.8%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(-
(*
(/ (sqrt (/ (- (- 1.0 cosTheta) cosTheta) (PI))) cosTheta)
(exp (* (- cosTheta) cosTheta)))
(- -1.0 c))))\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(-1 - c\right)}
\end{array}
Initial program 97.6%
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.8
Applied rewrites97.8%
Final simplification97.8%
(FPCore (cosTheta c) :precision binary32 (* (- (sqrt (PI)) (* (- (+ 1.0 c) (sqrt (/ 1.0 (PI)))) (* (PI) cosTheta))) cosTheta))
\begin{array}{l}
\\
\left(\sqrt{\mathsf{PI}\left(\right)} - \left(\left(1 + c\right) - \sqrt{\frac{1}{\mathsf{PI}\left(\right)}}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot cosTheta\right)\right) \cdot cosTheta
\end{array}
Initial program 97.6%
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.3%
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-/l/N/A
lower-/.f32N/A
lower-*.f3298.2
Applied rewrites98.2%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites95.4%
Final simplification95.4%
(FPCore (cosTheta c) :precision binary32 (* (sqrt (PI)) cosTheta))
\begin{array}{l}
\\
\sqrt{\mathsf{PI}\left(\right)} \cdot cosTheta
\end{array}
Initial program 97.6%
Taylor expanded in cosTheta around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-PI.f3292.4
Applied rewrites92.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.6%
Taylor expanded in c around inf
lower-/.f325.1
Applied rewrites5.1%
herbie shell --seed 2024288
(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))))))