UniformSampleCone, x

Percentage Accurate: 57.3% → 99.0%
Time: 15.2s
Alternatives: 5
Speedup: N/A×

Specification

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

\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 5 alternatives:

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

Initial Program: 57.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}

Alternative 1: 99.0% accurate, N/A× speedup?

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

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

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

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right) \cdot \color{blue}{ux}} \]
    3. lower--.f32N/A

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

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) + 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    5. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\left(\left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) \cdot -1 + 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    6. lower-fma.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left(ux \cdot {\left(maxCos - 1\right)}^{2}, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    7. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    8. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    9. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    10. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    11. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - maxCos \cdot 2\right) \cdot ux} \]
    12. lower-*.f3299.1

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - maxCos \cdot 2\right) \cdot ux} \]
  5. Applied rewrites99.1%

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

Alternative 2: 98.8% accurate, N/A× speedup?

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

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

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

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{{ux}^{2} \cdot \left(\left(-2 \cdot \frac{maxCos}{ux} + 2 \cdot \frac{1}{ux}\right) - {\left(1 + -1 \cdot maxCos\right)}^{2}\right)}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

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

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

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

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
  7. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
    3. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
    4. lower-/.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
    6. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
    7. lift-/.f3288.5

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
  8. Applied rewrites88.5%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(maxCos \cdot \left(2 \cdot \frac{1}{maxCos \cdot ux} - 2 \cdot \frac{1}{ux}\right) - {\left(\mathsf{fma}\left(-1, maxCos, 1\right)\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \]
  9. Taylor expanded in ux around inf

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{{ux}^{2} \cdot \color{blue}{\left(\left(-1 \cdot {\left(1 + -1 \cdot maxCos\right)}^{2} + 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}\right)}} \]
  10. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(-1 \cdot {\left(1 + -1 \cdot maxCos\right)}^{2} + 2 \cdot \frac{1}{ux}\right) - \color{blue}{2 \cdot \frac{maxCos}{ux}}\right)} \]
    2. pow2N/A

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

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

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\left(-1 \cdot {\left(1 + -1 \cdot maxCos\right)}^{2} + 2 \cdot \frac{1}{ux}\right) - 2 \cdot \color{blue}{\frac{maxCos}{ux}}\right)} \]
    5. lower-fma.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{\color{blue}{maxCos}}{ux}\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}\right)} \]
    7. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}\right)} \]
    8. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}\right)} \]
    9. lift-/.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}\right)} \]
    10. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}\right)} \]
    11. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{\color{blue}{ux}}\right)} \]
    12. lower-/.f3299.0

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux \cdot ux\right) \cdot \left(\mathsf{fma}\left(-1, {\left(1 + -1 \cdot maxCos\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}\right)} \]
  11. Applied rewrites99.0%

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

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

