
(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 10 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 (log (exp (* uy (* PI 2.0))))) (sqrt (* (- 1.0 maxCos) (* ux (+ 2.0 (* ux (+ maxCos -1.0))))))))
float code(float ux, float uy, float maxCos) {
return cosf(logf(expf((uy * (((float) M_PI) * 2.0f))))) * sqrtf(((1.0f - maxCos) * (ux * (2.0f + (ux * (maxCos + -1.0f))))));
}
function code(ux, uy, maxCos) return Float32(cos(log(exp(Float32(uy * Float32(Float32(pi) * Float32(2.0)))))) * sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * Float32(Float32(2.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(log(exp((uy * (single(pi) * single(2.0)))))) * sqrt(((single(1.0) - maxCos) * (ux * (single(2.0) + (ux * (maxCos + single(-1.0))))))); end
\begin{array}{l}
\\
\cos \log \left(e^{uy \cdot \left(\pi \cdot 2\right)}\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.0%
pow399.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 99.0%
*-commutative99.0%
*-commutative99.0%
*-commutative99.0%
associate-*r*99.0%
unpow199.0%
sqr-pow93.5%
fma-def93.5%
sub-neg93.5%
metadata-eval93.5%
unpow293.5%
cancel-sign-sub-inv93.5%
metadata-eval93.5%
unpow1/293.5%
Simplified99.0%
add-log-exp99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* 2.0 (* uy PI))) (sqrt (* (* (- 1.0 maxCos) ux) (+ 2.0 (* ux (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((((1.0f - maxCos) * ux) * (2.0f + (ux * (maxCos + -1.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * ux) * Float32(Float32(2.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((((single(1.0) - maxCos) * ux) * (single(2.0) + (ux * (maxCos + single(-1.0)))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(\left(1 - maxCos\right) \cdot ux\right) \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)}
\end{array}
Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.0%
pow399.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 99.0%
*-commutative99.0%
*-commutative99.0%
*-commutative99.0%
associate-*r*99.0%
unpow199.0%
sqr-pow93.5%
fma-def93.5%
sub-neg93.5%
metadata-eval93.5%
unpow293.5%
cancel-sign-sub-inv93.5%
metadata-eval93.5%
unpow1/293.5%
Simplified99.0%
Taylor expanded in uy around inf 99.0%
*-commutative99.0%
distribute-rgt-in99.0%
associate-*r*99.0%
unpow299.0%
+-commutative99.0%
+-commutative99.0%
unpow299.0%
associate-*r*99.0%
distribute-rgt-in99.0%
associate-*r*99.0%
*-commutative99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* PI 2.0))) (sqrt (* (- 1.0 maxCos) (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (((float) M_PI) * 2.0f))) * sqrtf(((1.0f - maxCos) * (ux * (2.0f - ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(pi) * Float32(2.0)))) * sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * Float32(Float32(2.0) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(pi) * single(2.0)))) * sqrt(((single(1.0) - maxCos) * (ux * (single(2.0) - ux)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(\pi \cdot 2\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot \left(2 - ux\right)\right)}
\end{array}
Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.0%
pow399.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 99.0%
*-commutative99.0%
*-commutative99.0%
*-commutative99.0%
associate-*r*99.0%
unpow199.0%
sqr-pow93.5%
fma-def93.5%
sub-neg93.5%
metadata-eval93.5%
unpow293.5%
cancel-sign-sub-inv93.5%
metadata-eval93.5%
unpow1/293.5%
Simplified99.0%
Taylor expanded in maxCos around 0 97.4%
neg-mul-197.4%
+-commutative97.4%
sub-neg97.4%
*-commutative97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= maxCos 0.0001900000061141327) (* (cos (* 2.0 (* uy PI))) (sqrt (* ux (- 2.0 ux)))) (sqrt (* (- 1.0 maxCos) (+ (* (+ maxCos -1.0) (* ux ux)) (* 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 0.0001900000061141327f) {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
} else {
tmp = sqrtf(((1.0f - maxCos) * (((maxCos + -1.0f) * (ux * ux)) + (2.0f * ux))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(0.0001900000061141327)) tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); else tmp = sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * ux)) + Float32(Float32(2.0) * ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(0.0001900000061141327)) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((ux * (single(2.0) - ux))); else tmp = sqrt(((single(1.0) - maxCos) * (((maxCos + single(-1.0)) * (ux * ux)) + (single(2.0) * ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 0.0001900000061141327:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot \left(ux \cdot ux\right) + 2 \cdot ux\right)}\\
\end{array}
\end{array}
if maxCos < 1.90000006e-4Initial program 58.0%
associate-*l*58.0%
sub-neg58.0%
+-commutative58.0%
distribute-rgt-neg-in58.0%
fma-def58.1%
+-commutative58.1%
associate-+r-58.1%
fma-def58.1%
neg-sub058.1%
+-commutative58.1%
associate-+r-58.0%
associate--r-58.0%
neg-sub058.0%
+-commutative58.0%
sub-neg58.0%
fma-def58.0%
Simplified58.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.0%
pow399.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 99.0%
*-commutative99.0%
*-commutative99.0%
*-commutative99.0%
associate-*r*99.0%
unpow199.0%
sqr-pow93.0%
fma-def93.0%
sub-neg93.0%
metadata-eval93.0%
unpow293.0%
cancel-sign-sub-inv93.0%
metadata-eval93.0%
unpow1/293.0%
Simplified99.0%
Taylor expanded in maxCos around 0 97.8%
neg-mul-197.8%
+-commutative97.8%
sub-neg97.8%
*-commutative97.8%
Simplified97.8%
if 1.90000006e-4 < maxCos Initial program 60.1%
associate-*l*60.1%
sub-neg60.1%
+-commutative60.1%
distribute-rgt-neg-in60.1%
fma-def60.8%
+-commutative60.8%
associate-+r-60.6%
fma-def60.6%
neg-sub060.6%
+-commutative60.6%
associate-+r-59.5%
associate--r-59.5%
neg-sub059.5%
+-commutative59.5%
sub-neg59.5%
fma-def59.5%
Simplified59.5%
Taylor expanded in ux around 0 98.1%
fma-def98.1%
sub-neg98.1%
metadata-eval98.1%
*-commutative98.1%
unpow298.1%
+-commutative98.1%
mul-1-neg98.1%
sub-neg98.1%
metadata-eval98.1%
distribute-neg-in98.1%
metadata-eval98.1%
+-commutative98.1%
mul-1-neg98.1%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in uy around 0 87.7%
*-commutative87.7%
cancel-sign-sub-inv87.7%
metadata-eval87.7%
metadata-eval87.7%
metadata-eval87.7%
distribute-lft-neg-in87.7%
distribute-rgt-neg-in87.7%
distribute-lft-in87.7%
sub-neg87.7%
associate-*r*87.7%
*-commutative87.7%
sub-neg87.7%
mul-1-neg87.7%
associate-*r*87.7%
associate-*r*87.7%
mul-1-neg87.7%
sub-neg87.7%
Simplified87.8%
Final simplification96.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.001500000013038516)
(sqrt
(+
(* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0)))
(* ux (- 2.0 (* 2.0 maxCos)))))
(* (cos (* uy (* PI 2.0))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.001500000013038516f) {
tmp = sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) + (ux * (2.0f - (2.0f * maxCos)))));
} else {
tmp = cosf((uy * (((float) M_PI) * 2.0f))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.001500000013038516)) tmp = sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(pi) * Float32(2.0)))) * 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.001500000013038516)) tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); else tmp = cos((uy * (single(pi) * single(2.0)))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.001500000013038516:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(\pi \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 0.00150000001Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-def58.2%
+-commutative58.2%
associate-+r-58.2%
fma-def58.2%
neg-sub058.2%
+-commutative58.2%
associate-+r-58.1%
associate--r-58.1%
neg-sub058.1%
+-commutative58.1%
sub-neg58.1%
fma-def58.1%
Simplified58.1%
Taylor expanded in ux around 0 99.3%
fma-def99.3%
sub-neg99.3%
metadata-eval99.3%
*-commutative99.3%
unpow299.3%
+-commutative99.3%
mul-1-neg99.3%
sub-neg99.3%
metadata-eval99.3%
distribute-neg-in99.3%
metadata-eval99.3%
+-commutative99.3%
mul-1-neg99.3%
associate--l+99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
Taylor expanded in uy around 0 96.0%
if 0.00150000001 < uy Initial program 58.4%
associate-*l*58.4%
sub-neg58.4%
+-commutative58.4%
distribute-rgt-neg-in58.4%
fma-def58.6%
+-commutative58.6%
associate-+r-58.7%
fma-def58.7%
neg-sub058.7%
+-commutative58.7%
associate-+r-58.5%
associate--r-58.5%
neg-sub058.5%
+-commutative58.5%
sub-neg58.5%
fma-def58.5%
Simplified58.5%
Taylor expanded in maxCos around 0 56.7%
Taylor expanded in ux around 0 72.7%
*-commutative72.7%
Simplified72.7%
Final simplification89.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0))) (* ux (- 2.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * 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((((1.0e0 - maxcos) * ((maxcos + (-1.0e0)) * (ux ** 2.0e0))) + (ux * (2.0e0 - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in uy around 0 79.3%
Final simplification79.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (* (- 1.0 maxCos) (+ 2.0 (- (* maxCos ux) ux))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((1.0f - maxCos) * (2.0f + ((maxCos * 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 * ((1.0e0 - maxcos) * (2.0e0 + ((maxcos * ux) - ux)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(2.0) + Float32(Float32(maxCos * ux) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(1.0) - maxCos) * (single(2.0) + ((maxCos * ux) - ux))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(1 - maxCos\right) \cdot \left(2 + \left(maxCos \cdot ux - ux\right)\right)\right)}
\end{array}
Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.0%
pow399.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 99.0%
*-commutative99.0%
*-commutative99.0%
*-commutative99.0%
associate-*r*99.0%
unpow199.0%
sqr-pow93.5%
fma-def93.5%
sub-neg93.5%
metadata-eval93.5%
unpow293.5%
cancel-sign-sub-inv93.5%
metadata-eval93.5%
unpow1/293.5%
Simplified99.0%
Taylor expanded in uy around 0 79.3%
*-commutative79.3%
*-commutative79.3%
*-commutative79.3%
sub-neg79.3%
metadata-eval79.3%
*-commutative79.3%
associate-*l*79.3%
distribute-rgt-in79.3%
neg-mul-179.3%
unsub-neg79.3%
*-commutative79.3%
Simplified79.3%
Final simplification79.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* 2.0 ux) (* ux ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * 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(((2.0e0 * ux) - (ux * ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in uy around 0 79.3%
Taylor expanded in maxCos around 0 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
*-commutative74.9%
unpow274.9%
Simplified74.9%
Final simplification74.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- 2.0 ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (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((ux * (2.0e0 - ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) - ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in uy around 0 79.3%
Taylor expanded in maxCos around 0 78.6%
fma-def78.6%
*-commutative78.6%
fma-def78.6%
unpow278.6%
+-commutative78.6%
mul-1-neg78.6%
unsub-neg78.6%
*-commutative78.6%
unpow278.6%
Simplified78.6%
Taylor expanded in maxCos around 0 74.9%
unpow274.9%
cancel-sign-sub-inv74.9%
distribute-rgt-out74.8%
sub-neg74.8%
Simplified74.8%
Final simplification74.8%
(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 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
+-commutative58.3%
associate-+r-58.3%
fma-def58.3%
neg-sub058.3%
+-commutative58.3%
associate-+r-58.2%
associate--r-58.2%
neg-sub058.2%
+-commutative58.2%
sub-neg58.2%
fma-def58.2%
Simplified58.2%
Taylor expanded in uy around 0 49.3%
Taylor expanded in ux around 0 6.6%
Final simplification6.6%
herbie shell --seed 2023172
(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)))))))