Beckmann Distribution sample, tan2theta, alphax == alphay

Percentage Accurate: 55.8% → 99.0%
Time: 4.4s
Alternatives: 5
Speedup: N/A×

Specification

?
\[\left(0.0001 \leq \alpha \land \alpha \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\]
\[\begin{array}{l} \\ \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (* (* (- alpha) alpha) (log (- 1.0 u0))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf((1.0f - u0));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(alpha, u0)
use fmin_fmax_functions
    real(4), intent (in) :: alpha
    real(4), intent (in) :: u0
    code = (-alpha * alpha) * log((1.0e0 - u0))
end function
function code(alpha, u0)
	return Float32(Float32(Float32(-alpha) * alpha) * log(Float32(Float32(1.0) - u0)))
end
function tmp = code(alpha, u0)
	tmp = (-alpha * alpha) * log((single(1.0) - u0));
end
\begin{array}{l}

\\
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\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 5 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: 55.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (* (* (- alpha) alpha) (log (- 1.0 u0))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * logf((1.0f - u0));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(alpha, u0)
use fmin_fmax_functions
    real(4), intent (in) :: alpha
    real(4), intent (in) :: u0
    code = (-alpha * alpha) * log((1.0e0 - u0))
end function
function code(alpha, u0)
	return Float32(Float32(Float32(-alpha) * alpha) * log(Float32(Float32(1.0) - u0)))
end
function tmp = code(alpha, u0)
	tmp = (-alpha * alpha) * log((single(1.0) - u0));
end
\begin{array}{l}

\\
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)
\end{array}

Alternative 1: 99.0% accurate, N/A× speedup?

\[\begin{array}{l} \\ -1 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot \mathsf{log1p}\left(-1 \cdot u0\right)\right) \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (* -1.0 (* (* alpha alpha) (log1p (* -1.0 u0)))))
float code(float alpha, float u0) {
	return -1.0f * ((alpha * alpha) * log1pf((-1.0f * u0)));
}
function code(alpha, u0)
	return Float32(Float32(-1.0) * Float32(Float32(alpha * alpha) * log1p(Float32(Float32(-1.0) * u0))))
end
\begin{array}{l}

\\
-1 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot \mathsf{log1p}\left(-1 \cdot u0\right)\right)
\end{array}
Derivation
  1. Initial program 53.3%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \color{blue}{\left(1 - u0\right)} \]
    2. lift-log.f32N/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\log \left(1 - u0\right)} \]
    3. *-lft-identityN/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - \color{blue}{1 \cdot u0}\right) \]
    4. fp-cancel-sub-sign-invN/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \color{blue}{\left(1 + \left(\mathsf{neg}\left(1\right)\right) \cdot u0\right)} \]
    5. metadata-evalN/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 + \color{blue}{-1} \cdot u0\right) \]
    6. mul-1-negN/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 + \color{blue}{\left(\mathsf{neg}\left(u0\right)\right)}\right) \]
    7. lower-log1p.f32N/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{neg}\left(u0\right)\right)} \]
    8. mul-1-negN/A

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \mathsf{log1p}\left(\color{blue}{-1 \cdot u0}\right) \]
    9. lower-*.f3299.0

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \mathsf{log1p}\left(\color{blue}{-1 \cdot u0}\right) \]
  4. Applied rewrites99.0%

    \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\mathsf{log1p}\left(-1 \cdot u0\right)} \]
  5. Final simplification99.0%

    \[\leadsto -1 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot \mathsf{log1p}\left(-1 \cdot u0\right)\right) \]
  6. Add Preprocessing

Alternative 2: 98.7% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \log \left(1 - u0\right)\\ t_1 := \left(\alpha \cdot \alpha\right) \cdot u0\\ \mathbf{if}\;t\_0 \leq -0.041999999433755875:\\ \;\;\;\;-1 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(t\_1 \cdot 0.25, u0, t\_1 \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0\\ \end{array} \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (let* ((t_0 (log (- 1.0 u0))) (t_1 (* (* alpha alpha) u0)))
   (if (<= t_0 -0.041999999433755875)
     (* -1.0 (* (* alpha alpha) t_0))
     (*
      (fma
       (* -1.0 alpha)
       (* -1.0 alpha)
       (*
        (-
         (fma (* t_1 0.25) u0 (* t_1 0.3333333333333333))
         (* -0.5 (* alpha alpha)))
        u0))
      u0))))
