UniformSampleCone 2

Percentage Accurate: 98.9% → 98.8%
Time: 24.0s
Alternatives: 24
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 24 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: 98.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(uy \cdot 2\right) \cdot \pi\\ t_1 := ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\\ \left(\left(\sqrt{1 + t\_1 \cdot \left(ux \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\right)} \cdot \cos t\_0\right) \cdot xi + \left(\sin t\_0 \cdot \sqrt{\left(ux \cdot \left(ux \cdot \mathsf{fma}\left(ux, ux, 0\right)\right)\right) \cdot \left(\mathsf{fma}\left(maxCos, maxCos \cdot -2, \frac{\mathsf{fma}\left(maxCos, -maxCos, \frac{1}{\mathsf{fma}\left(ux, ux, 0\right)}\right)}{-ux}\right) \cdot \frac{-1}{ux} - maxCos \cdot maxCos\right)}\right) \cdot yi\right) + t\_1 \cdot zi \end{array} \end{array} \]
(FPCore (xi yi zi ux uy maxCos)
 :precision binary32
 (let* ((t_0 (* (* uy 2.0) PI)) (t_1 (* ux (* (- 1.0 ux) maxCos))))
   (+
    (+
     (* (* (sqrt (+ 1.0 (* t_1 (* ux (* maxCos (+ ux -1.0)))))) (cos t_0)) xi)
     (*
      (*
       (sin t_0)
       (sqrt
        (*
         (* ux (* ux (fma ux ux 0.0)))
         (-
          (*
           (fma
            maxCos
            (* maxCos -2.0)
            (/ (fma maxCos (- maxCos) (/ 1.0 (fma ux ux 0.0))) (- ux)))
           (/ -1.0 ux))
          (* maxCos maxCos)))))
      yi))
    (* t_1 zi))))
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 = ux * ((1.0f - ux) * maxCos);
	return (((sqrtf((1.0f + (t_1 * (ux * (maxCos * (ux + -1.0f)))))) * cosf(t_0)) * xi) + ((sinf(t_0) * sqrtf(((ux * (ux * fmaf(ux, ux, 0.0f))) * ((fmaf(maxCos, (maxCos * -2.0f), (fmaf(maxCos, -maxCos, (1.0f / fmaf(ux, ux, 0.0f))) / -ux)) * (-1.0f / ux)) - (maxCos * maxCos))))) * yi)) + (t_1 * zi);
}
function code(xi, yi, zi, ux, uy, maxCos)
	t_0 = Float32(Float32(uy * Float32(2.0)) * Float32(pi))
	t_1 = Float32(ux * Float32(Float32(Float32(1.0) - ux) * maxCos))
	return Float32(Float32(Float32(Float32(sqrt(Float32(Float32(1.0) + Float32(t_1 * Float32(ux * Float32(maxCos * Float32(ux + Float32(-1.0))))))) * cos(t_0)) * xi) + Float32(Float32(sin(t_0) * sqrt(Float32(Float32(ux * Float32(ux * fma(ux, ux, Float32(0.0)))) * Float32(Float32(fma(maxCos, Float32(maxCos * Float32(-2.0)), Float32(fma(maxCos, Float32(-maxCos), Float32(Float32(1.0) / fma(ux, ux, Float32(0.0)))) / Float32(-ux))) * Float32(Float32(-1.0) / ux)) - Float32(maxCos * maxCos))))) * yi)) + Float32(t_1 * zi))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(uy \cdot 2\right) \cdot \pi\\
