UniformSampleCone 2

Percentage Accurate: 98.9% → 99.0%
Time: 27.8s
Alternatives: 15
Speedup: 1.0×

Specification

?
\[\left(\left(\left(\left(\left(-10000 \leq xi \land xi \leq 10000\right) \land \left(-10000 \leq yi \land yi \leq 10000\right)\right) \land \left(-10000 \leq zi \land zi \leq 10000\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq ux \land ux \leq 1\right)\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(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\ t_1 := \sqrt{1 - t_0 \cdot t_0}\\ t_2 := \left(uy \cdot 2\right) \cdot \pi\\ \left(\left(\cos t_2 \cdot t_1\right) \cdot xi + \left(\sin t_2 \cdot t_1\right) \cdot yi\right) + t_0 \cdot zi \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (let* ((t_0 (* (* (- 1.0 ux) maxCos) ux))
        (t_1 (sqrt (- 1.0 (* t_0 t_0))))
        (t_2 (* (* uy 2.0) PI)))
   (+ (+ (* (* (cos t_2) t_1) xi) (* (* (sin t_2) t_1) yi)) (* t_0 zi))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float t_0 = ((1.0f - ux) * maxCos) * ux;
	float t_1 = sqrtf((1.0f - (t_0 * t_0)));
	float t_2 = (uy * 2.0f) * ((float) M_PI);
	return (((cosf(t_2) * t_1) * xi) + ((sinf(t_2) * t_1) * yi)) + (t_0 * zi);
}
function code(xi, yi, zi, ux, uy, maxCos)
	t_0 = Float32(Float32(Float32(Float32(1.0) - ux) * maxCos) * ux)
	t_1 = sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))
	t_2 = Float32(Float32(uy * Float32(2.0)) * Float32(pi))
	return Float32(Float32(Float32(Float32(cos(t_2) * t_1) * xi) + Float32(Float32(sin(t_2) * t_1) * yi)) + Float32(t_0 * zi))
end
function tmp = code(xi, yi, zi, ux, uy, maxCos)
	t_0 = ((single(1.0) - ux) * maxCos) * ux;
	t_1 = sqrt((single(1.0) - (t_0 * t_0)));
	t_2 = (uy * single(2.0)) * single(pi);
	tmp = (((cos(t_2) * t_1) * xi) + ((sin(t_2) * t_1) * yi)) + (t_0 * zi);
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
t_1 := \sqrt{1 - t_0 \cdot t_0}\\
t_2 := \left(uy \cdot 2\right) \cdot \pi\\
\left(\left(\cos t_2 \cdot t_1\right) \cdot xi + \left(\sin t_2 \cdot t_1\right) \cdot yi\right) + t_0 \cdot zi
\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 15 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: 98.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
t_1 := \sqrt{1 - t_0 \cdot t_0}\\
t_2 := \left(uy \cdot 2\right) \cdot \pi\\
\left(\left(\cos t_2 \cdot t_1\right) \cdot xi + \left(\sin t_2 \cdot t_1\right) \cdot yi\right) + t_0 \cdot zi
\end{array}
\end{array}

Alternative 1: 99.0% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\\
t_1 := uy \cdot \left(2 \cdot \pi\right)\\
t_2 := \sqrt{1 + t_0 \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(ux + -1\right)\right)}\\
\mathsf{fma}\left(\cos t_1 \cdot t_2, xi, \sin t_1 \cdot \left(t_2 \cdot yi\right)\right) + t_0 \cdot zi
\end{array}
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  2. Simplified99.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) \cdot \left(maxCos \cdot ux\right)\right) \cdot \left(\left(1 - ux\right) \cdot \left(maxCos \cdot ux\right)\right)}, xi, \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \left(\sqrt{1 - \left(\left(1 - ux\right) \cdot \left(maxCos \cdot ux\right)\right) \cdot \left(\left(1 - ux\right) \cdot \left(maxCos \cdot ux\right)\right)} \cdot yi\right)\right) + \left(\left(1 - ux\right) \cdot \left(maxCos \cdot ux\right)\right) \cdot zi} \]
  3. Add Preprocessing
  4. Final simplification99.0%

    \[\leadsto \mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{1 + \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(ux + -1\right)\right)}, xi, \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \left(\sqrt{1 + \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(ux + -1\right)\right)} \cdot yi\right)\right) + \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right) \cdot zi \]
  5. Add Preprocessing