float code(float alpha, float u0) {
	float t_0 = logf((1.0f - u0));
	float t_1 = (alpha * alpha) * u0;
	float tmp;
	if (t_0 <= -0.041999999433755875f) {
		tmp = -1.0f * ((alpha * alpha) * t_0);
	} else {
		tmp = fmaf((-1.0f * alpha), (-1.0f * alpha), ((fmaf((t_1 * 0.25f), u0, (t_1 * 0.3333333333333333f)) - (-0.5f * (alpha * alpha))) * u0)) * u0;
	}
	return tmp;
}
function code(alpha, u0)
	t_0 = log(Float32(Float32(1.0) - u0))
	t_1 = Float32(Float32(alpha * alpha) * u0)
	tmp = Float32(0.0)
	if (t_0 <= Float32(-0.041999999433755875))
		tmp = Float32(Float32(-1.0) * Float32(Float32(alpha * alpha) * t_0));
	else
		tmp = Float32(fma(Float32(Float32(-1.0) * alpha), Float32(Float32(-1.0) * alpha), Float32(Float32(fma(Float32(t_1 * Float32(0.25)), u0, Float32(t_1 * Float32(0.3333333333333333))) - Float32(Float32(-0.5) * Float32(alpha * alpha))) * u0)) * u0);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \log \left(1 - u0\right)\\
