a parameter of renormalized beta distribution

Percentage Accurate: 99.8% → 99.6%
Time: 9.2s
Alternatives: 10
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 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 10 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, 0.8× speedup?

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

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

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


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

    1. Initial program 99.8%

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

        \[\leadsto m \cdot \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. distribute-rgt-out--N/A

        \[\leadsto \frac{m \cdot \left(1 - m\right)}{v} \cdot m - \color{blue}{1 \cdot m} \]
      3. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{\_.f64}\left(\left(m \cdot \frac{m \cdot \left(1 - m\right)}{v}\right), m\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \left(\frac{m \cdot \left(1 - m\right)}{v}\right)\right), m\right) \]
      7. associate-/l*N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \left(m \cdot \frac{1 - m}{v}\right)\right), m\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \left(\frac{1 - m}{v}\right)\right)\right), m\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\left(1 - m\right), v\right)\right)\right), m\right) \]
      10. --lowering--.f6499.7%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, m\right), v\right)\right)\right), m\right) \]
    4. Applied egg-rr99.7%

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

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \color{blue}{\left(\frac{m}{v}\right)}\right), m\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f6499.8%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{/.f64}\left(m, v\right)\right), m\right) \]
    7. Simplified99.8%

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

    if 4.99999999999999954e-22 < m

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{{m}^{3} \cdot \left(\frac{1}{m \cdot v} - \frac{1}{v}\right)} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

        \[\leadsto \left(\left(m \cdot m\right) \cdot m\right) \cdot \frac{1}{m \cdot v} + \left(\mathsf{neg}\left(\color{blue}{\frac{1}{v}}\right)\right) \cdot {m}^{3} \]
      5. unpow2N/A

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

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

        \[\leadsto {m}^{2} \cdot \left(m \cdot \frac{\frac{1}{m}}{v}\right) + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      8. associate-*r/N/A

        \[\leadsto {m}^{2} \cdot \frac{m \cdot \frac{1}{m}}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      9. rgt-mult-inverseN/A

        \[\leadsto {m}^{2} \cdot \frac{1}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{v}\right)\right)} \cdot {m}^{3} \]
      11. cube-multN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot \left(m \cdot \color{blue}{\left(m \cdot m\right)}\right) \]
      12. unpow2N/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot m\right) \cdot \color{blue}{{m}^{2}} \]
      14. distribute-lft-neg-inN/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1 \cdot m}{v}\right)\right) \cdot {m}^{2} \]
      16. *-lft-identityN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{m}{v}\right)\right) \cdot {m}^{2} \]
      17. mul-1-negN/A

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

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

      \[\leadsto \color{blue}{\frac{m \cdot \left(m \cdot \left(1 - m\right)\right)}{v}} \]
    6. Step-by-step derivation
      1. clear-numN/A

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

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

        \[\leadsto \frac{1}{\frac{v \cdot \frac{1}{m \cdot \left(1 - m\right)}}{m}} \]
      4. clear-numN/A

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

        \[\leadsto \mathsf{/.f64}\left(m, \color{blue}{\left(v \cdot \frac{1}{m \cdot \left(1 - m\right)}\right)}\right) \]
      6. div-invN/A

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

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \color{blue}{\left(m \cdot \left(1 - m\right)\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \mathsf{*.f64}\left(m, \color{blue}{\left(1 - m\right)}\right)\right)\right) \]
      9. --lowering--.f6499.9%

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \mathsf{*.f64}\left(m, \mathsf{\_.f64}\left(1, \color{blue}{m}\right)\right)\right)\right) \]
    7. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{m}{\frac{v}{m \cdot \left(1 - m\right)}}} \]
    8. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \left(m \cdot \left(1 + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right)\right)\right)\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \left(m \cdot 1 + \color{blue}{m \cdot \left(\mathsf{neg}\left(m\right)\right)}\right)\right)\right) \]
      3. distribute-rgt-neg-inN/A

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \left(m \cdot 1 + \left(\mathsf{neg}\left(m \cdot m\right)\right)\right)\right)\right) \]
      4. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \left(m \cdot 1 - \color{blue}{m \cdot m}\right)\right)\right) \]
      5. *-rgt-identityN/A

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \left(m - \color{blue}{m} \cdot m\right)\right)\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \mathsf{\_.f64}\left(m, \color{blue}{\left(m \cdot m\right)}\right)\right)\right) \]
      7. *-lowering-*.f6499.9%

        \[\leadsto \mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \mathsf{\_.f64}\left(m, \mathsf{*.f64}\left(m, \color{blue}{m}\right)\right)\right)\right) \]
    9. Applied egg-rr99.9%

      \[\leadsto \frac{m}{\frac{v}{\color{blue}{m - m \cdot m}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 60.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq 4.7 \cdot 10^{-104}:\\
\;\;\;\;0 - m\\

\mathbf{elif}\;m \leq 1:\\
\;\;\;\;m \cdot \frac{m}{v}\\

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


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

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{m} \]
      3. --lowering--.f6471.8%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
    5. Simplified71.8%

      \[\leadsto \color{blue}{0 - m} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-lowering-neg.f6471.8%

        \[\leadsto \mathsf{neg.f64}\left(m\right) \]
    7. Applied egg-rr71.8%

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

    if 4.7e-104 < m < 1

    1. Initial program 99.6%

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

      \[\leadsto \color{blue}{{m}^{3} \cdot \left(\frac{1}{m \cdot v} - \frac{1}{v}\right)} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

        \[\leadsto \left(\left(m \cdot m\right) \cdot m\right) \cdot \frac{1}{m \cdot v} + \left(\mathsf{neg}\left(\color{blue}{\frac{1}{v}}\right)\right) \cdot {m}^{3} \]
      5. unpow2N/A

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

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

        \[\leadsto {m}^{2} \cdot \left(m \cdot \frac{\frac{1}{m}}{v}\right) + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      8. associate-*r/N/A

        \[\leadsto {m}^{2} \cdot \frac{m \cdot \frac{1}{m}}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      9. rgt-mult-inverseN/A

        \[\leadsto {m}^{2} \cdot \frac{1}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{v}\right)\right)} \cdot {m}^{3} \]
      11. cube-multN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot \left(m \cdot \color{blue}{\left(m \cdot m\right)}\right) \]
      12. unpow2N/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot m\right) \cdot \color{blue}{{m}^{2}} \]
      14. distribute-lft-neg-inN/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1 \cdot m}{v}\right)\right) \cdot {m}^{2} \]
      16. *-lft-identityN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{m}{v}\right)\right) \cdot {m}^{2} \]
      17. mul-1-negN/A

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

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

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

      \[\leadsto \color{blue}{\frac{{m}^{2}}{v}} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({m}^{2}\right), \color{blue}{v}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(m \cdot m\right), v\right) \]
      3. *-lowering-*.f6478.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(m, m\right), v\right) \]
    8. Simplified78.2%

      \[\leadsto \color{blue}{\frac{m \cdot m}{v}} \]
    9. Step-by-step derivation
      1. associate-/l*N/A

        \[\leadsto m \cdot \color{blue}{\frac{m}{v}} \]
      2. clear-numN/A

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

        \[\leadsto \frac{m \cdot 1}{\color{blue}{\frac{v}{m}}} \]
      4. div-invN/A

        \[\leadsto \frac{m \cdot 1}{v \cdot \color{blue}{\frac{1}{m}}} \]
      5. times-fracN/A

        \[\leadsto \frac{m}{v} \cdot \color{blue}{\frac{1}{\frac{1}{m}}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{m}{v} \cdot \frac{1}{\frac{\mathsf{neg}\left(-1\right)}{m}} \]
      7. distribute-neg-fracN/A

        \[\leadsto \frac{m}{v} \cdot \frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{m}{v}\right), \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)}\right) \]
      9. remove-double-divN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{1}{\frac{m}{v}}}\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      10. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{1}{m} \cdot v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      11. associate-/r*N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\frac{1}{m}}}{v}\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\frac{\mathsf{neg}\left(-1\right)}{m}}}{v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      13. distribute-neg-fracN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}}{v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      14. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right), v\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\frac{1}{\frac{-1}{m}}\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      16. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\frac{1}{-1} \cdot m\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      17. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(-1 \cdot m\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      18. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m\right)\right)\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      19. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      20. distribute-frac-neg2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\frac{1}{\frac{-1}{m}}\right)\right)\right) \]
      21. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\frac{1}{-1} \cdot m\right)\right)\right) \]
      22. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(-1 \cdot m\right)\right)\right) \]
      23. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m\right)\right)\right)\right)\right) \]
      24. remove-double-neg78.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), m\right) \]
    10. Applied egg-rr78.5%

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

    if 1 < m

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{m} \]
      3. --lowering--.f645.6%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
    5. Simplified5.6%

      \[\leadsto \color{blue}{0 - m} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-lowering-neg.f645.6%

        \[\leadsto \mathsf{neg.f64}\left(m\right) \]
    7. Applied egg-rr5.6%

      \[\leadsto \color{blue}{-m} \]
    8. Step-by-step derivation
      1. neg-mul-1N/A

        \[\leadsto -1 \cdot \color{blue}{m} \]
      2. metadata-evalN/A

        \[\leadsto \left(-1 \cdot 1\right) \cdot m \]
      3. metadata-evalN/A

        \[\leadsto \left(-1 \cdot {v}^{0}\right) \cdot m \]
      4. metadata-evalN/A

        \[\leadsto \left(-1 \cdot {v}^{\left(-1 + 1\right)}\right) \cdot m \]
      5. pow-plusN/A

        \[\leadsto \left(-1 \cdot \left({v}^{-1} \cdot v\right)\right) \cdot m \]
      6. inv-powN/A

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

        \[\leadsto \left(\left(-1 \cdot \frac{1}{v}\right) \cdot v\right) \cdot m \]
      8. div-invN/A

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

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

        \[\leadsto \frac{-1}{v} \cdot \left(m \cdot \color{blue}{v}\right) \]
      11. clear-numN/A

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

        \[\leadsto \frac{1 \cdot \left(m \cdot v\right)}{\color{blue}{\frac{v}{-1}}} \]
      13. div-invN/A

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

        \[\leadsto \frac{1 \cdot \left(m \cdot v\right)}{v \cdot -1} \]
      15. *-lft-identityN/A

        \[\leadsto \frac{m \cdot v}{\color{blue}{v} \cdot -1} \]
      16. times-fracN/A

        \[\leadsto \frac{m}{v} \cdot \color{blue}{\frac{v}{-1}} \]
      17. frac-2negN/A

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

        \[\leadsto \frac{m}{v} \cdot \frac{\mathsf{neg}\left(v\right)}{1} \]
      19. /-rgt-identityN/A

        \[\leadsto \frac{m}{v} \cdot \left(\mathsf{neg}\left(v\right)\right) \]
      20. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{m}{v}\right), \color{blue}{\left(\mathsf{neg}\left(v\right)\right)}\right) \]
      21. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\color{blue}{v}\right)\right)\right) \]
      22. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(0 - \color{blue}{v}\right)\right) \]
      23. --lowering--.f6453.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{\_.f64}\left(0, \color{blue}{v}\right)\right) \]
    9. Applied egg-rr53.5%

      \[\leadsto \color{blue}{\frac{m}{v} \cdot \left(0 - v\right)} \]
    10. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(v\right)\right)\right) \]
      2. neg-lowering-neg.f6453.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{neg.f64}\left(v\right)\right) \]
    11. Applied egg-rr53.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 4.7 \cdot 10^{-104}:\\ \;\;\;\;0 - m\\ \mathbf{elif}\;m \leq 1:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \mathbf{else}:\\ \;\;\;\;0 - v \cdot \frac{m}{v}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 36.6% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq 3.2 \cdot 10^{-104}:\\
