
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
(FPCore (ux uy maxCos) :precision binary32 (* (sin (fma (* -2.0 uy) (PI) (/ (PI) 2.0))) (sqrt (* (- 2.0 (fma (fma ux (+ -2.0 maxCos) 2.0) maxCos ux)) ux))))
\begin{array}{l}
\\
\sin \left(\mathsf{fma}\left(-2 \cdot uy, \mathsf{PI}\left(\right), \frac{\mathsf{PI}\left(\right)}{2}\right)\right) \cdot \sqrt{\left(2 - \mathsf{fma}\left(\mathsf{fma}\left(ux, -2 + maxCos, 2\right), maxCos, ux\right)\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
associate--l-N/A
+-commutativeN/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
distribute-lft-neg-outN/A
metadata-evalN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3299.1
Applied rewrites99.1%
Taylor expanded in maxCos around 0
Applied rewrites99.1%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (fma 0.5 (PI) (* (* (PI) uy) -2.0))) (sqrt (* (- 2.0 (fma (fma ux (+ -2.0 maxCos) 2.0) maxCos ux)) ux))))
\begin{array}{l}
\\
\sin \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), \left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot -2\right)\right) \cdot \sqrt{\left(2 - \mathsf{fma}\left(\mathsf{fma}\left(ux, -2 + maxCos, 2\right), maxCos, ux\right)\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
associate--l-N/A
+-commutativeN/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
distribute-lft-neg-outN/A
metadata-evalN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3299.1
Applied rewrites99.1%
Taylor expanded in maxCos around 0
Applied rewrites99.1%
Taylor expanded in uy around 0
+-commutativeN/A
lower-fma.f32N/A
lower-PI.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.8
Applied rewrites98.8%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) (PI))) (sqrt (* (+ 1.0 (- 1.0 (fma (fma (+ maxCos -2.0) ux 2.0) maxCos ux))) ux))))
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(1 + \left(1 - \mathsf{fma}\left(\mathsf{fma}\left(maxCos + -2, ux, 2\right), maxCos, ux\right)\right)\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
associate--l-N/A
+-commutativeN/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
Applied rewrites98.8%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (+ uy uy) (PI))) (sqrt (* (- 2.0 (fma (fma ux (+ -2.0 maxCos) 2.0) maxCos ux)) ux))))
\begin{array}{l}
\\
\cos \left(\left(uy + uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - \mathsf{fma}\left(\mathsf{fma}\left(ux, -2 + maxCos, 2\right), maxCos, ux\right)\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
associate--l-N/A
+-commutativeN/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f3298.8
Applied rewrites98.8%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 (fma (fma -2.0 ux 2.0) maxCos ux)) ux))))
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - \mathsf{fma}\left(\mathsf{fma}\left(-2, ux, 2\right), maxCos, ux\right)\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
associate--l-N/A
+-commutativeN/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
Taylor expanded in maxCos around 0
Applied rewrites98.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 1.1000000199601345e-7)
(* (cos (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 ux) ux)))
(*
(fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0)
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (+ -1.0 maxCos)) ux)) (* 2.0 maxCos))
ux)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.1000000199601345 \cdot 10^{-7}:\\
\;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot \sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(-1 + maxCos\right)\right) \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if maxCos < 1.10000002e-7Initial program 52.5%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
associate--l-N/A
+-commutativeN/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
if 1.10000002e-7 < maxCos Initial program 54.9%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3250.7
Applied rewrites50.7%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3251.1
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3251.1
Applied rewrites51.1%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites90.1%
Final simplification97.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 (fma 2.0 maxCos ux)) ux))))
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - \mathsf{fma}\left(2, maxCos, ux\right)\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
associate--l-N/A
+-commutativeN/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
Taylor expanded in ux around 0
Applied rewrites97.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.029999999329447746)
(*
(fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0)
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (+ -1.0 maxCos)) ux)) (* 2.0 maxCos))
ux)))
(* (cos (* (* uy 2.0) (PI))) (sqrt (* 2.0 ux)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.029999999329447746:\\
\;\;\;\;\mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot \sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(-1 + maxCos\right)\right) \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 0.0299999993Initial program 53.8%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3253.4
Applied rewrites53.4%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3253.5
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3253.5
Applied rewrites53.5%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites98.3%
if 0.0299999993 < uy Initial program 47.8%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3282.8
Applied rewrites82.8%
Taylor expanded in maxCos around 0
Applied rewrites74.6%
Final simplification95.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0))
(t_1 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= (sqrt (- 1.0 (* t_1 t_1))) 0.037700001150369644)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(* t_0 (sqrt (- 1.0 (* t_1 (- 1.0 ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
t_1 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;\sqrt{1 - t\_1 \cdot t\_1} \leq 0.037700001150369644:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - t\_1 \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if (sqrt.f32 (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))))) < 0.0377000012Initial program 38.9%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3236.6
Applied rewrites36.6%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3236.6
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3236.6
Applied rewrites36.6%
Taylor expanded in ux around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites90.5%
Taylor expanded in ux around 0
Applied rewrites84.4%
if 0.0377000012 < (sqrt.f32 (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))))) Initial program 89.9%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3285.6
Applied rewrites85.6%
Taylor expanded in maxCos around 0
lower--.f3282.6
Applied rewrites82.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1 (fma maxCos ux (- 1.0 ux)))
(t_2 (fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0)))
(if (<= (* t_0 t_0) 0.9997000098228455)
(* t_2 (sqrt (fma t_1 (- t_1) 1.0)))
(* t_2 (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \mathsf{fma}\left(maxCos, ux, 1 - ux\right)\\
t_2 := \mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.9997000098228455:\\
\;\;\;\;t\_2 \cdot \sqrt{\mathsf{fma}\left(t\_1, -t\_1, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_2 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.99970001Initial program 88.0%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3283.8
Applied rewrites83.8%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3284.1
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3284.1
Applied rewrites84.1%
if 0.99970001 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 36.6%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3234.3
Applied rewrites34.3%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3234.3
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3234.3
Applied rewrites34.3%
Taylor expanded in ux around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites90.3%
Taylor expanded in ux around 0
Applied rewrites85.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0))
(t_1 (- (fma maxCos ux 1.0) ux)))
(if (<= ux 0.0001500000071246177)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(* t_0 (sqrt (- 1.0 (* t_1 t_1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
t_1 := \mathsf{fma}\left(maxCos, ux, 1\right) - ux\\
\mathbf{if}\;ux \leq 0.0001500000071246177:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - t\_1 \cdot t\_1}\\
\end{array}
\end{array}
if ux < 1.50000007e-4Initial program 36.6%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3234.3
Applied rewrites34.3%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3234.3
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3234.3
Applied rewrites34.3%
Taylor expanded in ux around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites90.3%
Taylor expanded in ux around 0
Applied rewrites85.4%
if 1.50000007e-4 < ux Initial program 88.0%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3283.8
Applied rewrites83.8%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3284.0
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3284.0
Applied rewrites84.0%
lift-fma.f32N/A
lift-fma.f32N/A
+-commutativeN/A
lift--.f32N/A
*-commutativeN/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-fma.f32N/A
+-commutativeN/A
lift--.f32N/A
*-commutativeN/A
*-commutativeN/A
distribute-lft-inN/A
lift--.f32N/A
lower-*.f32N/A
Applied rewrites83.8%
(FPCore (ux uy maxCos)
:precision binary32
(*
(fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0)
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (+ -1.0 maxCos)) ux)) (* 2.0 maxCos))
ux))))\begin{array}{l}
\\
\mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot \sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(-1 + maxCos\right)\right) \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3250.2
Applied rewrites50.2%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3250.3
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3250.3
Applied rewrites50.3%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites91.2%
Final simplification91.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (fma maxCos ux 1.0) ux)))
(if (<= ux 0.0002089000045089051)
(*
(fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0)
(sqrt (* (fma -2.0 maxCos 2.0) ux)))
(sqrt (- 1.0 (fma (* t_0 ux) maxCos (* t_0 (- 1.0 ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(maxCos, ux, 1\right) - ux\\
\mathbf{if}\;ux \leq 0.0002089000045089051:\\
\;\;\;\;\mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \mathsf{fma}\left(t\_0 \cdot ux, maxCos, t\_0 \cdot \left(1 - ux\right)\right)}\\
\end{array}
\end{array}
if ux < 2.08900005e-4Initial program 37.0%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3234.8
Applied rewrites34.8%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3234.8
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3234.8
Applied rewrites34.8%
Taylor expanded in ux around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites90.3%
Taylor expanded in ux around 0
Applied rewrites85.3%
if 2.08900005e-4 < ux Initial program 88.4%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3284.1
Applied rewrites84.1%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3284.3
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3284.3
Applied rewrites84.3%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower--.f3278.8
Applied rewrites78.8%
(FPCore (ux uy maxCos) :precision binary32 (* (fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 53.0%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3250.2
Applied rewrites50.2%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3250.3
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3250.3
Applied rewrites50.3%
Taylor expanded in ux around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites85.7%
Taylor expanded in ux around 0
Applied rewrites74.7%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (* uy uy) -2.0) (* (PI) (PI))) (sqrt (- 1.0 1.0))))
\begin{array}{l}
\\
\left(\left(\left(uy \cdot uy\right) \cdot -2\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - 1}
\end{array}
Initial program 53.0%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3250.2
Applied rewrites50.2%
Taylor expanded in ux around 0
Applied rewrites6.6%
Taylor expanded in uy around inf
Applied rewrites6.6%
herbie shell --seed 2025017
(FPCore (ux uy maxCos)
:name "UniformSampleCone, x"
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))