
(FPCore (x y z t) :precision binary64 (+ (- (- (* x (log y)) y) z) (log t)))
double code(double x, double y, double z, double t) {
return (((x * log(y)) - y) - z) + log(t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * log(y)) - y) - z) + log(t)
end function
public static double code(double x, double y, double z, double t) {
return (((x * Math.log(y)) - y) - z) + Math.log(t);
}
def code(x, y, z, t): return (((x * math.log(y)) - y) - z) + math.log(t)
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * log(y)) - y) - z) + log(t)) end
function tmp = code(x, y, z, t) tmp = (((x * log(y)) - y) - z) + log(t); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] - z), $MachinePrecision] + N[Log[t], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot \log y - y\right) - z\right) + \log t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (- (- (* x (log y)) y) z) (log t)))
double code(double x, double y, double z, double t) {
return (((x * log(y)) - y) - z) + log(t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * log(y)) - y) - z) + log(t)
end function
public static double code(double x, double y, double z, double t) {
return (((x * Math.log(y)) - y) - z) + Math.log(t);
}
def code(x, y, z, t): return (((x * math.log(y)) - y) - z) + math.log(t)
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * log(y)) - y) - z) + log(t)) end
function tmp = code(x, y, z, t) tmp = (((x * log(y)) - y) - z) + log(t); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] - z), $MachinePrecision] + N[Log[t], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot \log y - y\right) - z\right) + \log t
\end{array}
(FPCore (x y z t) :precision binary64 (fma (log y) x (- (- (log t) y) z)))
double code(double x, double y, double z, double t) {
return fma(log(y), x, ((log(t) - y) - z));
}
function code(x, y, z, t) return fma(log(y), x, Float64(Float64(log(t) - y) - z)) end
code[x_, y_, z_, t_] := N[(N[Log[y], $MachinePrecision] * x + N[(N[(N[Log[t], $MachinePrecision] - y), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log y, x, \left(\log t - y\right) - z\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
associate--l+N/A
*-rgt-identityN/A
*-inversesN/A
fp-cancel-sign-subN/A
mul-1-negN/A
associate-/l*N/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
remove-double-negN/A
fp-cancel-sign-subN/A
mul-1-negN/A
*-commutativeN/A
Applied rewrites99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x (log y)) y)))
(if (<= t_1 -10000.0)
(- (log t) y)
(if (<= t_1 1e+23) (+ (- z) (log t)) (* (log y) x)))))
double code(double x, double y, double z, double t) {
double t_1 = (x * log(y)) - y;
double tmp;
if (t_1 <= -10000.0) {
tmp = log(t) - y;
} else if (t_1 <= 1e+23) {
tmp = -z + log(t);
} else {
tmp = log(y) * x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = (x * log(y)) - y
if (t_1 <= (-10000.0d0)) then
tmp = log(t) - y
else if (t_1 <= 1d+23) then
tmp = -z + log(t)
else
tmp = log(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (x * Math.log(y)) - y;
double tmp;
if (t_1 <= -10000.0) {
tmp = Math.log(t) - y;
} else if (t_1 <= 1e+23) {
tmp = -z + Math.log(t);
} else {
tmp = Math.log(y) * x;
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * math.log(y)) - y tmp = 0 if t_1 <= -10000.0: tmp = math.log(t) - y elif t_1 <= 1e+23: tmp = -z + math.log(t) else: tmp = math.log(y) * x return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * log(y)) - y) tmp = 0.0 if (t_1 <= -10000.0) tmp = Float64(log(t) - y); elseif (t_1 <= 1e+23) tmp = Float64(Float64(-z) + log(t)); else tmp = Float64(log(y) * x); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * log(y)) - y; tmp = 0.0; if (t_1 <= -10000.0) tmp = log(t) - y; elseif (t_1 <= 1e+23) tmp = -z + log(t); else tmp = log(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t$95$1, -10000.0], N[(N[Log[t], $MachinePrecision] - y), $MachinePrecision], If[LessEqual[t$95$1, 1e+23], N[((-z) + N[Log[t], $MachinePrecision]), $MachinePrecision], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \log y - y\\
\mathbf{if}\;t\_1 \leq -10000:\\
\;\;\;\;\log t - y\\
\mathbf{elif}\;t\_1 \leq 10^{+23}:\\
\;\;\;\;\left(-z\right) + \log t\\
\mathbf{else}:\\
\;\;\;\;\log y \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 x (log.f64 y)) y) < -1e4Initial program 99.9%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-log.f6473.4
Applied rewrites73.4%
Taylor expanded in x around 0
Applied rewrites51.4%
if -1e4 < (-.f64 (*.f64 x (log.f64 y)) y) < 9.9999999999999992e22Initial program 100.0%
lift--.f64N/A
flip--N/A
fp-cancel-sub-sign-invN/A
div-addN/A
lift-*.f64N/A
associate-*l*N/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites100.0%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6498.5
Applied rewrites98.5%
if 9.9999999999999992e22 < (-.f64 (*.f64 x (log.f64 y)) y) Initial program 99.7%
lift--.f64N/A
flip--N/A
fp-cancel-sub-sign-invN/A
div-addN/A
lift-*.f64N/A
associate-*l*N/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites91.7%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
Applied rewrites99.3%
Taylor expanded in x around inf
lower-/.f64N/A
lower-log.f6499.3
Applied rewrites99.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f6479.0
Applied rewrites79.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -120000000.0) (not (<= z 1.4e-7))) (fma (log y) x (* (- (/ (- y) z) 1.0) z)) (- (fma (log y) x (log t)) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -120000000.0) || !(z <= 1.4e-7)) {
tmp = fma(log(y), x, (((-y / z) - 1.0) * z));
} else {
tmp = fma(log(y), x, log(t)) - y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -120000000.0) || !(z <= 1.4e-7)) tmp = fma(log(y), x, Float64(Float64(Float64(Float64(-y) / z) - 1.0) * z)); else tmp = Float64(fma(log(y), x, log(t)) - y); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -120000000.0], N[Not[LessEqual[z, 1.4e-7]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x + N[(N[(N[((-y) / z), $MachinePrecision] - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[y], $MachinePrecision] * x + N[Log[t], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -120000000 \lor \neg \left(z \leq 1.4 \cdot 10^{-7}\right):\\
\;\;\;\;\mathsf{fma}\left(\log y, x, \left(\frac{-y}{z} - 1\right) \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x, \log t\right) - y\\
\end{array}
\end{array}
if z < -1.2e8 or 1.4000000000000001e-7 < z Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
associate--l+N/A
*-rgt-identityN/A
*-inversesN/A
fp-cancel-sign-subN/A
mul-1-negN/A
associate-/l*N/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
remove-double-negN/A
fp-cancel-sign-subN/A
mul-1-negN/A
*-commutativeN/A
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites84.8%
Taylor expanded in z around inf
Applied rewrites99.9%
Taylor expanded in y around inf
Applied rewrites99.4%
if -1.2e8 < z < 1.4000000000000001e-7Initial program 99.9%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-log.f6498.9
Applied rewrites98.9%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (if (or (<= x -4e+20) (not (<= x 2e+21))) (fma (log y) x (* (- (/ (- y) z) 1.0) z)) (- (- (log t) y) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4e+20) || !(x <= 2e+21)) {
tmp = fma(log(y), x, (((-y / z) - 1.0) * z));
} else {
tmp = (log(t) - y) - z;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((x <= -4e+20) || !(x <= 2e+21)) tmp = fma(log(y), x, Float64(Float64(Float64(Float64(-y) / z) - 1.0) * z)); else tmp = Float64(Float64(log(t) - y) - z); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -4e+20], N[Not[LessEqual[x, 2e+21]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x + N[(N[(N[((-y) / z), $MachinePrecision] - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[t], $MachinePrecision] - y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+20} \lor \neg \left(x \leq 2 \cdot 10^{+21}\right):\\
\;\;\;\;\mathsf{fma}\left(\log y, x, \left(\frac{-y}{z} - 1\right) \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\log t - y\right) - z\\
\end{array}
\end{array}
if x < -4e20 or 2e21 < x Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
associate--l+N/A
*-rgt-identityN/A
*-inversesN/A
fp-cancel-sign-subN/A
mul-1-negN/A
associate-/l*N/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
remove-double-negN/A
fp-cancel-sign-subN/A
mul-1-negN/A
*-commutativeN/A
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites81.4%
Taylor expanded in z around inf
Applied rewrites90.4%
Taylor expanded in y around inf
Applied rewrites90.4%
if -4e20 < x < 2e21Initial program 100.0%
Taylor expanded in x around 0
associate--r+N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-log.f6498.3
Applied rewrites98.3%
Final simplification94.6%
(FPCore (x y z t) :precision binary64 (if (or (<= x -8e+107) (not (<= x 1e+126))) (* (log y) x) (- (- (log t) y) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -8e+107) || !(x <= 1e+126)) {
tmp = log(y) * x;
} else {
tmp = (log(t) - y) - z;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x <= (-8d+107)) .or. (.not. (x <= 1d+126))) then
tmp = log(y) * x
else
tmp = (log(t) - y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -8e+107) || !(x <= 1e+126)) {
tmp = Math.log(y) * x;
} else {
tmp = (Math.log(t) - y) - z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -8e+107) or not (x <= 1e+126): tmp = math.log(y) * x else: tmp = (math.log(t) - y) - z return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -8e+107) || !(x <= 1e+126)) tmp = Float64(log(y) * x); else tmp = Float64(Float64(log(t) - y) - z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -8e+107) || ~((x <= 1e+126))) tmp = log(y) * x; else tmp = (log(t) - y) - z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -8e+107], N[Not[LessEqual[x, 1e+126]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[Log[t], $MachinePrecision] - y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{+107} \lor \neg \left(x \leq 10^{+126}\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\log t - y\right) - z\\
\end{array}
\end{array}
if x < -7.9999999999999998e107 or 9.99999999999999925e125 < x Initial program 99.6%
lift--.f64N/A
flip--N/A
fp-cancel-sub-sign-invN/A
div-addN/A
lift-*.f64N/A
associate-*l*N/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites81.6%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
Applied rewrites99.3%
Taylor expanded in x around inf
lower-/.f64N/A
lower-log.f6498.5
Applied rewrites98.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f6478.1
Applied rewrites78.1%
if -7.9999999999999998e107 < x < 9.99999999999999925e125Initial program 100.0%
Taylor expanded in x around 0
associate--r+N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-log.f6492.1
Applied rewrites92.1%
Final simplification88.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.15e+27) (not (<= z 2.6e+142))) (- z) (- (log t) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.15e+27) || !(z <= 2.6e+142)) {
tmp = -z;
} else {
tmp = log(t) - y;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-1.15d+27)) .or. (.not. (z <= 2.6d+142))) then
tmp = -z
else
tmp = log(t) - y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.15e+27) || !(z <= 2.6e+142)) {
tmp = -z;
} else {
tmp = Math.log(t) - y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.15e+27) or not (z <= 2.6e+142): tmp = -z else: tmp = math.log(t) - y return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.15e+27) || !(z <= 2.6e+142)) tmp = Float64(-z); else tmp = Float64(log(t) - y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.15e+27) || ~((z <= 2.6e+142))) tmp = -z; else tmp = log(t) - y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.15e+27], N[Not[LessEqual[z, 2.6e+142]], $MachinePrecision]], (-z), N[(N[Log[t], $MachinePrecision] - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+27} \lor \neg \left(z \leq 2.6 \cdot 10^{+142}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\log t - y\\
\end{array}
\end{array}
if z < -1.15e27 or 2.60000000000000021e142 < z Initial program 99.9%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6476.1
Applied rewrites76.1%
if -1.15e27 < z < 2.60000000000000021e142Initial program 99.9%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-log.f6493.5
Applied rewrites93.5%
Taylor expanded in x around 0
Applied rewrites58.3%
Final simplification65.5%
(FPCore (x y z t) :precision binary64 (- z))
double code(double x, double y, double z, double t) {
return -z;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = -z
end function
public static double code(double x, double y, double z, double t) {
return -z;
}
def code(x, y, z, t): return -z
function code(x, y, z, t) return Float64(-z) end
function tmp = code(x, y, z, t) tmp = -z; end
code[x_, y_, z_, t_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.9%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6435.6
Applied rewrites35.6%
herbie shell --seed 2024338
(FPCore (x y z t)
:name "Numeric.SpecFunctions:incompleteGamma from math-functions-0.1.5.2, A"
:precision binary64
(+ (- (- (* x (log y)) y) z) (log t)))