UniformSampleCone, x

Percentage Accurate: 57.2% → 99.0%
Time: 14.7s
Alternatives: 12
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 12 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.2% 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(e^{\log \left(uy \cdot \left(2 \cdot \pi\right)\right)}\right) \cdot \sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {\left(1 - maxCos\right)}^{2} \cdot \left(ux \cdot \left(-ux\right)\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (*
  (cos (exp (log (* uy (* 2.0 PI)))))
  (sqrt
   (fma ux (fma maxCos -2.0 2.0) (* (pow (- 1.0 maxCos) 2.0) (* ux (- ux)))))))
float code(float ux, float uy, float maxCos) {
	return cosf(expf(logf((uy * (2.0f * ((float) M_PI)))))) * sqrtf(fmaf(ux, fmaf(maxCos, -2.0f, 2.0f), (powf((1.0f - maxCos), 2.0f) * (ux * -ux))));
}
function code(ux, uy, maxCos)
	return Float32(cos(exp(log(Float32(uy * Float32(Float32(2.0) * Float32(pi)))))) * sqrt(fma(ux, fma(maxCos, Float32(-2.0), Float32(2.0)), Float32((Float32(Float32(1.0) - maxCos) ^ Float32(2.0)) * Float32(ux * Float32(-ux))))))
end
\begin{array}{l}

\\
\cos \left(e^{\log \left(uy \cdot \left(2 \cdot \pi\right)\right)}\right) \cdot \sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {\left(1 - maxCos\right)}^{2} \cdot \left(ux \cdot \left(-ux\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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 -inf 99.2%

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

      \[\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)}} \]
    2. metadata-eval99.2%

      \[\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)} \]
    3. cancel-sign-sub-inv99.2%

      \[\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)} \]
    4. fma-def99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.0% accurate, 0.5× speedup?

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

\\
\sqrt{\mathsf{fma}\left(ux, \mathsf{fma}\left(maxCos, -2, 2\right), {\left(1 - maxCos\right)}^{2} \cdot \left(ux \cdot \left(-ux\right)\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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 -inf 99.2%

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

      \[\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)}} \]
    2. metadata-eval99.2%

      \[\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)} \]
    3. cancel-sign-sub-inv99.2%

      \[\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)} \]
    4. fma-def99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) + maxCos \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
    1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
    2. distribute-rgt-in59.1%

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

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

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

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

Alternative 4: 99.0% accurate, 0.8× speedup?

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

\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
    1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
    2. distribute-rgt-in59.1%

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

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

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

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

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

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

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

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

Alternative 5: 98.3% accurate, 1.0× speedup?

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

\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(\left(ux + ux\right) - maxCos \cdot \left(ux + \left(ux + ux \cdot \left(ux \cdot -2\right)\right)\right)\right) - ux \cdot ux}
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
    1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
    2. distribute-rgt-in59.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 96.2% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 59.2%

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

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

        \[\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-59.1%

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

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

        \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
      1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
      2. distribute-rgt-in59.7%

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

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

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

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

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

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

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

    if 9.50000031e-5 < (*.f32 uy 2)

    1. Initial program 57.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*57.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. +-commutative57.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-57.7%

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

        \[\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. +-commutative57.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(ux \cdot maxCos + \left(1 - ux\right)\right)}} \]
      6. associate-+r-57.6%

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

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

      \[\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. Step-by-step derivation
      1. sub-neg57.6%

        \[\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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
      2. distribute-rgt-in58.4%

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

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

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

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

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

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

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

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux + \color{blue}{\left(ux \cdot 1 + ux \cdot \left(-ux\right)\right)}} \]
      6. *-rgt-identity94.6%

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux + \left(\color{blue}{ux} + ux \cdot \left(-ux\right)\right)} \]
      7. distribute-rgt-neg-out94.6%

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

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

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

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

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

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

