
(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 (* (- m 2.0) m) m m) v) v))
double code(double m, double v) {
return (fma(((m - 2.0) * m), m, m) - v) / v;
}
function code(m, v) return Float64(Float64(fma(Float64(Float64(m - 2.0) * m), m, m) - v) / v) end
code[m_, v_] := N[(N[(N[(N[(N[(m - 2.0), $MachinePrecision] * m), $MachinePrecision] * m + m), $MachinePrecision] - v), $MachinePrecision] / v), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\left(m - 2\right) \cdot m, m, m\right) - v}{v}
\end{array}
Initial program 99.9%
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
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%
Taylor expanded in m around 0
Applied rewrites100.0%
Taylor expanded in v around 0
Applied rewrites100.0%
(FPCore (m v) :precision binary64 (if (<= (* (- (/ (* m (- 1.0 m)) v) 1.0) (- 1.0 m)) 500000000000.0) (/ (* 1.0 (- m v)) v) (/ (fma (* (- m 2.0) m) m m) v)))
double code(double m, double v) {
double tmp;
if (((((m * (1.0 - m)) / v) - 1.0) * (1.0 - m)) <= 500000000000.0) {
tmp = (1.0 * (m - v)) / v;
} else {
tmp = fma(((m - 2.0) * m), m, m) / v;
}
return tmp;
}
function code(m, v) tmp = 0.0 if (Float64(Float64(Float64(Float64(m * Float64(1.0 - m)) / v) - 1.0) * Float64(1.0 - m)) <= 500000000000.0) tmp = Float64(Float64(1.0 * Float64(m - v)) / v); else tmp = Float64(fma(Float64(Float64(m - 2.0) * m), m, m) / v); end return tmp end
code[m_, v_] := If[LessEqual[N[(N[(N[(N[(m * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision], 500000000000.0], N[(N[(1.0 * N[(m - v), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision], N[(N[(N[(N[(m - 2.0), $MachinePrecision] * m), $MachinePrecision] * m + m), $MachinePrecision] / v), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \leq 500000000000:\\
\;\;\;\;\frac{1 \cdot \left(m - v\right)}{v}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(m - 2\right) \cdot m, m, m\right)}{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)) < 5e11Initial program 100.0%
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
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.f64100.0
Applied rewrites100.0%
Taylor expanded in m around 0
Applied rewrites100.0%
Taylor expanded in m around 0
Applied rewrites100.0%
if 5e11 < (*.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
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
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%
Taylor expanded in m around 0
Applied rewrites99.9%
Taylor expanded in v around 0
Applied rewrites99.9%
Applied rewrites99.9%
(FPCore (m v) :precision binary64 (if (<= (* (- (/ (* m (- 1.0 m)) v) 1.0) (- 1.0 m)) 500000000000.0) (/ (* 1.0 (- m v)) v) (/ (fma (* m m) (- m 2.0) m) v)))
double code(double m, double v) {
double tmp;
if (((((m * (1.0 - m)) / v) - 1.0) * (1.0 - m)) <= 500000000000.0) {
tmp = (1.0 * (m - v)) / v;
} else {
tmp = fma((m * m), (m - 2.0), m) / v;
}
return tmp;
}
function code(m, v) tmp = 0.0 if (Float64(Float64(Float64(Float64(m * Float64(1.0 - m)) / v) - 1.0) * Float64(1.0 - m)) <= 500000000000.0) tmp = Float64(Float64(1.0 * Float64(m - v)) / v); else tmp = Float64(fma(Float64(m * m), Float64(m - 2.0), m) / v); end return tmp end
code[m_, v_] := If[LessEqual[N[(N[(N[(N[(m * N[(1.0 - m), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision] - 1.0), $MachinePrecision] * N[(1.0 - m), $MachinePrecision]), $MachinePrecision], 500000000000.0], N[(N[(1.0 * N[(m - v), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision], N[(N[(N[(m * m), $MachinePrecision] * N[(m - 2.0), $MachinePrecision] + m), $MachinePrecision] / v), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\frac{m \cdot \left(1 - m\right)}{v} - 1\right) \cdot \left(1 - m\right) \leq 500000000000:\\
\;\;\;\;\frac{1 \cdot \left(m - v\right)}{v}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(m \cdot m, m - 2, m\right)}{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)) < 5e11Initial program 100.0%
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
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.f64100.0
Applied rewrites100.0%
Taylor expanded in m around 0
Applied rewrites100.0%
Taylor expanded in m around 0
Applied rewrites100.0%
if 5e11 < (*.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
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
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%
Taylor expanded in m around 0
Applied rewrites99.9%
Taylor expanded in v around 0
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
associate-*r*N/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
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%
Applied rewrites99.9%
(FPCore (m v) :precision binary64 (* (- m (fma m m v)) (/ (- 1.0 m) v)))
double code(double m, double v) {
return (m - fma(m, m, v)) * ((1.0 - m) / v);
}
function code(m, v) return Float64(Float64(m - fma(m, m, v)) * Float64(Float64(1.0 - m) / v)) end
code[m_, v_] := N[(N[(m - N[(m * m + v), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 - m), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(m - \mathsf{fma}\left(m, m, v\right)\right) \cdot \frac{1 - m}{v}
\end{array}
Initial program 99.9%
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
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%
Applied rewrites99.8%
(FPCore (m v) :precision binary64 (if (<= m 5.2e+147) (/ (- (fma v m m) v) v) (/ (fma m m -1.0) 1.0)))
double code(double m, double v) {
double tmp;
if (m <= 5.2e+147) {
tmp = (fma(v, m, m) - v) / v;
} else {
tmp = fma(m, m, -1.0) / 1.0;
}
return tmp;
}
function code(m, v) tmp = 0.0 if (m <= 5.2e+147) tmp = Float64(Float64(fma(v, m, m) - v) / v); else tmp = Float64(fma(m, m, -1.0) / 1.0); end return tmp end
code[m_, v_] := If[LessEqual[m, 5.2e+147], N[(N[(N[(v * m + m), $MachinePrecision] - v), $MachinePrecision] / v), $MachinePrecision], N[(N[(m * m + -1.0), $MachinePrecision] / 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 5.2 \cdot 10^{+147}:\\
\;\;\;\;\frac{\mathsf{fma}\left(v, m, m\right) - v}{v}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(m, m, -1\right)}{1}\\
\end{array}
\end{array}
if m < 5.1999999999999997e147Initial program 99.9%
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
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%
Taylor expanded in m around 0
Applied rewrites71.6%
if 5.1999999999999997e147 < 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.9
Applied rewrites6.9%
Applied rewrites94.2%
Taylor expanded in m around 0
Applied rewrites94.6%
(FPCore (m v) :precision binary64 (if (<= m 5.2e+147) (/ (* 1.0 (- m v)) v) (/ (fma m m -1.0) 1.0)))
double code(double m, double v) {
double tmp;
if (m <= 5.2e+147) {
tmp = (1.0 * (m - v)) / v;
} else {
tmp = fma(m, m, -1.0) / 1.0;
}
return tmp;
}
function code(m, v) tmp = 0.0 if (m <= 5.2e+147) tmp = Float64(Float64(1.0 * Float64(m - v)) / v); else tmp = Float64(fma(m, m, -1.0) / 1.0); end return tmp end
code[m_, v_] := If[LessEqual[m, 5.2e+147], N[(N[(1.0 * N[(m - v), $MachinePrecision]), $MachinePrecision] / v), $MachinePrecision], N[(N[(m * m + -1.0), $MachinePrecision] / 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq 5.2 \cdot 10^{+147}:\\
\;\;\;\;\frac{1 \cdot \left(m - v\right)}{v}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(m, m, -1\right)}{1}\\
\end{array}
\end{array}
if m < 5.1999999999999997e147Initial program 99.9%
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
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%
Taylor expanded in m around 0
Applied rewrites64.7%
Taylor expanded in m around 0
Applied rewrites71.6%
if 5.1999999999999997e147 < 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.9
Applied rewrites6.9%
Applied rewrites94.2%
Taylor expanded in m around 0
Applied rewrites94.6%
(FPCore (m v) :precision binary64 (if (<= m 5.2e+147) (- (+ (/ m v) m) 1.0) (/ (fma m m -1.0) 1.0)))
double code(double m, double v) {
double tmp;
if (m <= 5.2e+147) {
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 <= 5.2e+147) 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, 5.2e+147], 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 5.2 \cdot 10^{+147}:\\
\;\;\;\;\left(\frac{m}{v} + m\right) - 1\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(m, m, -1\right)}{1}\\
\end{array}
\end{array}
if m < 5.1999999999999997e147Initial 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-/.f6471.6
Applied rewrites71.6%
if 5.1999999999999997e147 < 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.9
Applied rewrites6.9%
Applied rewrites94.2%
Taylor expanded in m around 0
Applied rewrites94.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-/.f6471.3
Applied rewrites71.3%
(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--.f6426.7
Applied rewrites26.7%
(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 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
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%
Taylor expanded in m around 0
Applied rewrites24.3%
herbie shell --seed 2024318
(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)))