b parameter of renormalized beta distribution

Percentage Accurate: 99.9% → 99.9%
Time: 5.8s
Alternatives: 14
Speedup: 1.0×

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

\\
\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right)
\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 14 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.1× speedup?

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

\\
\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)}{\frac{m + 1}{1 - m \cdot m}}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
  2. Step-by-step derivation
    1. *-commutative99.9%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
    2. sub-neg99.9%

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

      \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
    4. metadata-eval99.9%

      \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
  3. Simplified99.9%

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

      \[\leadsto \color{blue}{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 - m\right)} \]
    2. flip--99.9%

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

      \[\leadsto \color{blue}{\frac{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m}} \]
    4. fma-def97.5%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)} \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m} \]
    5. metadata-eval97.5%

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

      \[\leadsto \frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{\color{blue}{m + 1}} \]
  5. Applied egg-rr97.5%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{m + 1}} \]
  6. Step-by-step derivation
    1. associate-/l*99.9%

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

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

    \[\leadsto \frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)}{\frac{m + 1}{1 - m \cdot m}} \]

Alternative 2: 97.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{v}{1 - m}\\ \mathbf{if}\;m \leq 1:\\ \;\;\;\;\frac{m}{t_0} + \left(m + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{m \cdot \left(-m\right)}{t_0}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (let* ((t_0 (/ v (- 1.0 m))))
   (if (<= m 1.0) (+ (/ m t_0) (+ m -1.0)) (/ (* m (- m)) t_0))))