Alternative 3: 96.1% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 - maxCos \cdot 2\\ t_1 := {t\_0}^{2.5}\\ t_2 := {t\_0}^{1.5}\\ \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.125 \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{t\_2 \cdot t\_2}}, {\left(maxCos - 1\right)}^{4}, \left(-0.0625 \cdot \sqrt{\frac{\frac{1}{ux}}{t\_1 \cdot t\_1}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(-0.5 \cdot \sqrt{\frac{\frac{1}{ux}}{t\_0}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux \cdot t\_0}\right) \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (let* ((t_0 (- 2.0 (* maxCos 2.0))) (t_1 (pow t_0 2.5)) (t_2 (pow t_0 1.5)))
   (*
    (cos (* (* uy 2.0) PI))
    (fma
     (fma
      (fma
       (* -0.125 (sqrt (/ (/ 1.0 (pow ux 3.0)) (* t_2 t_2))))
       (pow (- maxCos 1.0) 4.0)
       (*
        (* -0.0625 (sqrt (/ (/ 1.0 ux) (* t_1 t_1))))
        (pow (- maxCos 1.0) 6.0)))
      (* ux ux)
      (* (* -0.5 (sqrt (/ (/ 1.0 ux) t_0))) (pow (- maxCos 1.0) 2.0)))
     (* ux ux)
     (sqrt (* ux t_0))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = 2.0f - (maxCos * 2.0f);
	float t_1 = powf(t_0, 2.5f);
	float t_2 = powf(t_0, 1.5f);
	return cosf(((uy * 2.0f) * ((float) M_PI))) * fmaf(fmaf(fmaf((-0.125f * sqrtf(((1.0f / powf(ux, 3.0f)) / (t_2 * t_2)))), powf((maxCos - 1.0f), 4.0f), ((-0.0625f * sqrtf(((1.0f / ux) / (t_1 * t_1)))) * powf((maxCos - 1.0f), 6.0f))), (ux * ux), ((-0.5f * sqrtf(((1.0f / ux) / t_0))) * powf((maxCos - 1.0f), 2.0f))), (ux * ux), sqrtf((ux * t_0)));
}
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(2.0) - Float32(maxCos * Float32(2.0)))
	t_1 = t_0 ^ Float32(2.5)
	t_2 = t_0 ^ Float32(1.5)
	return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * fma(fma(fma(Float32(Float32(-0.125) * sqrt(Float32(Float32(Float32(1.0) / (ux ^ Float32(3.0))) / Float32(t_2 * t_2)))), (Float32(maxCos - Float32(1.0)) ^ Float32(4.0)), Float32(Float32(Float32(-0.0625) * sqrt(Float32(Float32(Float32(1.0) / ux) / Float32(t_1 * t_1)))) * (Float32(maxCos - Float32(1.0)) ^ Float32(6.0)))), Float32(ux * ux), Float32(Float32(Float32(-0.5) * sqrt(Float32(Float32(Float32(1.0) / ux) / t_0))) * (Float32(maxCos - Float32(1.0)) ^ Float32(2.0)))), Float32(ux * ux), sqrt(Float32(ux * t_0))))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 - maxCos \cdot 2\\
t_1 := {t\_0}^{2.5}\\
t_2 := {t\_0}^{1.5}\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.125 \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{t\_2 \cdot t\_2}}, {\left(maxCos - 1\right)}^{4}, \left(-0.0625 \cdot \sqrt{\frac{\frac{1}{ux}}{t\_1 \cdot t\_1}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(-0.5 \cdot \sqrt{\frac{\frac{1}{ux}}{t\_0}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux \cdot t\_0}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 57.3%

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

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \color{blue}{\left(\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} + {ux}^{2} \cdot \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{ux \cdot \left(2 - 2 \cdot maxCos\right)}} \cdot {\left(maxCos - 1\right)}^{2}\right) + {ux}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\sqrt{\frac{1}{{ux}^{3} \cdot {\left(2 - 2 \cdot maxCos\right)}^{3}}} \cdot {\left(maxCos - 1\right)}^{4}\right) + \frac{-1}{16} \cdot \left(\sqrt{\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}} \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)} \]
  4. Applied rewrites97.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.125 \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{1.5} \cdot {\left(2 - maxCos \cdot 2\right)}^{1.5}}}, {\left(maxCos - 1\right)}^{4}, \left(-0.0625 \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{2.5} \cdot {\left(2 - maxCos \cdot 2\right)}^{2.5}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(-0.5 \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux} \cdot \sqrt{2 - maxCos \cdot 2}\right)} \]
  5. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{8} \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}}}}, {\left(maxCos - 1\right)}^{4}, \left(\frac{-1}{16} \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(\frac{-1}{2} \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux} \cdot \sqrt{2 - maxCos \cdot 2}\right) \]
    2. lift-sqrt.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{8} \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}}}}, {\left(maxCos - 1\right)}^{4}, \left(\frac{-1}{16} \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(\frac{-1}{2} \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux} \cdot \sqrt{2 - maxCos \cdot 2}\right) \]
    3. lift-sqrt.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{8} \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}}}}, {\left(maxCos - 1\right)}^{4}, \left(\frac{-1}{16} \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(\frac{-1}{2} \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux} \cdot \sqrt{2 - maxCos \cdot 2}\right) \]
    4. sqrt-unprodN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{8} \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}}}}, {\left(maxCos - 1\right)}^{4}, \left(\frac{-1}{16} \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(\frac{-1}{2} \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux \cdot \left(2 - maxCos \cdot 2\right)}\right) \]
    5. lower-sqrt.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{8} \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{3}{2}}}}, {\left(maxCos - 1\right)}^{4}, \left(\frac{-1}{16} \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}} \cdot {\left(2 - maxCos \cdot 2\right)}^{\frac{5}{2}}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(\frac{-1}{2} \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux \cdot \left(2 - maxCos \cdot 2\right)}\right) \]
    6. lower-*.f3297.4

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.125 \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{1.5} \cdot {\left(2 - maxCos \cdot 2\right)}^{1.5}}}, {\left(maxCos - 1\right)}^{4}, \left(-0.0625 \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{2.5} \cdot {\left(2 - maxCos \cdot 2\right)}^{2.5}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(-0.5 \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux \cdot \left(2 - maxCos \cdot 2\right)}\right) \]
  6. Applied rewrites97.4%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.125 \cdot \sqrt{\frac{\frac{1}{{ux}^{3}}}{{\left(2 - maxCos \cdot 2\right)}^{1.5} \cdot {\left(2 - maxCos \cdot 2\right)}^{1.5}}}, {\left(maxCos - 1\right)}^{4}, \left(-0.0625 \cdot \sqrt{\frac{\frac{1}{ux}}{{\left(2 - maxCos \cdot 2\right)}^{2.5} \cdot {\left(2 - maxCos \cdot 2\right)}^{2.5}}}\right) \cdot {\left(maxCos - 1\right)}^{6}\right), ux \cdot ux, \left(-0.5 \cdot \sqrt{\frac{\frac{1}{ux}}{2 - maxCos \cdot 2}}\right) \cdot {\left(maxCos - 1\right)}^{2}\right), ux \cdot ux, \sqrt{ux \cdot \left(2 - maxCos \cdot 2\right)}\right) \]
  7. Add Preprocessing

