UniformSampleCone, x

Percentage Accurate: 57.4% → 99.0%
Time: 16.3s
Alternatives: 14
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 14 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: 57.4% 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} \\ \cos \left(\sqrt[3]{{\left(uy \cdot 2\right)}^{3} \cdot {\pi}^{3}}\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (*
  (cos (cbrt (* (pow (* uy 2.0) 3.0) (pow PI 3.0))))
  (sqrt
   (fma (fma maxCos -2.0 2.0) ux (* (* ux ux) (- (pow (- 1.0 maxCos) 2.0)))))))
float code(float ux, float uy, float maxCos) {
	return cosf(cbrtf((powf((uy * 2.0f), 3.0f) * powf(((float) M_PI), 3.0f)))) * sqrtf(fmaf(fmaf(maxCos, -2.0f, 2.0f), ux, ((ux * ux) * -powf((1.0f - maxCos), 2.0f))));
}
function code(ux, uy, maxCos)
	return Float32(cos(cbrt(Float32((Float32(uy * Float32(2.0)) ^ Float32(3.0)) * (Float32(pi) ^ Float32(3.0))))) * sqrt(fma(fma(maxCos, Float32(-2.0), Float32(2.0)), ux, Float32(Float32(ux * ux) * Float32(-(Float32(Float32(1.0) - maxCos) ^ Float32(2.0)))))))
end
\begin{array}{l}

\\
\cos \left(\sqrt[3]{{\left(uy \cdot 2\right)}^{3} \cdot {\pi}^{3}}\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)}
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos \left(\sqrt[3]{{\left(uy \cdot 2\right)}^{3} \cdot {\pi}^{3}}\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)} \]

Alternative 2: 99.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (*
  (sqrt
   (fma (fma maxCos -2.0 2.0) ux (* (* ux ux) (- (pow (- 1.0 maxCos) 2.0)))))
  (cos (* uy (* 2.0 PI)))))
float code(float ux, float uy, float maxCos) {
	return sqrtf(fmaf(fmaf(maxCos, -2.0f, 2.0f), ux, ((ux * ux) * -powf((1.0f - maxCos), 2.0f)))) * cosf((uy * (2.0f * ((float) M_PI))));
}
function code(ux, uy, maxCos)
	return Float32(sqrt(fma(fma(maxCos, Float32(-2.0), Float32(2.0)), ux, Float32(Float32(ux * ux) * Float32(-(Float32(Float32(1.0) - maxCos) ^ Float32(2.0)))))) * cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))))
end
\begin{array}{l}

\\
\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \]

Alternative 3: 99.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), \left(1 - maxCos\right) \cdot \left(2 \cdot ux\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (*
  (cos (* uy (* 2.0 PI)))
  (sqrt
   (fma
    (+ maxCos -1.0)
    (* (* ux ux) (- 1.0 maxCos))
    (* (- 1.0 maxCos) (* 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
	return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), ((1.0f - maxCos) * (2.0f * ux))));
}
function code(ux, uy, maxCos)
	return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(2.0) * ux)))))
end
\begin{array}{l}

