UniformSampleCone, x

Percentage Accurate: 56.9% → 99.0%
Time: 19.3s
Alternatives: 10
Speedup: 3.1×

Specification

?
\[\left(\left(2.328306437 \cdot 10^{-10} \leq ux \land ux \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq uy \land uy \leq 1\right)\right) \land \left(0 \leq maxCos \land maxCos \leq 1\right)\]
\[\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
 (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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 56.9% accurate, 1.0× speedup?

\[\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
 (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}

Alternative 1: 99.0% accurate, 0.4× speedup?

\[\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} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. associate-*l*57.0%

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. sub-neg57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    3. +-commutative57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
    4. distribute-rgt-neg-in57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
    5. fma-def57.1%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
  3. Simplified57.2%

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
  4. Taylor expanded in ux around 0 98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  5. Step-by-step derivation
    1. fma-def98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
    2. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    3. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    4. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    5. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    6. distribute-lft-in98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    7. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    8. associate--l+98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    9. mul-1-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    10. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    11. associate-*r*98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
    12. sub-neg98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
    13. metadata-eval98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    14. +-commutative98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
  6. Simplified98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
  7. Step-by-step derivation
    1. *-commutative98.9%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)} \]
    2. add-cbrt-cube98.9%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)} \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}}} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \]
    3. add-cbrt-cube98.9%

      \[\leadsto \sqrt[3]{\left(\sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)} \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \cdot \color{blue}{\sqrt[3]{\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)\right) \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)}} \]
    4. cbrt-unprod98.9%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)} \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}\right) \cdot \left(\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)\right) \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)\right)}} \]
  8. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\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(uy \cdot 2\right)\right)}^{3}}} \]
  9. Final simplification99.1%

    \[\leadsto \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}} \]

Alternative 2: 99.1% accurate, 0.6× speedup?

\[\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} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. associate-*l*57.0%

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. sub-neg57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    3. +-commutative57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
    4. distribute-rgt-neg-in57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
    5. fma-def57.1%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
  3. Simplified57.2%

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
  4. Taylor expanded in ux around 0 98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  5. Step-by-step derivation
    1. fma-def98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
    2. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    3. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    4. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    5. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    6. distribute-lft-in98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    7. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    8. associate--l+98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    9. mul-1-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    10. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    11. associate-*r*98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
    12. sub-neg98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
    13. metadata-eval98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    14. +-commutative98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
  6. Simplified98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
  7. Final simplification98.9%

    \[\leadsto \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)} \]

Alternative 3: 99.1% accurate, 0.8× speedup?

\[\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} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. distribute-rgt-in57.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\left(1 - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right) + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    2. +-commutative57.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \color{blue}{\left(ux \cdot maxCos + \left(1 - ux\right)\right)} + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
    3. associate-+r-57.1%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \color{blue}{\left(\left(ux \cdot maxCos + 1\right) - ux\right)} + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
    4. fma-udef57.1%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)} - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
    5. +-commutative57.1%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(ux \cdot maxCos + \left(1 - ux\right)\right)}\right)} \]
    6. associate-+r-57.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(\left(ux \cdot maxCos + 1\right) - ux\right)}\right)} \]
    7. fma-udef57.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)} - ux\right)\right)} \]
  3. Applied egg-rr57.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right)\right)}} \]
  4. Step-by-step derivation
    1. distribute-rgt-out57.1%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}} \]
  5. Simplified57.1%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}} \]
  6. Taylor expanded in ux around 0 98.9%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{-1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}} \]
  7. Step-by-step derivation
    1. +-commutative98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 - 2 \cdot maxCos\right) + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)}} \]
    2. cancel-sign-sub-inv98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 + \left(-2\right) \cdot maxCos\right)} + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)} \]
    3. metadata-eval98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{-2} \cdot maxCos\right) + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)} \]
    4. mul-1-neg98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + -2 \cdot maxCos\right) + \color{blue}{\left(-{ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)}} \]
    5. unsub-neg98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 + -2 \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}}} \]
    6. metadata-eval98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{\left(-2\right)} \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
    7. cancel-sign-sub-inv98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 - 2 \cdot maxCos\right)} - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
    8. cancel-sign-sub-inv98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 + \left(-2\right) \cdot maxCos\right)} - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
    9. metadata-eval98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{-2} \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
    10. *-commutative98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{maxCos \cdot -2}\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
    11. unpow298.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \color{blue}{\left(ux \cdot ux\right)} \cdot {\left(maxCos - 1\right)}^{2}} \]
    12. unpow298.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot \color{blue}{\left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)}} \]
    13. swap-sqr98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \color{blue}{\left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)}} \]
    14. sub-neg98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)} \]
    15. metadata-eval98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + \color{blue}{-1}\right)\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)} \]
    16. sub-neg98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
    17. metadata-eval98.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
  8. Simplified98.9%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 + maxCos \cdot -2\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}} \]
  9. Final simplification98.9%

    \[\leadsto \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}} \]