Alternative 4: 96.0% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 - 2 \cdot maxCos\\ t_1 := ux \cdot t\_0\\ t_2 := {t\_1}^{0.5}\\ t_3 := \sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right)\\ \mathsf{fma}\left(t\_2, \sin \left(uy \cdot \mathsf{fma}\left(0.5, \frac{\pi}{uy}, 2 \cdot \pi\right)\right), \left(ux \cdot ux\right) \cdot \left(-0.5 \cdot \left(\frac{1}{t\_2} \cdot \left(t\_3 \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(-0.125, {\left(\frac{1}{{t\_1}^{3}}\right)}^{0.5} \cdot \left(t\_3 \cdot {\left(maxCos - 1\right)}^{4}\right), -0.0625 \cdot \left({\left(\frac{1}{ux \cdot {t\_0}^{5}}\right)}^{0.5} \cdot \left(t\_3 \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (let* ((t_0 (- 2.0 (* 2.0 maxCos)))
        (t_1 (* ux t_0))
        (t_2 (pow t_1 0.5))
        (t_3 (sin (fma 2.0 (* uy PI) (/ PI 2.0)))))
   (fma
    t_2
    (sin (* uy (fma 0.5 (/ PI uy) (* 2.0 PI))))
    (*
     (* ux ux)
     (+
      (* -0.5 (* (/ 1.0 t_2) (* t_3 (pow (- maxCos 1.0) 2.0))))
      (*
       (* ux ux)
       (fma
        -0.125
        (* (pow (/ 1.0 (pow t_1 3.0)) 0.5) (* t_3 (pow (- maxCos 1.0) 4.0)))
        (*
         -0.0625
         (*
          (pow (/ 1.0 (* ux (pow t_0 5.0))) 0.5)
          (* t_3 (pow (- maxCos 1.0) 6.0)))))))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = 2.0f - (2.0f * maxCos);
	float t_1 = ux * t_0;
	float t_2 = powf(t_1, 0.5f);
	float t_3 = sinf(fmaf(2.0f, (uy * ((float) M_PI)), (((float) M_PI) / 2.0f)));
	return fmaf(t_2, sinf((uy * fmaf(0.5f, (((float) M_PI) / uy), (2.0f * ((float) M_PI))))), ((ux * ux) * ((-0.5f * ((1.0f / t_2) * (t_3 * powf((maxCos - 1.0f), 2.0f)))) + ((ux * ux) * fmaf(-0.125f, (powf((1.0f / powf(t_1, 3.0f)), 0.5f) * (t_3 * powf((maxCos - 1.0f), 4.0f))), (-0.0625f * (powf((1.0f / (ux * powf(t_0, 5.0f))), 0.5f) * (t_3 * powf((maxCos - 1.0f), 6.0f)))))))));
}
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))
	t_1 = Float32(ux * t_0)
	t_2 = t_1 ^ Float32(0.5)
	t_3 = sin(fma(Float32(2.0), Float32(uy * Float32(pi)), Float32(Float32(pi) / Float32(2.0))))
	return fma(t_2, sin(Float32(uy * fma(Float32(0.5), Float32(Float32(pi) / uy), Float32(Float32(2.0) * Float32(pi))))), Float32(Float32(ux * ux) * Float32(Float32(Float32(-0.5) * Float32(Float32(Float32(1.0) / t_2) * Float32(t_3 * (Float32(maxCos - Float32(1.0)) ^ Float32(2.0))))) + Float32(Float32(ux * ux) * fma(Float32(-0.125), Float32((Float32(Float32(1.0) / (t_1 ^ Float32(3.0))) ^ Float32(0.5)) * Float32(t_3 * (Float32(maxCos - Float32(1.0)) ^ Float32(4.0)))), Float32(Float32(-0.0625) * Float32((Float32(Float32(1.0) / Float32(ux * (t_0 ^ Float32(5.0)))) ^ Float32(0.5)) * Float32(t_3 * (Float32(maxCos - Float32(1.0)) ^ Float32(6.0))))))))))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 - 2 \cdot maxCos\\
t_1 := ux \cdot t\_0\\
t_2 := {t\_1}^{0.5}\\
t_3 := \sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right)\\
\mathsf{fma}\left(t\_2, \sin \left(uy \cdot \mathsf{fma}\left(0.5, \frac{\pi}{uy}, 2 \cdot \pi\right)\right), \left(ux \cdot ux\right) \cdot \left(-0.5 \cdot \left(\frac{1}{t\_2} \cdot \left(t\_3 \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(-0.125, {\left(\frac{1}{{t\_1}^{3}}\right)}^{0.5} \cdot \left(t\_3 \cdot {\left(maxCos - 1\right)}^{4}\right), -0.0625 \cdot \left({\left(\frac{1}{ux \cdot {t\_0}^{5}}\right)}^{0.5} \cdot \left(t\_3 \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 57.3%

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

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

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

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right) \cdot \color{blue}{ux}} \]
    3. lower--.f32N/A

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

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) + 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    5. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\left(\left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) \cdot -1 + 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    6. lower-fma.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left(ux \cdot {\left(maxCos - 1\right)}^{2}, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    7. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    8. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    9. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    10. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - 2 \cdot maxCos\right) \cdot ux} \]
    11. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - maxCos \cdot 2\right) \cdot ux} \]
    12. lower-*.f3299.1

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(\mathsf{fma}\left({\left(maxCos - 1\right)}^{2} \cdot ux, -1, 2\right) - maxCos \cdot 2\right) \cdot ux} \]
  5. Applied rewrites99.1%

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

    \[\leadsto \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \cdot \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) + {ux}^{2} \cdot \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{ux \cdot \left(2 - 2 \cdot maxCos\right)}} \cdot \left(\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + {ux}^{2} \cdot \left(\frac{-1}{8} \cdot \left(\sqrt{\frac{1}{{ux}^{3} \cdot {\left(2 - 2 \cdot maxCos\right)}^{3}}} \cdot \left(\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right)\right) + \frac{-1}{16} \cdot \left(\sqrt{\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}} \cdot \left(\cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)} \]
  7. Applied rewrites97.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{0.5}, \sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right), \left(ux \cdot ux\right) \cdot \left(-0.5 \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{0.5}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(-0.125, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{0.5} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), -0.0625 \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{0.5} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right)} \]
  8. Taylor expanded in uy around inf

    \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}, \sin \left(uy \cdot \left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy} + 2 \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot ux\right) \cdot \left(\frac{-1}{2} \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(\frac{-1}{8}, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), \frac{-1}{16} \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
  9. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}, \sin \left(uy \cdot \left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy} + 2 \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot ux\right) \cdot \left(\frac{-1}{2} \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(\frac{-1}{8}, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), \frac{-1}{16} \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
    2. lower-fma.f32N/A

      \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}, \sin \left(uy \cdot \mathsf{fma}\left(\frac{1}{2}, \frac{\mathsf{PI}\left(\right)}{uy}, 2 \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot ux\right) \cdot \left(\frac{-1}{2} \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(\frac{-1}{8}, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), \frac{-1}{16} \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
    3. lower-/.f32N/A

      \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}, \sin \left(uy \cdot \mathsf{fma}\left(\frac{1}{2}, \frac{\mathsf{PI}\left(\right)}{uy}, 2 \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot ux\right) \cdot \left(\frac{-1}{2} \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(\frac{-1}{8}, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), \frac{-1}{16} \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
    4. lift-PI.f32N/A

      \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}, \sin \left(uy \cdot \mathsf{fma}\left(\frac{1}{2}, \frac{\pi}{uy}, 2 \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot ux\right) \cdot \left(\frac{-1}{2} \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(\frac{-1}{8}, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), \frac{-1}{16} \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
    5. lower-*.f32N/A

      \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}, \sin \left(uy \cdot \mathsf{fma}\left(\frac{1}{2}, \frac{\pi}{uy}, 2 \cdot \mathsf{PI}\left(\right)\right)\right), \left(ux \cdot ux\right) \cdot \left(\frac{-1}{2} \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{\frac{1}{2}}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(\frac{-1}{8}, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), \frac{-1}{16} \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{\frac{1}{2}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
    6. lift-PI.f3297.2

      \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{0.5}, \sin \left(uy \cdot \mathsf{fma}\left(0.5, \frac{\pi}{uy}, 2 \cdot \pi\right)\right), \left(ux \cdot ux\right) \cdot \left(-0.5 \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{0.5}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(-0.125, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{0.5} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), -0.0625 \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{0.5} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
  10. Applied rewrites97.2%

    \[\leadsto \mathsf{fma}\left({\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{0.5}, \sin \left(uy \cdot \mathsf{fma}\left(0.5, \frac{\pi}{uy}, 2 \cdot \pi\right)\right), \left(ux \cdot ux\right) \cdot \left(-0.5 \cdot \left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{0.5}} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{2}\right)\right) + \left(ux \cdot ux\right) \cdot \mathsf{fma}\left(-0.125, {\left(\frac{1}{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{3}}\right)}^{0.5} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{4}\right), -0.0625 \cdot \left({\left(\frac{1}{ux \cdot {\left(2 - 2 \cdot maxCos\right)}^{5}}\right)}^{0.5} \cdot \left(\sin \left(\mathsf{fma}\left(2, uy \cdot \pi, \frac{\pi}{2}\right)\right) \cdot {\left(maxCos - 1\right)}^{6}\right)\right)\right)\right)\right) \]
  11. Add Preprocessing

Alternative 5: 76.7% accurate, N/A× speedup?

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

\\
\sin \left(\mathsf{fma}\left(\pi \cdot uy, 2, \frac{\pi}{2}\right)\right) \cdot \left(\sqrt{ux} \cdot \sqrt{2 - maxCos \cdot 2}\right)
\end{array}
Derivation
  1. Initial program 57.3%

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

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

      \[\leadsto \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}} \]
    2. lower-*.f32N/A

      \[\leadsto \cos \left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \color{blue}{\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}} \]
  5. Applied rewrites78.4%

    \[\leadsto \color{blue}{\sin \left(\mathsf{fma}\left(\pi \cdot uy, 2, \frac{\pi}{2}\right)\right) \cdot \left(\sqrt{ux} \cdot \sqrt{2 - maxCos \cdot 2}\right)} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2025065 
(FPCore (ux uy maxCos)
  :name "UniformSampleCone, x"
  :precision binary32
  :pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
  (* (cos (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))