\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), \left(1 - maxCos\right) \cdot \left(2 \cdot ux\right)\right)}
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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-neg55.7%

      \[\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. +-commutative55.7%

      \[\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-in55.7%

      \[\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-def55.7%

      \[\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)}} \]
    6. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\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, ux - \mathsf{fma}\left(ux, 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}{\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\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(maxCos - 1, \left(1 - maxCos\right) \cdot {ux}^{2}, ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right)}} \]
    2. sub-neg98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 90.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0015999999595806003:\\ \;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= (* uy 2.0) 0.0015999999595806003)
   (sqrt
    (-
     (* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0)))
     (* ux (- (* 2.0 maxCos) 2.0))))
   (* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if ((uy * 2.0f) <= 0.0015999999595806003f) {
		tmp = sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) - (ux * ((2.0f * maxCos) - 2.0f))));
	} else {
		tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
	}
	return tmp;
}
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (Float32(uy * Float32(2.0)) <= Float32(0.0015999999595806003))
		tmp = sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) - Float32(ux * Float32(Float32(Float32(2.0) * maxCos) - Float32(2.0)))));
	else
		tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if ((uy * single(2.0)) <= single(0.0015999999595806003))
		tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) - (ux * ((single(2.0) * maxCos) - single(2.0)))));
	else
		tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0015999999595806003:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy 2) < 0.00159999996

    1. Initial program 55.9%

      \[\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*55.9%

        \[\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-neg55.9%

        \[\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. +-commutative55.9%

        \[\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-in55.9%

        \[\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-def55.9%

        \[\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)}} \]
      6. +-commutative55.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 55.3%

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

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
    6. Step-by-step derivation
      1. associate--l+58.0%

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

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

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

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
      7. fma-neg58.0%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
      8. associate--l+58.1%

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(-\left(maxCos - 1\right)\right)} - maxCos\right), -1\right)\right)} \]
      10. sub-neg58.1%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\color{blue}{\left(maxCos + \left(-1\right)\right)}\right) - maxCos\right), -1\right)\right)} \]
      11. metadata-eval58.1%

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(\left(-maxCos\right) + \left(--1\right)\right)} - maxCos\right), -1\right)\right)} \]
      13. metadata-eval58.1%

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 + \left(-maxCos\right)\right)} - maxCos\right), -1\right)\right)} \]
      15. sub-neg58.1%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 - maxCos\right)} - maxCos\right), -1\right)\right)} \]
      16. metadata-eval58.1%

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

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
    8. Taylor expanded in ux around 0 97.8%

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

    if 0.00159999996 < (*.f32 uy 2)

    1. Initial program 55.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*55.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. +-commutative55.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0015999999595806003:\\ \;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \end{array} \]

Alternative 5: 89.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0016499999910593033:\\ \;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= (* uy 2.0) 0.0016499999910593033)
   (sqrt
    (-
     (* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0)))
     (* ux (- (* 2.0 maxCos) 2.0))))
   (* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if ((uy * 2.0f) <= 0.0016499999910593033f) {
		tmp = sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) - (ux * ((2.0f * maxCos) - 2.0f))));
	} else {
		tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
	}
	return tmp;
}
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (Float32(uy * Float32(2.0)) <= Float32(0.0016499999910593033))
		tmp = sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) - Float32(ux * Float32(Float32(Float32(2.0) * maxCos) - Float32(2.0)))));
	else
		tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux)));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if ((uy * single(2.0)) <= single(0.0016499999910593033))
		tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) - (ux * ((single(2.0) * maxCos) - single(2.0)))));
	else
		tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0016499999910593033:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy 2) < 0.00165

    1. Initial program 55.6%

      \[\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*55.6%

        \[\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-neg55.6%

        \[\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. +-commutative55.6%

        \[\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-in55.6%

        \[\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-def55.6%

        \[\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)}} \]
      6. +-commutative55.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 55.0%

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

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
    6. Step-by-step derivation
      1. associate--l+57.7%

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

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

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

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
      7. fma-neg57.7%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
      8. associate--l+57.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
      9. mul-1-neg57.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(-\left(maxCos - 1\right)\right)} - maxCos\right), -1\right)\right)} \]
      10. sub-neg57.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\color{blue}{\left(maxCos + \left(-1\right)\right)}\right) - maxCos\right), -1\right)\right)} \]
      11. metadata-eval57.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
      12. distribute-neg-in57.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(\left(-maxCos\right) + \left(--1\right)\right)} - maxCos\right), -1\right)\right)} \]
      13. metadata-eval57.8%

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 + \left(-maxCos\right)\right)} - maxCos\right), -1\right)\right)} \]
      15. sub-neg57.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 - maxCos\right)} - maxCos\right), -1\right)\right)} \]
      16. metadata-eval57.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{-1}\right)\right)} \]
    7. Simplified57.8%

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
    8. Taylor expanded in ux around 0 97.7%

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

    if 0.00165 < (*.f32 uy 2)

    1. Initial program 55.8%

      \[\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*55.8%

        \[\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. +-commutative55.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0016499999910593033:\\ \;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\ \end{array} \]

Alternative 6: 92.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
	return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
function code(ux, uy, maxCos)
	return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux))))
end
function tmp = code(ux, uy, maxCos)
	tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((single(2.0) * ux) - (ux * ux)));
end
\begin{array}{l}

\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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. +-commutative94.3%

      \[\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-neg94.3%

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

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

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

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

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

Alternative 7: 79.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (sqrt
  (-
   (* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0)))
   (* ux (- (* 2.0 maxCos) 2.0)))))
