UniformSampleCone, x

Percentage Accurate: 56.6% → 98.8%
Time: 22.4s
Alternatives: 17
Speedup: 2.2×

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 17 alternatives:

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

Initial Program: 56.6% 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: 98.8% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.1% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.1% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 98.4% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 93.0% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}} \]
  10. Add Preprocessing

Alternative 6: 91.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\\
t_1 := 1 + \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(ux + -1\right) - ux \cdot maxCos\right)\\
\mathbf{if}\;t\_1 \leq 0.0004199999966658652:\\
\;\;\;\;t\_0 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{t\_1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) < 4.19999997e-4

    1. Initial program 38.5%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in ux around 0 91.7%

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

    if 4.19999997e-4 < (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos))))

    1. Initial program 90.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. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification91.1%

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

Alternative 7: 91.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0002099999983329326:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

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


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

    1. Initial program 38.5%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in ux around 0 91.7%

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

    if 2.09999998e-4 < ux

    1. Initial program 90.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. sub-neg90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 90.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0002099999983329326:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

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


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

    1. Initial program 38.5%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in ux around 0 91.7%

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

    if 2.09999998e-4 < ux

    1. Initial program 90.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. sub-neg90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 89.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\\
\mathbf{if}\;ux \leq 0.0002099999983329326:\\
\;\;\;\;t\_0 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

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


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

    1. Initial program 38.5%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in ux around 0 91.7%

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

    if 2.09999998e-4 < ux

    1. Initial program 90.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. sub-neg90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 85.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0007999999797903001:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

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


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

    1. Initial program 41.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. Add Preprocessing
    3. Taylor expanded in ux around 0 89.9%

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

    if 7.9999998e-4 < ux

    1. Initial program 92.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. sub-neg92.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 82.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0007999999797903001:\\
\;\;\;\;\cos \left(\left(uy \cdot \pi\right) \cdot 2\right) \cdot \sqrt{ux \cdot \left(2 - maxCos\right)}\\

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


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

    1. Initial program 41.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. sub-neg41.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.9999998e-4 < ux

    1. Initial program 92.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. sub-neg92.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 75.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 0.0001500000071246177:\\ \;\;\;\;\sqrt[3]{{\left(ux \cdot \left(1 + \left(\left(1 - maxCos\right) - maxCos\right)\right)\right)}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(ux \cdot \left(1 - maxCos\right) + -1\right) \cdot \left(1 + ux \cdot \left(maxCos + -1\right)\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 0.0001500000071246177)
   (cbrt (pow (* ux (+ 1.0 (- (- 1.0 maxCos) maxCos))) 1.5))
   (sqrt
    (+
     1.0
     (* (+ (* ux (- 1.0 maxCos)) -1.0) (+ 1.0 (* ux (+ maxCos -1.0))))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 0.0001500000071246177f) {
		tmp = cbrtf(powf((ux * (1.0f + ((1.0f - maxCos) - maxCos))), 1.5f));
	} else {
		tmp = sqrtf((1.0f + (((ux * (1.0f - maxCos)) + -1.0f) * (1.0f + (ux * (maxCos + -1.0f))))));
	}
	return tmp;
}
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(0.0001500000071246177))
		tmp = cbrt((Float32(ux * Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - maxCos) - maxCos))) ^ Float32(1.5)));
	else
		tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(ux * Float32(Float32(1.0) - maxCos)) + Float32(-1.0)) * Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0001500000071246177:\\
\;\;\;\;\sqrt[3]{{\left(ux \cdot \left(1 + \left(\left(1 - maxCos\right) - maxCos\right)\right)\right)}^{1.5}}\\

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


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

    1. Initial program 37.4%

      \[\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. sub-neg37.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)}} \]
    9. Step-by-step derivation
      1. add-cbrt-cube74.0%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)} \cdot \sqrt{ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)}\right) \cdot \sqrt{ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)}}} \]
      2. add-sqr-sqrt74.0%

        \[\leadsto \sqrt[3]{\color{blue}{\left(ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)\right)} \cdot \sqrt{ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)}} \]
      3. pow174.0%

        \[\leadsto \sqrt[3]{\color{blue}{{\left(ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)\right)}^{1}} \cdot \sqrt{ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)}} \]
      4. pow1/274.0%

        \[\leadsto \sqrt[3]{{\left(ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)\right)}^{1} \cdot \color{blue}{{\left(ux \cdot \left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right)\right)}^{0.5}}} \]
      5. pow-prod-up74.0%

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

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

        \[\leadsto \sqrt[3]{{\left(\color{blue}{\left(1 - \left(\left(maxCos - 1\right) + maxCos\right)\right)} \cdot ux\right)}^{\left(1 + 0.5\right)}} \]
      8. sub-neg74.0%

        \[\leadsto \sqrt[3]{{\left(\left(1 - \left(\color{blue}{\left(maxCos + \left(-1\right)\right)} + maxCos\right)\right) \cdot ux\right)}^{\left(1 + 0.5\right)}} \]
      9. metadata-eval74.0%

        \[\leadsto \sqrt[3]{{\left(\left(1 - \left(\left(maxCos + \color{blue}{-1}\right) + maxCos\right)\right) \cdot ux\right)}^{\left(1 + 0.5\right)}} \]
      10. metadata-eval74.0%

        \[\leadsto \sqrt[3]{{\left(\left(1 - \left(\left(maxCos + -1\right) + maxCos\right)\right) \cdot ux\right)}^{\color{blue}{1.5}}} \]
    10. Applied egg-rr74.0%

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

    if 1.50000007e-4 < ux

    1. Initial program 89.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. sub-neg89.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 0.0001500000071246177:\\ \;\;\;\;\sqrt[3]{{\left(ux \cdot \left(1 + \left(\left(1 - maxCos\right) - maxCos\right)\right)\right)}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(ux \cdot \left(1 - maxCos\right) + -1\right) \cdot \left(1 + ux \cdot \left(maxCos + -1\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 75.6% accurate, 1.8× speedup?

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

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

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


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

    1. Initial program 37.4%

      \[\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. sub-neg37.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.50000007e-4 < ux

    1. Initial program 89.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. sub-neg89.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 0.0001500000071246177:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(ux \cdot \left(1 - maxCos\right) + -1\right) \cdot \left(1 + ux \cdot \left(maxCos + -1\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 74.5% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 37.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. sub-neg37.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.59999996e-4 < ux

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 0.00015999999595806003:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux \cdot \left(1 - maxCos\right) + -1\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 74.4% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 37.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. sub-neg37.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.59999996e-4 < ux

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ux \leq 0.00015999999595806003:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 65.3% accurate, 2.1× speedup?

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

\\
\sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)}
\end{array}
Derivation
  1. Initial program 58.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. sub-neg58.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 17: 62.7% accurate, 2.2× speedup?

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

\\
\sqrt{2 \cdot ux}
\end{array}
Derivation
  1. Initial program 58.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. sub-neg58.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{ux \cdot \color{blue}{2}} \]
  10. Final simplification60.9%

    \[\leadsto \sqrt{2 \cdot ux} \]
  11. Add Preprocessing

Reproduce

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