Alternative 4: 96.6% accurate, 1.0× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy 2) < 1.87800004e-4

    1. Initial program 59.3%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Step-by-step derivation
      1. associate-*l*59.3%

        \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
      2. sub-neg59.3%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
      3. +-commutative59.3%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
      4. distribute-rgt-neg-in59.3%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
      5. fma-def59.5%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
    3. Simplified59.7%

      \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
    4. Taylor expanded in ux around 0 99.4%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
    5. Step-by-step derivation
      1. fma-def99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
      2. +-commutative99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      3. sub-neg99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      4. metadata-eval99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      5. +-commutative99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      6. distribute-lft-in99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      7. metadata-eval99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      8. associate--l+99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      9. mul-1-neg99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      10. sub-neg99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      11. associate-*r*99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
      12. sub-neg99.6%

        \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
      13. metadata-eval99.6%

        \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
      14. +-commutative99.6%

        \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
    6. Simplified99.6%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
    7. Taylor expanded in uy around 0 99.4%

      \[\leadsto \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
    8. Step-by-step derivation
      1. fma-def99.5%

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(ux, 2 - 2 \cdot maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
      2. cancel-sign-sub-inv99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{2 + \left(-2\right) \cdot maxCos}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      3. metadata-eval99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 + \color{blue}{-2} \cdot maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      4. *-commutative99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 + \color{blue}{maxCos \cdot -2}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      5. *-commutative99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \color{blue}{\left(\left(maxCos - 1\right) \cdot \left(1 - maxCos\right)\right)}\right)} \]
      6. sub-neg99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \left(\color{blue}{\left(maxCos + \left(-1\right)\right)} \cdot \left(1 - maxCos\right)\right)\right)} \]
      7. metadata-eval99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \left(\left(maxCos + \color{blue}{-1}\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    9. Simplified99.5%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}} \]

    if 1.87800004e-4 < (*.f32 uy 2)

    1. Initial program 53.5%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Step-by-step derivation
      1. distribute-rgt-in53.5%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\left(1 - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right) + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
      2. +-commutative53.5%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \color{blue}{\left(ux \cdot maxCos + \left(1 - ux\right)\right)} + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
      3. associate-+r-53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \color{blue}{\left(\left(ux \cdot maxCos + 1\right) - ux\right)} + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
      4. fma-udef53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)} - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
      5. +-commutative53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(ux \cdot maxCos + \left(1 - ux\right)\right)}\right)} \]
      6. associate-+r-53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(\left(ux \cdot maxCos + 1\right) - ux\right)}\right)} \]
      7. fma-udef53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)} - ux\right)\right)} \]
    3. Applied egg-rr53.4%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right)\right)}} \]
    4. Step-by-step derivation
      1. distribute-rgt-out53.5%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}} \]
    5. Simplified53.5%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}} \]
    6. Taylor expanded in ux around 0 97.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{-1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}} \]
    7. Step-by-step derivation
      1. +-commutative97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 - 2 \cdot maxCos\right) + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)}} \]
      2. cancel-sign-sub-inv97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 + \left(-2\right) \cdot maxCos\right)} + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)} \]
      3. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{-2} \cdot maxCos\right) + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)} \]
      4. mul-1-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + -2 \cdot maxCos\right) + \color{blue}{\left(-{ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)}} \]
      5. unsub-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 + -2 \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}}} \]
      6. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{\left(-2\right)} \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      7. cancel-sign-sub-inv97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 - 2 \cdot maxCos\right)} - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      8. cancel-sign-sub-inv97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 + \left(-2\right) \cdot maxCos\right)} - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      9. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{-2} \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      10. *-commutative97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{maxCos \cdot -2}\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      11. unpow297.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \color{blue}{\left(ux \cdot ux\right)} \cdot {\left(maxCos - 1\right)}^{2}} \]
      12. unpow297.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot \color{blue}{\left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)}} \]
      13. swap-sqr97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \color{blue}{\left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)}} \]
      14. sub-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)} \]
      15. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + \color{blue}{-1}\right)\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)} \]
      16. sub-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
      17. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    8. Simplified97.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 + maxCos \cdot -2\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}} \]
    9. Taylor expanded in maxCos around 0 94.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \color{blue}{\sqrt{2 \cdot ux - {ux}^{2}}} \]
    10. Step-by-step derivation
      1. unpow294.3%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux - \color{blue}{ux \cdot ux}} \]
      2. distribute-rgt-out--94.3%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 - ux\right)}} \]
    11. Simplified94.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \color{blue}{\sqrt{ux \cdot \left(2 - ux\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.4%

    \[\leadsto \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} \]

Alternative 5: 96.6% accurate, 1.0× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy 2) < 1.87800004e-4

    1. Initial program 59.3%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Step-by-step derivation
      1. associate-*l*59.3%

        \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
      2. sub-neg59.3%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
      3. +-commutative59.3%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
      4. distribute-rgt-neg-in59.3%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
      5. fma-def59.5%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
    3. Simplified59.7%

      \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
    4. Taylor expanded in ux around 0 99.4%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
    5. Step-by-step derivation
      1. fma-def99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
      2. +-commutative99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      3. sub-neg99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      4. metadata-eval99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      5. +-commutative99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      6. distribute-lft-in99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      7. metadata-eval99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      8. associate--l+99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      9. mul-1-neg99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      10. sub-neg99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
      11. associate-*r*99.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
      12. sub-neg99.6%

        \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
      13. metadata-eval99.6%

        \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
      14. +-commutative99.6%

        \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
    6. Simplified99.6%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
    7. Taylor expanded in uy around 0 99.4%

      \[\leadsto \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u99.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}\right)\right)} \]
      2. expm1-udef82.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}\right)} - 1} \]
    9. Applied egg-rr82.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}\right)} - 1} \]
    10. Step-by-step derivation
      1. expm1-def99.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}\right)\right)} \]
      2. expm1-log1p99.5%

        \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}} \]
      3. fma-udef99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{maxCos \cdot -2 + 2}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      4. *-commutative99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{-2 \cdot maxCos} + 2, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      5. +-commutative99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{2 + -2 \cdot maxCos}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      6. metadata-eval99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{2 \cdot 1} + -2 \cdot maxCos, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      7. metadata-eval99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + \color{blue}{\left(-2\right)} \cdot maxCos, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      8. distribute-lft-neg-in99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + \color{blue}{\left(-2 \cdot maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      9. distribute-rgt-neg-in99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + \color{blue}{2 \cdot \left(-maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      10. neg-mul-199.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + 2 \cdot \color{blue}{\left(-1 \cdot maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      11. distribute-lft-in99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{2 \cdot \left(1 + -1 \cdot maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      12. neg-mul-199.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot \left(1 + \color{blue}{\left(-maxCos\right)}\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      13. sub-neg99.5%

        \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot \color{blue}{\left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
      14. fma-def99.4%

        \[\leadsto \sqrt{\color{blue}{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right) + {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)}} \]
      15. associate-*r*99.4%

        \[\leadsto \sqrt{\color{blue}{\left(ux \cdot 2\right) \cdot \left(1 - maxCos\right)} + {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)} \]
      16. *-commutative99.4%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot ux\right)} \cdot \left(1 - maxCos\right) + {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)} \]
      17. associate-*r*99.4%

        \[\leadsto \sqrt{\left(2 \cdot ux\right) \cdot \left(1 - maxCos\right) + \color{blue}{\left({ux}^{2} \cdot \left(maxCos + -1\right)\right) \cdot \left(1 - maxCos\right)}} \]
      18. distribute-rgt-out99.5%

        \[\leadsto \sqrt{\color{blue}{\left(1 - maxCos\right) \cdot \left(2 \cdot ux + {ux}^{2} \cdot \left(maxCos + -1\right)\right)}} \]
    11. Simplified99.5%

      \[\leadsto \color{blue}{\sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot 2 + {ux}^{2} \cdot \left(maxCos + -1\right)\right)}} \]

    if 1.87800004e-4 < (*.f32 uy 2)

    1. Initial program 53.5%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Step-by-step derivation
      1. distribute-rgt-in53.5%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\left(1 - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right) + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
      2. +-commutative53.5%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \color{blue}{\left(ux \cdot maxCos + \left(1 - ux\right)\right)} + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
      3. associate-+r-53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \color{blue}{\left(\left(ux \cdot maxCos + 1\right) - ux\right)} + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
      4. fma-udef53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)} - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} \]
      5. +-commutative53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(ux \cdot maxCos + \left(1 - ux\right)\right)}\right)} \]
      6. associate-+r-53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(\left(ux \cdot maxCos + 1\right) - ux\right)}\right)} \]
      7. fma-udef53.4%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)} - ux\right)\right)} \]
    3. Applied egg-rr53.4%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\left(1 - ux\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) + \left(ux \cdot maxCos\right) \cdot \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right)\right)}} \]
    4. Step-by-step derivation
      1. distribute-rgt-out53.5%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}} \]
    5. Simplified53.5%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \color{blue}{\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}} \]
    6. Taylor expanded in ux around 0 97.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{-1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}} \]
    7. Step-by-step derivation
      1. +-commutative97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 - 2 \cdot maxCos\right) + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)}} \]
      2. cancel-sign-sub-inv97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 + \left(-2\right) \cdot maxCos\right)} + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)} \]
      3. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{-2} \cdot maxCos\right) + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)} \]
      4. mul-1-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + -2 \cdot maxCos\right) + \color{blue}{\left(-{ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)}} \]
      5. unsub-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 + -2 \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}}} \]
      6. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{\left(-2\right)} \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      7. cancel-sign-sub-inv97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 - 2 \cdot maxCos\right)} - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      8. cancel-sign-sub-inv97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 + \left(-2\right) \cdot maxCos\right)} - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      9. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{-2} \cdot maxCos\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      10. *-commutative97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{maxCos \cdot -2}\right) - {ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}} \]
      11. unpow297.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \color{blue}{\left(ux \cdot ux\right)} \cdot {\left(maxCos - 1\right)}^{2}} \]
      12. unpow297.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot \color{blue}{\left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)}} \]
      13. swap-sqr97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \color{blue}{\left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)}} \]
      14. sub-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)} \]
      15. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + \color{blue}{-1}\right)\right) \cdot \left(ux \cdot \left(maxCos - 1\right)\right)} \]
      16. sub-neg97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
      17. metadata-eval97.9%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    8. Simplified97.9%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 + maxCos \cdot -2\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}} \]
    9. Taylor expanded in maxCos around 0 94.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \color{blue}{\sqrt{2 \cdot ux - {ux}^{2}}} \]
    10. Step-by-step derivation
      1. unpow294.3%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux - \color{blue}{ux \cdot ux}} \]
      2. distribute-rgt-out--94.3%

        \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(2 - ux\right)}} \]
    11. Simplified94.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \color{blue}{\sqrt{ux \cdot \left(2 - ux\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.4%

    \[\leadsto \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} \]

Alternative 6: 79.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{\left(1 - maxCos\right) \cdot \left({ux}^{2} \cdot \left(maxCos + -1\right) + ux \cdot 2\right)} \end{array} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. associate-*l*57.0%

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. sub-neg57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    3. +-commutative57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
    4. distribute-rgt-neg-in57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
    5. fma-def57.1%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
  3. Simplified57.2%

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
  4. Taylor expanded in ux around 0 98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  5. Step-by-step derivation
    1. fma-def98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
    2. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    3. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    4. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    5. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    6. distribute-lft-in98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    7. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    8. associate--l+98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    9. mul-1-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    10. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    11. associate-*r*98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
    12. sub-neg98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
    13. metadata-eval98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    14. +-commutative98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
  6. Simplified98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
  7. Taylor expanded in uy around 0 81.0%

    \[\leadsto \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  8. Step-by-step derivation
    1. expm1-log1p-u80.9%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}\right)\right)} \]
    2. expm1-udef69.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}\right)} - 1} \]
  9. Applied egg-rr69.6%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}\right)} - 1} \]
  10. Step-by-step derivation
    1. expm1-def81.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}\right)\right)} \]
    2. expm1-log1p81.0%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}} \]
    3. fma-udef81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{maxCos \cdot -2 + 2}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    4. *-commutative81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{-2 \cdot maxCos} + 2, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    5. +-commutative81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{2 + -2 \cdot maxCos}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    6. metadata-eval81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{2 \cdot 1} + -2 \cdot maxCos, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    7. metadata-eval81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + \color{blue}{\left(-2\right)} \cdot maxCos, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    8. distribute-lft-neg-in81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + \color{blue}{\left(-2 \cdot maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    9. distribute-rgt-neg-in81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + \color{blue}{2 \cdot \left(-maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    10. neg-mul-181.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot 1 + 2 \cdot \color{blue}{\left(-1 \cdot maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    11. distribute-lft-in81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, \color{blue}{2 \cdot \left(1 + -1 \cdot maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    12. neg-mul-181.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot \left(1 + \color{blue}{\left(-maxCos\right)}\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    13. sub-neg81.0%

      \[\leadsto \sqrt{\mathsf{fma}\left(ux, 2 \cdot \color{blue}{\left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)} \]
    14. fma-def81.0%

      \[\leadsto \sqrt{\color{blue}{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right) + {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)}} \]
    15. associate-*r*81.0%

      \[\leadsto \sqrt{\color{blue}{\left(ux \cdot 2\right) \cdot \left(1 - maxCos\right)} + {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)} \]
    16. *-commutative81.0%

      \[\leadsto \sqrt{\color{blue}{\left(2 \cdot ux\right)} \cdot \left(1 - maxCos\right) + {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)} \]
    17. associate-*r*81.0%

      \[\leadsto \sqrt{\left(2 \cdot ux\right) \cdot \left(1 - maxCos\right) + \color{blue}{\left({ux}^{2} \cdot \left(maxCos + -1\right)\right) \cdot \left(1 - maxCos\right)}} \]
    18. distribute-rgt-out81.0%

      \[\leadsto \sqrt{\color{blue}{\left(1 - maxCos\right) \cdot \left(2 \cdot ux + {ux}^{2} \cdot \left(maxCos + -1\right)\right)}} \]
  11. Simplified81.0%

    \[\leadsto \color{blue}{\sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot 2 + {ux}^{2} \cdot \left(maxCos + -1\right)\right)}} \]
  12. Final simplification81.0%

    \[\leadsto \sqrt{\left(1 - maxCos\right) \cdot \left({ux}^{2} \cdot \left(maxCos + -1\right) + ux \cdot 2\right)} \]

Alternative 7: 78.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2}} \end{array} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. associate-*l*57.0%

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. sub-neg57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    3. +-commutative57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
    4. distribute-rgt-neg-in57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
    5. fma-def57.1%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
  3. Simplified57.2%

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
  4. Taylor expanded in ux around 0 98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  5. Step-by-step derivation
    1. fma-def98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
    2. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    3. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    4. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    5. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    6. distribute-lft-in98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    7. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    8. associate--l+98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    9. mul-1-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    10. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    11. associate-*r*98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
    12. sub-neg98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
    13. metadata-eval98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    14. +-commutative98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
  6. Simplified98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
  7. Taylor expanded in uy around 0 81.0%

    \[\leadsto \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  8. Taylor expanded in maxCos around 0 78.9%

    \[\leadsto \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + \color{blue}{-1 \cdot {ux}^{2}}} \]
  9. Step-by-step derivation
    1. mul-1-neg78.9%

      \[\leadsto \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + \color{blue}{\left(-{ux}^{2}\right)}} \]
  10. Simplified78.9%

    \[\leadsto \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + \color{blue}{\left(-{ux}^{2}\right)}} \]
  11. Final simplification78.9%

    \[\leadsto \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2}} \]

Alternative 8: 75.7% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot 2 - {ux}^{2}} \end{array} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. associate-*l*57.0%

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. sub-neg57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    3. +-commutative57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
    4. distribute-rgt-neg-in57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
    5. fma-def57.1%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
  3. Simplified57.2%

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
  4. Taylor expanded in ux around 0 98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  5. Step-by-step derivation
    1. fma-def98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
    2. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    3. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    4. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    5. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    6. distribute-lft-in98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    7. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    8. associate--l+98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    9. mul-1-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    10. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    11. associate-*r*98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
    12. sub-neg98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
    13. metadata-eval98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    14. +-commutative98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
  6. Simplified98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
  7. Taylor expanded in maxCos around 0 92.7%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \color{blue}{\sqrt{-1 \cdot {ux}^{2} + 2 \cdot ux}} \]
  8. Step-by-step derivation
    1. +-commutative92.7%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{2 \cdot ux + -1 \cdot {ux}^{2}}} \]
    2. mul-1-neg92.7%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux + \color{blue}{\left(-{ux}^{2}\right)}} \]
    3. unsub-neg92.7%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{2 \cdot ux - {ux}^{2}}} \]
    4. *-commutative92.7%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot 2} - {ux}^{2}} \]
  9. Simplified92.7%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \color{blue}{\sqrt{ux \cdot 2 - {ux}^{2}}} \]
  10. Taylor expanded in uy around 0 76.2%

    \[\leadsto \color{blue}{\sqrt{2 \cdot ux - {ux}^{2}}} \]
  11. Final simplification76.2%

    \[\leadsto \sqrt{ux \cdot 2 - {ux}^{2}} \]