float code(float ux, float uy, float maxCos) {
	return sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) - (ux * ((2.0f * maxCos) - 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) * ((maxcos + (-1.0e0)) * (ux ** 2.0e0))) - (ux * ((2.0e0 * maxcos) - 2.0e0))))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) - Float32(ux * Float32(Float32(Float32(2.0) * maxCos) - Float32(2.0)))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) - (ux * ((single(2.0) * maxCos) - single(2.0)))));
end
\begin{array}{l}

\\
\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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-neg55.7%

      \[\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. +-commutative55.7%

      \[\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-in55.7%

      \[\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-def55.7%

      \[\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)}} \]
    6. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
  4. Taylor expanded in uy around 0 46.9%

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
  6. Step-by-step derivation
    1. associate--l+49.0%

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

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

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

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
    7. fma-neg49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
    8. associate--l+49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
    9. mul-1-neg49.0%

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
    12. distribute-neg-in49.0%

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

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

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

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

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
  8. Taylor expanded in ux around 0 79.2%

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

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

Alternative 8: 75.5% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \sqrt{\mathsf{fma}\left(2, ux, ux \cdot \left(-ux\right)\right)} \end{array} \]
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma 2.0 ux (* ux (- ux)))))
float code(float ux, float uy, float maxCos) {
	return sqrtf(fmaf(2.0f, ux, (ux * -ux)));
}
function code(ux, uy, maxCos)
	return sqrt(fma(Float32(2.0), ux, Float32(ux * Float32(-ux))))
end
\begin{array}{l}

\\
\sqrt{\mathsf{fma}\left(2, ux, ux \cdot \left(-ux\right)\right)}
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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-neg55.7%

      \[\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. +-commutative55.7%

      \[\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-in55.7%

      \[\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-def55.7%

      \[\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)}} \]
    6. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
  4. Taylor expanded in uy around 0 46.9%

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
  6. Step-by-step derivation
    1. associate--l+49.0%

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

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

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

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
    7. fma-neg49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
    8. associate--l+49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
    9. mul-1-neg49.0%

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
    12. distribute-neg-in49.0%

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

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

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

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

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
  8. Taylor expanded in maxCos around 0 75.8%

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

      \[\leadsto \sqrt{\color{blue}{2 \cdot ux + -1 \cdot {ux}^{2}}} \]
    2. fma-def75.8%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(2, ux, -1 \cdot {ux}^{2}\right)}} \]
    3. mul-1-neg75.8%

      \[\leadsto \sqrt{\mathsf{fma}\left(2, ux, \color{blue}{-{ux}^{2}}\right)} \]
    4. unpow275.8%

      \[\leadsto \sqrt{\mathsf{fma}\left(2, ux, -\color{blue}{ux \cdot ux}\right)} \]
    5. distribute-rgt-neg-in75.8%

      \[\leadsto \sqrt{\mathsf{fma}\left(2, ux, \color{blue}{ux \cdot \left(-ux\right)}\right)} \]
  10. Simplified75.8%

    \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(2, ux, ux \cdot \left(-ux\right)\right)}} \]
  11. Final simplification75.8%

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

