
(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 14 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
(if (<= maxCos 1.999999987845058e-8)
(* (cos (* (* (PI) uy) 2.0)) (sqrt (+ (* (- 1.0 ux) ux) ux)))
(*
(sqrt
(*
(* maxCos maxCos)
(-
(*
(/
(- (+ (/ (/ 2.0 maxCos) ux) 2.0) (- (/ 2.0 ux) (/ -1.0 maxCos)))
maxCos)
(* ux ux))
(* ux ux))))
(cos (* (PI) (* 2.0 uy))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.999999987845058 \cdot 10^{-8}:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\frac{\left(\frac{\frac{2}{maxCos}}{ux} + 2\right) - \left(\frac{2}{ux} - \frac{-1}{maxCos}\right)}{maxCos} \cdot \left(ux \cdot ux\right) - ux \cdot ux\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if maxCos < 1.99999999e-8Initial program 60.5%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites52.3%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.8
Applied rewrites98.8%
if 1.99999999e-8 < maxCos Initial program 58.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3256.3
Applied rewrites56.3%
Applied rewrites98.6%
Taylor expanded in maxCos around inf
Applied rewrites98.5%
Taylor expanded in maxCos around inf
Applied rewrites98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (cos (* (PI) (* 2.0 uy))) 0.9999997019767761)
(* (sqrt (* (- 2.0 ux) ux)) (cos (* (* (PI) uy) 2.0)))
(*
1.0
(sqrt
(*
(* (- (/ (+ (* -2.0 maxCos) 2.0) ux) (pow (- maxCos 1.0) 2.0)) ux)
ux)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.9999997019767761:\\
\;\;\;\;\sqrt{\left(2 - ux\right) \cdot ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \sqrt{\left(\left(\frac{-2 \cdot maxCos + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right) \cdot ux\right) \cdot ux}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) < 0.999999702Initial program 61.4%
Taylor expanded in uy around 0
Applied rewrites42.9%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites41.0%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3293.9
Applied rewrites93.9%
Taylor expanded in ux around 0
Applied rewrites93.9%
if 0.999999702 < (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) Initial program 59.2%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3293.2
Applied rewrites93.2%
Applied rewrites93.3%
Applied rewrites99.3%
Taylor expanded in uy around 0
Applied rewrites99.2%
Final simplification97.0%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* (- (/ (+ (* -2.0 maxCos) 2.0) ux) (pow (- maxCos 1.0) 2.0)) ux) ux)) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(\left(\frac{-2 \cdot maxCos + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right) \cdot ux\right) \cdot ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 60.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3270.4
Applied rewrites70.4%
Applied rewrites70.3%
Applied rewrites98.7%
Final simplification98.7%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (cos (* (PI) (* 2.0 uy))) 0.9999480247497559)
(* (sqrt (* ux 2.0)) (cos (* (* (PI) uy) 2.0)))
(*
(sqrt
(-
(* (- (/ 2.0 ux) (- (/ maxCos ux) (- maxCos 1.0))) (* ux ux))
(* (* (fma maxCos ux (- 1.0 ux)) maxCos) ux)))
1.0)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.9999480247497559:\\
\;\;\;\;\sqrt{ux \cdot 2} \cdot \cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{2}{ux} - \left(\frac{maxCos}{ux} - \left(maxCos - 1\right)\right)\right) \cdot \left(ux \cdot ux\right) - \left(\mathsf{fma}\left(maxCos, ux, 1 - ux\right) \cdot maxCos\right) \cdot ux} \cdot 1\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) < 0.999948025Initial program 55.4%
Taylor expanded in uy around 0
Applied rewrites30.4%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites29.8%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3293.2
Applied rewrites93.2%
Taylor expanded in ux around 0
Applied rewrites74.8%
if 0.999948025 < (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) Initial program 61.8%
Taylor expanded in uy around 0
Applied rewrites60.5%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
associate--r+N/A
lower--.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
Applied rewrites37.7%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f32N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3294.6
Applied rewrites94.6%
Final simplification89.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 9.999999717180685e-10)
(* (sqrt (+ (- ux (* ux ux)) ux)) (cos (* (* (PI) uy) 2.0)))
(*
(sqrt
(*
(*
(-
(/
(- (/ (* (- (/ 2.0 ux) 1.0) ux) maxCos) (* (- (/ 2.0 ux) 2.0) ux))
maxCos)
ux)
(* maxCos maxCos))
ux))
(cos (* (PI) (* 2.0 uy))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 9.999999717180685 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{\left(ux - ux \cdot ux\right) + ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{\frac{\left(\frac{2}{ux} - 1\right) \cdot ux}{maxCos} - \left(\frac{2}{ux} - 2\right) \cdot ux}{maxCos} - ux\right) \cdot \left(maxCos \cdot maxCos\right)\right) \cdot ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if maxCos < 9.99999972e-10Initial program 59.6%
Taylor expanded in uy around 0
Applied rewrites51.6%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites51.4%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.8
Applied rewrites98.8%
Applied rewrites98.8%
if 9.99999972e-10 < maxCos Initial program 61.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3259.2
Applied rewrites59.3%
Applied rewrites59.3%
Taylor expanded in maxCos around -inf
Applied rewrites98.9%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 2.2000000043931323e-8)
(* (cos (* (* (PI) uy) 2.0)) (sqrt (+ (* (- 1.0 ux) ux) ux)))
(*
(sqrt
(*
(*
(-
(*
(-
(/ (- (/ 2.0 ux) 1.0) (* maxCos maxCos))
(/ (- (/ 2.0 ux) 2.0) maxCos))
ux)
ux)
(* maxCos maxCos))
ux))
(cos (* (PI) (* 2.0 uy))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 2.2000000043931323 \cdot 10^{-8}:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\left(\frac{\frac{2}{ux} - 1}{maxCos \cdot maxCos} - \frac{\frac{2}{ux} - 2}{maxCos}\right) \cdot ux - ux\right) \cdot \left(maxCos \cdot maxCos\right)\right) \cdot ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if maxCos < 2.2e-8Initial program 60.5%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites52.2%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.8
Applied rewrites98.8%
if 2.2e-8 < maxCos Initial program 58.4%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3255.3
Applied rewrites55.3%
Applied rewrites55.2%
Taylor expanded in maxCos around inf
Applied rewrites98.7%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 9.999999747378752e-6)
(* (cos (* (* (PI) uy) 2.0)) (sqrt (+ (* (- 1.0 ux) ux) ux)))
(*
(sqrt
(*
(-
(*
(-
(/ (- (/ 2.0 ux) 1.0) (* maxCos maxCos))
(/ (- (/ 2.0 ux) 2.0) maxCos))
(* ux ux))
(* ux ux))
(* maxCos maxCos)))
1.0)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{\frac{2}{ux} - 1}{maxCos \cdot maxCos} - \frac{\frac{2}{ux} - 2}{maxCos}\right) \cdot \left(ux \cdot ux\right) - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot 1\\
\end{array}
\end{array}
if maxCos < 9.99999975e-6Initial program 60.5%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites52.1%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.4
Applied rewrites98.4%
if 9.99999975e-6 < maxCos Initial program 56.7%
Taylor expanded in uy around 0
Applied rewrites51.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3252.3
Applied rewrites51.5%
Taylor expanded in maxCos around inf
Applied rewrites84.3%
Final simplification96.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 9.999999747378752e-6)
(* (sqrt (* (- 2.0 ux) ux)) (cos (* (* (PI) uy) 2.0)))
(*
(sqrt
(*
(-
(*
(-
(/ (- (/ 2.0 ux) 1.0) (* maxCos maxCos))
(/ (- (/ 2.0 ux) 2.0) maxCos))
(* ux ux))
(* ux ux))
(* maxCos maxCos)))
1.0)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{\left(2 - ux\right) \cdot ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{\frac{2}{ux} - 1}{maxCos \cdot maxCos} - \frac{\frac{2}{ux} - 2}{maxCos}\right) \cdot \left(ux \cdot ux\right) - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot 1\\
\end{array}
\end{array}
if maxCos < 9.99999975e-6Initial program 60.5%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites52.2%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.4
Applied rewrites98.4%
Taylor expanded in ux around 0
Applied rewrites98.3%
if 9.99999975e-6 < maxCos Initial program 56.7%
Taylor expanded in uy around 0
Applied rewrites51.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3252.3
Applied rewrites51.5%
Taylor expanded in maxCos around inf
Applied rewrites84.3%
Final simplification96.7%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(-
(* (- (/ 2.0 ux) (- (/ maxCos ux) (- maxCos 1.0))) (* ux ux))
(* (* (fma maxCos ux (- 1.0 ux)) maxCos) ux)))
1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf(((((2.0f / ux) - ((maxCos / ux) - (maxCos - 1.0f))) * (ux * ux)) - ((fmaf(maxCos, ux, (1.0f - ux)) * maxCos) * ux))) * 1.0f;
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(Float32(Float32(Float32(2.0) / ux) - Float32(Float32(maxCos / ux) - Float32(maxCos - Float32(1.0)))) * Float32(ux * ux)) - Float32(Float32(fma(maxCos, ux, Float32(Float32(1.0) - ux)) * maxCos) * ux))) * Float32(1.0)) end
\begin{array}{l}
\\
\sqrt{\left(\frac{2}{ux} - \left(\frac{maxCos}{ux} - \left(maxCos - 1\right)\right)\right) \cdot \left(ux \cdot ux\right) - \left(\mathsf{fma}\left(maxCos, ux, 1 - ux\right) \cdot maxCos\right) \cdot ux} \cdot 1
\end{array}
Initial program 60.1%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
associate--r+N/A
lower--.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
Applied rewrites30.0%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f32N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower-/.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3279.8
Applied rewrites79.8%
Final simplification79.8%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(-
(* (- (/ (- 2.0 maxCos) ux) (- 1.0 maxCos)) (* ux ux))
(* (* (fma maxCos ux (- 1.0 ux)) maxCos) ux)))
1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((((((2.0f - maxCos) / ux) - (1.0f - maxCos)) * (ux * ux)) - ((fmaf(maxCos, ux, (1.0f - ux)) * maxCos) * ux))) * 1.0f;
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(Float32(Float32(Float32(Float32(2.0) - maxCos) / ux) - Float32(Float32(1.0) - maxCos)) * Float32(ux * ux)) - Float32(Float32(fma(maxCos, ux, Float32(Float32(1.0) - ux)) * maxCos) * ux))) * Float32(1.0)) end
\begin{array}{l}
\\
\sqrt{\left(\frac{2 - maxCos}{ux} - \left(1 - maxCos\right)\right) \cdot \left(ux \cdot ux\right) - \left(\mathsf{fma}\left(maxCos, ux, 1 - ux\right) \cdot maxCos\right) \cdot ux} \cdot 1
\end{array}
Initial program 60.1%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
associate--r+N/A
lower--.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
Applied rewrites30.5%
Taylor expanded in ux around -inf
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-*r/N/A
metadata-evalN/A
div-subN/A
sub-negN/A
mul-1-negN/A
lower--.f32N/A
lower-/.f32N/A
mul-1-negN/A
sub-negN/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
unpow2N/A
lower-*.f3279.8
Applied rewrites79.8%
Final simplification79.8%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (+ (* (- 1.0 ux) ux) ux)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((((1.0f - ux) * ux) + ux)) * 1.0f;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((((1.0e0 - ux) * ux) + ux)) * 1.0e0
end function
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(Float32(Float32(1.0) - ux) * ux) + ux)) * Float32(1.0)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(1.0) - ux) * ux) + ux)) * single(1.0); end
\begin{array}{l}
\\
\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot 1
\end{array}
Initial program 60.1%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites50.7%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3276.7
Applied rewrites76.7%
Final simplification76.7%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux)) * 1.0f;
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) * Float32(1.0)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot 1
\end{array}
Initial program 60.1%
Taylor expanded in uy around 0
Applied rewrites52.4%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3260.9
Applied rewrites60.5%
Final simplification60.6%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma (- 1.0 ux) ux ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf((1.0f - ux), ux, ux));
}
function code(ux, uy, maxCos) return sqrt(fma(Float32(Float32(1.0) - ux), ux, ux)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(1 - ux, ux, ux\right)}
\end{array}
Initial program 60.1%
Taylor expanded in uy around 0
Applied rewrites52.4%
lift--.f32N/A
lift-*.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
lift-neg.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-+.f32N/A
lift-+.f32N/A
cancel-sign-sub-invN/A
lift-+.f32N/A
distribute-rgt-inN/A
Applied rewrites50.7%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3293.6
Applied rewrites93.6%
Taylor expanded in uy around 0
Applied rewrites30.6%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (- 1.0 1.0)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - 1.0f)) * 1.0f;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((1.0e0 - 1.0e0)) * 1.0e0
end function
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(1.0) - Float32(1.0))) * Float32(1.0)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(1.0) - single(1.0))) * single(1.0); end
\begin{array}{l}
\\
\sqrt{1 - 1} \cdot 1
\end{array}
Initial program 60.1%
Taylor expanded in uy around 0
Applied rewrites52.4%
Taylor expanded in ux around 0
Applied rewrites6.6%
Final simplification6.6%
herbie shell --seed 2024268
(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)))))))