double code(double m, double v) {
	double t_0 = v / (1.0 - m);
	double tmp;
	if (m <= 1.0) {
		tmp = (m / t_0) + (m + -1.0);
	} else {
		tmp = (m * -m) / t_0;
	}
	return tmp;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    real(8) :: t_0
    real(8) :: tmp
    t_0 = v / (1.0d0 - m)
    if (m <= 1.0d0) then
        tmp = (m / t_0) + (m + (-1.0d0))
    else
        tmp = (m * -m) / t_0
    end if
    code = tmp
end function
public static double code(double m, double v) {
	double t_0 = v / (1.0 - m);
	double tmp;
	if (m <= 1.0) {
		tmp = (m / t_0) + (m + -1.0);
	} else {
		tmp = (m * -m) / t_0;
	}
	return tmp;
}
def code(m, v):
	t_0 = v / (1.0 - m)
	tmp = 0
	if m <= 1.0:
		tmp = (m / t_0) + (m + -1.0)
	else:
		tmp = (m * -m) / t_0
	return tmp
function code(m, v)
	t_0 = Float64(v / Float64(1.0 - m))
	tmp = 0.0
	if (m <= 1.0)
		tmp = Float64(Float64(m / t_0) + Float64(m + -1.0));
	else
		tmp = Float64(Float64(m * Float64(-m)) / t_0);
	end
	return tmp
end
function tmp_2 = code(m, v)
	t_0 = v / (1.0 - m);
	tmp = 0.0;
	if (m <= 1.0)
		tmp = (m / t_0) + (m + -1.0);
	else
		tmp = (m * -m) / t_0;
	end
	tmp_2 = tmp;
end
code[m_, v_] := Block[{t$95$0 = N[(v / N[(1.0 - m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[m, 1.0], N[(N[(m / t$95$0), $MachinePrecision] + N[(m + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(m * (-m)), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{v}{1 - m}\\
\mathbf{if}\;m \leq 1:\\
\;\;\;\;\frac{m}{t_0} + \left(m + -1\right)\\

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


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

    1. Initial program 99.9%

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

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

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

        \[\leadsto \color{blue}{\frac{m \cdot \left(1 - m\right)}{v} + -1 \cdot \left(1 - m\right)} \]
      2. mul-1-neg98.1%

        \[\leadsto \frac{m \cdot \left(1 - m\right)}{v} + \color{blue}{\left(-\left(1 - m\right)\right)} \]
      3. unsub-neg98.1%

        \[\leadsto \color{blue}{\frac{m \cdot \left(1 - m\right)}{v} - \left(1 - m\right)} \]
      4. associate-/l*98.1%

        \[\leadsto \color{blue}{\frac{m}{\frac{v}{1 - m}}} - \left(1 - m\right) \]
    5. Simplified98.1%

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

    if 1 < m

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval99.8%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Taylor expanded in m around inf 98.4%

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

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

        \[\leadsto \left(1 - m\right) \cdot \left(-1 \cdot \color{blue}{\left(\frac{m}{v} \cdot m\right)} + -1\right) \]
      3. neg-mul-198.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\left(-\frac{m}{v} \cdot m\right)} + -1\right) \]
      4. distribute-rgt-neg-out98.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(-m\right)} + -1\right) \]
    6. Simplified98.3%

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

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

        \[\leadsto \color{blue}{-\frac{{m}^{2} \cdot \left(1 - m\right)}{v}} \]
      2. unpow298.4%

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

        \[\leadsto -\color{blue}{\frac{m \cdot m}{\frac{v}{1 - m}}} \]
      4. distribute-neg-frac98.4%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{\frac{v}{1 - m}}} \]
      5. distribute-rgt-neg-in98.4%

        \[\leadsto \frac{\color{blue}{m \cdot \left(-m\right)}}{\frac{v}{1 - m}} \]
    9. Simplified98.4%

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

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

Alternative 3: 99.9% accurate, 1.0× speedup?

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

\\
\left(1 - m\right) \cdot \left(-1 + \frac{m}{v} \cdot \left(1 - m\right)\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
  2. Step-by-step derivation
    1. *-commutative99.9%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
    2. sub-neg99.9%

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

      \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
    4. metadata-eval99.9%

      \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
  4. Final simplification99.9%

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

Alternative 4: 99.9% accurate, 1.0× speedup?

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

\\
\left(1 - m\right) \cdot \left(-1 + \frac{m \cdot \left(1 - m\right)}{v}\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
  2. Final simplification99.9%

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

Alternative 5: 97.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\left(1 - m\right) \cdot \left(\frac{m}{v} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{m \cdot \left(-m\right)}{\frac{v}{1 - m}}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (if (<= m 1.0)
   (* (- 1.0 m) (+ (/ m v) -1.0))
   (/ (* m (- m)) (/ v (- 1.0 m)))))
double code(double m, double v) {
	double tmp;
	if (m <= 1.0) {
		tmp = (1.0 - m) * ((m / v) + -1.0);
	} else {
		tmp = (m * -m) / (v / (1.0 - m));
	}
	return tmp;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    real(8) :: tmp
    if (m <= 1.0d0) then
        tmp = (1.0d0 - m) * ((m / v) + (-1.0d0))
    else
        tmp = (m * -m) / (v / (1.0d0 - m))
    end if
    code = tmp
end function
public static double code(double m, double v) {
	double tmp;
	if (m <= 1.0) {
		tmp = (1.0 - m) * ((m / v) + -1.0);
	} else {
		tmp = (m * -m) / (v / (1.0 - m));
	}
	return tmp;
}
def code(m, v):
	tmp = 0
	if m <= 1.0:
		tmp = (1.0 - m) * ((m / v) + -1.0)
	else:
		tmp = (m * -m) / (v / (1.0 - m))
	return tmp
function code(m, v)
	tmp = 0.0
	if (m <= 1.0)
		tmp = Float64(Float64(1.0 - m) * Float64(Float64(m / v) + -1.0));
	else
		tmp = Float64(Float64(m * Float64(-m)) / Float64(v / Float64(1.0 - m)));
	end
	return tmp
end
function tmp_2 = code(m, v)
	tmp = 0.0;
	if (m <= 1.0)
		tmp = (1.0 - m) * ((m / v) + -1.0);
	else
		tmp = (m * -m) / (v / (1.0 - m));
	end
	tmp_2 = tmp;
end
code[m_, v_] := If[LessEqual[m, 1.0], N[(N[(1.0 - m), $MachinePrecision] * N[(N[(m / v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(m * (-m)), $MachinePrecision] / N[(v / N[(1.0 - m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 1:\\
\;\;\;\;\left(1 - m\right) \cdot \left(\frac{m}{v} + -1\right)\\

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


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

    1. Initial program 99.9%

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

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

    if 1 < m

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval99.8%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Taylor expanded in m around inf 98.4%

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

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

        \[\leadsto \left(1 - m\right) \cdot \left(-1 \cdot \color{blue}{\left(\frac{m}{v} \cdot m\right)} + -1\right) \]
      3. neg-mul-198.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\left(-\frac{m}{v} \cdot m\right)} + -1\right) \]
      4. distribute-rgt-neg-out98.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(-m\right)} + -1\right) \]
    6. Simplified98.3%

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

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

        \[\leadsto \color{blue}{-\frac{{m}^{2} \cdot \left(1 - m\right)}{v}} \]
      2. unpow298.4%

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

        \[\leadsto -\color{blue}{\frac{m \cdot m}{\frac{v}{1 - m}}} \]
      4. distribute-neg-frac98.4%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{\frac{v}{1 - m}}} \]
      5. distribute-rgt-neg-in98.4%

        \[\leadsto \frac{\color{blue}{m \cdot \left(-m\right)}}{\frac{v}{1 - m}} \]
    9. Simplified98.4%

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

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

Alternative 6: 97.7% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq 1:\\
\;\;\;\;\frac{m}{v} + -1\\

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


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

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval100.0%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 - m\right)} \]
      2. flip--100.0%

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

        \[\leadsto \color{blue}{\frac{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m}} \]
      4. fma-def100.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)} \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m} \]
      5. metadata-eval100.0%

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{\color{blue}{m + 1}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{m + 1}} \]
    6. Step-by-step derivation
      1. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)}{\frac{m + 1}{1 - m \cdot m}}} \]
    7. Simplified100.0%

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

      \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m - 1} \]
    9. Step-by-step derivation
      1. sub-neg97.8%

        \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m + \left(-1\right)} \]
      2. *-commutative97.8%

        \[\leadsto \color{blue}{m \cdot \left(1 + \frac{1}{v}\right)} + \left(-1\right) \]
      3. distribute-rgt-in97.8%

        \[\leadsto \color{blue}{\left(1 \cdot m + \frac{1}{v} \cdot m\right)} + \left(-1\right) \]
      4. *-lft-identity97.8%

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

        \[\leadsto \left(m + \color{blue}{\frac{1 \cdot m}{v}}\right) + \left(-1\right) \]
      6. *-lft-identity98.0%

        \[\leadsto \left(m + \frac{\color{blue}{m}}{v}\right) + \left(-1\right) \]
      7. metadata-eval98.0%

        \[\leadsto \left(m + \frac{m}{v}\right) + \color{blue}{-1} \]
    10. Simplified98.0%

      \[\leadsto \color{blue}{\left(m + \frac{m}{v}\right) + -1} \]
    11. Taylor expanded in v around 0 98.0%

      \[\leadsto \color{blue}{\frac{m}{v}} + -1 \]

    if 1 < m

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval99.8%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Taylor expanded in m around inf 98.4%

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

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

        \[\leadsto \left(1 - m\right) \cdot \left(-1 \cdot \color{blue}{\left(\frac{m}{v} \cdot m\right)} + -1\right) \]
      3. neg-mul-198.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\left(-\frac{m}{v} \cdot m\right)} + -1\right) \]
      4. distribute-rgt-neg-out98.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(-m\right)} + -1\right) \]
    6. Simplified98.3%

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

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

        \[\leadsto \color{blue}{-\frac{{m}^{2} \cdot \left(1 - m\right)}{v}} \]
      2. unpow298.4%

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

        \[\leadsto -\color{blue}{\frac{m \cdot m}{\frac{v}{1 - m}}} \]
      4. distribute-neg-frac98.4%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{\frac{v}{1 - m}}} \]
      5. distribute-rgt-neg-in98.4%

        \[\leadsto \frac{\color{blue}{m \cdot \left(-m\right)}}{\frac{v}{1 - m}} \]
    9. Simplified98.4%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{{m}^{2}}{v} + \frac{{m}^{3}}{v}} \]
    11. Step-by-step derivation
      1. +-commutative23.0%

        \[\leadsto \color{blue}{\frac{{m}^{3}}{v} + -1 \cdot \frac{{m}^{2}}{v}} \]
      2. unpow323.0%

        \[\leadsto \frac{\color{blue}{\left(m \cdot m\right) \cdot m}}{v} + -1 \cdot \frac{{m}^{2}}{v} \]
      3. associate-*r/23.0%

        \[\leadsto \color{blue}{\left(m \cdot m\right) \cdot \frac{m}{v}} + -1 \cdot \frac{{m}^{2}}{v} \]
      4. associate-*r*23.0%

        \[\leadsto \color{blue}{m \cdot \left(m \cdot \frac{m}{v}\right)} + -1 \cdot \frac{{m}^{2}}{v} \]
      5. unpow223.0%

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

        \[\leadsto m \cdot \left(m \cdot \frac{m}{v}\right) + -1 \cdot \color{blue}{\left(m \cdot \frac{m}{v}\right)} \]
      7. distribute-rgt-in98.3%

        \[\leadsto \color{blue}{\left(m \cdot \frac{m}{v}\right) \cdot \left(m + -1\right)} \]
      8. associate-*l*98.3%

        \[\leadsto \color{blue}{m \cdot \left(\frac{m}{v} \cdot \left(m + -1\right)\right)} \]
      9. +-commutative98.3%

        \[\leadsto m \cdot \left(\frac{m}{v} \cdot \color{blue}{\left(-1 + m\right)}\right) \]
    12. Simplified98.3%

      \[\leadsto \color{blue}{m \cdot \left(\frac{m}{v} \cdot \left(-1 + m\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.2%

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

Alternative 7: 97.7% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq 1:\\
\;\;\;\;\frac{m}{v} + -1\\

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


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

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval100.0%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 - m\right)} \]
      2. flip--100.0%

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

        \[\leadsto \color{blue}{\frac{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m}} \]
      4. fma-def100.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)} \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m} \]
      5. metadata-eval100.0%

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{\color{blue}{m + 1}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{m + 1}} \]
    6. Step-by-step derivation
      1. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)}{\frac{m + 1}{1 - m \cdot m}}} \]
    7. Simplified100.0%

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

      \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m - 1} \]
    9. Step-by-step derivation
      1. sub-neg97.8%

        \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m + \left(-1\right)} \]
      2. *-commutative97.8%

        \[\leadsto \color{blue}{m \cdot \left(1 + \frac{1}{v}\right)} + \left(-1\right) \]
      3. distribute-rgt-in97.8%

        \[\leadsto \color{blue}{\left(1 \cdot m + \frac{1}{v} \cdot m\right)} + \left(-1\right) \]
      4. *-lft-identity97.8%

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

        \[\leadsto \left(m + \color{blue}{\frac{1 \cdot m}{v}}\right) + \left(-1\right) \]
      6. *-lft-identity98.0%

        \[\leadsto \left(m + \frac{\color{blue}{m}}{v}\right) + \left(-1\right) \]
      7. metadata-eval98.0%

        \[\leadsto \left(m + \frac{m}{v}\right) + \color{blue}{-1} \]
    10. Simplified98.0%

      \[\leadsto \color{blue}{\left(m + \frac{m}{v}\right) + -1} \]
    11. Taylor expanded in v around 0 98.0%

      \[\leadsto \color{blue}{\frac{m}{v}} + -1 \]

    if 1 < m

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval99.8%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Taylor expanded in m around inf 98.4%

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

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

        \[\leadsto \left(1 - m\right) \cdot \left(-1 \cdot \color{blue}{\left(\frac{m}{v} \cdot m\right)} + -1\right) \]
      3. neg-mul-198.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\left(-\frac{m}{v} \cdot m\right)} + -1\right) \]
      4. distribute-rgt-neg-out98.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(-m\right)} + -1\right) \]
    6. Simplified98.3%

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

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

        \[\leadsto \color{blue}{-\frac{{m}^{2} \cdot \left(1 - m\right)}{v}} \]
      2. unpow298.4%

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

        \[\leadsto -\color{blue}{\frac{m \cdot m}{\frac{v}{1 - m}}} \]
      4. distribute-neg-frac98.4%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{\frac{v}{1 - m}}} \]
      5. distribute-rgt-neg-in98.4%

        \[\leadsto \frac{\color{blue}{m \cdot \left(-m\right)}}{\frac{v}{1 - m}} \]
    9. Simplified98.4%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{{m}^{2}}{v} + \frac{{m}^{3}}{v}} \]
    11. Step-by-step derivation
      1. +-commutative23.0%

        \[\leadsto \color{blue}{\frac{{m}^{3}}{v} + -1 \cdot \frac{{m}^{2}}{v}} \]
      2. unpow323.0%

        \[\leadsto \frac{\color{blue}{\left(m \cdot m\right) \cdot m}}{v} + -1 \cdot \frac{{m}^{2}}{v} \]
      3. associate-*r/23.0%

        \[\leadsto \color{blue}{\left(m \cdot m\right) \cdot \frac{m}{v}} + -1 \cdot \frac{{m}^{2}}{v} \]
      4. associate-*r*23.0%

        \[\leadsto \color{blue}{m \cdot \left(m \cdot \frac{m}{v}\right)} + -1 \cdot \frac{{m}^{2}}{v} \]
      5. unpow223.0%

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

        \[\leadsto m \cdot \left(m \cdot \frac{m}{v}\right) + -1 \cdot \color{blue}{\left(m \cdot \frac{m}{v}\right)} \]
      7. distribute-rgt-in98.3%

        \[\leadsto \color{blue}{\left(m \cdot \frac{m}{v}\right) \cdot \left(m + -1\right)} \]
      8. associate-*l*98.3%

        \[\leadsto \color{blue}{m \cdot \left(\frac{m}{v} \cdot \left(m + -1\right)\right)} \]
      9. +-commutative98.3%

        \[\leadsto m \cdot \left(\frac{m}{v} \cdot \color{blue}{\left(-1 + m\right)}\right) \]
    12. Simplified98.3%

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

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

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

