Beckmann Sample, near normal, slope_x

Percentage Accurate: 57.8% → 99.0%
Time: 12.8s
Alternatives: 12
Speedup: 3.1×

Specification

?
\[\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)\]
\[\begin{array}{l} \\ \sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-logf((1.0f - u1))) * cosf(((2.0f * ((float) M_PI)) * u2));
}
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 tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(-log((single(1.0) - u1))) * cos(((single(2.0) * single(pi)) * u2));
end
\begin{array}{l}

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\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} \\ \sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-logf((1.0f - u1))) * cosf(((2.0f * ((float) M_PI)) * u2));
}
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 tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(-log((single(1.0) - u1))) * cos(((single(2.0) * single(pi)) * u2));
end
\begin{array}{l}

\\
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\end{array}

Alternative 1: 99.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\pi \cdot 2}\\ \cos \left(t\_0 \cdot \left(t\_0 \cdot u2\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)} \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (sqrt (* PI 2.0))))
   (* (cos (* t_0 (* t_0 u2))) (sqrt (- (log1p (- u1)))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = sqrtf((((float) M_PI) * 2.0f));
	return cosf((t_0 * (t_0 * u2))) * sqrtf(-log1pf(-u1));
}
function code(cosTheta_i, u1, u2)
	t_0 = sqrt(Float32(Float32(pi) * Float32(2.0)))
	return Float32(cos(Float32(t_0 * Float32(t_0 * u2))) * sqrt(Float32(-log1p(Float32(-u1)))))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{\pi \cdot 2}\\
\cos \left(t\_0 \cdot \left(t\_0 \cdot u2\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-cbrt-cube99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\color{blue}{\sqrt[3]{\left(\left(2 \cdot \pi\right) \cdot \left(2 \cdot \pi\right)\right) \cdot \left(2 \cdot \pi\right)}} \cdot u2\right) \]
    2. add-cbrt-cube99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\sqrt[3]{\left(\left(2 \cdot \pi\right) \cdot \left(2 \cdot \pi\right)\right) \cdot \left(2 \cdot \pi\right)} \cdot \color{blue}{\sqrt[3]{\left(u2 \cdot u2\right) \cdot u2}}\right) \]
    3. cbrt-unprod99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(\sqrt[3]{\left(\left(\left(2 \cdot \pi\right) \cdot \left(2 \cdot \pi\right)\right) \cdot \left(2 \cdot \pi\right)\right) \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}\right)} \]
    4. pow399.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\sqrt[3]{\color{blue}{{\left(2 \cdot \pi\right)}^{3}} \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}\right) \]
    5. pow399.1%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\sqrt[3]{{\left(2 \cdot \pi\right)}^{3} \cdot \color{blue}{{u2}^{3}}}\right) \]
  6. Applied egg-rr99.1%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(\sqrt[3]{{\left(2 \cdot \pi\right)}^{3} \cdot {u2}^{3}}\right)} \]
  7. Step-by-step derivation
    1. pow-prod-down99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\sqrt[3]{\color{blue}{{\left(\left(2 \cdot \pi\right) \cdot u2\right)}^{3}}}\right) \]
    2. associate-*r*99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\sqrt[3]{{\color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)}}^{3}}\right) \]
    3. rem-cbrt-cube99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
    4. associate-*r*99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
    5. add-sqr-sqrt99.0%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\color{blue}{\left(\sqrt{2 \cdot \pi} \cdot \sqrt{2 \cdot \pi}\right)} \cdot u2\right) \]
    6. associate-*l*99.1%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(\sqrt{2 \cdot \pi} \cdot \left(\sqrt{2 \cdot \pi} \cdot u2\right)\right)} \]
    7. *-commutative99.1%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\sqrt{\color{blue}{\pi \cdot 2}} \cdot \left(\sqrt{2 \cdot \pi} \cdot u2\right)\right) \]
    8. *-commutative99.1%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\sqrt{\pi \cdot 2} \cdot \left(\sqrt{\color{blue}{\pi \cdot 2}} \cdot u2\right)\right) \]
  8. Applied egg-rr99.1%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(\sqrt{\pi \cdot 2} \cdot \left(\sqrt{\pi \cdot 2} \cdot u2\right)\right)} \]
  9. Final simplification99.1%

    \[\leadsto \cos \left(\sqrt{\pi \cdot 2} \cdot \left(\sqrt{\pi \cdot 2} \cdot u2\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)} \]
  10. Add Preprocessing

