Beckmann Distribution sample, tan2theta, alphax == alphay

Percentage Accurate: 56.5% → 99.0%
Time: 4.1s
Alternatives: 9
Speedup: 2.4×

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)\]
\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
(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
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)

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 9 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.5% accurate, 1.0× speedup?

\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
(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
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right)

Alternative 1: 99.0% accurate, 0.9× speedup?

\[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \mathsf{log1p}\left(-u0\right) \]
(FPCore (alpha u0)
  :precision binary32
  (* (* (- alpha) alpha) (log1p (- u0))))
float code(float alpha, float u0) {
	return (-alpha * alpha) * log1pf(-u0);
}
function code(alpha, u0)
	return Float32(Float32(Float32(-alpha) * alpha) * log1p(Float32(-u0)))
end
\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \mathsf{log1p}\left(-u0\right)
Derivation
  1. Initial program 56.5%

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

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

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

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

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{neg}\left(u0\right)\right)} \]
    5. lower-neg.f3299.0%

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

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

Alternative 2: 99.0% accurate, 0.9× speedup?

\[\left(\mathsf{log1p}\left(-u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
(FPCore (alpha u0)
  :precision binary32
  (* (* (log1p (- u0)) (- alpha)) alpha))
float code(float alpha, float u0) {
	return (log1pf(-u0) * -alpha) * alpha;
}
function code(alpha, u0)
	return Float32(Float32(log1p(Float32(-u0)) * Float32(-alpha)) * alpha)
end
\left(\mathsf{log1p}\left(-u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha
Derivation
  1. Initial program 56.5%

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
  2. 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-*.f32N/A

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right)} \cdot \alpha \]
    8. lower-*.f3256.5%

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

    \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
  4. Step-by-step derivation
    1. lift-log.f32N/A

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

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

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

      \[\leadsto \left(\log \left(1 + \color{blue}{\left(-u0\right)}\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
    5. lower-log1p.f3299.0%

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

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

Alternative 3: 96.8% accurate, 0.8× speedup?

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

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


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

    1. Initial program 56.5%

      \[\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}{3} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{2} \cdot {\alpha}^{2}\right) + {\alpha}^{2}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f32N/A

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

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

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

        \[\leadsto u0 \cdot \mathsf{fma}\left(u0, \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot \color{blue}{u0}, \frac{1}{2} \cdot {\alpha}^{2}\right), {\alpha}^{2}\right) \]
      5. lower-pow.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(u0, \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right), {\alpha}^{2}\right) \]
      6. lower-*.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(u0, \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right), {\alpha}^{2}\right) \]
      7. lower-pow.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(u0, \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right), {\alpha}^{2}\right) \]
      8. lower-pow.f3291.1%

        \[\leadsto u0 \cdot \mathsf{fma}\left(u0, \mathsf{fma}\left(0.3333333333333333, {\alpha}^{2} \cdot u0, \color{blue}{0.5 \cdot {\alpha}^{2}}\right), {\alpha}^{2}\right) \]
    4. Applied rewrites91.1%

      \[\leadsto \color{blue}{u0 \cdot \mathsf{fma}\left(u0, \mathsf{fma}\left(0.3333333333333333, {\alpha}^{2} \cdot u0, 0.5 \cdot {\alpha}^{2}\right), {\alpha}^{2}\right)} \]
    5. Step-by-step derivation
      1. lift-fma.f32N/A

        \[\leadsto u0 \cdot \left(u0 \cdot \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right) + \color{blue}{{\alpha}^{2}}\right) \]
      2. +-commutativeN/A

        \[\leadsto u0 \cdot \left({\alpha}^{2} + \color{blue}{u0 \cdot \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right)}\right) \]
      3. lift-pow.f32N/A

        \[\leadsto u0 \cdot \left({\alpha}^{2} + \color{blue}{u0} \cdot \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right)\right) \]
      4. unpow2N/A

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

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \color{blue}{\alpha}, u0 \cdot \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \mathsf{fma}\left(\frac{1}{3}, {\alpha}^{2} \cdot u0, \frac{1}{2} \cdot {\alpha}^{2}\right) \cdot u0\right) \]
      7. lower-*.f3291.3%

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \mathsf{fma}\left(0.3333333333333333, {\alpha}^{2} \cdot u0, 0.5 \cdot {\alpha}^{2}\right) \cdot u0\right) \]
      8. lift-fma.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\frac{1}{3} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{2} \cdot {\alpha}^{2}\right) \cdot u0\right) \]
      9. lift-*.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\frac{1}{3} \cdot \left({\alpha}^{2} \cdot u0\right) + \frac{1}{2} \cdot {\alpha}^{2}\right) \cdot u0\right) \]
      10. *-commutativeN/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\frac{1}{3} \cdot \left(u0 \cdot {\alpha}^{2}\right) + \frac{1}{2} \cdot {\alpha}^{2}\right) \cdot u0\right) \]
      11. associate-*r*N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\left(\frac{1}{3} \cdot u0\right) \cdot {\alpha}^{2} + \frac{1}{2} \cdot {\alpha}^{2}\right) \cdot u0\right) \]
      12. lift-*.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\left(\frac{1}{3} \cdot u0\right) \cdot {\alpha}^{2} + \frac{1}{2} \cdot {\alpha}^{2}\right) \cdot u0\right) \]
      13. distribute-rgt-outN/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left({\alpha}^{2} \cdot \left(\frac{1}{3} \cdot u0 + \frac{1}{2}\right)\right) \cdot u0\right) \]
      14. lower-*.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left({\alpha}^{2} \cdot \left(\frac{1}{3} \cdot u0 + \frac{1}{2}\right)\right) \cdot u0\right) \]
      15. lift-pow.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left({\alpha}^{2} \cdot \left(\frac{1}{3} \cdot u0 + \frac{1}{2}\right)\right) \cdot u0\right) \]
      16. unpow2N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\left(\alpha \cdot \alpha\right) \cdot \left(\frac{1}{3} \cdot u0 + \frac{1}{2}\right)\right) \cdot u0\right) \]
      17. lower-*.f32N/A

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\left(\alpha \cdot \alpha\right) \cdot \left(\frac{1}{3} \cdot u0 + \frac{1}{2}\right)\right) \cdot u0\right) \]
      18. lower-fma.f3291.3%

        \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\left(\alpha \cdot \alpha\right) \cdot \mathsf{fma}\left(0.3333333333333333, u0, 0.5\right)\right) \cdot u0\right) \]
    6. Applied rewrites91.3%

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

      \[\leadsto u0 \cdot \mathsf{fma}\left(\alpha, \alpha, \left(\left(\alpha \cdot \alpha\right) \cdot \frac{1}{2}\right) \cdot u0\right) \]
    8. Step-by-step derivation
      1. Applied rewrites87.0%

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

      if 0.00400000019 < u0

      1. Initial program 56.5%

        \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
    9. Recombined 2 regimes into one program.
    10. Add Preprocessing

    Alternative 4: 96.7% accurate, 0.8× speedup?

    \[\begin{array}{l} t_0 := \left(-\alpha\right) \cdot \alpha\\ \mathbf{if}\;u0 \leq 0.004000000189989805:\\ \;\;\;\;t\_0 \cdot \left(\left(-0.5 \cdot u0\right) \cdot u0 - u0\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \log \left(1 - u0\right)\\ \end{array} \]
    (FPCore (alpha u0)
      :precision binary32
      (let* ((t_0 (* (- alpha) alpha)))
      (if (<= u0 0.004000000189989805)
        (* t_0 (- (* (* -0.5 u0) u0) u0))
        (* t_0 (log (- 1.0 u0))))))
    float code(float alpha, float u0) {
    	float t_0 = -alpha * alpha;
    	float tmp;
    	if (u0 <= 0.004000000189989805f) {
    		tmp = t_0 * (((-0.5f * u0) * u0) - u0);
    	} else {
    		tmp = t_0 * logf((1.0f - u0));
    	}
    	return tmp;
    }
    
    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
        real(4) :: t_0
        real(4) :: tmp
        t_0 = -alpha * alpha
        if (u0 <= 0.004000000189989805e0) then
            tmp = t_0 * ((((-0.5e0) * u0) * u0) - u0)
        else
            tmp = t_0 * log((1.0e0 - u0))
        end if
        code = tmp
    end function
    
    function code(alpha, u0)
    	t_0 = Float32(Float32(-alpha) * alpha)
    	tmp = Float32(0.0)
    	if (u0 <= Float32(0.004000000189989805))
    		tmp = Float32(t_0 * Float32(Float32(Float32(Float32(-0.5) * u0) * u0) - u0));
    	else
    		tmp = Float32(t_0 * log(Float32(Float32(1.0) - u0)));
    	end
    	return tmp
    end
    
    function tmp_2 = code(alpha, u0)
    	t_0 = -alpha * alpha;
    	tmp = single(0.0);
    	if (u0 <= single(0.004000000189989805))
    		tmp = t_0 * (((single(-0.5) * u0) * u0) - u0);
    	else
    		tmp = t_0 * log((single(1.0) - u0));
    	end
    	tmp_2 = tmp;
    end
    
    \begin{array}{l}
    t_0 := \left(-\alpha\right) \cdot \alpha\\
    \mathbf{if}\;u0 \leq 0.004000000189989805:\\
    \;\;\;\;t\_0 \cdot \left(\left(-0.5 \cdot u0\right) \cdot u0 - u0\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0 \cdot \log \left(1 - u0\right)\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if u0 < 0.00400000019

      1. Initial program 56.5%

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

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

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 - \color{blue}{1}\right)\right) \]
        3. lower-*.f3286.7%

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0 - 1\right)\right) \]
      4. Applied rewrites86.7%

        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(u0 \cdot \left(-0.5 \cdot u0 - 1\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f32N/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 - \color{blue}{1}\right)\right) \]
        3. sub-flipN/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 + -1\right)\right) \]
        5. distribute-rgt-inN/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(\frac{-1}{2} \cdot u0\right) \cdot u0 + \left(\mathsf{neg}\left(u0\right)\right)\right) \]
        7. sub-flip-reverseN/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(\frac{-1}{2} \cdot u0\right) \cdot u0 - \color{blue}{u0}\right) \]
        9. lower-*.f3286.9%

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(-0.5 \cdot u0\right) \cdot u0 - u0\right) \]
      6. Applied rewrites86.9%

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

      if 0.00400000019 < u0

      1. Initial program 56.5%

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

    Alternative 5: 96.7% accurate, 0.8× speedup?

    \[\begin{array}{l} \mathbf{if}\;u0 \leq 0.004000000189989805:\\ \;\;\;\;\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(-0.5 \cdot u0\right) \cdot u0 - u0\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha\\ \end{array} \]
    (FPCore (alpha u0)
      :precision binary32
      (if (<= u0 0.004000000189989805)
      (* (* (- alpha) alpha) (- (* (* -0.5 u0) u0) u0))
      (* (* (log (- 1.0 u0)) (- alpha)) alpha)))
    float code(float alpha, float u0) {
    	float tmp;
    	if (u0 <= 0.004000000189989805f) {
    		tmp = (-alpha * alpha) * (((-0.5f * u0) * u0) - u0);
    	} else {
    		tmp = (logf((1.0f - u0)) * -alpha) * alpha;
    	}
    	return tmp;
    }
    
    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
        real(4) :: tmp
        if (u0 <= 0.004000000189989805e0) then
            tmp = (-alpha * alpha) * ((((-0.5e0) * u0) * u0) - u0)
        else
            tmp = (log((1.0e0 - u0)) * -alpha) * alpha
        end if
        code = tmp
    end function
    
    function code(alpha, u0)
    	tmp = Float32(0.0)
    	if (u0 <= Float32(0.004000000189989805))
    		tmp = Float32(Float32(Float32(-alpha) * alpha) * Float32(Float32(Float32(Float32(-0.5) * u0) * u0) - u0));
    	else
    		tmp = Float32(Float32(log(Float32(Float32(1.0) - u0)) * Float32(-alpha)) * alpha);
    	end
    	return tmp
    end
    
    function tmp_2 = code(alpha, u0)
    	tmp = single(0.0);
    	if (u0 <= single(0.004000000189989805))
    		tmp = (-alpha * alpha) * (((single(-0.5) * u0) * u0) - u0);
    	else
    		tmp = (log((single(1.0) - u0)) * -alpha) * alpha;
    	end
    	tmp_2 = tmp;
    end
    
    \begin{array}{l}
    \mathbf{if}\;u0 \leq 0.004000000189989805:\\
    \;\;\;\;\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(-0.5 \cdot u0\right) \cdot u0 - u0\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if u0 < 0.00400000019

      1. Initial program 56.5%

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

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

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 - \color{blue}{1}\right)\right) \]
        3. lower-*.f3286.7%

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(-0.5 \cdot u0 - 1\right)\right) \]
      4. Applied rewrites86.7%

        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(u0 \cdot \left(-0.5 \cdot u0 - 1\right)\right)} \]
      5. Step-by-step derivation
        1. lift-*.f32N/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 - \color{blue}{1}\right)\right) \]
        3. sub-flipN/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(u0 \cdot \left(\frac{-1}{2} \cdot u0 + -1\right)\right) \]
        5. distribute-rgt-inN/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(\frac{-1}{2} \cdot u0\right) \cdot u0 + \left(\mathsf{neg}\left(u0\right)\right)\right) \]
        7. sub-flip-reverseN/A

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

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(\frac{-1}{2} \cdot u0\right) \cdot u0 - \color{blue}{u0}\right) \]
        9. lower-*.f3286.9%

          \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\left(-0.5 \cdot u0\right) \cdot u0 - u0\right) \]
      6. Applied rewrites86.9%

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

      if 0.00400000019 < u0

      1. Initial program 56.5%

        \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
      2. 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-*.f32N/A

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

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

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

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

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

          \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right)} \cdot \alpha \]
        8. lower-*.f3256.5%

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

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

    Alternative 6: 96.7% accurate, 0.8× speedup?

    \[\begin{array}{l} \mathbf{if}\;u0 \leq 0.004000000189989805:\\ \;\;\;\;\left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha\\ \end{array} \]
    (FPCore (alpha u0)
      :precision binary32
      (if (<= u0 0.004000000189989805)
      (* (* u0 (+ alpha (* 0.5 (* alpha u0)))) alpha)
      (* (* (log (- 1.0 u0)) (- alpha)) alpha)))
    float code(float alpha, float u0) {
    	float tmp;
    	if (u0 <= 0.004000000189989805f) {
    		tmp = (u0 * (alpha + (0.5f * (alpha * u0)))) * alpha;
    	} else {
    		tmp = (logf((1.0f - u0)) * -alpha) * alpha;
    	}
    	return tmp;
    }
    
    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
        real(4) :: tmp
        if (u0 <= 0.004000000189989805e0) then
            tmp = (u0 * (alpha + (0.5e0 * (alpha * u0)))) * alpha
        else
            tmp = (log((1.0e0 - u0)) * -alpha) * alpha
        end if
        code = tmp
    end function
    
    function code(alpha, u0)
    	tmp = Float32(0.0)
    	if (u0 <= Float32(0.004000000189989805))
    		tmp = Float32(Float32(u0 * Float32(alpha + Float32(Float32(0.5) * Float32(alpha * u0)))) * alpha);
    	else
    		tmp = Float32(Float32(log(Float32(Float32(1.0) - u0)) * Float32(-alpha)) * alpha);
    	end
    	return tmp
    end
    
    function tmp_2 = code(alpha, u0)
    	tmp = single(0.0);
    	if (u0 <= single(0.004000000189989805))
    		tmp = (u0 * (alpha + (single(0.5) * (alpha * u0)))) * alpha;
    	else
    		tmp = (log((single(1.0) - u0)) * -alpha) * alpha;
    	end
    	tmp_2 = tmp;
    end
    
    \begin{array}{l}
    \mathbf{if}\;u0 \leq 0.004000000189989805:\\
    \;\;\;\;\left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if u0 < 0.00400000019

      1. Initial program 56.5%

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

        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
      3. Step-by-step derivation
        1. lower-*.f3274.1%

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

        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
      5. Step-by-step derivation
        1. lift-*.f32N/A

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

          \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right)} \cdot \left(-1 \cdot u0\right) \]
        3. associate-*l*N/A

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

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

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

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

          \[\leadsto \color{blue}{\left(\left(-1 \cdot u0\right) \cdot \left(-\alpha\right)\right)} \cdot \alpha \]
        8. lower-*.f3274.1%

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

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

          \[\leadsto \left(\left(\mathsf{neg}\left(u0\right)\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
        11. lift-neg.f3274.1%

          \[\leadsto \left(\left(-u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
      6. Applied rewrites74.1%

        \[\leadsto \color{blue}{\left(\left(-u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
      7. 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 \]
      8. Step-by-step derivation
        1. lower-*.f32N/A

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

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

          \[\leadsto \left(u0 \cdot \left(\alpha + \frac{1}{2} \cdot \color{blue}{\left(\alpha \cdot u0\right)}\right)\right) \cdot \alpha \]
        4. lower-*.f3286.9%

          \[\leadsto \left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot \color{blue}{u0}\right)\right)\right) \cdot \alpha \]
      9. Applied rewrites86.9%

        \[\leadsto \color{blue}{\left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right)} \cdot \alpha \]

      if 0.00400000019 < u0

      1. Initial program 56.5%

        \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \log \left(1 - u0\right) \]
      2. 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-*.f32N/A

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

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

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

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

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

          \[\leadsto \color{blue}{\left(\log \left(1 - u0\right) \cdot \left(-\alpha\right)\right)} \cdot \alpha \]
        8. lower-*.f3256.5%

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

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

    Alternative 7: 86.9% accurate, 1.1× speedup?

    \[\left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha \]
    (FPCore (alpha u0)
      :precision binary32
      (* (* u0 (+ alpha (* 0.5 (* alpha u0)))) alpha))
    float code(float alpha, float u0) {
    	return (u0 * (alpha + (0.5f * (alpha * u0)))) * alpha;
    }
    
    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 = (u0 * (alpha + (0.5e0 * (alpha * u0)))) * alpha
    end function
    
    function code(alpha, u0)
    	return Float32(Float32(u0 * Float32(alpha + Float32(Float32(0.5) * Float32(alpha * u0)))) * alpha)
    end
    
    function tmp = code(alpha, u0)
    	tmp = (u0 * (alpha + (single(0.5) * (alpha * u0)))) * alpha;
    end
    
    \left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot u0\right)\right)\right) \cdot \alpha
    
    Derivation
    1. Initial program 56.5%

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

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
    3. Step-by-step derivation
      1. lower-*.f3274.1%

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

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
    5. Step-by-step derivation
      1. lift-*.f32N/A

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

        \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right)} \cdot \left(-1 \cdot u0\right) \]
      3. associate-*l*N/A

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(-1 \cdot u0\right) \cdot \left(-\alpha\right)\right)} \cdot \alpha \]
      8. lower-*.f3274.1%

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

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

        \[\leadsto \left(\left(\mathsf{neg}\left(u0\right)\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
      11. lift-neg.f3274.1%

        \[\leadsto \left(\left(-u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
    6. Applied rewrites74.1%

      \[\leadsto \color{blue}{\left(\left(-u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha} \]
    7. 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 \]
    8. Step-by-step derivation
      1. lower-*.f32N/A

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

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

        \[\leadsto \left(u0 \cdot \left(\alpha + \frac{1}{2} \cdot \color{blue}{\left(\alpha \cdot u0\right)}\right)\right) \cdot \alpha \]
      4. lower-*.f3286.9%

        \[\leadsto \left(u0 \cdot \left(\alpha + 0.5 \cdot \left(\alpha \cdot \color{blue}{u0}\right)\right)\right) \cdot \alpha \]
    9. Applied rewrites86.9%

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

    Alternative 8: 74.1% accurate, 1.8× speedup?

    \[\left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-u0\right) \]
    (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(Float32(-alpha) * alpha) * Float32(-u0))
    end
    
    function tmp = code(alpha, u0)
    	tmp = (-alpha * alpha) * -u0;
    end
    
    \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-u0\right)
    
    Derivation
    1. Initial program 56.5%

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

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
    3. Step-by-step derivation
      1. lower-*.f3274.1%

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

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
    5. Step-by-step derivation
      1. lift-*.f32N/A

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

        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(\mathsf{neg}\left(u0\right)\right) \]
      3. lift-neg.f3274.1%

        \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \left(-u0\right) \]
    6. Applied rewrites74.1%

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

    Alternative 9: 74.1% accurate, 2.4× speedup?

    \[\left(\alpha \cdot u0\right) \cdot \alpha \]
    (FPCore (alpha u0)
      :precision binary32
      (* (* alpha u0) alpha))
    float code(float alpha, float u0) {
    	return (alpha * u0) * alpha;
    }
    
    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 * u0) * alpha
    end function
    
    function code(alpha, u0)
    	return Float32(Float32(alpha * u0) * alpha)
    end
    
    function tmp = code(alpha, u0)
    	tmp = (alpha * u0) * alpha;
    end
    
    \left(\alpha \cdot u0\right) \cdot \alpha
    
    Derivation
    1. Initial program 56.5%

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

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
    3. Step-by-step derivation
      1. lower-*.f3274.1%

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

      \[\leadsto \left(\left(-\alpha\right) \cdot \alpha\right) \cdot \color{blue}{\left(-1 \cdot u0\right)} \]
    5. Step-by-step derivation
      1. lift-*.f32N/A

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

        \[\leadsto \color{blue}{\left(\left(-\alpha\right) \cdot \alpha\right)} \cdot \left(-1 \cdot u0\right) \]
      3. associate-*l*N/A

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(-1 \cdot u0\right) \cdot \left(-\alpha\right)\right)} \cdot \alpha \]
      8. lower-*.f3274.1%

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

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

        \[\leadsto \left(\left(\mathsf{neg}\left(u0\right)\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
      11. lift-neg.f3274.1%

        \[\leadsto \left(\left(-u0\right) \cdot \left(-\alpha\right)\right) \cdot \alpha \]
    6. Applied rewrites74.1%

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

      \[\leadsto \color{blue}{\left(\alpha \cdot u0\right)} \cdot \alpha \]
    8. Step-by-step derivation
      1. lower-*.f3274.1%

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

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

    Reproduce

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