
(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 7 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.7%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ (* (- a 0.5) (log t)) (log z))))
(if (<= (- a 0.5) -7.2e+22)
t_1
(if (<= (- a 0.5) 5.5e+57) (- (+ (log (+ x y)) (log z)) t) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = ((a - 0.5) * log(t)) + log(z);
double tmp;
if ((a - 0.5) <= -7.2e+22) {
tmp = t_1;
} else if ((a - 0.5) <= 5.5e+57) {
tmp = (log((x + y)) + log(z)) - t;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = ((a - 0.5d0) * log(t)) + log(z)
if ((a - 0.5d0) <= (-7.2d+22)) then
tmp = t_1
else if ((a - 0.5d0) <= 5.5d+57) then
tmp = (log((x + y)) + log(z)) - t
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = ((a - 0.5) * Math.log(t)) + Math.log(z);
double tmp;
if ((a - 0.5) <= -7.2e+22) {
tmp = t_1;
} else if ((a - 0.5) <= 5.5e+57) {
tmp = (Math.log((x + y)) + Math.log(z)) - t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = ((a - 0.5) * math.log(t)) + math.log(z) tmp = 0 if (a - 0.5) <= -7.2e+22: tmp = t_1 elif (a - 0.5) <= 5.5e+57: tmp = (math.log((x + y)) + math.log(z)) - t else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(Float64(a - 0.5) * log(t)) + log(z)) tmp = 0.0 if (Float64(a - 0.5) <= -7.2e+22) tmp = t_1; elseif (Float64(a - 0.5) <= 5.5e+57) tmp = Float64(Float64(log(Float64(x + y)) + log(z)) - t); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = ((a - 0.5) * log(t)) + log(z); tmp = 0.0; if ((a - 0.5) <= -7.2e+22) tmp = t_1; elseif ((a - 0.5) <= 5.5e+57) tmp = (log((x + y)) + log(z)) - t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a - 0.5), $MachinePrecision], -7.2e+22], t$95$1, If[LessEqual[N[(a - 0.5), $MachinePrecision], 5.5e+57], N[(N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(a - 0.5\right) \cdot \log t + \log z\\
\mathbf{if}\;a - 0.5 \leq -7.2 \cdot 10^{+22}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a - 0.5 \leq 5.5 \cdot 10^{+57}:\\
\;\;\;\;\left(\log \left(x + y\right) + \log z\right) - t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 a #s(literal 1/2 binary64)) < -7.2e22 or 5.5000000000000002e57 < (-.f64 a #s(literal 1/2 binary64)) Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites2.9%
Taylor expanded in x around 0
Applied rewrites17.6%
Taylor expanded in x around 0
Applied rewrites20.9%
Taylor expanded in x around 0
Applied rewrites83.1%
if -7.2e22 < (-.f64 a #s(literal 1/2 binary64)) < 5.5000000000000002e57Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites61.8%
(FPCore (x y z t a) :precision binary64 (if (<= t 235.0) (log (+ x y)) (- (- a 0.5) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 235.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 <= 235.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 <= 235.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 <= 235.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 <= 235.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 <= 235.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, 235.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 235:\\
\;\;\;\;\log \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(a - 0.5\right) - t\\
\end{array}
\end{array}
if t < 235Initial program 99.3%
Taylor expanded in x around 0
Applied rewrites10.0%
if 235 < t Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites68.6%
Taylor expanded in x around 0
Applied rewrites71.8%
(FPCore (x y z t a) :precision binary64 (+ (- (- a 0.5) t) (log z)))
double code(double x, double y, double z, double t, double a) {
return ((a - 0.5) - t) + log(z);
}
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) + log(z)
end function
public static double code(double x, double y, double z, double t, double a) {
return ((a - 0.5) - t) + Math.log(z);
}
def code(x, y, z, t, a): return ((a - 0.5) - t) + math.log(z)
function code(x, y, z, t, a) return Float64(Float64(Float64(a - 0.5) - t) + log(z)) end
function tmp = code(x, y, z, t, a) tmp = ((a - 0.5) - t) + log(z); end
code[x_, y_, z_, t_, a_] := N[(N[(N[(a - 0.5), $MachinePrecision] - t), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(a - 0.5\right) - t\right) + \log z
\end{array}
Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites6.3%
Taylor expanded in x around 0
Applied rewrites42.5%
Taylor expanded in x around 0
Applied rewrites43.2%
(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 rewrites11.0%
Taylor expanded in x around 0
Applied rewrites8.9%
if 1 < t Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites67.8%
Taylor expanded in x around 0
Applied rewrites71.0%
(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.7%
Taylor expanded in x around 0
Applied rewrites43.0%
Taylor expanded in x around 0
Applied rewrites41.1%
(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.7%
Taylor expanded in x around 0
Applied rewrites6.3%
Taylor expanded in x around 0
Applied rewrites5.6%
(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 2024313
(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))))