Alternative 7: 96.2% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 59.2%

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

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

        \[\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-59.1%

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

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

        \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
      1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
      2. distribute-rgt-in59.7%

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

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

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

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

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

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

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

    if 4.75000015e-5 < uy

    1. Initial program 57.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*57.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. +-commutative57.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-57.7%

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

        \[\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. +-commutative57.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(ux \cdot maxCos + \left(1 - ux\right)\right)}} \]
      6. associate-+r-57.6%

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

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

      \[\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 98.5%

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

        \[\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)}} \]
      2. metadata-eval98.5%

        \[\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)} \]
      3. cancel-sign-sub-inv98.5%

        \[\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)} \]
      4. fma-def98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(-ux\right) + \color{blue}{ux \cdot 2}} \]
      5. distribute-lft-out94.6%

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

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

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

Alternative 8: 89.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;uy \leq 0.0006500000017695129:\\ \;\;\;\;\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}\\ \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 0.0006500000017695129)
   (sqrt
    (- (* ux (+ 2.0 (* maxCos -2.0))) (* (* ux ux) (pow (+ maxCos -1.0) 2.0))))
   (* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (uy <= 0.0006500000017695129f) {
		tmp = sqrtf(((ux * (2.0f + (maxCos * -2.0f))) - ((ux * ux) * powf((maxCos + -1.0f), 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 (uy <= Float32(0.0006500000017695129))
		tmp = sqrt(Float32(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0)))) - Float32(Float32(ux * ux) * (Float32(maxCos + Float32(-1.0)) ^ 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(0.0006500000017695129))
		tmp = sqrt(((ux * (single(2.0) + (maxCos * single(-2.0)))) - ((ux * ux) * ((maxCos + single(-1.0)) ^ 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 \leq 0.0006500000017695129:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}\\

\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 uy < 6.50000002e-4

    1. Initial program 59.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*59.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. +-commutative59.1%

        \[\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-59.1%

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

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

        \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
      1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
      2. distribute-rgt-in59.7%

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

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

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

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

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

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

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

    if 6.50000002e-4 < uy

    1. Initial program 57.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*57.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. +-commutative57.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-57.2%

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

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

        \[\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-57.1%

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

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

      \[\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 47.0%

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

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

        \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot 2}} \]
    7. Simplified75.5%

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

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

Alternative 9: 79.7% accurate, 1.5× speedup?

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

\\
\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right) - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}}
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
    1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
    2. distribute-rgt-in59.1%

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

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

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

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

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

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

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

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

Alternative 10: 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 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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 uy around 0 51.7%

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

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

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

Alternative 11: 75.4% accurate, 3.0× speedup?

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

\\
\sqrt{\left(ux + ux\right) - ux \cdot ux}
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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. Step-by-step derivation
    1. sub-neg58.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(\mathsf{fma}\left(ux, maxCos, 1\right) + \left(-ux\right)\right)}} \]
    2. distribute-rgt-in59.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sqrt{2 \cdot ux - {ux}^{2}}} \]
  10. Step-by-step derivation
    1. count-277.1%

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

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

    \[\leadsto \color{blue}{\sqrt{\left(ux + ux\right) - ux \cdot ux}} \]
  12. Final simplification77.1%

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

Alternative 12: 62.1% accurate, 3.1× speedup?

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

\\
\sqrt{ux + ux}
\end{array}
Derivation
  1. Initial program 58.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*58.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. +-commutative58.6%

      \[\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-58.5%

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

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

      \[\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-58.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-def58.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. Simplified58.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 uy around 0 51.7%

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

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

    \[\leadsto \sqrt{\color{blue}{2 \cdot ux}} \]
  7. Step-by-step derivation
    1. count-263.5%

      \[\leadsto \sqrt{\color{blue}{ux + ux}} \]
  8. Simplified63.5%

    \[\leadsto \sqrt{\color{blue}{ux + ux}} \]
  9. Final simplification63.5%

    \[\leadsto \sqrt{ux + ux} \]

Reproduce

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