Alternative 9: 74.7% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -1 + \left(ux - maxCos \cdot ux\right)\\ t_1 := \left(ux + \left(-1 - maxCos \cdot ux\right)\right) \cdot t_0\\ \mathbf{if}\;ux \leq 7.999999797903001 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1 + \left(\left(\left(1 + maxCos \cdot ux\right) - ux\right) \cdot t_0\right) \cdot t_1}{1 + t_1}}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (let* ((t_0 (+ -1.0 (- ux (* maxCos ux))))
        (t_1 (* (+ ux (- -1.0 (* maxCos ux))) t_0)))
   (if (<= ux 7.999999797903001e-5)
     (sqrt (* ux (- 2.0 (* 2.0 maxCos))))
     (sqrt
      (/ (+ 1.0 (* (* (- (+ 1.0 (* maxCos ux)) ux) t_0) t_1)) (+ 1.0 t_1))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = -1.0f + (ux - (maxCos * ux));
	float t_1 = (ux + (-1.0f - (maxCos * ux))) * t_0;
	float tmp;
	if (ux <= 7.999999797903001e-5f) {
		tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
	} else {
		tmp = sqrtf(((1.0f + ((((1.0f + (maxCos * ux)) - ux) * t_0) * t_1)) / (1.0f + t_1)));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: t_0
    real(4) :: t_1
    real(4) :: tmp
    t_0 = (-1.0e0) + (ux - (maxcos * ux))
    t_1 = (ux + ((-1.0e0) - (maxcos * ux))) * t_0
    if (ux <= 7.999999797903001e-5) then
        tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
    else
        tmp = sqrt(((1.0e0 + ((((1.0e0 + (maxcos * ux)) - ux) * t_0) * t_1)) / (1.0e0 + t_1)))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(-1.0) + Float32(ux - Float32(maxCos * ux)))
	t_1 = Float32(Float32(ux + Float32(Float32(-1.0) - Float32(maxCos * ux))) * t_0)
	tmp = Float32(0.0)
	if (ux <= Float32(7.999999797903001e-5))
		tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))));
	else
		tmp = sqrt(Float32(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(Float32(1.0) + Float32(maxCos * ux)) - ux) * t_0) * t_1)) / Float32(Float32(1.0) + t_1)));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	t_0 = single(-1.0) + (ux - (maxCos * ux));
	t_1 = (ux + (single(-1.0) - (maxCos * ux))) * t_0;
	tmp = single(0.0);
	if (ux <= single(7.999999797903001e-5))
		tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
	else
		tmp = sqrt(((single(1.0) + ((((single(1.0) + (maxCos * ux)) - ux) * t_0) * t_1)) / (single(1.0) + t_1)));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -1 + \left(ux - maxCos \cdot ux\right)\\
t_1 := \left(ux + \left(-1 - maxCos \cdot ux\right)\right) \cdot t_0\\
\mathbf{if}\;ux \leq 7.999999797903001 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1 + \left(\left(\left(1 + maxCos \cdot ux\right) - ux\right) \cdot t_0\right) \cdot t_1}{1 + t_1}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ux < 7.9999998e-5

    1. Initial program 32.8%

      \[\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*32.8%

        \[\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-neg32.8%

        \[\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. +-commutative32.8%

        \[\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-in32.8%

        \[\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-def32.8%

        \[\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)}} \]
      6. +-commutative32.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 29.6%

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

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
    6. Step-by-step derivation
      1. associate--l+32.6%

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

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

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

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
      7. fma-neg32.6%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
      8. associate--l+32.6%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
      9. mul-1-neg32.6%

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
      12. distribute-neg-in32.6%

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

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

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{-1}\right)\right)} \]
    7. Simplified32.6%

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
    8. Taylor expanded in ux around 0 76.6%

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

    if 7.9999998e-5 < ux

    1. Initial program 89.6%

      \[\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*89.6%

        \[\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-neg89.6%

        \[\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. +-commutative89.6%

        \[\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-in89.6%

        \[\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-def89.6%

        \[\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)}} \]
      6. +-commutative89.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 72.6%

      \[\leadsto \color{blue}{\sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}} \]
    5. Step-by-step derivation
      1. flip-+72.6%

        \[\leadsto \sqrt{\color{blue}{\frac{1 \cdot 1 - \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)\right) \cdot \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)\right)}{1 - \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}}} \]
      2. metadata-eval72.6%

        \[\leadsto \sqrt{\frac{\color{blue}{1} - \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)\right) \cdot \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)\right)}{1 - \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}} \]
      3. associate--l+72.6%

        \[\leadsto \sqrt{\frac{1 - \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \color{blue}{\left(1 + \left(maxCos \cdot ux - ux\right)\right)}\right) \cdot \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)\right)}{1 - \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}} \]
      4. associate--l+72.8%

        \[\leadsto \sqrt{\frac{1 - \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)\right) \cdot \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \color{blue}{\left(1 + \left(maxCos \cdot ux - ux\right)\right)}\right)}{1 - \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}} \]
      5. associate--l+72.8%

        \[\leadsto \sqrt{\frac{1 - \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)\right) \cdot \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)\right)}{1 - \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \color{blue}{\left(1 + \left(maxCos \cdot ux - ux\right)\right)}}} \]
    6. Applied egg-rr72.8%

      \[\leadsto \sqrt{\color{blue}{\frac{1 - \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)\right) \cdot \left(\left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)\right)}{1 - \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 7.999999797903001 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1 + \left(\left(\left(1 + maxCos \cdot ux\right) - ux\right) \cdot \left(-1 + \left(ux - maxCos \cdot ux\right)\right)\right) \cdot \left(\left(ux + \left(-1 - maxCos \cdot ux\right)\right) \cdot \left(-1 + \left(ux - maxCos \cdot ux\right)\right)\right)}{1 + \left(ux + \left(-1 - maxCos \cdot ux\right)\right) \cdot \left(-1 + \left(ux - maxCos \cdot ux\right)\right)}}\\ \end{array} \]

