UniformSampleCone, y

Percentage Accurate: 57.8% → 98.2%
Time: 15.8s
Alternatives: 12
Speedup: 5.0×

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\\ \sin \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))))
   (* (sin (* (* 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 sinf(((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(sin(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 = sin(((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\\
\sin \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 12 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.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ \sin \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))))
   (* (sin (* (* 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 sinf(((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(sin(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 = sin(((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\\
\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}

Alternative 1: 98.2% accurate, 0.7× speedup?

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

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

    \[\sin \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 \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\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. lower-*.f32N/A

      \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\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)}} \]
    2. cancel-sign-sub-invN/A

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

      \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{ux \cdot \left(\color{blue}{\left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) + 2\right)} + \left(\mathsf{neg}\left(2\right)\right) \cdot maxCos\right)} \]
    4. metadata-evalN/A

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

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

      \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{ux \cdot \left(\color{blue}{\left(\mathsf{neg}\left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right)} + \left(2 + -2 \cdot maxCos\right)\right)} \]
    7. distribute-rgt-neg-inN/A

      \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{ux \cdot \left(\color{blue}{ux \cdot \left(\mathsf{neg}\left({\left(maxCos - 1\right)}^{2}\right)\right)} + \left(2 + -2 \cdot maxCos\right)\right)} \]
    8. lower-fma.f32N/A

      \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{ux \cdot \color{blue}{\mathsf{fma}\left(ux, \mathsf{neg}\left({\left(maxCos - 1\right)}^{2}\right), 2 + -2 \cdot maxCos\right)}} \]
  5. Applied rewrites98.3%

    \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \mathsf{fma}\left(ux, \left(maxCos + -1\right) \cdot \left(1 - maxCos\right), \mathsf{fma}\left(maxCos, -2, 2\right)\right)}} \]
  6. Step-by-step derivation
    1. Applied rewrites98.3%

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

      \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\frac{\left(\mathsf{fma}\left(ux, \left(maxCos + -1\right) \cdot \left(1 - maxCos\right), \mathsf{fma}\left(maxCos, -2, 2\right)\right) \cdot \left(-1 \cdot \left(ux \cdot \left(-2 \cdot \frac{maxCos}{ux} + \left(-1 \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right) + 2 \cdot \frac{1}{ux}\right)\right)\right)\right)\right) \cdot ux}{\left(maxCos + \color{blue}{-1}\right) \cdot \left(\left(1 - maxCos\right) \cdot ux\right) - \mathsf{fma}\left(maxCos, -2, 2\right)}} \]
    3. Step-by-step derivation
      1. Applied rewrites98.3%

        \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\frac{\left(\mathsf{fma}\left(ux, \left(maxCos + -1\right) \cdot \left(1 - maxCos\right), \mathsf{fma}\left(maxCos, -2, 2\right)\right) \cdot \left(\left(-ux\right) \cdot \mathsf{fma}\left(1 - maxCos, 1 - maxCos, \frac{\mathsf{fma}\left(maxCos, -2, 2\right)}{ux}\right)\right)\right) \cdot ux}{\left(maxCos + \color{blue}{-1}\right) \cdot \left(\left(1 - maxCos\right) \cdot ux\right) - \mathsf{fma}\left(maxCos, -2, 2\right)}} \]
      2. Final simplification98.3%

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

      Alternative 2: 98.2% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\frac{1}{\frac{1}{ux \cdot \left(\left(\left(1 - \left(maxCos + -1\right)\right) + \left(maxCos + -1\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right) - maxCos\right)}}} \end{array} \]
      (FPCore (ux uy maxCos)
       :precision binary32
       (*
        (sin (* (* uy 2.0) PI))
        (sqrt
         (/
          1.0
          (/
           1.0
           (*
            ux
            (-
             (+ (- 1.0 (+ maxCos -1.0)) (* (+ maxCos -1.0) (* ux (- 1.0 maxCos))))
             maxCos)))))))
      float code(float ux, float uy, float maxCos) {
      	return sinf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f / (1.0f / (ux * (((1.0f - (maxCos + -1.0f)) + ((maxCos + -1.0f) * (ux * (1.0f - maxCos)))) - maxCos)))));
      }
      
      function code(ux, uy, maxCos)
      	return Float32(sin(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) / Float32(Float32(1.0) / Float32(ux * Float32(Float32(Float32(Float32(1.0) - Float32(maxCos + Float32(-1.0))) + Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * Float32(Float32(1.0) - maxCos)))) - maxCos))))))
      end
      
      function tmp = code(ux, uy, maxCos)
      	tmp = sin(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) / (single(1.0) / (ux * (((single(1.0) - (maxCos + single(-1.0))) + ((maxCos + single(-1.0)) * (ux * (single(1.0) - maxCos)))) - maxCos)))));
      end
      
      \begin{array}{l}
      
      \\
      \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\frac{1}{\frac{1}{ux \cdot \left(\left(\left(1 - \left(maxCos + -1\right)\right) + \left(maxCos + -1\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right) - maxCos\right)}}}
      \end{array}
      
      Derivation
      1. Initial program 57.8%

        \[\sin \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. Step-by-step derivation
        1. lift--.f32N/A

          \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}} \]
        2. flip3--N/A

          \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\color{blue}{\frac{{1}^{3} - {\left(\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)}^{3}}{1 \cdot 1 + \left(\left(\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) \cdot \left(\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) + 1 \cdot \left(\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)\right)}}} \]
        3. clear-numN/A

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

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

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

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

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

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

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

        \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\frac{1}{\frac{1}{ux \cdot \left(\left(\left(1 - \left(maxCos + -1\right)\right) + \left(maxCos + -1\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right) - maxCos\right)}}} \]
      9. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2024230 
      (FPCore (ux uy maxCos)
        :name "UniformSampleCone, y"
        :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)))
        (* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))