UniformSampleCone 2

Percentage Accurate: 98.9% → 99.0%
Time: 20.7s
Alternatives: 25
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}

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 25 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(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\\ t_1 := \sqrt{1 - t\_0 \cdot t\_0}\\ \left(\left(\sin \left(\pi \cdot \mathsf{fma}\left(uy, -2, 0.5\right)\right) \cdot t\_1\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \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 (* (+ maxCos (* -1.0 (* maxCos ux))) ux))
        (t_1 (sqrt (- 1.0 (* t_0 t_0)))))
   (+
    (+
     (* (* (sin (* PI (fma uy -2.0 0.5))) t_1) xi)
     (* (* (sin (* (* uy 2.0) PI)) t_1) yi))
    (* t_0 zi))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float t_0 = (maxCos + (-1.0f * (maxCos * ux))) * ux;
	float t_1 = sqrtf((1.0f - (t_0 * t_0)));
	return (((sinf((((float) M_PI) * fmaf(uy, -2.0f, 0.5f))) * t_1) * xi) + ((sinf(((uy * 2.0f) * ((float) M_PI))) * t_1) * yi)) + (t_0 * zi);
}
function code(xi, yi, zi, ux, uy, maxCos)
	t_0 = Float32(Float32(maxCos + Float32(Float32(-1.0) * Float32(maxCos * ux))) * ux)
	t_1 = sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))
	return Float32(Float32(Float32(Float32(sin(Float32(Float32(pi) * fma(uy, Float32(-2.0), Float32(0.5)))) * t_1) * xi) + Float32(Float32(sin(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * t_1) * yi)) + Float32(t_0 * zi))
end
\begin{array}{l}

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

    \[\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. Taylor expanded in ux around 0

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  3. Applied rewrites98.9%

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  5. Applied rewrites98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  6. Taylor expanded in ux around 0

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  7. Applied rewrites98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  8. Taylor expanded in ux around 0

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

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

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

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

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

Alternative 2: 99.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 (* (+ maxCos (* -1.0 (* maxCos ux))) 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 = (maxCos + (-1.0f * (maxCos * ux))) * 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(maxCos + Float32(Float32(-1.0) * Float32(maxCos * ux))) * 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 = (maxCos + (single(-1.0) * (maxCos * ux))) * 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(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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}
Derivation
  1. Initial program 98.9%

    \[\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. Taylor expanded in ux around 0

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  3. Applied rewrites98.9%

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  5. Applied rewrites98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  6. Taylor expanded in ux around 0

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  7. Applied rewrites98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  8. Taylor expanded in ux around 0

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

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

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

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

Alternative 3: 99.0% accurate, 1.0× speedup?

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

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

    \[\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. Applied rewrites99.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left(1 - ux\right) \cdot maxCos, ux \cdot zi, \mathsf{fma}\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\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)}, yi, \left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\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)}\right) \cdot xi\right)\right)} \]
  3. Add Preprocessing

