a parameter of renormalized beta distribution

Percentage Accurate: 99.8% → 99.6%
Time: 6.7s
Alternatives: 9
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;
}
real(8) function code(m, v)
    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 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 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;
}
real(8) function code(m, v)
    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.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq 5 \cdot 10^{-28}:\\
\;\;\;\;m \cdot \frac{m}{v} - m\\

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


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

    1. Initial program 99.8%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
    2. Step-by-step derivation
      1. associate-*r/99.8%

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

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

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

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

        \[\leadsto \color{blue}{\frac{{m}^{2}}{v} + -1 \cdot m} \]
      2. unpow287.4%

        \[\leadsto \frac{\color{blue}{m \cdot m}}{v} + -1 \cdot m \]
      3. associate-*r/99.9%

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} + -1 \cdot m \]
      4. mul-1-neg99.9%

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

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

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

    if 5.0000000000000002e-28 < m

    1. Initial program 99.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{m \cdot \mathsf{fma}\left(m, \frac{1 - m}{v}, -1\right)} \]
    4. Step-by-step derivation
      1. metadata-eval99.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{{m}^{2} \cdot \left(1 - m\right)}{v}} \]
    7. Step-by-step derivation
      1. unpow299.9%

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

        \[\leadsto \color{blue}{\frac{m \cdot m}{\frac{v}{1 - m}}} \]
      3. associate-/r/99.9%

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

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

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

Alternative 2: 99.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq 6.6 \cdot 10^{-16}:\\
\;\;\;\;m \cdot \frac{m}{v} - m\\

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


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

    1. Initial program 99.8%

      \[\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot m \]
    2. Step-by-step derivation
      1. associate-*r/99.7%

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

        \[\leadsto \left(\color{blue}{\frac{1 - m}{v} \cdot m} - 1\right) \cdot m \]
    3. Applied egg-rr99.7%

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

      \[\leadsto \color{blue}{-1 \cdot m + \frac{{m}^{2}}{v}} \]
    5. Step-by-step derivation
      1. +-commutative87.6%

        \[\leadsto \color{blue}{\frac{{m}^{2}}{v} + -1 \cdot m} \]
      2. unpow287.6%

        \[\leadsto \frac{\color{blue}{m \cdot m}}{v} + -1 \cdot m \]
      3. associate-*r/99.9%

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} + -1 \cdot m \]
      4. mul-1-neg99.9%

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

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

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

    if 6.59999999999999976e-16 < m

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \color{blue}{\left(m \cdot \frac{1 - m}{v}\right)} \]
      5. associate-*r*99.9%

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

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

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

Alternative 3: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
    7. *-lft-identity99.9%

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

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

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

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

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

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

      \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
    14. /-rgt-identity99.9%

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

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

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

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

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

Alternative 4: 74.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq 1.18 \cdot 10^{-178}:\\ \;\;\;\;-m\\ \mathbf{elif}\;m \leq 1:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \mathbf{else}:\\ \;\;\;\;m \cdot \frac{m}{-v}\\ \end{array} \end{array} \]
(FPCore (m v)
 :precision binary64
 (if (<= m 1.18e-178) (- m) (if (<= m 1.0) (* m (/ m v)) (* m (/ m (- v))))))