t_1 := \left(\alpha \cdot \alpha\right) \cdot u0\\
\mathbf{if}\;t\_0 \leq -0.041999999433755875:\\
\;\;\;\;-1 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot t\_0\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(t\_1 \cdot 0.25, u0, t\_1 \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (log.f32 (-.f32 #s(literal 1 binary32) u0)) < -0.0419999994

    1. Initial program 97.2%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Add Preprocessing

    if -0.0419999994 < (log.f32 (-.f32 #s(literal 1 binary32) u0))

    1. Initial program 46.2%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u0 around 0

      \[\leadsto \color{blue}{u0 \cdot \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
      2. lower-*.f32N/A

        \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
    5. Applied rewrites98.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333 \cdot \left(\alpha \cdot \alpha\right), 1, 0.25 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot u0\right)\right), u0, 0.5 \cdot \left(\alpha \cdot \alpha\right)\right), u0, \alpha \cdot \alpha\right) \cdot u0} \]
    6. Applied rewrites99.0%

      \[\leadsto \mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(\left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.25, u0, \left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(1 - u0\right) \leq -0.041999999433755875:\\ \;\;\;\;-1 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot \log \left(1 - u0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(\left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.25, u0, \left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.7% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \log \left(1 - u0\right)\\ t_1 := \left(\alpha \cdot \alpha\right) \cdot u0\\ \mathbf{if}\;t\_0 \leq -0.041999999433755875:\\ \;\;\;\;\left(t\_0 \cdot \left(-1 \cdot \alpha\right)\right) \cdot \alpha\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(t\_1 \cdot 0.25, u0, t\_1 \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0\\ \end{array} \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (let* ((t_0 (log (- 1.0 u0))) (t_1 (* (* alpha alpha) u0)))
   (if (<= t_0 -0.041999999433755875)
     (* (* t_0 (* -1.0 alpha)) alpha)
     (*
      (fma
       (* -1.0 alpha)
       (* -1.0 alpha)
       (*
        (-
         (fma (* t_1 0.25) u0 (* t_1 0.3333333333333333))
         (* -0.5 (* alpha alpha)))
        u0))
      u0))))
float code(float alpha, float u0) {
	float t_0 = logf((1.0f - u0));
	float t_1 = (alpha * alpha) * u0;
	float tmp;
	if (t_0 <= -0.041999999433755875f) {
		tmp = (t_0 * (-1.0f * alpha)) * alpha;
	} else {
		tmp = fmaf((-1.0f * alpha), (-1.0f * alpha), ((fmaf((t_1 * 0.25f), u0, (t_1 * 0.3333333333333333f)) - (-0.5f * (alpha * alpha))) * u0)) * u0;
	}
	return tmp;
}
function code(alpha, u0)
	t_0 = log(Float32(Float32(1.0) - u0))
	t_1 = Float32(Float32(alpha * alpha) * u0)
	tmp = Float32(0.0)
	if (t_0 <= Float32(-0.041999999433755875))
		tmp = Float32(Float32(t_0 * Float32(Float32(-1.0) * alpha)) * alpha);
	else
		tmp = Float32(fma(Float32(Float32(-1.0) * alpha), Float32(Float32(-1.0) * alpha), Float32(Float32(fma(Float32(t_1 * Float32(0.25)), u0, Float32(t_1 * Float32(0.3333333333333333))) - Float32(Float32(-0.5) * Float32(alpha * alpha))) * u0)) * u0);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \log \left(1 - u0\right)\\
t_1 := \left(\alpha \cdot \alpha\right) \cdot u0\\
\mathbf{if}\;t\_0 \leq -0.041999999433755875:\\
\;\;\;\;\left(t\_0 \cdot \left(-1 \cdot \alpha\right)\right) \cdot \alpha\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(t\_1 \cdot 0.25, u0, t\_1 \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (log.f32 (-.f32 #s(literal 1 binary32) u0)) < -0.0419999994

    1. Initial program 97.2%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f32N/A

        \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)} \]
      2. lift-neg.f32N/A

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\alpha\right)\right)} \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
      3. lift-*.f32N/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\alpha\right)\right) \cdot \alpha\right)} \cdot \log \left(1 - u0\right) \]
      4. distribute-lft-neg-outN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\alpha \cdot \alpha\right)\right)} \cdot \log \left(1 - u0\right) \]
      5. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{\alpha}^{2}}\right)\right) \cdot \log \left(1 - u0\right) \]
      6. mul-1-negN/A

        \[\leadsto \color{blue}{\left(-1 \cdot {\alpha}^{2}\right)} \cdot \log \left(1 - u0\right) \]
      7. lift--.f32N/A

        \[\leadsto \left(-1 \cdot {\alpha}^{2}\right) \cdot \log \color{blue}{\left(1 - u0\right)} \]
      8. lift-log.f32N/A

        \[\leadsto \left(-1 \cdot {\alpha}^{2}\right) \cdot \color{blue}{\log \left(1 - u0\right)} \]
      9. *-commutativeN/A

        \[\leadsto \color{blue}{\log \left(1 - u0\right) \cdot \left(-1 \cdot {\alpha}^{2}\right)} \]
      10. mul-1-negN/A

        \[\leadsto \log \left(1 - u0\right) \cdot \color{blue}{\left(\mathsf{neg}\left({\alpha}^{2}\right)\right)} \]
      11. unpow2N/A

        \[\leadsto \log \left(1 - u0\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\alpha \cdot \alpha}\right)\right) \]
      12. distribute-lft-neg-outN/A

        \[\leadsto \log \left(1 - u0\right) \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\alpha\right)\right) \cdot \alpha\right)} \]
      13. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(\mathsf{neg}\left(\alpha\right)\right)\right) \cdot \alpha} \]
      14. lower-*.f32N/A

        \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(\mathsf{neg}\left(\alpha\right)\right)\right) \cdot \alpha} \]
      15. lower-*.f32N/A

        \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(\mathsf{neg}\left(\alpha\right)\right)\right)} \cdot \alpha \]
      16. lift-log.f32N/A

        \[\leadsto \left(\color{blue}{\log \left(1 - u0\right)} \cdot \left(\mathsf{neg}\left(\alpha\right)\right)\right) \cdot \alpha \]
      17. lift--.f32N/A

        \[\leadsto \left(\log \color{blue}{\left(1 - u0\right)} \cdot \left(\mathsf{neg}\left(\alpha\right)\right)\right) \cdot \alpha \]
      18. mul-1-negN/A

        \[\leadsto \left(\log \left(1 - u0\right) \cdot \color{blue}{\left(-1 \cdot \alpha\right)}\right) \cdot \alpha \]
      19. lower-*.f3296.9

        \[\leadsto \left(\log \left(1 - u0\right) \cdot \color{blue}{\left(-1 \cdot \alpha\right)}\right) \cdot \alpha \]
    4. Applied rewrites96.9%

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

    if -0.0419999994 < (log.f32 (-.f32 #s(literal 1 binary32) u0))

    1. Initial program 46.2%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Add Preprocessing
    3. Taylor expanded in u0 around 0

      \[\leadsto \color{blue}{u0 \cdot \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
      2. lower-*.f32N/A

        \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
    5. Applied rewrites98.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333 \cdot \left(\alpha \cdot \alpha\right), 1, 0.25 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot u0\right)\right), u0, 0.5 \cdot \left(\alpha \cdot \alpha\right)\right), u0, \alpha \cdot \alpha\right) \cdot u0} \]
    6. Applied rewrites99.0%

      \[\leadsto \mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(\left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.25, u0, \left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 93.4% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\alpha \cdot \alpha\right) \cdot u0\\ \mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(t\_0 \cdot 0.25, u0, t\_0 \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0 \end{array} \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (let* ((t_0 (* (* alpha alpha) u0)))
   (*
    (fma
     (* -1.0 alpha)
     (* -1.0 alpha)
     (*
      (-
       (fma (* t_0 0.25) u0 (* t_0 0.3333333333333333))
       (* -0.5 (* alpha alpha)))
      u0))
    u0)))
float code(float alpha, float u0) {
	float t_0 = (alpha * alpha) * u0;
	return fmaf((-1.0f * alpha), (-1.0f * alpha), ((fmaf((t_0 * 0.25f), u0, (t_0 * 0.3333333333333333f)) - (-0.5f * (alpha * alpha))) * u0)) * u0;
}
function code(alpha, u0)
	t_0 = Float32(Float32(alpha * alpha) * u0)
	return Float32(fma(Float32(Float32(-1.0) * alpha), Float32(Float32(-1.0) * alpha), Float32(Float32(fma(Float32(t_0 * Float32(0.25)), u0, Float32(t_0 * Float32(0.3333333333333333))) - Float32(Float32(-0.5) * Float32(alpha * alpha))) * u0)) * u0)
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\alpha \cdot \alpha\right) \cdot u0\\
\mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(t\_0 \cdot 0.25, u0, t\_0 \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0
\end{array}
\end{array}
Derivation
  1. Initial program 53.3%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. Add Preprocessing
  3. Taylor expanded in u0 around 0

    \[\leadsto \color{blue}{u0 \cdot \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right)} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
    2. lower-*.f32N/A

      \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
  5. Applied rewrites92.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333 \cdot \left(\alpha \cdot \alpha\right), 1, 0.25 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot u0\right)\right), u0, 0.5 \cdot \left(\alpha \cdot \alpha\right)\right), u0, \alpha \cdot \alpha\right) \cdot u0} \]
  6. Applied rewrites93.0%

    \[\leadsto \mathsf{fma}\left(-1 \cdot \alpha, -1 \cdot \alpha, \left(\mathsf{fma}\left(\left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.25, u0, \left(\left(\alpha \cdot \alpha\right) \cdot u0\right) \cdot 0.3333333333333333\right) - -0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0\right) \cdot u0 \]
  7. Add Preprocessing

Alternative 5: 92.6% accurate, N/A× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\alpha \cdot \alpha, 0.25, \mathsf{fma}\left(\frac{\alpha \cdot \alpha}{u0}, 0.3333333333333333, \mathsf{fma}\left({\left(\frac{\alpha}{u0}\right)}^{2}, 0.5, \frac{\alpha \cdot \alpha}{\left(u0 \cdot u0\right) \cdot u0}\right)\right)\right) \cdot {\left(u0 \cdot u0\right)}^{2} \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (*
  (fma
   (* alpha alpha)
   0.25
   (fma
    (/ (* alpha alpha) u0)
    0.3333333333333333
    (fma (pow (/ alpha u0) 2.0) 0.5 (/ (* alpha alpha) (* (* u0 u0) u0)))))
  (pow (* u0 u0) 2.0)))
