
(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 5 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) (* (PI) 0.5))))))
(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 + \mathsf{PI}\left(\right) \cdot 0.5\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.4%
Final simplification99.4%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* (PI) 0.5))
(t_1 (sin (atan (* (/ alphay alphax) (tan t_0)))))
(t_2
(cos (atan (* (/ alphay alphax) (tan (+ (* (* 2.0 (PI)) u1) t_0)))))))
(/
1.0
(sqrt
(+
1.0
(/
(*
u0
(/
1.0
(+
(/ (* t_2 t_2) (* alphax alphax))
(/ (* t_1 t_1) (* alphay alphay)))))
(- 1.0 u0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot 0.5\\
t_1 := \sin \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan t\_0\right)\\
t_2 := \cos \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u1 + t\_0\right)\right)\\
\frac{1}{\sqrt{1 + \frac{u0 \cdot \frac{1}{\frac{t\_2 \cdot t\_2}{alphax \cdot alphax} + \frac{t\_1 \cdot t\_1}{alphay \cdot alphay}}}{1 - u0}}}
\end{array}
\end{array}
Initial program 99.4%
Taylor expanded in u1 around 0
lower-*.f32N/A
lower-PI.f3297.6
Applied rewrites97.6%
Taylor expanded in u1 around 0
lower-*.f32N/A
lower-PI.f3297.8
Applied rewrites97.8%
Final simplification97.8%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* 4.0 (* u1 u1))))
(/
1.0
(sqrt
(+
1.0
(/
(* (* alphay alphay) u0)
(*
(- 1.0 u0)
(+
0.5
(*
-0.5
(cos
(*
2.0
(atan
(*
(/ alphay alphax)
(tan
(*
(PI)
(/
(fma (* 2.0 u1) t_0 0.125)
(+ 0.25 (- t_0 u1))))))))))))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \left(u1 \cdot u1\right)\\
\frac{1}{\sqrt{1 + \frac{\left(alphay \cdot alphay\right) \cdot u0}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot \frac{\mathsf{fma}\left(2 \cdot u1, t\_0, 0.125\right)}{0.25 + \left(t\_0 - u1\right)}\right)\right)\right)\right)}}}
\end{array}
\end{array}
Initial program 99.4%
Taylor expanded in alphay around 0
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-*.f32N/A
Applied rewrites92.8%
Applied rewrites96.8%
+-commutativeN/A
flip3-+N/A
+-commutativeN/A
lower-/.f32N/A
cube-multN/A
lower-fma.f32N/A
lower-*.f32N/A
swap-sqrN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f32N/A
metadata-evalN/A
lower-*.f32N/A
metadata-evalN/A
lower-+.f32N/A
metadata-evalN/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
metadata-evalN/A
*-commutativeN/A
*-lft-identityN/A
Applied rewrites97.2%
Final simplification97.2%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(/
1.0
(sqrt
(+
1.0
(/
(* (* alphay alphay) u0)
(*
(- 1.0 u0)
(+
0.5
(*
-0.5
(cos (* 2.0 (atan (* (/ alphay alphax) (tan (* (PI) 0.5))))))))))))))\begin{array}{l}
\\
\frac{1}{\sqrt{1 + \frac{\left(alphay \cdot alphay\right) \cdot u0}{\left(1 - u0\right) \cdot \left(0.5 + -0.5 \cdot \cos \left(2 \cdot \tan^{-1} \left(\frac{alphay}{alphax} \cdot \tan \left(\mathsf{PI}\left(\right) \cdot 0.5\right)\right)\right)\right)}}}
\end{array}
Initial program 99.4%
Taylor expanded in alphay around 0
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-*.f32N/A
Applied rewrites92.8%
Applied rewrites96.8%
Taylor expanded in u1 around 0
Applied rewrites97.1%
Final simplification97.1%
(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 alphay around 0
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-*.f32N/A
Applied rewrites92.8%
Taylor expanded in alphay around 0
Applied rewrites91.7%
herbie shell --seed 2024216
(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))))))