double code(double m, double v) {
	double tmp;
	if (m <= 1.18e-178) {
		tmp = -m;
	} else if (m <= 1.0) {
		tmp = m * (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.18d-178) then
        tmp = -m
    else if (m <= 1.0d0) then
        tmp = m * (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.18e-178) {
		tmp = -m;
	} else if (m <= 1.0) {
		tmp = m * (m / v);
	} else {
		tmp = m * (m / -v);
	}
	return tmp;
}
def code(m, v):
	tmp = 0
	if m <= 1.18e-178:
		tmp = -m
	elif m <= 1.0:
		tmp = m * (m / v)
	else:
		tmp = m * (m / -v)
	return tmp
function code(m, v)
	tmp = 0.0
	if (m <= 1.18e-178)
		tmp = Float64(-m);
	elseif (m <= 1.0)
		tmp = Float64(m * Float64(m / v));
	else
		tmp = Float64(m * Float64(m / Float64(-v)));
	end
	return tmp
end
function tmp_2 = code(m, v)
	tmp = 0.0;
	if (m <= 1.18e-178)
		tmp = -m;
	elseif (m <= 1.0)
		tmp = m * (m / v);
	else
		tmp = m * (m / -v);
	end
	tmp_2 = tmp;
end
code[m_, v_] := If[LessEqual[m, 1.18e-178], (-m), If[LessEqual[m, 1.0], N[(m * N[(m / v), $MachinePrecision]), $MachinePrecision], N[(m * N[(m / (-v)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.18 \cdot 10^{-178}:\\
\;\;\;\;-m\\

\mathbf{elif}\;m \leq 1:\\
\;\;\;\;m \cdot \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.18000000000000006e-178

    1. Initial program 99.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
      7. *-lft-identity99.9%

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    5. Step-by-step derivation
      1. neg-mul-183.6%

        \[\leadsto \color{blue}{-m} \]
    6. Simplified83.6%

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

    if 1.18000000000000006e-178 < m < 1

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.7%

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \color{blue}{\left(m \cdot \frac{1 - m}{v}\right)} \]
      5. associate-*r*70.1%

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

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

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

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

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
    9. Simplified70.2%

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

    if 1 < m

    1. Initial program 99.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
      7. *-lft-identity99.9%

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \color{blue}{\left(m \cdot \frac{1 - m}{v}\right)} \]
      5. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
    10. Step-by-step derivation
      1. associate-*r/0.1%

        \[\leadsto \color{blue}{\frac{m \cdot m}{v}} \]
      2. frac-2neg0.1%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{-v}} \]
      3. distribute-rgt-neg-in0.1%

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

        \[\leadsto \frac{m \cdot \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)}}{-v} \]
      5. sqrt-unprod78.0%

        \[\leadsto \frac{m \cdot \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}}}{-v} \]
      6. sqr-neg78.0%

        \[\leadsto \frac{m \cdot \sqrt{\color{blue}{m \cdot m}}}{-v} \]
      7. sqrt-prod78.0%

        \[\leadsto \frac{m \cdot \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)}}{-v} \]
      8. add-sqr-sqrt78.0%

        \[\leadsto \frac{m \cdot \color{blue}{m}}{-v} \]
    11. Applied egg-rr78.0%

      \[\leadsto \color{blue}{\frac{m \cdot m}{-v}} \]
    12. Step-by-step derivation
      1. associate-/l*78.0%

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

        \[\leadsto \color{blue}{\frac{m}{-v} \cdot m} \]
    13. Simplified78.0%

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

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

Alternative 5: 97.9% accurate, 1.1× speedup?

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

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

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


\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. Step-by-step derivation
      1. associate-*r/99.7%

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

        \[\leadsto \left(\color{blue}{\frac{1 - m}{v} \cdot m} - 1\right) \cdot m \]
    3. Applied egg-rr99.7%

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

      \[\leadsto \color{blue}{-1 \cdot m + \frac{{m}^{2}}{v}} \]
    5. Step-by-step derivation
      1. +-commutative85.5%

        \[\leadsto \color{blue}{\frac{{m}^{2}}{v} + -1 \cdot m} \]
      2. unpow285.5%

        \[\leadsto \frac{\color{blue}{m \cdot m}}{v} + -1 \cdot m \]
      3. associate-*r/97.2%

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} + -1 \cdot m \]
      4. mul-1-neg97.2%

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

        \[\leadsto \color{blue}{m \cdot \frac{m}{v} - m} \]
    6. Simplified97.2%

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

    if 1 < m

    1. Initial program 99.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
      7. *-lft-identity99.9%

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 87.5% accurate, 1.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;m \cdot \frac{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. Taylor expanded in m around 0 97.1%

      \[\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. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
      7. *-lft-identity99.9%

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \color{blue}{\left(m \cdot \frac{1 - m}{v}\right)} \]
      5. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
    10. Step-by-step derivation
      1. associate-*r/0.1%

        \[\leadsto \color{blue}{\frac{m \cdot m}{v}} \]
      2. frac-2neg0.1%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{-v}} \]
      3. distribute-rgt-neg-in0.1%

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

        \[\leadsto \frac{m \cdot \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)}}{-v} \]
      5. sqrt-unprod78.0%

        \[\leadsto \frac{m \cdot \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}}}{-v} \]
      6. sqr-neg78.0%

        \[\leadsto \frac{m \cdot \sqrt{\color{blue}{m \cdot m}}}{-v} \]
      7. sqrt-prod78.0%

        \[\leadsto \frac{m \cdot \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)}}{-v} \]
      8. add-sqr-sqrt78.0%

        \[\leadsto \frac{m \cdot \color{blue}{m}}{-v} \]
    11. Applied egg-rr78.0%

      \[\leadsto \color{blue}{\frac{m \cdot m}{-v}} \]
    12. Step-by-step derivation
      1. associate-/l*78.0%

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

        \[\leadsto \color{blue}{\frac{m}{-v} \cdot m} \]
    13. Simplified78.0%

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

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

