a parameter of renormalized beta distribution

Percentage Accurate: 99.8% → 99.7%
Time: 4.4s
Alternatives: 7
Speedup: N/A×

Specification

?
\[\left(0 < m \land 0 < v\right) \land v < 0.25\]
\[\begin{array}{l} \\ \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \end{array} \]
(FPCore (m v) :precision binary64 (* (- (/ (* m (- 1.0 m)) v) 1.0) m))
double code(double m, double v) {
	return (((m * (1.0 - m)) / v) - 1.0) * m;
}
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(8) function code(m, v)
use fmin_fmax_functions
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    code = (((m * (1.0d0 - m)) / v) - 1.0d0) * m
end function
public static double code(double m, double v) {
	return (((m * (1.0 - m)) / v) - 1.0) * m;
}
def code(m, v):
	return (((m * (1.0 - m)) / v) - 1.0) * m
function code(m, v)
	return Float64(Float64(Float64(Float64(m * Float64(1.0 - m)) / v) - 1.0) * m)
end
function tmp = code(m, v)
	tmp = (((m * (1.0 - m)) / v) - 1.0) * m;
end
code[m_, v_] := N[(N[(N[(N[(m * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * m), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 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: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \end{array} \]
(FPCore (m v) :precision binary64 (* (- (/ (* m (- 1.0 m)) v) 1.0) m))
double code(double m, double v) {
	return (((m * (1.0 - m)) / v) - 1.0) * m;
}
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(8) function code(m, v)
use fmin_fmax_functions
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    code = (((m * (1.0d0 - m)) / v) - 1.0d0) * m
end function
public static double code(double m, double v) {
	return (((m * (1.0 - m)) / v) - 1.0) * m;
}
def code(m, v):
	return (((m * (1.0 - m)) / v) - 1.0) * m
function code(m, v)
	return Float64(Float64(Float64(Float64(m * Float64(1.0 - m)) / v) - 1.0) * m)
end
function tmp = code(m, v)
	tmp = (((m * (1.0 - m)) / v) - 1.0) * m;
end
code[m_, v_] := N[(N[(N[(N[(m * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * m), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m
\end{array}

Alternative 1: 99.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 2.05 \cdot 10^{-16}:\\ \;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(1 - m\right) \cdot m\right) \cdot m}{v}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (if (<= m 2.05e-16) (fma (/ m v) m (- m)) (/ (* (* (- 1.0 m) m) m) v)))
double code(double m, double v) {
	double tmp;
	if (m <= 2.05e-16) {
		tmp = fma((m / v), m, -m);
	} else {
		tmp = (((1.0 - m) * m) * m) / v;
	}
	return tmp;
}
function code(m, v)
	tmp = 0.0
	if (m <= 2.05e-16)
		tmp = fma(Float64(m / v), m, Float64(-m));
	else
		tmp = Float64(Float64(Float64(Float64(1.0 - m) * m) * m) / v);
	end
	return tmp
end
code[m_, v_] := If[LessEqual[m, 2.05e-16], N[(N[(m / v), $MachinePrecision] * m + (-m)), $MachinePrecision], N[(N[(N[(N[(1.0 - m), $MachinePrecision] * m), $MachinePrecision] * m), $MachinePrecision] / v), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 2.05 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(1 - m\right) \cdot m\right) \cdot m}{v}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < 2.05000000000000003e-16

    1. Initial program 99.8%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \cdot m \]
      2. metadata-evalN/A

        \[\leadsto \left(\frac{m \cdot \left(1 - m\right)}{v} - \color{blue}{1 \cdot 1}\right) \cdot m \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right)} \cdot m \]
      4. lift-/.f64N/A

        \[\leadsto \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
      5. lift-*.f64N/A

        \[\leadsto \left(\frac{\color{blue}{m \cdot \left(1 - m\right)}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
      6. *-commutativeN/A

        \[\leadsto \left(\frac{\color{blue}{\left(1 - m\right) \cdot m}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
      7. associate-/l*N/A

        \[\leadsto \left(\color{blue}{\left(1 - m\right) \cdot \frac{m}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
      8. metadata-evalN/A

        \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1} \cdot 1\right) \cdot m \]
      9. metadata-evalN/A

        \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1}\right) \cdot m \]
      10. metadata-evalN/A

        \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right) \cdot m \]
      11. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, \mathsf{neg}\left(1\right)\right)} \cdot m \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(1 - m, \color{blue}{\frac{m}{v}}, \mathsf{neg}\left(1\right)\right) \cdot m \]
      13. metadata-eval99.8

        \[\leadsto \mathsf{fma}\left(1 - m, \frac{m}{v}, \color{blue}{-1}\right) \cdot m \]
    4. Applied rewrites99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \cdot m \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right) \cdot m} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{m \cdot \mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \]
      3. lift-fma.f64N/A

        \[\leadsto m \cdot \color{blue}{\left(\left(1 - m\right) \cdot \frac{m}{v} + -1\right)} \]
      4. lift-/.f64N/A

        \[\leadsto m \cdot \left(\left(1 - m\right) \cdot \color{blue}{\frac{m}{v}} + -1\right) \]
      5. associate-*r/N/A

        \[\leadsto m \cdot \left(\color{blue}{\frac{\left(1 - m\right) \cdot m}{v}} + -1\right) \]
      6. associate-*l/N/A

        \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v} \cdot m} + -1\right) \]
      7. lift-/.f64N/A

        \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v}} \cdot m + -1\right) \]
      8. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\left(\frac{1 - m}{v} \cdot m\right) \cdot m + -1 \cdot m} \]
      9. *-commutativeN/A

        \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{m \cdot -1} \]
      10. metadata-evalN/A

        \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + m \cdot \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
      11. distribute-rgt-neg-outN/A

        \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(\mathsf{neg}\left(m \cdot 1\right)\right)} \]
      12. *-rgt-identityN/A

        \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \left(\mathsf{neg}\left(\color{blue}{m}\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(-m\right)} \]
      14. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
      15. lower-*.f6499.8

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1 - m}{v} \cdot m}, m, -m\right) \]
    6. Applied rewrites99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
    7. Taylor expanded in m around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{m}{v}}, m, -m\right) \]
    8. Step-by-step derivation
      1. Applied rewrites99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{m}{v}}, m, -m\right) \]

      if 2.05000000000000003e-16 < m

      1. Initial program 99.9%

        \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \cdot m \]
        2. metadata-evalN/A

          \[\leadsto \left(\frac{m \cdot \left(1 - m\right)}{v} - \color{blue}{1 \cdot 1}\right) \cdot m \]
        3. fp-cancel-sub-sign-invN/A

          \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right)} \cdot m \]
        4. lift-/.f64N/A

          \[\leadsto \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
        5. lift-*.f64N/A

          \[\leadsto \left(\frac{\color{blue}{m \cdot \left(1 - m\right)}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
        6. *-commutativeN/A

          \[\leadsto \left(\frac{\color{blue}{\left(1 - m\right) \cdot m}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
        7. associate-/l*N/A

          \[\leadsto \left(\color{blue}{\left(1 - m\right) \cdot \frac{m}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
        8. metadata-evalN/A

          \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1} \cdot 1\right) \cdot m \]
        9. metadata-evalN/A

          \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1}\right) \cdot m \]
        10. metadata-evalN/A

          \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right) \cdot m \]
        11. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, \mathsf{neg}\left(1\right)\right)} \cdot m \]
        12. lower-/.f64N/A

          \[\leadsto \mathsf{fma}\left(1 - m, \color{blue}{\frac{m}{v}}, \mathsf{neg}\left(1\right)\right) \cdot m \]
        13. metadata-eval99.9

          \[\leadsto \mathsf{fma}\left(1 - m, \frac{m}{v}, \color{blue}{-1}\right) \cdot m \]
      4. Applied rewrites99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \cdot m \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right) \cdot m} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{m \cdot \mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \]
        3. lift-fma.f64N/A

          \[\leadsto m \cdot \color{blue}{\left(\left(1 - m\right) \cdot \frac{m}{v} + -1\right)} \]
        4. lift-/.f64N/A

          \[\leadsto m \cdot \left(\left(1 - m\right) \cdot \color{blue}{\frac{m}{v}} + -1\right) \]
        5. associate-*r/N/A

          \[\leadsto m \cdot \left(\color{blue}{\frac{\left(1 - m\right) \cdot m}{v}} + -1\right) \]
        6. associate-*l/N/A

          \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v} \cdot m} + -1\right) \]
        7. lift-/.f64N/A

          \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v}} \cdot m + -1\right) \]
        8. distribute-rgt-inN/A

          \[\leadsto \color{blue}{\left(\frac{1 - m}{v} \cdot m\right) \cdot m + -1 \cdot m} \]
        9. *-commutativeN/A

          \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{m \cdot -1} \]
        10. metadata-evalN/A

          \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + m \cdot \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
        11. distribute-rgt-neg-outN/A

          \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(\mathsf{neg}\left(m \cdot 1\right)\right)} \]
        12. *-rgt-identityN/A

          \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \left(\mathsf{neg}\left(\color{blue}{m}\right)\right) \]
        13. lift-neg.f64N/A

          \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(-m\right)} \]
        14. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
        15. lower-*.f6499.9

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1 - m}{v} \cdot m}, m, -m\right) \]
      6. Applied rewrites99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
      7. Step-by-step derivation
        1. lift-fma.f64N/A

          \[\leadsto \color{blue}{\left(\frac{1 - m}{v} \cdot m\right) \cdot m + \left(-m\right)} \]
        2. lift-*.f64N/A

          \[\leadsto \color{blue}{\left(\frac{1 - m}{v} \cdot m\right)} \cdot m + \left(-m\right) \]
        3. associate-*l*N/A

          \[\leadsto \color{blue}{\frac{1 - m}{v} \cdot \left(m \cdot m\right)} + \left(-m\right) \]
        4. lift-*.f64N/A

          \[\leadsto \frac{1 - m}{v} \cdot \color{blue}{\left(m \cdot m\right)} + \left(-m\right) \]
        5. lower-fma.f6499.9

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v}, m \cdot m, -m\right)} \]
      8. Applied rewrites99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v}, m \cdot m, -m\right)} \]
      9. Taylor expanded in v around 0

        \[\leadsto \color{blue}{\frac{{m}^{2} \cdot \left(1 - m\right)}{v}} \]
      10. Applied rewrites99.9%

        \[\leadsto \color{blue}{\frac{\left(\left(1 - m\right) \cdot m\right) \cdot m}{v}} \]
    9. Recombined 2 regimes into one program.
    10. Add Preprocessing

    Alternative 2: 48.6% accurate, 0.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \leq -5 \cdot 10^{-305}:\\ \;\;\;\;-m\\ \mathbf{else}:\\ \;\;\;\;\frac{m}{v} \cdot m\\ \end{array} \end{array} \]
    (FPCore (m v)
     :precision binary64
     (if (<= (* (- (/ (* m (- 1.0 m)) v) 1.0) m) -5e-305) (- m) (* (/ m v) m)))
    double code(double m, double v) {
    	double tmp;
    	if (((((m * (1.0 - m)) / v) - 1.0) * m) <= -5e-305) {
    		tmp = -m;
    	} else {
    		tmp = (m / v) * m;
    	}
    	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(8) function code(m, v)
    use fmin_fmax_functions
        real(8), intent (in) :: m
        real(8), intent (in) :: v
        real(8) :: tmp
        if (((((m * (1.0d0 - m)) / v) - 1.0d0) * m) <= (-5d-305)) then
            tmp = -m
        else
            tmp = (m / v) * m
        end if
        code = tmp
    end function
    
    public static double code(double m, double v) {
    	double tmp;
    	if (((((m * (1.0 - m)) / v) - 1.0) * m) <= -5e-305) {
    		tmp = -m;
    	} else {
    		tmp = (m / v) * m;
    	}
    	return tmp;
    }
    
    def code(m, v):
    	tmp = 0
    	if ((((m * (1.0 - m)) / v) - 1.0) * m) <= -5e-305:
    		tmp = -m
    	else:
    		tmp = (m / v) * m
    	return tmp
    
    function code(m, v)
    	tmp = 0.0
    	if (Float64(Float64(Float64(Float64(m * Float64(1.0 - m)) / v) - 1.0) * m) <= -5e-305)
    		tmp = Float64(-m);
    	else
    		tmp = Float64(Float64(m / v) * m);
    	end
    	return tmp
    end
    
    function tmp_2 = code(m, v)
    	tmp = 0.0;
    	if (((((m * (1.0 - m)) / v) - 1.0) * m) <= -5e-305)
    		tmp = -m;
    	else
    		tmp = (m / v) * m;
    	end
    	tmp_2 = tmp;
    end
    
    code[m_, v_] := If[LessEqual[N[(N[(N[(N[(m * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * m), $MachinePrecision], -5e-305], (-m), N[(N[(m / v), $MachinePrecision] * m), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \leq -5 \cdot 10^{-305}:\\
    \;\;\;\;-m\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{m}{v} \cdot m\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 (-.f64 (/.f64 (*.f64 m (-.f64 #s(literal 1 binary64) m)) v) #s(literal 1 binary64)) m) < -4.99999999999999985e-305

      1. Initial program 99.9%

        \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
      2. Add Preprocessing
      3. Taylor expanded in m around 0

        \[\leadsto \color{blue}{-1 \cdot m} \]
      4. Step-by-step derivation
        1. Applied rewrites36.0%

          \[\leadsto \color{blue}{-m} \]

        if -4.99999999999999985e-305 < (*.f64 (-.f64 (/.f64 (*.f64 m (-.f64 #s(literal 1 binary64) m)) v) #s(literal 1 binary64)) m)

        1. Initial program 99.7%

          \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
        2. Add Preprocessing
        3. Taylor expanded in v around 0

          \[\leadsto \color{blue}{\frac{m \cdot \left(1 - m\right)}{v}} \cdot m \]
        4. Step-by-step derivation
          1. Applied rewrites97.2%

            \[\leadsto \color{blue}{\frac{\left(1 - m\right) \cdot m}{v}} \cdot m \]
          2. Taylor expanded in m around 0

            \[\leadsto \frac{m}{v} \cdot m \]
          3. Step-by-step derivation
            1. Applied rewrites91.5%

              \[\leadsto \frac{m}{v} \cdot m \]
          4. Recombined 2 regimes into one program.
          5. Final simplification50.1%

            \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \leq -5 \cdot 10^{-305}:\\ \;\;\;\;-m\\ \mathbf{else}:\\ \;\;\;\;\frac{m}{v} \cdot m\\ \end{array} \]
          6. Add Preprocessing

          Alternative 3: 97.7% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(-m\right) \cdot m\right) \cdot m}{v}\\ \end{array} \end{array} \]
          (FPCore (m v)
           :precision binary64
           (if (<= m 1.0) (fma (/ m v) m (- m)) (/ (* (* (- m) m) m) v)))
          double code(double m, double v) {
          	double tmp;
          	if (m <= 1.0) {
          		tmp = fma((m / v), m, -m);
          	} else {
          		tmp = ((-m * m) * m) / v;
          	}
          	return tmp;
          }
          
          function code(m, v)
          	tmp = 0.0
          	if (m <= 1.0)
          		tmp = fma(Float64(m / v), m, Float64(-m));
          	else
          		tmp = Float64(Float64(Float64(Float64(-m) * m) * m) / v);
          	end
          	return tmp
          end
          
          code[m_, v_] := If[LessEqual[m, 1.0], N[(N[(m / v), $MachinePrecision] * m + (-m)), $MachinePrecision], N[(N[(N[((-m) * m), $MachinePrecision] * m), $MachinePrecision] / v), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;m \leq 1:\\
          \;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{\left(\left(-m\right) \cdot m\right) \cdot m}{v}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if m < 1

            1. Initial program 99.8%

              \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
            2. Add Preprocessing
            3. Step-by-step derivation
              1. lift--.f64N/A

                \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \cdot m \]
              2. metadata-evalN/A

                \[\leadsto \left(\frac{m \cdot \left(1 - m\right)}{v} - \color{blue}{1 \cdot 1}\right) \cdot m \]
              3. fp-cancel-sub-sign-invN/A

                \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right)} \cdot m \]
              4. lift-/.f64N/A

                \[\leadsto \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
              5. lift-*.f64N/A

                \[\leadsto \left(\frac{\color{blue}{m \cdot \left(1 - m\right)}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
              6. *-commutativeN/A

                \[\leadsto \left(\frac{\color{blue}{\left(1 - m\right) \cdot m}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
              7. associate-/l*N/A

                \[\leadsto \left(\color{blue}{\left(1 - m\right) \cdot \frac{m}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
              8. metadata-evalN/A

                \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1} \cdot 1\right) \cdot m \]
              9. metadata-evalN/A

                \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1}\right) \cdot m \]
              10. metadata-evalN/A

                \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right) \cdot m \]
              11. lower-fma.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, \mathsf{neg}\left(1\right)\right)} \cdot m \]
              12. lower-/.f64N/A

                \[\leadsto \mathsf{fma}\left(1 - m, \color{blue}{\frac{m}{v}}, \mathsf{neg}\left(1\right)\right) \cdot m \]
              13. metadata-eval99.8

                \[\leadsto \mathsf{fma}\left(1 - m, \frac{m}{v}, \color{blue}{-1}\right) \cdot m \]
            4. Applied rewrites99.8%

              \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \cdot m \]
            5. Step-by-step derivation
              1. lift-*.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right) \cdot m} \]
              2. *-commutativeN/A

                \[\leadsto \color{blue}{m \cdot \mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \]
              3. lift-fma.f64N/A

                \[\leadsto m \cdot \color{blue}{\left(\left(1 - m\right) \cdot \frac{m}{v} + -1\right)} \]
              4. lift-/.f64N/A

                \[\leadsto m \cdot \left(\left(1 - m\right) \cdot \color{blue}{\frac{m}{v}} + -1\right) \]
              5. associate-*r/N/A

                \[\leadsto m \cdot \left(\color{blue}{\frac{\left(1 - m\right) \cdot m}{v}} + -1\right) \]
              6. associate-*l/N/A

                \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v} \cdot m} + -1\right) \]
              7. lift-/.f64N/A

                \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v}} \cdot m + -1\right) \]
              8. distribute-rgt-inN/A

                \[\leadsto \color{blue}{\left(\frac{1 - m}{v} \cdot m\right) \cdot m + -1 \cdot m} \]
              9. *-commutativeN/A

                \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{m \cdot -1} \]
              10. metadata-evalN/A

                \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + m \cdot \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
              11. distribute-rgt-neg-outN/A

                \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(\mathsf{neg}\left(m \cdot 1\right)\right)} \]
              12. *-rgt-identityN/A

                \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \left(\mathsf{neg}\left(\color{blue}{m}\right)\right) \]
              13. lift-neg.f64N/A

                \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(-m\right)} \]
              14. lower-fma.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
              15. lower-*.f6499.8

                \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1 - m}{v} \cdot m}, m, -m\right) \]
            6. Applied rewrites99.8%

              \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
            7. Taylor expanded in m around 0

              \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{m}{v}}, m, -m\right) \]
            8. Step-by-step derivation
              1. Applied rewrites97.0%

                \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{m}{v}}, m, -m\right) \]

              if 1 < m

              1. Initial program 99.9%

                \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
              2. Add Preprocessing
              3. Taylor expanded in m around inf

                \[\leadsto \color{blue}{-1 \cdot \frac{{m}^{3}}{v}} \]
              4. Step-by-step derivation
                1. Applied rewrites98.2%

                  \[\leadsto \color{blue}{\frac{{\left(-m\right)}^{3}}{v}} \]
                2. Step-by-step derivation
                  1. Applied rewrites98.2%

                    \[\leadsto \frac{\left(\left(-m\right) \cdot m\right) \cdot m}{v} \]
                3. Recombined 2 regimes into one program.
                4. Final simplification97.6%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(-m\right) \cdot m\right) \cdot m}{v}\\ \end{array} \]
                5. Add Preprocessing

                Alternative 4: 51.1% accurate, 1.1× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\ \mathbf{else}:\\ \;\;\;\;-m\\ \end{array} \end{array} \]
                (FPCore (m v) :precision binary64 (if (<= m 1.0) (fma (/ m v) m (- m)) (- m)))
                double code(double m, double v) {
                	double tmp;
                	if (m <= 1.0) {
                		tmp = fma((m / v), m, -m);
                	} else {
                		tmp = -m;
                	}
                	return tmp;
                }
                
                function code(m, v)
                	tmp = 0.0
                	if (m <= 1.0)
                		tmp = fma(Float64(m / v), m, Float64(-m));
                	else
                		tmp = Float64(-m);
                	end
                	return tmp
                end
                
                code[m_, v_] := If[LessEqual[m, 1.0], N[(N[(m / v), $MachinePrecision] * m + (-m)), $MachinePrecision], (-m)]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;m \leq 1:\\
                \;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;-m\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if m < 1

                  1. Initial program 99.8%

                    \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
                  2. Add Preprocessing
                  3. Step-by-step derivation
                    1. lift--.f64N/A

                      \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \cdot m \]
                    2. metadata-evalN/A

                      \[\leadsto \left(\frac{m \cdot \left(1 - m\right)}{v} - \color{blue}{1 \cdot 1}\right) \cdot m \]
                    3. fp-cancel-sub-sign-invN/A

                      \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right)} \cdot m \]
                    4. lift-/.f64N/A

                      \[\leadsto \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                    5. lift-*.f64N/A

                      \[\leadsto \left(\frac{\color{blue}{m \cdot \left(1 - m\right)}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                    6. *-commutativeN/A

                      \[\leadsto \left(\frac{\color{blue}{\left(1 - m\right) \cdot m}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                    7. associate-/l*N/A

                      \[\leadsto \left(\color{blue}{\left(1 - m\right) \cdot \frac{m}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                    8. metadata-evalN/A

                      \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1} \cdot 1\right) \cdot m \]
                    9. metadata-evalN/A

                      \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1}\right) \cdot m \]
                    10. metadata-evalN/A

                      \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right) \cdot m \]
                    11. lower-fma.f64N/A

                      \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, \mathsf{neg}\left(1\right)\right)} \cdot m \]
                    12. lower-/.f64N/A

                      \[\leadsto \mathsf{fma}\left(1 - m, \color{blue}{\frac{m}{v}}, \mathsf{neg}\left(1\right)\right) \cdot m \]
                    13. metadata-eval99.8

                      \[\leadsto \mathsf{fma}\left(1 - m, \frac{m}{v}, \color{blue}{-1}\right) \cdot m \]
                  4. Applied rewrites99.8%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \cdot m \]
                  5. Step-by-step derivation
                    1. lift-*.f64N/A

                      \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right) \cdot m} \]
                    2. *-commutativeN/A

                      \[\leadsto \color{blue}{m \cdot \mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \]
                    3. lift-fma.f64N/A

                      \[\leadsto m \cdot \color{blue}{\left(\left(1 - m\right) \cdot \frac{m}{v} + -1\right)} \]
                    4. lift-/.f64N/A

                      \[\leadsto m \cdot \left(\left(1 - m\right) \cdot \color{blue}{\frac{m}{v}} + -1\right) \]
                    5. associate-*r/N/A

                      \[\leadsto m \cdot \left(\color{blue}{\frac{\left(1 - m\right) \cdot m}{v}} + -1\right) \]
                    6. associate-*l/N/A

                      \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v} \cdot m} + -1\right) \]
                    7. lift-/.f64N/A

                      \[\leadsto m \cdot \left(\color{blue}{\frac{1 - m}{v}} \cdot m + -1\right) \]
                    8. distribute-rgt-inN/A

                      \[\leadsto \color{blue}{\left(\frac{1 - m}{v} \cdot m\right) \cdot m + -1 \cdot m} \]
                    9. *-commutativeN/A

                      \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{m \cdot -1} \]
                    10. metadata-evalN/A

                      \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + m \cdot \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
                    11. distribute-rgt-neg-outN/A

                      \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(\mathsf{neg}\left(m \cdot 1\right)\right)} \]
                    12. *-rgt-identityN/A

                      \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \left(\mathsf{neg}\left(\color{blue}{m}\right)\right) \]
                    13. lift-neg.f64N/A

                      \[\leadsto \left(\frac{1 - m}{v} \cdot m\right) \cdot m + \color{blue}{\left(-m\right)} \]
                    14. lower-fma.f64N/A

                      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
                    15. lower-*.f6499.8

                      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1 - m}{v} \cdot m}, m, -m\right) \]
                  6. Applied rewrites99.8%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1 - m}{v} \cdot m, m, -m\right)} \]
                  7. Taylor expanded in m around 0

                    \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{m}{v}}, m, -m\right) \]
                  8. Step-by-step derivation
                    1. Applied rewrites97.0%

                      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{m}{v}}, m, -m\right) \]

                    if 1 < m

                    1. Initial program 99.9%

                      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
                    2. Add Preprocessing
                    3. Taylor expanded in m around 0

                      \[\leadsto \color{blue}{-1 \cdot m} \]
                    4. Step-by-step derivation
                      1. Applied rewrites5.5%

                        \[\leadsto \color{blue}{-m} \]
                    5. Recombined 2 regimes into one program.
                    6. Final simplification51.2%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\mathsf{fma}\left(\frac{m}{v}, m, -m\right)\\ \mathbf{else}:\\ \;\;\;\;-m\\ \end{array} \]
                    7. Add Preprocessing

                    Alternative 5: 51.1% accurate, 1.1× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\left(\frac{m}{v} - 1\right) \cdot m\\ \mathbf{else}:\\ \;\;\;\;-m\\ \end{array} \end{array} \]
                    (FPCore (m v) :precision binary64 (if (<= m 1.0) (* (- (/ m v) 1.0) m) (- m)))
                    double code(double m, double v) {
                    	double tmp;
                    	if (m <= 1.0) {
                    		tmp = ((m / v) - 1.0) * m;
                    	} else {
                    		tmp = -m;
                    	}
                    	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(8) function code(m, v)
                    use fmin_fmax_functions
                        real(8), intent (in) :: m
                        real(8), intent (in) :: v
                        real(8) :: tmp
                        if (m <= 1.0d0) then
                            tmp = ((m / v) - 1.0d0) * m
                        else
                            tmp = -m
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double m, double v) {
                    	double tmp;
                    	if (m <= 1.0) {
                    		tmp = ((m / v) - 1.0) * m;
                    	} else {
                    		tmp = -m;
                    	}
                    	return tmp;
                    }
                    
                    def code(m, v):
                    	tmp = 0
                    	if m <= 1.0:
                    		tmp = ((m / v) - 1.0) * m
                    	else:
                    		tmp = -m
                    	return tmp
                    
                    function code(m, v)
                    	tmp = 0.0
                    	if (m <= 1.0)
                    		tmp = Float64(Float64(Float64(m / v) - 1.0) * m);
                    	else
                    		tmp = Float64(-m);
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(m, v)
                    	tmp = 0.0;
                    	if (m <= 1.0)
                    		tmp = ((m / v) - 1.0) * m;
                    	else
                    		tmp = -m;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[m_, v_] := If[LessEqual[m, 1.0], N[(N[(N[(m / v), $MachinePrecision] - 1.0), $MachinePrecision] * m), $MachinePrecision], (-m)]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;m \leq 1:\\
                    \;\;\;\;\left(\frac{m}{v} - 1\right) \cdot m\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;-m\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if m < 1

                      1. Initial program 99.8%

                        \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
                      2. Add Preprocessing
                      3. Taylor expanded in m around 0

                        \[\leadsto \left(\frac{\color{blue}{m}}{v} - 1\right) \cdot m \]
                      4. Step-by-step derivation
                        1. Applied rewrites96.9%

                          \[\leadsto \left(\frac{\color{blue}{m}}{v} - 1\right) \cdot m \]

                        if 1 < m

                        1. Initial program 99.9%

                          \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
                        2. Add Preprocessing
                        3. Taylor expanded in m around 0

                          \[\leadsto \color{blue}{-1 \cdot m} \]
                        4. Step-by-step derivation
                          1. Applied rewrites5.5%

                            \[\leadsto \color{blue}{-m} \]
                        5. Recombined 2 regimes into one program.
                        6. Final simplification51.2%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\left(\frac{m}{v} - 1\right) \cdot m\\ \mathbf{else}:\\ \;\;\;\;-m\\ \end{array} \]
                        7. Add Preprocessing

                        Alternative 6: 99.8% accurate, 1.1× speedup?

                        \[\begin{array}{l} \\ \mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right) \cdot m \end{array} \]
                        (FPCore (m v) :precision binary64 (* (fma (- 1.0 m) (/ m v) -1.0) m))
                        double code(double m, double v) {
                        	return fma((1.0 - m), (m / v), -1.0) * m;
                        }
                        
                        function code(m, v)
                        	return Float64(fma(Float64(1.0 - m), Float64(m / v), -1.0) * m)
                        end
                        
                        code[m_, v_] := N[(N[(N[(1.0 - m), $MachinePrecision] * N[(m / v), $MachinePrecision] + -1.0), $MachinePrecision] * m), $MachinePrecision]
                        
                        \begin{array}{l}
                        
                        \\
                        \mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right) \cdot m
                        \end{array}
                        
                        Derivation
                        1. Initial program 99.9%

                          \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
                        2. Add Preprocessing
                        3. Step-by-step derivation
                          1. lift--.f64N/A

                            \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \cdot m \]
                          2. metadata-evalN/A

                            \[\leadsto \left(\frac{m \cdot \left(1 - m\right)}{v} - \color{blue}{1 \cdot 1}\right) \cdot m \]
                          3. fp-cancel-sub-sign-invN/A

                            \[\leadsto \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right)} \cdot m \]
                          4. lift-/.f64N/A

                            \[\leadsto \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                          5. lift-*.f64N/A

                            \[\leadsto \left(\frac{\color{blue}{m \cdot \left(1 - m\right)}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                          6. *-commutativeN/A

                            \[\leadsto \left(\frac{\color{blue}{\left(1 - m\right) \cdot m}}{v} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                          7. associate-/l*N/A

                            \[\leadsto \left(\color{blue}{\left(1 - m\right) \cdot \frac{m}{v}} + \left(\mathsf{neg}\left(1\right)\right) \cdot 1\right) \cdot m \]
                          8. metadata-evalN/A

                            \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1} \cdot 1\right) \cdot m \]
                          9. metadata-evalN/A

                            \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{-1}\right) \cdot m \]
                          10. metadata-evalN/A

                            \[\leadsto \left(\left(1 - m\right) \cdot \frac{m}{v} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right) \cdot m \]
                          11. lower-fma.f64N/A

                            \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, \mathsf{neg}\left(1\right)\right)} \cdot m \]
                          12. lower-/.f64N/A

                            \[\leadsto \mathsf{fma}\left(1 - m, \color{blue}{\frac{m}{v}}, \mathsf{neg}\left(1\right)\right) \cdot m \]
                          13. metadata-eval99.9

                            \[\leadsto \mathsf{fma}\left(1 - m, \frac{m}{v}, \color{blue}{-1}\right) \cdot m \]
                        4. Applied rewrites99.9%

                          \[\leadsto \color{blue}{\mathsf{fma}\left(1 - m, \frac{m}{v}, -1\right)} \cdot m \]
                        5. Add Preprocessing

                        Alternative 7: 26.6% accurate, 9.3× speedup?

                        \[\begin{array}{l} \\ -m \end{array} \]
                        (FPCore (m v) :precision binary64 (- m))
                        double code(double m, double v) {
                        	return -m;
                        }
                        
                        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(8) function code(m, v)
                        use fmin_fmax_functions
                            real(8), intent (in) :: m
                            real(8), intent (in) :: v
                            code = -m
                        end function
                        
                        public static double code(double m, double v) {
                        	return -m;
                        }
                        
                        def code(m, v):
                        	return -m
                        
                        function code(m, v)
                        	return Float64(-m)
                        end
                        
                        function tmp = code(m, v)
                        	tmp = -m;
                        end
                        
                        code[m_, v_] := (-m)
                        
                        \begin{array}{l}
                        
                        \\
                        -m
                        \end{array}
                        
                        Derivation
                        1. Initial program 99.9%

                          \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
                        2. Add Preprocessing
                        3. Taylor expanded in m around 0

                          \[\leadsto \color{blue}{-1 \cdot m} \]
                        4. Step-by-step derivation
                          1. Applied rewrites27.4%

                            \[\leadsto \color{blue}{-m} \]
                          2. Final simplification27.4%

                            \[\leadsto -m \]
                          3. Add Preprocessing

                          Reproduce

                          ?
                          herbie shell --seed 2025021 
                          (FPCore (m v)
                            :name "a parameter of renormalized beta distribution"
                            :precision binary64
                            :pre (and (and (< 0.0 m) (< 0.0 v)) (< v 0.25))
                            (* (- (/ (* m (- 1.0 m)) v) 1.0) m))