t_1 := ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\\
\left(\left(\sqrt{1 + t\_1 \cdot \left(ux \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\right)} \cdot \cos t\_0\right) \cdot xi + \left(\sin t\_0 \cdot \sqrt{\left(ux \cdot \left(ux \cdot \mathsf{fma}\left(ux, ux, 0\right)\right)\right) \cdot \left(\mathsf{fma}\left(maxCos, maxCos \cdot -2, \frac{\mathsf{fma}\left(maxCos, -maxCos, \frac{1}{\mathsf{fma}\left(ux, ux, 0\right)}\right)}{-ux}\right) \cdot \frac{-1}{ux} - maxCos \cdot maxCos\right)}\right) \cdot yi\right) + t\_1 \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. Add Preprocessing
  3. Taylor expanded in ux around inf

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  4. Step-by-step derivation
    1. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. pow-lowering-pow.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4}} \cdot \left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. --lowering--.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \color{blue}{\left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. /-lowering-/.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\color{blue}{\frac{1}{{ux}^{4}}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    5. pow-lowering-pow.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{\color{blue}{{ux}^{4}}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    6. accelerator-lowering-fma.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \color{blue}{\mathsf{fma}\left(-2, \frac{{maxCos}^{2}}{ux}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    7. /-lowering-/.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \color{blue}{\frac{{maxCos}^{2}}{ux}}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    8. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{\color{blue}{maxCos \cdot maxCos}}{ux}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    9. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{\color{blue}{maxCos \cdot maxCos}}{ux}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    10. +-commutativeN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \color{blue}{{maxCos}^{2} + \frac{{maxCos}^{2}}{{ux}^{2}}}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    11. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \color{blue}{maxCos \cdot maxCos} + \frac{{maxCos}^{2}}{{ux}^{2}}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    12. accelerator-lowering-fma.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \color{blue}{\mathsf{fma}\left(maxCos, maxCos, \frac{{maxCos}^{2}}{{ux}^{2}}\right)}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    13. /-lowering-/.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \color{blue}{\frac{{maxCos}^{2}}{{ux}^{2}}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    14. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{\color{blue}{maxCos \cdot maxCos}}{{ux}^{2}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    15. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{\color{blue}{maxCos \cdot maxCos}}{{ux}^{2}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    16. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos \cdot maxCos}{\color{blue}{ux \cdot ux}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    17. *-lowering-*.f3298.9

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos \cdot maxCos}{ux \cdot ux}\right)\right)\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 -inf

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(-1 \cdot \frac{-2 \cdot {maxCos}^{2} + -1 \cdot \frac{-1 \cdot {maxCos}^{2} + \frac{1}{{ux}^{2}}}{ux}}{ux} + -1 \cdot {maxCos}^{2}\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  7. Simplified98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\left(-maxCos \cdot maxCos\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(-maxCos, maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  8. Step-by-step derivation
    1. metadata-evalN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{\color{blue}{\left(3 + 1\right)}} \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. pow-plusN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{\left({ux}^{3} \cdot ux\right)} \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{\left({ux}^{3} \cdot ux\right)} \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. cube-multN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\color{blue}{\left(ux \cdot \left(ux \cdot ux\right)\right)} \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    5. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\color{blue}{\left(ux \cdot \left(ux \cdot ux\right)\right)} \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    6. +-lft-identityN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(ux \cdot \color{blue}{\left(0 + ux \cdot ux\right)}\right) \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    7. +-commutativeN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(ux \cdot \color{blue}{\left(ux \cdot ux + 0\right)}\right) \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    8. accelerator-lowering-fma.f3298.9

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{\left(\left(ux \cdot \mathsf{fma}\left(ux, ux, 0\right)\right) \cdot ux\right)} \cdot \left(\left(-maxCos \cdot maxCos\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(-maxCos, maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  10. Step-by-step derivation
    1. div-invN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(ux \cdot \mathsf{fma}\left(ux, ux, 0\right)\right) \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \color{blue}{\left(\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\left(\mathsf{neg}\left(maxCos\right)\right) \cdot maxCos + \frac{1}{ux \cdot ux}}{ux}\right) \cdot \frac{1}{ux}}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(ux \cdot \mathsf{fma}\left(ux, ux, 0\right)\right) \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \color{blue}{\left(\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\left(\mathsf{neg}\left(maxCos\right)\right) \cdot maxCos + \frac{1}{ux \cdot ux}}{ux}\right) \cdot \frac{1}{ux}}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  11. Applied egg-rr98.9%

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

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

Alternative 2: 98.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\\
t_1 := \left(uy \cdot 2\right) \cdot \pi\\
t\_0 \cdot zi + \left(\left(\sqrt{1 + t\_0 \cdot \left(ux \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\right)} \cdot \cos t\_1\right) \cdot xi + yi \cdot \left(\sin t\_1 \cdot \sqrt{\left(ux \cdot \left(ux \cdot \mathsf{fma}\left(ux, ux, 0\right)\right)\right) \cdot \left(\frac{\frac{\mathsf{fma}\left(-maxCos, maxCos, \frac{1}{ux \cdot ux}\right)}{ux} - \left(maxCos \cdot maxCos\right) \cdot -2}{ux} - maxCos \cdot maxCos\right)}\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. Add Preprocessing
  3. Taylor expanded in ux around inf

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  4. Step-by-step derivation
    1. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. pow-lowering-pow.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4}} \cdot \left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. --lowering--.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \color{blue}{\left(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. /-lowering-/.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\color{blue}{\frac{1}{{ux}^{4}}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    5. pow-lowering-pow.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{\color{blue}{{ux}^{4}}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    6. accelerator-lowering-fma.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \color{blue}{\mathsf{fma}\left(-2, \frac{{maxCos}^{2}}{ux}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    7. /-lowering-/.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \color{blue}{\frac{{maxCos}^{2}}{ux}}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    8. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{\color{blue}{maxCos \cdot maxCos}}{ux}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    9. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{\color{blue}{maxCos \cdot maxCos}}{ux}, \frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    10. +-commutativeN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \color{blue}{{maxCos}^{2} + \frac{{maxCos}^{2}}{{ux}^{2}}}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    11. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \color{blue}{maxCos \cdot maxCos} + \frac{{maxCos}^{2}}{{ux}^{2}}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    12. accelerator-lowering-fma.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \color{blue}{\mathsf{fma}\left(maxCos, maxCos, \frac{{maxCos}^{2}}{{ux}^{2}}\right)}\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    13. /-lowering-/.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \color{blue}{\frac{{maxCos}^{2}}{{ux}^{2}}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    14. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{\color{blue}{maxCos \cdot maxCos}}{{ux}^{2}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    15. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{\color{blue}{maxCos \cdot maxCos}}{{ux}^{2}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    16. unpow2N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos \cdot maxCos}{\color{blue}{ux \cdot ux}}\right)\right)\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    17. *-lowering-*.f3298.9

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

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\frac{1}{{ux}^{4}} - \mathsf{fma}\left(-2, \frac{maxCos \cdot maxCos}{ux}, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos \cdot maxCos}{ux \cdot ux}\right)\right)\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 -inf

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(-1 \cdot \frac{-2 \cdot {maxCos}^{2} + -1 \cdot \frac{-1 \cdot {maxCos}^{2} + \frac{1}{{ux}^{2}}}{ux}}{ux} + -1 \cdot {maxCos}^{2}\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  7. Simplified98.9%

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{{ux}^{4} \cdot \left(\left(-maxCos \cdot maxCos\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(-maxCos, maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  8. Step-by-step derivation
    1. metadata-evalN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{{ux}^{\color{blue}{\left(3 + 1\right)}} \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. pow-plusN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{\left({ux}^{3} \cdot ux\right)} \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{\left({ux}^{3} \cdot ux\right)} \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. cube-multN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\color{blue}{\left(ux \cdot \left(ux \cdot ux\right)\right)} \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    5. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\color{blue}{\left(ux \cdot \left(ux \cdot ux\right)\right)} \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    6. +-lft-identityN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(ux \cdot \color{blue}{\left(0 + ux \cdot ux\right)}\right) \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    7. +-commutativeN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(ux \cdot \color{blue}{\left(ux \cdot ux + 0\right)}\right) \cdot ux\right) \cdot \left(\left(\mathsf{neg}\left(maxCos \cdot maxCos\right)\right) - \frac{\left(maxCos \cdot maxCos\right) \cdot -2 - \frac{\mathsf{fma}\left(\mathsf{neg}\left(maxCos\right), maxCos, \frac{1}{ux \cdot ux}\right)}{ux}}{ux}\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    8. accelerator-lowering-fma.f3298.9

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

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

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

Alternative 3: 98.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \left(uy \cdot 2\right) \cdot \pi\\
t_1 := \sqrt{\mathsf{fma}\left(maxCos \cdot \left(ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right), ux \cdot \left(ux + -1\right), 1\right)}\\
\mathsf{fma}\left(xi, t\_1 \cdot \cos t\_0, ux \cdot \left(maxCos \cdot \left(\left(1 - ux\right) \cdot zi\right)\right)\right) + t\_1 \cdot \left(\sin t\_0 \cdot yi\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. Add Preprocessing
  3. Applied egg-rr98.5%

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

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

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

Alternative 4: 99.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := 2 \cdot \left(uy \cdot \pi\right)\\
t_1 := \sqrt{\mathsf{fma}\left(ux, \left(1 - ux\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\right), 1\right)}\\
\mathsf{fma}\left(\left(1 - ux\right) \cdot \left(ux \cdot maxCos\right), zi, \mathsf{fma}\left(t\_1, xi \cdot \cos t\_0, t\_1 \cdot \left(yi \cdot \sin t\_0\right)\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. Add Preprocessing
  3. Applied egg-rr98.9%

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

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

Alternative 5: 98.8% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_0 := ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\\
t\_0 \cdot zi + \left(\left(\sqrt{1 + t\_0 \cdot \left(ux \cdot \left(maxCos \cdot \left(ux + -1\right)\right)\right)} \cdot \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\right) \cdot xi + yi \cdot \sin \left(uy \cdot \left(2 \cdot \pi\right)\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. Add Preprocessing
  3. Taylor expanded in ux around 0

    \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  4. Step-by-step derivation
    1. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 + \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. sin-lowering-sin.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 + yi \cdot \color{blue}{\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. *-commutativeN/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 + yi \cdot \sin \color{blue}{\left(\left(uy \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. associate-*l*N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 + yi \cdot \sin \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    5. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 + yi \cdot \sin \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    6. *-lowering-*.f32N/A

      \[\leadsto \left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\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 + yi \cdot \sin \left(uy \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    7. PI-lowering-PI.f3298.7

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

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

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

Alternative 6: 97.0% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := uy \cdot \left(2 \cdot \pi\right)\\
t_1 := \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}\\
\mathbf{if}\;uy \cdot 2 \leq 0.07999999821186066:\\
\;\;\;\;\mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \mathsf{fma}\left(t\_1, \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\right), \left(t\_1 \cdot \mathsf{fma}\left(-2, xi \cdot \left(\pi \cdot \pi\right), \left(uy \cdot -1.3333333333333333\right) \cdot \left(yi \cdot \left(\pi \cdot \left(\pi \cdot \pi\right)\right)\right)\right)\right) \cdot \left(uy \cdot uy\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 (*.f32 uy #s(literal 2 binary32)) < 0.0799999982

    1. Initial program 99.2%

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

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

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

    if 0.0799999982 < (*.f32 uy #s(literal 2 binary32))

    1. Initial program 97.6%

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

      \[\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)} \]
    4. Step-by-step derivation
      1. accelerator-lowering-fma.f32N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \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)} \]
      2. cos-lowering-cos.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \color{blue}{\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. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \color{blue}{\left(\left(uy \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
      5. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
      6. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
      7. PI-lowering-PI.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 2\right)\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
      8. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}\right) \]
      9. sin-lowering-sin.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), yi \cdot \color{blue}{\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), yi \cdot \sin \color{blue}{\left(\left(uy \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}\right) \]
      11. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), yi \cdot \sin \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}\right) \]
      12. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), yi \cdot \sin \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}\right) \]
      13. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), yi \cdot \sin \left(uy \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)\right) \]
      14. PI-lowering-PI.f3290.5

        \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\pi \cdot 2\right)\right), yi \cdot \sin \left(uy \cdot \left(\color{blue}{\pi} \cdot 2\right)\right)\right) \]
    5. Simplified90.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.07999999821186066:\\ \;\;\;\;\mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\right), \left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)} \cdot \mathsf{fma}\left(-2, xi \cdot \left(\pi \cdot \pi\right), \left(uy \cdot -1.3333333333333333\right) \cdot \left(yi \cdot \left(\pi \cdot \left(\pi \cdot \pi\right)\right)\right)\right)\right) \cdot \left(uy \cdot uy\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(xi, \cos \left(uy \cdot \left(2 \cdot \pi\right)\right), yi \cdot \sin \left(uy \cdot \left(2 \cdot \pi\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 96.1% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := uy \cdot \left(2 \cdot \pi\right)\\
\mathsf{fma}\left(xi, \cos t\_0, \mathsf{fma}\left(yi, \sin t\_0, maxCos \cdot \left(ux \cdot zi\right)\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. Add Preprocessing
  3. 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)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{\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) + maxCos \cdot \left(ux \cdot zi\right)} \]
    2. associate-+l+N/A

      \[\leadsto \color{blue}{xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + \left(yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)\right)} \]
    3. accelerator-lowering-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \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) + maxCos \cdot \left(ux \cdot zi\right)\right)} \]
    4. cos-lowering-cos.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \color{blue}{\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) + maxCos \cdot \left(ux \cdot zi\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \color{blue}{\left(\left(uy \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)\right) \]
    6. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)\right) \]
    7. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)\right) \]
    8. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)\right) \]
    9. PI-lowering-PI.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 2\right)\right), yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)\right) \]
    10. accelerator-lowering-fma.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \color{blue}{\mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), maxCos \cdot \left(ux \cdot zi\right)\right)}\right) \]
    11. sin-lowering-sin.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \mathsf{fma}\left(yi, \color{blue}{\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}, maxCos \cdot \left(ux \cdot zi\right)\right)\right) \]
    12. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \mathsf{fma}\left(yi, \sin \color{blue}{\left(\left(uy \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}, maxCos \cdot \left(ux \cdot zi\right)\right)\right) \]
    13. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \mathsf{fma}\left(yi, \sin \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}, maxCos \cdot \left(ux \cdot zi\right)\right)\right) \]
    14. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \mathsf{fma}\left(yi, \sin \color{blue}{\left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)}, maxCos \cdot \left(ux \cdot zi\right)\right)\right) \]
    15. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \mathsf{fma}\left(yi, \sin \left(uy \cdot \color{blue}{\left(\mathsf{PI}\left(\right) \cdot 2\right)}\right), maxCos \cdot \left(ux \cdot zi\right)\right)\right) \]
    16. PI-lowering-PI.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \mathsf{fma}\left(yi, \sin \left(uy \cdot \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot 2\right)\right), maxCos \cdot \left(ux \cdot zi\right)\right)\right) \]
    17. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \mathsf{fma}\left(yi, \sin \left(uy \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right), \color{blue}{maxCos \cdot \left(ux \cdot zi\right)}\right)\right) \]
    18. *-lowering-*.f3295.5

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \cos \left(uy \cdot \left(\pi \cdot 2\right)\right), \mathsf{fma}\left(yi, \sin \left(uy \cdot \left(\pi \cdot 2\right)\right), maxCos \cdot \left(ux \cdot zi\right)\right)\right)} \]
  6. Final simplification95.5%

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

