
(FPCore (x y z t a) :precision binary64 (+ (- (+ (log (+ x y)) (log z)) t) (* (- a 0.5) (log t))))
double code(double x, double y, double z, double t, double a) {
return ((log((x + y)) + log(z)) - t) + ((a - 0.5) * log(t));
}
real(8) function code(x, y, z, t, a)
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
code = ((log((x + y)) + log(z)) - t) + ((a - 0.5d0) * log(t))
end function
public static double code(double x, double y, double z, double t, double a) {
return ((Math.log((x + y)) + Math.log(z)) - t) + ((a - 0.5) * Math.log(t));
}
def code(x, y, z, t, a): return ((math.log((x + y)) + math.log(z)) - t) + ((a - 0.5) * math.log(t))
function code(x, y, z, t, a) return Float64(Float64(Float64(log(Float64(x + y)) + log(z)) - t) + Float64(Float64(a - 0.5) * log(t))) end
function tmp = code(x, y, z, t, a) tmp = ((log((x + y)) + log(z)) - t) + ((a - 0.5) * log(t)); end
code[x_, y_, z_, t_, a_] := N[(N[(N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ (- (+ (log (+ x y)) (log z)) t) (* (- a 0.5) (log t))))
double code(double x, double y, double z, double t, double a) {
return ((log((x + y)) + log(z)) - t) + ((a - 0.5) * log(t));
}
real(8) function code(x, y, z, t, a)
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
code = ((log((x + y)) + log(z)) - t) + ((a - 0.5d0) * log(t))
end function
public static double code(double x, double y, double z, double t, double a) {
return ((Math.log((x + y)) + Math.log(z)) - t) + ((a - 0.5) * Math.log(t));
}
def code(x, y, z, t, a): return ((math.log((x + y)) + math.log(z)) - t) + ((a - 0.5) * math.log(t))
function code(x, y, z, t, a) return Float64(Float64(Float64(log(Float64(x + y)) + log(z)) - t) + Float64(Float64(a - 0.5) * log(t))) end
function tmp = code(x, y, z, t, a) tmp = ((log((x + y)) + log(z)) - t) + ((a - 0.5) * log(t)); end
code[x_, y_, z_, t_, a_] := N[(N[(N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t
\end{array}
(FPCore (x y z t a) :precision binary64 (- (- (+ (log (+ y x)) (log z)) t) (* (- 0.5 a) (log t))))
double code(double x, double y, double z, double t, double a) {
return ((log((y + x)) + log(z)) - t) - ((0.5 - a) * log(t));
}
real(8) function code(x, y, z, t, a)
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
code = ((log((y + x)) + log(z)) - t) - ((0.5d0 - a) * log(t))
end function
public static double code(double x, double y, double z, double t, double a) {
return ((Math.log((y + x)) + Math.log(z)) - t) - ((0.5 - a) * Math.log(t));
}
def code(x, y, z, t, a): return ((math.log((y + x)) + math.log(z)) - t) - ((0.5 - a) * math.log(t))
function code(x, y, z, t, a) return Float64(Float64(Float64(log(Float64(y + x)) + log(z)) - t) - Float64(Float64(0.5 - a) * log(t))) end
function tmp = code(x, y, z, t, a) tmp = ((log((y + x)) + log(z)) - t) - ((0.5 - a) * log(t)); end
code[x_, y_, z_, t_, a_] := N[(N[(N[(N[Log[N[(y + x), $MachinePrecision]], $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision] - N[(N[(0.5 - a), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\log \left(y + x\right) + \log z\right) - t\right) - \left(0.5 - a\right) \cdot \log t
\end{array}
Initial program 99.6%
Final simplification99.6%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (- (+ (log (+ y x)) (log z)) t) (* (- 0.5 a) (log t)))))
(if (<= t_1 -50000000000.0)
(- (- t) (/ (log t) (/ -1.0 (- a 0.5))))
(if (<= t_1 850.0)
(fma (- a 0.5) (log t) (log (* z (+ y x))))
(fma (- a 0.5) (log t) (- t))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = ((log((y + x)) + log(z)) - t) - ((0.5 - a) * log(t));
double tmp;
if (t_1 <= -50000000000.0) {
tmp = -t - (log(t) / (-1.0 / (a - 0.5)));
} else if (t_1 <= 850.0) {
tmp = fma((a - 0.5), log(t), log((z * (y + x))));
} else {
tmp = fma((a - 0.5), log(t), -t);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(Float64(log(Float64(y + x)) + log(z)) - t) - Float64(Float64(0.5 - a) * log(t))) tmp = 0.0 if (t_1 <= -50000000000.0) tmp = Float64(Float64(-t) - Float64(log(t) / Float64(-1.0 / Float64(a - 0.5)))); elseif (t_1 <= 850.0) tmp = fma(Float64(a - 0.5), log(t), log(Float64(z * Float64(y + x)))); else tmp = fma(Float64(a - 0.5), log(t), Float64(-t)); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(N[(N[Log[N[(y + x), $MachinePrecision]], $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision] - N[(N[(0.5 - a), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -50000000000.0], N[((-t) - N[(N[Log[t], $MachinePrecision] / N[(-1.0 / N[(a - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 850.0], N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision] + N[Log[N[(z * N[(y + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision] + (-t)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\left(\log \left(y + x\right) + \log z\right) - t\right) - \left(0.5 - a\right) \cdot \log t\\
\mathbf{if}\;t\_1 \leq -50000000000:\\
\;\;\;\;\left(-t\right) - \frac{\log t}{\frac{-1}{a - 0.5}}\\
\mathbf{elif}\;t\_1 \leq 850:\\
\;\;\;\;\mathsf{fma}\left(a - 0.5, \log t, \log \left(z \cdot \left(y + x\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a - 0.5, \log t, -t\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 (+.f64 (log.f64 (+.f64 x y)) (log.f64 z)) t) (*.f64 (-.f64 a #s(literal 1/2 binary64)) (log.f64 t))) < -5e10Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
flip3--N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
clear-numN/A
flip3--N/A
lift--.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in t around inf
mul-1-negN/A
lower-neg.f6499.4
Applied rewrites99.4%
if -5e10 < (+.f64 (-.f64 (+.f64 (log.f64 (+.f64 x y)) (log.f64 z)) t) (*.f64 (-.f64 a #s(literal 1/2 binary64)) (log.f64 t))) < 850Initial program 98.9%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
Applied rewrites92.5%
Taylor expanded in t around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-log.f64N/A
lower-log.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6489.0
Applied rewrites89.0%
if 850 < (+.f64 (-.f64 (+.f64 (log.f64 (+.f64 x y)) (log.f64 z)) t) (*.f64 (-.f64 a #s(literal 1/2 binary64)) (log.f64 t))) Initial program 99.6%
Taylor expanded in x around 0
associate-+r+N/A
+-commutativeN/A
associate--l+N/A
*-commutativeN/A
+-commutativeN/A
associate-+r-N/A
lower-fma.f64N/A
lower--.f64N/A
lower-log.f64N/A
associate-+r-N/A
+-commutativeN/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-log.f64N/A
lower-log.f6470.0
Applied rewrites70.0%
Taylor expanded in t around inf
Applied rewrites79.1%
Final simplification92.2%
(FPCore (x y z t a) :precision binary64 (+ (log (+ x y)) (+ (- (log z) t) (* (- a 0.5) (log t)))))
double code(double x, double y, double z, double t, double a) {
return log((x + y)) + ((log(z) - t) + ((a - 0.5) * log(t)));
}
real(8) function code(x, y, z, t, a)
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
code = log((x + y)) + ((log(z) - t) + ((a - 0.5d0) * log(t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return Math.log((x + y)) + ((Math.log(z) - t) + ((a - 0.5) * Math.log(t)));
}
def code(x, y, z, t, a): return math.log((x + y)) + ((math.log(z) - t) + ((a - 0.5) * math.log(t)))
function code(x, y, z, t, a) return Float64(log(Float64(x + y)) + Float64(Float64(log(z) - t) + Float64(Float64(a - 0.5) * log(t)))) end
function tmp = code(x, y, z, t, a) tmp = log((x + y)) + ((log(z) - t) + ((a - 0.5) * log(t))); end
code[x_, y_, z_, t_, a_] := N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[(N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(x + y\right) + \left(\left(\log z - t\right) + \left(a - 0.5\right) \cdot \log t\right)
\end{array}
herbie shell --seed 2024230
(FPCore (x y z t a)
:name "Numeric.SpecFunctions:logGammaL from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (+ (log (+ x y)) (+ (- (log z) t) (* (- a 1/2) (log t)))))
(+ (- (+ (log (+ x y)) (log z)) t) (* (- a 0.5) (log t))))