
(FPCore (x y z t a b c i) :precision binary64 (+ (+ (+ (+ (+ (* x (log y)) z) t) a) (* (- b 0.5) (log c))) (* y i)))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((((x * log(y)) + z) + t) + a) + ((b - 0.5) * log(c))) + (y * i);
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = (((((x * log(y)) + z) + t) + a) + ((b - 0.5d0) * log(c))) + (y * i)
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((((x * Math.log(y)) + z) + t) + a) + ((b - 0.5) * Math.log(c))) + (y * i);
}
def code(x, y, z, t, a, b, c, i): return (((((x * math.log(y)) + z) + t) + a) + ((b - 0.5) * math.log(c))) + (y * i)
function code(x, y, z, t, a, b, c, i) return Float64(Float64(Float64(Float64(Float64(Float64(x * log(y)) + z) + t) + a) + Float64(Float64(b - 0.5) * log(c))) + Float64(y * i)) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = (((((x * log(y)) + z) + t) + a) + ((b - 0.5) * log(c))) + (y * i); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] + t), $MachinePrecision] + a), $MachinePrecision] + N[(N[(b - 0.5), $MachinePrecision] * N[Log[c], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * i), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x \cdot \log y + z\right) + t\right) + a\right) + \left(b - 0.5\right) \cdot \log c\right) + y \cdot i
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b c i) :precision binary64 (+ (+ (+ (+ (+ (* x (log y)) z) t) a) (* (- b 0.5) (log c))) (* y i)))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((((x * log(y)) + z) + t) + a) + ((b - 0.5) * log(c))) + (y * i);
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = (((((x * log(y)) + z) + t) + a) + ((b - 0.5d0) * log(c))) + (y * i)
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((((x * Math.log(y)) + z) + t) + a) + ((b - 0.5) * Math.log(c))) + (y * i);
}
def code(x, y, z, t, a, b, c, i): return (((((x * math.log(y)) + z) + t) + a) + ((b - 0.5) * math.log(c))) + (y * i)
function code(x, y, z, t, a, b, c, i) return Float64(Float64(Float64(Float64(Float64(Float64(x * log(y)) + z) + t) + a) + Float64(Float64(b - 0.5) * log(c))) + Float64(y * i)) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = (((((x * log(y)) + z) + t) + a) + ((b - 0.5) * log(c))) + (y * i); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] + t), $MachinePrecision] + a), $MachinePrecision] + N[(N[(b - 0.5), $MachinePrecision] * N[Log[c], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * i), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x \cdot \log y + z\right) + t\right) + a\right) + \left(b - 0.5\right) \cdot \log c\right) + y \cdot i
\end{array}
(FPCore (x y z t a b c i) :precision binary64 (+ (* i y) (+ (* (log c) (- b 0.5)) (+ a (+ t (+ z (* (log y) x)))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (i * y) + ((log(c) * (b - 0.5)) + (a + (t + (z + (log(y) * x)))));
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = (i * y) + ((log(c) * (b - 0.5d0)) + (a + (t + (z + (log(y) * x)))))
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (i * y) + ((Math.log(c) * (b - 0.5)) + (a + (t + (z + (Math.log(y) * x)))));
}
def code(x, y, z, t, a, b, c, i): return (i * y) + ((math.log(c) * (b - 0.5)) + (a + (t + (z + (math.log(y) * x)))))
function code(x, y, z, t, a, b, c, i) return Float64(Float64(i * y) + Float64(Float64(log(c) * Float64(b - 0.5)) + Float64(a + Float64(t + Float64(z + Float64(log(y) * x)))))) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = (i * y) + ((log(c) * (b - 0.5)) + (a + (t + (z + (log(y) * x))))); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(i * y), $MachinePrecision] + N[(N[(N[Log[c], $MachinePrecision] * N[(b - 0.5), $MachinePrecision]), $MachinePrecision] + N[(a + N[(t + N[(z + N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
i \cdot y + \left(\log c \cdot \left(b - 0.5\right) + \left(a + \left(t + \left(z + \log y \cdot x\right)\right)\right)\right)
\end{array}
Initial program 99.5%
Final simplification99.5%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (* (log c) b))
(t_2 (* (log y) x))
(t_3 (+ (* i y) (+ (* (log c) (- b 0.5)) (+ a (+ t (+ z t_2)))))))
(if (<= t_3 -1e+303)
(+ t_2 (* i y))
(if (<= t_3 -2e+192)
(fma (/ z t) t t)
(if (<= t_3 2e+71)
(fma y i t_1)
(if (<= t_3 2e+303) (+ t_1 (+ a t)) (fma (* (/ y a) i) a a)))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = log(c) * b;
double t_2 = log(y) * x;
double t_3 = (i * y) + ((log(c) * (b - 0.5)) + (a + (t + (z + t_2))));
double tmp;
if (t_3 <= -1e+303) {
tmp = t_2 + (i * y);
} else if (t_3 <= -2e+192) {
tmp = fma((z / t), t, t);
} else if (t_3 <= 2e+71) {
tmp = fma(y, i, t_1);
} else if (t_3 <= 2e+303) {
tmp = t_1 + (a + t);
} else {
tmp = fma(((y / a) * i), a, a);
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = Float64(log(c) * b) t_2 = Float64(log(y) * x) t_3 = Float64(Float64(i * y) + Float64(Float64(log(c) * Float64(b - 0.5)) + Float64(a + Float64(t + Float64(z + t_2))))) tmp = 0.0 if (t_3 <= -1e+303) tmp = Float64(t_2 + Float64(i * y)); elseif (t_3 <= -2e+192) tmp = fma(Float64(z / t), t, t); elseif (t_3 <= 2e+71) tmp = fma(y, i, t_1); elseif (t_3 <= 2e+303) tmp = Float64(t_1 + Float64(a + t)); else tmp = fma(Float64(Float64(y / a) * i), a, a); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(N[Log[c], $MachinePrecision] * b), $MachinePrecision]}, Block[{t$95$2 = N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$3 = N[(N[(i * y), $MachinePrecision] + N[(N[(N[Log[c], $MachinePrecision] * N[(b - 0.5), $MachinePrecision]), $MachinePrecision] + N[(a + N[(t + N[(z + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1e+303], N[(t$95$2 + N[(i * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -2e+192], N[(N[(z / t), $MachinePrecision] * t + t), $MachinePrecision], If[LessEqual[t$95$3, 2e+71], N[(y * i + t$95$1), $MachinePrecision], If[LessEqual[t$95$3, 2e+303], N[(t$95$1 + N[(a + t), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / a), $MachinePrecision] * i), $MachinePrecision] * a + a), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log c \cdot b\\
t_2 := \log y \cdot x\\
t_3 := i \cdot y + \left(\log c \cdot \left(b - 0.5\right) + \left(a + \left(t + \left(z + t\_2\right)\right)\right)\right)\\
\mathbf{if}\;t\_3 \leq -1 \cdot 10^{+303}:\\
\;\;\;\;t\_2 + i \cdot y\\
\mathbf{elif}\;t\_3 \leq -2 \cdot 10^{+192}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, t, t\right)\\
\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+71}:\\
\;\;\;\;\mathsf{fma}\left(y, i, t\_1\right)\\
\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+303}:\\
\;\;\;\;t\_1 + \left(a + t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a} \cdot i, a, a\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (+.f64 (+.f64 (*.f64 x (log.f64 y)) z) t) a) (*.f64 (-.f64 b #s(literal 1/2 binary64)) (log.f64 c))) (*.f64 y i)) < -1e303Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f6479.6
Applied rewrites79.6%
if -1e303 < (+.f64 (+.f64 (+.f64 (+.f64 (+.f64 (*.f64 x (log.f64 y)) z) t) a) (*.f64 (-.f64 b #s(literal 1/2 binary64)) (log.f64 c))) (*.f64 y i)) < -2.00000000000000008e192Initial program 99.8%
Taylor expanded in t around -inf
associate-*r*N/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
associate-*r*N/A
Applied rewrites65.5%
Taylor expanded in z around inf
Applied rewrites29.5%
if -2.00000000000000008e192 < (+.f64 (+.f64 (+.f64 (+.f64 (+.f64 (*.f64 x (log.f64 y)) z) t) a) (*.f64 (-.f64 b #s(literal 1/2 binary64)) (log.f64 c))) (*.f64 y i)) < 2.0000000000000001e71Initial program 99.8%
Taylor expanded in b around inf
lower-*.f64N/A
lower-log.f6426.3
Applied rewrites26.3%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6426.3
Applied rewrites26.3%
if 2.0000000000000001e71 < (+.f64 (+.f64 (+.f64 (+.f64 (+.f64 (*.f64 x (log.f64 y)) z) t) a) (*.f64 (-.f64 b #s(literal 1/2 binary64)) (log.f64 c))) (*.f64 y i)) < 2e303Initial program 99.8%
Taylor expanded in x around 0
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-log.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6482.1
Applied rewrites82.1%
Taylor expanded in b around inf
Applied rewrites54.1%
if 2e303 < (+.f64 (+.f64 (+.f64 (+.f64 (+.f64 (*.f64 x (log.f64 y)) z) t) a) (*.f64 (-.f64 b #s(literal 1/2 binary64)) (log.f64 c))) (*.f64 y i)) Initial program 99.4%
Taylor expanded in a around -inf
associate-*r*N/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
associate-*r*N/A
Applied rewrites90.3%
Taylor expanded in y around inf
Applied rewrites79.5%
Final simplification47.0%
herbie shell --seed 2024230
(FPCore (x y z t a b c i)
:name "Numeric.SpecFunctions:logBeta from math-functions-0.1.5.2, B"
:precision binary64
(+ (+ (+ (+ (+ (* x (log y)) z) t) a) (* (- b 0.5) (log c))) (* y i)))