Alternative 8: 97.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1:\\ \;\;\;\;\left(1 - m\right) \cdot \left(\frac{m}{v} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m \cdot \left(m + -1\right)}{v}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (if (<= m 1.0) (* (- 1.0 m) (+ (/ m v) -1.0)) (* m (/ (* m (+ m -1.0)) v))))
double code(double m, double v) {
	double tmp;
	if (m <= 1.0) {
		tmp = (1.0 - m) * ((m / v) + -1.0);
	} else {
		tmp = m * ((m * (m + -1.0)) / v);
	}
	return tmp;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    real(8) :: tmp
    if (m <= 1.0d0) then
        tmp = (1.0d0 - m) * ((m / v) + (-1.0d0))
    else
        tmp = m * ((m * (m + (-1.0d0))) / v)
    end if
    code = tmp
end function
public static double code(double m, double v) {
	double tmp;
	if (m <= 1.0) {
		tmp = (1.0 - m) * ((m / v) + -1.0);
	} else {
		tmp = m * ((m * (m + -1.0)) / v);
	}
	return tmp;
}
def code(m, v):
	tmp = 0
	if m <= 1.0:
		tmp = (1.0 - m) * ((m / v) + -1.0)
	else:
		tmp = m * ((m * (m + -1.0)) / v)
	return tmp
function code(m, v)
	tmp = 0.0
	if (m <= 1.0)
		tmp = Float64(Float64(1.0 - m) * Float64(Float64(m / v) + -1.0));
	else
		tmp = Float64(m * Float64(Float64(m * Float64(m + -1.0)) / v));
	end
	return tmp
end
function tmp_2 = code(m, v)
	tmp = 0.0;
	if (m <= 1.0)
		tmp = (1.0 - m) * ((m / v) + -1.0);
	else
		tmp = m * ((m * (m + -1.0)) / v);
	end
	tmp_2 = tmp;
end
code[m_, v_] := If[LessEqual[m, 1.0], N[(N[(1.0 - m), $MachinePrecision] * N[(N[(m / v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(m * N[(N[(m * N[(m + -1.0), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 1:\\
\;\;\;\;\left(1 - m\right) \cdot \left(\frac{m}{v} + -1\right)\\

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


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

    1. Initial program 99.9%

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

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

    if 1 < m

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval99.8%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Taylor expanded in m around inf 98.4%

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

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

        \[\leadsto \left(1 - m\right) \cdot \left(-1 \cdot \color{blue}{\left(\frac{m}{v} \cdot m\right)} + -1\right) \]
      3. neg-mul-198.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\left(-\frac{m}{v} \cdot m\right)} + -1\right) \]
      4. distribute-rgt-neg-out98.3%

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(-m\right)} + -1\right) \]
    6. Simplified98.3%

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

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

        \[\leadsto \color{blue}{-\frac{{m}^{2} \cdot \left(1 - m\right)}{v}} \]
      2. unpow298.4%

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

        \[\leadsto -\color{blue}{\frac{m \cdot m}{\frac{v}{1 - m}}} \]
      4. distribute-neg-frac98.4%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{\frac{v}{1 - m}}} \]
      5. distribute-rgt-neg-in98.4%

        \[\leadsto \frac{\color{blue}{m \cdot \left(-m\right)}}{\frac{v}{1 - m}} \]
    9. Simplified98.4%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{{m}^{2}}{v} + \frac{{m}^{3}}{v}} \]
    11. Step-by-step derivation
      1. +-commutative23.0%

        \[\leadsto \color{blue}{\frac{{m}^{3}}{v} + -1 \cdot \frac{{m}^{2}}{v}} \]
      2. unpow323.0%

        \[\leadsto \frac{\color{blue}{\left(m \cdot m\right) \cdot m}}{v} + -1 \cdot \frac{{m}^{2}}{v} \]
      3. associate-*r/23.0%

        \[\leadsto \color{blue}{\left(m \cdot m\right) \cdot \frac{m}{v}} + -1 \cdot \frac{{m}^{2}}{v} \]
      4. associate-*r*23.0%

        \[\leadsto \color{blue}{m \cdot \left(m \cdot \frac{m}{v}\right)} + -1 \cdot \frac{{m}^{2}}{v} \]
      5. unpow223.0%

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

        \[\leadsto m \cdot \left(m \cdot \frac{m}{v}\right) + -1 \cdot \color{blue}{\left(m \cdot \frac{m}{v}\right)} \]
      7. distribute-rgt-in98.3%

        \[\leadsto \color{blue}{\left(m \cdot \frac{m}{v}\right) \cdot \left(m + -1\right)} \]
      8. associate-*l*98.3%

        \[\leadsto \color{blue}{m \cdot \left(\frac{m}{v} \cdot \left(m + -1\right)\right)} \]
      9. +-commutative98.3%

        \[\leadsto m \cdot \left(\frac{m}{v} \cdot \color{blue}{\left(-1 + m\right)}\right) \]
    12. Simplified98.3%

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

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

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

Alternative 9: 73.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1.22 \cdot 10^{-117}:\\ \;\;\;\;-1\\ \mathbf{elif}\;m \leq 2.2:\\ \;\;\;\;\frac{m}{v}\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (if (<= m 1.22e-117) -1.0 (if (<= m 2.2) (/ m v) (* m (/ m v)))))
double code(double m, double v) {
	double tmp;
	if (m <= 1.22e-117) {
		tmp = -1.0;
	} else if (m <= 2.2) {
		tmp = m / v;
	} else {
		tmp = m * (m / v);
	}
	return tmp;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    real(8) :: tmp
    if (m <= 1.22d-117) then
        tmp = -1.0d0
    else if (m <= 2.2d0) then
        tmp = m / v
    else
        tmp = m * (m / v)
    end if
    code = tmp
end function
public static double code(double m, double v) {
	double tmp;
	if (m <= 1.22e-117) {
		tmp = -1.0;
	} else if (m <= 2.2) {
		tmp = m / v;
	} else {
		tmp = m * (m / v);
	}
	return tmp;
}
def code(m, v):
	tmp = 0
	if m <= 1.22e-117:
		tmp = -1.0
	elif m <= 2.2:
		tmp = m / v
	else:
		tmp = m * (m / v)
	return tmp
function code(m, v)
	tmp = 0.0
	if (m <= 1.22e-117)
		tmp = -1.0;
	elseif (m <= 2.2)
		tmp = Float64(m / v);
	else
		tmp = Float64(m * Float64(m / v));
	end
	return tmp
end
function tmp_2 = code(m, v)
	tmp = 0.0;
	if (m <= 1.22e-117)
		tmp = -1.0;
	elseif (m <= 2.2)
		tmp = m / v;
	else
		tmp = m * (m / v);
	end
	tmp_2 = tmp;
end
code[m_, v_] := If[LessEqual[m, 1.22e-117], -1.0, If[LessEqual[m, 2.2], N[(m / v), $MachinePrecision], N[(m * N[(m / v), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.22 \cdot 10^{-117}:\\
\;\;\;\;-1\\

\mathbf{elif}\;m \leq 2.2:\\
\;\;\;\;\frac{m}{v}\\

\mathbf{else}:\\
\;\;\;\;m \cdot \frac{m}{v}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < 1.21999999999999997e-117

    1. Initial program 100.0%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg100.0%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval100.0%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified100.0%

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

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

    if 1.21999999999999997e-117 < m < 2.2000000000000002

    1. Initial program 99.9%

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

      \[\leadsto \left(\frac{\color{blue}{m}}{v} - 1\right) \cdot \left(1 - m\right) \]
    3. Step-by-step derivation
      1. sub-neg94.5%

        \[\leadsto \left(\frac{m}{v} - 1\right) \cdot \color{blue}{\left(1 + \left(-m\right)\right)} \]
      2. distribute-rgt-in94.5%

        \[\leadsto \color{blue}{1 \cdot \left(\frac{m}{v} - 1\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right)} \]
      3. *-un-lft-identity94.5%

        \[\leadsto \color{blue}{\left(\frac{m}{v} - 1\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      4. sub-neg94.5%

        \[\leadsto \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      5. metadata-eval94.5%

        \[\leadsto \left(\frac{m}{v} + \color{blue}{-1}\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      6. add-sqr-sqrt0.0%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      7. sqrt-unprod94.1%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}} \cdot \left(\frac{m}{v} - 1\right) \]
      8. sqr-neg94.1%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \sqrt{\color{blue}{m \cdot m}} \cdot \left(\frac{m}{v} - 1\right) \]
      9. sqrt-prod94.1%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      10. add-sqr-sqrt94.1%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{m} \cdot \left(\frac{m}{v} - 1\right) \]
      11. sub-neg94.1%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} \]
      12. metadata-eval94.1%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + \color{blue}{-1}\right) \]
    4. Applied egg-rr94.1%

      \[\leadsto \color{blue}{\left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + -1\right)} \]
    5. Step-by-step derivation
      1. distribute-rgt1-in94.1%

        \[\leadsto \color{blue}{\left(m + 1\right) \cdot \left(\frac{m}{v} + -1\right)} \]
      2. +-commutative94.1%

        \[\leadsto \color{blue}{\left(1 + m\right)} \cdot \left(\frac{m}{v} + -1\right) \]
      3. +-commutative94.1%

        \[\leadsto \left(1 + m\right) \cdot \color{blue}{\left(-1 + \frac{m}{v}\right)} \]
    6. Simplified94.1%

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

      \[\leadsto \color{blue}{\frac{m \cdot \left(1 + m\right)}{v}} \]
    8. Step-by-step derivation
      1. associate-*r/79.7%

        \[\leadsto \color{blue}{m \cdot \frac{1 + m}{v}} \]
    9. Simplified79.7%

      \[\leadsto \color{blue}{m \cdot \frac{1 + m}{v}} \]
    10. Taylor expanded in m around 0 80.2%

      \[\leadsto \color{blue}{\frac{m}{v}} \]

    if 2.2000000000000002 < m

    1. Initial program 99.9%

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

      \[\leadsto \left(\frac{\color{blue}{m}}{v} - 1\right) \cdot \left(1 - m\right) \]
    3. Step-by-step derivation
      1. sub-neg0.1%

        \[\leadsto \left(\frac{m}{v} - 1\right) \cdot \color{blue}{\left(1 + \left(-m\right)\right)} \]
      2. distribute-rgt-in0.1%

        \[\leadsto \color{blue}{1 \cdot \left(\frac{m}{v} - 1\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right)} \]
      3. *-un-lft-identity0.1%

        \[\leadsto \color{blue}{\left(\frac{m}{v} - 1\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      4. sub-neg0.1%

        \[\leadsto \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      5. metadata-eval0.1%

        \[\leadsto \left(\frac{m}{v} + \color{blue}{-1}\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      6. add-sqr-sqrt0.0%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      7. sqrt-unprod77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}} \cdot \left(\frac{m}{v} - 1\right) \]
      8. sqr-neg77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \sqrt{\color{blue}{m \cdot m}} \cdot \left(\frac{m}{v} - 1\right) \]
      9. sqrt-prod77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      10. add-sqr-sqrt77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{m} \cdot \left(\frac{m}{v} - 1\right) \]
      11. sub-neg77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} \]
      12. metadata-eval77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + \color{blue}{-1}\right) \]
    4. Applied egg-rr77.6%

      \[\leadsto \color{blue}{\left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + -1\right)} \]
    5. Step-by-step derivation
      1. distribute-rgt1-in77.6%

        \[\leadsto \color{blue}{\left(m + 1\right) \cdot \left(\frac{m}{v} + -1\right)} \]
      2. +-commutative77.6%

        \[\leadsto \color{blue}{\left(1 + m\right)} \cdot \left(\frac{m}{v} + -1\right) \]
      3. +-commutative77.6%

        \[\leadsto \left(1 + m\right) \cdot \color{blue}{\left(-1 + \frac{m}{v}\right)} \]
    6. Simplified77.6%

      \[\leadsto \color{blue}{\left(1 + m\right) \cdot \left(-1 + \frac{m}{v}\right)} \]
    7. Taylor expanded in m around inf 77.6%

      \[\leadsto \color{blue}{\frac{{m}^{2}}{v}} \]
    8. Step-by-step derivation
      1. unpow277.6%

        \[\leadsto \frac{\color{blue}{m \cdot m}}{v} \]
      2. associate-*r/77.6%

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
    9. Simplified77.6%

      \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 1.22 \cdot 10^{-117}:\\ \;\;\;\;-1\\ \mathbf{elif}\;m \leq 2.2:\\ \;\;\;\;\frac{m}{v}\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \end{array} \]

