?

Average Error: 13.5 → 0.4
Time: 20.5s
Precision: binary32
Cost: 20068

?

\[\left(\left(cosTheta_i > 0.9999 \land cosTheta_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
\[\begin{array}{l} t_0 := \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ t_1 := \log \left(1 - u1\right)\\ \mathbf{if}\;1 - u1 \leq 0.9549999833106995:\\ \;\;\;\;\sqrt{-\left(\frac{t_1}{-2} - t_1 \cdot -1.5\right)} \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(\left(-u1\right) + \left(-0.3333333333333333 \cdot {u1}^{3} + \left(-0.5 \cdot {u1}^{2} + -0.25 \cdot {u1}^{4}\right)\right)\right)} \cdot t_0\\ \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (cos (* (* 2.0 PI) u2))) (t_1 (log (- 1.0 u1))))
   (if (<= (- 1.0 u1) 0.9549999833106995)
     (* (sqrt (- (- (/ t_1 -2.0) (* t_1 -1.5)))) t_0)
     (*
      (sqrt
       (-
        (+
         (- u1)
         (+
          (* -0.3333333333333333 (pow u1 3.0))
          (+ (* -0.5 (pow u1 2.0)) (* -0.25 (pow u1 4.0)))))))
      t_0))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-logf((1.0f - u1))) * cosf(((2.0f * ((float) M_PI)) * u2));
}
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = cosf(((2.0f * ((float) M_PI)) * u2));
	float t_1 = logf((1.0f - u1));
	float tmp;
	if ((1.0f - u1) <= 0.9549999833106995f) {
		tmp = sqrtf(-((t_1 / -2.0f) - (t_1 * -1.5f))) * t_0;
	} else {
		tmp = sqrtf(-(-u1 + ((-0.3333333333333333f * powf(u1, 3.0f)) + ((-0.5f * powf(u1, 2.0f)) + (-0.25f * powf(u1, 4.0f)))))) * t_0;
	}
	return tmp;
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(-log(Float32(Float32(1.0) - u1)))) * cos(Float32(Float32(Float32(2.0) * Float32(pi)) * u2)))
end
function code(cosTheta_i, u1, u2)
	t_0 = cos(Float32(Float32(Float32(2.0) * Float32(pi)) * u2))
	t_1 = log(Float32(Float32(1.0) - u1))
	tmp = Float32(0.0)
	if (Float32(Float32(1.0) - u1) <= Float32(0.9549999833106995))
		tmp = Float32(sqrt(Float32(-Float32(Float32(t_1 / Float32(-2.0)) - Float32(t_1 * Float32(-1.5))))) * t_0);
	else
		tmp = Float32(sqrt(Float32(-Float32(Float32(-u1) + Float32(Float32(Float32(-0.3333333333333333) * (u1 ^ Float32(3.0))) + Float32(Float32(Float32(-0.5) * (u1 ^ Float32(2.0))) + Float32(Float32(-0.25) * (u1 ^ Float32(4.0)))))))) * t_0);
	end
	return tmp
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(-log((single(1.0) - u1))) * cos(((single(2.0) * single(pi)) * u2));
end
function tmp_2 = code(cosTheta_i, u1, u2)
	t_0 = cos(((single(2.0) * single(pi)) * u2));
	t_1 = log((single(1.0) - u1));
	tmp = single(0.0);
	if ((single(1.0) - u1) <= single(0.9549999833106995))
		tmp = sqrt(-((t_1 / single(-2.0)) - (t_1 * single(-1.5)))) * t_0;
	else
		tmp = sqrt(-(-u1 + ((single(-0.3333333333333333) * (u1 ^ single(3.0))) + ((single(-0.5) * (u1 ^ single(2.0))) + (single(-0.25) * (u1 ^ single(4.0))))))) * t_0;
	end
	tmp_2 = tmp;
