
(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 11 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 (* (exp (+ (* (- (log (- 1.0 z)) b) a) (* (- (log z) t) y))) x))
double code(double x, double y, double z, double t, double a, double b) {
return exp((((log((1.0 - z)) - b) * a) + ((log(z) - t) * y))) * x;
}
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 = exp((((log((1.0d0 - z)) - b) * a) + ((log(z) - t) * y))) * x
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return Math.exp((((Math.log((1.0 - z)) - b) * a) + ((Math.log(z) - t) * y))) * x;
}
def code(x, y, z, t, a, b): return math.exp((((math.log((1.0 - z)) - b) * a) + ((math.log(z) - t) * y))) * x
function code(x, y, z, t, a, b) return Float64(exp(Float64(Float64(Float64(log(Float64(1.0 - z)) - b) * a) + Float64(Float64(log(z) - t) * y))) * x) end
function tmp = code(x, y, z, t, a, b) tmp = exp((((log((1.0 - z)) - b) * a) + ((log(z) - t) * y))) * x; end
code[x_, y_, z_, t_, a_, b_] := N[(N[Exp[N[(N[(N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * a), $MachinePrecision] + N[(N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
e^{\left(\log \left(1 - z\right) - b\right) \cdot a + \left(\log z - t\right) \cdot y} \cdot x
\end{array}
Initial program 96.2%
Final simplification96.2%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma (- x) (* t y) x))
(t_2 (* 1.0 t_1))
(t_3 (fma (* t y) x x))
(t_4 (+ (* (- (log (- 1.0 z)) b) a) (* (- (log z) t) y)))
(t_5 (* 1.0 (* t_1 t_3))))
(if (<= t_4 -1e+31)
(/ t_5 t_3)
(if (<= t_4 5.0) t_2 (if (<= t_4 2e+263) (* (/ 1.0 t_3) t_5) t_2)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(-x, (t * y), x);
double t_2 = 1.0 * t_1;
double t_3 = fma((t * y), x, x);
double t_4 = ((log((1.0 - z)) - b) * a) + ((log(z) - t) * y);
double t_5 = 1.0 * (t_1 * t_3);
double tmp;
if (t_4 <= -1e+31) {
tmp = t_5 / t_3;
} else if (t_4 <= 5.0) {
tmp = t_2;
} else if (t_4 <= 2e+263) {
tmp = (1.0 / t_3) * t_5;
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(Float64(-x), Float64(t * y), x) t_2 = Float64(1.0 * t_1) t_3 = fma(Float64(t * y), x, x) t_4 = Float64(Float64(Float64(log(Float64(1.0 - z)) - b) * a) + Float64(Float64(log(z) - t) * y)) t_5 = Float64(1.0 * Float64(t_1 * t_3)) tmp = 0.0 if (t_4 <= -1e+31) tmp = Float64(t_5 / t_3); elseif (t_4 <= 5.0) tmp = t_2; elseif (t_4 <= 2e+263) tmp = Float64(Float64(1.0 / t_3) * t_5); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[((-x) * N[(t * y), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(t * y), $MachinePrecision] * x + x), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * a), $MachinePrecision] + N[(N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(1.0 * N[(t$95$1 * t$95$3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -1e+31], N[(t$95$5 / t$95$3), $MachinePrecision], If[LessEqual[t$95$4, 5.0], t$95$2, If[LessEqual[t$95$4, 2e+263], N[(N[(1.0 / t$95$3), $MachinePrecision] * t$95$5), $MachinePrecision], t$95$2]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(-x, t \cdot y, x\right)\\
t_2 := 1 \cdot t\_1\\
t_3 := \mathsf{fma}\left(t \cdot y, x, x\right)\\
t_4 := \left(\log \left(1 - z\right) - b\right) \cdot a + \left(\log z - t\right) \cdot y\\
t_5 := 1 \cdot \left(t\_1 \cdot t\_3\right)\\
\mathbf{if}\;t\_4 \leq -1 \cdot 10^{+31}:\\
\;\;\;\;\frac{t\_5}{t\_3}\\
\mathbf{elif}\;t\_4 \leq 5:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_4 \leq 2 \cdot 10^{+263}:\\
\;\;\;\;\frac{1}{t\_3} \cdot t\_5\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))) < -9.9999999999999996e30Initial program 98.7%
Taylor expanded in t around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-*r*N/A
associate-*r*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
Applied rewrites65.1%
Taylor expanded in a around 0
Applied rewrites34.2%
Taylor expanded in y around 0
Applied rewrites3.0%
Applied rewrites12.4%
if -9.9999999999999996e30 < (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))) < 5 or 2.00000000000000003e263 < (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))) Initial program 94.0%
Taylor expanded in t around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-*r*N/A
associate-*r*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
Applied rewrites78.8%
Taylor expanded in a around 0
Applied rewrites61.6%
Taylor expanded in y around 0
Applied rewrites57.7%
Applied rewrites65.0%
if 5 < (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))) < 2.00000000000000003e263Initial program 97.6%
Taylor expanded in t around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-*r*N/A
associate-*r*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
Applied rewrites72.5%
Taylor expanded in a around 0
Applied rewrites42.0%
Taylor expanded in y around 0
Applied rewrites14.9%
Applied rewrites24.4%
Final simplification35.4%
herbie shell --seed 2024230
(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))))))