Alternative 4: 98.9% accurate, 1.2× speedup?

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

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

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

    \[\leadsto \left(\left(\color{blue}{\sin \left(\mathsf{fma}\left(uy \cdot 2, \pi, \frac{\pi}{2}\right)\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 \]
  3. Applied rewrites99.0%

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

Alternative 5: 98.7% accurate, 1.5× speedup?

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

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

    \[\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. Taylor expanded in ux around 0

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  3. Applied rewrites98.9%

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  5. Applied rewrites98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  6. Taylor expanded in ux around 0

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  7. Applied rewrites98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
  8. Taylor expanded in ux around 0

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

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

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

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

    \[\leadsto \left(\left(\color{blue}{\sin \left(\pi \cdot \mathsf{fma}\left(uy, -2, 0.5\right)\right)} \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot zi \]
  13. Taylor expanded in maxCos around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(\frac{1}{2} + -2 \cdot uy\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
  14. Applied rewrites98.7%

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

Alternative 6: 98.6% accurate, 1.6× speedup?

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

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

    \[\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. Taylor expanded in maxCos around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
  3. Applied rewrites98.6%

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

Alternative 7: 98.6% accurate, 1.6× speedup?

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

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

    \[\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. Taylor expanded in maxCos around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
  3. Applied rewrites98.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), \mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)\right)} \]
  4. Applied rewrites98.6%

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

Alternative 8: 97.3% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;uy \leq 0.009999999776482582:\\ \;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(2, yi \cdot \pi, uy \cdot \mathsf{fma}\left(-2, xi \cdot {\pi}^{2}, -1.3333333333333333 \cdot \left(uy \cdot \left(yi \cdot {\pi}^{3}\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(xi, \sin \left(\pi \cdot \left(0.5 + -2 \cdot uy\right)\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (if (<= uy 0.009999999776482582)
   (+
    xi
    (fma
     maxCos
     (* ux (* zi (- 1.0 ux)))
     (*
      uy
      (fma
       2.0
       (* yi PI)
       (*
        uy
        (fma
         -2.0
         (* xi (pow PI 2.0))
         (* -1.3333333333333333 (* uy (* yi (pow PI 3.0))))))))))
   (fma xi (sin (* PI (+ 0.5 (* -2.0 uy)))) (* yi (sin (* 2.0 (* uy PI)))))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float tmp;
	if (uy <= 0.009999999776482582f) {
		tmp = xi + fmaf(maxCos, (ux * (zi * (1.0f - ux))), (uy * fmaf(2.0f, (yi * ((float) M_PI)), (uy * fmaf(-2.0f, (xi * powf(((float) M_PI), 2.0f)), (-1.3333333333333333f * (uy * (yi * powf(((float) M_PI), 3.0f)))))))));
	} else {
		tmp = fmaf(xi, sinf((((float) M_PI) * (0.5f + (-2.0f * uy)))), (yi * sinf((2.0f * (uy * ((float) M_PI))))));
	}
	return tmp;
}
function code(xi, yi, zi, ux, uy, maxCos)
	tmp = Float32(0.0)
	if (uy <= Float32(0.009999999776482582))
		tmp = Float32(xi + fma(maxCos, Float32(ux * Float32(zi * Float32(Float32(1.0) - ux))), Float32(uy * fma(Float32(2.0), Float32(yi * Float32(pi)), Float32(uy * fma(Float32(-2.0), Float32(xi * (Float32(pi) ^ Float32(2.0))), Float32(Float32(-1.3333333333333333) * Float32(uy * Float32(yi * (Float32(pi) ^ Float32(3.0)))))))))));
	else
		tmp = fma(xi, sin(Float32(Float32(pi) * Float32(Float32(0.5) + Float32(Float32(-2.0) * uy)))), Float32(yi * sin(Float32(Float32(2.0) * Float32(uy * Float32(pi))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.009999999776482582:\\
\;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(2, yi \cdot \pi, uy \cdot \mathsf{fma}\left(-2, xi \cdot {\pi}^{2}, -1.3333333333333333 \cdot \left(uy \cdot \left(yi \cdot {\pi}^{3}\right)\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(xi, \sin \left(\pi \cdot \left(0.5 + -2 \cdot uy\right)\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if uy < 0.00999999978

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto xi + \color{blue}{\left(maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + uy \cdot \left(2 \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right) + uy \cdot \left(-2 \cdot \left(xi \cdot {\mathsf{PI}\left(\right)}^{2}\right) + \frac{-4}{3} \cdot \left(uy \cdot \left(yi \cdot {\mathsf{PI}\left(\right)}^{3}\right)\right)\right)\right)\right)} \]
    5. Applied rewrites88.7%

      \[\leadsto xi + \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(2, yi \cdot \pi, uy \cdot \mathsf{fma}\left(-2, xi \cdot {\pi}^{2}, -1.3333333333333333 \cdot \left(uy \cdot \left(yi \cdot {\pi}^{3}\right)\right)\right)\right)\right)} \]

    if 0.00999999978 < uy

    1. Initial program 98.9%

      \[\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. Taylor expanded in ux around 0

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
    3. Applied rewrites98.9%

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

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
    5. Applied rewrites98.9%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
    6. Taylor expanded in ux around 0

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
    7. Applied rewrites98.9%

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\color{blue}{\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\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 \]
    8. Taylor expanded in ux around 0

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

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

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

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

      \[\leadsto \left(\left(\color{blue}{\sin \left(\pi \cdot \mathsf{fma}\left(uy, -2, 0.5\right)\right)} \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(maxCos + -1 \cdot \left(maxCos \cdot ux\right)\right) \cdot ux\right) \cdot zi \]
    13. Taylor expanded in ux around 0

      \[\leadsto \color{blue}{xi \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(\frac{1}{2} + -2 \cdot uy\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    14. Applied rewrites90.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \sin \left(\pi \cdot \left(0.5 + -2 \cdot uy\right)\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 97.2% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 \cdot \left(uy \cdot \pi\right)\\ \mathbf{if}\;uy \leq 0.009999999776482582:\\ \;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(2, yi \cdot \pi, uy \cdot \mathsf{fma}\left(-2, xi \cdot {\pi}^{2}, -1.3333333333333333 \cdot \left(uy \cdot \left(yi \cdot {\pi}^{3}\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(xi, \cos t\_0, yi \cdot \sin t\_0\right)\\ \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (let* ((t_0 (* 2.0 (* uy PI))))
   (if (<= uy 0.009999999776482582)
     (+
      xi
      (fma
       maxCos
       (* ux (* zi (- 1.0 ux)))
       (*
        uy
        (fma
         2.0
         (* yi PI)
         (*
          uy
          (fma
           -2.0
           (* xi (pow PI 2.0))
           (* -1.3333333333333333 (* uy (* yi (pow PI 3.0))))))))))
     (fma xi (cos t_0) (* yi (sin t_0))))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float t_0 = 2.0f * (uy * ((float) M_PI));
	float tmp;
	if (uy <= 0.009999999776482582f) {
		tmp = xi + fmaf(maxCos, (ux * (zi * (1.0f - ux))), (uy * fmaf(2.0f, (yi * ((float) M_PI)), (uy * fmaf(-2.0f, (xi * powf(((float) M_PI), 2.0f)), (-1.3333333333333333f * (uy * (yi * powf(((float) M_PI), 3.0f)))))))));
	} else {
		tmp = fmaf(xi, cosf(t_0), (yi * sinf(t_0)));
	}
	return tmp;
}
function code(xi, yi, zi, ux, uy, maxCos)
	t_0 = Float32(Float32(2.0) * Float32(uy * Float32(pi)))
	tmp = Float32(0.0)
	if (uy <= Float32(0.009999999776482582))
		tmp = Float32(xi + fma(maxCos, Float32(ux * Float32(zi * Float32(Float32(1.0) - ux))), Float32(uy * fma(Float32(2.0), Float32(yi * Float32(pi)), Float32(uy * fma(Float32(-2.0), Float32(xi * (Float32(pi) ^ Float32(2.0))), Float32(Float32(-1.3333333333333333) * Float32(uy * Float32(yi * (Float32(pi) ^ Float32(3.0)))))))))));
	else
		tmp = fma(xi, cos(t_0), Float32(yi * sin(t_0)));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 \cdot \left(uy \cdot \pi\right)\\
\mathbf{if}\;uy \leq 0.009999999776482582:\\
\;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(2, yi \cdot \pi, uy \cdot \mathsf{fma}\left(-2, xi \cdot {\pi}^{2}, -1.3333333333333333 \cdot \left(uy \cdot \left(yi \cdot {\pi}^{3}\right)\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(xi, \cos t\_0, yi \cdot \sin t\_0\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if uy < 0.00999999978

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto xi + \color{blue}{\left(maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + uy \cdot \left(2 \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right) + uy \cdot \left(-2 \cdot \left(xi \cdot {\mathsf{PI}\left(\right)}^{2}\right) + \frac{-4}{3} \cdot \left(uy \cdot \left(yi \cdot {\mathsf{PI}\left(\right)}^{3}\right)\right)\right)\right)\right)} \]
    5. Applied rewrites88.7%

      \[\leadsto xi + \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(2, yi \cdot \pi, uy \cdot \mathsf{fma}\left(-2, xi \cdot {\pi}^{2}, -1.3333333333333333 \cdot \left(uy \cdot \left(yi \cdot {\pi}^{3}\right)\right)\right)\right)\right)} \]

    if 0.00999999978 < uy

    1. Initial program 98.9%

      \[\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. Taylor expanded in ux around 0

      \[\leadsto \color{blue}{xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    3. Applied rewrites90.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 95.5% accurate, 1.6× speedup?

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

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

    \[\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. Taylor expanded in ux around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot zi\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
  3. Applied rewrites95.5%

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

Alternative 11: 89.5% accurate, 2.3× speedup?

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

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

    \[\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. Taylor expanded in maxCos around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
  3. Applied rewrites98.6%

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

    \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), \mathsf{fma}\left(xi, \cos \left(2 \cdot \left(uy \cdot \pi\right)\right), 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right)\right) \]
  5. Applied rewrites89.5%

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

Alternative 12: 87.9% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\\ \mathbf{if}\;uy \leq 0.07000000029802322:\\ \;\;\;\;xi + \mathsf{fma}\left(maxCos, t\_0, uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(maxCos, t\_0, yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (let* ((t_0 (* ux (* zi (- 1.0 ux)))))
   (if (<= uy 0.07000000029802322)
     (+
      xi
      (fma
       maxCos
       t_0
       (* uy (fma -2.0 (* uy (* xi (pow PI 2.0))) (* 2.0 (* yi PI))))))
     (fma maxCos t_0 (* yi (sin (* 2.0 (* uy PI))))))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float t_0 = ux * (zi * (1.0f - ux));
	float tmp;
	if (uy <= 0.07000000029802322f) {
		tmp = xi + fmaf(maxCos, t_0, (uy * fmaf(-2.0f, (uy * (xi * powf(((float) M_PI), 2.0f))), (2.0f * (yi * ((float) M_PI))))));
	} else {
		tmp = fmaf(maxCos, t_0, (yi * sinf((2.0f * (uy * ((float) M_PI))))));
	}
	return tmp;
}
function code(xi, yi, zi, ux, uy, maxCos)
	t_0 = Float32(ux * Float32(zi * Float32(Float32(1.0) - ux)))
	tmp = Float32(0.0)
	if (uy <= Float32(0.07000000029802322))
		tmp = Float32(xi + fma(maxCos, t_0, Float32(uy * fma(Float32(-2.0), Float32(uy * Float32(xi * (Float32(pi) ^ Float32(2.0)))), Float32(Float32(2.0) * Float32(yi * Float32(pi)))))));
	else
		tmp = fma(maxCos, t_0, Float32(yi * sin(Float32(Float32(2.0) * Float32(uy * Float32(pi))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\\
\mathbf{if}\;uy \leq 0.07000000029802322:\\
\;\;\;\;xi + \mathsf{fma}\left(maxCos, t\_0, uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(maxCos, t\_0, yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if uy < 0.0700000003

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto xi + \color{blue}{\left(maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + uy \cdot \left(-2 \cdot \left(uy \cdot \left(xi \cdot {\mathsf{PI}\left(\right)}^{2}\right)\right) + 2 \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    5. Applied rewrites85.1%

      \[\leadsto xi + \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)} \]

    if 0.0700000003 < uy

    1. Initial program 98.9%

      \[\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. Taylor expanded in xi around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + yi \cdot \left(\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
    3. Applied rewrites45.2%

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

      \[\leadsto maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    5. Applied rewrites45.1%

      \[\leadsto \mathsf{fma}\left(maxCos, \color{blue}{ux \cdot \left(zi \cdot \left(1 - ux\right)\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 13: 87.6% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;uy \leq 0.17000000178813934:\\ \;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;ux \cdot \mathsf{fma}\left(maxCos, zi, \frac{yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}{ux}\right)\\ \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (if (<= uy 0.17000000178813934)
   (+
    xi
    (fma
     maxCos
     (* ux (* zi (- 1.0 ux)))
     (* uy (fma -2.0 (* uy (* xi (pow PI 2.0))) (* 2.0 (* yi PI))))))
   (* ux (fma maxCos zi (/ (* yi (sin (* 2.0 (* uy PI)))) ux)))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float tmp;
	if (uy <= 0.17000000178813934f) {
		tmp = xi + fmaf(maxCos, (ux * (zi * (1.0f - ux))), (uy * fmaf(-2.0f, (uy * (xi * powf(((float) M_PI), 2.0f))), (2.0f * (yi * ((float) M_PI))))));
	} else {
		tmp = ux * fmaf(maxCos, zi, ((yi * sinf((2.0f * (uy * ((float) M_PI))))) / ux));
	}
	return tmp;
}
function code(xi, yi, zi, ux, uy, maxCos)
	tmp = Float32(0.0)
	if (uy <= Float32(0.17000000178813934))
		tmp = Float32(xi + fma(maxCos, Float32(ux * Float32(zi * Float32(Float32(1.0) - ux))), Float32(uy * fma(Float32(-2.0), Float32(uy * Float32(xi * (Float32(pi) ^ Float32(2.0)))), Float32(Float32(2.0) * Float32(yi * Float32(pi)))))));
	else
		tmp = Float32(ux * fma(maxCos, zi, Float32(Float32(yi * sin(Float32(Float32(2.0) * Float32(uy * Float32(pi))))) / ux)));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.17000000178813934:\\
\;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;ux \cdot \mathsf{fma}\left(maxCos, zi, \frac{yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}{ux}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if uy < 0.170000002

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto xi + \color{blue}{\left(maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + uy \cdot \left(-2 \cdot \left(uy \cdot \left(xi \cdot {\mathsf{PI}\left(\right)}^{2}\right)\right) + 2 \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    5. Applied rewrites85.1%

      \[\leadsto xi + \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)} \]

    if 0.170000002 < uy

    1. Initial program 98.9%

      \[\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. Taylor expanded in xi around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + yi \cdot \left(\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
    3. Applied rewrites45.2%

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

      \[\leadsto maxCos \cdot \left(ux \cdot zi\right) + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    5. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(maxCos, \color{blue}{ux \cdot zi}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right) \]
    6. Taylor expanded in ux around inf

      \[\leadsto ux \cdot \left(maxCos \cdot zi + \color{blue}{\frac{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}{ux}}\right) \]
    7. Applied rewrites43.0%

      \[\leadsto ux \cdot \mathsf{fma}\left(maxCos, \color{blue}{zi}, \frac{yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}{ux}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 14: 87.6% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;uy \leq 0.17000000178813934:\\ \;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(ux \cdot zi, maxCos, \sin \left(\left(\pi + \pi\right) \cdot uy\right) \cdot yi\right)\\ \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (if (<= uy 0.17000000178813934)
   (+
    xi
    (fma
     maxCos
     (* ux (* zi (- 1.0 ux)))
     (* uy (fma -2.0 (* uy (* xi (pow PI 2.0))) (* 2.0 (* yi PI))))))
   (fma (* ux zi) maxCos (* (sin (* (+ PI PI) uy)) yi))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float tmp;
	if (uy <= 0.17000000178813934f) {
		tmp = xi + fmaf(maxCos, (ux * (zi * (1.0f - ux))), (uy * fmaf(-2.0f, (uy * (xi * powf(((float) M_PI), 2.0f))), (2.0f * (yi * ((float) M_PI))))));
	} else {
		tmp = fmaf((ux * zi), maxCos, (sinf(((((float) M_PI) + ((float) M_PI)) * uy)) * yi));
	}
	return tmp;
}
function code(xi, yi, zi, ux, uy, maxCos)
	tmp = Float32(0.0)
	if (uy <= Float32(0.17000000178813934))
		tmp = Float32(xi + fma(maxCos, Float32(ux * Float32(zi * Float32(Float32(1.0) - ux))), Float32(uy * fma(Float32(-2.0), Float32(uy * Float32(xi * (Float32(pi) ^ Float32(2.0)))), Float32(Float32(2.0) * Float32(yi * Float32(pi)))))));
	else
		tmp = fma(Float32(ux * zi), maxCos, Float32(sin(Float32(Float32(Float32(pi) + Float32(pi)) * uy)) * yi));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.17000000178813934:\\
\;\;\;\;xi + \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(ux \cdot zi, maxCos, \sin \left(\left(\pi + \pi\right) \cdot uy\right) \cdot yi\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if uy < 0.170000002

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto xi + \color{blue}{\left(maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + uy \cdot \left(-2 \cdot \left(uy \cdot \left(xi \cdot {\mathsf{PI}\left(\right)}^{2}\right)\right) + 2 \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    5. Applied rewrites85.1%

      \[\leadsto xi + \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), uy \cdot \mathsf{fma}\left(-2, uy \cdot \left(xi \cdot {\pi}^{2}\right), 2 \cdot \left(yi \cdot \pi\right)\right)\right)} \]

    if 0.170000002 < uy

    1. Initial program 98.9%

      \[\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. Taylor expanded in xi around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + yi \cdot \left(\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
    3. Applied rewrites45.2%

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

      \[\leadsto maxCos \cdot \left(ux \cdot zi\right) + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    5. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(maxCos, \color{blue}{ux \cdot zi}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right) \]
    6. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(ux \cdot zi, maxCos, \sin \left(\left(\pi + \pi\right) \cdot uy\right) \cdot yi\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 84.1% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;uy \leq 0.07000000029802322:\\ \;\;\;\;\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi + 2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(ux \cdot zi, maxCos, \sin \left(\left(\pi + \pi\right) \cdot uy\right) \cdot yi\right)\\ \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (if (<= uy 0.07000000029802322)
   (fma maxCos (* ux (* zi (- 1.0 ux))) (+ xi (* 2.0 (* uy (* yi PI)))))
   (fma (* ux zi) maxCos (* (sin (* (+ PI PI) uy)) yi))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float tmp;
	if (uy <= 0.07000000029802322f) {
		tmp = fmaf(maxCos, (ux * (zi * (1.0f - ux))), (xi + (2.0f * (uy * (yi * ((float) M_PI))))));
	} else {
		tmp = fmaf((ux * zi), maxCos, (sinf(((((float) M_PI) + ((float) M_PI)) * uy)) * yi));
	}
	return tmp;
}
function code(xi, yi, zi, ux, uy, maxCos)
	tmp = Float32(0.0)
	if (uy <= Float32(0.07000000029802322))
		tmp = fma(maxCos, Float32(ux * Float32(zi * Float32(Float32(1.0) - ux))), Float32(xi + Float32(Float32(2.0) * Float32(uy * Float32(yi * Float32(pi))))));
	else
		tmp = fma(Float32(ux * zi), maxCos, Float32(sin(Float32(Float32(Float32(pi) + Float32(pi)) * uy)) * yi));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.07000000029802322:\\
\;\;\;\;\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi + 2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(ux \cdot zi, maxCos, \sin \left(\left(\pi + \pi\right) \cdot uy\right) \cdot yi\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if uy < 0.0700000003

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    5. Applied rewrites81.0%

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

    if 0.0700000003 < uy

    1. Initial program 98.9%

      \[\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. Taylor expanded in xi around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + yi \cdot \left(\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
    3. Applied rewrites45.2%

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

      \[\leadsto maxCos \cdot \left(ux \cdot zi\right) + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    5. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(maxCos, \color{blue}{ux \cdot zi}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right) \]
    6. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(ux \cdot zi, maxCos, \sin \left(\left(\pi + \pi\right) \cdot uy\right) \cdot yi\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 16: 83.1% accurate, 3.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.11500000208616257:\\
\;\;\;\;\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi + 2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if uy < 0.115000002

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    5. Applied rewrites81.0%

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

    if 0.115000002 < uy

    1. Initial program 98.9%

      \[\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. Taylor expanded in maxCos around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. Applied rewrites98.6%

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

      \[\leadsto xi \cdot \color{blue}{\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    5. Applied rewrites52.1%

      \[\leadsto xi \cdot \color{blue}{\cos \left(2 \cdot \left(uy \cdot \pi\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 17: 81.0% accurate, 6.0× speedup?

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

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

    \[\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. Taylor expanded in maxCos around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
  3. Applied rewrites98.6%

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

    \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
  5. Applied rewrites81.0%

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

Alternative 18: 81.0% accurate, 6.0× speedup?

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

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

    \[\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. Taylor expanded in maxCos around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
  3. Applied rewrites98.6%

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

    \[\leadsto xi + \color{blue}{\left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)} \]
  5. Applied rewrites81.0%

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

Alternative 19: 61.5% accurate, 6.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(maxCos, ux \cdot zi, 2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)\right)\\ \mathbf{if}\;yi \leq -3.999999984016789 \cdot 10^{-11}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;yi \leq 1.99999996490334 \cdot 10^{-14}:\\ \;\;\;\;xi + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (let* ((t_0 (fma maxCos (* ux zi) (* 2.0 (* uy (* yi PI))))))
   (if (<= yi -3.999999984016789e-11)
     t_0
     (if (<= yi 1.99999996490334e-14)
       (+ xi (* maxCos (* ux (* zi (- 1.0 ux)))))
       t_0))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	float t_0 = fmaf(maxCos, (ux * zi), (2.0f * (uy * (yi * ((float) M_PI)))));
	float tmp;
	if (yi <= -3.999999984016789e-11f) {
		tmp = t_0;
	} else if (yi <= 1.99999996490334e-14f) {
		tmp = xi + (maxCos * (ux * (zi * (1.0f - ux))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(xi, yi, zi, ux, uy, maxCos)
	t_0 = fma(maxCos, Float32(ux * zi), Float32(Float32(2.0) * Float32(uy * Float32(yi * Float32(pi)))))
	tmp = Float32(0.0)
	if (yi <= Float32(-3.999999984016789e-11))
		tmp = t_0;
	elseif (yi <= Float32(1.99999996490334e-14))
		tmp = Float32(xi + Float32(maxCos * Float32(ux * Float32(zi * Float32(Float32(1.0) - ux)))));
	else
		tmp = t_0;
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(maxCos, ux \cdot zi, 2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)\right)\\
\mathbf{if}\;yi \leq -3.999999984016789 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;yi \leq 1.99999996490334 \cdot 10^{-14}:\\
\;\;\;\;xi + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if yi < -3.99999998e-11 or 1.99999996e-14 < yi

    1. Initial program 98.9%

      \[\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. Taylor expanded in xi around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + yi \cdot \left(\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
    3. Applied rewrites45.2%

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

      \[\leadsto maxCos \cdot \left(ux \cdot zi\right) + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    5. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(maxCos, \color{blue}{ux \cdot zi}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\right) \]
    6. Taylor expanded in uy around 0

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot zi, 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    7. Applied rewrites36.4%

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot zi, 2 \cdot \left(uy \cdot \left(yi \cdot \pi\right)\right)\right) \]

    if -3.99999998e-11 < yi < 1.99999996e-14

    1. Initial program 98.9%

      \[\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. Taylor expanded in uy around 0

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
    3. Applied rewrites51.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
    4. Taylor expanded in maxCos around 0

      \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
    5. Applied rewrites51.1%

      \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 20: 51.1% accurate, 10.4× speedup?

\[\begin{array}{l} \\ xi + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (+ xi (* maxCos (* ux (* zi (- 1.0 ux))))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	return xi + (maxCos * (ux * (zi * (1.0f - ux))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(xi, yi, zi, ux, uy, maxcos)
use fmin_fmax_functions
    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 = xi + (maxcos * (ux * (zi * (1.0e0 - ux))))
end function
function code(xi, yi, zi, ux, uy, maxCos)
	return Float32(xi + Float32(maxCos * Float32(ux * Float32(zi * Float32(Float32(1.0) - ux)))))
end
function tmp = code(xi, yi, zi, ux, uy, maxCos)
	tmp = xi + (maxCos * (ux * (zi * (single(1.0) - ux))));
end
\begin{array}{l}

\\
xi + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\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. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
  3. Applied rewrites51.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
  4. Taylor expanded in maxCos around 0

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
  5. Applied rewrites51.1%

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
  6. Add Preprocessing

Alternative 21: 48.9% accurate, 16.4× speedup?

\[\begin{array}{l} \\ xi + \left(maxCos \cdot ux\right) \cdot zi \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (+ xi (* (* maxCos ux) zi)))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	return xi + ((maxCos * ux) * zi);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(xi, yi, zi, ux, uy, maxcos)
use fmin_fmax_functions
    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 = xi + ((maxcos * ux) * zi)
end function
function code(xi, yi, zi, ux, uy, maxCos)
	return Float32(xi + Float32(Float32(maxCos * ux) * zi))
end
function tmp = code(xi, yi, zi, ux, uy, maxCos)
	tmp = xi + ((maxCos * ux) * zi);
end
\begin{array}{l}

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

    \[\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. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
  3. Applied rewrites51.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
  4. Taylor expanded in ux around 0

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  5. Applied rewrites48.9%

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  6. Applied rewrites48.9%

    \[\leadsto xi + \left(maxCos \cdot ux\right) \cdot zi \]
  7. Add Preprocessing

Alternative 22: 48.9% accurate, 17.3× speedup?

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

\\
\mathsf{fma}\left(maxCos \cdot zi, ux, xi\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\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. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
  3. Applied rewrites51.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
  4. Taylor expanded in ux around 0

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  5. Applied rewrites48.9%

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  6. Applied rewrites48.9%

    \[\leadsto \mathsf{fma}\left(maxCos \cdot zi, ux, xi\right) \]
  7. Add Preprocessing

Alternative 23: 48.9% accurate, 17.3× speedup?

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

\\
\mathsf{fma}\left(maxCos \cdot ux, zi, xi\right)
\end{array}
Derivation
  1. Initial program 98.9%

    \[\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. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
  3. Applied rewrites51.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
  4. Taylor expanded in ux around 0

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  5. Applied rewrites48.9%

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  6. Applied rewrites48.9%

    \[\leadsto \mathsf{fma}\left(maxCos \cdot ux, zi, xi\right) \]
  7. Add Preprocessing

Alternative 24: 44.3% accurate, 20.3× speedup?

\[\begin{array}{l} \\ zi \cdot \frac{xi}{zi} \end{array} \]
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* zi (/ xi zi)))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
	return zi * (xi / zi);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(xi, yi, zi, ux, uy, maxcos)
use fmin_fmax_functions
    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 = zi * (xi / zi)
end function
function code(xi, yi, zi, ux, uy, maxCos)
	return Float32(zi * Float32(xi / zi))
end
function tmp = code(xi, yi, zi, ux, uy, maxCos)
	tmp = zi * (xi / zi);
end
\begin{array}{l}

\\
zi \cdot \frac{xi}{zi}
\end{array}
Derivation
  1. Initial program 98.9%

    \[\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. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
  3. Applied rewrites51.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
  4. Taylor expanded in zi around inf

    \[\leadsto zi \cdot \color{blue}{\left(maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right) + \frac{xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}}{zi}\right)} \]
  5. Applied rewrites50.9%

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

    \[\leadsto zi \cdot \frac{xi}{zi} \]
  7. Applied rewrites44.3%

    \[\leadsto zi \cdot \frac{xi}{zi} \]
  8. Add Preprocessing

Alternative 25: 12.2% accurate, 22.3× 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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(xi, yi, zi, ux, uy, maxcos)
use fmin_fmax_functions
    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 98.9%

    \[\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. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
  3. Applied rewrites51.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot \left(zi \cdot \left(1 - ux\right)\right), xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} \]
  4. Taylor expanded in ux around 0

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  5. Applied rewrites48.9%

    \[\leadsto xi + \color{blue}{maxCos \cdot \left(ux \cdot zi\right)} \]
  6. Taylor expanded in xi around 0

    \[\leadsto maxCos \cdot \left(ux \cdot \color{blue}{zi}\right) \]
  7. Applied rewrites12.2%

    \[\leadsto maxCos \cdot \left(ux \cdot \color{blue}{zi}\right) \]
  8. Add Preprocessing

Reproduce

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