
(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 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))))))
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 (* ux (- (- 2.0 (* ux (pow (+ -1.0 maxCos) 2.0))) (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * ((2.0f - (ux * powf((-1.0f + maxCos), 2.0f))) - (2.0f * maxCos))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0)))) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * ((single(2.0) - (ux * ((single(-1.0) + maxCos) ^ single(2.0)))) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 - ux \cdot {\left(-1 + maxCos\right)}^{2}\right) - 2 \cdot maxCos\right)}
\end{array}
Initial program 59.2%
Taylor expanded in ux around 0 99.2%
Final simplification99.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (- (/ (+ 2.0 (* maxCos -2.0)) ux) (pow (+ -1.0 maxCos) 2.0))) (* (cos (* (* uy 2.0) PI)) ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((((2.0f + (maxCos * -2.0f)) / ux) - powf((-1.0f + maxCos), 2.0f))) * (cosf(((uy * 2.0f) * ((float) M_PI))) * ux);
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))) / ux) - (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0)))) * Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * ux)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(2.0) + (maxCos * single(-2.0))) / ux) - ((single(-1.0) + maxCos) ^ single(2.0)))) * (cos(((uy * single(2.0)) * single(pi))) * ux); end
\begin{array}{l}
\\
\sqrt{\frac{2 + maxCos \cdot -2}{ux} - {\left(-1 + maxCos\right)}^{2}} \cdot \left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot ux\right)
\end{array}
Initial program 59.2%
Taylor expanded in ux around inf 98.8%
Taylor expanded in uy around inf 98.7%
*-commutative98.7%
associate--r+98.7%
associate-*r/98.7%
metadata-eval98.7%
associate-*r/98.7%
div-sub98.8%
cancel-sign-sub-inv98.8%
metadata-eval98.8%
*-commutative98.8%
sub-neg98.8%
metadata-eval98.8%
associate-*r*98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) PI)) (sqrt (* ux (- 2.0 (+ (* ux (pow (+ -1.0 maxCos) 2.0)) (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * (2.0f - ((ux * powf((-1.0f + maxCos), 2.0f)) + (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0))) + Float32(Float32(2.0) * maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * (single(2.0) - ((ux * ((single(-1.0) + maxCos) ^ single(2.0))) + (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - \left(ux \cdot {\left(-1 + maxCos\right)}^{2} + 2 \cdot maxCos\right)\right)}
\end{array}
Initial program 59.2%
Taylor expanded in ux around 0 99.2%
associate--l+99.2%
associate-*r*99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (cos (* (* uy 2.0) PI)) 0.9999949932098389) (* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux))) (sqrt (* ux (+ 2.0 (- (* ux (- -1.0 (* maxCos -2.0))) (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (cosf(((uy * 2.0f) * ((float) M_PI))) <= 0.9999949932098389f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
} else {
tmp = sqrtf((ux * (2.0f + ((ux * (-1.0f - (maxCos * -2.0f))) - (2.0f * maxCos)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) <= Float32(0.9999949932098389)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); else tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(ux * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0)))) - Float32(Float32(2.0) * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (cos(((uy * single(2.0)) * single(pi))) <= single(0.9999949932098389)) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); else tmp = sqrt((ux * (single(2.0) + ((ux * (single(-1.0) - (maxCos * single(-2.0)))) - (single(2.0) * maxCos))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \leq 0.9999949932098389:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(ux \cdot \left(-1 - maxCos \cdot -2\right) - 2 \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999994993Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-define56.7%
Simplified56.8%
Taylor expanded in maxCos around 0 53.4%
Taylor expanded in ux around 0 72.6%
if 0.999994993 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 60.3%
associate-*l*60.3%
sub-neg60.3%
+-commutative60.3%
distribute-rgt-neg-in60.3%
fma-define60.4%
Simplified60.5%
Taylor expanded in uy around 0 60.0%
mul-1-neg60.0%
sub-neg60.0%
metadata-eval60.0%
+-commutative60.0%
associate--l+60.3%
*-commutative60.3%
Simplified60.3%
Taylor expanded in maxCos around 0 59.8%
Taylor expanded in ux around 0 97.7%
associate--l+97.7%
associate-*r*97.7%
mul-1-neg97.7%
Simplified97.7%
Final simplification89.9%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* uy 2.0) 0.00018000000272877514) (* ux (sqrt (- (/ (+ 2.0 (* maxCos -2.0)) ux) (pow (+ -1.0 maxCos) 2.0)))) (* ux (* (cos (* (* uy 2.0) PI)) (sqrt (+ -1.0 (/ 2.0 ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.00018000000272877514f) {
tmp = ux * sqrtf((((2.0f + (maxCos * -2.0f)) / ux) - powf((-1.0f + maxCos), 2.0f)));
} else {
tmp = ux * (cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((-1.0f + (2.0f / ux))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.00018000000272877514)) tmp = Float32(ux * sqrt(Float32(Float32(Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))) / ux) - (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0))))); else tmp = Float32(ux * Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(-1.0) + Float32(Float32(2.0) / ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.00018000000272877514)) tmp = ux * sqrt((((single(2.0) + (maxCos * single(-2.0))) / ux) - ((single(-1.0) + maxCos) ^ single(2.0)))); else tmp = ux * (cos(((uy * single(2.0)) * single(pi))) * sqrt((single(-1.0) + (single(2.0) / ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.00018000000272877514:\\
\;\;\;\;ux \cdot \sqrt{\frac{2 + maxCos \cdot -2}{ux} - {\left(-1 + maxCos\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;ux \cdot \left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{-1 + \frac{2}{ux}}\right)\\
\end{array}
\end{array}
if (*.f32 uy 2) < 1.80000003e-4Initial program 58.6%
Taylor expanded in ux around inf 99.2%
Taylor expanded in uy around 0 98.9%
associate--r+98.9%
associate-*r/98.9%
metadata-eval98.9%
associate-*r/98.9%
div-sub99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
if 1.80000003e-4 < (*.f32 uy 2) Initial program 60.0%
Taylor expanded in ux around inf 98.4%
Taylor expanded in maxCos around 0 90.4%
associate-*l*90.5%
associate-*r*90.5%
sub-neg90.5%
associate-*r/90.5%
metadata-eval90.5%
metadata-eval90.5%
Simplified90.5%
Final simplification95.6%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* uy 2.0) 0.00018000000272877514) (sqrt (* ux (+ (- 2.0 (* ux (pow (+ -1.0 maxCos) 2.0))) (* maxCos -2.0)))) (* ux (* (cos (* (* uy 2.0) PI)) (sqrt (+ -1.0 (/ 2.0 ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.00018000000272877514f) {
tmp = sqrtf((ux * ((2.0f - (ux * powf((-1.0f + maxCos), 2.0f))) + (maxCos * -2.0f))));
} else {
tmp = ux * (cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((-1.0f + (2.0f / ux))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.00018000000272877514)) tmp = sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0)))) + Float32(maxCos * Float32(-2.0))))); else tmp = Float32(ux * Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(-1.0) + Float32(Float32(2.0) / ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.00018000000272877514)) tmp = sqrt((ux * ((single(2.0) - (ux * ((single(-1.0) + maxCos) ^ single(2.0)))) + (maxCos * single(-2.0))))); else tmp = ux * (cos(((uy * single(2.0)) * single(pi))) * sqrt((single(-1.0) + (single(2.0) / ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.00018000000272877514:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(2 - ux \cdot {\left(-1 + maxCos\right)}^{2}\right) + maxCos \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;ux \cdot \left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{-1 + \frac{2}{ux}}\right)\\
\end{array}
\end{array}
if (*.f32 uy 2) < 1.80000003e-4Initial program 58.6%
Taylor expanded in ux around 0 99.6%
associate--l+99.6%
associate-*r*99.6%
mul-1-neg99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in uy around 0 99.5%
cancel-sign-sub-inv99.5%
associate-*r*99.5%
neg-mul-199.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
+-commutative99.5%
metadata-eval99.5%
*-commutative99.5%
Simplified99.5%
if 1.80000003e-4 < (*.f32 uy 2) Initial program 60.0%
Taylor expanded in ux around inf 98.4%
Taylor expanded in maxCos around 0 90.4%
associate-*l*90.5%
associate-*r*90.5%
sub-neg90.5%
associate-*r/90.5%
metadata-eval90.5%
metadata-eval90.5%
Simplified90.5%
Final simplification95.9%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) PI)) (sqrt (+ (* maxCos (* ux (- (* 2.0 ux) 2.0))) (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf(((maxCos * (ux * ((2.0f * ux) - 2.0f))) + (ux * (2.0f - ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(maxCos * Float32(ux * Float32(Float32(Float32(2.0) * ux) - Float32(2.0)))) + Float32(ux * Float32(Float32(2.0) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt(((maxCos * (ux * ((single(2.0) * ux) - single(2.0)))) + (ux * (single(2.0) - ux)))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{maxCos \cdot \left(ux \cdot \left(2 \cdot ux - 2\right)\right) + ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 59.2%
Taylor expanded in ux around 0 99.2%
Taylor expanded in maxCos around 0 98.5%
Final simplification98.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* uy 2.0) 0.00018000000272877514) (sqrt (* ux (+ 2.0 (- (* ux (- -1.0 (* maxCos -2.0))) (* 2.0 maxCos))))) (* ux (* (cos (* (* uy 2.0) PI)) (sqrt (+ -1.0 (/ 2.0 ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.00018000000272877514f) {
tmp = sqrtf((ux * (2.0f + ((ux * (-1.0f - (maxCos * -2.0f))) - (2.0f * maxCos)))));
} else {
tmp = ux * (cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((-1.0f + (2.0f / ux))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.00018000000272877514)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(ux * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0)))) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(ux * Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(-1.0) + Float32(Float32(2.0) / ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.00018000000272877514)) tmp = sqrt((ux * (single(2.0) + ((ux * (single(-1.0) - (maxCos * single(-2.0)))) - (single(2.0) * maxCos))))); else tmp = ux * (cos(((uy * single(2.0)) * single(pi))) * sqrt((single(-1.0) + (single(2.0) / ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.00018000000272877514:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(ux \cdot \left(-1 - maxCos \cdot -2\right) - 2 \cdot maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;ux \cdot \left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{-1 + \frac{2}{ux}}\right)\\
\end{array}
\end{array}
if (*.f32 uy 2) < 1.80000003e-4Initial program 58.6%
associate-*l*58.6%
sub-neg58.6%
+-commutative58.6%
distribute-rgt-neg-in58.6%
fma-define58.7%
Simplified58.8%
Taylor expanded in uy around 0 58.5%
mul-1-neg58.5%
sub-neg58.5%
metadata-eval58.5%
+-commutative58.5%
associate--l+58.8%
*-commutative58.8%
Simplified58.8%
Taylor expanded in maxCos around 0 58.1%
Taylor expanded in ux around 0 99.0%
associate--l+99.0%
associate-*r*99.0%
mul-1-neg99.0%
Simplified99.0%
if 1.80000003e-4 < (*.f32 uy 2) Initial program 60.0%
Taylor expanded in ux around inf 98.4%
Taylor expanded in maxCos around 0 90.4%
associate-*l*90.5%
associate-*r*90.5%
sub-neg90.5%
associate-*r/90.5%
metadata-eval90.5%
metadata-eval90.5%
Simplified90.5%
Final simplification95.6%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* uy 2.0) 0.00018000000272877514) (sqrt (* ux (+ 2.0 (- (* ux (- -1.0 (* maxCos -2.0))) (* 2.0 maxCos))))) (* (cos (* (* uy 2.0) PI)) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.00018000000272877514f) {
tmp = sqrtf((ux * (2.0f + ((ux * (-1.0f - (maxCos * -2.0f))) - (2.0f * maxCos)))));
} else {
tmp = cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * (2.0f - ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.00018000000272877514)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(ux * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0)))) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.00018000000272877514)) tmp = sqrt((ux * (single(2.0) + ((ux * (single(-1.0) - (maxCos * single(-2.0)))) - (single(2.0) * maxCos))))); else tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * (single(2.0) - ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.00018000000272877514:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(ux \cdot \left(-1 - maxCos \cdot -2\right) - 2 \cdot maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 1.80000003e-4Initial program 58.6%
associate-*l*58.6%
sub-neg58.6%
+-commutative58.6%
distribute-rgt-neg-in58.6%
fma-define58.7%
Simplified58.8%
Taylor expanded in uy around 0 58.5%
mul-1-neg58.5%
sub-neg58.5%
metadata-eval58.5%
+-commutative58.5%
associate--l+58.8%
*-commutative58.8%
Simplified58.8%
Taylor expanded in maxCos around 0 58.1%
Taylor expanded in ux around 0 99.0%
associate--l+99.0%
associate-*r*99.0%
mul-1-neg99.0%
Simplified99.0%
if 1.80000003e-4 < (*.f32 uy 2) Initial program 60.0%
Taylor expanded in ux around 0 98.6%
associate--l+98.6%
associate-*r*98.6%
mul-1-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in maxCos around 0 90.4%
neg-mul-190.4%
+-commutative90.4%
neg-mul-190.4%
*-commutative90.4%
fma-undefine90.4%
fma-undefine90.4%
*-commutative90.4%
neg-mul-190.4%
+-commutative90.4%
unsub-neg90.4%
associate-*r*90.4%
Simplified90.4%
Final simplification95.5%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 2.0 (- (* ux (- -1.0 (* maxCos -2.0))) (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f + ((ux * (-1.0f - (maxCos * -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 + ((ux * ((-1.0e0) - (maxcos * (-2.0e0)))) - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(ux * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0)))) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) + ((ux * (single(-1.0) - (maxCos * single(-2.0)))) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 + \left(ux \cdot \left(-1 - maxCos \cdot -2\right) - 2 \cdot maxCos\right)\right)}
\end{array}
Initial program 59.2%
associate-*l*59.2%
sub-neg59.2%
+-commutative59.2%
distribute-rgt-neg-in59.2%
fma-define59.2%
Simplified59.4%
Taylor expanded in uy around 0 51.7%
mul-1-neg51.7%
sub-neg51.7%
metadata-eval51.7%
+-commutative51.7%
associate--l+51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in maxCos around 0 51.5%
Taylor expanded in ux around 0 80.5%
associate--l+80.5%
associate-*r*80.5%
mul-1-neg80.5%
Simplified80.5%
Final simplification80.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 59.2%
associate-*l*59.2%
sub-neg59.2%
+-commutative59.2%
distribute-rgt-neg-in59.2%
fma-define59.2%
Simplified59.4%
Taylor expanded in uy around 0 51.7%
mul-1-neg51.7%
sub-neg51.7%
metadata-eval51.7%
+-commutative51.7%
associate--l+51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in maxCos around 0 51.5%
Taylor expanded in ux around 0 64.9%
Final simplification64.9%
(FPCore (ux uy maxCos) :precision binary32 (* ux (sqrt (+ -1.0 (/ 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
return ux * sqrtf((-1.0f + (2.0f / ux)));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = ux * sqrt(((-1.0e0) + (2.0e0 / ux)))
end function
function code(ux, uy, maxCos) return Float32(ux * sqrt(Float32(Float32(-1.0) + Float32(Float32(2.0) / ux)))) end
function tmp = code(ux, uy, maxCos) tmp = ux * sqrt((single(-1.0) + (single(2.0) / ux))); end
\begin{array}{l}
\\
ux \cdot \sqrt{-1 + \frac{2}{ux}}
\end{array}
Initial program 59.2%
Taylor expanded in ux around inf 98.8%
Taylor expanded in maxCos around 0 91.2%
Taylor expanded in uy around 0 75.5%
sub-neg75.5%
metadata-eval75.5%
+-commutative75.5%
associate-*r/75.5%
metadata-eval75.5%
Simplified75.5%
Final simplification75.5%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* 2.0 ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((2.0f * ux));
}
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))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(2.0) * ux)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(2.0) * ux)); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux}
\end{array}
Initial program 59.2%
associate-*l*59.2%
sub-neg59.2%
+-commutative59.2%
distribute-rgt-neg-in59.2%
fma-define59.2%
Simplified59.4%
Taylor expanded in maxCos around 0 56.6%
Taylor expanded in ux around 0 72.1%
Taylor expanded in uy around 0 61.9%
Final simplification61.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt 0.0))
float code(float ux, float uy, float maxCos) {
return sqrtf(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 = sqrt(0.0e0)
end function
function code(ux, uy, maxCos) return sqrt(Float32(0.0)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(single(0.0)); end
\begin{array}{l}
\\
\sqrt{0}
\end{array}
Initial program 59.2%
associate-*l*59.2%
sub-neg59.2%
+-commutative59.2%
distribute-rgt-neg-in59.2%
fma-define59.2%
Simplified59.4%
Taylor expanded in uy around 0 51.7%
mul-1-neg51.7%
sub-neg51.7%
metadata-eval51.7%
+-commutative51.7%
associate--l+51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in ux around 0 6.6%
Final simplification6.6%
herbie shell --seed 2024096
(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)))))))