Alternative 2: 99.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \left(1 - ux\right) \cdot maxCos\\
t_1 := uy \cdot \left(2 \cdot \pi\right)\\
\mathsf{fma}\left(t_0, ux \cdot zi, \sqrt{1 + t_0 \cdot \left(\left(maxCos \cdot \left(ux + -1\right)\right) \cdot \left(ux \cdot ux\right)\right)} \cdot \left(\cos t_1 \cdot xi + \sin t_1 \cdot yi\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  2. Simplified99.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left(1 - ux\right) \cdot maxCos, ux \cdot zi, \sqrt{1 - \left(maxCos \cdot \left(ux + -1\right)\right) \cdot \left(\left(ux \cdot ux\right) \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\right)} \cdot \left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot xi + \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot yi\right)\right)} \]
  3. Add Preprocessing
  4. Final simplification99.0%

    \[\leadsto \mathsf{fma}\left(\left(1 - ux\right) \cdot maxCos, ux \cdot zi, \sqrt{1 + \left(\left(1 - ux\right) \cdot maxCos\right) \cdot \left(\left(maxCos \cdot \left(ux + -1\right)\right) \cdot \left(ux \cdot ux\right)\right)} \cdot \left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot xi + \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot yi\right)\right) \]
  5. Add Preprocessing

Alternative 3: 98.8% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_0 := \pi \cdot \left(uy \cdot 2\right)\\
t_1 := ux \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\\
\left(xi \cdot \left(\sqrt{1 - t_1 \cdot t_1} \cdot \cos t_0\right) + yi \cdot \sin t_0\right) + zi \cdot \left(ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 99.0%

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  4. Step-by-step derivation
    1. associate-*r*98.8%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + yi \cdot \sin \color{blue}{\left(\left(2 \cdot uy\right) \cdot \pi\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. *-commutative98.8%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + yi \cdot \sin \left(\color{blue}{\left(uy \cdot 2\right)} \cdot \pi\right)\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. *-commutative98.8%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + yi \cdot \sin \color{blue}{\left(\pi \cdot \left(uy \cdot 2\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. *-commutative98.8%

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

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

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

Alternative 4: 90.2% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_0 := \left(1 - ux\right) \cdot maxCos\\
\mathsf{fma}\left(t_0, ux \cdot zi, \sqrt{1 + t_0 \cdot \left(\left(maxCos \cdot \left(ux + -1\right)\right) \cdot \left(ux \cdot ux\right)\right)} \cdot \left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot xi + \left(uy \cdot 2\right) \cdot \left(\pi \cdot yi\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  2. Simplified99.0%

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

    \[\leadsto \mathsf{fma}\left(\left(1 - ux\right) \cdot maxCos, ux \cdot zi, \sqrt{1 - \left(maxCos \cdot \left(ux + -1\right)\right) \cdot \left(\left(ux \cdot ux\right) \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\right)} \cdot \left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot xi + \color{blue}{2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)}\right)\right) \]
  5. Step-by-step derivation
    1. associate-*r*89.5%

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

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

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

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

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

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

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

Alternative 5: 90.2% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := ux \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\\
zi \cdot \left(ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right) + \left(xi \cdot \left(\sqrt{1 - t_0 \cdot t_0} \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\right) + \left(uy \cdot 2\right) \cdot \left(\pi \cdot yi\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 99.0%

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  4. Step-by-step derivation
    1. associate-*r*98.8%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + yi \cdot \sin \color{blue}{\left(\left(2 \cdot uy\right) \cdot \pi\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. *-commutative98.8%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + yi \cdot \sin \left(\color{blue}{\left(uy \cdot 2\right)} \cdot \pi\right)\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. *-commutative98.8%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + yi \cdot \sin \color{blue}{\left(\pi \cdot \left(uy \cdot 2\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. *-commutative98.8%

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

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \color{blue}{2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  7. Step-by-step derivation
    1. associate-*r*89.3%

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

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \color{blue}{\left(2 \cdot uy\right) \cdot \left(\pi \cdot yi\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  9. Final simplification89.3%

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

Alternative 6: 59.5% accurate, 1.5× speedup?

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right), \sqrt{1 - \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right)\right)} \cdot xi, maxCos \cdot \left(\left(ux \cdot zi\right) \cdot \color{blue}{\frac{1 \cdot 1 - ux \cdot ux}{1 + ux}}\right)\right) \]
    3. associate-*r/60.3%

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

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

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

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

    \[\leadsto \mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right), \sqrt{1 - \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right)\right)} \cdot xi, maxCos \cdot \color{blue}{\frac{\left(ux \cdot zi\right) \cdot \left(1 - {ux}^{2}\right)}{ux + 1}}\right) \]
  8. Step-by-step derivation
    1. associate-/l*60.3%

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

    \[\leadsto \mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right), \sqrt{1 - \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right)\right)} \cdot xi, maxCos \cdot \color{blue}{\frac{ux \cdot zi}{\frac{ux + 1}{1 - {ux}^{2}}}}\right) \]
  10. Step-by-step derivation
    1. frac-2neg60.3%

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

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

      \[\leadsto \mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right), \sqrt{1 - \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right)\right)} \cdot xi, maxCos \cdot \left(-\frac{ux \cdot zi}{-\color{blue}{\frac{1}{\frac{1 - {ux}^{2}}{ux + 1}}}}\right)\right) \]
    4. distribute-neg-frac60.4%

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right), \sqrt{1 - \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right)\right)} \cdot xi, maxCos \cdot \left(-\frac{ux \cdot zi}{\frac{-1}{\color{blue}{1 - ux}}}\right)\right) \]
  11. Applied egg-rr60.4%

    \[\leadsto \mathsf{fma}\left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right), \sqrt{1 - \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right)\right)\right)} \cdot xi, maxCos \cdot \color{blue}{\left(-\frac{ux \cdot zi}{\frac{-1}{1 - ux}}\right)}\right) \]
  12. Final simplification60.4%

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