\;\;\;\;0 - m\\

\mathbf{elif}\;m \leq 1:\\
\;\;\;\;m \cdot \frac{m}{v}\\

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


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

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{m} \]
      3. --lowering--.f6471.8%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
    5. Simplified71.8%

      \[\leadsto \color{blue}{0 - m} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-lowering-neg.f6471.8%

        \[\leadsto \mathsf{neg.f64}\left(m\right) \]
    7. Applied egg-rr71.8%

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

    if 3.19999999999999989e-104 < m < 1

    1. Initial program 99.6%

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

      \[\leadsto \color{blue}{{m}^{3} \cdot \left(\frac{1}{m \cdot v} - \frac{1}{v}\right)} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

        \[\leadsto \left(\left(m \cdot m\right) \cdot m\right) \cdot \frac{1}{m \cdot v} + \left(\mathsf{neg}\left(\color{blue}{\frac{1}{v}}\right)\right) \cdot {m}^{3} \]
      5. unpow2N/A

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

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

        \[\leadsto {m}^{2} \cdot \left(m \cdot \frac{\frac{1}{m}}{v}\right) + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      8. associate-*r/N/A

        \[\leadsto {m}^{2} \cdot \frac{m \cdot \frac{1}{m}}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      9. rgt-mult-inverseN/A

        \[\leadsto {m}^{2} \cdot \frac{1}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{v}\right)\right)} \cdot {m}^{3} \]
      11. cube-multN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot \left(m \cdot \color{blue}{\left(m \cdot m\right)}\right) \]
      12. unpow2N/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot m\right) \cdot \color{blue}{{m}^{2}} \]
      14. distribute-lft-neg-inN/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1 \cdot m}{v}\right)\right) \cdot {m}^{2} \]
      16. *-lft-identityN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{m}{v}\right)\right) \cdot {m}^{2} \]
      17. mul-1-negN/A

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

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

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

      \[\leadsto \color{blue}{\frac{{m}^{2}}{v}} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({m}^{2}\right), \color{blue}{v}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(m \cdot m\right), v\right) \]
      3. *-lowering-*.f6478.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(m, m\right), v\right) \]
    8. Simplified78.2%

      \[\leadsto \color{blue}{\frac{m \cdot m}{v}} \]
    9. Step-by-step derivation
      1. associate-/l*N/A

        \[\leadsto m \cdot \color{blue}{\frac{m}{v}} \]
      2. clear-numN/A

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

        \[\leadsto \frac{m \cdot 1}{\color{blue}{\frac{v}{m}}} \]
      4. div-invN/A

        \[\leadsto \frac{m \cdot 1}{v \cdot \color{blue}{\frac{1}{m}}} \]
      5. times-fracN/A

        \[\leadsto \frac{m}{v} \cdot \color{blue}{\frac{1}{\frac{1}{m}}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{m}{v} \cdot \frac{1}{\frac{\mathsf{neg}\left(-1\right)}{m}} \]
      7. distribute-neg-fracN/A

        \[\leadsto \frac{m}{v} \cdot \frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{m}{v}\right), \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)}\right) \]
      9. remove-double-divN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{1}{\frac{m}{v}}}\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      10. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{1}{m} \cdot v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      11. associate-/r*N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\frac{1}{m}}}{v}\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\frac{\mathsf{neg}\left(-1\right)}{m}}}{v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      13. distribute-neg-fracN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}}{v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      14. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right), v\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\frac{1}{\frac{-1}{m}}\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      16. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\frac{1}{-1} \cdot m\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      17. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(-1 \cdot m\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      18. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m\right)\right)\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      19. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      20. distribute-frac-neg2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\frac{1}{\frac{-1}{m}}\right)\right)\right) \]
      21. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\frac{1}{-1} \cdot m\right)\right)\right) \]
      22. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(-1 \cdot m\right)\right)\right) \]
      23. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m\right)\right)\right)\right)\right) \]
      24. remove-double-neg78.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), m\right) \]
    10. Applied egg-rr78.5%

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

    if 1 < m

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{m} \]
      3. --lowering--.f645.6%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
    5. Simplified5.6%

      \[\leadsto \color{blue}{0 - m} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. *-rgt-identityN/A

        \[\leadsto \mathsf{neg}\left(m \cdot 1\right) \]
      3. *-rgt-identityN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      4. remove-double-divN/A

        \[\leadsto \mathsf{neg}\left(\frac{1}{\frac{1}{m}}\right) \]
      5. distribute-neg-frac2N/A

        \[\leadsto \frac{1}{\color{blue}{\mathsf{neg}\left(\frac{1}{m}\right)}} \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\mathsf{neg}\left(\frac{1}{m}\right)\right)}\right) \]
      7. distribute-neg-fracN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{-1}{m}\right)\right) \]
      9. /-lowering-/.f645.6%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(-1, \color{blue}{m}\right)\right) \]
    7. Applied egg-rr5.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{-1}{m}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification41.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 3.2 \cdot 10^{-104}:\\ \;\;\;\;0 - m\\ \mathbf{elif}\;m \leq 1:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{-1}{m}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 36.6% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq 2.75 \cdot 10^{-104}:\\
