Average Error: 14.3 → 0.5
Time: 8.0s
Precision: binary32
\[0.0001 \leq \alpha \land \alpha \leq 1 \land 2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\]
\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\]
\[\begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9705305099487305:\\ \;\;\;\;\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(u0 + \left(0.25 \cdot {u0}^{4} + \left(0.5 \cdot {u0}^{2} + 0.3333333333333333 \cdot {u0}^{3}\right)\right)\right) \cdot \left(\alpha \cdot \alpha\right)\\ \end{array}\]
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)
\begin{array}{l}
\mathbf{if}\;1 - u0 \leq 0.9705305099487305:\\
\;\;\;\;\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(u0 + \left(0.25 \cdot {u0}^{4} + \left(0.5 \cdot {u0}^{2} + 0.3333333333333333 \cdot {u0}^{3}\right)\right)\right) \cdot \left(\alpha \cdot \alpha\right)\\

\end{array}
(FPCore (alpha u0)
 :precision binary32
 (* (* (- alpha) alpha) (log (- 1.0 u0))))
(FPCore (alpha u0)
 :precision binary32
 (if (<= (- 1.0 u0) 0.9705305099487305)
   (* (- alpha) (* alpha (log (- 1.0 u0))))
   (*
    (+
     u0
     (+
      (* 0.25 (pow u0 4.0))
      (+ (* 0.5 (pow u0 2.0)) (* 0.3333333333333333 (pow u0 3.0)))))
    (* alpha alpha))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf(1.0f - u0);
}
float code(float alpha, float u0) {
	float tmp;
	if ((1.0f - u0) <= 0.9705305099487305f) {
		tmp = -alpha * (alpha * logf(1.0f - u0));
	} else {
		tmp = (u0 + ((0.25f * powf(u0, 4.0f)) + ((0.5f * powf(u0, 2.0f)) + (0.3333333333333333f * powf(u0, 3.0f))))) * (alpha * alpha);
	}
	return tmp;
}

Error

Bits error versus alpha

Bits error versus u0

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 u0) < 0.97053051

    1. Initial program 1.2

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\]
    2. Using strategy rm
    3. Applied associate-*l*_binary321.2

      \[\leadsto \color{blue}{\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)}\]

    if 0.97053051 < (-.f32 1 u0)

    1. Initial program 16.6

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)\]
    2. Taylor expanded around 0 0.3

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-\left(u0 + \left(0.25 \cdot {u0}^{4} + \left(0.5 \cdot {u0}^{2} + 0.3333333333333333 \cdot {u0}^{3}\right)\right)\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9705305099487305:\\ \;\;\;\;\left(-\alpha\right) \cdot \left(\alpha \cdot \log \left(1 - u0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(u0 + \left(0.25 \cdot {u0}^{4} + \left(0.5 \cdot {u0}^{2} + 0.3333333333333333 \cdot {u0}^{3}\right)\right)\right) \cdot \left(\alpha \cdot \alpha\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2021175 
(FPCore (alpha u0)
  :name "Beckmann Distribution sample, tan2theta, alphax == alphay"
  :precision binary32
  :pre (and (<= 0.0001 alpha 1.0) (<= 2.328306437e-10 u0 1.0))
  (* (* (- alpha) alpha) (log (- 1.0 u0))))