
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0
(atan
(* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))
(t_1 (sin t_0))
(t_2 (cos t_0)))
(/
1.0
(sqrt
(+
1.0
(/
(*
(/
1.0
(+
(/ (* t_2 t_2) (* alphax alphax))
(/ (* t_1 t_1) (* alphay alphay))))
u0)
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0
(atan
(* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))
(t_1 (sin t_0))
(t_2 (cos t_0)))
(/
1.0
(sqrt
(+
1.0
(/
(*
(/
1.0
(+
(/ (* t_2 t_2) (* alphax alphax))
(/ (* t_1 t_1) (* alphay alphay))))
u0)
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0
(atan
(* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))
(t_1 (sin t_0))
(t_2 (cos t_0)))
(/
1.0
(sqrt
(+
1.0
(/
(*
(/
1.0
(+
(/ (* t_2 t_2) (* alphax alphax))
(/ (* t_1 t_1) (* alphay alphay))))
u0)
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\frac{1}{\sqrt{1 + \frac{\frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}
Initial program 99.3%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0
(atan
(* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))
(t_1 (cos t_0))
(t_2 (sin t_0)))
(sqrt
(+
1.0
(/
(*
(/
1.0
(+
(/ (* t_1 t_1) (* alphax alphax))
(/ (* t_2 t_2) (* alphay alphay))))
u0)
(- 1.0 u0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
\sqrt{1 + \frac{\frac{1}{\frac{t\_1 \cdot t\_1}{alphax \cdot alphax} + \frac{t\_2 \cdot t\_2}{alphay \cdot alphay}} \cdot u0}{1 - u0}}
\end{array}
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0
(atan
(* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))
(t_1 (cos t_0))
(t_2 (sin t_0)))
(+
1.0
(/
(*
(/
1.0
(+ (/ (* t_1 t_1) (* alphax alphax)) (/ (* t_2 t_2) (* alphay alphay))))
u0)
(- 1.0 u0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
1 + \frac{\frac{1}{\frac{t\_1 \cdot t\_1}{alphax \cdot alphax} + \frac{t\_2 \cdot t\_2}{alphay \cdot alphay}} \cdot u0}{1 - u0}
\end{array}
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.1%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(sqrt
(+
1.0
(cos
(atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI))))))))))\begin{array}{l}
\\
\sqrt{1 + \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)}
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
Taylor expanded in u0 around 0
Applied rewrites66.8%
(FPCore (u0 u1 alphax alphay) :precision binary32 (+ 1.0 (cos (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))))
\begin{array}{l}
\\
1 + \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)\right)\right)
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
Taylor expanded in u0 around 0
Applied rewrites66.8%
Taylor expanded in u0 around 0
Applied rewrites64.4%
(FPCore (u0 u1 alphax alphay) :precision binary32 (sqrt (sqrt (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI))))))
\begin{array}{l}
\\
\sqrt{\sqrt{\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)}}
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
Taylor expanded in u0 around 0
Applied rewrites66.8%
Taylor expanded in u0 around 0
Applied rewrites37.1%
(FPCore (u0 u1 alphax alphay) :precision binary32 (sqrt (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))
\begin{array}{l}
\\
\sqrt{\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)}
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
Taylor expanded in u0 around 0
Applied rewrites33.7%
(FPCore (u0 u1 alphax alphay) :precision binary32 (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI))))
\begin{array}{l}
\\
\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + 0.5 \cdot \mathsf{PI}\left(\right)
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
Taylor expanded in u0 around inf
Applied rewrites18.1%
Taylor expanded in u0 around 0
Applied rewrites30.1%
(FPCore (u0 u1 alphax alphay) :precision binary32 (sqrt (PI)))
\begin{array}{l}
\\
\sqrt{\mathsf{PI}\left(\right)}
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
Taylor expanded in u0 around 0
Applied rewrites66.8%
Taylor expanded in u0 around 0
Applied rewrites29.3%
(FPCore (u0 u1 alphax alphay) :precision binary32 (PI))
\begin{array}{l}
\\
\mathsf{PI}\left(\right)
\end{array}
Initial program 99.3%
Taylor expanded in u0 around 0
Applied rewrites90.6%
Taylor expanded in u0 around 0
Applied rewrites66.8%
Taylor expanded in u0 around 0
Applied rewrites26.1%
herbie shell --seed 2024321
(FPCore (u0 u1 alphax alphay)
:name "Trowbridge-Reitz Sample, sample surface normal, cosTheta"
:precision binary32
:pre (and (and (and (and (<= 2.328306437e-10 u0) (<= u0 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 0.5))) (and (<= 0.0001 alphax) (<= alphax 1.0))) (and (<= 0.0001 alphay) (<= alphay 1.0)))
(/ 1.0 (sqrt (+ 1.0 (/ (* (/ 1.0 (+ (/ (* (cos (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI))))))) (cos (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))) (* alphax alphax)) (/ (* (sin (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI))))))) (sin (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) (* 0.5 (PI)))))))) (* alphay alphay)))) u0) (- 1.0 u0))))))