\;\;\;\;0 - m\\

\mathbf{elif}\;m \leq 1:\\
\;\;\;\;m \cdot \frac{m}{v}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < 2.7499999999999999e-104 or 1 < m

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{m} \]
      3. --lowering--.f6434.2%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
    5. Simplified34.2%

      \[\leadsto \color{blue}{0 - m} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-lowering-neg.f6434.2%

        \[\leadsto \mathsf{neg.f64}\left(m\right) \]
    7. Applied egg-rr34.2%

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

    if 2.7499999999999999e-104 < m < 1

    1. Initial program 99.6%

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

      \[\leadsto \color{blue}{{m}^{3} \cdot \left(\frac{1}{m \cdot v} - \frac{1}{v}\right)} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

        \[\leadsto \left(\left(m \cdot m\right) \cdot m\right) \cdot \frac{1}{m \cdot v} + \left(\mathsf{neg}\left(\color{blue}{\frac{1}{v}}\right)\right) \cdot {m}^{3} \]
      5. unpow2N/A

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

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

        \[\leadsto {m}^{2} \cdot \left(m \cdot \frac{\frac{1}{m}}{v}\right) + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      8. associate-*r/N/A

        \[\leadsto {m}^{2} \cdot \frac{m \cdot \frac{1}{m}}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      9. rgt-mult-inverseN/A

        \[\leadsto {m}^{2} \cdot \frac{1}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{v}\right)\right)} \cdot {m}^{3} \]
      11. cube-multN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot \left(m \cdot \color{blue}{\left(m \cdot m\right)}\right) \]
      12. unpow2N/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot m\right) \cdot \color{blue}{{m}^{2}} \]
      14. distribute-lft-neg-inN/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1 \cdot m}{v}\right)\right) \cdot {m}^{2} \]
      16. *-lft-identityN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{m}{v}\right)\right) \cdot {m}^{2} \]
      17. mul-1-negN/A

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

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

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

      \[\leadsto \color{blue}{\frac{{m}^{2}}{v}} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({m}^{2}\right), \color{blue}{v}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(m \cdot m\right), v\right) \]
      3. *-lowering-*.f6478.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(m, m\right), v\right) \]
    8. Simplified78.2%

      \[\leadsto \color{blue}{\frac{m \cdot m}{v}} \]
    9. Step-by-step derivation
      1. associate-/l*N/A

        \[\leadsto m \cdot \color{blue}{\frac{m}{v}} \]
      2. clear-numN/A

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

        \[\leadsto \frac{m \cdot 1}{\color{blue}{\frac{v}{m}}} \]
      4. div-invN/A

        \[\leadsto \frac{m \cdot 1}{v \cdot \color{blue}{\frac{1}{m}}} \]
      5. times-fracN/A

        \[\leadsto \frac{m}{v} \cdot \color{blue}{\frac{1}{\frac{1}{m}}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{m}{v} \cdot \frac{1}{\frac{\mathsf{neg}\left(-1\right)}{m}} \]
      7. distribute-neg-fracN/A

        \[\leadsto \frac{m}{v} \cdot \frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)} \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{m}{v}\right), \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)}\right) \]
      9. remove-double-divN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{1}{\frac{m}{v}}}\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      10. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{1}{m} \cdot v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      11. associate-/r*N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\frac{1}{m}}}{v}\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\frac{\mathsf{neg}\left(-1\right)}{m}}}{v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      13. distribute-neg-fracN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}}{v}\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      14. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right), v\right), \left(\frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\frac{1}{\frac{-1}{m}}\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      16. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\frac{1}{-1} \cdot m\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      17. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(-1 \cdot m\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      18. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m\right)\right)\right)\right), v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      19. remove-double-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\frac{1}{\mathsf{neg}\left(\frac{-1}{m}\right)}\right)\right) \]
      20. distribute-frac-neg2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\frac{1}{\frac{-1}{m}}\right)\right)\right) \]
      21. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\frac{1}{-1} \cdot m\right)\right)\right) \]
      22. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(-1 \cdot m\right)\right)\right) \]
      23. neg-mul-1N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m\right)\right)\right)\right)\right) \]
      24. remove-double-neg78.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), m\right) \]
    10. Applied egg-rr78.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq 2.75 \cdot 10^{-104}:\\ \;\;\;\;0 - m\\ \mathbf{elif}\;m \leq 1:\\ \;\;\;\;m \cdot \frac{m}{v}\\ \mathbf{else}:\\ \;\;\;\;0 - m\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.7% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 99.8%

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

        \[\leadsto m \cdot \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. distribute-rgt-out--N/A

        \[\leadsto \frac{m \cdot \left(1 - m\right)}{v} \cdot m - \color{blue}{1 \cdot m} \]
      3. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{\_.f64}\left(\left(m \cdot \frac{m \cdot \left(1 - m\right)}{v}\right), m\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \left(\frac{m \cdot \left(1 - m\right)}{v}\right)\right), m\right) \]
      7. associate-/l*N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \left(m \cdot \frac{1 - m}{v}\right)\right), m\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \left(\frac{1 - m}{v}\right)\right)\right), m\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\left(1 - m\right), v\right)\right)\right), m\right) \]
      10. --lowering--.f6499.7%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, m\right), v\right)\right)\right), m\right) \]
    4. Applied egg-rr99.7%

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

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \color{blue}{\left(\frac{m}{v}\right)}\right), m\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f6499.8%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{/.f64}\left(m, v\right)\right), m\right) \]
    7. Simplified99.8%

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

    if 1.4000000000000001e-20 < m

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{{m}^{3} \cdot \left(\frac{1}{m \cdot v} - \frac{1}{v}\right)} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

        \[\leadsto \left(\left(m \cdot m\right) \cdot m\right) \cdot \frac{1}{m \cdot v} + \left(\mathsf{neg}\left(\color{blue}{\frac{1}{v}}\right)\right) \cdot {m}^{3} \]
      5. unpow2N/A

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

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

        \[\leadsto {m}^{2} \cdot \left(m \cdot \frac{\frac{1}{m}}{v}\right) + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      8. associate-*r/N/A

        \[\leadsto {m}^{2} \cdot \frac{m \cdot \frac{1}{m}}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      9. rgt-mult-inverseN/A

        \[\leadsto {m}^{2} \cdot \frac{1}{v} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot {m}^{3} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{v}\right)\right)} \cdot {m}^{3} \]
      11. cube-multN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot \left(m \cdot \color{blue}{\left(m \cdot m\right)}\right) \]
      12. unpow2N/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\left(\mathsf{neg}\left(\frac{1}{v}\right)\right) \cdot m\right) \cdot \color{blue}{{m}^{2}} \]
      14. distribute-lft-neg-inN/A

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

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{1 \cdot m}{v}\right)\right) \cdot {m}^{2} \]
      16. *-lft-identityN/A

        \[\leadsto \frac{1}{v} \cdot {m}^{2} + \left(\mathsf{neg}\left(\frac{m}{v}\right)\right) \cdot {m}^{2} \]
      17. mul-1-negN/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(m, \left(\frac{1 - m}{v}\right)\right), m\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\left(1 - m\right), v\right)\right), m\right) \]
      7. --lowering--.f6499.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, m\right), v\right)\right), m\right) \]
    7. Applied egg-rr99.9%

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

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