Alternative 9: 75.6% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(2 - ux\right)} \end{array} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. associate-*l*57.0%

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. sub-neg57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    3. +-commutative57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
    4. distribute-rgt-neg-in57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
    5. fma-def57.1%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
  3. Simplified57.2%

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
  4. Taylor expanded in ux around 0 98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  5. Step-by-step derivation
    1. fma-def98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)}} \]
    2. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(-1 \cdot \left(maxCos - 1\right) + 1\right)} - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    3. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    4. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    5. +-commutative98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(-1 \cdot \color{blue}{\left(-1 + maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    6. distribute-lft-in98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\color{blue}{\left(-1 \cdot -1 + -1 \cdot maxCos\right)} + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    7. metadata-eval98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(\left(\color{blue}{1} + -1 \cdot maxCos\right) + 1\right) - maxCos, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    8. associate--l+98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 + -1 \cdot maxCos\right) + \left(1 - maxCos\right)}, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    9. mul-1-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 + \color{blue}{\left(-maxCos\right)}\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    10. sub-neg98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{\left(1 - maxCos\right)} + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)\right)} \]
    11. associate-*r*98.9%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \color{blue}{\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos - 1\right)}\right)} \]
    12. sub-neg98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)}\right)} \]
    13. metadata-eval98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + \color{blue}{-1}\right)\right)} \]
    14. +-commutative98.9%

      \[\leadsto \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({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \color{blue}{\left(-1 + maxCos\right)}\right)} \]
  6. Simplified98.9%

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(-1 + maxCos\right)\right)}} \]
  7. Taylor expanded in uy around 0 81.0%

    \[\leadsto \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)}} \]
  8. Taylor expanded in maxCos around 0 76.2%

    \[\leadsto \sqrt{\color{blue}{-1 \cdot {ux}^{2} + 2 \cdot ux}} \]
  9. Step-by-step derivation
    1. +-commutative76.2%

      \[\leadsto \sqrt{\color{blue}{2 \cdot ux + -1 \cdot {ux}^{2}}} \]
    2. mul-1-neg76.2%

      \[\leadsto \sqrt{2 \cdot ux + \color{blue}{\left(-{ux}^{2}\right)}} \]
    3. sub-neg76.2%

      \[\leadsto \sqrt{\color{blue}{2 \cdot ux - {ux}^{2}}} \]
    4. unpow276.2%

      \[\leadsto \sqrt{2 \cdot ux - \color{blue}{ux \cdot ux}} \]
    5. distribute-rgt-out--76.1%

      \[\leadsto \sqrt{\color{blue}{ux \cdot \left(2 - ux\right)}} \]
  10. Simplified76.1%

    \[\leadsto \sqrt{\color{blue}{ux \cdot \left(2 - ux\right)}} \]
  11. Final simplification76.1%

    \[\leadsto \sqrt{ux \cdot \left(2 - ux\right)} \]

