
(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 6 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 (* -2.0 (* (PI) u1)))))
(sqrt
(/
1.0
(+
1.0
(/
u0
(*
(+
(/
(pow (/ 1.0 (sqrt (+ 1.0 (pow (/ (/ alphay alphax) t_0) 2.0)))) 2.0)
(* alphax alphax))
(/
(pow (sin (atan (/ alphay (* t_0 alphax)))) 2.0)
(* alphay alphay)))
(- 1.0 u0))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(-2 \cdot \left(\mathsf{PI}\left(\right) \cdot u1\right)\right)\\
\sqrt{\frac{1}{1 + \frac{u0}{\left(\frac{{\left(\frac{1}{\sqrt{1 + {\left(\frac{\frac{alphay}{alphax}}{t\_0}\right)}^{2}}}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\frac{alphay}{t\_0 \cdot alphax}\right)}^{2}}{alphay \cdot alphay}\right) \cdot \left(1 - u0\right)}}}
\end{array}
\end{array}
Initial program 99.4%
lift-*.f32N/A
*-commutativeN/A
Applied rewrites99.4%
Taylor expanded in u1 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
Applied rewrites99.8%
Applied rewrites99.8%
Applied rewrites99.8%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(sqrt
(/
1.0
(+
1.0
(/
u0
(*
(+
(/
(pow
(/
1.0
(sqrt
(+ 1.0 (pow (/ (/ alphay alphax) (tan (* -2.0 (* (PI) u1)))) 2.0))))
2.0)
(* alphax alphax))
(/
(pow (sin (atan (* -0.5 (/ alphay (* alphax (* u1 (PI))))))) 2.0)
(* alphay alphay)))
(- 1.0 u0)))))))\begin{array}{l}
\\
\sqrt{\frac{1}{1 + \frac{u0}{\left(\frac{{\left(\frac{1}{\sqrt{1 + {\left(\frac{\frac{alphay}{alphax}}{\tan \left(-2 \cdot \left(\mathsf{PI}\left(\right) \cdot u1\right)\right)}\right)}^{2}}}\right)}^{2}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(-0.5 \cdot \frac{alphay}{alphax \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)}\right)}^{2}}{alphay \cdot alphay}\right) \cdot \left(1 - u0\right)}}}
\end{array}
Initial program 99.4%
lift-*.f32N/A
*-commutativeN/A
Applied rewrites99.4%
Taylor expanded in u1 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
Applied rewrites99.8%
Applied rewrites99.8%
Taylor expanded in u1 around 0
Applied rewrites99.6%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(let* ((t_0 (* 2.0 (* u1 (PI)))))
(sqrt
(/
1.0
(+
1.0
(/
u0
(*
(+
(/
(*
4.0
(/
(* (* alphax alphax) (* (* u1 u1) (* (PI) (PI))))
(* alphay alphay)))
(* alphax alphax))
(/
(pow
(sin (atan (* (/ (- alphay) alphax) (/ (cos t_0) (sin t_0)))))
2.0)
(* alphay alphay)))
(- 1.0 u0))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \left(u1 \cdot \mathsf{PI}\left(\right)\right)\\
\sqrt{\frac{1}{1 + \frac{u0}{\left(\frac{4 \cdot \frac{\left(alphax \cdot alphax\right) \cdot \left(\left(u1 \cdot u1\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right)}{alphay \cdot alphay}}{alphax \cdot alphax} + \frac{{\sin \tan^{-1} \left(\frac{-alphay}{alphax} \cdot \frac{\cos t\_0}{\sin t\_0}\right)}^{2}}{alphay \cdot alphay}\right) \cdot \left(1 - u0\right)}}}
\end{array}
\end{array}
Initial program 99.4%
lift-*.f32N/A
*-commutativeN/A
Applied rewrites99.4%
Taylor expanded in u1 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
Applied rewrites99.8%
Applied rewrites99.8%
Taylor expanded in u1 around 0
Applied rewrites99.0%
Final simplification99.0%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(pow
(+
(/
(*
(pow (sin (atan (/ (/ alphay alphax) (tan (* (* u1 (PI)) -2.0))))) -2.0)
(* u0 (* alphay alphay)))
(- 1.0 u0))
1.0)
-0.5))\begin{array}{l}
\\
{\left(\frac{{\sin \tan^{-1} \left(\frac{\frac{alphay}{alphax}}{\tan \left(\left(u1 \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right)}\right)}^{-2} \cdot \left(u0 \cdot \left(alphay \cdot alphay\right)\right)}{1 - u0} + 1\right)}^{-0.5}
\end{array}
Initial program 99.4%
Taylor expanded in alphax around inf
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-pow.f32N/A
Applied rewrites97.8%
Applied rewrites98.4%
(FPCore (u0 u1 alphax alphay)
:precision binary32
(/
1.0
(sqrt
(+
(/
(*
(pow (sin (atan (/ (/ alphay alphax) (tan (* (* u1 (PI)) -2.0))))) -2.0)
(* u0 (* alphay alphay)))
(- 1.0 u0))
1.0))))\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{{\sin \tan^{-1} \left(\frac{\frac{alphay}{alphax}}{\tan \left(\left(u1 \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right)}\right)}^{-2} \cdot \left(u0 \cdot \left(alphay \cdot alphay\right)\right)}{1 - u0} + 1}}
\end{array}
Initial program 99.4%
Taylor expanded in alphax around inf
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-pow.f32N/A
Applied rewrites97.8%
Applied rewrites98.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 alphax around 0
lower-/.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-pow.f32N/A
Applied rewrites41.0%
Taylor expanded in u0 around 0
Applied rewrites90.7%
herbie shell --seed 2024305
(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))))))