Beckmann Sample, near normal, slope_x

Percentage Accurate: 57.7% → 99.0%
Time: 10.1s
Alternatives: 6
Speedup: 4.0×

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 6 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} \\ \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, 1.0× speedup?

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

\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)
\end{array}
Derivation
  1. Initial program 63.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-neg63.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-def99.1%

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

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

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

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

Alternative 2: 90.4% accurate, 1.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \cos t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 (*.f32 2 (PI.f32)) u2) < 0.0109999999

    1. Initial program 64.7%

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

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

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

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

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

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

    if 0.0109999999 < (*.f32 (*.f32 2 (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. Step-by-step derivation
      1. add-sqr-sqrt59.5%

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

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

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

        \[\leadsto {\color{blue}{\left({\left(-\log \left(1 - u1\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      5. add-sqr-sqrt59.5%

        \[\leadsto {\left({\color{blue}{\left(\sqrt{-\log \left(1 - u1\right)} \cdot \sqrt{-\log \left(1 - u1\right)}\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      6. sqrt-unprod59.7%

        \[\leadsto {\left({\color{blue}{\left(\sqrt{\left(-\log \left(1 - u1\right)\right) \cdot \left(-\log \left(1 - u1\right)\right)}\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      7. sqr-neg59.7%

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

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

        \[\leadsto {\left({\color{blue}{\log \left(1 - u1\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      10. sub-neg1.5%

        \[\leadsto {\left({\log \color{blue}{\left(1 + \left(-u1\right)\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      11. log1p-udef-0.0%

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

        \[\leadsto {\left({\left(\mathsf{log1p}\left(\color{blue}{\sqrt{-u1} \cdot \sqrt{-u1}}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      13. sqrt-unprod71.6%

        \[\leadsto {\left({\left(\mathsf{log1p}\left(\color{blue}{\sqrt{\left(-u1\right) \cdot \left(-u1\right)}}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      14. sqr-neg71.6%

        \[\leadsto {\left({\left(\mathsf{log1p}\left(\sqrt{\color{blue}{u1 \cdot u1}}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      15. sqrt-unprod71.7%

        \[\leadsto {\left({\left(\mathsf{log1p}\left(\color{blue}{\sqrt{u1} \cdot \sqrt{u1}}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      16. add-sqr-sqrt71.6%

        \[\leadsto {\left({\left(\mathsf{log1p}\left(\color{blue}{u1}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      17. metadata-eval71.6%

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

      \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{0.25}\right)}^{2}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    4. Taylor expanded in u1 around 0 73.8%

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

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

Alternative 3: 80.0% accurate, 2.0× 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 63.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-neg63.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-def99.1%

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

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \]

Alternative 4: 72.7% accurate, 3.8× speedup?

\[\begin{array}{l} \\ \sqrt{u1 - -0.5 \cdot \left(u1 \cdot u1\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (sqrt (- u1 (* -0.5 (* u1 u1)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 - (-0.5f * (u1 * 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 - ((-0.5e0) * (u1 * u1))))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 - Float32(Float32(-0.5) * Float32(u1 * u1))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 - (single(-0.5) * (u1 * u1))));
end
\begin{array}{l}

\\
\sqrt{u1 - -0.5 \cdot \left(u1 \cdot u1\right)}
\end{array}
Derivation
  1. Initial program 63.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-neg63.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-def99.1%

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

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

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

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

    \[\leadsto \sqrt{-\color{blue}{\left(-1 \cdot u1 + -0.5 \cdot {u1}^{2}\right)}} \cdot 1 \]
  6. Step-by-step derivation
    1. +-commutative70.7%

      \[\leadsto \sqrt{-\color{blue}{\left(-0.5 \cdot {u1}^{2} + -1 \cdot u1\right)}} \cdot 1 \]
    2. mul-1-neg70.7%

      \[\leadsto \sqrt{-\left(-0.5 \cdot {u1}^{2} + \color{blue}{\left(-u1\right)}\right)} \cdot 1 \]
    3. unsub-neg70.7%

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

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

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

    \[\leadsto \sqrt{u1 - -0.5 \cdot \left(u1 \cdot u1\right)} \]

Alternative 5: 64.8% accurate, 3.9× speedup?

\[\begin{array}{l} \\ {\left(u1 \cdot u1\right)}^{0.25} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (pow (* u1 u1) 0.25))
float code(float cosTheta_i, float u1, float u2) {
	return powf((u1 * 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 = (u1 * u1) ** 0.25e0
end function
function code(cosTheta_i, u1, u2)
	return Float32(u1 * u1) ^ Float32(0.25)
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = (u1 * u1) ^ single(0.25);
end
\begin{array}{l}

\\
{\left(u1 \cdot u1\right)}^{0.25}
\end{array}
Derivation
  1. Initial program 63.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-neg63.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-def99.1%

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  5. Step-by-step derivation
    1. pow1/280.1%

      \[\leadsto \color{blue}{{\left(-\mathsf{log1p}\left(-u1\right)\right)}^{0.5}} \cdot 1 \]
    2. add-sqr-sqrt80.1%

      \[\leadsto {\color{blue}{\left(\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right)}}^{0.5} \cdot 1 \]
    3. sqrt-unprod80.1%

      \[\leadsto {\color{blue}{\left(\sqrt{\left(-\mathsf{log1p}\left(-u1\right)\right) \cdot \left(-\mathsf{log1p}\left(-u1\right)\right)}\right)}}^{0.5} \cdot 1 \]
    4. sqr-neg80.1%

      \[\leadsto {\left(\sqrt{\color{blue}{\mathsf{log1p}\left(-u1\right) \cdot \mathsf{log1p}\left(-u1\right)}}\right)}^{0.5} \cdot 1 \]
    5. sqrt-unprod-0.0%

      \[\leadsto {\color{blue}{\left(\sqrt{\mathsf{log1p}\left(-u1\right)} \cdot \sqrt{\mathsf{log1p}\left(-u1\right)}\right)}}^{0.5} \cdot 1 \]
    6. add-sqr-sqrt-0.0%

      \[\leadsto {\color{blue}{\left(\mathsf{log1p}\left(-u1\right)\right)}}^{0.5} \cdot 1 \]
    7. add-sqr-sqrt-0.0%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{\sqrt{-u1} \cdot \sqrt{-u1}}\right)\right)}^{0.5} \cdot 1 \]
    8. sqrt-unprod60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{\sqrt{\left(-u1\right) \cdot \left(-u1\right)}}\right)\right)}^{0.5} \cdot 1 \]
    9. sqr-neg60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\sqrt{\color{blue}{u1 \cdot u1}}\right)\right)}^{0.5} \cdot 1 \]
    10. sqrt-unprod60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{\sqrt{u1} \cdot \sqrt{u1}}\right)\right)}^{0.5} \cdot 1 \]
    11. add-sqr-sqrt60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{u1}\right)\right)}^{0.5} \cdot 1 \]
    12. metadata-eval60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(u1\right)\right)}^{\color{blue}{\left(0.25 + 0.25\right)}} \cdot 1 \]
    13. pow-prod-up60.2%

      \[\leadsto \color{blue}{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{0.25} \cdot {\left(\mathsf{log1p}\left(u1\right)\right)}^{0.25}\right)} \cdot 1 \]
    14. pow-prod-down60.3%

      \[\leadsto \color{blue}{{\left(\mathsf{log1p}\left(u1\right) \cdot \mathsf{log1p}\left(u1\right)\right)}^{0.25}} \cdot 1 \]
    15. pow260.3%

      \[\leadsto {\color{blue}{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}}^{0.25} \cdot 1 \]
  6. Applied egg-rr60.3%

    \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot 1 \]
  7. Taylor expanded in u1 around 0 61.9%

    \[\leadsto {\color{blue}{\left({u1}^{2}\right)}}^{0.25} \cdot 1 \]
  8. Step-by-step derivation
    1. unpow261.9%

      \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot 1 \]
  9. Simplified61.9%

    \[\leadsto {\color{blue}{\left(u1 \cdot u1\right)}}^{0.25} \cdot 1 \]
  10. Final simplification61.9%

    \[\leadsto {\left(u1 \cdot u1\right)}^{0.25} \]

Alternative 6: 64.8% accurate, 4.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 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 63.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-neg63.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-def99.1%

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

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

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

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  5. Step-by-step derivation
    1. pow1/280.1%

      \[\leadsto \color{blue}{{\left(-\mathsf{log1p}\left(-u1\right)\right)}^{0.5}} \cdot 1 \]
    2. add-sqr-sqrt80.1%

      \[\leadsto {\color{blue}{\left(\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right)}}^{0.5} \cdot 1 \]
    3. sqrt-unprod80.1%

      \[\leadsto {\color{blue}{\left(\sqrt{\left(-\mathsf{log1p}\left(-u1\right)\right) \cdot \left(-\mathsf{log1p}\left(-u1\right)\right)}\right)}}^{0.5} \cdot 1 \]
    4. sqr-neg80.1%

      \[\leadsto {\left(\sqrt{\color{blue}{\mathsf{log1p}\left(-u1\right) \cdot \mathsf{log1p}\left(-u1\right)}}\right)}^{0.5} \cdot 1 \]
    5. sqrt-unprod-0.0%

      \[\leadsto {\color{blue}{\left(\sqrt{\mathsf{log1p}\left(-u1\right)} \cdot \sqrt{\mathsf{log1p}\left(-u1\right)}\right)}}^{0.5} \cdot 1 \]
    6. add-sqr-sqrt-0.0%

      \[\leadsto {\color{blue}{\left(\mathsf{log1p}\left(-u1\right)\right)}}^{0.5} \cdot 1 \]
    7. add-sqr-sqrt-0.0%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{\sqrt{-u1} \cdot \sqrt{-u1}}\right)\right)}^{0.5} \cdot 1 \]
    8. sqrt-unprod60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{\sqrt{\left(-u1\right) \cdot \left(-u1\right)}}\right)\right)}^{0.5} \cdot 1 \]
    9. sqr-neg60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\sqrt{\color{blue}{u1 \cdot u1}}\right)\right)}^{0.5} \cdot 1 \]
    10. sqrt-unprod60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{\sqrt{u1} \cdot \sqrt{u1}}\right)\right)}^{0.5} \cdot 1 \]
    11. add-sqr-sqrt60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(\color{blue}{u1}\right)\right)}^{0.5} \cdot 1 \]
    12. metadata-eval60.3%

      \[\leadsto {\left(\mathsf{log1p}\left(u1\right)\right)}^{\color{blue}{\left(0.25 + 0.25\right)}} \cdot 1 \]
    13. pow-prod-up60.2%

      \[\leadsto \color{blue}{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{0.25} \cdot {\left(\mathsf{log1p}\left(u1\right)\right)}^{0.25}\right)} \cdot 1 \]
    14. pow-prod-down60.3%

      \[\leadsto \color{blue}{{\left(\mathsf{log1p}\left(u1\right) \cdot \mathsf{log1p}\left(u1\right)\right)}^{0.25}} \cdot 1 \]
    15. pow260.3%

      \[\leadsto {\color{blue}{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}}^{0.25} \cdot 1 \]
  6. Applied egg-rr60.3%

    \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{2}\right)}^{0.25}} \cdot 1 \]
  7. Taylor expanded in u1 around 0 61.9%

    \[\leadsto \color{blue}{\sqrt{u1}} \cdot 1 \]
  8. Final simplification61.9%

    \[\leadsto \sqrt{u1} \]

Reproduce

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