
(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 6 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 (+ 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}
Initial program 99.6%
(FPCore (x y z t a) :precision binary64 (if (<= t 1.05e+17) (* (- a 0.5) (log t)) (- (- a 0.5) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 1.05e+17) {
tmp = (a - 0.5) * log(t);
} else {
tmp = (a - 0.5) - t;
}
return tmp;
}
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
real(8) :: tmp
if (t <= 1.05d+17) then
tmp = (a - 0.5d0) * log(t)
else
tmp = (a - 0.5d0) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 1.05e+17) {
tmp = (a - 0.5) * Math.log(t);
} else {
tmp = (a - 0.5) - t;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if t <= 1.05e+17: tmp = (a - 0.5) * math.log(t) else: tmp = (a - 0.5) - t return tmp
function code(x, y, z, t, a) tmp = 0.0 if (t <= 1.05e+17) tmp = Float64(Float64(a - 0.5) * log(t)); else tmp = Float64(Float64(a - 0.5) - t); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= 1.05e+17) tmp = (a - 0.5) * log(t); else tmp = (a - 0.5) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, 1.05e+17], N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision], N[(N[(a - 0.5), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 1.05 \cdot 10^{+17}:\\
\;\;\;\;\left(a - 0.5\right) \cdot \log t\\
\mathbf{else}:\\
\;\;\;\;\left(a - 0.5\right) - t\\
\end{array}
\end{array}
if t < 1.05e17Initial program 99.3%
Taylor expanded in x around 0
Applied rewrites10.0%
Taylor expanded in x around 0
Applied rewrites7.5%
Taylor expanded in x around 0
Applied rewrites56.2%
if 1.05e17 < t Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites76.9%
Taylor expanded in x around 0
Applied rewrites79.4%
(FPCore (x y z t a) :precision binary64 (if (<= t 1.0) (log (+ x y)) (- (- a 0.5) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 1.0) {
tmp = log((x + y));
} else {
tmp = (a - 0.5) - t;
}
return tmp;
}
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
real(8) :: tmp
if (t <= 1.0d0) then
tmp = log((x + y))
else
tmp = (a - 0.5d0) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 1.0) {
tmp = Math.log((x + y));
} else {
tmp = (a - 0.5) - t;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if t <= 1.0: tmp = math.log((x + y)) else: tmp = (a - 0.5) - t return tmp
function code(x, y, z, t, a) tmp = 0.0 if (t <= 1.0) tmp = log(Float64(x + y)); else tmp = Float64(Float64(a - 0.5) - t); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= 1.0) tmp = log((x + y)); else tmp = (a - 0.5) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, 1.0], N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision], N[(N[(a - 0.5), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 1:\\
\;\;\;\;\log \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(a - 0.5\right) - t\\
\end{array}
\end{array}
if t < 1Initial program 99.3%
Taylor expanded in x around 0
Applied rewrites10.2%
if 1 < t Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites75.8%
Taylor expanded in x around 0
Applied rewrites78.4%
(FPCore (x y z t a) :precision binary64 (if (<= t 1.0) (log z) (- (- a 0.5) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 1.0) {
tmp = log(z);
} else {
tmp = (a - 0.5) - t;
}
return tmp;
}
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
real(8) :: tmp
if (t <= 1.0d0) then
tmp = log(z)
else
tmp = (a - 0.5d0) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 1.0) {
tmp = Math.log(z);
} else {
tmp = (a - 0.5) - t;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if t <= 1.0: tmp = math.log(z) else: tmp = (a - 0.5) - t return tmp
function code(x, y, z, t, a) tmp = 0.0 if (t <= 1.0) tmp = log(z); else tmp = Float64(Float64(a - 0.5) - t); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= 1.0) tmp = log(z); else tmp = (a - 0.5) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, 1.0], N[Log[z], $MachinePrecision], N[(N[(a - 0.5), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 1:\\
\;\;\;\;\log z\\
\mathbf{else}:\\
\;\;\;\;\left(a - 0.5\right) - t\\
\end{array}
\end{array}
if t < 1Initial program 99.3%
Taylor expanded in x around 0
Applied rewrites10.2%
Taylor expanded in x around 0
Applied rewrites6.4%
if 1 < t Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites75.8%
Taylor expanded in x around 0
Applied rewrites78.4%
(FPCore (x y z t a) :precision binary64 (- (- a 0.5) t))
double code(double x, double y, double z, double t, double a) {
return (a - 0.5) - 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 = (a - 0.5d0) - t
end function
public static double code(double x, double y, double z, double t, double a) {
return (a - 0.5) - t;
}
def code(x, y, z, t, a): return (a - 0.5) - t
function code(x, y, z, t, a) return Float64(Float64(a - 0.5) - t) end
function tmp = code(x, y, z, t, a) tmp = (a - 0.5) - t; end
code[x_, y_, z_, t_, a_] := N[(N[(a - 0.5), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(a - 0.5\right) - t
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites41.2%
Taylor expanded in x around 0
Applied rewrites38.2%
(FPCore (x y z t a) :precision binary64 (- a 0.5))
double code(double x, double y, double z, double t, double a) {
return a - 0.5;
}
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 = a - 0.5d0
end function
public static double code(double x, double y, double z, double t, double a) {
return a - 0.5;
}
def code(x, y, z, t, a): return a - 0.5
function code(x, y, z, t, a) return Float64(a - 0.5) end
function tmp = code(x, y, z, t, a) tmp = a - 0.5; end
code[x_, y_, z_, t_, a_] := N[(a - 0.5), $MachinePrecision]
\begin{array}{l}
\\
a - 0.5
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites6.6%
Taylor expanded in x around 0
Applied rewrites4.4%
(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 2024321
(FPCore (x y z t a)
:name "Numeric.SpecFunctions:logGammaL from math-functions-0.1.5.2"
:precision binary64
:pre (TRUE)
: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))))