
(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 (* (tan (+ (* 0.5 (PI)) (* (* 2.0 (PI)) u1))) (/ alphay alphax)))
(t_1 (sin (atan t_0))))
(/
1.0
(sqrt
(-
1.0
(/
(*
(/
-1.0
(-
(/ (* t_1 t_1) (* alphay alphay))
(/ (/ -1.0 (+ (pow t_0 2.0) 1.0)) (* alphax alphax))))
u0)
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(0.5 \cdot \mathsf{PI}\left(\right) + \left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1\right) \cdot \frac{alphay}{alphax}\\
t_1 := \sin \tan^{-1} t\_0\\
\frac{1}{\sqrt{1 - \frac{\frac{-1}{\frac{t\_1 \cdot t\_1}{alphay \cdot alphay} - \frac{\frac{-1}{{t\_0}^{2} + 1}}{alphax \cdot alphax}} \cdot u0}{1 - u0}}}
\end{array}
\end{array}
Initial program 99.4%
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 rewrites92.9%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
+-commutativeN/A
lift-+.f3299.4
lift-*.f32N/A
*-commutativeN/A
lift-*.f3299.4
lift-*.f32N/A
*-commutativeN/A
lower-*.f3299.4
Applied rewrites99.4%
Final simplification99.4%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(sqrt
(/
1.0
(-
1.0
(/
(/ u0 (- u0 1.0))
(+
(pow
(/
(sin (atan (* (tan (* (+ (* u1 2.0) 0.5) (PI))) (/ alphay alphax))))
alphay)
2.0)
(pow
(/
(cos (atan (* (tan (* (fma u1 2.0 0.5) (PI))) (/ alphay alphax))))
alphax)
2.0)))))))\begin{array}{l}
\\
\sqrt{\frac{1}{1 - \frac{\frac{u0}{u0 - 1}}{{\left(\frac{\sin \tan^{-1} \left(\tan \left(\left(u1 \cdot 2 + 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{2} + {\left(\frac{\cos \tan^{-1} \left(\tan \left(\mathsf{fma}\left(u1, 2, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphax}\right)}^{2}}}}
\end{array}
Initial program 99.4%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Applied rewrites98.1%
Applied rewrites98.3%
Final simplification91.8%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(sqrt
(/
1.0
(-
1.0
(/
(/ u0 (- u0 1.0))
(+
(pow
(/ (sin (atan (* (tan (* 0.5 (PI))) (/ alphay alphax)))) alphay)
2.0)
(pow
(/
(cos (atan (* (tan (* (fma u1 2.0 0.5) (PI))) (/ alphay alphax))))
alphax)
2.0)))))))\begin{array}{l}
\\
\sqrt{\frac{1}{1 - \frac{\frac{u0}{u0 - 1}}{{\left(\frac{\sin \tan^{-1} \left(\tan \left(0.5 \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{2} + {\left(\frac{\cos \tan^{-1} \left(\tan \left(\mathsf{fma}\left(u1, 2, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphax}\right)}^{2}}}}
\end{array}
Initial program 99.4%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Applied rewrites98.0%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Final simplification91.6%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* 0.5 (PI))))
(/
1.0
(sqrt
(-
1.0
(/
(/ u0 (- u0 1.0))
(-
(pow
(/
(sin (atan (* (tan (+ t_0 (* (* 2.0 (PI)) u1))) (/ alphay alphax))))
alphay)
2.0)
(/
(- -1.0 (cos (* (atan (* (tan t_0) (/ alphay alphax))) 2.0)))
(* (* alphax alphax) 2.0)))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{PI}\left(\right)\\
\frac{1}{\sqrt{1 - \frac{\frac{u0}{u0 - 1}}{{\left(\frac{\sin \tan^{-1} \left(\tan \left(t\_0 + \left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{2} - \frac{-1 - \cos \left(\tan^{-1} \left(\tan t\_0 \cdot \frac{alphay}{alphax}\right) \cdot 2\right)}{\left(alphax \cdot alphax\right) \cdot 2}}}}
\end{array}
\end{array}
Initial program 99.4%
Applied rewrites87.2%
Applied rewrites85.3%
Taylor expanded in u1 around 0
Applied rewrites48.2%
lift-PI.f32N/A
lift-fma.f32N/A
+-commutativeN/A
lower-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f3297.8
Applied rewrites97.8%
Final simplification97.8%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (atan (* (tan (* (fma u1 2.0 0.5) (PI))) (/ alphay alphax)))))
(sqrt
(/
1.0
(-
1.0
(/
(/ u0 (- u0 1.0))
(+
(pow (/ (sin t_0) alphay) 2.0)
(/ (+ (cos (* t_0 2.0)) 1.0) (* (* alphax alphax) 2.0)))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1} \left(\tan \left(\mathsf{fma}\left(u1, 2, 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} + \frac{\cos \left(t\_0 \cdot 2\right) + 1}{\left(alphax \cdot alphax\right) \cdot 2}}}}
\end{array}
\end{array}
Initial program 99.4%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Applied rewrites98.1%
Applied rewrites98.1%
Final simplification98.0%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(/
1.0
(sqrt
(-
1.0
(/
(*
(/
-1.0
(-
(/
(/
-1.0
(-
-1.0
(pow
(* (tan (+ (* 0.5 (PI)) (* (* 2.0 (PI)) u1))) (/ alphay alphax))
2.0)))
(* alphax alphax))
(/
(-
(cos
(*
(atan (* (tan (* (fma u1 2.0 0.5) (PI))) (/ alphay alphax)))
2.0))
1.0)
(* (* alphay alphay) 2.0))))
u0)
(- 1.0 u0))))))\begin{array}{l}
\\
\frac{1}{\sqrt{1 - \frac{\frac{-1}{\frac{\frac{-1}{-1 - {\left(\tan \left(0.5 \cdot \mathsf{PI}\left(\right) + \left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1\right) \cdot \frac{alphay}{alphax}\right)}^{2}}}{alphax \cdot alphax} - \frac{\cos \left(\tan^{-1} \left(\tan \left(\mathsf{fma}\left(u1, 2, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right) \cdot 2\right) - 1}{\left(alphay \cdot alphay\right) \cdot 2}} \cdot u0}{1 - u0}}}
\end{array}
Initial program 99.4%
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 rewrites92.9%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
+-commutativeN/A
lift-+.f3299.4
lift-*.f32N/A
*-commutativeN/A
lift-*.f3299.4
lift-*.f32N/A
*-commutativeN/A
lower-*.f3299.4
Applied rewrites99.4%
lift-/.f32N/A
Applied rewrites70.7%
Final simplification70.7%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(pow
(-
1.0
(/
(*
(pow
(/
(sin (atan (* (tan (* (fma u1 2.0 0.5) (PI))) (/ alphay alphax))))
alphay)
-2.0)
u0)
(- u0 1.0)))
-0.5))\begin{array}{l}
\\
{\left(1 - \frac{{\left(\frac{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(u1, 2, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{-2} \cdot u0}{u0 - 1}\right)}^{-0.5}
\end{array}
Initial program 99.4%
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 rewrites92.9%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
+-commutativeN/A
lift-+.f3299.4
lift-*.f32N/A
*-commutativeN/A
lift-*.f3299.4
lift-*.f32N/A
*-commutativeN/A
lower-*.f3299.4
Applied rewrites99.4%
Taylor expanded in alphax around inf
Applied rewrites97.7%
Applied rewrites83.9%
Final simplification82.7%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(/
1.0
(sqrt
(-
1.0
(/
(*
(pow
(/
(sin (atan (* (tan (* (fma u1 2.0 0.5) (PI))) (/ alphay alphax))))
alphay)
-2.0)
u0)
(- u0 1.0))))))\begin{array}{l}
\\
\frac{1}{\sqrt{1 - \frac{{\left(\frac{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(u1, 2, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{-2} \cdot u0}{u0 - 1}}}
\end{array}
Initial program 99.4%
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.1%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
+-commutativeN/A
lift-+.f3299.4
lift-*.f32N/A
*-commutativeN/A
lift-*.f3299.4
lift-*.f32N/A
*-commutativeN/A
lower-*.f3299.4
Applied rewrites99.4%
Taylor expanded in alphax around inf
Applied rewrites97.7%
Applied rewrites97.7%
Final simplification97.7%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(sqrt
(-
1.0
(*
(pow
(/
(sin (atan (* (tan (* (fma u1 2.0 0.5) (PI))) (/ alphay alphax))))
alphay)
-2.0)
(/ u0 (- 1.0 u0))))))\begin{array}{l}
\\
\sqrt{1 - {\left(\frac{\sin \tan^{-1} \left(\tan \left(\mathsf{fma}\left(u1, 2, 0.5\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \frac{alphay}{alphax}\right)}{alphay}\right)}^{-2} \cdot \frac{u0}{1 - u0}}
\end{array}
Initial program 99.4%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Taylor expanded in alphay around 0
Applied rewrites6.6%
Applied rewrites95.2%
(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.4%
Taylor expanded in u0 around 0
Applied rewrites91.2%
herbie shell --seed 2024284
(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))))))