
(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 8 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 (* (- 0.5 (* u1 -2.0)) (PI))) (t_1 (cos t_0)) (t_2 (sin t_0)))
(sqrt
(/
1.0
(+
(*
(/ (* u0 alphay) (- 1.0 u0))
(/
alphax
(+
(/
(* (pow (sin (atan (* (/ t_2 t_1) (/ alphay alphax)))) 2.0) alphax)
alphay)
(/
alphay
(*
(+
(*
(/ (pow t_2 2.0) (pow t_1 2.0))
(/ (* alphay alphay) (* alphax alphax)))
1.0)
alphax)))))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 - u1 \cdot -2\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
\sqrt{\frac{1}{\frac{u0 \cdot alphay}{1 - u0} \cdot \frac{alphax}{\frac{{\sin \tan^{-1} \left(\frac{t\_2}{t\_1} \cdot \frac{alphay}{alphax}\right)}^{2} \cdot alphax}{alphay} + \frac{alphay}{\left(\frac{{t\_2}^{2}}{{t\_1}^{2}} \cdot \frac{alphay \cdot alphay}{alphax \cdot alphax} + 1\right) \cdot alphax}} + 1}}
\end{array}
\end{array}
Initial program 99.3%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites78.7%
Applied rewrites79.5%
Taylor expanded in alphax around 0
lower-/.f32N/A
lower-+.f32N/A
Applied rewrites98.5%
Taylor expanded in u1 around inf
Applied rewrites99.9%
Final simplification99.9%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (- 0.5 (* u1 -2.0)) (PI))) (t_1 (sin t_0)) (t_2 (cos t_0)))
(sqrt
(/
1.0
(+
(*
(/ u0 (- 1.0 u0))
(/
alphay
(+
(/ (pow (sin (atan (* (/ t_1 t_2) (/ alphay alphax)))) 2.0) alphay)
(/ (pow t_2 2.0) (* (pow t_1 2.0) alphay)))))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 - u1 \cdot -2\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\sqrt{\frac{1}{\frac{u0}{1 - u0} \cdot \frac{alphay}{\frac{{\sin \tan^{-1} \left(\frac{t\_1}{t\_2} \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay} + \frac{{t\_2}^{2}}{{t\_1}^{2} \cdot alphay}} + 1}}
\end{array}
\end{array}
Initial program 99.3%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites78.7%
Applied rewrites78.8%
Taylor expanded in alphax around 0
lower-/.f32N/A
lower-+.f32N/A
Applied rewrites98.5%
Taylor expanded in alphax around 0
Applied rewrites99.0%
Final simplification99.0%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (- 0.5 (* u1 -2.0)) (PI))) (t_1 (cos t_0)))
(/
1.0
(sqrt
(+
(/
(*
(/
alphay
(+
(/
(pow
(sin (atan (* (/ (sin (* 0.5 (PI))) t_1) (/ alphay alphax))))
2.0)
alphay)
(/ (pow t_1 2.0) (* (pow (sin t_0) 2.0) alphay))))
u0)
(- 1.0 u0))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 - u1 \cdot -2\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos t\_0\\
\frac{1}{\sqrt{\frac{\frac{alphay}{\frac{{\sin \tan^{-1} \left(\frac{\sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)}{t\_1} \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay} + \frac{{t\_1}^{2}}{{\sin t\_0}^{2} \cdot alphay}} \cdot u0}{1 - u0} + 1}}
\end{array}
\end{array}
Initial program 99.3%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites78.6%
Applied rewrites79.1%
Taylor expanded in alphax around 0
lower-/.f32N/A
lower-+.f32N/A
Applied rewrites98.5%
Taylor expanded in u1 around 0
Applied rewrites98.5%
Final simplification98.5%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (- 0.5 (* u1 -2.0)) (PI))) (t_1 (cos t_0)))
(/
1.0
(sqrt
(+
(/
(*
(/
alphay
(+
(/ (pow t_1 2.0) (* (pow (sin (* 0.5 (PI))) 2.0) alphay))
(/
(pow (sin (atan (* (/ (sin t_0) t_1) (/ alphay alphax)))) 2.0)
alphay)))
u0)
(- 1.0 u0))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 - u1 \cdot -2\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos t\_0\\
\frac{1}{\sqrt{\frac{\frac{alphay}{\frac{{t\_1}^{2}}{{\sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)}^{2} \cdot alphay} + \frac{{\sin \tan^{-1} \left(\frac{\sin t\_0}{t\_1} \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay}} \cdot u0}{1 - u0} + 1}}
\end{array}
\end{array}
Initial program 99.3%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites79.5%
Applied rewrites79.1%
Taylor expanded in alphax around 0
lower-/.f32N/A
lower-+.f32N/A
Applied rewrites98.5%
Taylor expanded in u1 around 0
Applied rewrites97.9%
Final simplification97.9%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (- 0.5 (* u1 -2.0)) (PI))))
(sqrt
(/
1.0
(+
(*
(/
(* alphay alphay)
(pow (sin (atan (* (/ (sin t_0) (cos t_0)) (/ alphay alphax)))) 2.0))
(/ u0 (- 1.0 u0)))
1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 - u1 \cdot -2\right) \cdot \mathsf{PI}\left(\right)\\
\sqrt{\frac{1}{\frac{alphay \cdot alphay}{{\sin \tan^{-1} \left(\frac{\sin t\_0}{\cos t\_0} \cdot \frac{alphay}{alphax}\right)}^{2}} \cdot \frac{u0}{1 - u0} + 1}}
\end{array}
\end{array}
Initial program 99.3%
Applied rewrites87.5%
Taylor expanded in u1 around 0
Applied rewrites97.6%
Taylor expanded in alphax around inf
Applied rewrites97.6%
Final simplification97.6%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(/
1.0
(sqrt
(+
(/
(*
(/
1.0
(/
(fma
(/ (/ alphay alphax) alphax)
alphax
(*
(/
(pow
(sin (atan (* (tan (* (fma 2.0 u1 0.5) (PI))) (/ alphay alphax))))
2.0)
alphay)
alphax))
(* alphay alphax)))
u0)
(- 1.0 u0))
1.0))))\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{\frac{1}{\frac{\mathsf{fma}\left(\frac{\frac{alphay}{alphax}}{alphax}, alphax, \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay} \cdot alphax\right)}{alphay \cdot alphax}} \cdot u0}{1 - u0} + 1}}
\end{array}
Initial program 99.3%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites79.2%
Applied rewrites78.7%
Taylor expanded in alphax around inf
lower-*.f32N/A
lower-+.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lower-/.f32N/A
Applied rewrites91.6%
Applied rewrites90.6%
Final simplification90.3%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(/
1.0
(sqrt
(+
(/
(*
(/
1.0
(/
(fma
alphax
(/ (/ alphay alphax) alphax)
(*
(/
(pow
(sin (atan (* (tan (* (fma 2.0 u1 0.5) (PI))) (/ alphay alphax))))
2.0)
alphay)
alphax))
(* alphay alphax)))
u0)
(- 1.0 u0))
1.0))))\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{\frac{1}{\frac{\mathsf{fma}\left(alphax, \frac{\frac{alphay}{alphax}}{alphax}, \frac{{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}^{2}}{alphay} \cdot alphax\right)}{alphay \cdot alphax}} \cdot u0}{1 - u0} + 1}}
\end{array}
Initial program 99.3%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites79.0%
Applied rewrites79.2%
Taylor expanded in alphax around inf
lower-*.f32N/A
lower-+.f32N/A
lower-/.f32N/A
unpow2N/A
lower-*.f32N/A
lower-/.f32N/A
Applied rewrites91.6%
Applied rewrites90.3%
Final simplification90.3%
(FPCore (u0 u1 alphax alphay) :precision binary32 1.0)
float code(float u0, float u1, float alphax, float alphay) {
return 1.0f;
}
real(4) function code(u0, u1, alphax, alphay)
real(4), intent (in) :: u0
real(4), intent (in) :: u1
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
code = 1.0e0
end function
function code(u0, u1, alphax, alphay) return Float32(1.0) end
function tmp = code(u0, u1, alphax, alphay) tmp = single(1.0); end
\begin{array}{l}
\\
1
\end{array}
Initial program 99.3%
Taylor expanded in alphax around 0
Applied rewrites90.3%
herbie shell --seed 2024278
(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))))))