Alternative 8: 92.2% accurate, 1.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;zi \cdot \mathsf{fma}\left(t\_0, \mathsf{fma}\left(xi, \frac{\cos \left(\left(uy \cdot 2\right) \cdot \pi\right)}{zi}, 2 \cdot \frac{uy \cdot \left(\pi \cdot yi\right)}{zi}\right), maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy #s(literal 2 binary32)) < 0.0900000036

    1. Initial program 99.2%

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

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

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

    if 0.0900000036 < (*.f32 uy #s(literal 2 binary32))

    1. Initial program 97.6%

      \[\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. Add Preprocessing
    3. Applied egg-rr97.5%

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

      \[\leadsto \color{blue}{zi \cdot \left(maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right) + \left(\frac{xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}{zi} \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)} + \frac{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}{zi} \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)\right)} \]
    5. Step-by-step derivation
      1. *-lowering-*.f32N/A

        \[\leadsto \color{blue}{zi \cdot \left(maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right) + \left(\frac{xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}{zi} \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)} + \frac{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}{zi} \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)\right)} \]
      2. +-commutativeN/A

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

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

      \[\leadsto zi \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(xi, \frac{\cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)}{zi}, \color{blue}{2 \cdot \frac{uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)}{zi}}\right), maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right)\right) \]
    8. Step-by-step derivation
      1. *-lowering-*.f32N/A

        \[\leadsto zi \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(xi, \frac{\cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)}{zi}, \color{blue}{2 \cdot \frac{uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)}{zi}}\right), maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right)\right) \]
      2. /-lowering-/.f32N/A

        \[\leadsto zi \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(xi, \frac{\cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)}{zi}, 2 \cdot \color{blue}{\frac{uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)}{zi}}\right), maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right)\right) \]
      3. *-lowering-*.f32N/A

        \[\leadsto zi \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(xi, \frac{\cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)}{zi}, 2 \cdot \frac{\color{blue}{uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)}}{zi}\right), maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right)\right) \]
      4. *-lowering-*.f32N/A

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

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

      \[\leadsto zi \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(xi, \frac{\cos \left(\left(2 \cdot uy\right) \cdot \pi\right)}{zi}, \color{blue}{2 \cdot \frac{uy \cdot \left(yi \cdot \pi\right)}{zi}}\right), maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.09000000357627869:\\ \;\;\;\;\mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\right), \left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)} \cdot \mathsf{fma}\left(-2, xi \cdot \left(\pi \cdot \pi\right), \left(uy \cdot -1.3333333333333333\right) \cdot \left(yi \cdot \left(\pi \cdot \left(\pi \cdot \pi\right)\right)\right)\right)\right) \cdot \left(uy \cdot uy\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;zi \cdot \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \mathsf{fma}\left(xi, \frac{\cos \left(\left(uy \cdot 2\right) \cdot \pi\right)}{zi}, 2 \cdot \frac{uy \cdot \left(\pi \cdot yi\right)}{zi}\right), maxCos \cdot \left(ux \cdot \left(1 - ux\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 88.3% accurate, 1.8× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(xi, \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot t\_0, ux \cdot \left(maxCos \cdot \left(\left(1 - ux\right) \cdot zi\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy #s(literal 2 binary32)) < 0.18099999

    1. Initial program 99.2%

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

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

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

    if 0.18099999 < (*.f32 uy #s(literal 2 binary32))

    1. Initial program 97.1%

      \[\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. Add Preprocessing
    3. Taylor expanded in yi 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)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
      2. associate-*l*N/A

        \[\leadsto \color{blue}{xi \cdot \left(\cos \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)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) \]
      3. accelerator-lowering-fma.f32N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \cos \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)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)} \]
    5. Simplified57.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(\left(1 - ux\right) \cdot \left(1 - ux\right)\right) \cdot \left(0 - ux \cdot ux\right), 1\right)} \cdot \cos \left(uy \cdot \left(\pi \cdot 2\right)\right), ux \cdot \left(maxCos \cdot \left(\left(1 - ux\right) \cdot zi\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.7%

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

Alternative 10: 88.3% accurate, 1.8× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(xi, t\_0 \cdot \cos \left(\left(uy \cdot 2\right) \cdot \pi\right), maxCos \cdot \left(ux \cdot \left(\left(1 - ux\right) \cdot zi\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy #s(literal 2 binary32)) < 0.180000007

    1. Initial program 99.2%

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

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

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

    if 0.180000007 < (*.f32 uy #s(literal 2 binary32))

    1. Initial program 97.2%

      \[\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. Add Preprocessing
    3. Applied egg-rr97.0%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{\mathsf{fma}\left(\cos \left(2 \cdot \left(uy \cdot \pi\right)\right), \sqrt{\mathsf{fma}\left(ux, \left(0 - \left(1 - ux\right)\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right), 1\right)} \cdot xi, \mathsf{fma}\left(\sqrt{\mathsf{fma}\left(ux, \left(0 - \left(1 - ux\right)\right) \cdot \left(\left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right), 1\right)}, \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot yi, \left(1 - ux\right) \cdot \left(maxCos \cdot \left(ux \cdot zi\right)\right)\right)\right)}}} \]
    4. Taylor expanded in yi 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)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}} \]
    5. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
      2. associate-*l*N/A

        \[\leadsto \color{blue}{xi \cdot \left(\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) \]
      3. accelerator-lowering-fma.f32N/A

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

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

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

Alternative 11: 89.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}\\
\mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \mathsf{fma}\left(t\_0, \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\right), \left(t\_0 \cdot \mathsf{fma}\left(-2, xi \cdot \left(\pi \cdot \pi\right), \left(uy \cdot -1.3333333333333333\right) \cdot \left(yi \cdot \left(\pi \cdot \left(\pi \cdot \pi\right)\right)\right)\right)\right) \cdot \left(uy \cdot uy\right)\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. Add Preprocessing
  3. Taylor expanded in uy around 0

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

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

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

Alternative 12: 85.9% accurate, 2.3× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}\\
\left(ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right) \cdot zi + \mathsf{fma}\left(xi, t\_0, uy \cdot \left(t\_0 \cdot \mathsf{fma}\left(-2, \pi \cdot \left(\pi \cdot \left(uy \cdot xi\right)\right), \pi \cdot \left(2 \cdot yi\right)\right)\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. Add Preprocessing
  3. Taylor expanded in uy around 0

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

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

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

Alternative 13: 85.9% accurate, 2.3× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}\\
\mathsf{fma}\left(xi, t\_0, \mathsf{fma}\left(uy, t\_0 \cdot \mathsf{fma}\left(-2, \pi \cdot \left(\pi \cdot \left(uy \cdot xi\right)\right), \pi \cdot \left(2 \cdot yi\right)\right), ux \cdot \left(maxCos \cdot \left(\left(1 - ux\right) \cdot zi\right)\right)\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. Add Preprocessing
  3. Taylor expanded in uy around 0

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

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

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

Alternative 14: 83.9% accurate, 2.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy #s(literal 2 binary32)) < 0.00700000022

    1. Initial program 99.2%

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

      \[\leadsto \color{blue}{\left(2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left(\color{blue}{\left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
      2. distribute-rgt-outN/A

        \[\leadsto \color{blue}{\sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)} \cdot \left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) + xi\right)} + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
      3. *-lowering-*.f32N/A

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

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

    if 0.00700000022 < (*.f32 uy #s(literal 2 binary32))

    1. Initial program 98.0%

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

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + \left(yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)} \cdot \left(yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) \]
      3. accelerator-lowering-fma.f32N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}, yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)} \]
    5. Simplified55.0%

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

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{yi \cdot \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)} \]
      2. accelerator-lowering-fma.f32N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)} \]
      3. sin-lowering-sin.f32N/A

        \[\leadsto \mathsf{fma}\left(yi, \color{blue}{\sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right) \]
      4. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \color{blue}{\left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right) \]
      5. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \color{blue}{\left(uy \cdot \mathsf{PI}\left(\right)\right)}\right), maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right) \]
      6. PI-lowering-PI.f32N/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \color{blue}{\mathsf{PI}\left(\right)}\right)\right), maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right) \]
      7. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), \color{blue}{\left(maxCos \cdot ux\right) \cdot \left(zi \cdot \left(1 - ux\right)\right)}\right) \]
      8. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), \color{blue}{\left(maxCos \cdot ux\right) \cdot \left(zi \cdot \left(1 - ux\right)\right)}\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), \color{blue}{\left(ux \cdot maxCos\right)} \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) \]
      10. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), \color{blue}{\left(ux \cdot maxCos\right)} \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(\left(1 - ux\right) \cdot zi\right)}\right) \]
      12. *-lowering-*.f32N/A

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot maxCos\right) \cdot \color{blue}{\left(\left(1 - ux\right) \cdot zi\right)}\right) \]
      13. --lowering--.f3255.0

        \[\leadsto \mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \pi\right)\right), \left(ux \cdot maxCos\right) \cdot \left(\color{blue}{\left(1 - ux\right)} \cdot zi\right)\right) \]
    8. Simplified55.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.007000000216066837:\\ \;\;\;\;\left(ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right) \cdot zi + \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)} \cdot \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(yi, \sin \left(2 \cdot \left(uy \cdot \pi\right)\right), \left(ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) \cdot zi\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 84.1% accurate, 2.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 uy #s(literal 2 binary32)) < 0.18099999

    1. Initial program 99.2%

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

      \[\leadsto \color{blue}{\left(2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    4. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left(\color{blue}{\left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
      2. distribute-rgt-outN/A

        \[\leadsto \color{blue}{\sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)} \cdot \left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) + xi\right)} + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
      3. *-lowering-*.f32N/A

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

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

    if 0.18099999 < (*.f32 uy #s(literal 2 binary32))

    1. Initial program 97.1%

      \[\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. Add Preprocessing
    3. Applied egg-rr97.0%

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

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\left(xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}}}} \]
    5. Step-by-step derivation
      1. associate-*l*N/A

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{xi \cdot \left(\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}}} \]
      2. *-lowering-*.f32N/A

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{xi \cdot \left(\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}}} \]
      3. *-lowering-*.f32N/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \color{blue}{\left(\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}}} \]
      4. cos-lowering-cos.f32N/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \left(\color{blue}{\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}} \]
      5. associate-*r*N/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \left(\cos \color{blue}{\left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)} \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}} \]
      6. *-lowering-*.f32N/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \left(\cos \color{blue}{\left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)} \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}} \]
      7. *-lowering-*.f32N/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \left(\cos \left(\color{blue}{\left(2 \cdot uy\right)} \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}} \]
      8. PI-lowering-PI.f32N/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \left(\cos \left(\left(2 \cdot uy\right) \cdot \color{blue}{\mathsf{PI}\left(\right)}\right) \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}\right)}} \]
      9. sqrt-lowering-sqrt.f32N/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \left(\cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \color{blue}{\sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}}\right)}} \]
      10. +-commutativeN/A

        \[\leadsto \frac{1}{\frac{1}{xi \cdot \left(\cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{{maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right) + 1}}\right)}} \]
      11. accelerator-lowering-fma.f32N/A

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

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

      \[\leadsto \color{blue}{xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    8. Step-by-step derivation
      1. *-lowering-*.f32N/A

        \[\leadsto \color{blue}{xi \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
      2. cos-lowering-cos.f32N/A

        \[\leadsto xi \cdot \color{blue}{\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right)} \]
      3. associate-*r*N/A

        \[\leadsto xi \cdot \cos \color{blue}{\left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)} \]
      4. *-lowering-*.f32N/A

        \[\leadsto xi \cdot \cos \color{blue}{\left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)} \]
      5. *-lowering-*.f32N/A

        \[\leadsto xi \cdot \cos \left(\color{blue}{\left(2 \cdot uy\right)} \cdot \mathsf{PI}\left(\right)\right) \]
      6. PI-lowering-PI.f3251.9

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

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

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

Alternative 16: 81.7% accurate, 4.2× speedup?

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

\\
\left(ux \cdot \left(\left(1 - ux\right) \cdot maxCos\right)\right) \cdot zi + \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)} \cdot \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, 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. Add Preprocessing
  3. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{\left(2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right)} + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  4. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \left(\color{blue}{\left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}} + xi \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. distribute-rgt-outN/A

      \[\leadsto \color{blue}{\sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)} \cdot \left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) + xi\right)} + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    3. *-lowering-*.f32N/A

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

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

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