Alternative 10: 87.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 2.4:\\ \;\;\;\;\frac{m}{v} + -1\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m + 1}{v}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (if (<= m 2.4) (+ (/ m v) -1.0) (* m (/ (+ m 1.0) v))))
double code(double m, double v) {
	double tmp;
	if (m <= 2.4) {
		tmp = (m / v) + -1.0;
	} else {
		tmp = m * ((m + 1.0) / v);
	}
	return tmp;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    real(8) :: tmp
    if (m <= 2.4d0) then
        tmp = (m / v) + (-1.0d0)
    else
        tmp = m * ((m + 1.0d0) / v)
    end if
    code = tmp
end function
public static double code(double m, double v) {
	double tmp;
	if (m <= 2.4) {
		tmp = (m / v) + -1.0;
	} else {
		tmp = m * ((m + 1.0) / v);
	}
	return tmp;
}
def code(m, v):
	tmp = 0
	if m <= 2.4:
		tmp = (m / v) + -1.0
	else:
		tmp = m * ((m + 1.0) / v)
	return tmp
function code(m, v)
	tmp = 0.0
	if (m <= 2.4)
		tmp = Float64(Float64(m / v) + -1.0);
	else
		tmp = Float64(m * Float64(Float64(m + 1.0) / v));
	end
	return tmp
end
function tmp_2 = code(m, v)
	tmp = 0.0;
	if (m <= 2.4)
		tmp = (m / v) + -1.0;
	else
		tmp = m * ((m + 1.0) / v);
	end
	tmp_2 = tmp;
end
code[m_, v_] := If[LessEqual[m, 2.4], N[(N[(m / v), $MachinePrecision] + -1.0), $MachinePrecision], N[(m * N[(N[(m + 1.0), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 2.4:\\
\;\;\;\;\frac{m}{v} + -1\\

\mathbf{else}:\\
\;\;\;\;m \cdot \frac{m + 1}{v}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < 2.39999999999999991

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval100.0%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 - m\right)} \]
      2. flip--100.0%

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

        \[\leadsto \color{blue}{\frac{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m}} \]
      4. fma-def100.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)} \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m} \]
      5. metadata-eval100.0%

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{\color{blue}{m + 1}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{m + 1}} \]
    6. Step-by-step derivation
      1. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)}{\frac{m + 1}{1 - m \cdot m}}} \]
    7. Simplified100.0%

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

      \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m - 1} \]
    9. Step-by-step derivation
      1. sub-neg97.8%

        \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m + \left(-1\right)} \]
      2. *-commutative97.8%

        \[\leadsto \color{blue}{m \cdot \left(1 + \frac{1}{v}\right)} + \left(-1\right) \]
      3. distribute-rgt-in97.8%

        \[\leadsto \color{blue}{\left(1 \cdot m + \frac{1}{v} \cdot m\right)} + \left(-1\right) \]
      4. *-lft-identity97.8%

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

        \[\leadsto \left(m + \color{blue}{\frac{1 \cdot m}{v}}\right) + \left(-1\right) \]
      6. *-lft-identity98.0%

        \[\leadsto \left(m + \frac{\color{blue}{m}}{v}\right) + \left(-1\right) \]
      7. metadata-eval98.0%

        \[\leadsto \left(m + \frac{m}{v}\right) + \color{blue}{-1} \]
    10. Simplified98.0%

      \[\leadsto \color{blue}{\left(m + \frac{m}{v}\right) + -1} \]
    11. Taylor expanded in v around 0 98.0%

      \[\leadsto \color{blue}{\frac{m}{v}} + -1 \]

    if 2.39999999999999991 < m

    1. Initial program 99.9%

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

      \[\leadsto \left(\frac{\color{blue}{m}}{v} - 1\right) \cdot \left(1 - m\right) \]
    3. Step-by-step derivation
      1. sub-neg0.1%

        \[\leadsto \left(\frac{m}{v} - 1\right) \cdot \color{blue}{\left(1 + \left(-m\right)\right)} \]
      2. distribute-rgt-in0.1%

        \[\leadsto \color{blue}{1 \cdot \left(\frac{m}{v} - 1\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right)} \]
      3. *-un-lft-identity0.1%

        \[\leadsto \color{blue}{\left(\frac{m}{v} - 1\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      4. sub-neg0.1%

        \[\leadsto \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      5. metadata-eval0.1%

        \[\leadsto \left(\frac{m}{v} + \color{blue}{-1}\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      6. add-sqr-sqrt0.0%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      7. sqrt-unprod77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}} \cdot \left(\frac{m}{v} - 1\right) \]
      8. sqr-neg77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \sqrt{\color{blue}{m \cdot m}} \cdot \left(\frac{m}{v} - 1\right) \]
      9. sqrt-prod77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      10. add-sqr-sqrt77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{m} \cdot \left(\frac{m}{v} - 1\right) \]
      11. sub-neg77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} \]
      12. metadata-eval77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + \color{blue}{-1}\right) \]
    4. Applied egg-rr77.6%

      \[\leadsto \color{blue}{\left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + -1\right)} \]
    5. Step-by-step derivation
      1. distribute-rgt1-in77.6%

        \[\leadsto \color{blue}{\left(m + 1\right) \cdot \left(\frac{m}{v} + -1\right)} \]
      2. +-commutative77.6%

        \[\leadsto \color{blue}{\left(1 + m\right)} \cdot \left(\frac{m}{v} + -1\right) \]
      3. +-commutative77.6%

        \[\leadsto \left(1 + m\right) \cdot \color{blue}{\left(-1 + \frac{m}{v}\right)} \]
    6. Simplified77.6%

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

      \[\leadsto \color{blue}{\frac{m \cdot \left(1 + m\right)}{v}} \]
    8. Step-by-step derivation
      1. associate-*r/77.6%

        \[\leadsto \color{blue}{m \cdot \frac{1 + m}{v}} \]
    9. Simplified77.6%

      \[\leadsto \color{blue}{m \cdot \frac{1 + m}{v}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 2.4:\\ \;\;\;\;\frac{m}{v} + -1\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m + 1}{v}\\ \end{array} \]

