
(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
(* (tan (+ (* 0.5 (PI)) (* u1 (* (PI) 2.0)))) (/ alphay alphax))))
(t_1 (cos t_0))
(t_2 (sin t_0)))
(/
1.0
(sqrt
(-
1.0
(/
(*
(/
-1.0
(+
(/ (* t_2 t_2) (* alphay alphay))
(/ (* t_1 t_1) (* alphax alphax))))
u0)
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\tan \left(0.5 \cdot \mathsf{PI}\left(\right) + u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \frac{alphay}{alphax}\right)\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
\frac{1}{\sqrt{1 - \frac{\frac{-1}{\frac{t\_2 \cdot t\_2}{alphay \cdot alphay} + \frac{t\_1 \cdot t\_1}{alphax \cdot alphax}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}
Initial program 99.5%
Final simplification99.5%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* 0.5 (PI)))
(t_1 (atan (* (tan (+ t_0 (* u1 (* (PI) 2.0)))) (/ alphay alphax))))
(t_2 (cos t_1)))
(/
1.0
(sqrt
(-
1.0
(/
(*
(/
-1.0
(+
(/
(* (sin (atan (* (tan t_0) (/ alphay alphax)))) (sin t_1))
(* alphay alphay))
(/ (* t_2 t_2) (* alphax alphax))))
u0)
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{PI}\left(\right)\\
t_1 := \tan^{-1} \left(\tan \left(t\_0 + u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \frac{alphay}{alphax}\right)\\
t_2 := \cos t\_1\\
\frac{1}{\sqrt{1 - \frac{\frac{-1}{\frac{\sin \tan^{-1} \left(\tan t\_0 \cdot \frac{alphay}{alphax}\right) \cdot \sin t\_1}{alphay \cdot alphay} + \frac{t\_2 \cdot t\_2}{alphax \cdot alphax}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.9
Applied rewrites98.9%
Final simplification98.9%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* 0.5 (PI)))
(t_1
(cos (atan (* (tan (+ t_0 (* u1 (* (PI) 2.0)))) (/ alphay alphax)))))
(t_2 (sin (atan (* (tan t_0) (/ alphay alphax))))))
(/
1.0
(sqrt
(-
1.0
(/
(*
(/
-1.0
(+
(/ (* t_2 t_2) (* alphay alphay))
(/ (* t_1 t_1) (* alphax alphax))))
u0)
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{PI}\left(\right)\\
t_1 := \cos \tan^{-1} \left(\tan \left(t\_0 + u1 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot \frac{alphay}{alphax}\right)\\
t_2 := \sin \tan^{-1} \left(\tan t\_0 \cdot \frac{alphay}{alphax}\right)\\
\frac{1}{\sqrt{1 - \frac{\frac{-1}{\frac{t\_2 \cdot t\_2}{alphay \cdot alphay} + \frac{t\_1 \cdot t\_1}{alphax \cdot alphax}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.9
Applied rewrites98.9%
Taylor expanded in u1 around 0
lower-*.f32N/A
lower-PI.f3298.9
Applied rewrites98.9%
Final simplification98.9%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (fma 2.0 u1 0.5) (PI))) (t_1 (* (sin t_0) (/ alphay alphax))))
(sqrt
(/
1.0
(-
1.0
(/
(/ u0 (- u0 1.0))
(+
(/
(pow (cos (atan (/ t_1 (cos (* (+ (* u1 2.0) 0.5) (PI)))))) 2.0)
(* alphax alphax))
(/ (pow (sin (atan (/ t_1 (cos t_0)))) 2.0) (* alphay alphay)))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin t\_0 \cdot \frac{alphay}{alphax}\\
\sqrt{\frac{1}{1 - \frac{\frac{u0}{u0 - 1}}{\frac{{\cos \tan^{-1} \left(\frac{t\_1}{\cos \left(\left(u1 \cdot 2 + 0.5\right) \cdot \mathsf{PI}\left(\right)\right)}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\frac{t\_1}{\cos t\_0}\right)}^{2}}{alphay \cdot alphay}}}}
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in u1 around 0
Applied rewrites98.8%
Applied rewrites99.0%
Final simplification99.0%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (atan (* (tan (* (fma 2.0 u1 0.5) (PI))) (/ alphay alphax)))))
(pow
(-
1.0
(/
(/ u0 (- u0 1.0))
(+ (pow (/ (sin t_0) alphay) 2.0) (pow (/ alphax (cos t_0)) -2.0))))
-0.5)))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\tan \left(\mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)\\
{\left(1 - \frac{\frac{u0}{u0 - 1}}{{\left(\frac{\sin t\_0}{alphay}\right)}^{2} + {\left(\frac{alphax}{\cos t\_0}\right)}^{-2}}\right)}^{-0.5}
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in u1 around 0
Applied rewrites98.8%
Applied rewrites99.0%
Applied rewrites92.6%
Final simplification92.3%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (atan (* (tan (* (fma 2.0 u1 0.5) (PI))) (/ alphay alphax)))))
(sqrt
(/
1.0
(-
1.0
(/
(/ u0 (- u0 1.0))
(+ (pow (/ (sin t_0) alphay) 2.0) (pow (/ alphax (cos t_0)) -2.0))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\tan \left(\mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)\\
\sqrt{\frac{1}{1 - \frac{\frac{u0}{u0 - 1}}{{\left(\frac{\sin t\_0}{alphay}\right)}^{2} + {\left(\frac{alphax}{\cos t\_0}\right)}^{-2}}}}
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in u1 around 0
Applied rewrites98.8%
Applied rewrites99.0%
Applied rewrites98.8%
Final simplification98.8%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (fma 2.0 u1 0.5) (PI))))
(/
1.0
(sqrt
(-
1.0
(/
(/
(* u0 (* alphay alphay))
(pow (sin (atan (/ (* (sin t_0) (/ alphay alphax)) (cos t_0)))) 2.0))
(- u0 1.0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\\
\frac{1}{\sqrt{1 - \frac{\frac{u0 \cdot \left(alphay \cdot alphay\right)}{{\sin \tan^{-1} \left(\frac{\sin t\_0 \cdot \frac{alphay}{alphax}}{\cos t\_0}\right)}^{2}}}{u0 - 1}}}
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in alphax around inf
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-pow.f32N/A
Applied rewrites98.4%
Final simplification98.4%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (fma 2.0 u1 0.5) (PI))))
(/
1.0
(sqrt
(-
1.0
(/
(/
(* (* u0 (* alphay alphay)) 2.0)
(-
1.0
(cos (* (atan (* (/ (sin t_0) (cos t_0)) (/ alphay alphax))) 2.0))))
(- u0 1.0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\\
\frac{1}{\sqrt{1 - \frac{\frac{\left(u0 \cdot \left(alphay \cdot alphay\right)\right) \cdot 2}{1 - \cos \left(\tan^{-1} \left(\frac{\sin t\_0}{\cos t\_0} \cdot \frac{alphay}{alphax}\right) \cdot 2\right)}}{u0 - 1}}}
\end{array}
\end{array}
Initial program 99.5%
lift-*.f32N/A
lift-cos.f32N/A
lift-atan.f32N/A
cos-atanN/A
lift-cos.f32N/A
lift-atan.f32N/A
cos-atanN/A
Applied rewrites93.9%
Applied rewrites56.6%
Taylor expanded in alphax around inf
associate-*r/N/A
lower-/.f32N/A
lower-*.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
Applied rewrites98.4%
Final simplification98.4%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(-
1.0
(/
(* u0 (* alphay alphay))
(*
(-
(cos (* (atan (* (tan (* (fma 2.0 u1 0.5) (PI))) (/ alphay alphax))) 2.0))
1.0)
(- u0 1.0)))))\begin{array}{l}
\\
1 - \frac{u0 \cdot \left(alphay \cdot alphay\right)}{\left(\cos \left(\tan^{-1} \left(\tan \left(\mathsf{fma}\left(2, u1, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right) \cdot 2\right) - 1\right) \cdot \left(u0 - 1\right)}
\end{array}
Initial program 99.5%
Applied rewrites57.1%
Taylor expanded in alphay around 0
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
associate-/r*N/A
Applied rewrites77.1%
Applied rewrites78.3%
Applied rewrites77.4%
Final simplification80.4%
(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.5%
Taylor expanded in u0 around 0
Applied rewrites93.4%
herbie shell --seed 2024332
(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))))))