Alternative 17: 81.8% accurate, 4.3× speedup?

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

\\
\mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)} \cdot \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\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. Add Preprocessing
  3. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(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)}\right)} \]
  4. Simplified80.8%

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

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

Alternative 18: 81.7% accurate, 4.5× speedup?

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

\\
\mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\right) \cdot \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(2, ux, -1\right), 1\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. Add Preprocessing
  3. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(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)}\right)} \]
  4. Simplified80.8%

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

    \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{{ux}^{2} \cdot \left(2 \cdot ux - 1\right)}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
  6. Step-by-step derivation
    1. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{{ux}^{2} \cdot \left(2 \cdot ux - 1\right)}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{\left(ux \cdot ux\right)} \cdot \left(2 \cdot ux - 1\right), 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    3. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{\left(ux \cdot ux\right)} \cdot \left(2 \cdot ux - 1\right), 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    4. sub-negN/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \color{blue}{\left(2 \cdot ux + \left(\mathsf{neg}\left(1\right)\right)\right)}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(2 \cdot ux + \color{blue}{-1}\right), 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    6. accelerator-lowering-fma.f3280.6

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

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

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

Alternative 19: 81.7% accurate, 5.0× speedup?

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

\\
\mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \mathsf{fma}\left(\pi \cdot \left(2 \cdot yi\right), uy, xi\right) \cdot \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, 0 - ux \cdot ux, 1\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. Add Preprocessing
  3. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(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)}\right)} \]
  4. Simplified80.8%

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

    \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{-1 \cdot {ux}^{2}}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
  6. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{\mathsf{neg}\left({ux}^{2}\right)}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    2. neg-sub0N/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{0 - {ux}^{2}}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    3. --lowering--.f32N/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{0 - {ux}^{2}}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{fma}\left(maxCos, ux \cdot \left(\left(1 - ux\right) \cdot zi\right), \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, 0 - \color{blue}{ux \cdot ux}, 1\right)} \cdot \mathsf{fma}\left(\left(2 \cdot yi\right) \cdot \mathsf{PI}\left(\right), uy, xi\right)\right) \]
    5. *-lowering-*.f3280.5

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

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

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