Alternative 11: 87.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 2.2:\\ \;\;\;\;\frac{m}{v} + -1\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (if (<= m 2.2) (+ (/ m v) -1.0) (* m (/ m v))))
double code(double m, double v) {
	double tmp;
	if (m <= 2.2) {
		tmp = (m / v) + -1.0;
	} else {
		tmp = m * (m / v);
	}
	return tmp;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    real(8) :: tmp
    if (m <= 2.2d0) then
        tmp = (m / v) + (-1.0d0)
    else
        tmp = m * (m / v)
    end if
    code = tmp
end function
public static double code(double m, double v) {
	double tmp;
	if (m <= 2.2) {
		tmp = (m / v) + -1.0;
	} else {
		tmp = m * (m / v);
	}
	return tmp;
}
def code(m, v):
	tmp = 0
	if m <= 2.2:
		tmp = (m / v) + -1.0
	else:
		tmp = m * (m / v)
	return tmp
function code(m, v)
	tmp = 0.0
	if (m <= 2.2)
		tmp = Float64(Float64(m / v) + -1.0);
	else
		tmp = Float64(m * Float64(m / v));
	end
	return tmp
end
function tmp_2 = code(m, v)
	tmp = 0.0;
	if (m <= 2.2)
		tmp = (m / v) + -1.0;
	else
		tmp = m * (m / v);
	end
	tmp_2 = tmp;
end
code[m_, v_] := If[LessEqual[m, 2.2], N[(N[(m / v), $MachinePrecision] + -1.0), $MachinePrecision], N[(m * N[(m / v), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 2.2:\\
\;\;\;\;\frac{m}{v} + -1\\

\mathbf{else}:\\
\;\;\;\;m \cdot \frac{m}{v}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < 2.2000000000000002

    1. Initial program 99.9%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg99.9%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval100.0%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
    4. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 - m\right)} \]
      2. flip--100.0%

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

        \[\leadsto \color{blue}{\frac{\left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right) \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m}} \]
      4. fma-def100.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)} \cdot \left(1 \cdot 1 - m \cdot m\right)}{1 + m} \]
      5. metadata-eval100.0%

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{\color{blue}{m + 1}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m \cdot m\right)}{m + 1}} \]
    6. Step-by-step derivation
      1. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right)}{\frac{m + 1}{1 - m \cdot m}}} \]
    7. Simplified100.0%

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

      \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m - 1} \]
    9. Step-by-step derivation
      1. sub-neg97.8%

        \[\leadsto \color{blue}{\left(1 + \frac{1}{v}\right) \cdot m + \left(-1\right)} \]
      2. *-commutative97.8%

        \[\leadsto \color{blue}{m \cdot \left(1 + \frac{1}{v}\right)} + \left(-1\right) \]
      3. distribute-rgt-in97.8%

        \[\leadsto \color{blue}{\left(1 \cdot m + \frac{1}{v} \cdot m\right)} + \left(-1\right) \]
      4. *-lft-identity97.8%

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

        \[\leadsto \left(m + \color{blue}{\frac{1 \cdot m}{v}}\right) + \left(-1\right) \]
      6. *-lft-identity98.0%

        \[\leadsto \left(m + \frac{\color{blue}{m}}{v}\right) + \left(-1\right) \]
      7. metadata-eval98.0%

        \[\leadsto \left(m + \frac{m}{v}\right) + \color{blue}{-1} \]
    10. Simplified98.0%

      \[\leadsto \color{blue}{\left(m + \frac{m}{v}\right) + -1} \]
    11. Taylor expanded in v around 0 98.0%

      \[\leadsto \color{blue}{\frac{m}{v}} + -1 \]

    if 2.2000000000000002 < m

    1. Initial program 99.9%

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

      \[\leadsto \left(\frac{\color{blue}{m}}{v} - 1\right) \cdot \left(1 - m\right) \]
    3. Step-by-step derivation
      1. sub-neg0.1%

        \[\leadsto \left(\frac{m}{v} - 1\right) \cdot \color{blue}{\left(1 + \left(-m\right)\right)} \]
      2. distribute-rgt-in0.1%

        \[\leadsto \color{blue}{1 \cdot \left(\frac{m}{v} - 1\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right)} \]
      3. *-un-lft-identity0.1%

        \[\leadsto \color{blue}{\left(\frac{m}{v} - 1\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      4. sub-neg0.1%

        \[\leadsto \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      5. metadata-eval0.1%

        \[\leadsto \left(\frac{m}{v} + \color{blue}{-1}\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      6. add-sqr-sqrt0.0%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      7. sqrt-unprod77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}} \cdot \left(\frac{m}{v} - 1\right) \]
      8. sqr-neg77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \sqrt{\color{blue}{m \cdot m}} \cdot \left(\frac{m}{v} - 1\right) \]
      9. sqrt-prod77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      10. add-sqr-sqrt77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{m} \cdot \left(\frac{m}{v} - 1\right) \]
      11. sub-neg77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} \]
      12. metadata-eval77.6%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + \color{blue}{-1}\right) \]
    4. Applied egg-rr77.6%

      \[\leadsto \color{blue}{\left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + -1\right)} \]
    5. Step-by-step derivation
      1. distribute-rgt1-in77.6%

        \[\leadsto \color{blue}{\left(m + 1\right) \cdot \left(\frac{m}{v} + -1\right)} \]
      2. +-commutative77.6%

        \[\leadsto \color{blue}{\left(1 + m\right)} \cdot \left(\frac{m}{v} + -1\right) \]
      3. +-commutative77.6%

        \[\leadsto \left(1 + m\right) \cdot \color{blue}{\left(-1 + \frac{m}{v}\right)} \]
    6. Simplified77.6%

      \[\leadsto \color{blue}{\left(1 + m\right) \cdot \left(-1 + \frac{m}{v}\right)} \]
    7. Taylor expanded in m around inf 77.6%

      \[\leadsto \color{blue}{\frac{{m}^{2}}{v}} \]
    8. Step-by-step derivation
      1. unpow277.6%

        \[\leadsto \frac{\color{blue}{m \cdot m}}{v} \]
      2. associate-*r/77.6%

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
    9. Simplified77.6%

      \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 2.2:\\ \;\;\;\;\frac{m}{v} + -1\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \end{array} \]