end
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\
t_1 := \log \left(1 - u1\right)\\
\mathbf{if}\;1 - u1 \leq 0.9549999833106995:\\
\;\;\;\;\sqrt{-\left(\frac{t_1}{-2} - t_1 \cdot -1.5\right)} \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{-\left(\left(-u1\right) + \left(-0.3333333333333333 \cdot {u1}^{3} + \left(-0.5 \cdot {u1}^{2} + -0.25 \cdot {u1}^{4}\right)\right)\right)} \cdot t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (-.f32 1 u1) < 0.954999983

    1. Initial program 0.7

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Applied egg-rr0.8

      \[\leadsto \sqrt{-\color{blue}{\left(\frac{\log \left(1 - u1\right)}{-2} - -3 \cdot \frac{\log \left(1 - u1\right)}{2}\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. Simplified0.8

      \[\leadsto \sqrt{-\color{blue}{\left(\frac{\log \left(1 - u1\right)}{-2} - \log \left(1 - u1\right) \cdot -1.5\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      Proof

      [Start]0.8

      \[ \sqrt{-\left(\frac{\log \left(1 - u1\right)}{-2} - -3 \cdot \frac{\log \left(1 - u1\right)}{2}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

      rational_best-simplify-55 [=>]0.8

      \[ \sqrt{-\left(\frac{\log \left(1 - u1\right)}{-2} - \color{blue}{\log \left(1 - u1\right) \cdot \frac{-3}{2}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

      metadata-eval [=>]0.8

      \[ \sqrt{-\left(\frac{\log \left(1 - u1\right)}{-2} - \log \left(1 - u1\right) \cdot \color{blue}{-1.5}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    if 0.954999983 < (-.f32 1 u1)

    1. Initial program 15.7

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Taylor expanded in u1 around 0 0.3

      \[\leadsto \sqrt{-\color{blue}{\left(-1 \cdot u1 + \left(-0.25 \cdot {u1}^{4} + \left(-0.3333333333333333 \cdot {u1}^{3} + -0.5 \cdot {u1}^{2}\right)\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. Simplified0.3

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-u1\right) + \left(-0.3333333333333333 \cdot {u1}^{3} + \left(-0.5 \cdot {u1}^{2} + -0.25 \cdot {u1}^{4}\right)\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      Proof

      [Start]0.3

      \[ \sqrt{-\left(-1 \cdot u1 + \left(-0.25 \cdot {u1}^{4} + \left(-0.3333333333333333 \cdot {u1}^{3} + -0.5 \cdot {u1}^{2}\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

      rational_best-simplify-1 [=>]0.3

      \[ \sqrt{-\left(\color{blue}{u1 \cdot -1} + \left(-0.25 \cdot {u1}^{4} + \left(-0.3333333333333333 \cdot {u1}^{3} + -0.5 \cdot {u1}^{2}\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

      rational_best-simplify-10 [=>]0.3

      \[ \sqrt{-\left(\color{blue}{\left(-u1\right)} + \left(-0.25 \cdot {u1}^{4} + \left(-0.3333333333333333 \cdot {u1}^{3} + -0.5 \cdot {u1}^{2}\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

      rational_best-simplify-3 [=>]0.3

      \[ \sqrt{-\left(\left(-u1\right) + \left(-0.25 \cdot {u1}^{4} + \color{blue}{\left(-0.5 \cdot {u1}^{2} + -0.3333333333333333 \cdot {u1}^{3}\right)}\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

      rational_best-simplify-47 [=>]0.3

      \[ \sqrt{-\left(\left(-u1\right) + \color{blue}{\left(-0.3333333333333333 \cdot {u1}^{3} + \left(-0.5 \cdot {u1}^{2} + -0.25 \cdot {u1}^{4}\right)\right)}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9549999833106995:\\ \;\;\;\;\sqrt{-\left(\frac{\log \left(1 - u1\right)}{-2} - \log \left(1 - u1\right) \cdot -1.5\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(\left(-u1\right) + \left(-0.3333333333333333 \cdot {u1}^{3} + \left(-0.5 \cdot {u1}^{2} + -0.25 \cdot {u1}^{4}\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost20004
\[\begin{array}{l} t_0 := \log \left(1 - u1\right)\\ \mathbf{if}\;1 - u1 \leq 0.9549999833106995:\\ \;\;\;\;\sqrt{-\left(\frac{t_0}{-2} - t_0 \cdot -1.5\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{u1}^{4} \cdot 0.25 + \left(\left(u1 - -0.5 \cdot {u1}^{2}\right) + {u1}^{3} \cdot 0.3333333333333333\right)} \cdot \cos \left(u2 \cdot \left(2 \cdot \pi\right)\right)\\ \end{array} \]
Alternative 2
Error0.5
Cost16676
\[\begin{array}{l} t_0 := \log \left(1 - u1\right)\\ \mathbf{if}\;1 - u1 \leq 0.9854999780654907:\\ \;\;\;\;\sqrt{-\left(\frac{t_0}{-2} - t_0 \cdot -1.5\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1 - \left(-0.3333333333333333 \cdot {u1}^{3} + -0.5 \cdot {u1}^{2}\right)} \cdot \cos \left(\pi \cdot \left(2 \cdot u2\right)\right)\\ \end{array} \]
Alternative 3
Error0.5
Cost16644
\[\begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9854999780654907:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1 - \left(-0.3333333333333333 \cdot {u1}^{3} + -0.5 \cdot {u1}^{2}\right)} \cdot \cos \left(\pi \cdot \left(2 \cdot u2\right)\right)\\ \end{array} \]
Alternative 4
Error4.4
Cost13316
\[\begin{array}{l} t_0 := \left(2 \cdot \pi\right) \cdot u2\\ \mathbf{if}\;t_0 \leq 0.0026000000070780516:\\ \;\;\;\;\sqrt{{u1}^{3} \cdot 0.3333333333333333 + \left(u1 - -0.5 \cdot {u1}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(-u1\right)} \cdot \cos t_0\\ \end{array} \]
Alternative 5
Error4.4
Cost13316
\[\begin{array}{l} t_0 := \left(2 \cdot \pi\right) \cdot u2\\ \mathbf{if}\;t_0 \leq 0.0026000000070780516:\\ \;\;\;\;\sqrt{u1 - \left(-0.3333333333333333 \cdot {u1}^{3} + -0.5 \cdot {u1}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(-u1\right)} \cdot \cos t_0\\ \end{array} \]
Alternative 6
Error0.8
Cost13284
\[\begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9968000054359436:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1 - -0.5 \cdot {u1}^{2}} \cdot \cos \left(\left(u2 \cdot \pi\right) \cdot 2\right)\\ \end{array} \]
Alternative 7
Error4.7
Cost13220
\[\begin{array}{l} t_0 := -\log \left(1 - u1\right)\\ \mathbf{if}\;t_0 \leq 0.001075000036507845:\\ \;\;\;\;\sqrt{-\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{t_0}\\ \end{array} \]
Alternative 8
Error2.8
Cost13220
\[\begin{array}{l} t_0 := \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{if}\;1 - u1 \leq 0.9998400211334229:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(-u1\right)} \cdot t_0\\ \end{array} \]
Alternative 9
Error7.7
Cost9892
\[\begin{array}{l} t_0 := -\log \left(1 - u1\right)\\ \mathbf{if}\;t_0 \leq 0.00015999999595806003:\\ \;\;\;\;\sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{t_0}\\ \end{array} \]
Alternative 10
Error6.5
Cost6724
\[\begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9955000281333923:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot {u1}^{2} + u1}\\ \end{array} \]
Alternative 11
Error11.1
Cost3232
\[\sqrt{u1} \]

Error

Reproduce?

herbie shell --seed 2023100 
(FPCore (cosTheta_i u1 u2)
  :name "Beckmann Sample, near normal, slope_x"
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))