
(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 12 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 (exp (log (* uy (* 2.0 PI))))) (sqrt (fma ux (fma maxCos -2.0 2.0) (* (pow (- 1.0 maxCos) 2.0) (* ux (- ux)))))))
float code(float ux, float uy, float maxCos) {
return cosf(expf(logf((uy * (2.0f * ((float) M_PI)))))) * sqrtf(fmaf(ux, fmaf(maxCos, -2.0f, 2.0f), (powf((1.0f - maxCos), 2.0f) * (ux * -ux))));
}
function code(ux, uy, maxCos) return Float32(cos(exp(log(Float32(uy * Float32(Float32(2.0) * Float32(pi)))))) * sqrt(fma(ux, fma(maxCos, Float32(-2.0), Float32(2.0)), Float32((Float32(Float32(1.0) - maxCos) ^ Float32(2.0)) * Float32(ux * Float32(-ux)))))) end
\begin{array}{l}
\\
\cos \left(e^{\log \left(uy \cdot \left(2 \cdot \pi\right)\right)}\right) \cdot \sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {\left(1 - maxCos\right)}^{2} \cdot \left(ux \cdot \left(-ux\right)\right)\right)}
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
metadata-eval99.2%
cancel-sign-sub-inv99.2%
fma-def99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
+-commutative99.2%
*-commutative99.2%
fma-def99.2%
mul-1-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
mul-1-neg99.2%
unsub-neg99.2%
unpow299.2%
distribute-rgt-neg-in99.2%
Simplified99.2%
add-exp-log99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (fma ux (fma maxCos -2.0 2.0) (* (pow (- 1.0 maxCos) 2.0) (* ux (- ux))))) (cos (* uy (* 2.0 PI)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(ux, fmaf(maxCos, -2.0f, 2.0f), (powf((1.0f - maxCos), 2.0f) * (ux * -ux)))) * cosf((uy * (2.0f * ((float) M_PI))));
}
function code(ux, uy, maxCos) return Float32(sqrt(fma(ux, fma(maxCos, Float32(-2.0), Float32(2.0)), Float32((Float32(Float32(1.0) - maxCos) ^ Float32(2.0)) * Float32(ux * Float32(-ux))))) * cos(Float32(uy * Float32(Float32(2.0) * Float32(pi))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {\left(1 - maxCos\right)}^{2} \cdot \left(ux \cdot \left(-ux\right)\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
metadata-eval99.2%
cancel-sign-sub-inv99.2%
fma-def99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
+-commutative99.2%
*-commutative99.2%
fma-def99.2%
mul-1-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
mul-1-neg99.2%
unsub-neg99.2%
unpow299.2%
distribute-rgt-neg-in99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(+
(* (pow ux 2.0) (+ (+ maxCos -1.0) (* maxCos (- 1.0 maxCos))))
(* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((powf(ux, 2.0f) * ((maxCos + -1.0f) + (maxCos * (1.0f - maxCos)))) + (ux * (2.0f - (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) + Float32(maxCos * Float32(Float32(1.0) - maxCos)))) + Float32(ux * Float32(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)) * ((maxCos + single(-1.0)) + (maxCos * (single(1.0) - maxCos)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) + maxCos \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
sub-neg58.3%
distribute-rgt-in59.1%
Applied egg-rr59.1%
Taylor expanded in ux around 0 99.2%
Final simplification99.2%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(-
(* ux (+ 2.0 (* maxCos -2.0)))
(* (* ux ux) (pow (+ maxCos -1.0) 2.0))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((ux * (2.0f + (maxCos * -2.0f))) - ((ux * ux) * powf((maxCos + -1.0f), 2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0)))) - Float32(Float32(ux * ux) * (Float32(maxCos + Float32(-1.0)) ^ Float32(2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((ux * (single(2.0) + (maxCos * single(-2.0)))) - ((ux * ux) * ((maxCos + single(-1.0)) ^ single(2.0))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
sub-neg58.3%
distribute-rgt-in59.1%
Applied egg-rr59.1%
Taylor expanded in ux around 0 99.2%
rem-cube-cbrt99.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (- (- (+ ux ux) (* maxCos (+ ux (+ ux (* ux (* ux -2.0)))))) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((((ux + ux) - (maxCos * (ux + (ux + (ux * (ux * -2.0f)))))) - (ux * ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(ux + ux) - Float32(maxCos * Float32(ux + Float32(ux + Float32(ux * Float32(ux * Float32(-2.0))))))) - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((((ux + ux) - (maxCos * (ux + (ux + (ux * (ux * single(-2.0))))))) - (ux * ux))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(\left(ux + ux\right) - maxCos \cdot \left(ux + \left(ux + ux \cdot \left(ux \cdot -2\right)\right)\right)\right) - ux \cdot ux}
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
sub-neg58.3%
distribute-rgt-in59.1%
Applied egg-rr59.1%
Taylor expanded in maxCos around 0 98.2%
associate--l+98.2%
associate-*r*98.2%
fma-neg98.2%
mul-1-neg98.2%
mul-1-neg98.2%
unpow298.2%
distribute-rgt-neg-out98.2%
distribute-lft-out98.2%
mul-1-neg98.2%
remove-double-neg98.2%
sub-neg98.2%
distribute-lft-in98.2%
*-rgt-identity98.2%
distribute-rgt-neg-out98.2%
unpow298.2%
unsub-neg98.2%
unpow298.2%
Simplified98.2%
Taylor expanded in maxCos around 0 98.1%
+-commutative98.1%
mul-1-neg98.1%
unsub-neg98.1%
count-298.1%
cancel-sign-sub-inv98.1%
metadata-eval98.1%
distribute-lft-in98.1%
*-rgt-identity98.1%
*-commutative98.1%
unpow298.1%
Simplified98.1%
Final simplification98.1%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 9.500000305706635e-5)
(sqrt
(- (* ux (+ 2.0 (* maxCos -2.0))) (* (* ux ux) (pow (+ maxCos -1.0) 2.0))))
(* (cos (* uy (* 2.0 PI))) (sqrt (+ ux (- ux (* ux ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 9.500000305706635e-5f) {
tmp = sqrtf(((ux * (2.0f + (maxCos * -2.0f))) - ((ux * ux) * powf((maxCos + -1.0f), 2.0f))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux + (ux - (ux * ux))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(9.500000305706635e-5)) tmp = sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0)))) - Float32(Float32(ux * ux) * (Float32(maxCos + Float32(-1.0)) ^ Float32(2.0))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux + Float32(ux - Float32(ux * ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(9.500000305706635e-5)) tmp = sqrt(((ux * (single(2.0) + (maxCos * single(-2.0)))) - ((ux * ux) * ((maxCos + single(-1.0)) ^ single(2.0))))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux + (ux - (ux * ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 9.500000305706635 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux + \left(ux - ux \cdot ux\right)}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 9.50000031e-5Initial program 59.2%
associate-*l*59.2%
+-commutative59.2%
associate-+r-59.1%
fma-def59.1%
+-commutative59.1%
associate-+r-58.9%
fma-def58.9%
Simplified58.9%
sub-neg58.9%
distribute-rgt-in59.7%
Applied egg-rr59.7%
Taylor expanded in ux around 0 99.7%
rem-cube-cbrt99.7%
Applied egg-rr99.7%
Taylor expanded in uy around 0 99.7%
Simplified99.6%
if 9.50000031e-5 < (*.f32 uy 2) Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
Simplified57.6%
sub-neg57.6%
distribute-rgt-in58.4%
Applied egg-rr58.4%
Taylor expanded in maxCos around 0 94.6%
sub-neg94.6%
mul-1-neg94.6%
remove-double-neg94.6%
sub-neg94.6%
distribute-lft-in94.6%
*-rgt-identity94.6%
distribute-rgt-neg-out94.6%
unpow294.6%
unsub-neg94.6%
unpow294.6%
Simplified94.6%
Final simplification97.5%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 4.7500001528533176e-5)
(sqrt
(- (* ux (+ 2.0 (* maxCos -2.0))) (* (* ux ux) (pow (+ maxCos -1.0) 2.0))))
(* (cos (* 2.0 (* uy PI))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 4.7500001528533176e-5f) {
tmp = sqrtf(((ux * (2.0f + (maxCos * -2.0f))) - ((ux * ux) * powf((maxCos + -1.0f), 2.0f))));
} else {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(4.7500001528533176e-5)) tmp = sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0)))) - Float32(Float32(ux * ux) * (Float32(maxCos + Float32(-1.0)) ^ Float32(2.0))))); else tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * 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(4.7500001528533176e-5)) tmp = sqrt(((ux * (single(2.0) + (maxCos * single(-2.0)))) - ((ux * ux) * ((maxCos + single(-1.0)) ^ single(2.0))))); else tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((ux * (single(2.0) - ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 4.7500001528533176 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\end{array}
\end{array}
if uy < 4.75000015e-5Initial program 59.2%
associate-*l*59.2%
+-commutative59.2%
associate-+r-59.1%
fma-def59.1%
+-commutative59.1%
associate-+r-58.9%
fma-def58.9%
Simplified58.9%
sub-neg58.9%
distribute-rgt-in59.7%
Applied egg-rr59.7%
Taylor expanded in ux around 0 99.7%
rem-cube-cbrt99.7%
Applied egg-rr99.7%
Taylor expanded in uy around 0 99.7%
Simplified99.6%
if 4.75000015e-5 < uy Initial program 57.7%
associate-*l*57.7%
+-commutative57.7%
associate-+r-57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.6%
fma-def57.6%
Simplified57.6%
Taylor expanded in ux around -inf 98.5%
+-commutative98.5%
metadata-eval98.5%
cancel-sign-sub-inv98.5%
fma-def98.6%
cancel-sign-sub-inv98.6%
metadata-eval98.6%
+-commutative98.6%
*-commutative98.6%
fma-def98.6%
mul-1-neg98.6%
*-commutative98.6%
distribute-rgt-neg-in98.6%
mul-1-neg98.6%
unsub-neg98.6%
unpow298.6%
distribute-rgt-neg-in98.6%
Simplified98.6%
Taylor expanded in maxCos around 0 94.6%
mul-1-neg94.6%
unpow294.6%
distribute-rgt-neg-out94.6%
*-commutative94.6%
distribute-lft-out94.6%
Simplified94.6%
Final simplification97.5%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.0006500000017695129)
(sqrt
(- (* ux (+ 2.0 (* maxCos -2.0))) (* (* ux ux) (pow (+ maxCos -1.0) 2.0))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.0006500000017695129f) {
tmp = sqrtf(((ux * (2.0f + (maxCos * -2.0f))) - ((ux * ux) * powf((maxCos + -1.0f), 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.0006500000017695129)) tmp = sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0)))) - Float32(Float32(ux * ux) * (Float32(maxCos + Float32(-1.0)) ^ 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.0006500000017695129)) tmp = sqrt(((ux * (single(2.0) + (maxCos * single(-2.0)))) - ((ux * ux) * ((maxCos + single(-1.0)) ^ 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.0006500000017695129:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 6.50000002e-4Initial program 59.1%
associate-*l*59.1%
+-commutative59.1%
associate-+r-59.1%
fma-def59.1%
+-commutative59.1%
associate-+r-58.9%
fma-def58.9%
Simplified58.9%
sub-neg58.9%
distribute-rgt-in59.7%
Applied egg-rr59.7%
Taylor expanded in ux around 0 99.6%
rem-cube-cbrt99.6%
Applied egg-rr99.6%
Taylor expanded in uy around 0 97.8%
Simplified97.8%
if 6.50000002e-4 < uy Initial program 57.3%
associate-*l*57.3%
+-commutative57.3%
associate-+r-57.2%
fma-def57.2%
+-commutative57.2%
associate-+r-57.1%
fma-def57.1%
Simplified57.1%
Taylor expanded in ux around 0 47.0%
Taylor expanded in maxCos around 0 75.5%
*-commutative75.5%
Simplified75.5%
Final simplification91.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux (+ 2.0 (* maxCos -2.0))) (* (* ux ux) (pow (+ maxCos -1.0) 2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f + (maxCos * -2.0f))) - ((ux * ux) * powf((maxCos + -1.0f), 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 * ux) * ((maxcos + (-1.0e0)) ** 2.0e0))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0)))) - Float32(Float32(ux * ux) * (Float32(maxCos + Float32(-1.0)) ^ Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) + (maxCos * single(-2.0)))) - ((ux * ux) * ((maxCos + single(-1.0)) ^ single(2.0))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
sub-neg58.3%
distribute-rgt-in59.1%
Applied egg-rr59.1%
Taylor expanded in ux around 0 99.2%
rem-cube-cbrt99.0%
Applied egg-rr99.0%
Taylor expanded in uy around 0 81.8%
Simplified81.8%
Final simplification81.8%
(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 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in uy around 0 51.7%
Taylor expanded in ux around 0 66.1%
Final simplification66.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (+ ux ux) (* ux ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux + ux) - (ux * 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(((ux + ux) - (ux * ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux + ux) - Float32(ux * ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux + ux) - (ux * ux))); end
\begin{array}{l}
\\
\sqrt{\left(ux + ux\right) - ux \cdot ux}
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
sub-neg58.3%
distribute-rgt-in59.1%
Applied egg-rr59.1%
Taylor expanded in maxCos around 0 93.3%
sub-neg93.3%
mul-1-neg93.3%
remove-double-neg93.3%
sub-neg93.3%
distribute-lft-in93.3%
*-rgt-identity93.3%
distribute-rgt-neg-out93.3%
unpow293.3%
unsub-neg93.3%
unpow293.3%
Simplified93.3%
Taylor expanded in uy around 0 77.1%
count-277.1%
unpow277.1%
Simplified77.1%
Final simplification77.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ ux ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux + 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((ux + ux))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux + ux)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux + ux)); end
\begin{array}{l}
\\
\sqrt{ux + ux}
\end{array}
Initial program 58.6%
associate-*l*58.6%
+-commutative58.6%
associate-+r-58.5%
fma-def58.5%
+-commutative58.5%
associate-+r-58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in uy around 0 51.7%
Taylor expanded in ux around 0 66.1%
Taylor expanded in maxCos around 0 63.5%
count-263.5%
Simplified63.5%
Final simplification63.5%
herbie shell --seed 2023297
(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)))))))