float code(float alpha, float u0) {
	return fmaf((alpha * alpha), 0.25f, fmaf(((alpha * alpha) / u0), 0.3333333333333333f, fmaf(powf((alpha / u0), 2.0f), 0.5f, ((alpha * alpha) / ((u0 * u0) * u0))))) * powf((u0 * u0), 2.0f);
}
function code(alpha, u0)
	return Float32(fma(Float32(alpha * alpha), Float32(0.25), fma(Float32(Float32(alpha * alpha) / u0), Float32(0.3333333333333333), fma((Float32(alpha / u0) ^ Float32(2.0)), Float32(0.5), Float32(Float32(alpha * alpha) / Float32(Float32(u0 * u0) * u0))))) * (Float32(u0 * u0) ^ Float32(2.0)))
end
\begin{array}{l}

\\
\mathsf{fma}\left(\alpha \cdot \alpha, 0.25, \mathsf{fma}\left(\frac{\alpha \cdot \alpha}{u0}, 0.3333333333333333, \mathsf{fma}\left({\left(\frac{\alpha}{u0}\right)}^{2}, 0.5, \frac{\alpha \cdot \alpha}{\left(u0 \cdot u0\right) \cdot u0}\right)\right)\right) \cdot {\left(u0 \cdot u0\right)}^{2}
\end{array}
Derivation
  1. Initial program 53.3%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. Add Preprocessing
  3. Taylor expanded in u0 around 0

    \[\leadsto \color{blue}{u0 \cdot \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right)} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
    2. lower-*.f32N/A

      \[\leadsto \left(u0 \cdot \left(\frac{1}{2} \cdot {\alpha}^{2} + u0 \cdot \left(\frac{1}{4} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{3} \cdot {\alpha}^{2}\right)\right) + {\alpha}^{2}\right) \cdot \color{blue}{u0} \]
  5. Applied rewrites92.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333 \cdot \left(\alpha \cdot \alpha\right), 1, 0.25 \cdot \left(\left(\alpha \cdot \alpha\right) \cdot u0\right)\right), u0, 0.5 \cdot \left(\alpha \cdot \alpha\right)\right), u0, \alpha \cdot \alpha\right) \cdot u0} \]
  6. Taylor expanded in u0 around inf

    \[\leadsto {u0}^{4} \cdot \color{blue}{\left(\frac{1}{4} \cdot {\alpha}^{2} + \left(\frac{1}{3} \cdot \frac{{\alpha}^{2}}{u0} + \left(\frac{1}{2} \cdot \frac{{\alpha}^{2}}{{u0}^{2}} + \frac{{\alpha}^{2}}{{u0}^{3}}\right)\right)\right)} \]
  7. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(\frac{1}{4} \cdot {\alpha}^{2} + \left(\frac{1}{3} \cdot \frac{{\alpha}^{2}}{u0} + \left(\frac{1}{2} \cdot \frac{{\alpha}^{2}}{{u0}^{2}} + \frac{{\alpha}^{2}}{{u0}^{3}}\right)\right)\right) \cdot {u0}^{\color{blue}{4}} \]
    2. lower-*.f32N/A

      \[\leadsto \left(\frac{1}{4} \cdot {\alpha}^{2} + \left(\frac{1}{3} \cdot \frac{{\alpha}^{2}}{u0} + \left(\frac{1}{2} \cdot \frac{{\alpha}^{2}}{{u0}^{2}} + \frac{{\alpha}^{2}}{{u0}^{3}}\right)\right)\right) \cdot {u0}^{\color{blue}{4}} \]
  8. Applied rewrites92.2%

    \[\leadsto \mathsf{fma}\left(\alpha \cdot \alpha, 0.25, \mathsf{fma}\left(\frac{\alpha \cdot \alpha}{u0}, 0.3333333333333333, \mathsf{fma}\left({\left(\frac{\alpha}{u0}\right)}^{2}, 0.5, \frac{\alpha \cdot \alpha}{\left(u0 \cdot u0\right) \cdot u0}\right)\right)\right) \cdot \color{blue}{{\left(u0 \cdot u0\right)}^{2}} \]
  9. Add Preprocessing

Reproduce

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