Alternative 12: 60.7% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1.22 \cdot 10^{-117}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{m}{v}\\ \end{array} \end{array} \]
(FPCore (m v) :precision binary64 (if (<= m 1.22e-117) -1.0 (/ m v)))
double code(double m, double v) {
	double tmp;
	if (m <= 1.22e-117) {
		tmp = -1.0;
	} else {
		tmp = m / v;
	}
	return tmp;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    real(8) :: tmp
    if (m <= 1.22d-117) then
        tmp = -1.0d0
    else
        tmp = m / v
    end if
    code = tmp
end function
public static double code(double m, double v) {
	double tmp;
	if (m <= 1.22e-117) {
		tmp = -1.0;
	} else {
		tmp = m / v;
	}
	return tmp;
}
def code(m, v):
	tmp = 0
	if m <= 1.22e-117:
		tmp = -1.0
	else:
		tmp = m / v
	return tmp
function code(m, v)
	tmp = 0.0
	if (m <= 1.22e-117)
		tmp = -1.0;
	else
		tmp = Float64(m / v);
	end
	return tmp
end
function tmp_2 = code(m, v)
	tmp = 0.0;
	if (m <= 1.22e-117)
		tmp = -1.0;
	else
		tmp = m / v;
	end
	tmp_2 = tmp;
end
code[m_, v_] := If[LessEqual[m, 1.22e-117], -1.0, N[(m / v), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.22 \cdot 10^{-117}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;\frac{m}{v}\\


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

    1. Initial program 100.0%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. sub-neg100.0%

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

        \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
      4. metadata-eval100.0%

        \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
    3. Simplified100.0%

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

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

    if 1.21999999999999997e-117 < m

    1. Initial program 99.9%

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

      \[\leadsto \left(\frac{\color{blue}{m}}{v} - 1\right) \cdot \left(1 - m\right) \]
    3. Step-by-step derivation
      1. sub-neg22.6%

        \[\leadsto \left(\frac{m}{v} - 1\right) \cdot \color{blue}{\left(1 + \left(-m\right)\right)} \]
      2. distribute-rgt-in22.6%

        \[\leadsto \color{blue}{1 \cdot \left(\frac{m}{v} - 1\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right)} \]
      3. *-un-lft-identity22.6%

        \[\leadsto \color{blue}{\left(\frac{m}{v} - 1\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      4. sub-neg22.6%

        \[\leadsto \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      5. metadata-eval22.6%

        \[\leadsto \left(\frac{m}{v} + \color{blue}{-1}\right) + \left(-m\right) \cdot \left(\frac{m}{v} - 1\right) \]
      6. add-sqr-sqrt0.0%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      7. sqrt-unprod81.5%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}} \cdot \left(\frac{m}{v} - 1\right) \]
      8. sqr-neg81.5%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \sqrt{\color{blue}{m \cdot m}} \cdot \left(\frac{m}{v} - 1\right) \]
      9. sqrt-prod81.5%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)} \cdot \left(\frac{m}{v} - 1\right) \]
      10. add-sqr-sqrt81.5%

        \[\leadsto \left(\frac{m}{v} + -1\right) + \color{blue}{m} \cdot \left(\frac{m}{v} - 1\right) \]
      11. sub-neg81.5%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \color{blue}{\left(\frac{m}{v} + \left(-1\right)\right)} \]
      12. metadata-eval81.5%

        \[\leadsto \left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + \color{blue}{-1}\right) \]
    4. Applied egg-rr81.5%

      \[\leadsto \color{blue}{\left(\frac{m}{v} + -1\right) + m \cdot \left(\frac{m}{v} + -1\right)} \]
    5. Step-by-step derivation
      1. distribute-rgt1-in81.5%

        \[\leadsto \color{blue}{\left(m + 1\right) \cdot \left(\frac{m}{v} + -1\right)} \]
      2. +-commutative81.5%

        \[\leadsto \color{blue}{\left(1 + m\right)} \cdot \left(\frac{m}{v} + -1\right) \]
      3. +-commutative81.5%

        \[\leadsto \left(1 + m\right) \cdot \color{blue}{\left(-1 + \frac{m}{v}\right)} \]
    6. Simplified81.5%

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

      \[\leadsto \color{blue}{\frac{m \cdot \left(1 + m\right)}{v}} \]
    8. Step-by-step derivation
      1. associate-*r/78.1%

        \[\leadsto \color{blue}{m \cdot \frac{1 + m}{v}} \]
    9. Simplified78.1%

      \[\leadsto \color{blue}{m \cdot \frac{1 + m}{v}} \]
    10. Taylor expanded in m around 0 60.6%

      \[\leadsto \color{blue}{\frac{m}{v}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 1.22 \cdot 10^{-117}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{m}{v}\\ \end{array} \]

Alternative 13: 27.0% accurate, 4.3× speedup?

\[\begin{array}{l} \\ m + -1 \end{array} \]
(FPCore (m v) :precision binary64 (+ m -1.0))
double code(double m, double v) {
	return m + -1.0;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    code = m + (-1.0d0)
end function
public static double code(double m, double v) {
	return m + -1.0;
}
def code(m, v):
	return m + -1.0
function code(m, v)
	return Float64(m + -1.0)
end
function tmp = code(m, v)
	tmp = m + -1.0;
end
code[m_, v_] := N[(m + -1.0), $MachinePrecision]
\begin{array}{l}

\\
m + -1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
  2. Step-by-step derivation
    1. *-commutative99.9%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
    2. sub-neg99.9%

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

      \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
    4. metadata-eval99.9%

      \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + -1\right)} \]
  4. Taylor expanded in v around inf 26.8%

    \[\leadsto \color{blue}{-1 \cdot \left(1 - m\right)} \]
  5. Step-by-step derivation
    1. neg-mul-126.8%

      \[\leadsto \color{blue}{-\left(1 - m\right)} \]
    2. neg-sub026.8%

      \[\leadsto \color{blue}{0 - \left(1 - m\right)} \]
    3. associate--r-26.8%

      \[\leadsto \color{blue}{\left(0 - 1\right) + m} \]
    4. metadata-eval26.8%

      \[\leadsto \color{blue}{-1} + m \]
  6. Simplified26.8%

    \[\leadsto \color{blue}{-1 + m} \]
  7. Final simplification26.8%

    \[\leadsto m + -1 \]

