
(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 7 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 96.5%
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%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -420.0) (not (<= t 4.2e+120))) (* x (exp (* (- y) t))) (* x (exp (fma (- b) a (* y (log z)))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -420.0) || !(t <= 4.2e+120)) {
tmp = x * exp((-y * t));
} else {
tmp = x * exp(fma(-b, a, (y * log(z))));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -420.0) || !(t <= 4.2e+120)) tmp = Float64(x * exp(Float64(Float64(-y) * t))); else tmp = Float64(x * exp(fma(Float64(-b), a, Float64(y * log(z))))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -420.0], N[Not[LessEqual[t, 4.2e+120]], $MachinePrecision]], N[(x * N[Exp[N[((-y) * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[Exp[N[((-b) * a + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -420 \lor \neg \left(t \leq 4.2 \cdot 10^{+120}\right):\\
\;\;\;\;x \cdot e^{\left(-y\right) \cdot t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot e^{\mathsf{fma}\left(-b, a, y \cdot \log z\right)}\\
\end{array}
\end{array}
if t < -420 or 4.2000000000000001e120 < t Initial program 98.9%
Taylor expanded in t around inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6481.3
Applied rewrites81.3%
if -420 < t < 4.2000000000000001e120Initial program 95.0%
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.f6494.4
Applied rewrites94.4%
Taylor expanded in t around 0
Applied rewrites93.7%
Final simplification88.9%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -9.2e+98) (not (<= t 3.6e+14))) (* x (exp (* (- y) t))) (* x (exp (* (- (log (- 1.0 z)) b) a)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -9.2e+98) || !(t <= 3.6e+14)) {
tmp = x * exp((-y * t));
} else {
tmp = x * exp(((log((1.0 - z)) - 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 <= (-9.2d+98)) .or. (.not. (t <= 3.6d+14))) then
tmp = x * exp((-y * t))
else
tmp = x * exp(((log((1.0d0 - z)) - 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 <= -9.2e+98) || !(t <= 3.6e+14)) {
tmp = x * Math.exp((-y * t));
} else {
tmp = x * Math.exp(((Math.log((1.0 - z)) - b) * a));
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t <= -9.2e+98) or not (t <= 3.6e+14): tmp = x * math.exp((-y * t)) else: tmp = x * math.exp(((math.log((1.0 - z)) - b) * a)) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -9.2e+98) || !(t <= 3.6e+14)) tmp = Float64(x * exp(Float64(Float64(-y) * t))); else tmp = Float64(x * exp(Float64(Float64(log(Float64(1.0 - z)) - b) * a))); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t <= -9.2e+98) || ~((t <= 3.6e+14))) tmp = x * exp((-y * t)); else tmp = x * exp(((log((1.0 - z)) - b) * a)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -9.2e+98], N[Not[LessEqual[t, 3.6e+14]], $MachinePrecision]], N[(x * N[Exp[N[((-y) * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[Exp[N[(N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -9.2 \cdot 10^{+98} \lor \neg \left(t \leq 3.6 \cdot 10^{+14}\right):\\
\;\;\;\;x \cdot e^{\left(-y\right) \cdot t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot e^{\left(\log \left(1 - z\right) - b\right) \cdot a}\\
\end{array}
\end{array}
if t < -9.20000000000000053e98 or 3.6e14 < t Initial program 97.1%
Taylor expanded in t around inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6479.5
Applied rewrites79.5%
if -9.20000000000000053e98 < t < 3.6e14Initial program 96.1%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f64N/A
lower--.f6465.2
Applied rewrites65.2%
Final simplification70.7%
(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 96.5%
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.3
Applied rewrites95.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -310.0) (not (<= t 3.6e+14))) (* x (exp (* (- y) t))) (* x (exp (* (- a) b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t <= -310.0) || !(t <= 3.6e+14)) {
tmp = x * exp((-y * t));
} else {
tmp = x * exp((-a * b));
}
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 <= (-310.0d0)) .or. (.not. (t <= 3.6d+14))) then
tmp = x * exp((-y * t))
else
tmp = x * exp((-a * b))
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 <= -310.0) || !(t <= 3.6e+14)) {
tmp = x * Math.exp((-y * t));
} else {
tmp = x * Math.exp((-a * b));
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t <= -310.0) or not (t <= 3.6e+14): tmp = x * math.exp((-y * t)) else: tmp = x * math.exp((-a * b)) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((t <= -310.0) || !(t <= 3.6e+14)) tmp = Float64(x * exp(Float64(Float64(-y) * t))); else tmp = Float64(x * exp(Float64(Float64(-a) * b))); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t <= -310.0) || ~((t <= 3.6e+14))) tmp = x * exp((-y * t)); else tmp = x * exp((-a * b)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -310.0], N[Not[LessEqual[t, 3.6e+14]], $MachinePrecision]], N[(x * N[Exp[N[((-y) * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[Exp[N[((-a) * b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -310 \lor \neg \left(t \leq 3.6 \cdot 10^{+14}\right):\\
\;\;\;\;x \cdot e^{\left(-y\right) \cdot t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot e^{\left(-a\right) \cdot b}\\
\end{array}
\end{array}
if t < -310 or 3.6e14 < t Initial program 97.6%
Taylor expanded in t around inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6478.1
Applied rewrites78.1%
if -310 < t < 3.6e14Initial program 95.5%
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.5
Applied rewrites95.5%
Taylor expanded in y around 0
Applied rewrites62.9%
Final simplification70.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= b -1.42e-141) (not (<= b 2e-204))) (* x (exp (* (- a) b))) (* x (exp (* (- a) z)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((b <= -1.42e-141) || !(b <= 2e-204)) {
tmp = x * exp((-a * b));
} else {
tmp = x * exp((-a * z));
}
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 <= (-1.42d-141)) .or. (.not. (b <= 2d-204))) then
tmp = x * exp((-a * b))
else
tmp = x * exp((-a * z))
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 <= -1.42e-141) || !(b <= 2e-204)) {
tmp = x * Math.exp((-a * b));
} else {
tmp = x * Math.exp((-a * z));
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (b <= -1.42e-141) or not (b <= 2e-204): tmp = x * math.exp((-a * b)) else: tmp = x * math.exp((-a * z)) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((b <= -1.42e-141) || !(b <= 2e-204)) tmp = Float64(x * exp(Float64(Float64(-a) * b))); else tmp = Float64(x * exp(Float64(Float64(-a) * z))); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((b <= -1.42e-141) || ~((b <= 2e-204))) tmp = x * exp((-a * b)); else tmp = x * exp((-a * z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[b, -1.42e-141], N[Not[LessEqual[b, 2e-204]], $MachinePrecision]], N[(x * N[Exp[N[((-a) * b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[Exp[N[((-a) * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.42 \cdot 10^{-141} \lor \neg \left(b \leq 2 \cdot 10^{-204}\right):\\
\;\;\;\;x \cdot e^{\left(-a\right) \cdot b}\\
\mathbf{else}:\\
\;\;\;\;x \cdot e^{\left(-a\right) \cdot z}\\
\end{array}
\end{array}
if b < -1.42000000000000003e-141 or 2e-204 < b Initial program 100.0%
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.0
Applied rewrites99.0%
Taylor expanded in y around 0
Applied rewrites65.8%
if -1.42000000000000003e-141 < b < 2e-204Initial program 82.2%
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.7%
Final simplification63.4%
(FPCore (x y z t a b) :precision binary64 (* x (exp (* (- a) z))))
double code(double x, double y, double z, double t, double a, double b) {
return x * exp((-a * z));
}
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((-a * z))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x * Math.exp((-a * z));
}
def code(x, y, z, t, a, b): return x * math.exp((-a * z))
function code(x, y, z, t, a, b) return Float64(x * exp(Float64(Float64(-a) * z))) end
function tmp = code(x, y, z, t, a, b) tmp = x * exp((-a * z)); end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[((-a) * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{\left(-a\right) \cdot z}
\end{array}
Initial program 96.5%
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 rewrites33.8%
herbie shell --seed 2024338
(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))))))