Alternative 6: 99.8% accurate, 0.8× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(1\right), m, m \cdot \frac{m \cdot \left(1 - m\right)}{v}\right) \]
    7. associate-*r/N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(1\right), m, \frac{m \cdot \left(m \cdot \left(1 - m\right)\right)}{v}\right) \]
    8. associate-*l/N/A

      \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(1\right), m, \frac{m}{v} \cdot \left(m \cdot \left(1 - m\right)\right)\right) \]
    9. remove-double-negN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(1\right), m, \frac{m}{v} \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m \cdot \left(1 - m\right)\right)\right)\right)\right)\right) \]
    10. distribute-rgt-neg-outN/A

      \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(1\right), m, \mathsf{neg}\left(\frac{m}{v} \cdot \left(\mathsf{neg}\left(m \cdot \left(1 - m\right)\right)\right)\right)\right) \]
    11. fmm-undefN/A

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

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

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

      \[\leadsto \mathsf{\_.f64}\left(\left(\mathsf{neg}\left(m\right)\right), \color{blue}{\left(\frac{m}{v} \cdot \left(\mathsf{neg}\left(m \cdot \left(1 - m\right)\right)\right)\right)}\right) \]
    15. neg-sub0N/A

      \[\leadsto \mathsf{\_.f64}\left(\left(0 - m\right), \left(\color{blue}{\frac{m}{v}} \cdot \left(\mathsf{neg}\left(m \cdot \left(1 - m\right)\right)\right)\right)\right) \]
    16. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \left(\color{blue}{\frac{m}{v}} \cdot \left(\mathsf{neg}\left(m \cdot \left(1 - m\right)\right)\right)\right)\right) \]
    17. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\left(\frac{m}{v}\right), \color{blue}{\left(\mathsf{neg}\left(m \cdot \left(1 - m\right)\right)\right)}\right)\right) \]
    18. /-lowering-/.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\color{blue}{m \cdot \left(1 - m\right)}\right)\right)\right)\right) \]
    19. distribute-rgt-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(m \cdot \color{blue}{\left(\mathsf{neg}\left(\left(1 - m\right)\right)\right)}\right)\right)\right) \]
    20. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{*.f64}\left(m, \color{blue}{\left(\mathsf{neg}\left(\left(1 - m\right)\right)\right)}\right)\right)\right) \]
    21. sub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{*.f64}\left(m, \left(\mathsf{neg}\left(\left(1 + \left(\mathsf{neg}\left(m\right)\right)\right)\right)\right)\right)\right)\right) \]
    22. distribute-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{*.f64}\left(m, \left(\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(m\right)\right)\right)\right)}\right)\right)\right)\right) \]
    23. remove-double-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{*.f64}\left(m, \left(\left(\mathsf{neg}\left(1\right)\right) + m\right)\right)\right)\right) \]
    24. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{*.f64}\left(m, \left(m + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right)\right)\right)\right) \]
    25. +-lowering-+.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(0, m\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{*.f64}\left(m, \mathsf{+.f64}\left(m, \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right)\right)\right)\right) \]
  4. Applied egg-rr99.9%

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

    \[\leadsto \frac{m}{v} \cdot \left(m \cdot \left(0 - \left(m + -1\right)\right)\right) - m \]
  6. Add Preprocessing