Alternative 20: 81.6% accurate, 9.3× speedup?

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

\\
xi + \mathsf{fma}\left(ux \cdot maxCos, \left(1 - ux\right) \cdot zi, \left(uy \cdot 2\right) \cdot \left(\pi \cdot yi\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. Add Preprocessing
  3. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(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)}\right)} \]
  4. Simplified80.8%

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

    \[\leadsto \color{blue}{xi + \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)} \]
  6. Step-by-step derivation
    1. +-lowering-+.f32N/A

      \[\leadsto \color{blue}{xi + \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)} \]
    2. +-commutativeN/A

      \[\leadsto xi + \color{blue}{\left(maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    3. associate-*r*N/A

      \[\leadsto xi + \left(\color{blue}{\left(maxCos \cdot ux\right) \cdot \left(zi \cdot \left(1 - ux\right)\right)} + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    4. accelerator-lowering-fma.f32N/A

      \[\leadsto xi + \color{blue}{\mathsf{fma}\left(maxCos \cdot ux, zi \cdot \left(1 - ux\right), 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right)} \]
    5. *-lowering-*.f32N/A

      \[\leadsto xi + \mathsf{fma}\left(\color{blue}{maxCos \cdot ux}, zi \cdot \left(1 - ux\right), 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto xi + \mathsf{fma}\left(maxCos \cdot ux, \color{blue}{\left(1 - ux\right) \cdot zi}, 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    7. *-lowering-*.f32N/A

      \[\leadsto xi + \mathsf{fma}\left(maxCos \cdot ux, \color{blue}{\left(1 - ux\right) \cdot zi}, 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    8. --lowering--.f32N/A

      \[\leadsto xi + \mathsf{fma}\left(maxCos \cdot ux, \color{blue}{\left(1 - ux\right)} \cdot zi, 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) \]
    9. associate-*r*N/A

      \[\leadsto xi + \mathsf{fma}\left(maxCos \cdot ux, \left(1 - ux\right) \cdot zi, \color{blue}{\left(2 \cdot uy\right) \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)}\right) \]
    10. *-lowering-*.f32N/A

      \[\leadsto xi + \mathsf{fma}\left(maxCos \cdot ux, \left(1 - ux\right) \cdot zi, \color{blue}{\left(2 \cdot uy\right) \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)}\right) \]
    11. *-lowering-*.f32N/A

      \[\leadsto xi + \mathsf{fma}\left(maxCos \cdot ux, \left(1 - ux\right) \cdot zi, \color{blue}{\left(2 \cdot uy\right)} \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \]
    12. *-lowering-*.f32N/A

      \[\leadsto xi + \mathsf{fma}\left(maxCos \cdot ux, \left(1 - ux\right) \cdot zi, \left(2 \cdot uy\right) \cdot \color{blue}{\left(yi \cdot \mathsf{PI}\left(\right)\right)}\right) \]
    13. PI-lowering-PI.f3280.4

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

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

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

Alternative 21: 79.3% accurate, 11.8× speedup?

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

\\
\mathsf{fma}\left(uy \cdot 2, \pi \cdot yi, xi\right) + zi \cdot \left(ux \cdot maxCos\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. Add Preprocessing
  3. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(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)}\right)} \]
  4. Simplified80.8%

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

    \[\leadsto \color{blue}{xi + \left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)\right)} \]
  6. Step-by-step derivation
    1. associate-+r+N/A

      \[\leadsto \color{blue}{\left(xi + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)} \]
    2. +-lowering-+.f32N/A

      \[\leadsto \color{blue}{\left(xi + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)\right) + maxCos \cdot \left(ux \cdot zi\right)} \]
    3. +-commutativeN/A

      \[\leadsto \color{blue}{\left(2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) + xi\right)} + maxCos \cdot \left(ux \cdot zi\right) \]
    4. associate-*r*N/A

      \[\leadsto \left(\color{blue}{\left(2 \cdot uy\right) \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)} + xi\right) + maxCos \cdot \left(ux \cdot zi\right) \]
    5. accelerator-lowering-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot uy, yi \cdot \mathsf{PI}\left(\right), xi\right)} + maxCos \cdot \left(ux \cdot zi\right) \]
    6. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot uy}, yi \cdot \mathsf{PI}\left(\right), xi\right) + maxCos \cdot \left(ux \cdot zi\right) \]
    7. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(2 \cdot uy, \color{blue}{yi \cdot \mathsf{PI}\left(\right)}, xi\right) + maxCos \cdot \left(ux \cdot zi\right) \]
    8. PI-lowering-PI.f32N/A

      \[\leadsto \mathsf{fma}\left(2 \cdot uy, yi \cdot \color{blue}{\mathsf{PI}\left(\right)}, xi\right) + maxCos \cdot \left(ux \cdot zi\right) \]
    9. associate-*r*N/A

      \[\leadsto \mathsf{fma}\left(2 \cdot uy, yi \cdot \mathsf{PI}\left(\right), xi\right) + \color{blue}{\left(maxCos \cdot ux\right) \cdot zi} \]
    10. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(2 \cdot uy, yi \cdot \mathsf{PI}\left(\right), xi\right) + \color{blue}{\left(maxCos \cdot ux\right) \cdot zi} \]
    11. *-lowering-*.f3277.7

      \[\leadsto \mathsf{fma}\left(2 \cdot uy, yi \cdot \pi, xi\right) + \color{blue}{\left(maxCos \cdot ux\right)} \cdot zi \]
  7. Simplified77.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot uy, yi \cdot \pi, xi\right) + \left(maxCos \cdot ux\right) \cdot zi} \]
  8. Final simplification77.7%

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

