
(FPCore (x y z t a b) :precision binary64 (* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))
double code(double x, double y, double z, double t, double a, double b) {
return x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x * exp(((y * (log(z) - t)) + (a * (log((1.0d0 - z)) - b))))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x * Math.exp(((y * (Math.log(z) - t)) + (a * (Math.log((1.0 - z)) - b))));
}
def code(x, y, z, t, a, b): return x * math.exp(((y * (math.log(z) - t)) + (a * (math.log((1.0 - z)) - b))))
function code(x, y, z, t, a, b) return Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + Float64(a * Float64(log(Float64(1.0 - z)) - b))))) end
function tmp = code(x, y, z, t, a, b) tmp = x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b)))); end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))
double code(double x, double y, double z, double t, double a, double b) {
return x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x * exp(((y * (log(z) - t)) + (a * (log((1.0d0 - z)) - b))))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x * Math.exp(((y * (Math.log(z) - t)) + (a * (Math.log((1.0 - z)) - b))));
}
def code(x, y, z, t, a, b): return x * math.exp(((y * (math.log(z) - t)) + (a * (math.log((1.0 - z)) - b))))
function code(x, y, z, t, a, b) return Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + Float64(a * Float64(log(Float64(1.0 - z)) - b))))) end
function tmp = code(x, y, z, t, a, b) tmp = x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b)))); end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\end{array}
(FPCore (x y z t a b) :precision binary64 (* x (exp (fma (- a) (+ z b) (* (- (log z) t) y)))))
double code(double x, double y, double z, double t, double a, double b) {
return x * exp(fma(-a, (z + b), ((log(z) - t) * y)));
}
function code(x, y, z, t, a, b) return Float64(x * exp(fma(Float64(-a), Float64(z + b), Float64(Float64(log(z) - t) * y)))) end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[((-a) * N[(z + b), $MachinePrecision] + N[(N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{\mathsf{fma}\left(-a, z + b, \left(\log z - t\right) \cdot y\right)}
\end{array}
Initial program 94.7%
Taylor expanded in z around 0
associate-+r+N/A
+-commutativeN/A
associate-*r*N/A
associate-*r*N/A
distribute-lft-outN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6499.6
Applied rewrites99.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -600.0) (not (<= t 1.4e+187))) (* x (exp (* (- y) t))) (* x (exp (fma (- b) a (* (log z) y))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -600.0) || !(t <= 1.4e+187)) {
tmp = x * exp((-y * t));
} else {
tmp = x * exp(fma(-b, a, (log(z) * y)));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -600.0) || !(t <= 1.4e+187)) tmp = Float64(x * exp(Float64(Float64(-y) * t))); else tmp = Float64(x * exp(fma(Float64(-b), a, Float64(log(z) * y)))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -600.0], N[Not[LessEqual[t, 1.4e+187]], $MachinePrecision]], N[(x * N[Exp[N[((-y) * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[Exp[N[((-b) * a + N[(N[Log[z], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -600 \lor \neg \left(t \leq 1.4 \cdot 10^{+187}\right):\\
\;\;\;\;x \cdot e^{\left(-y\right) \cdot t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot e^{\mathsf{fma}\left(-b, a, \log z \cdot y\right)}\\
\end{array}
\end{array}
if t < -600 or 1.39999999999999995e187 < t Initial program 95.9%
Taylor expanded in t around inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6485.0
Applied rewrites85.0%
if -600 < t < 1.39999999999999995e187Initial program 93.9%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6493.9
Applied rewrites93.9%
Taylor expanded in t around 0
Applied rewrites92.7%
Final simplification89.8%
(FPCore (x y z t a b) :precision binary64 (* x (exp (fma (- b) a (* (- (log z) t) y)))))
double code(double x, double y, double z, double t, double a, double b) {
return x * exp(fma(-b, a, ((log(z) - t) * y)));
}
function code(x, y, z, t, a, b) return Float64(x * exp(fma(Float64(-b), a, Float64(Float64(log(z) - t) * y)))) end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[((-b) * a + N[(N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{\mathsf{fma}\left(-b, a, \left(\log z - t\right) \cdot y\right)}
\end{array}
Initial program 94.7%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6495.1
Applied rewrites95.1%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -600.0) (not (<= t 3e+28))) (* x (exp (* (- y) t))) (* x (exp (* (- b) a)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -600.0) || !(t <= 3e+28)) {
tmp = x * exp((-y * t));
} else {
tmp = x * exp((-b * a));
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((t <= (-600.0d0)) .or. (.not. (t <= 3d+28))) then
tmp = x * exp((-y * t))
else
tmp = x * exp((-b * a))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -600.0) || !(t <= 3e+28)) {
tmp = x * Math.exp((-y * t));
} else {
tmp = x * Math.exp((-b * a));
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t <= -600.0) or not (t <= 3e+28): tmp = x * math.exp((-y * t)) else: tmp = x * math.exp((-b * a)) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -600.0) || !(t <= 3e+28)) tmp = Float64(x * exp(Float64(Float64(-y) * t))); else tmp = Float64(x * exp(Float64(Float64(-b) * a))); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t <= -600.0) || ~((t <= 3e+28))) tmp = x * exp((-y * t)); else tmp = x * exp((-b * a)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -600.0], N[Not[LessEqual[t, 3e+28]], $MachinePrecision]], N[(x * N[Exp[N[((-y) * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[Exp[N[((-b) * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -600 \lor \neg \left(t \leq 3 \cdot 10^{+28}\right):\\
\;\;\;\;x \cdot e^{\left(-y\right) \cdot t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot e^{\left(-b\right) \cdot a}\\
\end{array}
\end{array}
if t < -600 or 3.0000000000000001e28 < t Initial program 96.1%
Taylor expanded in t around inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6483.8
Applied rewrites83.8%
if -600 < t < 3.0000000000000001e28Initial program 93.3%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6493.3
Applied rewrites93.3%
Taylor expanded in y around 0
Applied rewrites70.8%
Final simplification77.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= b -7.5e-25) (not (<= b 5e-150))) (* x (exp (* (- b) a))) (* x (exp (* (- z) a)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((b <= -7.5e-25) || !(b <= 5e-150)) {
tmp = x * exp((-b * a));
} else {
tmp = x * exp((-z * a));
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-7.5d-25)) .or. (.not. (b <= 5d-150))) then
tmp = x * exp((-b * a))
else
tmp = x * exp((-z * a))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((b <= -7.5e-25) || !(b <= 5e-150)) {
tmp = x * Math.exp((-b * a));
} else {
tmp = x * Math.exp((-z * a));
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (b <= -7.5e-25) or not (b <= 5e-150): tmp = x * math.exp((-b * a)) else: tmp = x * math.exp((-z * a)) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((b <= -7.5e-25) || !(b <= 5e-150)) tmp = Float64(x * exp(Float64(Float64(-b) * a))); else tmp = Float64(x * exp(Float64(Float64(-z) * a))); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((b <= -7.5e-25) || ~((b <= 5e-150))) tmp = x * exp((-b * a)); else tmp = x * exp((-z * a)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[b, -7.5e-25], N[Not[LessEqual[b, 5e-150]], $MachinePrecision]], N[(x * N[Exp[N[((-b) * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[Exp[N[((-z) * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-25} \lor \neg \left(b \leq 5 \cdot 10^{-150}\right):\\
\;\;\;\;x \cdot e^{\left(-b\right) \cdot a}\\
\mathbf{else}:\\
\;\;\;\;x \cdot e^{\left(-z\right) \cdot a}\\
\end{array}
\end{array}
if b < -7.49999999999999989e-25 or 4.9999999999999999e-150 < b Initial program 98.9%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6499.5
Applied rewrites99.5%
Taylor expanded in y around 0
Applied rewrites71.5%
if -7.49999999999999989e-25 < b < 4.9999999999999999e-150Initial program 84.4%
Taylor expanded in z around 0
associate-+r+N/A
+-commutativeN/A
associate-*r*N/A
associate-*r*N/A
distribute-lft-outN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
Applied rewrites53.4%
Final simplification66.2%
(FPCore (x y z t a b) :precision binary64 (* x (exp (* (- z) a))))
double code(double x, double y, double z, double t, double a, double b) {
return x * exp((-z * a));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x * exp((-z * a))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x * Math.exp((-z * a));
}
def code(x, y, z, t, a, b): return x * math.exp((-z * a))
function code(x, y, z, t, a, b) return Float64(x * exp(Float64(Float64(-z) * a))) end
function tmp = code(x, y, z, t, a, b) tmp = x * exp((-z * a)); end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[((-z) * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{\left(-z\right) \cdot a}
\end{array}
Initial program 94.7%
Taylor expanded in z around 0
associate-+r+N/A
+-commutativeN/A
associate-*r*N/A
associate-*r*N/A
distribute-lft-outN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6499.6
Applied rewrites99.6%
Taylor expanded in z around inf
Applied rewrites34.6%
herbie shell --seed 2024329
(FPCore (x y z t a b)
:name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, B"
:precision binary64
(* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))