
(FPCore (m v) :precision binary64 (* (- (/ (* m (- 1.0 m)) v) 1.0) (- 1.0 m)))
double code(double m, double v) {
return (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m);
}
real(8) function code(m, v)
real(8), intent (in) :: m
real(8), intent (in) :: v
code = (((m * (1.0d0 - m)) / v) - 1.0d0) * (1.0d0 - m)
end function
public static double code(double m, double v) {
return (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m);
}
def code(m, v): return (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m)
function code(m, v) return Float64(Float64(Float64(Float64(m * Float64(1.0 - m)) / v) - 1.0) * Float64(1.0 - m)) end
function tmp = code(m, v) tmp = (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m); end
code[m_, v_] := N[(N[(N[(N[(m * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (m v) :precision binary64 (* (- (/ (* m (- 1.0 m)) v) 1.0) (- 1.0 m)))
double code(double m, double v) {
return (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m);
}
real(8) function code(m, v)
real(8), intent (in) :: m
real(8), intent (in) :: v
code = (((m * (1.0d0 - m)) / v) - 1.0d0) * (1.0d0 - m)
end function
public static double code(double m, double v) {
return (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m);
}
def code(m, v): return (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m)
function code(m, v) return Float64(Float64(Float64(Float64(m * Float64(1.0 - m)) / v) - 1.0) * Float64(1.0 - m)) end
function tmp = code(m, v) tmp = (((m * (1.0 - m)) / v) - 1.0) * (1.0 - m); end
code[m_, v_] := N[(N[(N[(N[(m * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right)
\end{array}
(FPCore (m v) :precision binary64 (/ (* (fma (- 1.0 m) m (- v)) (- 1.0 m)) v))
double code(double m, double v) {
return (fma((1.0 - m), m, -v) * (1.0 - m)) / v;
}
function code(m, v) return Float64(Float64(fma(Float64(1.0 - m), m, Float64(-v)) * Float64(1.0 - m)) / v) end
code[m_, v_] := N[(N[(N[(N[(1.0 - m), $MachinePrecision] * m + (-v)), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(1 - m, m, -v\right) \cdot \left(1 - m\right)}{v}
\end{array}
Initial program 99.9%
Taylor expanded in m around 0
Applied rewrites23.4%
Taylor expanded in v around 0
lower-/.f64N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (m v) :precision binary64 (if (<= (* (- (/ (* (- 1.0 m) m) v) 1.0) (- 1.0 m)) -0.5) -1.0 (* 1.0 (/ m v))))
double code(double m, double v) {
double tmp;
if ((((((1.0 - m) * m) / v) - 1.0) * (1.0 - m)) <= -0.5) {
tmp = -1.0;
} else {
tmp = 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 ((((((1.0d0 - m) * m) / v) - 1.0d0) * (1.0d0 - m)) <= (-0.5d0)) then
tmp = -1.0d0
else
tmp = 1.0d0 * (m / v)
end if
code = tmp
end function
public static double code(double m, double v) {
double tmp;
if ((((((1.0 - m) * m) / v) - 1.0) * (1.0 - m)) <= -0.5) {
tmp = -1.0;
} else {
tmp = 1.0 * (m / v);
}
return tmp;
}
def code(m, v): tmp = 0 if (((((1.0 - m) * m) / v) - 1.0) * (1.0 - m)) <= -0.5: tmp = -1.0 else: tmp = 1.0 * (m / v) return tmp
function code(m, v) tmp = 0.0 if (Float64(Float64(Float64(Float64(Float64(1.0 - m) * m) / v) - 1.0) * Float64(1.0 - m)) <= -0.5) tmp = -1.0; else tmp = Float64(1.0 * Float64(m / v)); end return tmp end
function tmp_2 = code(m, v) tmp = 0.0; if ((((((1.0 - m) * m) / v) - 1.0) * (1.0 - m)) <= -0.5) tmp = -1.0; else tmp = 1.0 * (m / v); end tmp_2 = tmp; end
code[m_, v_] := If[LessEqual[N[(N[(N[(N[(N[(1.0 - m), $MachinePrecision] * m), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision], -0.5], -1.0, N[(1.0 * N[(m / v), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\frac{\left(1 - m\right) \cdot m}{v} - 1\right) \cdot \left(1 - m\right) \leq -0.5:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \frac{m}{v}\\
\end{array}
\end{array}
if (*.f64 (-.f64 (/.f64 (*.f64 m (-.f64 #s(literal 1 binary64) m)) v) #s(literal 1 binary64)) (-.f64 #s(literal 1 binary64) m)) < -0.5Initial program 100.0%
Taylor expanded in m around 0
Applied rewrites97.0%
if -0.5 < (*.f64 (-.f64 (/.f64 (*.f64 m (-.f64 #s(literal 1 binary64) m)) v) #s(literal 1 binary64)) (-.f64 #s(literal 1 binary64) m)) Initial program 99.9%
Taylor expanded in v around 0
associate-/l*N/A
div-subN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
div-subN/A
lower-/.f64N/A
lower--.f6497.3
Applied rewrites97.3%
Taylor expanded in m around 0
Applied rewrites28.5%
Taylor expanded in m around 0
Applied rewrites63.3%
Final simplification71.2%
(FPCore (m v) :precision binary64 (if (<= m 1.9e-8) (fma (fma -2.0 m 1.0) (/ m v) (- m 1.0)) (* (* (/ m v) (- 1.0 m)) (- 1.0 m))))
double code(double m, double v) {
double tmp;
if (m <= 1.9e-8) {
tmp = fma(fma(-2.0, m, 1.0), (m / v), (m - 1.0));
} else {
tmp = ((m / v) * (1.0 - m)) * (1.0 - m);
}
return tmp;
}
function code(m, v) tmp = 0.0 if (m <= 1.9e-8) tmp = fma(fma(-2.0, m, 1.0), Float64(m / v), Float64(m - 1.0)); else tmp = Float64(Float64(Float64(m / v) * Float64(1.0 - m)) * Float64(1.0 - m)); end return tmp end
code[m_, v_] := If[LessEqual[m, 1.9e-8], N[(N[(-2.0 * m + 1.0), $MachinePrecision] * N[(m / v), $MachinePrecision] + N[(m - 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(m / v), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.9 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-2, m, 1\right), \frac{m}{v}, m - 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{m}{v} \cdot \left(1 - m\right)\right) \cdot \left(1 - m\right)\\
\end{array}
\end{array}
if m < 1.90000000000000014e-8Initial program 100.0%
Taylor expanded in m around 0
distribute-rgt-inN/A
*-lft-identityN/A
associate--l+N/A
+-commutativeN/A
associate-+l-N/A
unsub-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-*r/N/A
*-rgt-identityN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
Applied rewrites100.0%
if 1.90000000000000014e-8 < m Initial program 99.8%
Taylor expanded in v around 0
associate-/l*N/A
div-subN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
div-subN/A
lower-/.f64N/A
lower--.f6499.8
Applied rewrites99.8%
Applied rewrites99.9%
(FPCore (m v) :precision binary64 (if (<= m 1.5e-15) (fma (fma -2.0 m 1.0) (/ m v) (- m 1.0)) (/ (fma (- m 2.0) (* m m) m) v)))
double code(double m, double v) {
double tmp;
if (m <= 1.5e-15) {
tmp = fma(fma(-2.0, m, 1.0), (m / v), (m - 1.0));
} else {
tmp = fma((m - 2.0), (m * m), m) / v;
}
return tmp;
}
function code(m, v) tmp = 0.0 if (m <= 1.5e-15) tmp = fma(fma(-2.0, m, 1.0), Float64(m / v), Float64(m - 1.0)); else tmp = Float64(fma(Float64(m - 2.0), Float64(m * m), m) / v); end return tmp end
code[m_, v_] := If[LessEqual[m, 1.5e-15], N[(N[(-2.0 * m + 1.0), $MachinePrecision] * N[(m / v), $MachinePrecision] + N[(m - 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(m - 2.0), $MachinePrecision] * N[(m * m), $MachinePrecision] + m), $MachinePrecision] / v), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 1.5 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-2, m, 1\right), \frac{m}{v}, m - 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(m - 2, m \cdot m, m\right)}{v}\\
\end{array}
\end{array}
if m < 1.5e-15Initial program 100.0%
Taylor expanded in m around 0
distribute-rgt-inN/A
*-lft-identityN/A
associate--l+N/A
+-commutativeN/A
associate-+l-N/A
unsub-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
associate-*r/N/A
*-rgt-identityN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
Applied rewrites100.0%
if 1.5e-15 < m Initial program 99.8%
Taylor expanded in m around 0
Applied rewrites0.7%
Taylor expanded in v around 0
lower-/.f64N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in m around 0
Applied rewrites99.9%
Taylor expanded in v around 0
Applied rewrites99.8%
(FPCore (m v) :precision binary64 (if (<= m 6e-41) (- (+ (/ m v) m) 1.0) (/ (fma (- m 2.0) (* m m) m) v)))
double code(double m, double v) {
double tmp;
if (m <= 6e-41) {
tmp = ((m / v) + m) - 1.0;
} else {
tmp = fma((m - 2.0), (m * m), m) / v;
}
return tmp;
}
function code(m, v) tmp = 0.0 if (m <= 6e-41) tmp = Float64(Float64(Float64(m / v) + m) - 1.0); else tmp = Float64(fma(Float64(m - 2.0), Float64(m * m), m) / v); end return tmp end
code[m_, v_] := If[LessEqual[m, 6e-41], N[(N[(N[(m / v), $MachinePrecision] + m), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(m - 2.0), $MachinePrecision] * N[(m * m), $MachinePrecision] + m), $MachinePrecision] / v), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 6 \cdot 10^{-41}:\\
\;\;\;\;\left(\frac{m}{v} + m\right) - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(m - 2, m \cdot m, m\right)}{v}\\
\end{array}
\end{array}
if m < 5.99999999999999978e-41Initial program 100.0%
Taylor expanded in m around 0
lower--.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l/N/A
*-lft-identityN/A
*-lft-identityN/A
lower-+.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
if 5.99999999999999978e-41 < m Initial program 99.9%
Taylor expanded in m around 0
Applied rewrites0.7%
Taylor expanded in v around 0
lower-/.f64N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in m around 0
Applied rewrites99.9%
Taylor expanded in v around 0
Applied rewrites99.8%
(FPCore (m v) :precision binary64 (* (fma (/ m v) (- 1.0 m) -1.0) (- 1.0 m)))
double code(double m, double v) {
return fma((m / v), (1.0 - m), -1.0) * (1.0 - m);
}
function code(m, v) return Float64(fma(Float64(m / v), Float64(1.0 - m), -1.0) * Float64(1.0 - m)) end
code[m_, v_] := N[(N[(N[(m / v), $MachinePrecision] * N[(1.0 - m), $MachinePrecision] + -1.0), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{m}{v}, 1 - m, -1\right) \cdot \left(1 - m\right)
\end{array}
Initial program 99.9%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
metadata-eval99.9
Applied rewrites99.9%
(FPCore (m v) :precision binary64 (* (/ (- m (fma m m v)) v) (- 1.0 m)))
double code(double m, double v) {
return ((m - fma(m, m, v)) / v) * (1.0 - m);
}
function code(m, v) return Float64(Float64(Float64(m - fma(m, m, v)) / v) * Float64(1.0 - m)) end
code[m_, v_] := N[(N[(N[(m - N[(m * m + v), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{m - \mathsf{fma}\left(m, m, v\right)}{v} \cdot \left(1 - m\right)
\end{array}
Initial program 99.9%
Taylor expanded in v around 0
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
unpow2N/A
associate--l-N/A
lower--.f64N/A
unpow2N/A
lower-fma.f6499.9
Applied rewrites99.9%
(FPCore (m v) :precision binary64 (if (<= m 6.5e+153) (- (+ (/ m v) m) 1.0) (/ (fma m m -1.0) 1.0)))
double code(double m, double v) {
double tmp;
if (m <= 6.5e+153) {
tmp = ((m / v) + m) - 1.0;
} else {
tmp = fma(m, m, -1.0) / 1.0;
}
return tmp;
}
function code(m, v) tmp = 0.0 if (m <= 6.5e+153) tmp = Float64(Float64(Float64(m / v) + m) - 1.0); else tmp = Float64(fma(m, m, -1.0) / 1.0); end return tmp end
code[m_, v_] := If[LessEqual[m, 6.5e+153], N[(N[(N[(m / v), $MachinePrecision] + m), $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(m * m + -1.0), $MachinePrecision] / 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 6.5 \cdot 10^{+153}:\\
\;\;\;\;\left(\frac{m}{v} + m\right) - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(m, m, -1\right)}{1}\\
\end{array}
\end{array}
if m < 6.49999999999999972e153Initial program 99.9%
Taylor expanded in m around 0
lower--.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l/N/A
*-lft-identityN/A
*-lft-identityN/A
lower-+.f64N/A
lower-/.f6473.1
Applied rewrites73.1%
if 6.49999999999999972e153 < m Initial program 100.0%
Taylor expanded in v around inf
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f646.8
Applied rewrites6.8%
Applied rewrites97.2%
Taylor expanded in m around 0
Applied rewrites97.6%
(FPCore (m v) :precision binary64 (- (+ (/ m v) m) 1.0))
double code(double m, double v) {
return ((m / v) + m) - 1.0;
}
real(8) function code(m, v)
real(8), intent (in) :: m
real(8), intent (in) :: v
code = ((m / v) + m) - 1.0d0
end function
public static double code(double m, double v) {
return ((m / v) + m) - 1.0;
}
def code(m, v): return ((m / v) + m) - 1.0
function code(m, v) return Float64(Float64(Float64(m / v) + m) - 1.0) end
function tmp = code(m, v) tmp = ((m / v) + m) - 1.0; end
code[m_, v_] := N[(N[(N[(m / v), $MachinePrecision] + m), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{m}{v} + m\right) - 1
\end{array}
Initial program 99.9%
Taylor expanded in m around 0
lower--.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l/N/A
*-lft-identityN/A
*-lft-identityN/A
lower-+.f64N/A
lower-/.f6473.8
Applied rewrites73.8%
(FPCore (m v) :precision binary64 (- m 1.0))
double code(double m, double v) {
return m - 1.0;
}
real(8) function code(m, v)
real(8), intent (in) :: m
real(8), intent (in) :: v
code = m - 1.0d0
end function
public static double code(double m, double v) {
return m - 1.0;
}
def code(m, v): return m - 1.0
function code(m, v) return Float64(m - 1.0) end
function tmp = code(m, v) tmp = m - 1.0; end
code[m_, v_] := N[(m - 1.0), $MachinePrecision]
\begin{array}{l}
\\
m - 1
\end{array}
Initial program 99.9%
Taylor expanded in v around inf
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6425.9
Applied rewrites25.9%
(FPCore (m v) :precision binary64 -1.0)
double code(double m, double v) {
return -1.0;
}
real(8) function code(m, v)
real(8), intent (in) :: m
real(8), intent (in) :: v
code = -1.0d0
end function
public static double code(double m, double v) {
return -1.0;
}
def code(m, v): return -1.0
function code(m, v) return -1.0 end
function tmp = code(m, v) tmp = -1.0; end
code[m_, v_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 99.9%
Taylor expanded in m around 0
Applied rewrites23.4%
herbie shell --seed 2024270
(FPCore (m v)
:name "b parameter of renormalized beta distribution"
:precision binary64
:pre (and (and (< 0.0 m) (< 0.0 v)) (< v 0.25))
(* (- (/ (* m (- 1.0 m)) v) 1.0) (- 1.0 m)))