Alternative 22: 74.8% accurate, 20.8× speedup?

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

\\
\mathsf{fma}\left(uy \cdot 2, \pi \cdot yi, 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. Add Preprocessing
  3. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{2 \cdot \left(\left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{1 - {maxCos}^{2} \cdot \left({ux}^{2} \cdot {\left(1 - ux\right)}^{2}\right)}\right) + \left(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)}\right)} \]
  4. Simplified80.8%

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

    \[\leadsto \color{blue}{xi + 2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right)} \]
  6. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{2 \cdot \left(uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)\right) + xi} \]
    2. associate-*r*N/A

      \[\leadsto \color{blue}{\left(2 \cdot uy\right) \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right)} + xi \]
    3. accelerator-lowering-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot uy, yi \cdot \mathsf{PI}\left(\right), xi\right)} \]
    4. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{2 \cdot uy}, yi \cdot \mathsf{PI}\left(\right), xi\right) \]
    5. *-lowering-*.f32N/A

      \[\leadsto \mathsf{fma}\left(2 \cdot uy, \color{blue}{yi \cdot \mathsf{PI}\left(\right)}, xi\right) \]
    6. PI-lowering-PI.f3272.4

      \[\leadsto \mathsf{fma}\left(2 \cdot uy, yi \cdot \color{blue}{\pi}, xi\right) \]
  7. Simplified72.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot uy, yi \cdot \pi, xi\right)} \]
  8. Final simplification72.4%

    \[\leadsto \mathsf{fma}\left(uy \cdot 2, \pi \cdot yi, xi\right) \]
  9. Add Preprocessing

