
(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 18 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
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux * ((1.0f + (1.0f - maxCos)) - maxCos))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.4%
+-commutative59.4%
associate-+r-59.5%
fma-def59.5%
neg-sub059.5%
+-commutative59.5%
associate-+r-59.2%
associate--r-59.2%
neg-sub059.2%
+-commutative59.2%
sub-neg59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(+ ux (* ux (- (- 1.0 maxCos) maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux + (ux * ((1.0f - maxCos) - maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) - maxCos)))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux + ux \cdot \left(\left(1 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.4%
+-commutative59.4%
associate-+r-59.5%
fma-def59.5%
neg-sub059.5%
+-commutative59.5%
associate-+r-59.2%
associate--r-59.2%
neg-sub059.2%
+-commutative59.2%
sub-neg59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.0%
*-lft-identity99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
sub-neg99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(+
(* ux (fma maxCos -2.0 2.0))
(* (* ux ux) (- -1.0 (* maxCos (+ maxCos -2.0))))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((ux * fmaf(maxCos, -2.0f, 2.0f)) + ((ux * ux) * (-1.0f - (maxCos * (maxCos + -2.0f))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(ux * fma(maxCos, Float32(-2.0), Float32(2.0))) + Float32(Float32(ux * ux) * Float32(Float32(-1.0) - Float32(maxCos * Float32(maxCos + Float32(-2.0)))))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \mathsf{fma}\left(maxCos, -2, 2\right) + \left(ux \cdot ux\right) \cdot \left(-1 - maxCos \cdot \left(maxCos + -2\right)\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
+-commutative59.3%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
*-commutative99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
unpow299.0%
Simplified99.0%
Taylor expanded in maxCos around 0 99.0%
associate-+r+99.0%
+-commutative99.0%
unpow299.0%
distribute-rgt-out99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (+ (* ux (fma maxCos -2.0 2.0)) (* (* ux ux) (- -1.0 (* maxCos -2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((ux * fmaf(maxCos, -2.0f, 2.0f)) + ((ux * ux) * (-1.0f - (maxCos * -2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(ux * fma(maxCos, Float32(-2.0), Float32(2.0))) + Float32(Float32(ux * ux) * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0))))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \mathsf{fma}\left(maxCos, -2, 2\right) + \left(ux \cdot ux\right) \cdot \left(-1 - maxCos \cdot -2\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
+-commutative59.3%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
*-commutative99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
unpow299.0%
Simplified99.0%
Taylor expanded in maxCos around 0 98.3%
Final simplification98.3%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (- (* ux (fma maxCos -2.0 2.0)) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((ux * fmaf(maxCos, -2.0f, 2.0f)) - (ux * ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(ux * fma(maxCos, Float32(-2.0), Float32(2.0))) - Float32(ux * ux)))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \mathsf{fma}\left(maxCos, -2, 2\right) - ux \cdot ux}
\end{array}
Initial program 59.3%
associate-*l*59.3%
+-commutative59.3%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
*-commutative99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
unpow299.0%
Simplified99.0%
Taylor expanded in maxCos around 0 99.0%
associate-+r+99.0%
+-commutative99.0%
unpow299.0%
distribute-rgt-out99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 97.5%
unpow297.5%
Simplified97.5%
Final simplification97.5%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* uy 2.0))) (sqrt (- (* 2.0 ux) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 59.3%
associate-*l*59.3%
+-commutative59.3%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
*-commutative99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
unpow299.0%
Simplified99.0%
Taylor expanded in maxCos around 0 94.0%
associate-*r*94.0%
unpow294.0%
Simplified94.0%
Final simplification94.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.00139999995008111)
(sqrt
(+
(* ux (- (- 1.0 (+ maxCos -1.0)) maxCos))
(* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0)))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.00139999995008111f) {
tmp = sqrtf(((ux * ((1.0f - (maxCos + -1.0f)) - maxCos)) + ((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f)))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.00139999995008111)) tmp = sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) - Float32(maxCos + Float32(-1.0))) - maxCos)) + Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * (ux ^ Float32(2.0)))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(0.00139999995008111)) tmp = sqrt(((ux * ((single(1.0) - (maxCos + single(-1.0))) - maxCos)) + ((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.00139999995008111:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 - \left(maxCos + -1\right)\right) - maxCos\right) + \left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 0.00139999995Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.4%
+-commutative58.4%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.3%
associate--r-58.3%
neg-sub058.3%
+-commutative58.3%
sub-neg58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in uy around 0 57.7%
Taylor expanded in ux around inf 97.8%
if 0.00139999995 < uy Initial program 62.1%
associate-*l*62.1%
+-commutative62.1%
associate-+r-62.0%
fma-def62.0%
+-commutative62.0%
associate-+r-61.6%
fma-def61.6%
Simplified61.6%
Taylor expanded in ux around 0 43.9%
Taylor expanded in maxCos around 0 70.2%
Final simplification90.5%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
+-commutative59.3%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
*-commutative99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
unpow299.0%
Simplified99.0%
Taylor expanded in maxCos around 0 94.0%
associate-*r*94.0%
unpow294.0%
distribute-rgt-out--94.0%
Simplified94.0%
Final simplification94.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* ux (- (- 1.0 (+ maxCos -1.0)) maxCos)) (* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * ((1.0f - (maxCos + -1.0f)) - maxCos)) + ((maxCos + -1.0f) * ((1.0f - maxCos) * powf(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 * ((1.0e0 - (maxcos + (-1.0e0))) - maxcos)) + ((maxcos + (-1.0e0)) * ((1.0e0 - maxcos) * (ux ** 2.0e0)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) - Float32(maxCos + Float32(-1.0))) - maxCos)) + Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * (ux ^ Float32(2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * ((single(1.0) - (maxCos + single(-1.0))) - maxCos)) + ((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(1 - \left(maxCos + -1\right)\right) - maxCos\right) + \left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.4%
+-commutative59.4%
associate-+r-59.5%
fma-def59.5%
neg-sub059.5%
+-commutative59.5%
associate-+r-59.2%
associate--r-59.2%
neg-sub059.2%
+-commutative59.2%
sub-neg59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in uy around 0 51.0%
Taylor expanded in ux around inf 83.0%
Final simplification83.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0))) (* ux (- 2.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (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((((maxcos + (-1.0e0)) * ((1.0e0 - maxcos) * (ux ** 2.0e0))) + (ux * (2.0e0 - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{\left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.4%
+-commutative59.4%
associate-+r-59.5%
fma-def59.5%
neg-sub059.5%
+-commutative59.5%
associate-+r-59.2%
associate--r-59.2%
neg-sub059.2%
+-commutative59.2%
sub-neg59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in uy around 0 83.0%
Final simplification83.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* 2.0 ux) (pow ux 2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * ux) - powf(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(((2.0e0 * ux) - (ux ** 2.0e0)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux - {ux}^{2}}
\end{array}
Initial program 59.3%
associate-*l*59.3%
+-commutative59.3%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.1%
fma-def59.1%
Simplified59.1%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
*-commutative99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
unpow299.0%
Simplified99.0%
Taylor expanded in maxCos around 0 94.0%
associate-*r*94.0%
unpow294.0%
Simplified94.0%
Taylor expanded in uy around 0 79.6%
Final simplification79.6%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00019999999494757503)
(sqrt (+ ux (* ux (- 1.0 (* 2.0 maxCos)))))
(sqrt
(+ 1.0 (* (- ux (+ 1.0 (* maxCos ux))) (+ 1.0 (* (+ maxCos -1.0) ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf((ux + (ux * (1.0f - (2.0f * maxCos)))));
} else {
tmp = sqrtf((1.0f + ((ux - (1.0f + (maxCos * ux))) * (1.0f + ((maxCos + -1.0f) * ux)))));
}
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.00019999999494757503e0) then
tmp = sqrt((ux + (ux * (1.0e0 - (2.0e0 * maxcos)))))
else
tmp = sqrt((1.0e0 + ((ux - (1.0e0 + (maxcos * ux))) * (1.0e0 + ((maxcos + (-1.0e0)) * ux)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019999999494757503)) tmp = sqrt(Float32(ux + Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(ux - Float32(Float32(1.0) + Float32(maxCos * ux))) * Float32(Float32(1.0) + Float32(Float32(maxCos + Float32(-1.0)) * ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019999999494757503)) tmp = sqrt((ux + (ux * (single(1.0) - (single(2.0) * maxCos))))); else tmp = sqrt((single(1.0) + ((ux - (single(1.0) + (maxCos * ux))) * (single(1.0) + ((maxCos + single(-1.0)) * ux))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{ux + ux \cdot \left(1 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos + -1\right) \cdot ux\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 38.5%
associate-*l*38.5%
sub-neg38.5%
+-commutative38.5%
distribute-rgt-neg-in38.5%
fma-def38.5%
+-commutative38.5%
associate-+r-38.6%
fma-def38.6%
neg-sub038.6%
+-commutative38.6%
associate-+r-38.5%
associate--r-38.5%
neg-sub038.5%
+-commutative38.5%
sub-neg38.5%
fma-def38.5%
Simplified38.5%
Taylor expanded in ux around 0 92.3%
associate--l+92.3%
distribute-rgt-in92.3%
*-lft-identity92.3%
mul-1-neg92.3%
sub-neg92.3%
metadata-eval92.3%
distribute-neg-in92.3%
metadata-eval92.3%
+-commutative92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in uy around 0 81.6%
if 1.99999995e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-def90.5%
+-commutative90.5%
associate-+r-90.4%
fma-def90.4%
neg-sub090.4%
+-commutative90.4%
associate-+r-90.1%
associate--r-90.1%
neg-sub090.1%
+-commutative90.1%
sub-neg90.1%
fma-def90.1%
Simplified90.1%
Taylor expanded in uy around 0 71.6%
Taylor expanded in ux around -inf 71.8%
mul-1-neg71.8%
unsub-neg71.8%
mul-1-neg71.8%
sub-neg71.8%
Simplified71.8%
Final simplification77.6%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019999999494757503) (sqrt (+ ux (* ux (- 1.0 (* 2.0 maxCos))))) (sqrt (+ 1.0 (* (- (+ 1.0 (* maxCos ux)) ux) (+ -1.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf((ux + (ux * (1.0f - (2.0f * maxCos)))));
} else {
tmp = sqrtf((1.0f + (((1.0f + (maxCos * ux)) - ux) * (-1.0f + ux))));
}
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.00019999999494757503e0) then
tmp = sqrt((ux + (ux * (1.0e0 - (2.0e0 * maxcos)))))
else
tmp = sqrt((1.0e0 + (((1.0e0 + (maxcos * ux)) - ux) * ((-1.0e0) + ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019999999494757503)) tmp = sqrt(Float32(ux + Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) + Float32(maxCos * ux)) - ux) * Float32(Float32(-1.0) + ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019999999494757503)) tmp = sqrt((ux + (ux * (single(1.0) - (single(2.0) * maxCos))))); else tmp = sqrt((single(1.0) + (((single(1.0) + (maxCos * ux)) - ux) * (single(-1.0) + ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{ux + ux \cdot \left(1 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(\left(1 + maxCos \cdot ux\right) - ux\right) \cdot \left(-1 + ux\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 38.5%
associate-*l*38.5%
sub-neg38.5%
+-commutative38.5%
distribute-rgt-neg-in38.5%
fma-def38.5%
+-commutative38.5%
associate-+r-38.6%
fma-def38.6%
neg-sub038.6%
+-commutative38.6%
associate-+r-38.5%
associate--r-38.5%
neg-sub038.5%
+-commutative38.5%
sub-neg38.5%
fma-def38.5%
Simplified38.5%
Taylor expanded in ux around 0 92.3%
associate--l+92.3%
distribute-rgt-in92.3%
*-lft-identity92.3%
mul-1-neg92.3%
sub-neg92.3%
metadata-eval92.3%
distribute-neg-in92.3%
metadata-eval92.3%
+-commutative92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in uy around 0 81.6%
if 1.99999995e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-def90.5%
+-commutative90.5%
associate-+r-90.4%
fma-def90.4%
neg-sub090.4%
+-commutative90.4%
associate-+r-90.1%
associate--r-90.1%
neg-sub090.1%
+-commutative90.1%
sub-neg90.1%
fma-def90.1%
Simplified90.1%
Taylor expanded in uy around 0 71.6%
Taylor expanded in maxCos around 0 69.1%
Final simplification76.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019999999494757503) (sqrt (* ux (+ 1.0 (- (- 1.0 maxCos) maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ -1.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf((ux * (1.0f + ((1.0f - maxCos) - maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f + ux))));
}
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.00019999999494757503e0) then
tmp = sqrt((ux * (1.0e0 + ((1.0e0 - maxcos) - maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) + ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019999999494757503)) tmp = sqrt(Float32(ux * Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - maxCos) - maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) + ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019999999494757503)) tmp = sqrt((ux * (single(1.0) + ((single(1.0) - maxCos) - maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) + ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{ux \cdot \left(1 + \left(\left(1 - maxCos\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 + ux\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 38.5%
associate-*l*38.5%
sub-neg38.5%
+-commutative38.5%
distribute-rgt-neg-in38.5%
fma-def38.5%
+-commutative38.5%
associate-+r-38.6%
fma-def38.6%
neg-sub038.6%
+-commutative38.6%
associate-+r-38.5%
associate--r-38.5%
neg-sub038.5%
+-commutative38.5%
sub-neg38.5%
fma-def38.5%
Simplified38.5%
Taylor expanded in uy around 0 37.1%
Taylor expanded in ux around 0 81.5%
mul-1-neg81.5%
sub-neg81.5%
associate--l-81.5%
sub-neg81.5%
metadata-eval81.5%
Simplified81.5%
if 1.99999995e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-def90.5%
+-commutative90.5%
associate-+r-90.4%
fma-def90.4%
neg-sub090.4%
+-commutative90.4%
associate-+r-90.1%
associate--r-90.1%
neg-sub090.1%
+-commutative90.1%
sub-neg90.1%
fma-def90.1%
Simplified90.1%
Taylor expanded in uy around 0 71.6%
Taylor expanded in maxCos around 0 68.8%
Final simplification76.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019999999494757503) (sqrt (+ ux (* ux (- 1.0 (* 2.0 maxCos))))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ -1.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf((ux + (ux * (1.0f - (2.0f * maxCos)))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f + ux))));
}
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.00019999999494757503e0) then
tmp = sqrt((ux + (ux * (1.0e0 - (2.0e0 * maxcos)))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) + ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019999999494757503)) tmp = sqrt(Float32(ux + Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) + ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019999999494757503)) tmp = sqrt((ux + (ux * (single(1.0) - (single(2.0) * maxCos))))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) + ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{ux + ux \cdot \left(1 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 + ux\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 38.5%
associate-*l*38.5%
sub-neg38.5%
+-commutative38.5%
distribute-rgt-neg-in38.5%
fma-def38.5%
+-commutative38.5%
associate-+r-38.6%
fma-def38.6%
neg-sub038.6%
+-commutative38.6%
associate-+r-38.5%
associate--r-38.5%
neg-sub038.5%
+-commutative38.5%
sub-neg38.5%
fma-def38.5%
Simplified38.5%
Taylor expanded in ux around 0 92.3%
associate--l+92.3%
distribute-rgt-in92.3%
*-lft-identity92.3%
mul-1-neg92.3%
sub-neg92.3%
metadata-eval92.3%
distribute-neg-in92.3%
metadata-eval92.3%
+-commutative92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in uy around 0 81.6%
if 1.99999995e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-def90.5%
+-commutative90.5%
associate-+r-90.4%
fma-def90.4%
neg-sub090.4%
+-commutative90.4%
associate-+r-90.1%
associate--r-90.1%
neg-sub090.1%
+-commutative90.1%
sub-neg90.1%
fma-def90.1%
Simplified90.1%
Taylor expanded in uy around 0 71.6%
Taylor expanded in maxCos around 0 68.8%
Final simplification76.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 1.0 (- (- 1.0 maxCos) maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (1.0f + ((1.0f - maxCos) - 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 * (1.0e0 + ((1.0e0 - maxcos) - maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - maxCos) - maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(1.0) + ((single(1.0) - maxCos) - maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(1 + \left(\left(1 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.4%
+-commutative59.4%
associate-+r-59.5%
fma-def59.5%
neg-sub059.5%
+-commutative59.5%
associate-+r-59.2%
associate--r-59.2%
neg-sub059.2%
+-commutative59.2%
sub-neg59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in uy around 0 51.0%
Taylor expanded in ux around 0 66.6%
mul-1-neg66.6%
sub-neg66.6%
associate--l-66.6%
sub-neg66.6%
metadata-eval66.6%
Simplified66.6%
Final simplification66.6%
(FPCore (ux uy maxCos) :precision binary32 (- 1.0 (* 0.5 (* (* ux ux) (* maxCos maxCos)))))
float code(float ux, float uy, float maxCos) {
return 1.0f - (0.5f * ((ux * ux) * (maxCos * maxCos)));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = 1.0e0 - (0.5e0 * ((ux * ux) * (maxcos * maxcos)))
end function
function code(ux, uy, maxCos) return Float32(Float32(1.0) - Float32(Float32(0.5) * Float32(Float32(ux * ux) * Float32(maxCos * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = single(1.0) - (single(0.5) * ((ux * ux) * (maxCos * maxCos))); end
\begin{array}{l}
\\
1 - 0.5 \cdot \left(\left(ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)\right)
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.4%
+-commutative59.4%
associate-+r-59.5%
fma-def59.5%
neg-sub059.5%
+-commutative59.5%
associate-+r-59.2%
associate--r-59.2%
neg-sub059.2%
+-commutative59.2%
sub-neg59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in uy around 0 51.0%
Taylor expanded in ux around inf 20.2%
Taylor expanded in ux around 0 20.2%
*-commutative20.2%
unpow220.2%
associate-*l*20.2%
sub-neg20.2%
metadata-eval20.2%
Simplified20.2%
Taylor expanded in maxCos around inf 20.4%
associate-*r*20.4%
mul-1-neg20.4%
unpow220.4%
unpow220.4%
Simplified20.4%
Final simplification20.4%
(FPCore (ux uy maxCos) :precision binary32 1.0)
float code(float ux, float uy, float maxCos) {
return 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 = 1.0e0
end function
function code(ux, uy, maxCos) return Float32(1.0) end
function tmp = code(ux, uy, maxCos) tmp = single(1.0); end
\begin{array}{l}
\\
1
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.4%
+-commutative59.4%
associate-+r-59.5%
fma-def59.5%
neg-sub059.5%
+-commutative59.5%
associate-+r-59.2%
associate--r-59.2%
neg-sub059.2%
+-commutative59.2%
sub-neg59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in uy around 0 51.0%
Taylor expanded in ux around inf 20.2%
Taylor expanded in ux around 0 20.4%
Final simplification20.4%
herbie shell --seed 2023224
(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)))))))