
(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 13 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
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= maxCos 9.000000034120603e-8)
(* (sqrt (+ (* (- 1.0 ux) ux) ux)) t_0)
(*
(sqrt
(*
(-
(*
(- (/ (+ (/ -1.0 maxCos) 2.0) maxCos) 1.0)
(* (* maxCos maxCos) ux))
(* (- 2.0 (/ 2.0 maxCos)) maxCos))
ux))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;maxCos \leq 9.000000034120603 \cdot 10^{-8}:\\
\;\;\;\;\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{\frac{-1}{maxCos} + 2}{maxCos} - 1\right) \cdot \left(\left(maxCos \cdot maxCos\right) \cdot ux\right) - \left(2 - \frac{2}{maxCos}\right) \cdot maxCos\right) \cdot ux} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 9.00000003e-8Initial program 56.4%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
Applied rewrites39.8%
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--.f3299.0
Applied rewrites99.0%
if 9.00000003e-8 < maxCos Initial program 51.1%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3251.4
lift-*.f32N/A
*-commutativeN/A
lower-*.f3251.4
Applied rewrites51.4%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites49.3%
Taylor expanded in ux around 0
Applied rewrites98.8%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (+ -1.0 ux) (* ux maxCos)))
(t_1 (cos (* (PI) (* 2.0 uy))))
(t_2 (* (+ (/ (- 1.0 ux) maxCos) ux) maxCos)))
(if (<= (* (sqrt (- 1.0 (* t_0 t_0))) t_1) 0.013700000010430813)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_1)
(* (sqrt (- 1.0 (- t_2 (* (- ux (* ux maxCos)) t_2)))) 1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-1 + ux\right) - ux \cdot maxCos\\
t_1 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_2 := \left(\frac{1 - ux}{maxCos} + ux\right) \cdot maxCos\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot t\_1 \leq 0.013700000010430813:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(t\_2 - \left(ux - ux \cdot maxCos\right) \cdot t\_2\right)} \cdot 1\\
\end{array}
\end{array}
if (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (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.0137Initial program 39.3%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
Applied rewrites22.9%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3263.0
Applied rewrites63.0%
if 0.0137 < (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (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 88.6%
Taylor expanded in uy around 0
Applied rewrites76.9%
Taylor expanded in maxCos around inf
*-commutativeN/A
lower-*.f32N/A
associate--l+N/A
div-subN/A
lower-+.f32N/A
lower-/.f32N/A
lower--.f3276.9
Applied rewrites76.9%
lift-*.f32N/A
*-commutativeN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lift--.f32N/A
sub-negN/A
distribute-lft-inN/A
lower-+.f32N/A
Applied rewrites77.7%
Final simplification68.0%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* ux ux) (- (/ (+ (* maxCos -2.0) 2.0) ux) (pow (- maxCos 1.0) 2.0)))) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{maxCos \cdot -2 + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 55.5%
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-*.f3268.2
Applied rewrites68.2%
Applied rewrites98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (+ (/ (- 1.0 ux) maxCos) ux) maxCos))
(t_1 (- (+ -1.0 ux) (* ux maxCos)))
(t_2 (- ux (* ux maxCos))))
(if (<=
(* (sqrt (- 1.0 (* t_1 t_1))) (cos (* (PI) (* 2.0 uy))))
0.013700000010430813)
(*
(sqrt (- t_2 (* (* (fma (- maxCos 1.0) ux 1.0) ux) (- maxCos 1.0))))
1.0)
(* (sqrt (- 1.0 (- t_0 (* t_2 t_0)))) 1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\frac{1 - ux}{maxCos} + ux\right) \cdot maxCos\\
t_1 := \left(-1 + ux\right) - ux \cdot maxCos\\
t_2 := ux - ux \cdot maxCos\\
\mathbf{if}\;\sqrt{1 - t\_1 \cdot t\_1} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.013700000010430813:\\
\;\;\;\;\sqrt{t\_2 - \left(\mathsf{fma}\left(maxCos - 1, ux, 1\right) \cdot ux\right) \cdot \left(maxCos - 1\right)} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(t\_0 - t\_2 \cdot t\_0\right)} \cdot 1\\
\end{array}
\end{array}
if (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (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.0137Initial program 39.3%
Taylor expanded in uy around 0
Applied rewrites32.1%
Applied rewrites72.8%
if 0.0137 < (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (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 88.6%
Taylor expanded in uy around 0
Applied rewrites76.9%
Taylor expanded in maxCos around inf
*-commutativeN/A
lower-*.f32N/A
associate--l+N/A
div-subN/A
lower-+.f32N/A
lower-/.f32N/A
lower--.f3276.9
Applied rewrites76.9%
lift-*.f32N/A
*-commutativeN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lift--.f32N/A
sub-negN/A
distribute-lft-inN/A
lower-+.f32N/A
Applied rewrites77.7%
Final simplification71.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= maxCos 3.2000000373955118e-6)
(* (sqrt (+ (* (- 1.0 ux) ux) ux)) t_0)
(* (sqrt (* (- (/ 2.0 maxCos) 2.0) (* ux maxCos))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;maxCos \leq 3.2000000373955118 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{2}{maxCos} - 2\right) \cdot \left(ux \cdot maxCos\right)} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 3.20000004e-6Initial program 56.2%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
Applied rewrites39.8%
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--.f3298.8
Applied rewrites98.8%
if 3.20000004e-6 < maxCos Initial program 51.1%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3251.5
lift-*.f32N/A
*-commutativeN/A
lower-*.f3251.5
Applied rewrites51.5%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites49.3%
Taylor expanded in ux around 0
Applied rewrites80.7%
Final simplification96.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (+ (* (- 1.0 ux) ux) ux)) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 55.5%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
Applied rewrites37.4%
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--.f3292.8
Applied rewrites92.8%
Final simplification92.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (* ux maxCos) (+ -1.0 ux))))
(if (<= t_0 0.9998875260353088)
(* (sqrt (- 1.0 (* (- (* (- maxCos 1.0) ux) -1.0) t_0))) 1.0)
(*
(sqrt
(-
(- ux (* ux maxCos))
(* (* (fma (- maxCos 1.0) ux 1.0) ux) (- maxCos 1.0))))
1.0))))
float code(float ux, float uy, float maxCos) {
float t_0 = (ux * maxCos) - (-1.0f + ux);
float tmp;
if (t_0 <= 0.9998875260353088f) {
tmp = sqrtf((1.0f - ((((maxCos - 1.0f) * ux) - -1.0f) * t_0))) * 1.0f;
} else {
tmp = sqrtf(((ux - (ux * maxCos)) - ((fmaf((maxCos - 1.0f), ux, 1.0f) * ux) * (maxCos - 1.0f)))) * 1.0f;
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(ux * maxCos) - Float32(Float32(-1.0) + ux)) tmp = Float32(0.0) if (t_0 <= Float32(0.9998875260353088)) tmp = Float32(sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(Float32(maxCos - Float32(1.0)) * ux) - Float32(-1.0)) * t_0))) * Float32(1.0)); else tmp = Float32(sqrt(Float32(Float32(ux - Float32(ux * maxCos)) - Float32(Float32(fma(Float32(maxCos - Float32(1.0)), ux, Float32(1.0)) * ux) * Float32(maxCos - Float32(1.0))))) * Float32(1.0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos - \left(-1 + ux\right)\\
\mathbf{if}\;t\_0 \leq 0.9998875260353088:\\
\;\;\;\;\sqrt{1 - \left(\left(maxCos - 1\right) \cdot ux - -1\right) \cdot t\_0} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(ux - ux \cdot maxCos\right) - \left(\mathsf{fma}\left(maxCos - 1, ux, 1\right) \cdot ux\right) \cdot \left(maxCos - 1\right)} \cdot 1\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999887526Initial program 88.9%
Taylor expanded in uy around 0
Applied rewrites69.8%
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
neg-mul-1N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-*.f32N/A
*-commutativeN/A
distribute-lft-inN/A
lift-+.f32N/A
lift-*.f32N/A
+-commutativeN/A
lower-+.f3269.8
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lift--.f32N/A
*-commutativeN/A
lower-*.f3269.8
Applied rewrites69.8%
if 0.999887526 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 37.1%
Taylor expanded in uy around 0
Applied rewrites34.1%
Applied rewrites76.7%
Final simplification73.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (* ux maxCos) (+ -1.0 ux))))
(if (<= t_0 0.9998875260353088)
(* (sqrt (- 1.0 (* (- (* (- maxCos 1.0) ux) -1.0) t_0))) 1.0)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) 1.0))))
float code(float ux, float uy, float maxCos) {
float t_0 = (ux * maxCos) - (-1.0f + ux);
float tmp;
if (t_0 <= 0.9998875260353088f) {
tmp = sqrtf((1.0f - ((((maxCos - 1.0f) * ux) - -1.0f) * t_0))) * 1.0f;
} else {
tmp = sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux)) * 1.0f;
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(ux * maxCos) - Float32(Float32(-1.0) + ux)) tmp = Float32(0.0) if (t_0 <= Float32(0.9998875260353088)) tmp = Float32(sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(Float32(maxCos - Float32(1.0)) * ux) - Float32(-1.0)) * t_0))) * Float32(1.0)); else tmp = Float32(sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) * Float32(1.0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos - \left(-1 + ux\right)\\
\mathbf{if}\;t\_0 \leq 0.9998875260353088:\\
\;\;\;\;\sqrt{1 - \left(\left(maxCos - 1\right) \cdot ux - -1\right) \cdot t\_0} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot 1\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999887526Initial program 88.9%
Taylor expanded in uy around 0
Applied rewrites69.8%
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
neg-mul-1N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+r+N/A
lift-*.f32N/A
*-commutativeN/A
distribute-lft-inN/A
lift-+.f32N/A
lift-*.f32N/A
+-commutativeN/A
lower-+.f3269.8
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lift--.f32N/A
*-commutativeN/A
lower-*.f3269.8
Applied rewrites69.8%
if 0.999887526 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 37.1%
Taylor expanded in uy around 0
Applied rewrites34.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3274.1
Applied rewrites73.9%
Final simplification72.6%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (- (* ux maxCos) (+ -1.0 ux)) 0.9998875260353088) (* (sqrt (- 1.0 (* (- 1.0 ux) (- (- (* ux maxCos) ux) -1.0)))) 1.0) (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) 1.0)))
float code(float ux, float uy, float maxCos) {
float tmp;
if (((ux * maxCos) - (-1.0f + ux)) <= 0.9998875260353088f) {
tmp = sqrtf((1.0f - ((1.0f - ux) * (((ux * maxCos) - ux) - -1.0f)))) * 1.0f;
} else {
tmp = sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux)) * 1.0f;
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(ux * maxCos) - Float32(Float32(-1.0) + ux)) <= Float32(0.9998875260353088)) tmp = Float32(sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * Float32(Float32(Float32(ux * maxCos) - ux) - Float32(-1.0))))) * Float32(1.0)); else tmp = Float32(sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) * Float32(1.0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \cdot maxCos - \left(-1 + ux\right) \leq 0.9998875260353088:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos - ux\right) - -1\right)} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot 1\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999887526Initial program 88.9%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3288.9
lift-*.f32N/A
*-commutativeN/A
lower-*.f3288.9
Applied rewrites88.9%
lift--.f32N/A
lift--.f32N/A
associate--r-N/A
lift-/.f32N/A
lift-/.f32N/A
sub-divN/A
metadata-evalN/A
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
flip--N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-+l-N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower--.f3289.0
lift-*.f32N/A
*-commutativeN/A
lift-*.f3289.0
Applied rewrites89.0%
Taylor expanded in maxCos around 0
lower--.f3284.0
Applied rewrites84.0%
Taylor expanded in uy around 0
Applied rewrites66.6%
if 0.999887526 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 37.1%
Taylor expanded in uy around 0
Applied rewrites34.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3274.1
Applied rewrites73.9%
Final simplification71.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (* ux maxCos) (+ -1.0 ux))))
(if (<= t_0 0.9998875260353088)
(* (sqrt (- 1.0 (* (- 1.0 ux) t_0))) 1.0)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) 1.0))))
float code(float ux, float uy, float maxCos) {
float t_0 = (ux * maxCos) - (-1.0f + ux);
float tmp;
if (t_0 <= 0.9998875260353088f) {
tmp = sqrtf((1.0f - ((1.0f - ux) * t_0))) * 1.0f;
} else {
tmp = sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux)) * 1.0f;
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(ux * maxCos) - Float32(Float32(-1.0) + ux)) tmp = Float32(0.0) if (t_0 <= Float32(0.9998875260353088)) tmp = Float32(sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * t_0))) * Float32(1.0)); else tmp = Float32(sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) * Float32(1.0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos - \left(-1 + ux\right)\\
\mathbf{if}\;t\_0 \leq 0.9998875260353088:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot t\_0} \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot 1\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999887526Initial program 88.9%
Taylor expanded in uy around 0
Applied rewrites69.8%
Taylor expanded in maxCos around 0
lower--.f3266.6
Applied rewrites66.6%
if 0.999887526 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 37.1%
Taylor expanded in uy around 0
Applied rewrites34.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3274.1
Applied rewrites73.9%
Final simplification71.2%
(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 55.5%
Taylor expanded in uy around 0
Applied rewrites46.8%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3263.8
Applied rewrites63.6%
Final simplification59.9%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (fma -1.0 1.0 1.0)) 1.0))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(-1.0f, 1.0f, 1.0f)) * 1.0f;
}
function code(ux, uy, maxCos) return Float32(sqrt(fma(Float32(-1.0), Float32(1.0), Float32(1.0))) * Float32(1.0)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-1, 1, 1\right)} \cdot 1
\end{array}
Initial program 55.5%
Taylor expanded in uy around 0
Applied rewrites46.8%
Taylor expanded in ux around 0
Applied rewrites6.6%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
neg-mul-1N/A
lower-fma.f3219.3
Applied rewrites19.3%
Final simplification19.0%
(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 55.5%
Taylor expanded in uy around 0
Applied rewrites46.8%
Taylor expanded in ux around 0
Applied rewrites6.6%
Final simplification6.6%
herbie shell --seed 2024277
(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)))))))