Alternative 7: 59.4% accurate, 1.5× speedup?

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 59.4% accurate, 1.5× speedup?

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

Alternative 9: 59.4% accurate, 1.5× speedup?

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 57.2% accurate, 1.6× speedup?

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

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

Alternative 11: 57.2% accurate, 2.1× speedup?

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

\\
\mathsf{fma}\left(maxCos, ux \cdot zi, xi \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot zi\right) + xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)} \]
  11. Step-by-step derivation
    1. fma-def58.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot zi, xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)} \]
    2. associate-*r*58.8%

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot zi, xi \cdot \cos \color{blue}{\left(\left(2 \cdot uy\right) \cdot \pi\right)}\right) \]
    3. *-commutative58.8%

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot zi, xi \cdot \cos \color{blue}{\left(\pi \cdot \left(2 \cdot uy\right)\right)}\right) \]
  12. Simplified58.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot zi, xi \cdot \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)\right)} \]
  13. Final simplification58.8%

    \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot zi, xi \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\right) \]
  14. Add Preprocessing

Alternative 12: 57.2% accurate, 2.1× speedup?

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

\\
\mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), ux \cdot \left(maxCos \cdot zi\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot zi\right) + xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)} \]
  11. Step-by-step derivation
    1. +-commutative58.8%

      \[\leadsto \color{blue}{xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right) + maxCos \cdot \left(ux \cdot zi\right)} \]
    2. fma-def58.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), maxCos \cdot \left(ux \cdot zi\right)\right)} \]
    3. *-commutative58.8%

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), \color{blue}{\left(ux \cdot zi\right) \cdot maxCos}\right) \]
    4. associate-*l*58.8%

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

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), ux \cdot \color{blue}{\left(maxCos \cdot zi\right)}\right) \]
  12. Simplified58.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), ux \cdot \left(maxCos \cdot zi\right)\right)} \]
  13. Final simplification58.8%

    \[\leadsto \mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), ux \cdot \left(maxCos \cdot zi\right)\right) \]
  14. Add Preprocessing

Alternative 13: 57.2% accurate, 3.1× speedup?

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

\\
maxCos \cdot \left(ux \cdot zi\right) + xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot zi\right) + xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)} \]
  11. Final simplification58.8%

    \[\leadsto maxCos \cdot \left(ux \cdot zi\right) + xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \]
  12. Add Preprocessing

Alternative 14: 52.7% accurate, 3.2× speedup?

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

\\
xi \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{xi \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)} \]
  11. Step-by-step derivation
    1. associate-*r*55.1%

      \[\leadsto xi \cdot \cos \color{blue}{\left(\left(2 \cdot uy\right) \cdot \pi\right)} \]
    2. *-commutative55.1%

      \[\leadsto xi \cdot \cos \color{blue}{\left(\pi \cdot \left(2 \cdot uy\right)\right)} \]
  12. Simplified55.1%

    \[\leadsto \color{blue}{xi \cdot \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)} \]
  13. Final simplification55.1%

    \[\leadsto xi \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \]
  14. Add Preprocessing

Alternative 15: 12.1% accurate, 131.8× speedup?

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

\\
maxCos \cdot \left(ux \cdot zi\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)} \]
    2. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  11. Final simplification11.3%

    \[\leadsto maxCos \cdot \left(ux \cdot zi\right) \]
  12. Add Preprocessing

Reproduce

?
herbie shell --seed 2024011 
(FPCore (xi yi zi ux uy maxCos)
  :name "UniformSampleCone 2"
  :precision binary32
  :pre (and (and (and (and (and (and (<= -10000.0 xi) (<= xi 10000.0)) (and (<= -10000.0 yi) (<= yi 10000.0))) (and (<= -10000.0 zi) (<= zi 10000.0))) (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) maxCos) ux) (* (* (- 1.0 ux) maxCos) ux))))) xi) (* (* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (* (* (- 1.0 ux) maxCos) ux) (* (* (- 1.0 ux) maxCos) ux))))) yi)) (* (* (* (- 1.0 ux) maxCos) ux) zi)))