?

Average Error: 12.4 → 0.5
Time: 1.5min
Precision: binary64
Cost: 26816

?

\[\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)\]
\[\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)} \]
\[\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux - {\left(ux - maxCos \cdot ux\right)}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]
(FPCore (ux uy maxCos)
 :precision binary64
 (*
  (sin (* (* uy 2.0) PI))
  (sqrt
   (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))
(FPCore (ux uy maxCos)
 :precision binary64
 (*
  (sqrt (- (* (+ (* -2.0 maxCos) 2.0) ux) (pow (- ux (* maxCos ux)) 2.0)))
  (sin (* 2.0 (* uy PI)))))
double code(double ux, double uy, double maxCos) {
	return sin(((uy * 2.0) * ((double) M_PI))) * sqrt((1.0 - (((1.0 - ux) + (ux * maxCos)) * ((1.0 - ux) + (ux * maxCos)))));
}
double code(double ux, double uy, double maxCos) {
	return sqrt(((((-2.0 * maxCos) + 2.0) * ux) - pow((ux - (maxCos * ux)), 2.0))) * sin((2.0 * (uy * ((double) M_PI))));
}
public static double code(double ux, double uy, double maxCos) {
	return Math.sin(((uy * 2.0) * Math.PI)) * Math.sqrt((1.0 - (((1.0 - ux) + (ux * maxCos)) * ((1.0 - ux) + (ux * maxCos)))));
}
public static double code(double ux, double uy, double maxCos) {
	return Math.sqrt(((((-2.0 * maxCos) + 2.0) * ux) - Math.pow((ux - (maxCos * ux)), 2.0))) * Math.sin((2.0 * (uy * Math.PI)));
}
def code(ux, uy, maxCos):
	return math.sin(((uy * 2.0) * math.pi)) * math.sqrt((1.0 - (((1.0 - ux) + (ux * maxCos)) * ((1.0 - ux) + (ux * maxCos)))))
def code(ux, uy, maxCos):
	return math.sqrt(((((-2.0 * maxCos) + 2.0) * ux) - math.pow((ux - (maxCos * ux)), 2.0))) * math.sin((2.0 * (uy * math.pi)))
function code(ux, uy, maxCos)
	return Float64(sin(Float64(Float64(uy * 2.0) * pi)) * sqrt(Float64(1.0 - Float64(Float64(Float64(1.0 - ux) + Float64(ux * maxCos)) * Float64(Float64(1.0 - ux) + Float64(ux * maxCos))))))
end
function code(ux, uy, maxCos)
	return Float64(sqrt(Float64(Float64(Float64(Float64(-2.0 * maxCos) + 2.0) * ux) - (Float64(ux - Float64(maxCos * ux)) ^ 2.0))) * sin(Float64(2.0 * Float64(uy * pi))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sin(((uy * 2.0) * pi)) * sqrt((1.0 - (((1.0 - ux) + (ux * maxCos)) * ((1.0 - ux) + (ux * maxCos)))));
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt(((((-2.0 * maxCos) + 2.0) * ux) - ((ux - (maxCos * ux)) ^ 2.0))) * sin((2.0 * (uy * pi)));
end
code[ux_, uy_, maxCos_] := N[(N[Sin[N[(N[(uy * 2.0), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(1.0 - N[(N[(N[(1.0 - ux), $MachinePrecision] + N[(ux * maxCos), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 - ux), $MachinePrecision] + N[(ux * maxCos), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[ux_, uy_, maxCos_] := N[(N[Sqrt[N[(N[(N[(N[(-2.0 * maxCos), $MachinePrecision] + 2.0), $MachinePrecision] * ux), $MachinePrecision] - N[Power[N[(ux - N[(maxCos * ux), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(2.0 * N[(uy * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\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)}
\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux - {\left(ux - maxCos \cdot ux\right)}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 12.4

    \[\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. Taylor expanded in ux around 0 0.5

    \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{\left(2 - 2 \cdot maxCos\right) \cdot ux + -1 \cdot \left({ux}^{2} \cdot {\left(maxCos - 1\right)}^{2}\right)}} \]
  3. Simplified0.5

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

    \[\leadsto \color{blue}{\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux - {\left(ux - maxCos \cdot ux\right)}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)} \]

Alternatives

Alternative 1
Error1.0
Cost21124
\[\begin{array}{l} t_0 := 1 - \left(ux - maxCos \cdot ux\right)\\ t_1 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;maxCos \leq 8.2 \cdot 10^{-12}:\\ \;\;\;\;t_1 \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \sqrt{1 - \left(t_0 + t_0 \cdot \left(ux \cdot \left(maxCos + -1\right)\right)\right)}\\ \end{array} \]
Alternative 2
Error1.1
Cost20868
\[\begin{array}{l} t_0 := 1 - \left(ux - maxCos \cdot ux\right)\\ t_1 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;maxCos \leq 8.8 \cdot 10^{-12}:\\ \;\;\;\;t_1 \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \sqrt{\left(t_0 - 1\right) \cdot \left(-1 - t_0\right)}\\ \end{array} \]
Alternative 3
Error1.1
Cost20740
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ t_1 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;maxCos \leq 6.8 \cdot 10^{-12}:\\ \;\;\;\;t_1 \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \sqrt{1 - t_0 \cdot t_0}\\ \end{array} \]
Alternative 4
Error1.1
Cost20740
\[\begin{array}{l} t_0 := 1 - \left(ux - maxCos \cdot ux\right)\\ t_1 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;maxCos \leq 1.32 \cdot 10^{-11}:\\ \;\;\;\;t_1 \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \sqrt{1 - t_0 \cdot t_0}\\ \end{array} \]
Alternative 5
Error21.3
Cost19972
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.00075:\\ \;\;\;\;\left(\left(2 \cdot uy\right) \cdot \pi\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux}\\ \end{array} \]
Alternative 6
Error1.8
Cost19840
\[\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)} \]
Alternative 7
Error24.9
Cost13440
\[\left(\left(2 \cdot uy\right) \cdot \pi\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux} \]
Alternative 8
Error39.1
Cost13312
\[\left(2 \cdot uy\right) \cdot \left(\sqrt{ux \cdot 2} \cdot \pi\right) \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (ux uy maxCos)
  :name "UniformSampleCone, y"
  :precision binary64
  :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)))))))