Alternative 14: 24.6% accurate, 13.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (m v) :precision binary64 -1.0)
double code(double m, double v) {
	return -1.0;
}
real(8) function code(m, v)
    real(8), intent (in) :: m
    real(8), intent (in) :: v
    code = -1.0d0
end function
public static double code(double m, double v) {
	return -1.0;
}
def code(m, v):
	return -1.0
function code(m, v)
	return -1.0
end
function tmp = code(m, v)
	tmp = -1.0;
end
code[m_, v_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \]
  2. Step-by-step derivation
    1. *-commutative99.9%

      \[\leadsto \color{blue}{\left(1 - m\right) \cdot \left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
    2. sub-neg99.9%

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

      \[\leadsto \left(1 - m\right) \cdot \left(\color{blue}{\frac{m}{v} \cdot \left(1 - m\right)} + \left(-1\right)\right) \]
    4. metadata-eval99.9%

      \[\leadsto \left(1 - m\right) \cdot \left(\frac{m}{v} \cdot \left(1 - m\right) + \color{blue}{-1}\right) \]
  3. Simplified99.9%

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

    \[\leadsto \color{blue}{-1} \]
  5. Final simplification24.1%

    \[\leadsto -1 \]

Reproduce

?
herbie shell --seed 2023215 
(FPCore (m v)
  :name "b 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) (- 1.0 m)))