Alternative 7: 74.8% accurate, 0.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0 - v \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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto m \cdot \color{blue}{\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right)} \]
      2. distribute-rgt-out--N/A

        \[\leadsto \frac{m \cdot \left(1 - m\right)}{v} \cdot m - \color{blue}{1 \cdot m} \]
      3. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{\_.f64}\left(\left(m \cdot \frac{m \cdot \left(1 - m\right)}{v}\right), m\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \left(\frac{m \cdot \left(1 - m\right)}{v}\right)\right), m\right) \]
      7. associate-/l*N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \left(m \cdot \frac{1 - m}{v}\right)\right), m\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \left(\frac{1 - m}{v}\right)\right)\right), m\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\left(1 - m\right), v\right)\right)\right), m\right) \]
      10. --lowering--.f6499.7%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{*.f64}\left(m, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(1, m\right), v\right)\right)\right), m\right) \]
    4. Applied egg-rr99.7%

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

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \color{blue}{\left(\frac{m}{v}\right)}\right), m\right) \]
    6. Step-by-step derivation
      1. /-lowering-/.f6498.8%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(m, \mathsf{/.f64}\left(m, v\right)\right), m\right) \]
    7. Simplified98.8%

      \[\leadsto m \cdot \color{blue}{\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. Add Preprocessing
    3. Taylor expanded in m around 0

      \[\leadsto \color{blue}{-1 \cdot m} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{m} \]
      3. --lowering--.f645.6%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
    5. Simplified5.6%

      \[\leadsto \color{blue}{0 - m} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-lowering-neg.f645.6%

        \[\leadsto \mathsf{neg.f64}\left(m\right) \]
    7. Applied egg-rr5.6%

      \[\leadsto \color{blue}{-m} \]
    8. Step-by-step derivation
      1. neg-mul-1N/A

        \[\leadsto -1 \cdot \color{blue}{m} \]
      2. metadata-evalN/A

        \[\leadsto \left(-1 \cdot 1\right) \cdot m \]
      3. metadata-evalN/A

        \[\leadsto \left(-1 \cdot {v}^{0}\right) \cdot m \]
      4. metadata-evalN/A

        \[\leadsto \left(-1 \cdot {v}^{\left(-1 + 1\right)}\right) \cdot m \]
      5. pow-plusN/A

        \[\leadsto \left(-1 \cdot \left({v}^{-1} \cdot v\right)\right) \cdot m \]
      6. inv-powN/A

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

        \[\leadsto \left(\left(-1 \cdot \frac{1}{v}\right) \cdot v\right) \cdot m \]
      8. div-invN/A

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

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

        \[\leadsto \frac{-1}{v} \cdot \left(m \cdot \color{blue}{v}\right) \]
      11. clear-numN/A

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

        \[\leadsto \frac{1 \cdot \left(m \cdot v\right)}{\color{blue}{\frac{v}{-1}}} \]
      13. div-invN/A

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

        \[\leadsto \frac{1 \cdot \left(m \cdot v\right)}{v \cdot -1} \]
      15. *-lft-identityN/A

        \[\leadsto \frac{m \cdot v}{\color{blue}{v} \cdot -1} \]
      16. times-fracN/A

        \[\leadsto \frac{m}{v} \cdot \color{blue}{\frac{v}{-1}} \]
      17. frac-2negN/A

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

        \[\leadsto \frac{m}{v} \cdot \frac{\mathsf{neg}\left(v\right)}{1} \]
      19. /-rgt-identityN/A

        \[\leadsto \frac{m}{v} \cdot \left(\mathsf{neg}\left(v\right)\right) \]
      20. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{m}{v}\right), \color{blue}{\left(\mathsf{neg}\left(v\right)\right)}\right) \]
      21. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\color{blue}{v}\right)\right)\right) \]
      22. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(0 - \color{blue}{v}\right)\right) \]
      23. --lowering--.f6453.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{\_.f64}\left(0, \color{blue}{v}\right)\right) \]
    9. Applied egg-rr53.5%

      \[\leadsto \color{blue}{\frac{m}{v} \cdot \left(0 - v\right)} \]
    10. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(v\right)\right)\right) \]
      2. neg-lowering-neg.f6453.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{neg.f64}\left(v\right)\right) \]
    11. Applied egg-rr53.5%

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

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