Alternative 2: 94.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\\ \mathbf{if}\;t\_0 \leq 0.9999997615814209:\\ \;\;\;\;t\_0 \cdot \sqrt{u1 \cdot \left(1 - u1 \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (cos (* (* PI 2.0) u2))))
   (if (<= t_0 0.9999997615814209)
     (* t_0 (sqrt (* u1 (- 1.0 (* u1 -0.5)))))
     (sqrt (- (log1p (- u1)))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = cosf(((((float) M_PI) * 2.0f) * u2));
	float tmp;
	if (t_0 <= 0.9999997615814209f) {
		tmp = t_0 * sqrtf((u1 * (1.0f - (u1 * -0.5f))));
	} else {
		tmp = sqrtf(-log1pf(-u1));
	}
	return tmp;
}
function code(cosTheta_i, u1, u2)
	t_0 = cos(Float32(Float32(Float32(pi) * Float32(2.0)) * u2))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.9999997615814209))
		tmp = Float32(t_0 * sqrt(Float32(u1 * Float32(Float32(1.0) - Float32(u1 * Float32(-0.5))))));
	else
		tmp = sqrt(Float32(-log1p(Float32(-u1))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.9999997615814209:\\
\;\;\;\;t\_0 \cdot \sqrt{u1 \cdot \left(1 - u1 \cdot -0.5\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)) < 0.999999762

    1. Initial program 61.2%

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

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

    if 0.999999762 < (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))

    1. Initial program 55.5%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Step-by-step derivation
      1. sub-neg55.5%

        \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      2. log1p-define99.5%

        \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in u2 around 0 99.4%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \leq 0.9999997615814209:\\ \;\;\;\;\cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1 \cdot \left(1 - u1 \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 90.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\\ \mathbf{if}\;t\_0 \leq 0.9999549984931946:\\ \;\;\;\;t\_0 \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (cos (* (* PI 2.0) u2))))
   (if (<= t_0 0.9999549984931946)
     (* t_0 (sqrt u1))
     (sqrt (- (log1p (- u1)))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = cosf(((((float) M_PI) * 2.0f) * u2));
	float tmp;
	if (t_0 <= 0.9999549984931946f) {
		tmp = t_0 * sqrtf(u1);
	} else {
		tmp = sqrtf(-log1pf(-u1));
	}
	return tmp;
}
function code(cosTheta_i, u1, u2)
	t_0 = cos(Float32(Float32(Float32(pi) * Float32(2.0)) * u2))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.9999549984931946))
		tmp = Float32(t_0 * sqrt(u1));
	else
		tmp = sqrt(Float32(-log1p(Float32(-u1))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(\left(\pi \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.9999549984931946:\\
\;\;\;\;t\_0 \cdot \sqrt{u1}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)) < 0.999954998

    1. Initial program 62.7%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-exp-log53.1%

        \[\leadsto \color{blue}{e^{\log \left(\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)}} \]
      2. add-sqr-sqrt53.1%

        \[\leadsto e^{\log \left(\sqrt{\color{blue}{\sqrt{-\log \left(1 - u1\right)} \cdot \sqrt{-\log \left(1 - u1\right)}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      3. sqrt-unprod53.1%

        \[\leadsto e^{\log \left(\sqrt{\color{blue}{\sqrt{\left(-\log \left(1 - u1\right)\right) \cdot \left(-\log \left(1 - u1\right)\right)}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      4. sqr-neg53.1%

        \[\leadsto e^{\log \left(\sqrt{\sqrt{\color{blue}{\log \left(1 - u1\right) \cdot \log \left(1 - u1\right)}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      5. sqrt-unprod1.0%

        \[\leadsto e^{\log \left(\sqrt{\color{blue}{\sqrt{\log \left(1 - u1\right)} \cdot \sqrt{\log \left(1 - u1\right)}}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      6. add-sqr-sqrt1.0%

        \[\leadsto e^{\log \left(\sqrt{\color{blue}{\log \left(1 - u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      7. sub-neg1.0%

        \[\leadsto e^{\log \left(\sqrt{\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      8. log1p-undefine-0.0%

        \[\leadsto e^{\log \left(\sqrt{\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      9. add-sqr-sqrt-0.0%

        \[\leadsto e^{\log \left(\sqrt{\mathsf{log1p}\left(\color{blue}{\sqrt{-u1} \cdot \sqrt{-u1}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      10. sqrt-unprod59.7%

        \[\leadsto e^{\log \left(\sqrt{\mathsf{log1p}\left(\color{blue}{\sqrt{\left(-u1\right) \cdot \left(-u1\right)}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      11. sqr-neg59.7%

        \[\leadsto e^{\log \left(\sqrt{\mathsf{log1p}\left(\sqrt{\color{blue}{u1 \cdot u1}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      12. sqrt-unprod59.7%

        \[\leadsto e^{\log \left(\sqrt{\mathsf{log1p}\left(\color{blue}{\sqrt{u1} \cdot \sqrt{u1}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      13. add-sqr-sqrt59.7%

        \[\leadsto e^{\log \left(\sqrt{\mathsf{log1p}\left(\color{blue}{u1}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\right)} \]
      14. associate-*l*59.7%

        \[\leadsto e^{\log \left(\sqrt{\mathsf{log1p}\left(u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)}\right)} \]
    4. Applied egg-rr59.7%

      \[\leadsto \color{blue}{e^{\log \left(\sqrt{\mathsf{log1p}\left(u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)\right)}} \]
    5. Taylor expanded in u1 around 0 74.8%

      \[\leadsto \color{blue}{\sqrt{u1} \cdot \cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)} \]
    6. Step-by-step derivation
      1. *-commutative74.8%

        \[\leadsto \sqrt{u1} \cdot \cos \color{blue}{\left(\left(u2 \cdot \pi\right) \cdot 2\right)} \]
      2. associate-*r*74.8%

        \[\leadsto \sqrt{u1} \cdot \cos \color{blue}{\left(u2 \cdot \left(\pi \cdot 2\right)\right)} \]
    7. Simplified74.8%

      \[\leadsto \color{blue}{\sqrt{u1} \cdot \cos \left(u2 \cdot \left(\pi \cdot 2\right)\right)} \]

    if 0.999954998 < (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))

    1. Initial program 56.0%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Step-by-step derivation
      1. sub-neg56.0%

        \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      2. log1p-define99.4%

        \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in u2 around 0 96.5%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \leq 0.9999549984931946:\\ \;\;\;\;\cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (cos (* (* PI 2.0) u2)) (sqrt (- (log1p (- u1))))))
float code(float cosTheta_i, float u1, float u2) {
	return cosf(((((float) M_PI) * 2.0f) * u2)) * sqrtf(-log1pf(-u1));
}
function code(cosTheta_i, u1, u2)
	return Float32(cos(Float32(Float32(Float32(pi) * Float32(2.0)) * u2)) * sqrt(Float32(-log1p(Float32(-u1)))))
end
\begin{array}{l}

\\
\cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Final simplification99.0%

    \[\leadsto \cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)} \]
  6. Add Preprocessing

Alternative 5: 95.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\pi \cdot 2\right) \cdot u2\\ \mathbf{if}\;t\_0 \leq 0.0002500000118743628:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos t\_0 \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 - u1 \cdot -0.3333333333333333\right)\right)}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (* (* PI 2.0) u2)))
   (if (<= t_0 0.0002500000118743628)
     (sqrt (- (log1p (- u1))))
     (*
      (cos t_0)
      (sqrt (* u1 (+ 1.0 (* u1 (- 0.5 (* u1 -0.3333333333333333))))))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = (((float) M_PI) * 2.0f) * u2;
	float tmp;
	if (t_0 <= 0.0002500000118743628f) {
		tmp = sqrtf(-log1pf(-u1));
	} else {
		tmp = cosf(t_0) * sqrtf((u1 * (1.0f + (u1 * (0.5f - (u1 * -0.3333333333333333f))))));
	}
	return tmp;
}
function code(cosTheta_i, u1, u2)
	t_0 = Float32(Float32(Float32(pi) * Float32(2.0)) * u2)
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.0002500000118743628))
		tmp = sqrt(Float32(-log1p(Float32(-u1))));
	else
		tmp = Float32(cos(t_0) * sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(Float32(0.5) - Float32(u1 * Float32(-0.3333333333333333))))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\pi \cdot 2\right) \cdot u2\\
\mathbf{if}\;t\_0 \leq 0.0002500000118743628:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos t\_0 \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 - u1 \cdot -0.3333333333333333\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2) < 2.50000012e-4

    1. Initial program 56.3%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Step-by-step derivation
      1. sub-neg56.3%

        \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      2. log1p-define99.6%

        \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in u2 around 0 99.6%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]

    if 2.50000012e-4 < (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)

    1. Initial program 59.6%

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

      \[\leadsto \sqrt{-\color{blue}{u1 \cdot \left(u1 \cdot \left(-0.3333333333333333 \cdot u1 - 0.5\right) - 1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\pi \cdot 2\right) \cdot u2 \leq 0.0002500000118743628:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 - u1 \cdot -0.3333333333333333\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 93.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 - u1 \cdot -0.25\right)\right)\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (*
  (cos (* (* PI 2.0) u2))
  (sqrt
   (* u1 (+ 1.0 (* u1 (+ 0.5 (* u1 (- 0.3333333333333333 (* u1 -0.25))))))))))
float code(float cosTheta_i, float u1, float u2) {
	return cosf(((((float) M_PI) * 2.0f) * u2)) * sqrtf((u1 * (1.0f + (u1 * (0.5f + (u1 * (0.3333333333333333f - (u1 * -0.25f))))))));
}
function code(cosTheta_i, u1, u2)
	return Float32(cos(Float32(Float32(Float32(pi) * Float32(2.0)) * u2)) * sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(Float32(0.5) + Float32(u1 * Float32(Float32(0.3333333333333333) - Float32(u1 * Float32(-0.25))))))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = cos(((single(pi) * single(2.0)) * u2)) * sqrt((u1 * (single(1.0) + (u1 * (single(0.5) + (u1 * (single(0.3333333333333333) - (u1 * single(-0.25)))))))));
end
\begin{array}{l}

\\
\cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 - u1 \cdot -0.25\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 57.9%

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

    \[\leadsto \sqrt{-\color{blue}{u1 \cdot \left(u1 \cdot \left(u1 \cdot \left(-0.25 \cdot u1 - 0.3333333333333333\right) - 0.5\right) - 1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  4. Final simplification94.1%

    \[\leadsto \cos \left(\left(\pi \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 - u1 \cdot -0.25\right)\right)\right)} \]
  5. Add Preprocessing

Alternative 7: 79.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (- (log1p (- u1)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-log1pf(-u1));
}
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(-log1p(Float32(-u1))))
end
\begin{array}{l}

\\
\sqrt{-\mathsf{log1p}\left(-u1\right)}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in u2 around 0 81.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Final simplification81.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \]
  7. Add Preprocessing

Alternative 8: 76.1% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 - u1 \cdot -0.25\right)\right)\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (sqrt
  (* u1 (+ 1.0 (* u1 (+ 0.5 (* u1 (- 0.3333333333333333 (* u1 -0.25)))))))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 * (1.0f + (u1 * (0.5f + (u1 * (0.3333333333333333f - (u1 * -0.25f))))))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 * (1.0e0 + (u1 * (0.5e0 + (u1 * (0.3333333333333333e0 - (u1 * (-0.25e0)))))))))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(Float32(0.5) + Float32(u1 * Float32(Float32(0.3333333333333333) - Float32(u1 * Float32(-0.25)))))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 * (single(1.0) + (u1 * (single(0.5) + (u1 * (single(0.3333333333333333) - (u1 * single(-0.25)))))))));
end
\begin{array}{l}

\\
\sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 - u1 \cdot -0.25\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in u2 around 0 81.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 78.4%

    \[\leadsto \sqrt{-\color{blue}{u1 \cdot \left(u1 \cdot \left(u1 \cdot \left(-0.25 \cdot u1 - 0.3333333333333333\right) - 0.5\right) - 1\right)}} \cdot 1 \]
  7. Final simplification78.4%

    \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 + u1 \cdot \left(0.3333333333333333 - u1 \cdot -0.25\right)\right)\right)} \]
  8. Add Preprocessing

Alternative 9: 74.8% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 - u1 \cdot -0.3333333333333333\right)\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (sqrt (* u1 (+ 1.0 (* u1 (- 0.5 (* u1 -0.3333333333333333)))))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 * (1.0f + (u1 * (0.5f - (u1 * -0.3333333333333333f))))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 * (1.0e0 + (u1 * (0.5e0 - (u1 * (-0.3333333333333333e0)))))))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 * Float32(Float32(1.0) + Float32(u1 * Float32(Float32(0.5) - Float32(u1 * Float32(-0.3333333333333333)))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 * (single(1.0) + (u1 * (single(0.5) - (u1 * single(-0.3333333333333333)))))));
end
\begin{array}{l}

\\
\sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 - u1 \cdot -0.3333333333333333\right)\right)}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in u2 around 0 81.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 77.0%

    \[\leadsto \sqrt{-\color{blue}{u1 \cdot \left(u1 \cdot \left(-0.3333333333333333 \cdot u1 - 0.5\right) - 1\right)}} \cdot 1 \]
  7. Final simplification77.0%

    \[\leadsto \sqrt{u1 \cdot \left(1 + u1 \cdot \left(0.5 - u1 \cdot -0.3333333333333333\right)\right)} \]
  8. Add Preprocessing

Alternative 10: 72.3% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \sqrt{u1 \cdot \left(1 - u1 \cdot -0.5\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (sqrt (* u1 (- 1.0 (* u1 -0.5)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 * (1.0f - (u1 * -0.5f))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 * (1.0e0 - (u1 * (-0.5e0)))))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 * Float32(Float32(1.0) - Float32(u1 * Float32(-0.5)))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 * (single(1.0) - (u1 * single(-0.5)))));
end
\begin{array}{l}

\\
\sqrt{u1 \cdot \left(1 - u1 \cdot -0.5\right)}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in u2 around 0 81.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 74.4%

    \[\leadsto \sqrt{-\color{blue}{u1 \cdot \left(-0.5 \cdot u1 - 1\right)}} \cdot 1 \]
  7. Final simplification74.4%

    \[\leadsto \sqrt{u1 \cdot \left(1 - u1 \cdot -0.5\right)} \]
  8. Add Preprocessing

Alternative 11: 5.0% accurate, 3.0× speedup?

\[\begin{array}{l} \\ -\sqrt{u1} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (- (sqrt u1)))
float code(float cosTheta_i, float u1, float u2) {
	return -sqrtf(u1);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = -sqrt(u1)
end function
function code(cosTheta_i, u1, u2)
	return Float32(-sqrt(u1))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = -sqrt(u1);
end
\begin{array}{l}

\\
-\sqrt{u1}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in u2 around 0 81.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 -0.0%

    \[\leadsto \color{blue}{\left(\sqrt{u1} \cdot {\left(\sqrt{-1}\right)}^{2}\right)} \cdot 1 \]
  7. Step-by-step derivation
    1. *-commutative-0.0%

      \[\leadsto \color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \sqrt{u1}\right)} \cdot 1 \]
    2. unpow2-0.0%

      \[\leadsto \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{u1}\right) \cdot 1 \]
    3. rem-square-sqrt4.8%

      \[\leadsto \left(\color{blue}{-1} \cdot \sqrt{u1}\right) \cdot 1 \]
    4. mul-1-neg4.8%

      \[\leadsto \color{blue}{\left(-\sqrt{u1}\right)} \cdot 1 \]
  8. Simplified4.8%

    \[\leadsto \color{blue}{\left(-\sqrt{u1}\right)} \cdot 1 \]
  9. Final simplification4.8%

    \[\leadsto -\sqrt{u1} \]
  10. Add Preprocessing

Alternative 12: 64.4% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sqrt{u1} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt u1))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(u1);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt(u1)
end function
function code(cosTheta_i, u1, u2)
	return sqrt(u1)
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(u1);
end
\begin{array}{l}

\\
\sqrt{u1}
\end{array}
Derivation
  1. Initial program 57.9%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg57.9%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-define99.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in u2 around 0 81.4%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  6. Taylor expanded in u1 around 0 67.1%

    \[\leadsto \sqrt{-\color{blue}{-1 \cdot u1}} \cdot 1 \]
  7. Step-by-step derivation
    1. mul-1-neg67.1%

      \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot 1 \]
  8. Simplified67.1%

    \[\leadsto \sqrt{-\color{blue}{\left(-u1\right)}} \cdot 1 \]
  9. Final simplification67.1%

    \[\leadsto \sqrt{u1} \]
  10. Add Preprocessing

Reproduce

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