
(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
(cbrt
(*
(pow
(fma
ux
(* 2.0 (- 1.0 maxCos))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0))))
1.5)
(pow (cos (* PI (* 2.0 uy))) 3.0))))
float code(float ux, float uy, float maxCos) {
return cbrtf((powf(fmaf(ux, (2.0f * (1.0f - maxCos)), (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f)))), 1.5f) * powf(cosf((((float) M_PI) * (2.0f * uy))), 3.0f)));
}
function code(ux, uy, maxCos) return cbrt(Float32((fma(ux, Float32(Float32(2.0) * Float32(Float32(1.0) - maxCos)), Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0))))) ^ Float32(1.5)) * (cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) ^ Float32(3.0)))) end
\begin{array}{l}
\\
\sqrt[3]{{\left(\mathsf{fma}\left(ux, 2 \cdot \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)\right)}^{1.5} \cdot {\cos \left(\pi \cdot \left(2 \cdot uy\right)\right)}^{3}}
\end{array}
Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.1%
Simplified57.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
distribute-lft-in98.9%
metadata-eval98.9%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
associate-*r*98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
*-commutative98.9%
add-cbrt-cube98.9%
add-cbrt-cube98.9%
cbrt-unprod98.9%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(fma
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 cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, ((1.0f - maxCos) + (1.0f - maxCos)), ((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos)), Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * (ux ^ Float32(2.0))))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\end{array}
Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.1%
Simplified57.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
distribute-lft-in98.9%
metadata-eval98.9%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
associate-*r*98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* 2.0 uy))) (sqrt (- (* ux (+ 2.0 (* maxCos -2.0))) (pow (* ux (+ maxCos -1.0)) 2.0)))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (2.0f * uy))) * sqrtf(((ux * (2.0f + (maxCos * -2.0f))) - powf((ux * (maxCos + -1.0f)), 2.0f)));
}
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(maxCos * Float32(-2.0)))) - (Float32(ux * Float32(maxCos + Float32(-1.0))) ^ Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt(((ux * (single(2.0) + (maxCos * single(-2.0)))) - ((ux * (maxCos + single(-1.0))) ^ single(2.0)))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}
\end{array}
Initial program 57.0%
distribute-rgt-in57.0%
+-commutative57.0%
associate-+r-57.1%
fma-udef57.1%
+-commutative57.1%
associate-+r-57.0%
fma-udef57.0%
Applied egg-rr57.0%
distribute-rgt-out57.1%
Simplified57.1%
Taylor expanded in ux around 0 98.9%
+-commutative98.9%
cancel-sign-sub-inv98.9%
metadata-eval98.9%
mul-1-neg98.9%
unsub-neg98.9%
metadata-eval98.9%
cancel-sign-sub-inv98.9%
cancel-sign-sub-inv98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
unpow298.9%
swap-sqr98.9%
sub-neg98.9%
metadata-eval98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* 2.0 uy) 0.00018780000391416252)
(sqrt
(fma
ux
(+ 2.0 (* maxCos -2.0))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0)))))
(* (cos (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.00018780000391416252f) {
tmp = sqrtf(fmaf(ux, (2.0f + (maxCos * -2.0f)), (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f)))));
} 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 (Float32(Float32(2.0) * uy) <= Float32(0.00018780000391416252)) tmp = sqrt(fma(ux, Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))), Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0)))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.00018780000391416252:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\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 (*.f32 uy 2) < 1.87800004e-4Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.5%
Simplified59.7%
Taylor expanded in ux around 0 99.4%
fma-def99.6%
+-commutative99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
distribute-lft-in99.6%
metadata-eval99.6%
associate--l+99.6%
mul-1-neg99.6%
sub-neg99.6%
associate-*r*99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in uy around 0 99.4%
fma-def99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
*-commutative99.5%
*-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
Simplified99.5%
if 1.87800004e-4 < (*.f32 uy 2) Initial program 53.5%
distribute-rgt-in53.5%
+-commutative53.5%
associate-+r-53.4%
fma-udef53.4%
+-commutative53.4%
associate-+r-53.4%
fma-udef53.4%
Applied egg-rr53.4%
distribute-rgt-out53.5%
Simplified53.5%
Taylor expanded in ux around 0 97.9%
+-commutative97.9%
cancel-sign-sub-inv97.9%
metadata-eval97.9%
mul-1-neg97.9%
unsub-neg97.9%
metadata-eval97.9%
cancel-sign-sub-inv97.9%
cancel-sign-sub-inv97.9%
metadata-eval97.9%
*-commutative97.9%
unpow297.9%
unpow297.9%
swap-sqr97.9%
sub-neg97.9%
metadata-eval97.9%
sub-neg97.9%
metadata-eval97.9%
Simplified97.9%
Taylor expanded in maxCos around 0 94.3%
unpow294.3%
distribute-rgt-out--94.3%
Simplified94.3%
Final simplification97.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.00018780000391416252) (sqrt (* (- 1.0 maxCos) (+ (* (pow ux 2.0) (+ maxCos -1.0)) (* ux 2.0)))) (* (cos (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.00018780000391416252f) {
tmp = sqrtf(((1.0f - maxCos) * ((powf(ux, 2.0f) * (maxCos + -1.0f)) + (ux * 2.0f))));
} 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 (Float32(Float32(2.0) * uy) <= Float32(0.00018780000391416252)) tmp = sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32((ux ^ Float32(2.0)) * Float32(maxCos + Float32(-1.0))) + Float32(ux * Float32(2.0))))); 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 ((single(2.0) * uy) <= single(0.00018780000391416252)) tmp = sqrt(((single(1.0) - maxCos) * (((ux ^ single(2.0)) * (maxCos + single(-1.0))) + (ux * single(2.0))))); 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}\;2 \cdot uy \leq 0.00018780000391416252:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left({ux}^{2} \cdot \left(maxCos + -1\right) + ux \cdot 2\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 (*.f32 uy 2) < 1.87800004e-4Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.5%
Simplified59.7%
Taylor expanded in ux around 0 99.4%
fma-def99.6%
+-commutative99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
distribute-lft-in99.6%
metadata-eval99.6%
associate--l+99.6%
mul-1-neg99.6%
sub-neg99.6%
associate-*r*99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in uy around 0 99.4%
expm1-log1p-u99.3%
expm1-udef82.2%
Applied egg-rr82.2%
expm1-def99.4%
expm1-log1p99.5%
fma-udef99.5%
*-commutative99.5%
+-commutative99.5%
metadata-eval99.5%
metadata-eval99.5%
distribute-lft-neg-in99.5%
distribute-rgt-neg-in99.5%
neg-mul-199.5%
distribute-lft-in99.5%
neg-mul-199.5%
sub-neg99.5%
fma-def99.4%
associate-*r*99.4%
*-commutative99.4%
associate-*r*99.4%
distribute-rgt-out99.5%
Simplified99.5%
if 1.87800004e-4 < (*.f32 uy 2) Initial program 53.5%
distribute-rgt-in53.5%
+-commutative53.5%
associate-+r-53.4%
fma-udef53.4%
+-commutative53.4%
associate-+r-53.4%
fma-udef53.4%
Applied egg-rr53.4%
distribute-rgt-out53.5%
Simplified53.5%
Taylor expanded in ux around 0 97.9%
+-commutative97.9%
cancel-sign-sub-inv97.9%
metadata-eval97.9%
mul-1-neg97.9%
unsub-neg97.9%
metadata-eval97.9%
cancel-sign-sub-inv97.9%
cancel-sign-sub-inv97.9%
metadata-eval97.9%
*-commutative97.9%
unpow297.9%
unpow297.9%
swap-sqr97.9%
sub-neg97.9%
metadata-eval97.9%
sub-neg97.9%
metadata-eval97.9%
Simplified97.9%
Taylor expanded in maxCos around 0 94.3%
unpow294.3%
distribute-rgt-out--94.3%
Simplified94.3%
Final simplification97.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* (- 1.0 maxCos) (+ (* (pow ux 2.0) (+ maxCos -1.0)) (* ux 2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((1.0f - maxCos) * ((powf(ux, 2.0f) * (maxCos + -1.0f)) + (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(((1.0e0 - maxcos) * (((ux ** 2.0e0) * (maxcos + (-1.0e0))) + (ux * 2.0e0))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32((ux ^ Float32(2.0)) * Float32(maxCos + Float32(-1.0))) + Float32(ux * Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(1.0) - maxCos) * (((ux ^ single(2.0)) * (maxCos + single(-1.0))) + (ux * single(2.0))))); end
\begin{array}{l}
\\
\sqrt{\left(1 - maxCos\right) \cdot \left({ux}^{2} \cdot \left(maxCos + -1\right) + ux \cdot 2\right)}
\end{array}
Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.1%
Simplified57.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
distribute-lft-in98.9%
metadata-eval98.9%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
associate-*r*98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in uy around 0 81.0%
expm1-log1p-u80.9%
expm1-udef69.6%
Applied egg-rr69.6%
expm1-def81.0%
expm1-log1p81.0%
fma-udef81.0%
*-commutative81.0%
+-commutative81.0%
metadata-eval81.0%
metadata-eval81.0%
distribute-lft-neg-in81.0%
distribute-rgt-neg-in81.0%
neg-mul-181.0%
distribute-lft-in81.0%
neg-mul-181.0%
sub-neg81.0%
fma-def81.0%
associate-*r*81.0%
*-commutative81.0%
associate-*r*81.0%
distribute-rgt-out81.0%
Simplified81.0%
Final simplification81.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux (- 2.0 (* 2.0 maxCos))) (pow ux 2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (2.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 * (2.0e0 - (2.0e0 * maxcos))) - (ux ** 2.0e0)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) - (ux ^ Float32(2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2}}
\end{array}
Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.1%
Simplified57.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
distribute-lft-in98.9%
metadata-eval98.9%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
associate-*r*98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in uy around 0 81.0%
Taylor expanded in maxCos around 0 78.9%
mul-1-neg78.9%
Simplified78.9%
Final simplification78.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux 2.0) (pow ux 2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * 2.0f) - 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 * 2.0e0) - (ux ** 2.0e0)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(2.0)) - (ux ^ Float32(2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * single(2.0)) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot 2 - {ux}^{2}}
\end{array}
Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.1%
Simplified57.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
distribute-lft-in98.9%
metadata-eval98.9%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
associate-*r*98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in maxCos around 0 92.7%
+-commutative92.7%
mul-1-neg92.7%
unsub-neg92.7%
*-commutative92.7%
Simplified92.7%
Taylor expanded in uy around 0 76.2%
Final simplification76.2%
(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 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.1%
Simplified57.2%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
distribute-lft-in98.9%
metadata-eval98.9%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
associate-*r*98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in uy around 0 81.0%
Taylor expanded in maxCos around 0 76.2%
+-commutative76.2%
mul-1-neg76.2%
sub-neg76.2%
unpow276.2%
distribute-rgt-out--76.1%
Simplified76.1%
Final simplification76.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- -2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf((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 * -(-2.0e0)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(-Float32(-2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * -single(-2.0))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(--2\right)}
\end{array}
Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.1%
Simplified57.2%
Taylor expanded in uy around 0 50.3%
Taylor expanded in ux around 0 65.2%
Taylor expanded in maxCos around 0 62.9%
*-commutative62.9%
Simplified62.9%
Final simplification62.9%
herbie shell --seed 2023319
(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)))))))