Alternative 8: 74.8% accurate, 0.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0 - v \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. Add Preprocessing
    3. Taylor expanded in m around 0

      \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\color{blue}{\left(\frac{m}{v}\right)}, 1\right), m\right) \]
    4. Step-by-step derivation
      1. /-lowering-/.f6498.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(m, v\right), 1\right), m\right) \]
    5. Simplified98.8%

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

    if 1 < m

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot m} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{m} \]
      3. --lowering--.f645.6%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
    5. Simplified5.6%

      \[\leadsto \color{blue}{0 - m} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(m\right) \]
      2. neg-lowering-neg.f645.6%

        \[\leadsto \mathsf{neg.f64}\left(m\right) \]
    7. Applied egg-rr5.6%

      \[\leadsto \color{blue}{-m} \]
    8. Step-by-step derivation
      1. neg-mul-1N/A

        \[\leadsto -1 \cdot \color{blue}{m} \]
      2. metadata-evalN/A

        \[\leadsto \left(-1 \cdot 1\right) \cdot m \]
      3. metadata-evalN/A

        \[\leadsto \left(-1 \cdot {v}^{0}\right) \cdot m \]
      4. metadata-evalN/A

        \[\leadsto \left(-1 \cdot {v}^{\left(-1 + 1\right)}\right) \cdot m \]
      5. pow-plusN/A

        \[\leadsto \left(-1 \cdot \left({v}^{-1} \cdot v\right)\right) \cdot m \]
      6. inv-powN/A

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

        \[\leadsto \left(\left(-1 \cdot \frac{1}{v}\right) \cdot v\right) \cdot m \]
      8. div-invN/A

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

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

        \[\leadsto \frac{-1}{v} \cdot \left(m \cdot \color{blue}{v}\right) \]
      11. clear-numN/A

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

        \[\leadsto \frac{1 \cdot \left(m \cdot v\right)}{\color{blue}{\frac{v}{-1}}} \]
      13. div-invN/A

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

        \[\leadsto \frac{1 \cdot \left(m \cdot v\right)}{v \cdot -1} \]
      15. *-lft-identityN/A

        \[\leadsto \frac{m \cdot v}{\color{blue}{v} \cdot -1} \]
      16. times-fracN/A

        \[\leadsto \frac{m}{v} \cdot \color{blue}{\frac{v}{-1}} \]
      17. frac-2negN/A

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

        \[\leadsto \frac{m}{v} \cdot \frac{\mathsf{neg}\left(v\right)}{1} \]
      19. /-rgt-identityN/A

        \[\leadsto \frac{m}{v} \cdot \left(\mathsf{neg}\left(v\right)\right) \]
      20. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{m}{v}\right), \color{blue}{\left(\mathsf{neg}\left(v\right)\right)}\right) \]
      21. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(\color{blue}{v}\right)\right)\right) \]
      22. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(0 - \color{blue}{v}\right)\right) \]
      23. --lowering--.f6453.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{\_.f64}\left(0, \color{blue}{v}\right)\right) \]
    9. Applied egg-rr53.5%

      \[\leadsto \color{blue}{\frac{m}{v} \cdot \left(0 - v\right)} \]
    10. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \left(\mathsf{neg}\left(v\right)\right)\right) \]
      2. neg-lowering-neg.f6453.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(m, v\right), \mathsf{neg.f64}\left(v\right)\right) \]
    11. Applied egg-rr53.5%

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

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

