?

Average Error: 13.5 → 0.4
Time: 17.5s
Precision: binary32
Cost: 23300

?

\[\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 := \log \left(1 - u1\right)\\ t_1 := \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{if}\;-t_0 \leq 0.039000000804662704:\\ \;\;\;\;\sqrt{-\left(\left(-u1\right) + \left(-0.5 \cdot {u1}^{2} + \left(-0.25 \cdot {u1}^{4} + -0.3333333333333333 \cdot {u1}^{3}\right)\right)\right)} \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(t_0 \cdot \frac{1}{t_0}\right) \cdot t_0} \cdot t_1\\ \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 (log (- 1.0 u1))) (t_1 (cos (* (* 2.0 PI) u2))))
   (if (<= (- t_0) 0.039000000804662704)
     (*
      (sqrt
       (-
        (+
         (- u1)
         (+
          (* -0.5 (pow u1 2.0))
          (+ (* -0.25 (pow u1 4.0)) (* -0.3333333333333333 (pow u1 3.0)))))))
      t_1)
     (* (sqrt (- (* (* t_0 (/ 1.0 t_0)) t_0))) t_1))))
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 = logf((1.0f - u1));
	float t_1 = cosf(((2.0f * ((float) M_PI)) * u2));
	float tmp;
	if (-t_0 <= 0.039000000804662704f) {
		tmp = sqrtf(-(-u1 + ((-0.5f * powf(u1, 2.0f)) + ((-0.25f * powf(u1, 4.0f)) + (-0.3333333333333333f * powf(u1, 3.0f)))))) * t_1;
	} else {
		tmp = sqrtf(-((t_0 * (1.0f / t_0)) * t_0)) * t_1;
	}
	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 = log(Float32(Float32(1.0) - u1))
	t_1 = cos(Float32(Float32(Float32(2.0) * Float32(pi)) * u2))
	tmp = Float32(0.0)
	if (Float32(-t_0) <= Float32(0.039000000804662704))
		tmp = Float32(sqrt(Float32(-Float32(Float32(-u1) + Float32(Float32(Float32(-0.5) * (u1 ^ Float32(2.0))) + Float32(Float32(Float32(-0.25) * (u1 ^ Float32(4.0))) + Float32(Float32(-0.3333333333333333) * (u1 ^ Float32(3.0)))))))) * t_1);
	else
		tmp = Float32(sqrt(Float32(-Float32(Float32(t_0 * Float32(Float32(1.0) / t_0)) * t_0))) * t_1);
	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 = log((single(1.0) - u1));
	t_1 = cos(((single(2.0) * single(pi)) * u2));
	tmp = single(0.0);
	if (-t_0 <= single(0.039000000804662704))
		tmp = sqrt(-(-u1 + ((single(-0.5) * (u1 ^ single(2.0))) + ((single(-0.25) * (u1 ^ single(4.0))) + (single(-0.3333333333333333) * (u1 ^ single(3.0))))))) * t_1;
	else
		tmp = sqrt(-((t_0 * (single(1.0) / t_0)) * t_0)) * t_1;
	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 := \log \left(1 - u1\right)\\
t_1 := \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\
\mathbf{if}\;-t_0 \leq 0.039000000804662704:\\
\;\;\;\;\sqrt{-\left(\left(-u1\right) + \left(-0.5 \cdot {u1}^{2} + \left(-0.25 \cdot {u1}^{4} + -0.3333333333333333 \cdot {u1}^{3}\right)\right)\right)} \cdot t_1\\

\mathbf{else}:\\
\;\;\;\;\sqrt{-\left(t_0 \cdot \frac{1}{t_0}\right) \cdot t_0} \cdot t_1\\


\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 (neg.f32 (log.f32 (-.f32 1 u1))) < 0.0390000008

    1. Initial program 15.8

      \[\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.5 \cdot {u1}^{2} + \left(-0.25 \cdot {u1}^{4} + -0.3333333333333333 \cdot {u1}^{3}\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_oopsla_all_46_json_45_simplify-74 [=>]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_oopsla_all_46_json_45_simplify-92 [=>]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_oopsla_all_46_json_45_simplify-35 [=>]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_oopsla_all_46_json_45_simplify-82 [=>]0.3

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

    if 0.0390000008 < (neg.f32 (log.f32 (-.f32 1 u1)))

    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(\log \left(1 - u1\right) \cdot \frac{1}{\log \left(1 - u1\right)}\right) \cdot \log \left(1 - u1\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}\;-\log \left(1 - u1\right) \leq 0.039000000804662704:\\ \;\;\;\;\sqrt{-\left(\left(-u1\right) + \left(-0.5 \cdot {u1}^{2} + \left(-0.25 \cdot {u1}^{4} + -0.3333333333333333 \cdot {u1}^{3}\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(\log \left(1 - u1\right) \cdot \frac{1}{\log \left(1 - u1\right)}\right) \cdot \log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.5
Cost19940
\[\begin{array}{l} t_0 := \log \left(1 - u1\right)\\ \mathbf{if}\;1 - u1 \leq 0.9879999756813049:\\ \;\;\;\;\sqrt{-\left(t_0 \cdot \frac{1}{t_0}\right) \cdot t_0} \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(2 \cdot \left(u2 \cdot \pi\right)\right)\\ \end{array} \]
Alternative 2
Error0.5
Cost16644
\[\begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9879999756813049:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{u1}^{3} \cdot 0.3333333333333333 + \left(u1 + {u1}^{2} \cdot 0.5\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.9879999756813049:\\ \;\;\;\;\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(2 \cdot \left(u2 \cdot \pi\right)\right)\\ \end{array} \]
Alternative 4
Error4.5
Cost13316
\[\begin{array}{l} t_0 := \left(2 \cdot \pi\right) \cdot u2\\ \mathbf{if}\;t_0 \leq 0.0012000000569969416:\\ \;\;\;\;\sqrt{0.5 \cdot {u1}^{2} + \left(0.3333333333333333 \cdot {u1}^{3} + u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(-u1\right)} \cdot \cos t_0\\ \end{array} \]
Alternative 5
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 - {u1}^{2} \cdot -0.5} \cdot \cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)\\ \end{array} \]
Alternative 6
Error2.7
Cost13220
\[\begin{array}{l} t_0 := \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{if}\;1 - u1 \leq 0.9998499751091003:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(-u1\right)} \cdot t_0\\ \end{array} \]
Alternative 7
Error4.7
Cost9988
\[\begin{array}{l} \mathbf{if}\;1 - u1 \leq 0.9983500242233276:\\ \;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \end{array} \]
Alternative 8
Error6.5
Cost9956
\[\begin{array}{l} t_0 := -\log \left(1 - u1\right)\\ \mathbf{if}\;t_0 \leq 0.003000000026077032:\\ \;\;\;\;\sqrt{u1 - {u1}^{2} \cdot -0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{t_0} \cdot 1\\ \end{array} \]
Alternative 9
Error11.2
Cost6592
\[\sqrt{u1 - -0.3333333333333333 \cdot {u1}^{3}} \]
Alternative 10
Error8.6
Cost6592
\[\sqrt{u1 - {u1}^{2} \cdot -0.5} \]
Alternative 11
Error11.2
Cost3232
\[\sqrt{u1} \]

Error

Reproduce?

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