Alternative 10: 74.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 9.999999747378752e-5)
   (sqrt (* ux (- 2.0 (* 2.0 maxCos))))
   (sqrt
    (- 1.0 (* (+ 1.0 (* ux (+ maxCos -1.0))) (- (+ 1.0 (* maxCos ux)) ux))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 9.999999747378752e-5f) {
		tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
	} else {
		tmp = sqrtf((1.0f - ((1.0f + (ux * (maxCos + -1.0f))) * ((1.0f + (maxCos * ux)) - ux))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 9.999999747378752e-5) then
        tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
    else
        tmp = sqrt((1.0e0 - ((1.0e0 + (ux * (maxcos + (-1.0e0)))) * ((1.0e0 + (maxcos * ux)) - ux))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(9.999999747378752e-5))
		tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))));
	else
		tmp = sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(Float32(Float32(1.0) + Float32(maxCos * ux)) - ux))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(9.999999747378752e-5))
		tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
	else
		tmp = sqrt((single(1.0) - ((single(1.0) + (ux * (maxCos + single(-1.0)))) * ((single(1.0) + (maxCos * ux)) - ux))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ux < 9.99999975e-5

    1. Initial program 33.1%

      \[\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*33.1%

        \[\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-neg33.1%

        \[\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. +-commutative33.1%

        \[\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-in33.1%

        \[\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-def33.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)}} \]
      6. +-commutative33.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 29.8%

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

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
    6. Step-by-step derivation
      1. associate--l+32.8%

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

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

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

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
      7. fma-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
      8. associate--l+32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
      9. mul-1-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(-\left(maxCos - 1\right)\right)} - maxCos\right), -1\right)\right)} \]
      10. sub-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\color{blue}{\left(maxCos + \left(-1\right)\right)}\right) - maxCos\right), -1\right)\right)} \]
      11. metadata-eval32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
      12. distribute-neg-in32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(\left(-maxCos\right) + \left(--1\right)\right)} - maxCos\right), -1\right)\right)} \]
      13. metadata-eval32.8%

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 + \left(-maxCos\right)\right)} - maxCos\right), -1\right)\right)} \]
      15. sub-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 - maxCos\right)} - maxCos\right), -1\right)\right)} \]
      16. metadata-eval32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{-1}\right)\right)} \]
    7. Simplified32.8%

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
    8. Taylor expanded in ux around 0 76.6%

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

    if 9.99999975e-5 < ux

    1. Initial program 89.8%

      \[\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*89.8%

        \[\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-neg89.8%

        \[\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. +-commutative89.8%

        \[\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-in89.8%

        \[\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-def89.8%

        \[\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)}} \]
      6. +-commutative89.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, ux - \color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)}, 1\right)} \]
    3. Simplified89.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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 72.6%

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

      \[\leadsto \sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \color{blue}{\left(1 + -1 \cdot \left(ux \cdot \left(1 + -1 \cdot maxCos\right)\right)\right)}} \]
    6. Step-by-step derivation
      1. mul-1-neg72.8%

        \[\leadsto \sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 + \color{blue}{\left(-ux \cdot \left(1 + -1 \cdot maxCos\right)\right)}\right)} \]
      2. unsub-neg72.8%

        \[\leadsto \sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \color{blue}{\left(1 - ux \cdot \left(1 + -1 \cdot maxCos\right)\right)}} \]
      3. mul-1-neg72.8%

        \[\leadsto \sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 - ux \cdot \left(1 + \color{blue}{\left(-maxCos\right)}\right)\right)} \]
      4. sub-neg72.8%

        \[\leadsto \sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \left(1 - ux \cdot \color{blue}{\left(1 - maxCos\right)}\right)} \]
    7. Simplified72.8%

      \[\leadsto \sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \color{blue}{\left(1 - ux \cdot \left(1 - maxCos\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}\\ \end{array} \]

Alternative 11: 73.7% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 9.999999747378752e-5)
   (sqrt (* ux (- 2.0 (* 2.0 maxCos))))
   (sqrt (- 1.0 (* (- 1.0 ux) (- (+ 1.0 (* maxCos ux)) ux))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 9.999999747378752e-5f) {
		tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
	} else {
		tmp = sqrtf((1.0f - ((1.0f - ux) * ((1.0f + (maxCos * ux)) - ux))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 9.999999747378752e-5) then
        tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
    else
        tmp = sqrt((1.0e0 - ((1.0e0 - ux) * ((1.0e0 + (maxcos * ux)) - ux))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(9.999999747378752e-5))
		tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))));
	else
		tmp = sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * Float32(Float32(Float32(1.0) + Float32(maxCos * ux)) - ux))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(9.999999747378752e-5))
		tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
	else
		tmp = sqrt((single(1.0) - ((single(1.0) - ux) * ((single(1.0) + (maxCos * ux)) - ux))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ux < 9.99999975e-5

    1. Initial program 33.1%

      \[\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*33.1%

        \[\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-neg33.1%

        \[\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. +-commutative33.1%

        \[\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-in33.1%

        \[\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-def33.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)}} \]
      6. +-commutative33.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 29.8%

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

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
    6. Step-by-step derivation
      1. associate--l+32.8%

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

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

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

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
      7. fma-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
      8. associate--l+32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
      9. mul-1-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(-\left(maxCos - 1\right)\right)} - maxCos\right), -1\right)\right)} \]
      10. sub-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\color{blue}{\left(maxCos + \left(-1\right)\right)}\right) - maxCos\right), -1\right)\right)} \]
      11. metadata-eval32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
      12. distribute-neg-in32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(\left(-maxCos\right) + \left(--1\right)\right)} - maxCos\right), -1\right)\right)} \]
      13. metadata-eval32.8%

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 + \left(-maxCos\right)\right)} - maxCos\right), -1\right)\right)} \]
      15. sub-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 - maxCos\right)} - maxCos\right), -1\right)\right)} \]
      16. metadata-eval32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{-1}\right)\right)} \]
    7. Simplified32.8%

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
    8. Taylor expanded in ux around 0 76.6%

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

    if 9.99999975e-5 < ux

    1. Initial program 89.8%

      \[\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*89.8%

        \[\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-neg89.8%

        \[\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. +-commutative89.8%

        \[\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-in89.8%

        \[\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-def89.8%

        \[\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)}} \]
      6. +-commutative89.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, ux - \color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)}, 1\right)} \]
    3. Simplified89.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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 72.6%

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

      \[\leadsto \sqrt{1 + \left(ux - \left(1 + maxCos \cdot ux\right)\right) \cdot \color{blue}{\left(1 - ux\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}\\ \end{array} \]

Alternative 12: 73.5% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - \left(ux + -1\right) \cdot \left(ux + -1\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 9.999999747378752e-5)
   (sqrt (* ux (- 2.0 (* 2.0 maxCos))))
   (sqrt (- 1.0 (* (+ ux -1.0) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 9.999999747378752e-5f) {
		tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
	} else {
		tmp = sqrtf((1.0f - ((ux + -1.0f) * (ux + -1.0f))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 9.999999747378752e-5) then
        tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
    else
        tmp = sqrt((1.0e0 - ((ux + (-1.0e0)) * (ux + (-1.0e0)))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(9.999999747378752e-5))
		tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))));
	else
		tmp = sqrt(Float32(Float32(1.0) - Float32(Float32(ux + Float32(-1.0)) * Float32(ux + Float32(-1.0)))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(9.999999747378752e-5))
		tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
	else
		tmp = sqrt((single(1.0) - ((ux + single(-1.0)) * (ux + single(-1.0)))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(ux + -1\right) \cdot \left(ux + -1\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ux < 9.99999975e-5

    1. Initial program 33.1%

      \[\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*33.1%

        \[\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-neg33.1%

        \[\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. +-commutative33.1%

        \[\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-in33.1%

        \[\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-def33.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)}} \]
      6. +-commutative33.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 29.8%

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

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
    6. Step-by-step derivation
      1. associate--l+32.8%

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

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

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

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

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
      7. fma-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
      8. associate--l+32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
      9. mul-1-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(-\left(maxCos - 1\right)\right)} - maxCos\right), -1\right)\right)} \]
      10. sub-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\color{blue}{\left(maxCos + \left(-1\right)\right)}\right) - maxCos\right), -1\right)\right)} \]
      11. metadata-eval32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
      12. distribute-neg-in32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(\left(-maxCos\right) + \left(--1\right)\right)} - maxCos\right), -1\right)\right)} \]
      13. metadata-eval32.8%

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

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 + \left(-maxCos\right)\right)} - maxCos\right), -1\right)\right)} \]
      15. sub-neg32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 - maxCos\right)} - maxCos\right), -1\right)\right)} \]
      16. metadata-eval32.8%

        \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{-1}\right)\right)} \]
    7. Simplified32.8%

      \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
    8. Taylor expanded in ux around 0 76.6%

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

    if 9.99999975e-5 < ux

    1. Initial program 89.8%

      \[\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*89.8%

        \[\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-neg89.8%

        \[\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. +-commutative89.8%

        \[\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-in89.8%

        \[\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-def89.8%

        \[\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)}} \]
      6. +-commutative89.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, ux - \color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)}, 1\right)} \]
    3. Simplified89.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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
    4. Taylor expanded in uy around 0 72.6%

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

      \[\leadsto \sqrt{\color{blue}{1 + \left(ux - 1\right) \cdot \left(1 - ux\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - \left(ux + -1\right) \cdot \left(ux + -1\right)}\\ \end{array} \]

Alternative 13: 64.7% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
	return sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
end
\begin{array}{l}

\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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-neg55.7%

      \[\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. +-commutative55.7%

      \[\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-in55.7%

      \[\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-def55.7%

      \[\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)}} \]
    6. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
  4. Taylor expanded in uy around 0 46.9%

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
  6. Step-by-step derivation
    1. associate--l+49.0%

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

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

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

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
    7. fma-neg49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
    8. associate--l+49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
    9. mul-1-neg49.0%

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
    12. distribute-neg-in49.0%

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

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

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

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

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
  8. Taylor expanded in ux around 0 64.2%

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

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

Alternative 14: 62.1% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt{2 \cdot ux} \end{array} \]
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* 2.0 ux)))
float code(float ux, float uy, float maxCos) {
	return sqrtf((2.0f * ux));
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt((2.0e0 * ux))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(Float32(2.0) * ux))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((single(2.0) * ux));
end
\begin{array}{l}

