UniformSampleCone, x

Percentage Accurate: 57.7% → 99.0%
Time: 17.9s
Alternatives: 20
Speedup: 3.1×

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 20 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.7% 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, 0.6× speedup?

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

\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left(1 - maxCos\right) \cdot \left({ux}^{2} \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 96.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\\
\mathbf{if}\;t_0 \leq 0.9999995827674866:\\
\;\;\;\;t_0 \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 90.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\\ \mathbf{if}\;t_0 \leq 0.9999849796295166:\\ \;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) - {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (let* ((t_0 (cos (* PI (* uy 2.0)))))
   (if (<= t_0 0.9999849796295166)
     (* t_0 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
     (sqrt
      (-
       (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))
       (* (pow ux 2.0) (* (- 1.0 maxCos) (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = cosf((((float) M_PI) * (uy * 2.0f)));
	float tmp;
	if (t_0 <= 0.9999849796295166f) {
		tmp = t_0 * sqrtf((ux * (2.0f - (2.0f * maxCos))));
	} else {
		tmp = sqrtf(((ux * ((1.0f + (1.0f - maxCos)) - maxCos)) - (powf(ux, 2.0f) * ((1.0f - maxCos) * (1.0f - maxCos)))));
	}
	return tmp;
}
function code(ux, uy, maxCos)
	t_0 = cos(Float32(Float32(pi) * Float32(uy * Float32(2.0))))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.9999849796295166))
		tmp = Float32(t_0 * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))));
	else
		tmp = sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)) - Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(1.0) - maxCos)))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	t_0 = cos((single(pi) * (uy * single(2.0))));
	tmp = single(0.0);
	if (t_0 <= single(0.9999849796295166))
		tmp = t_0 * sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
	else
		tmp = sqrt(((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)) - ((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(1.0) - maxCos)))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\\
\mathbf{if}\;t_0 \leq 0.9999849796295166:\\
\;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) - {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 99.0% accurate, 0.8× speedup?

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

\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 98.2% accurate, 0.8× speedup?

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

\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(-1 + 2 \cdot maxCos\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 97.4% accurate, 0.8× speedup?

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

\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2}}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 91.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := ux \cdot \left(1 - ux\right)\\
\mathbf{if}\;1 - t_0 \cdot t_0 \leq 0.00022000000171829015:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{1 + \left(\left(-1 - ux \cdot \left(ux + -2\right)\right) - maxCos \cdot \left(t_1 + t_1\right)\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 91.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left(1 - ux\right) + ux \cdot maxCos \leq 0.9998000264167786:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux - \left(1 + ux \cdot maxCos\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 90.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0017999999690800905:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 80.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) - {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (sqrt
  (-
   (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))
   (* (pow ux 2.0) (* (- 1.0 maxCos) (- 1.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
	return sqrtf(((ux * ((1.0f + (1.0f - maxCos)) - maxCos)) - (powf(ux, 2.0f) * ((1.0f - maxCos) * (1.0f - maxCos)))));
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt(((ux * ((1.0e0 + (1.0e0 - maxcos)) - maxcos)) - ((ux ** 2.0e0) * ((1.0e0 - maxcos) * (1.0e0 - maxcos)))))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)) - Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(1.0) - maxCos)))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt(((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)) - ((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(1.0) - maxCos)))));
end
\begin{array}{l}

\\
\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) - {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 80.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (sqrt
  (+
   (* ux (- 2.0 (* 2.0 maxCos)))
   (* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0))))))
float code(float ux, float uy, float maxCos) {
	return sqrtf(((ux * (2.0f - (2.0f * maxCos))) + (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f)))));
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt(((ux * (2.0e0 - (2.0e0 * maxcos))) + ((ux ** 2.0e0) * ((1.0e0 - maxcos) * (maxcos + (-1.0e0))))))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) + Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0))))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) + ((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (maxCos + single(-1.0))))));
end
\begin{array}{l}