Alternative 9: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ m \cdot \left(-1 + \frac{m}{\frac{v}{1 - m}}\right) \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(m * Float64(-1.0 + Float64(m / Float64(v / Float64(1.0 - m)))))
end
function tmp = code(m, v)
	tmp = m * (-1.0 + (m / (v / (1.0 - m))));
end
code[m_, v_] := N[(m * N[(-1.0 + N[(m / N[(v / N[(1.0 - m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{m}{v} \cdot \left(1 - m\right)\right), 1\right), m\right) \]
    2. associate-/r/N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\left(\frac{m}{\frac{v}{1 - m}}\right), 1\right), m\right) \]
    3. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(m, \left(\frac{v}{1 - m}\right)\right), 1\right), m\right) \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \left(1 - m\right)\right)\right), 1\right), m\right) \]
    5. --lowering--.f6499.8%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(m, \mathsf{/.f64}\left(v, \mathsf{\_.f64}\left(1, m\right)\right)\right), 1\right), m\right) \]
  4. Applied egg-rr99.8%

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

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

Alternative 10: 27.1% accurate, 3.7× speedup?

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

\\
0 - m
\end{array}
Derivation
  1. Initial program 99.8%

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

    \[\leadsto \color{blue}{-1 \cdot m} \]
  4. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(m\right) \]
    2. neg-sub0N/A

      \[\leadsto 0 - \color{blue}{m} \]
    3. --lowering--.f6430.6%

      \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{m}\right) \]
  5. Simplified30.6%

    \[\leadsto \color{blue}{0 - m} \]
  6. Step-by-step derivation
    1. sub0-negN/A

      \[\leadsto \mathsf{neg}\left(m\right) \]
    2. neg-lowering-neg.f6430.6%

      \[\leadsto \mathsf{neg.f64}\left(m\right) \]
  7. Applied egg-rr30.6%

    \[\leadsto \color{blue}{-m} \]
  8. Final simplification30.6%

    \[\leadsto 0 - m \]
  9. Add Preprocessing

Reproduce

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