Alternative 7: 87.5% accurate, 1.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;m \cdot \frac{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. Step-by-step derivation
      1. associate-*r/99.7%

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

        \[\leadsto \left(\color{blue}{\frac{1 - m}{v} \cdot m} - 1\right) \cdot m \]
    3. Applied egg-rr99.7%

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

      \[\leadsto \color{blue}{-1 \cdot m + \frac{{m}^{2}}{v}} \]
    5. Step-by-step derivation
      1. +-commutative85.5%

        \[\leadsto \color{blue}{\frac{{m}^{2}}{v} + -1 \cdot m} \]
      2. unpow285.5%

        \[\leadsto \frac{\color{blue}{m \cdot m}}{v} + -1 \cdot m \]
      3. associate-*r/97.2%

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} + -1 \cdot m \]
      4. mul-1-neg97.2%

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

        \[\leadsto \color{blue}{m \cdot \frac{m}{v} - m} \]
    6. Simplified97.2%

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

    if 1 < m

    1. Initial program 99.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
      7. *-lft-identity99.9%

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \color{blue}{\left(m \cdot \frac{1 - m}{v}\right)} \]
      5. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
    10. Step-by-step derivation
      1. associate-*r/0.1%

        \[\leadsto \color{blue}{\frac{m \cdot m}{v}} \]
      2. frac-2neg0.1%

        \[\leadsto \color{blue}{\frac{-m \cdot m}{-v}} \]
      3. distribute-rgt-neg-in0.1%

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

        \[\leadsto \frac{m \cdot \color{blue}{\left(\sqrt{-m} \cdot \sqrt{-m}\right)}}{-v} \]
      5. sqrt-unprod78.0%

        \[\leadsto \frac{m \cdot \color{blue}{\sqrt{\left(-m\right) \cdot \left(-m\right)}}}{-v} \]
      6. sqr-neg78.0%

        \[\leadsto \frac{m \cdot \sqrt{\color{blue}{m \cdot m}}}{-v} \]
      7. sqrt-prod78.0%

        \[\leadsto \frac{m \cdot \color{blue}{\left(\sqrt{m} \cdot \sqrt{m}\right)}}{-v} \]
      8. add-sqr-sqrt78.0%

        \[\leadsto \frac{m \cdot \color{blue}{m}}{-v} \]
    11. Applied egg-rr78.0%

      \[\leadsto \color{blue}{\frac{m \cdot m}{-v}} \]
    12. Step-by-step derivation
      1. associate-/l*78.0%

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

        \[\leadsto \color{blue}{\frac{m}{-v} \cdot m} \]
    13. Simplified78.0%

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

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

Alternative 8: 37.6% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;v \leq 4.8 \cdot 10^{-185}:\\
\;\;\;\;m \cdot \frac{m}{v}\\

\mathbf{else}:\\
\;\;\;\;-m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if v < 4.8000000000000002e-185

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

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

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

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

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

        \[\leadsto m \cdot \color{blue}{\left(m \cdot \frac{1 - m}{v}\right)} \]
      5. associate-*r*83.6%

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

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

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

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

        \[\leadsto \color{blue}{m \cdot \frac{m}{v}} \]
    9. Simplified39.2%

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

    if 4.8000000000000002e-185 < v

    1. Initial program 99.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
      7. *-lft-identity99.9%

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

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

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

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

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

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

        \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
      14. /-rgt-identity99.9%

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    5. Step-by-step derivation
      1. neg-mul-145.3%

        \[\leadsto \color{blue}{-m} \]
    6. Simplified45.3%

      \[\leadsto \color{blue}{-m} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification42.7%

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

Alternative 9: 27.2% accurate, 5.5× speedup?

\[\begin{array}{l} \\ -m \end{array} \]
(FPCore (m v) :precision binary64 (- m))
double code(double m, double v) {
	return -m;
}
real(8) function code(m, v)
    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. Step-by-step derivation
    1. *-commutative99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(m \cdot \left(1 - m\right)\right) \cdot \frac{m}{v}} + m \cdot \left(-1\right) \]
    7. *-lft-identity99.9%

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

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

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

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

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

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

      \[\leadsto m \cdot \left(\color{blue}{\frac{m \cdot \left(1 - m\right)}{\frac{v}{1}}} + \left(-1\right)\right) \]
    14. /-rgt-identity99.9%

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot m} \]
  5. Step-by-step derivation
    1. neg-mul-129.2%

      \[\leadsto \color{blue}{-m} \]
  6. Simplified29.2%

    \[\leadsto \color{blue}{-m} \]
  7. Final simplification29.2%

    \[\leadsto -m \]

Reproduce

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