
(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 9 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 (* (sqrt (/ (PI) (- (- 1.0 cosTheta) cosTheta))) cosTheta)))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\left(1 - cosTheta\right) - cosTheta}} \cdot cosTheta} + \left(c + 1\right)}
\end{array}
Initial program 97.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*r/N/A
lower-/.f32N/A
Applied rewrites98.2%
lift--.f32N/A
sub-negN/A
lift--.f32N/A
lift-neg.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3298.2
Applied rewrites98.2%
lift-/.f32N/A
clear-numN/A
lift--.f32N/A
lift--.f32N/A
associate--r-N/A
lift--.f32N/A
lift-neg.f32N/A
sub-negN/A
lift--.f32N/A
lower-/.f32N/A
div-invN/A
metadata-evalN/A
lift-sqrt.f32N/A
sqrt-divN/A
lift-/.f32N/A
Applied rewrites98.7%
Final simplification98.7%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
(*
(/ (sqrt (- (- 1.0 cosTheta) cosTheta)) (* (sqrt (PI)) cosTheta))
(exp (* (- cosTheta) cosTheta)))
(+ c 1.0))))\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(c + 1\right)}
\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%
Final simplification98.6%
(FPCore (cosTheta c)
:precision binary32
(/
1.0
(+
1.0
(*
(exp (* (- cosTheta) cosTheta))
(/ 1.0 (* (sqrt (/ (PI) (- (- 1.0 cosTheta) cosTheta))) cosTheta))))))\begin{array}{l}
\\
\frac{1}{1 + e^{\left(-cosTheta\right) \cdot cosTheta} \cdot \frac{1}{\sqrt{\frac{\mathsf{PI}\left(\right)}{\left(1 - cosTheta\right) - cosTheta}} \cdot cosTheta}}
\end{array}
Initial program 97.8%
Taylor expanded in c around 0
Applied rewrites97.4%
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
clear-numN/A
lower-/.f32N/A
div-invN/A
metadata-evalN/A
lift-sqrt.f32N/A
sqrt-divN/A
lift-/.f32N/A
clear-numN/A
lift-/.f32N/A
lift-sqrt.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)))
(+ 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 97.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*r/N/A
lower-/.f32N/A
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)))\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} + 1}
\end{array}
Initial program 97.8%
Taylor expanded in c around 0
Applied rewrites97.4%
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
(/
1.0
(+
(*
(/ (- 1.0 cosTheta) (* (sqrt (PI)) cosTheta))
(exp (* (- cosTheta) cosTheta)))
(+ c 1.0))))\begin{array}{l}
\\
\frac{1}{\frac{1 - cosTheta}{\sqrt{\mathsf{PI}\left(\right)} \cdot cosTheta} \cdot e^{\left(-cosTheta\right) \cdot cosTheta} + \left(c + 1\right)}
\end{array}
Initial program 97.8%
Taylor expanded in cosTheta around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-/.f32N/A
Applied rewrites96.7%
Applied rewrites97.2%
Final simplification97.2%
(FPCore (cosTheta c) :precision binary32 (/ 1.0 (+ (* (/ 1.0 (* (sqrt (PI)) cosTheta)) (- 1.0 cosTheta)) (+ c 1.0))))
\begin{array}{l}
\\
\frac{1}{\frac{1}{\sqrt{\mathsf{PI}\left(\right)} \cdot cosTheta} \cdot \left(1 - cosTheta\right) + \left(c + 1\right)}
\end{array}
Initial program 97.8%
lift-/.f32N/A
inv-powN/A
lift-sqrt.f32N/A
pow1/2N/A
pow-powN/A
rem-cube-cbrtN/A
lift-PI.f32N/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
metadata-evalN/A
metadata-eval97.8
Applied rewrites97.8%
Taylor expanded in cosTheta around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-/.f32N/A
Applied rewrites96.4%
Applied rewrites96.9%
Final simplification96.9%
(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.0
Applied rewrites94.0%
(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 2024271
(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))))))