
(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:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 99.8%
*-commutative99.8%
sub-neg99.8%
associate-*l/99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (m v) :precision binary64 (if (<= m 1.6e-167) (- m) (if (<= m 1.0) (* m (/ m v)) (* m (- -1.0 (/ m v))))))
double code(double m, double v) {
double tmp;
if (m <= 1.6e-167) {
tmp = -m;
} else if (m <= 1.0) {
tmp = m * (m / v);
} else {
tmp = 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.6d-167) then
tmp = -m
else if (m <= 1.0d0) then
tmp = m * (m / v)
else
tmp = m * ((-1.0d0) - (m / v))
end if
code = tmp
end function
public static double code(double m, double v) {
double tmp;
if (m <= 1.6e-167) {
tmp = -m;
} else if (m <= 1.0) {
tmp = m * (m / v);
} else {
tmp = m * (-1.0 - (m / v));
}
return tmp;
}
def code(m, v): tmp = 0 if m <= 1.6e-167: tmp = -m elif m <= 1.0: tmp = m * (m / v) else: tmp = m * (-1.0 - (m / v)) return tmp
function code(m, v) tmp = 0.0 if (m <= 1.6e-167) tmp = Float64(-m); elseif (m <= 1.0) tmp = Float64(m * Float64(m / v)); else tmp = Float64(m * Float64(-1.0 - Float64(m / v))); end return tmp end
function tmp_2 = code(m, v) tmp = 0.0; if (m <= 1.6e-167) tmp = -m; elseif (m <= 1.0) tmp = m * (m / v); else tmp = m * (-1.0 - (m / v)); end tmp_2 = tmp; end
code[m_, v_] := If[LessEqual[m, 1.6e-167], (-m), If[LessEqual[m, 1.0], N[(m * N[(m / v), $MachinePrecision]), $MachinePrecision], N[(m * N[(-1.0 - N[(m / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.6 \cdot 10^{-167}:\\
\;\;\;\;-m\\
\mathbf{elif}\;m \leq 1:\\
\;\;\;\;m \cdot \frac{m}{v}\\
\mathbf{else}:\\
\;\;\;\;m \cdot \left(-1 - \frac{m}{v}\right)\\
\end{array}
\end{array}
if m < 1.6000000000000001e-167Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in m around 0 84.4%
neg-mul-184.4%
Simplified84.4%
if 1.6000000000000001e-167 < m < 1Initial program 99.6%
*-commutative99.6%
sub-neg99.6%
associate-*l/99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in m around 0 87.5%
neg-mul-187.5%
+-commutative87.5%
unsub-neg87.5%
Simplified87.5%
Taylor expanded in m around inf 66.2%
unpow266.2%
associate-/l*70.9%
associate-/r/71.0%
Applied egg-rr71.0%
if 1 < m Initial program 99.9%
sub-neg99.9%
div-inv99.9%
associate-*l*99.9%
div-inv99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in m around 0 0.1%
fma-def0.1%
frac-2neg0.1%
metadata-eval0.1%
add-sqr-sqrt0.0%
sqrt-unprod88.3%
sqr-neg88.3%
sqrt-unprod86.0%
add-sqr-sqrt86.0%
Applied egg-rr86.0%
fma-udef86.0%
associate-*r/86.0%
*-commutative86.0%
mul-1-neg86.0%
distribute-neg-frac86.0%
+-commutative86.0%
sub-neg86.0%
Simplified86.0%
Final simplification81.3%
(FPCore (m v) :precision binary64 (if (or (<= m 1.55e-167) (not (<= m 1.0))) (- m) (* m (/ m v))))
double code(double m, double v) {
double tmp;
if ((m <= 1.55e-167) || !(m <= 1.0)) {
tmp = -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.55d-167) .or. (.not. (m <= 1.0d0))) then
tmp = -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.55e-167) || !(m <= 1.0)) {
tmp = -m;
} else {
tmp = m * (m / v);
}
return tmp;
}
def code(m, v): tmp = 0 if (m <= 1.55e-167) or not (m <= 1.0): tmp = -m else: tmp = m * (m / v) return tmp
function code(m, v) tmp = 0.0 if ((m <= 1.55e-167) || !(m <= 1.0)) tmp = Float64(-m); else tmp = Float64(m * Float64(m / v)); end return tmp end
function tmp_2 = code(m, v) tmp = 0.0; if ((m <= 1.55e-167) || ~((m <= 1.0))) tmp = -m; else tmp = m * (m / v); end tmp_2 = tmp; end
code[m_, v_] := If[Or[LessEqual[m, 1.55e-167], N[Not[LessEqual[m, 1.0]], $MachinePrecision]], (-m), N[(m * N[(m / v), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.55 \cdot 10^{-167} \lor \neg \left(m \leq 1\right):\\
\;\;\;\;-m\\
\mathbf{else}:\\
\;\;\;\;m \cdot \frac{m}{v}\\
\end{array}
\end{array}
if m < 1.55e-167 or 1 < m Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
associate-*l/99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in m around 0 33.7%
neg-mul-133.7%
Simplified33.7%
if 1.55e-167 < m < 1Initial program 99.6%
*-commutative99.6%
sub-neg99.6%
associate-*l/99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in m around 0 87.5%
neg-mul-187.5%
+-commutative87.5%
unsub-neg87.5%
Simplified87.5%
Taylor expanded in m around inf 66.2%
unpow266.2%
associate-/l*70.9%
associate-/r/71.0%
Applied egg-rr71.0%
Final simplification44.5%
(FPCore (m v) :precision binary64 (if (<= m 1.0) (* m (+ (/ m v) -1.0)) (* m (+ -1.0 (/ m (/ (- v) m))))))
double code(double m, double v) {
double tmp;
if (m <= 1.0) {
tmp = m * ((m / v) + -1.0);
} else {
tmp = m * (-1.0 + (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) + (-1.0d0))
else
tmp = m * ((-1.0d0) + (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) + -1.0);
} else {
tmp = m * (-1.0 + (m / (-v / m)));
}
return tmp;
}
def code(m, v): tmp = 0 if m <= 1.0: tmp = m * ((m / v) + -1.0) else: tmp = m * (-1.0 + (m / (-v / m))) 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(-1.0 + Float64(m / Float64(Float64(-v) / m)))); 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 * (-1.0 + (m / (-v / m))); 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[(-1.0 + N[(m / N[((-v) / m), $MachinePrecision]), $MachinePrecision]), $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 \left(-1 + \frac{m}{\frac{-v}{m}}\right)\\
\end{array}
\end{array}
if m < 1Initial program 99.8%
Taylor expanded in m around 0 95.9%
if 1 < m Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
associate-/l*99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in m around inf 97.9%
associate-*r/97.9%
neg-mul-197.9%
Simplified97.9%
Final simplification96.8%
(FPCore (m v) :precision binary64 (if (<= m 1.0) (* m (+ (/ m v) -1.0)) (* m (- -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 * (-1.0 - (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 * ((-1.0d0) - (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 * (-1.0 - (m * (m / v)));
}
return tmp;
}
def code(m, v): tmp = 0 if m <= 1.0: tmp = m * ((m / v) + -1.0) else: tmp = m * (-1.0 - (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(-1.0 - Float64(m * 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 = m * (-1.0 - (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[(-1.0 - N[(m * N[(m / v), $MachinePrecision]), $MachinePrecision]), $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 \left(-1 - m \cdot \frac{m}{v}\right)\\
\end{array}
\end{array}
if m < 1Initial program 99.8%
Taylor expanded in m around 0 95.9%
if 1 < m Initial program 99.9%
sub-neg99.9%
div-inv99.9%
associate-*l*99.9%
div-inv99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in m around inf 97.9%
neg-mul-197.9%
distribute-frac-neg97.9%
Simplified97.9%
Final simplification96.9%
(FPCore (m v) :precision binary64 (if (<= m 1.0) (* m (+ (/ m v) -1.0)) (* m (- -1.0 (/ m v)))))
double code(double m, double v) {
double tmp;
if (m <= 1.0) {
tmp = m * ((m / v) + -1.0);
} else {
tmp = 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.0d0) then
tmp = m * ((m / v) + (-1.0d0))
else
tmp = m * ((-1.0d0) - (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 * (-1.0 - (m / v));
}
return tmp;
}
def code(m, v): tmp = 0 if m <= 1.0: tmp = m * ((m / v) + -1.0) else: tmp = m * (-1.0 - (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(-1.0 - 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 = m * (-1.0 - (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[(-1.0 - 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}:\\
\;\;\;\;m \cdot \left(-1 - \frac{m}{v}\right)\\
\end{array}
\end{array}
if m < 1Initial program 99.8%
Taylor expanded in m around 0 95.9%
if 1 < m Initial program 99.9%
sub-neg99.9%
div-inv99.9%
associate-*l*99.9%
div-inv99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in m around 0 0.1%
fma-def0.1%
frac-2neg0.1%
metadata-eval0.1%
add-sqr-sqrt0.0%
sqrt-unprod88.3%
sqr-neg88.3%
sqrt-unprod86.0%
add-sqr-sqrt86.0%
Applied egg-rr86.0%
fma-udef86.0%
associate-*r/86.0%
*-commutative86.0%
mul-1-neg86.0%
distribute-neg-frac86.0%
+-commutative86.0%
sub-neg86.0%
Simplified86.0%
Final simplification91.4%
(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}
Initial program 99.8%
*-commutative99.8%
sub-neg99.8%
associate-*l/99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in m around 0 29.3%
neg-mul-129.3%
Simplified29.3%
Final simplification29.3%
herbie shell --seed 2024013
(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))