Alternative 23: 48.8% accurate, 29.4× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(maxCos, ux \cdot 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(maxCos, Float32(ux * zi), xi)
end
\begin{array}{l}

\\
\mathsf{fma}\left(maxCos, ux \cdot 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. Add Preprocessing
  3. Applied egg-rr98.5%

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

    \[\leadsto \frac{1}{\frac{1}{\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(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}}}} \]
  5. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{xi \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)}}} \]
    2. accelerator-lowering-fma.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\mathsf{fma}\left(xi, \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}}} \]
    3. sqrt-lowering-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \color{blue}{\sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    4. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\color{blue}{{maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right) + 1}}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    5. accelerator-lowering-fma.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\color{blue}{\mathsf{fma}\left({maxCos}^{2}, {ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    6. unpow2N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(\color{blue}{maxCos \cdot maxCos}, {ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    7. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(\color{blue}{maxCos \cdot maxCos}, {ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    8. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{{ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)}, 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    9. unpow2N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{\left(ux \cdot ux\right)} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    10. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{\left(ux \cdot ux\right)} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    11. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \color{blue}{\left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)}, 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    12. --lowering--.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\color{blue}{\left(1 - ux\right)} \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    13. sub-negN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \color{blue}{\left(ux + \left(\mathsf{neg}\left(1\right)\right)\right)}\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    14. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + \color{blue}{-1}\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    15. +-lowering-+.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \color{blue}{\left(ux + -1\right)}\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    16. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)}\right)}} \]
  6. Simplified49.4%

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

    \[\leadsto \color{blue}{xi + maxCos \cdot \left(ux \cdot zi\right)} \]
  8. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{maxCos \cdot \left(ux \cdot zi\right) + xi} \]
    2. accelerator-lowering-fma.f32N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(maxCos, ux \cdot zi, xi\right)} \]
    3. *-lowering-*.f3247.2

      \[\leadsto \mathsf{fma}\left(maxCos, \color{blue}{ux \cdot zi}, xi\right) \]
  9. Simplified47.2%

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

