Beckmann Distribution sample, tan2theta, alphax == alphay

Percentage Accurate: 56.2% → 98.6%
Time: 7.5s
Alternatives: 11
Speedup: 2.3×

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}

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 11 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: 56.2% 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: 98.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;u0 \leq 0.03500000014901161:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u0, 0.3333333333333333\right), u0, 0.5\right) \cdot \alpha\right) \cdot \alpha\right) \cdot u0, u0, \left(\alpha \cdot \alpha\right) \cdot u0\right)\\

\mathbf{else}:\\
\;\;\;\;\left(-\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u0 < 0.0350000001

    1. Initial program 48.8%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. 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)} \]
    3. Applied rewrites98.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\left(\alpha \cdot \alpha\right) \cdot 0.25, u0, \left(\alpha \cdot \alpha\right) \cdot 0.3333333333333333\right), u0, \left(\alpha \cdot \alpha\right) \cdot 0.5\right), u0, \alpha \cdot \alpha\right) \cdot u0} \]
    4. Applied rewrites98.9%

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(u0, \mathsf{fma}\left(0.25, u0, 0.3333333333333333\right) \cdot \left(\alpha \cdot \alpha\right), 0.5 \cdot \left(\alpha \cdot \alpha\right)\right) \cdot u0, \color{blue}{u0}, \left(\alpha \cdot \alpha\right) \cdot u0\right) \]
    5. Applied rewrites98.9%

      \[\leadsto \mathsf{fma}\left(\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u0, 0.3333333333333333\right), u0, 0.5\right) \cdot \alpha\right) \cdot \alpha\right) \cdot u0, u0, \left(\alpha \cdot \alpha\right) \cdot u0\right) \]

    if 0.0350000001 < u0

    1. Initial program 96.6%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites96.6%

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

      \[\leadsto \color{blue}{\left(-\log \left(1 - u0\right) \cdot \alpha\right)} \cdot \alpha \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 98.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;u0 \leq 0.03500000014901161:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u0, 0.3333333333333333\right), u0, 0.5\right) \cdot \left(\alpha \cdot \alpha\right), u0, \alpha \cdot \alpha\right) \cdot u0\\

\mathbf{else}:\\
\;\;\;\;\left(-\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u0 < 0.0350000001

    1. Initial program 48.8%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. 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)} \]
    3. Applied rewrites98.9%

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

      \[\leadsto \mathsf{fma}\left({\alpha}^{2} \cdot \left(\frac{1}{2} + u0 \cdot \left(\frac{1}{3} + \frac{1}{4} \cdot u0\right)\right), u0, \alpha \cdot \alpha\right) \cdot u0 \]
    5. Applied rewrites98.9%

      \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u0, 0.3333333333333333\right), u0, 0.5\right) \cdot \left(\alpha \cdot \alpha\right), u0, \alpha \cdot \alpha\right) \cdot u0 \]

    if 0.0350000001 < u0

    1. Initial program 96.6%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites96.6%

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

      \[\leadsto \color{blue}{\left(-\log \left(1 - u0\right) \cdot \alpha\right)} \cdot \alpha \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 98.6% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;u0 \leq 0.03500000014901161:\\
\;\;\;\;\mathsf{fma}\left(u0 \cdot u0, \mathsf{fma}\left(\mathsf{fma}\left(0.25, u0, 0.3333333333333333\right), u0, 0.5\right), u0\right) \cdot \left(\alpha \cdot \alpha\right)\\

\mathbf{else}:\\
\;\;\;\;\left(-\log \left(1 - u0\right) \cdot \alpha\right) \cdot \alpha\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if u0 < 0.0350000001

    1. Initial program 48.8%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. 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)} \]
    3. Applied rewrites98.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\left(\alpha \cdot \alpha\right) \cdot 0.25, u0, \left(\alpha \cdot \alpha\right) \cdot 0.3333333333333333\right), u0, \left(\alpha \cdot \alpha\right) \cdot 0.5\right), u0, \alpha \cdot \alpha\right) \cdot u0} \]
    4. Applied rewrites98.9%

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

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

      \[\leadsto \mathsf{fma}\left(u0 \cdot u0, \mathsf{fma}\left(\mathsf{fma}\left(0.25, u0, 0.3333333333333333\right), u0, 0.5\right), u0\right) \cdot \color{blue}{\left(\alpha \cdot \alpha\right)} \]

    if 0.0350000001 < u0

    1. Initial program 96.6%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites96.6%

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

      \[\leadsto \color{blue}{\left(-\log \left(1 - u0\right) \cdot \alpha\right)} \cdot \alpha \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 98.3% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u0, 0.3333333333333333\right), u0, 0.5\right), u0, 1\right) \cdot \left(\alpha \cdot \alpha\right)\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.0399999991

    1. Initial program 96.7%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites96.7%

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

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

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

    1. Initial program 49.0%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. 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)} \]
    3. Applied rewrites98.9%

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

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

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

Alternative 5: 98.1% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(\alpha \cdot \mathsf{fma}\left(0.3333333333333333, u0, 0.5\right), u0, \alpha\right) \cdot u0\right) \cdot \alpha\\


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

    1. Initial program 95.3%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites95.3%

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

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

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

    1. Initial program 46.5%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites46.5%

      \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
    3. Taylor expanded in u0 around 0

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

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

      \[\leadsto \left(\mathsf{fma}\left(\alpha \cdot \left(\frac{1}{2} + \frac{1}{3} \cdot u0\right), u0, \alpha\right) \cdot u0\right) \cdot \alpha \]
    6. Applied rewrites98.8%

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