Alternative 10: 62.1% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(--2\right)} \end{array} \]
(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}
Derivation
  1. Initial program 57.0%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Step-by-step derivation
    1. associate-*l*57.0%

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. sub-neg57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}} \]
    3. +-commutative57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1}} \]
    4. distribute-rgt-neg-in57.0%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1} \]
    5. fma-def57.1%

      \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}} \]
  3. Simplified57.2%

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, -1 - ux \cdot \left(maxCos + -1\right), 1\right)}} \]
  4. Taylor expanded in uy around 0 50.3%

    \[\leadsto \color{blue}{\sqrt{1 + -1 \cdot \left(\left(1 + ux \cdot \left(maxCos - 1\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)\right)}} \]
  5. Taylor expanded in ux around 0 65.2%

    \[\leadsto \sqrt{\color{blue}{-1 \cdot \left(ux \cdot \left(2 \cdot maxCos - 2\right)\right)}} \]
  6. Taylor expanded in maxCos around 0 62.9%

    \[\leadsto \sqrt{-1 \cdot \color{blue}{\left(-2 \cdot ux\right)}} \]
  7. Step-by-step derivation
    1. *-commutative62.9%

      \[\leadsto \sqrt{-1 \cdot \color{blue}{\left(ux \cdot -2\right)}} \]
  8. Simplified62.9%

    \[\leadsto \sqrt{-1 \cdot \color{blue}{\left(ux \cdot -2\right)}} \]
  9. Final simplification62.9%

    \[\leadsto \sqrt{ux \cdot \left(--2\right)} \]

Reproduce

?
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)))))))