\\
\sqrt{2 \cdot ux}
\end{array}
Derivation
  1. Initial program 55.7%

    \[\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*55.7%

      \[\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-neg55.7%

      \[\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. +-commutative55.7%

      \[\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-in55.7%

      \[\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-def55.7%

      \[\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)}} \]
    6. +-commutative55.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\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, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
  4. Taylor expanded in uy around 0 46.9%

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)\right) - 1\right)}} \]
  6. Step-by-step derivation
    1. associate--l+49.0%

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

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

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

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \color{blue}{\left(ux \cdot ux\right)} + \left(ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) - 1\right)\right)} \]
    7. fma-neg49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, -1\right)}\right)} \]
    8. associate--l+49.0%

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, -1\right)\right)} \]
    9. mul-1-neg49.0%

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

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

      \[\leadsto \sqrt{1 + \left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(-\left(maxCos + \color{blue}{-1}\right)\right) - maxCos\right), -1\right)\right)} \]
    12. distribute-neg-in49.0%

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

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

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

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

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

    \[\leadsto \sqrt{1 + \color{blue}{\left(\left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) \cdot \left(ux \cdot ux\right) + \mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), -1\right)\right)}} \]
  8. Taylor expanded in ux around 0 64.2%

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

    \[\leadsto \sqrt{\color{blue}{2 \cdot ux}} \]
  10. Step-by-step derivation
    1. *-commutative62.3%

      \[\leadsto \sqrt{\color{blue}{ux \cdot 2}} \]
  11. Simplified62.3%

    \[\leadsto \sqrt{\color{blue}{ux \cdot 2}} \]
  12. Final simplification62.3%

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

Reproduce

?
herbie shell --seed 2023255 
(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)))))))