Alternative 24: 45.0% accurate, 353.0× speedup?

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

\\
xi
\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. Add Preprocessing
  3. Applied egg-rr98.5%

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

    \[\leadsto \frac{1}{\frac{1}{\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(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}}}} \]
  5. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{xi \cdot \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)} + maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)}}} \]
    2. accelerator-lowering-fma.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\mathsf{fma}\left(xi, \sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}}} \]
    3. sqrt-lowering-sqrt.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \color{blue}{\sqrt{1 + {maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right)}}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    4. +-commutativeN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\color{blue}{{maxCos}^{2} \cdot \left({ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)\right) + 1}}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    5. accelerator-lowering-fma.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\color{blue}{\mathsf{fma}\left({maxCos}^{2}, {ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    6. unpow2N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(\color{blue}{maxCos \cdot maxCos}, {ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    7. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(\color{blue}{maxCos \cdot maxCos}, {ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    8. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{{ux}^{2} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)}, 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    9. unpow2N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{\left(ux \cdot ux\right)} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    10. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \color{blue}{\left(ux \cdot ux\right)} \cdot \left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    11. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \color{blue}{\left(\left(1 - ux\right) \cdot \left(ux - 1\right)\right)}, 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    12. --lowering--.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\color{blue}{\left(1 - ux\right)} \cdot \left(ux - 1\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    13. sub-negN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \color{blue}{\left(ux + \left(\mathsf{neg}\left(1\right)\right)\right)}\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    14. metadata-evalN/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + \color{blue}{-1}\right)\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    15. +-lowering-+.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \color{blue}{\left(ux + -1\right)}\right), 1\right)}, maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)\right)}} \]
    16. *-lowering-*.f32N/A

      \[\leadsto \frac{1}{\frac{1}{\mathsf{fma}\left(xi, \sqrt{\mathsf{fma}\left(maxCos \cdot maxCos, \left(ux \cdot ux\right) \cdot \left(\left(1 - ux\right) \cdot \left(ux + -1\right)\right), 1\right)}, \color{blue}{maxCos \cdot \left(ux \cdot \left(zi \cdot \left(1 - ux\right)\right)\right)}\right)}} \]
  6. Simplified49.4%

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

    \[\leadsto \color{blue}{xi} \]
  8. Step-by-step derivation
    1. Simplified42.7%

      \[\leadsto \color{blue}{xi} \]
    2. Add Preprocessing

    Reproduce

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