UniformSampleCone 2

Percentage Accurate: 98.9% → 99.0%
Time: 14.9s
Alternatives: 1
Speedup: N/A×

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

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

Initial Program: 98.9% accurate, 1.0× speedup?

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

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

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

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

\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
\mathsf{fma}\left(\sin \left(\mathsf{fma}\left(-\pi, uy \cdot 2, \frac{\pi}{2}\right)\right) \cdot \sin \cos^{-1} t\_0, xi, \mathsf{fma}\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right), \sqrt{\left({ux}^{-4} - \mathsf{fma}\left(\frac{maxCos \cdot maxCos}{ux}, -2, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos}{ux} \cdot \frac{maxCos}{ux}\right)\right)\right) \cdot {ux}^{4}} \cdot yi, t\_0 \cdot zi\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 99.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 ux around inf

    \[\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}} - \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. *-commutativeN/A

      \[\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(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right) \cdot \color{blue}{{ux}^{4}}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
    2. lower-*.f32N/A

      \[\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(\frac{1}{{ux}^{4}} - \left(-2 \cdot \frac{{maxCos}^{2}}{ux} + \left(\frac{{maxCos}^{2}}{{ux}^{2}} + {maxCos}^{2}\right)\right)\right) \cdot \color{blue}{{ux}^{4}}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  5. Applied rewrites99.2%

    \[\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({ux}^{-4} - \mathsf{fma}\left(\frac{maxCos \cdot maxCos}{ux}, -2, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos \cdot maxCos}{ux \cdot ux}\right)\right)\right) \cdot {ux}^{4}}}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi \]
  6. Applied rewrites99.2%

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\cos \left(\left(uy \cdot 2\right) \cdot \pi\right)} \cdot \sin \cos^{-1} \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right), xi, \mathsf{fma}\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right), \sqrt{\left({ux}^{-4} - \mathsf{fma}\left(\frac{maxCos \cdot maxCos}{ux}, -2, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos}{ux} \cdot \frac{maxCos}{ux}\right)\right)\right) \cdot {ux}^{4}} \cdot yi, \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)\right) \]
    2. cos-neg-revN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sin \left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right) \cdot \color{blue}{\left(2 \cdot uy\right)}\right)\right) + \frac{\pi}{2}\right) \cdot \sin \cos^{-1} \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right), xi, \mathsf{fma}\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right), \sqrt{\left({ux}^{-4} - \mathsf{fma}\left(\frac{maxCos \cdot maxCos}{ux}, -2, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos}{ux} \cdot \frac{maxCos}{ux}\right)\right)\right) \cdot {ux}^{4}} \cdot yi, \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)\right) \]
    6. distribute-lft-neg-inN/A

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

      \[\leadsto \mathsf{fma}\left(\sin \color{blue}{\left(\mathsf{fma}\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right), 2 \cdot uy, \frac{\pi}{2}\right)\right)} \cdot \sin \cos^{-1} \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right), xi, \mathsf{fma}\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right), \sqrt{\left({ux}^{-4} - \mathsf{fma}\left(\frac{maxCos \cdot maxCos}{ux}, -2, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos}{ux} \cdot \frac{maxCos}{ux}\right)\right)\right) \cdot {ux}^{4}} \cdot yi, \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)\right) \]
    8. lower-neg.f32N/A

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

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

      \[\leadsto \mathsf{fma}\left(\sin \left(\mathsf{fma}\left(-\pi, \color{blue}{uy \cdot 2}, \frac{\pi}{2}\right)\right) \cdot \sin \cos^{-1} \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right), xi, \mathsf{fma}\left(\sin \left(\left(uy \cdot 2\right) \cdot \pi\right), \sqrt{\left({ux}^{-4} - \mathsf{fma}\left(\frac{maxCos \cdot maxCos}{ux}, -2, \mathsf{fma}\left(maxCos, maxCos, \frac{maxCos}{ux} \cdot \frac{maxCos}{ux}\right)\right)\right) \cdot {ux}^{4}} \cdot yi, \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\right)\right) \]
    11. lift-*.f3299.3

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

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

Reproduce

?
herbie shell --seed 2025062 -o reduce:regimes -o reduce:simplify
(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)))