
(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 (* PI (* 2.0 uy))) (sqrt (* (* ux (+ 2.0 (* ux (+ maxCos -1.0)))) (- 1.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (2.0f * uy))) * sqrtf(((ux * (2.0f + (ux * (maxCos + -1.0f)))) * (1.0f - maxCos)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))) * Float32(Float32(1.0) - maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt(((ux * (single(2.0) + (ux * (maxCos + single(-1.0))))) * (single(1.0) - maxCos))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{\left(ux \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)\right) \cdot \left(1 - maxCos\right)}
\end{array}
Initial program 54.9%
associate-*l*54.9%
sub-neg54.9%
+-commutative54.9%
distribute-rgt-neg-in54.9%
fma-def55.0%
+-commutative55.0%
associate-+r-55.0%
fma-def55.0%
neg-sub055.0%
+-commutative55.0%
associate-+r-54.9%
associate--r-54.9%
neg-sub054.9%
+-commutative54.9%
sub-neg54.9%
fma-def54.9%
Simplified54.9%
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.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
expm1-log1p-u99.1%
Applied egg-rr99.1%
Taylor expanded in uy around inf 99.1%
associate-*r*99.1%
*-commutative99.1%
*-commutative99.1%
*-commutative99.1%
*-commutative99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
distribute-rgt-in99.1%
sub-neg99.1%
*-commutative99.1%
associate-*r*99.1%
*-commutative99.1%
distribute-rgt-out99.2%
Simplified99.2%
Taylor expanded in uy around inf 99.2%
associate-*r*99.2%
*-commutative99.2%
*-commutative99.2%
sub-neg99.2%
metadata-eval99.2%
unpow299.2%
fma-udef99.2%
*-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= uy 9.000000136438757e-5) (sqrt (* (* ux (+ 2.0 (* ux (+ maxCos -1.0)))) (- 1.0 maxCos))) (* (cos (* uy (* PI 2.0))) (sqrt (- (* 2.0 ux) (* ux ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 9.000000136438757e-5f) {
tmp = sqrtf(((ux * (2.0f + (ux * (maxCos + -1.0f)))) * (1.0f - maxCos)));
} else {
tmp = cosf((uy * (((float) M_PI) * 2.0f))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(9.000000136438757e-5)) tmp = sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))) * Float32(Float32(1.0) - maxCos))); else tmp = Float32(cos(Float32(uy * Float32(Float32(pi) * Float32(2.0)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(9.000000136438757e-5)) tmp = sqrt(((ux * (single(2.0) + (ux * (maxCos + single(-1.0))))) * (single(1.0) - maxCos))); else tmp = cos((uy * (single(pi) * single(2.0)))) * sqrt(((single(2.0) * ux) - (ux * ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 9.000000136438757 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\left(ux \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)\right) \cdot \left(1 - maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(\pi \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\end{array}
\end{array}
if uy < 9.00000014e-5Initial program 51.8%
associate-*l*51.8%
sub-neg51.8%
+-commutative51.8%
distribute-rgt-neg-in51.8%
fma-def51.9%
+-commutative51.9%
associate-+r-51.9%
fma-def51.9%
neg-sub051.9%
+-commutative51.9%
associate-+r-51.8%
associate--r-51.8%
neg-sub051.8%
+-commutative51.8%
sub-neg51.8%
fma-def51.8%
Simplified51.8%
Taylor expanded in ux around 0 99.4%
fma-def99.4%
sub-neg99.4%
metadata-eval99.4%
*-commutative99.4%
unpow299.4%
+-commutative99.4%
mul-1-neg99.4%
sub-neg99.4%
metadata-eval99.4%
distribute-neg-in99.4%
metadata-eval99.4%
+-commutative99.4%
mul-1-neg99.4%
associate--l+99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
expm1-log1p-u99.4%
Applied egg-rr99.4%
Taylor expanded in uy around inf 99.4%
associate-*r*99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
cancel-sign-sub-inv99.4%
metadata-eval99.4%
distribute-rgt-in99.4%
sub-neg99.4%
*-commutative99.4%
associate-*r*99.4%
*-commutative99.4%
distribute-rgt-out99.5%
Simplified99.5%
Taylor expanded in uy around 0 99.4%
*-commutative99.4%
+-commutative99.4%
*-commutative99.4%
*-commutative99.4%
unpow299.4%
associate-*l*99.4%
distribute-lft-out99.4%
*-commutative99.4%
sub-neg99.4%
metadata-eval99.4%
Simplified99.4%
if 9.00000014e-5 < uy Initial program 59.2%
associate-*l*59.2%
+-commutative59.2%
associate-+r-59.3%
fma-def59.3%
+-commutative59.3%
associate-+r-59.2%
fma-def59.2%
Simplified59.2%
Taylor expanded in ux around -inf 98.7%
metadata-eval98.7%
cancel-sign-sub-inv98.7%
*-commutative98.7%
fma-def98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
+-commutative98.7%
*-commutative98.7%
fma-def98.7%
mul-1-neg98.7%
distribute-rgt-neg-in98.7%
unpow298.7%
mul-1-neg98.7%
sub-neg98.7%
Simplified98.7%
Taylor expanded in maxCos around 0 93.4%
+-commutative93.4%
neg-mul-193.4%
unsub-neg93.4%
unpow293.4%
Simplified93.4%
Final simplification96.9%
(FPCore (ux uy maxCos) :precision binary32 (if (<= uy 9.000000136438757e-5) (sqrt (* (* ux (+ 2.0 (* ux (+ maxCos -1.0)))) (- 1.0 maxCos))) (* (cos (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 9.000000136438757e-5f) {
tmp = sqrtf(((ux * (2.0f + (ux * (maxCos + -1.0f)))) * (1.0f - maxCos)));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(9.000000136438757e-5)) tmp = sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))) * Float32(Float32(1.0) - maxCos))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * 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(9.000000136438757e-5)) tmp = sqrt(((ux * (single(2.0) + (ux * (maxCos + single(-1.0))))) * (single(1.0) - maxCos))); else tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt((ux * (single(2.0) - ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 9.000000136438757 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\left(ux \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)\right) \cdot \left(1 - maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\end{array}
\end{array}
if uy < 9.00000014e-5Initial program 51.8%
associate-*l*51.8%
sub-neg51.8%
+-commutative51.8%
distribute-rgt-neg-in51.8%
fma-def51.9%
+-commutative51.9%
associate-+r-51.9%
fma-def51.9%
neg-sub051.9%
+-commutative51.9%
associate-+r-51.8%
associate--r-51.8%
neg-sub051.8%
+-commutative51.8%
sub-neg51.8%
fma-def51.8%
Simplified51.8%
Taylor expanded in ux around 0 99.4%
fma-def99.4%
sub-neg99.4%
metadata-eval99.4%
*-commutative99.4%
unpow299.4%
+-commutative99.4%
mul-1-neg99.4%
sub-neg99.4%
metadata-eval99.4%
distribute-neg-in99.4%
metadata-eval99.4%
+-commutative99.4%
mul-1-neg99.4%
associate--l+99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
expm1-log1p-u99.4%
Applied egg-rr99.4%
Taylor expanded in uy around inf 99.4%
associate-*r*99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
*-commutative99.4%
cancel-sign-sub-inv99.4%
metadata-eval99.4%
distribute-rgt-in99.4%
sub-neg99.4%
*-commutative99.4%
associate-*r*99.4%
*-commutative99.4%
distribute-rgt-out99.5%
Simplified99.5%
Taylor expanded in uy around 0 99.4%
*-commutative99.4%
+-commutative99.4%
*-commutative99.4%
*-commutative99.4%
unpow299.4%
associate-*l*99.4%
distribute-lft-out99.4%
*-commutative99.4%
sub-neg99.4%
metadata-eval99.4%
Simplified99.4%
if 9.00000014e-5 < uy Initial program 59.2%
associate-*l*59.2%
sub-neg59.2%
+-commutative59.2%
distribute-rgt-neg-in59.2%
fma-def59.2%
+-commutative59.2%
associate-+r-59.3%
fma-def59.3%
neg-sub059.3%
+-commutative59.3%
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 98.6%
fma-def98.6%
sub-neg98.6%
metadata-eval98.6%
*-commutative98.6%
unpow298.6%
+-commutative98.6%
mul-1-neg98.6%
sub-neg98.6%
metadata-eval98.6%
distribute-neg-in98.6%
metadata-eval98.6%
+-commutative98.6%
mul-1-neg98.6%
associate--l+98.7%
mul-1-neg98.7%
sub-neg98.7%
Simplified98.7%
expm1-log1p-u98.5%
Applied egg-rr98.5%
Taylor expanded in uy around inf 98.7%
associate-*r*98.7%
*-commutative98.7%
*-commutative98.7%
*-commutative98.7%
*-commutative98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
distribute-rgt-in98.7%
sub-neg98.7%
*-commutative98.7%
associate-*r*98.7%
*-commutative98.7%
distribute-rgt-out98.7%
Simplified98.7%
Taylor expanded in maxCos around 0 93.4%
associate-*r*93.4%
*-commutative93.4%
+-commutative93.4%
unpow293.4%
associate-*r*93.4%
distribute-rgt-out93.4%
mul-1-neg93.4%
Simplified93.4%
Final simplification96.9%
(FPCore (ux uy maxCos) :precision binary32 (if (<= uy 0.00419999985024333) (sqrt (* (* ux (+ 2.0 (* ux (+ maxCos -1.0)))) (- 1.0 maxCos))) (* (cos (* uy (* PI 2.0))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.00419999985024333f) {
tmp = sqrtf(((ux * (2.0f + (ux * (maxCos + -1.0f)))) * (1.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.00419999985024333)) tmp = sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))) * Float32(Float32(1.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.00419999985024333)) tmp = sqrt(((ux * (single(2.0) + (ux * (maxCos + single(-1.0))))) * (single(1.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.00419999985024333:\\
\;\;\;\;\sqrt{\left(ux \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)\right) \cdot \left(1 - 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.00419999985Initial program 54.2%
associate-*l*54.2%
sub-neg54.2%
+-commutative54.2%
distribute-rgt-neg-in54.2%
fma-def54.4%
+-commutative54.4%
associate-+r-54.4%
fma-def54.4%
neg-sub054.4%
+-commutative54.4%
associate-+r-54.3%
associate--r-54.3%
neg-sub054.3%
+-commutative54.3%
sub-neg54.3%
fma-def54.3%
Simplified54.3%
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.3%
mul-1-neg99.3%
sub-neg99.3%
Simplified99.3%
expm1-log1p-u99.3%
Applied egg-rr99.3%
Taylor expanded in uy around inf 99.3%
associate-*r*99.3%
*-commutative99.3%
*-commutative99.3%
*-commutative99.3%
*-commutative99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
distribute-rgt-in99.3%
sub-neg99.3%
*-commutative99.3%
associate-*r*99.3%
*-commutative99.3%
distribute-rgt-out99.3%
Simplified99.3%
Taylor expanded in uy around 0 95.3%
*-commutative95.3%
+-commutative95.3%
*-commutative95.3%
*-commutative95.3%
unpow295.3%
associate-*l*95.3%
distribute-lft-out95.3%
*-commutative95.3%
sub-neg95.3%
metadata-eval95.3%
Simplified95.3%
if 0.00419999985 < uy Initial program 57.1%
associate-*l*57.1%
+-commutative57.1%
associate-+r-57.4%
fma-def57.4%
+-commutative57.4%
associate-+r-57.2%
fma-def57.2%
Simplified57.2%
Taylor expanded in ux around 0 45.5%
Taylor expanded in maxCos around 0 71.8%
Final simplification89.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* (* ux (+ 2.0 (* ux (+ maxCos -1.0)))) (- 1.0 maxCos))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f + (ux * (maxCos + -1.0f)))) * (1.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 * (maxcos + (-1.0e0))))) * (1.0e0 - maxcos)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))) * Float32(Float32(1.0) - maxCos))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) + (ux * (maxCos + single(-1.0))))) * (single(1.0) - maxCos))); end
\begin{array}{l}
\\
\sqrt{\left(ux \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)\right) \cdot \left(1 - maxCos\right)}
\end{array}
Initial program 54.9%
associate-*l*54.9%
sub-neg54.9%
+-commutative54.9%
distribute-rgt-neg-in54.9%
fma-def55.0%
+-commutative55.0%
associate-+r-55.0%
fma-def55.0%
neg-sub055.0%
+-commutative55.0%
associate-+r-54.9%
associate--r-54.9%
neg-sub054.9%
+-commutative54.9%
sub-neg54.9%
fma-def54.9%
Simplified54.9%
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.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
expm1-log1p-u99.1%
Applied egg-rr99.1%
Taylor expanded in uy around inf 99.1%
associate-*r*99.1%
*-commutative99.1%
*-commutative99.1%
*-commutative99.1%
*-commutative99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
distribute-rgt-in99.1%
sub-neg99.1%
*-commutative99.1%
associate-*r*99.1%
*-commutative99.1%
distribute-rgt-out99.2%
Simplified99.2%
Taylor expanded in uy around 0 80.6%
*-commutative80.6%
+-commutative80.6%
*-commutative80.6%
*-commutative80.6%
unpow280.6%
associate-*l*80.6%
distribute-lft-out80.6%
*-commutative80.6%
sub-neg80.6%
metadata-eval80.6%
Simplified80.6%
Final simplification80.6%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0003000000142492354) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (+ ux -1.0) (- 1.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0003000000142492354f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((ux + -1.0f) * (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.0003000000142492354e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((ux + (-1.0e0)) * (1.0e0 - ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0003000000142492354)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(ux + Float32(-1.0)) * Float32(Float32(1.0) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0003000000142492354)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((ux + single(-1.0)) * (single(1.0) - ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0003000000142492354:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(ux + -1\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 3.00000014e-4Initial program 36.6%
add-cube-cbrt36.6%
pow336.6%
associate-*r*36.6%
pow236.6%
+-commutative36.6%
fma-def36.6%
Applied egg-rr36.6%
Taylor expanded in uy around 0 33.3%
associate-+r-33.3%
Simplified33.3%
Taylor expanded in ux around 0 76.4%
if 3.00000014e-4 < ux Initial program 88.3%
associate-*l*88.3%
sub-neg88.3%
+-commutative88.3%
distribute-rgt-neg-in88.3%
fma-def88.6%
+-commutative88.6%
associate-+r-88.4%
fma-def88.4%
neg-sub088.4%
+-commutative88.4%
associate-+r-88.3%
associate--r-88.3%
neg-sub088.3%
+-commutative88.3%
sub-neg88.3%
fma-def88.3%
Simplified88.3%
Taylor expanded in uy around 0 73.0%
Taylor expanded in maxCos around 0 70.1%
Final simplification74.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux (- 2.0 (* 2.0 maxCos))) (* ux ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (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 * (2.0e0 - (2.0e0 * maxcos))) - (ux * ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) - Float32(ux * ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) - (ux * ux))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - ux \cdot ux}
\end{array}
Initial program 54.9%
associate-*l*54.9%
sub-neg54.9%
+-commutative54.9%
distribute-rgt-neg-in54.9%
fma-def55.0%
+-commutative55.0%
associate-+r-55.0%
fma-def55.0%
neg-sub055.0%
+-commutative55.0%
associate-+r-54.9%
associate--r-54.9%
neg-sub054.9%
+-commutative54.9%
sub-neg54.9%
fma-def54.9%
Simplified54.9%
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.1%
mul-1-neg99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 80.6%
Taylor expanded in maxCos around 0 79.7%
mul-1-neg79.7%
unpow279.7%
distribute-rgt-neg-in79.7%
Simplified79.7%
Final simplification79.7%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (- 2.0 maxCos) maxCos))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.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 * ((2.0e0 - maxcos) - maxcos)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(2.0) - maxCos) - maxCos))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) - maxCos) - maxCos))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)}
\end{array}
Initial program 54.9%
associate-*l*54.9%
sub-neg54.9%
+-commutative54.9%
distribute-rgt-neg-in54.9%
fma-def55.0%
+-commutative55.0%
associate-+r-55.0%
fma-def55.0%
neg-sub055.0%
+-commutative55.0%
associate-+r-54.9%
associate--r-54.9%
neg-sub054.9%
+-commutative54.9%
sub-neg54.9%
fma-def54.9%
Simplified54.9%
Taylor expanded in ux around 0 78.2%
Taylor expanded in uy around 0 67.0%
neg-mul-167.0%
unsub-neg67.0%
sub-neg67.0%
metadata-eval67.0%
+-commutative67.0%
associate--r+67.0%
metadata-eval67.0%
Simplified67.0%
Final simplification67.0%
(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 54.9%
add-cube-cbrt54.8%
pow354.8%
associate-*r*54.8%
pow254.8%
+-commutative54.8%
fma-def54.8%
Applied egg-rr54.8%
Taylor expanded in uy around 0 47.4%
associate-+r-47.6%
Simplified47.6%
Taylor expanded in ux around 0 67.0%
Final simplification67.0%
(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 54.9%
add-cube-cbrt54.8%
pow354.8%
associate-*r*54.8%
pow254.8%
+-commutative54.8%
fma-def54.8%
Applied egg-rr54.8%
Taylor expanded in uy around 0 47.4%
associate-+r-47.6%
Simplified47.6%
Taylor expanded in ux around 0 67.0%
Taylor expanded in maxCos around 0 64.6%
Final simplification64.6%
herbie shell --seed 2023257
(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)))))))