\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 75.4% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 0.0001500000071246177:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(1 + ux \cdot \left(maxCos + -1\right), -1 + ux \cdot \left(1 - maxCos\right), 1\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 0.0001500000071246177)
   (sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)))
   (sqrt
    (fma (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (* ux (- 1.0 maxCos))) 1.0))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 0.0001500000071246177f) {
		tmp = sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
	} else {
		tmp = sqrtf(fmaf((1.0f + (ux * (maxCos + -1.0f))), (-1.0f + (ux * (1.0f - maxCos))), 1.0f));
	}
	return tmp;
}
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(0.0001500000071246177))
		tmp = sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt(fma(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))), Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos))), Float32(1.0)));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0001500000071246177:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(1 + ux \cdot \left(maxCos + -1\right), -1 + ux \cdot \left(1 - maxCos\right), 1\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 13: 75.4% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(1 + ux \cdot maxCos\right) - ux, -1 + ux \cdot \left(1 - maxCos\right), 1\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 9.999999747378752e-5)
   (sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)))
   (sqrt
    (fma (- (+ 1.0 (* ux maxCos)) ux) (+ -1.0 (* ux (- 1.0 maxCos))) 1.0))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 9.999999747378752e-5f) {
		tmp = sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
	} else {
		tmp = sqrtf(fmaf(((1.0f + (ux * maxCos)) - ux), (-1.0f + (ux * (1.0f - maxCos))), 1.0f));
	}
	return tmp;
}
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(9.999999747378752e-5))
		tmp = sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt(fma(Float32(Float32(Float32(1.0) + Float32(ux * maxCos)) - ux), Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos))), Float32(1.0)));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\left(1 + ux \cdot maxCos\right) - ux, -1 + ux \cdot \left(1 - maxCos\right), 1\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 14: 75.4% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 0.00019999999494757503:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 0.00019999999494757503)
   (sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)))
   (sqrt
    (+
     1.0
     (* (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (* ux (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 0.00019999999494757503f) {
		tmp = sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
	} else {
		tmp = sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (-1.0f + (ux * (1.0f - maxCos))))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 0.00019999999494757503e0) then
        tmp = sqrt((ux * ((1.0e0 + (1.0e0 - maxcos)) - maxcos)))
    else
        tmp = sqrt((1.0e0 + ((1.0e0 + (ux * (maxcos + (-1.0e0)))) * ((-1.0e0) + (ux * (1.0e0 - maxcos))))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(0.00019999999494757503))
		tmp = sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos))))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(0.00019999999494757503))
		tmp = sqrt((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (single(-1.0) + (ux * (single(1.0) - maxCos))))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 15: 74.1% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 0.00039999998989515007:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 0.00039999998989515007)
   (sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)))
   (sqrt (+ 1.0 (* (- 1.0 ux) (+ -1.0 (* ux (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 0.00039999998989515007f) {
		tmp = sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
	} else {
		tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f + (ux * (1.0f - maxCos))))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 0.00039999998989515007e0) then
        tmp = sqrt((ux * ((1.0e0 + (1.0e0 - maxcos)) - maxcos)))
    else
        tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) + (ux * (1.0e0 - maxcos))))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(0.00039999998989515007))
		tmp = sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos))))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(0.00039999998989515007))
		tmp = sqrt((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) + (ux * (single(1.0) - maxCos))))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00039999998989515007:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 16: 74.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 0.00039999998989515007:\\ \;\;\;\;\sqrt{ux \cdot \left(--2\right) - 2 \cdot \left(ux \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 0.00039999998989515007)
   (sqrt (- (* ux (- -2.0)) (* 2.0 (* ux maxCos))))
   (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 0.00039999998989515007f) {
		tmp = sqrtf(((ux * -(-2.0f)) - (2.0f * (ux * maxCos))));
	} else {
		tmp = sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 0.00039999998989515007e0) then
        tmp = sqrt(((ux * -(-2.0e0)) - (2.0e0 * (ux * maxcos))))
    else
        tmp = sqrt((1.0e0 + ((1.0e0 - ux) * (ux + (-1.0e0)))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(0.00039999998989515007))
		tmp = sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(Float32(2.0) * Float32(ux * maxCos))));
	else
		tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux + Float32(-1.0)))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(0.00039999998989515007))
		tmp = sqrt(((ux * -single(-2.0)) - (single(2.0) * (ux * maxCos))));
	else
		tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (ux + single(-1.0)))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00039999998989515007:\\
\;\;\;\;\sqrt{ux \cdot \left(--2\right) - 2 \cdot \left(ux \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 17: 74.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 0.00039999998989515007:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 0.00039999998989515007)
   (sqrt (* ux (- 2.0 (* 2.0 maxCos))))
   (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 0.00039999998989515007f) {
		tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
	} else {
		tmp = sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 0.00039999998989515007e0) then
        tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
    else
        tmp = sqrt((1.0e0 + ((1.0e0 - ux) * (ux + (-1.0e0)))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(0.00039999998989515007))
		tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))));
	else
		tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux + Float32(-1.0)))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(0.00039999998989515007))
		tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
	else
		tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (ux + single(-1.0)))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00039999998989515007:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 18: 74.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ux \leq 0.00039999998989515007:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\ \end{array} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (if (<= ux 0.00039999998989515007)
   (sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)))
   (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
	float tmp;
	if (ux <= 0.00039999998989515007f) {
		tmp = sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
	} else {
		tmp = sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
	}
	return tmp;
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: tmp
    if (ux <= 0.00039999998989515007e0) then
        tmp = sqrt((ux * ((1.0e0 + (1.0e0 - maxcos)) - maxcos)))
    else
        tmp = sqrt((1.0e0 + ((1.0e0 - ux) * (ux + (-1.0e0)))))
    end if
    code = tmp
end function
function code(ux, uy, maxCos)
	tmp = Float32(0.0)
	if (ux <= Float32(0.00039999998989515007))
		tmp = sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux + Float32(-1.0)))));
	end
	return tmp
end
function tmp_2 = code(ux, uy, maxCos)
	tmp = single(0.0);
	if (ux <= single(0.00039999998989515007))
		tmp = sqrt((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)));
	else
		tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (ux + single(-1.0)))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00039999998989515007:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 19: 64.4% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \end{array} \]
(FPCore (ux uy maxCos)
 :precision binary32
 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
	return sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos))));
end
\begin{array}{l}

\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 20: 61.9% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt{ux \cdot \left(--2\right)} \end{array} \]
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- -2.0))))
float code(float ux, float uy, float maxCos) {
	return sqrtf((ux * -(-2.0f)));
}
real(4) function code(ux, uy, maxcos)
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt((ux * -(-2.0e0)))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(ux * Float32(-Float32(-2.0))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((ux * -single(-2.0)));
end
\begin{array}{l}

\\
\sqrt{ux \cdot \left(--2\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

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