
(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))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))) end
function tmp = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\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))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))) end
function tmp = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t_0 \cdot t_0}
\end{array}
\end{array}
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(-
(* ux (+ (- 2.0 ux) (* maxCos (fma 2.0 ux -2.0))))
(* (* ux ux) (* maxCos maxCos))))
(cos (* (* 2.0 uy) PI))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * ((2.0f - ux) + (maxCos * fmaf(2.0f, ux, -2.0f)))) - ((ux * ux) * (maxCos * maxCos)))) * cosf(((2.0f * uy) * ((float) M_PI)));
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(ux * Float32(Float32(Float32(2.0) - ux) + Float32(maxCos * fma(Float32(2.0), ux, Float32(-2.0))))) - Float32(Float32(ux * ux) * Float32(maxCos * maxCos)))) * cos(Float32(Float32(Float32(2.0) * uy) * Float32(pi)))) end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 - ux\right) + maxCos \cdot \mathsf{fma}\left(2, ux, -2\right)\right) - \left(ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot \cos \left(\left(2 \cdot uy\right) \cdot \pi\right)
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in ux around -inf 99.1%
metadata-eval99.1%
cancel-sign-sub-inv99.1%
*-commutative99.1%
fma-def99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
+-commutative99.1%
*-commutative99.1%
fma-def99.1%
mul-1-neg99.1%
distribute-rgt-neg-in99.1%
unpow299.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
pow199.1%
associate-*l*99.1%
Applied egg-rr99.1%
unpow199.1%
*-commutative99.1%
fma-udef99.1%
fma-udef99.1%
*-commutative99.1%
+-commutative99.1%
*-commutative99.1%
distribute-lft-out99.1%
+-commutative99.1%
fma-def99.1%
distribute-rgt-neg-out99.1%
distribute-lft-neg-in99.1%
associate-*r*99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 99.1%
associate-+r+99.0%
mul-1-neg99.0%
unsub-neg99.0%
associate-*r*99.1%
distribute-rgt-out99.1%
neg-mul-199.1%
+-commutative99.1%
unsub-neg99.1%
fma-neg99.1%
metadata-eval99.1%
*-commutative99.1%
unpow299.1%
unpow299.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (* 2.0 uy) PI))))
(if (<= t_0 0.9999998211860657)
(* t_0 (sqrt (- (* ux 2.0) (* ux ux))))
(sqrt
(* ux (+ 2.0 (- (* maxCos -2.0) (* ux (pow (- 1.0 maxCos) 2.0)))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = cosf(((2.0f * uy) * ((float) M_PI)));
float tmp;
if (t_0 <= 0.9999998211860657f) {
tmp = t_0 * sqrtf(((ux * 2.0f) - (ux * ux)));
} else {
tmp = sqrtf((ux * (2.0f + ((maxCos * -2.0f) - (ux * powf((1.0f - maxCos), 2.0f))))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = cos(Float32(Float32(Float32(2.0) * uy) * Float32(pi))) tmp = Float32(0.0) if (t_0 <= Float32(0.9999998211860657)) tmp = Float32(t_0 * sqrt(Float32(Float32(ux * Float32(2.0)) - Float32(ux * ux)))); else tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos * Float32(-2.0)) - Float32(ux * (Float32(Float32(1.0) - maxCos) ^ Float32(2.0))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = cos(((single(2.0) * uy) * single(pi))); tmp = single(0.0); if (t_0 <= single(0.9999998211860657)) tmp = t_0 * sqrt(((ux * single(2.0)) - (ux * ux))); else tmp = sqrt((ux * (single(2.0) + ((maxCos * single(-2.0)) - (ux * ((single(1.0) - maxCos) ^ single(2.0))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot uy\right) \cdot \pi\right)\\
\mathbf{if}\;t_0 \leq 0.9999998211860657:\\
\;\;\;\;t_0 \cdot \sqrt{ux \cdot 2 - ux \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(maxCos \cdot -2 - ux \cdot {\left(1 - maxCos\right)}^{2}\right)\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999999821Initial program 55.5%
associate-*l*55.5%
+-commutative55.5%
associate-+r-55.5%
fma-def55.5%
+-commutative55.5%
associate-+r-55.4%
fma-def55.4%
Simplified55.4%
Taylor expanded in ux around -inf 98.5%
metadata-eval98.5%
cancel-sign-sub-inv98.5%
*-commutative98.5%
fma-def98.5%
cancel-sign-sub-inv98.5%
metadata-eval98.5%
+-commutative98.5%
*-commutative98.5%
fma-def98.5%
mul-1-neg98.5%
distribute-rgt-neg-in98.5%
unpow298.5%
mul-1-neg98.5%
unsub-neg98.5%
Simplified98.5%
Taylor expanded in maxCos around 0 91.8%
associate-*r*91.8%
+-commutative91.8%
mul-1-neg91.8%
unsub-neg91.8%
unpow291.8%
Simplified91.8%
if 0.999999821 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 59.5%
associate-*l*59.5%
+-commutative59.5%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around -inf 99.5%
metadata-eval99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
fma-def99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
+-commutative99.6%
*-commutative99.6%
fma-def99.6%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
unpow299.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
pow199.6%
associate-*l*99.6%
Applied egg-rr99.6%
unpow199.6%
*-commutative99.6%
fma-udef99.5%
fma-udef99.5%
*-commutative99.5%
+-commutative99.5%
*-commutative99.5%
distribute-lft-out99.6%
+-commutative99.6%
fma-def99.6%
distribute-rgt-neg-out99.6%
distribute-lft-neg-in99.6%
associate-*r*99.6%
Simplified99.6%
Taylor expanded in uy around 0 99.5%
Final simplification96.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (* 2.0 uy) PI))))
(if (<= t_0 0.9999998211860657)
(* t_0 (sqrt (- (* ux 2.0) (* ux ux))))
(sqrt (* ux (- (fma -2.0 maxCos 2.0) (* ux (pow (- 1.0 maxCos) 2.0))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = cosf(((2.0f * uy) * ((float) M_PI)));
float tmp;
if (t_0 <= 0.9999998211860657f) {
tmp = t_0 * sqrtf(((ux * 2.0f) - (ux * ux)));
} else {
tmp = sqrtf((ux * (fmaf(-2.0f, maxCos, 2.0f) - (ux * powf((1.0f - maxCos), 2.0f)))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = cos(Float32(Float32(Float32(2.0) * uy) * Float32(pi))) tmp = Float32(0.0) if (t_0 <= Float32(0.9999998211860657)) tmp = Float32(t_0 * sqrt(Float32(Float32(ux * Float32(2.0)) - Float32(ux * ux)))); else tmp = sqrt(Float32(ux * Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) - Float32(ux * (Float32(Float32(1.0) - maxCos) ^ Float32(2.0)))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot uy\right) \cdot \pi\right)\\
\mathbf{if}\;t_0 \leq 0.9999998211860657:\\
\;\;\;\;t_0 \cdot \sqrt{ux \cdot 2 - ux \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) - ux \cdot {\left(1 - maxCos\right)}^{2}\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999999821Initial program 55.5%
associate-*l*55.5%
+-commutative55.5%
associate-+r-55.5%
fma-def55.5%
+-commutative55.5%
associate-+r-55.4%
fma-def55.4%
Simplified55.4%
Taylor expanded in ux around -inf 98.5%
metadata-eval98.5%
cancel-sign-sub-inv98.5%
*-commutative98.5%
fma-def98.5%
cancel-sign-sub-inv98.5%
metadata-eval98.5%
+-commutative98.5%
*-commutative98.5%
fma-def98.5%
mul-1-neg98.5%
distribute-rgt-neg-in98.5%
unpow298.5%
mul-1-neg98.5%
unsub-neg98.5%
Simplified98.5%
Taylor expanded in maxCos around 0 91.8%
associate-*r*91.8%
+-commutative91.8%
mul-1-neg91.8%
unsub-neg91.8%
unpow291.8%
Simplified91.8%
if 0.999999821 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 59.5%
associate-*l*59.5%
+-commutative59.5%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around -inf 99.5%
metadata-eval99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
fma-def99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
+-commutative99.6%
*-commutative99.6%
fma-def99.6%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
unpow299.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
Taylor expanded in uy around 0 99.4%
fma-def99.4%
+-commutative99.4%
mul-1-neg99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
unpow299.4%
associate-*r*99.4%
fma-def99.4%
*-commutative99.4%
distribute-lft-out99.5%
+-commutative99.5%
fma-def99.5%
distribute-rgt-neg-out99.5%
distribute-lft-neg-in99.5%
Simplified99.5%
Final simplification96.1%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (cos (* (* 2.0 uy) PI)) 0.9999998211860657) (* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 ux)))) (sqrt (* ux (+ 2.0 (- (* maxCos -2.0) (* ux (pow (- 1.0 maxCos) 2.0))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (cosf(((2.0f * uy) * ((float) M_PI))) <= 0.9999998211860657f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
} else {
tmp = sqrtf((ux * (2.0f + ((maxCos * -2.0f) - (ux * powf((1.0f - maxCos), 2.0f))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (cos(Float32(Float32(Float32(2.0) * uy) * Float32(pi))) <= Float32(0.9999998211860657)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); else tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos * Float32(-2.0)) - Float32(ux * (Float32(Float32(1.0) - maxCos) ^ Float32(2.0))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (cos(((single(2.0) * uy) * single(pi))) <= single(0.9999998211860657)) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - ux))); else tmp = sqrt((ux * (single(2.0) + ((maxCos * single(-2.0)) - (ux * ((single(1.0) - maxCos) ^ single(2.0))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\left(2 \cdot uy\right) \cdot \pi\right) \leq 0.9999998211860657:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(maxCos \cdot -2 - ux \cdot {\left(1 - maxCos\right)}^{2}\right)\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999999821Initial program 55.5%
associate-*l*55.5%
+-commutative55.5%
associate-+r-55.5%
fma-def55.5%
+-commutative55.5%
associate-+r-55.4%
fma-def55.4%
Simplified55.4%
Taylor expanded in ux around 0 98.5%
cancel-sign-sub-inv98.5%
metadata-eval98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
*-commutative98.5%
fma-def98.5%
sub-neg98.5%
metadata-eval98.5%
unpow298.5%
Simplified98.5%
Taylor expanded in maxCos around 0 91.8%
unpow291.8%
distribute-rgt-out--91.8%
Simplified91.8%
if 0.999999821 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 59.5%
associate-*l*59.5%
+-commutative59.5%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around -inf 99.5%
metadata-eval99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
fma-def99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
+-commutative99.6%
*-commutative99.6%
fma-def99.6%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
unpow299.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
pow199.6%
associate-*l*99.6%
Applied egg-rr99.6%
unpow199.6%
*-commutative99.6%
fma-udef99.5%
fma-udef99.5%
*-commutative99.5%
+-commutative99.5%
*-commutative99.5%
distribute-lft-out99.6%
+-commutative99.6%
fma-def99.6%
distribute-rgt-neg-out99.6%
distribute-lft-neg-in99.6%
associate-*r*99.6%
Simplified99.6%
Taylor expanded in uy around 0 99.5%
Final simplification96.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* (* 2.0 uy) PI))
(sqrt
(*
ux
(+ (fma -2.0 maxCos 2.0) (* ux (* (- 1.0 maxCos) (+ maxCos -1.0))))))))
float code(float ux, float uy, float maxCos) {
return cosf(((2.0f * uy) * ((float) M_PI))) * sqrtf((ux * (fmaf(-2.0f, maxCos, 2.0f) + (ux * ((1.0f - maxCos) * (maxCos + -1.0f))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(Float32(2.0) * uy) * Float32(pi))) * sqrt(Float32(ux * Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0)))))))) end
\begin{array}{l}
\\
\cos \left(\left(2 \cdot uy\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + ux \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in ux around -inf 99.1%
metadata-eval99.1%
cancel-sign-sub-inv99.1%
*-commutative99.1%
fma-def99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
+-commutative99.1%
*-commutative99.1%
fma-def99.1%
mul-1-neg99.1%
distribute-rgt-neg-in99.1%
unpow299.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
pow199.1%
associate-*l*99.1%
Applied egg-rr99.1%
unpow199.1%
*-commutative99.1%
fma-udef99.1%
fma-udef99.1%
*-commutative99.1%
+-commutative99.1%
*-commutative99.1%
distribute-lft-out99.1%
+-commutative99.1%
fma-def99.1%
distribute-rgt-neg-out99.1%
distribute-lft-neg-in99.1%
associate-*r*99.1%
Simplified99.1%
unpow299.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* 2.0 uy) PI)) (sqrt (+ (* ux (- 2.0 ux)) (* maxCos (* ux (- (* ux 2.0) 2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf(((2.0f * uy) * ((float) M_PI))) * sqrtf(((ux * (2.0f - ux)) + (maxCos * (ux * ((ux * 2.0f) - 2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(Float32(2.0) * uy) * Float32(pi))) * sqrt(Float32(Float32(ux * Float32(Float32(2.0) - ux)) + Float32(maxCos * Float32(ux * Float32(Float32(ux * Float32(2.0)) - Float32(2.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((single(2.0) * uy) * single(pi))) * sqrt(((ux * (single(2.0) - ux)) + (maxCos * (ux * ((ux * single(2.0)) - single(2.0)))))); end
\begin{array}{l}
\\
\cos \left(\left(2 \cdot uy\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - ux\right) + maxCos \cdot \left(ux \cdot \left(ux \cdot 2 - 2\right)\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in ux around -inf 99.1%
metadata-eval99.1%
cancel-sign-sub-inv99.1%
*-commutative99.1%
fma-def99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
+-commutative99.1%
*-commutative99.1%
fma-def99.1%
mul-1-neg99.1%
distribute-rgt-neg-in99.1%
unpow299.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
pow199.1%
associate-*l*99.1%
Applied egg-rr99.1%
unpow199.1%
*-commutative99.1%
fma-udef99.1%
fma-udef99.1%
*-commutative99.1%
+-commutative99.1%
*-commutative99.1%
distribute-lft-out99.1%
+-commutative99.1%
fma-def99.1%
distribute-rgt-neg-out99.1%
distribute-lft-neg-in99.1%
associate-*r*99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 97.9%
Final simplification97.9%
(FPCore (ux uy maxCos) :precision binary32 (if (<= uy 0.0015999999595806003) (sqrt (* ux (+ 2.0 (- (* maxCos -2.0) (* ux (pow (- 1.0 maxCos) 2.0)))))) (* (cos (* uy (* 2.0 PI))) (sqrt (* ux 2.0)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.0015999999595806003f) {
tmp = sqrtf((ux * (2.0f + ((maxCos * -2.0f) - (ux * powf((1.0f - maxCos), 2.0f))))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * 2.0f));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.0015999999595806003)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos * Float32(-2.0)) - Float32(ux * (Float32(Float32(1.0) - maxCos) ^ Float32(2.0))))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(2.0)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(0.0015999999595806003)) tmp = sqrt((ux * (single(2.0) + ((maxCos * single(-2.0)) - (ux * ((single(1.0) - maxCos) ^ single(2.0))))))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * single(2.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.0015999999595806003:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(maxCos \cdot -2 - ux \cdot {\left(1 - maxCos\right)}^{2}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot 2}\\
\end{array}
\end{array}
if uy < 0.00159999996Initial program 59.4%
associate-*l*59.4%
+-commutative59.4%
associate-+r-59.2%
fma-def59.2%
+-commutative59.2%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around -inf 99.5%
metadata-eval99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
fma-def99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
+-commutative99.5%
*-commutative99.5%
fma-def99.5%
mul-1-neg99.5%
distribute-rgt-neg-in99.5%
unpow299.5%
mul-1-neg99.5%
unsub-neg99.5%
Simplified99.5%
pow199.5%
associate-*l*99.5%
Applied egg-rr99.5%
unpow199.5%
*-commutative99.5%
fma-udef99.5%
fma-udef99.5%
*-commutative99.5%
+-commutative99.5%
*-commutative99.5%
distribute-lft-out99.5%
+-commutative99.5%
fma-def99.5%
distribute-rgt-neg-out99.5%
distribute-lft-neg-in99.5%
associate-*r*99.5%
Simplified99.5%
Taylor expanded in uy around 0 96.0%
if 0.00159999996 < uy Initial program 53.6%
associate-*l*53.6%
+-commutative53.6%
associate-+r-53.6%
fma-def53.6%
+-commutative53.6%
associate-+r-53.5%
fma-def53.5%
Simplified53.5%
Taylor expanded in ux around 0 43.0%
Taylor expanded in maxCos around 0 75.4%
Final simplification90.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 2.0 (- (* maxCos -2.0) (* ux (pow (- 1.0 maxCos) 2.0)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f + ((maxCos * -2.0f) - (ux * powf((1.0f - maxCos), 2.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((ux * (2.0e0 + ((maxcos * (-2.0e0)) - (ux * ((1.0e0 - maxcos) ** 2.0e0))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos * Float32(-2.0)) - Float32(ux * (Float32(Float32(1.0) - maxCos) ^ Float32(2.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) + ((maxCos * single(-2.0)) - (ux * ((single(1.0) - maxCos) ^ single(2.0))))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 + \left(maxCos \cdot -2 - ux \cdot {\left(1 - maxCos\right)}^{2}\right)\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in ux around -inf 99.1%
metadata-eval99.1%
cancel-sign-sub-inv99.1%
*-commutative99.1%
fma-def99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
+-commutative99.1%
*-commutative99.1%
fma-def99.1%
mul-1-neg99.1%
distribute-rgt-neg-in99.1%
unpow299.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
pow199.1%
associate-*l*99.1%
Applied egg-rr99.1%
unpow199.1%
*-commutative99.1%
fma-udef99.1%
fma-udef99.1%
*-commutative99.1%
+-commutative99.1%
*-commutative99.1%
distribute-lft-out99.1%
+-commutative99.1%
fma-def99.1%
distribute-rgt-neg-out99.1%
distribute-lft-neg-in99.1%
associate-*r*99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.8%
Final simplification79.8%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00015999999595806003) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (- 1.0 (pow (- 1.0 ux) 2.0)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00015999999595806003f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f - powf((1.0f - ux), 2.0f)));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.00015999999595806003e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 - ((1.0e0 - ux) ** 2.0e0)))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00015999999595806003)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) - (Float32(Float32(1.0) - ux) ^ Float32(2.0)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00015999999595806003)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) - ((single(1.0) - ux) ^ single(2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00015999999595806003:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - {\left(1 - ux\right)}^{2}}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 35.4%
associate-*l*35.4%
+-commutative35.4%
associate-+r-35.4%
fma-def35.4%
+-commutative35.4%
associate-+r-35.3%
fma-def35.3%
Simplified35.3%
Taylor expanded in uy around 0 32.2%
Taylor expanded in ux around 0 73.6%
if 1.59999996e-4 < ux Initial program 89.3%
associate-*l*89.3%
+-commutative89.3%
associate-+r-89.1%
fma-def89.1%
+-commutative89.1%
associate-+r-88.9%
fma-def88.9%
Simplified88.9%
Taylor expanded in uy around 0 76.1%
Taylor expanded in maxCos around 0 72.6%
Final simplification73.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (fma -2.0 maxCos 2.0) ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (fmaf(-2.0f, maxCos, 2.0f) - ux)));
}
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) - ux))) end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) - ux\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in ux around -inf 99.1%
metadata-eval99.1%
cancel-sign-sub-inv99.1%
*-commutative99.1%
fma-def99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
+-commutative99.1%
*-commutative99.1%
fma-def99.1%
mul-1-neg99.1%
distribute-rgt-neg-in99.1%
unpow299.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
add-log-exp97.6%
Applied egg-rr97.6%
Taylor expanded in maxCos around 0 95.7%
Taylor expanded in uy around 0 78.5%
+-commutative78.5%
mul-1-neg78.5%
unpow278.5%
distribute-rgt-neg-in78.5%
*-commutative78.5%
distribute-lft-out78.5%
fma-def78.5%
Simplified78.5%
Final simplification78.5%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in uy around 0 50.4%
Taylor expanded in ux around 0 63.9%
Final simplification63.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux 2.0)))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * 2.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((ux * 2.0e0))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(2.0))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * single(2.0))); end
\begin{array}{l}
\\
\sqrt{ux \cdot 2}
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in uy around 0 50.4%
Taylor expanded in ux around 0 63.9%
Taylor expanded in maxCos around 0 60.9%
Final simplification60.9%
(FPCore (ux uy maxCos) :precision binary32 0.0)
float code(float ux, float uy, float maxCos) {
return 0.0f;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = 0.0e0
end function
function code(ux, uy, maxCos) return Float32(0.0) end
function tmp = code(ux, uy, maxCos) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
+-commutative57.6%
associate-+r-57.5%
fma-def57.5%
Simplified57.5%
Taylor expanded in uy around 0 50.4%
Taylor expanded in ux around 0 63.9%
add-log-exp55.9%
*-commutative55.9%
cancel-sign-sub-inv55.9%
metadata-eval55.9%
Applied egg-rr55.9%
Taylor expanded in ux around 0 6.6%
Final simplification6.6%
herbie shell --seed 2023274
(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)))))))