Alternative 6: 97.8% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 95.7%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites95.6%

      \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
    3. Applied rewrites95.6%

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

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

    1. Initial program 47.1%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites47.1%

      \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
    3. Taylor expanded in u0 around 0

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

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

      \[\leadsto \left(\left(\alpha \cdot \left(1 + u0 \cdot \left(\frac{1}{2} + \frac{1}{3} \cdot u0\right)\right)\right) \cdot u0\right) \cdot \alpha \]
    6. Applied rewrites98.4%

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

Alternative 7: 96.7% accurate, 0.6× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(0.5, u0 \cdot \alpha, \alpha\right) \cdot u0\right) \cdot \alpha\\


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

    1. Initial program 93.2%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites93.2%

      \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
    3. Applied rewrites93.2%

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

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

    1. Initial program 43.2%

      \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    2. Applied rewrites43.2%

      \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
    3. Taylor expanded in u0 around 0

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

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

      \[\leadsto \left(\left(\alpha + \frac{1}{2} \cdot \left(\alpha \cdot u0\right)\right) \cdot u0\right) \cdot \alpha \]
    6. Applied rewrites97.9%

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

Alternative 8: 87.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \left(\mathsf{fma}\left(0.5 \cdot \alpha, u0, \alpha\right) \cdot u0\right) \cdot \alpha \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (* (* (fma (* 0.5 alpha) u0 alpha) u0) alpha))
float code(float alpha, float u0) {
	return (fmaf((0.5f * alpha), u0, alpha) * u0) * alpha;
}
function code(alpha, u0)
	return Float32(Float32(fma(Float32(Float32(0.5) * alpha), u0, alpha) * u0) * alpha)
end
\begin{array}{l}

\\
\left(\mathsf{fma}\left(0.5 \cdot \alpha, u0, \alpha\right) \cdot u0\right) \cdot \alpha
\end{array}
Derivation
  1. Initial program 56.2%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. Applied rewrites56.2%

    \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
  3. Taylor expanded in u0 around 0

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

    \[\leadsto \color{blue}{\left(\mathsf{fma}\left(0.5 \cdot \alpha, u0, \alpha\right) \cdot u0\right)} \cdot \alpha \]
  5. Add Preprocessing

Alternative 9: 87.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \left(\mathsf{fma}\left(0.5, u0 \cdot \alpha, \alpha\right) \cdot u0\right) \cdot \alpha \end{array} \]
(FPCore (alpha u0)
 :precision binary32
 (* (* (fma 0.5 (* u0 alpha) alpha) u0) alpha))
float code(float alpha, float u0) {
	return (fmaf(0.5f, (u0 * alpha), alpha) * u0) * alpha;
}
function code(alpha, u0)
	return Float32(Float32(fma(Float32(0.5), Float32(u0 * alpha), alpha) * u0) * alpha)
end
\begin{array}{l}

\\
\left(\mathsf{fma}\left(0.5, u0 \cdot \alpha, \alpha\right) \cdot u0\right) \cdot \alpha
\end{array}
Derivation
  1. Initial program 56.2%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. Applied rewrites56.2%

    \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
  3. Taylor expanded in u0 around 0

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

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

    \[\leadsto \left(\left(\alpha + \frac{1}{2} \cdot \left(\alpha \cdot u0\right)\right) \cdot u0\right) \cdot \alpha \]
  6. Applied rewrites87.1%

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

Alternative 10: 86.9% accurate, 1.1× speedup?

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

\\
\left(\left(\mathsf{fma}\left(u0, 0.5, 1\right) \cdot \alpha\right) \cdot u0\right) \cdot \alpha
\end{array}
Derivation
  1. Initial program 56.2%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. Applied rewrites56.2%

    \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
  3. Taylor expanded in u0 around 0

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

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

    \[\leadsto \left(\left(\alpha + \frac{1}{2} \cdot \left(\alpha \cdot u0\right)\right) \cdot u0\right) \cdot \alpha \]
  6. Applied rewrites87.1%

    \[\leadsto \left(\mathsf{fma}\left(0.5, u0 \cdot \alpha, \alpha\right) \cdot u0\right) \cdot \alpha \]
  7. Taylor expanded in alpha around 0

    \[\leadsto \left(\left(\alpha \cdot \left(1 + \frac{1}{2} \cdot u0\right)\right) \cdot u0\right) \cdot \alpha \]
  8. Applied rewrites86.9%

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

Alternative 11: 74.3% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \left(\alpha \cdot \alpha\right) \cdot u0 \end{array} \]
(FPCore (alpha u0) :precision binary32 (* (* alpha alpha) u0))
float code(float alpha, float u0) {
	return (alpha * alpha) * 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) * u0
end function
function code(alpha, u0)
	return Float32(Float32(alpha * alpha) * u0)
end
function tmp = code(alpha, u0)
	tmp = (alpha * alpha) * u0;
end
\begin{array}{l}

\\
\left(\alpha \cdot \alpha\right) \cdot u0
\end{array}
Derivation
  1. Initial program 56.2%

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

    \[\leadsto \color{blue}{{\alpha}^{2} \cdot u0} \]
  3. Applied rewrites74.3%

    \[\leadsto \color{blue}{\left(\alpha \cdot \alpha\right) \cdot u0} \]
  4. Add Preprocessing

Reproduce

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