
(FPCore (x y z t) :precision binary64 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))
double code(double x, double y, double z, double t) {
return (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x - 1.0d0) * log(y)) + ((z - 1.0d0) * log((1.0d0 - y)))) - t
end function
public static double code(double x, double y, double z, double t) {
return (((x - 1.0) * Math.log(y)) + ((z - 1.0) * Math.log((1.0 - y)))) - t;
}
def code(x, y, z, t): return (((x - 1.0) * math.log(y)) + ((z - 1.0) * math.log((1.0 - y)))) - t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t) end
function tmp = code(x, y, z, t) tmp = (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))
double code(double x, double y, double z, double t) {
return (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x - 1.0d0) * log(y)) + ((z - 1.0d0) * log((1.0d0 - y)))) - t
end function
public static double code(double x, double y, double z, double t) {
return (((x - 1.0) * Math.log(y)) + ((z - 1.0) * Math.log((1.0 - y)))) - t;
}
def code(x, y, z, t): return (((x - 1.0) * math.log(y)) + ((z - 1.0) * math.log((1.0 - y)))) - t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t) end
function tmp = code(x, y, z, t) tmp = (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\end{array}
(FPCore (x y z t) :precision binary64 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (- (log1p (* (- y) y)) (log1p y)))) t))
double code(double x, double y, double z, double t) {
return (((x - 1.0) * log(y)) + ((z - 1.0) * (log1p((-y * y)) - log1p(y)))) - t;
}
public static double code(double x, double y, double z, double t) {
return (((x - 1.0) * Math.log(y)) + ((z - 1.0) * (Math.log1p((-y * y)) - Math.log1p(y)))) - t;
}
def code(x, y, z, t): return (((x - 1.0) * math.log(y)) + ((z - 1.0) * (math.log1p((-y * y)) - math.log1p(y)))) - t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * Float64(log1p(Float64(Float64(-y) * y)) - log1p(y)))) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[(N[Log[1 + N[((-y) * y), $MachinePrecision]], $MachinePrecision] - N[Log[1 + y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \left(\mathsf{log1p}\left(\left(-y\right) \cdot y\right) - \mathsf{log1p}\left(y\right)\right)\right) - t
\end{array}
Initial program 88.3%
lift-log.f64N/A
lift--.f64N/A
flip--N/A
log-divN/A
lower--.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log1p.f6499.8
Applied rewrites99.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* (log y) x) t))
(t_2 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t)))
(if (<= t_2 -2e+39)
t_1
(if (<= t_2 155.0)
(* (* (fma -0.5 y -1.0) z) y)
(if (<= t_2 3.5e+28) (- (* (log y) -1.0) t) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (log(y) * x) - t;
double t_2 = (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
double tmp;
if (t_2 <= -2e+39) {
tmp = t_1;
} else if (t_2 <= 155.0) {
tmp = (fma(-0.5, y, -1.0) * z) * y;
} else if (t_2 <= 3.5e+28) {
tmp = (log(y) * -1.0) - t;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(log(y) * x) - t) t_2 = Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t) tmp = 0.0 if (t_2 <= -2e+39) tmp = t_1; elseif (t_2 <= 155.0) tmp = Float64(Float64(fma(-0.5, y, -1.0) * z) * y); elseif (t_2 <= 3.5e+28) tmp = Float64(Float64(log(y) * -1.0) - t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[t$95$2, -2e+39], t$95$1, If[LessEqual[t$95$2, 155.0], N[(N[(N[(-0.5 * y + -1.0), $MachinePrecision] * z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$2, 3.5e+28], N[(N[(N[Log[y], $MachinePrecision] * -1.0), $MachinePrecision] - t), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log y \cdot x - t\\
t_2 := \left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t\\
\mathbf{if}\;t\_2 \leq -2 \cdot 10^{+39}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 155:\\
\;\;\;\;\left(\mathsf{fma}\left(-0.5, y, -1\right) \cdot z\right) \cdot y\\
\mathbf{elif}\;t\_2 \leq 3.5 \cdot 10^{+28}:\\
\;\;\;\;\log y \cdot -1 - t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) t) < -1.99999999999999988e39 or 3.5e28 < (-.f64 (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) t) Initial program 96.7%
Taylor expanded in x around inf
*-commutativeN/A
remove-double-negN/A
log-recN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-log.f6496.7
Applied rewrites96.7%
if -1.99999999999999988e39 < (-.f64 (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) t) < 155Initial program 48.6%
Taylor expanded in y around 0
Applied rewrites97.2%
Taylor expanded in y around inf
Applied rewrites7.7%
Taylor expanded in z around inf
Applied rewrites55.3%
if 155 < (-.f64 (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) t) < 3.5e28Initial program 73.6%
Taylor expanded in y around 0
remove-double-negN/A
log-recN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-log.f64N/A
lower--.f6473.6
Applied rewrites73.6%
Taylor expanded in x around 0
Applied rewrites72.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y))))))
(if (<= t_1 -1e+42)
(fma (log y) (- x 1.0) (- t))
(if (<= t_1 3.5e+28)
(fma (* z y) (fma -0.5 y -1.0) (- (+ (log y) t)))
(- (* (log y) x) t)))))
double code(double x, double y, double z, double t) {
double t_1 = ((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)));
double tmp;
if (t_1 <= -1e+42) {
tmp = fma(log(y), (x - 1.0), -t);
} else if (t_1 <= 3.5e+28) {
tmp = fma((z * y), fma(-0.5, y, -1.0), -(log(y) + t));
} else {
tmp = (log(y) * x) - t;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) tmp = 0.0 if (t_1 <= -1e+42) tmp = fma(log(y), Float64(x - 1.0), Float64(-t)); elseif (t_1 <= 3.5e+28) tmp = fma(Float64(z * y), fma(-0.5, y, -1.0), Float64(-Float64(log(y) + t))); else tmp = Float64(Float64(log(y) * x) - t); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+42], N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + (-t)), $MachinePrecision], If[LessEqual[t$95$1, 3.5e+28], N[(N[(z * y), $MachinePrecision] * N[(-0.5 * y + -1.0), $MachinePrecision] + (-N[(N[Log[y], $MachinePrecision] + t), $MachinePrecision])), $MachinePrecision], N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x - 1, -t\right)\\
\mathbf{elif}\;t\_1 \leq 3.5 \cdot 10^{+28}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y, \mathsf{fma}\left(-0.5, y, -1\right), -\left(\log y + t\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log y \cdot x - t\\
\end{array}
\end{array}
if (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) < -1.00000000000000004e42Initial program 93.3%
Taylor expanded in y around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-subN/A
remove-double-negN/A
distribute-lft-neg-outN/A
log-recN/A
mul-1-negN/A
log-recN/A
mul-1-negN/A
associate-*r*N/A
mul-1-negN/A
log-recN/A
lower-fma.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-log.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f6493.4
Applied rewrites93.4%
if -1.00000000000000004e42 < (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) < 3.5e28Initial program 82.2%
Taylor expanded in y around 0
Applied rewrites99.6%
Taylor expanded in x around 0
Applied rewrites98.0%
Taylor expanded in z around inf
Applied rewrites97.6%
if 3.5e28 < (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) Initial program 98.0%
Taylor expanded in x around inf
*-commutativeN/A
remove-double-negN/A
log-recN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-log.f6498.0
Applied rewrites98.0%
Final simplification96.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t)))
(if (or (<= t_1 -2e+39) (not (<= t_1 3.5e+28)))
(- (* (log y) x) t)
(* (* (fma -0.5 y -1.0) z) y))))
double code(double x, double y, double z, double t) {
double t_1 = (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
double tmp;
if ((t_1 <= -2e+39) || !(t_1 <= 3.5e+28)) {
tmp = (log(y) * x) - t;
} else {
tmp = (fma(-0.5, y, -1.0) * z) * y;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t) tmp = 0.0 if ((t_1 <= -2e+39) || !(t_1 <= 3.5e+28)) tmp = Float64(Float64(log(y) * x) - t); else tmp = Float64(Float64(fma(-0.5, y, -1.0) * z) * y); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+39], N[Not[LessEqual[t$95$1, 3.5e+28]], $MachinePrecision]], N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - t), $MachinePrecision], N[(N[(N[(-0.5 * y + -1.0), $MachinePrecision] * z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+39} \lor \neg \left(t\_1 \leq 3.5 \cdot 10^{+28}\right):\\
\;\;\;\;\log y \cdot x - t\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-0.5, y, -1\right) \cdot z\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) t) < -1.99999999999999988e39 or 3.5e28 < (-.f64 (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) t) Initial program 96.7%
Taylor expanded in x around inf
*-commutativeN/A
remove-double-negN/A
log-recN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-log.f6496.7
Applied rewrites96.7%
if -1.99999999999999988e39 < (-.f64 (+.f64 (*.f64 (-.f64 x #s(literal 1 binary64)) (log.f64 y)) (*.f64 (-.f64 z #s(literal 1 binary64)) (log.f64 (-.f64 #s(literal 1 binary64) y)))) t) < 3.5e28Initial program 66.7%
Taylor expanded in y around 0
Applied rewrites99.1%
Taylor expanded in y around inf
Applied rewrites4.8%
Taylor expanded in z around inf
Applied rewrites33.0%
Final simplification78.8%
(FPCore (x y z t) :precision binary64 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (* (fma (fma -0.3333333333333333 y -0.5) y -1.0) y))) t))
double code(double x, double y, double z, double t) {
return (((x - 1.0) * log(y)) + ((z - 1.0) * (fma(fma(-0.3333333333333333, y, -0.5), y, -1.0) * y))) - t;
}
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * Float64(fma(fma(-0.3333333333333333, y, -0.5), y, -1.0) * y))) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[(N[(N[(-0.3333333333333333 * y + -0.5), $MachinePrecision] * y + -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(-0.3333333333333333, y, -0.5\right), y, -1\right) \cdot y\right)\right) - t
\end{array}
Initial program 88.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6499.7
Applied rewrites99.7%
(FPCore (x y z t) :precision binary64 (fma (* (- z 1.0) y) (fma -0.5 y -1.0) (fma (log y) (- x 1.0) (- t))))
double code(double x, double y, double z, double t) {
return fma(((z - 1.0) * y), fma(-0.5, y, -1.0), fma(log(y), (x - 1.0), -t));
}
function code(x, y, z, t) return fma(Float64(Float64(z - 1.0) * y), fma(-0.5, y, -1.0), fma(log(y), Float64(x - 1.0), Float64(-t))) end
code[x_, y_, z_, t_] := N[(N[(N[(z - 1.0), $MachinePrecision] * y), $MachinePrecision] * N[(-0.5 * y + -1.0), $MachinePrecision] + N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + (-t)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(z - 1\right) \cdot y, \mathsf{fma}\left(-0.5, y, -1\right), \mathsf{fma}\left(\log y, x - 1, -t\right)\right)
\end{array}
Initial program 88.3%
Taylor expanded in y around 0
Applied rewrites99.6%
(FPCore (x y z t) :precision binary64 (fma (- y) (- z 1.0) (fma (log y) (- x 1.0) (- t))))
double code(double x, double y, double z, double t) {
return fma(-y, (z - 1.0), fma(log(y), (x - 1.0), -t));
}
function code(x, y, z, t) return fma(Float64(-y), Float64(z - 1.0), fma(log(y), Float64(x - 1.0), Float64(-t))) end
code[x_, y_, z_, t_] := N[((-y) * N[(z - 1.0), $MachinePrecision] + N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + (-t)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-y, z - 1, \mathsf{fma}\left(\log y, x - 1, -t\right)\right)
\end{array}
Initial program 88.3%
Taylor expanded in y around 0
associate--l+N/A
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-subN/A
remove-double-negN/A
distribute-lft-neg-outN/A
log-recN/A
mul-1-negN/A
log-recN/A
mul-1-negN/A
associate-*r*N/A
mul-1-negN/A
log-recN/A
Applied rewrites99.4%
(FPCore (x y z t) :precision binary64 (if (<= z 1.75e+275) (fma (log y) (- x 1.0) (- t)) (* (* (fma -0.5 y -1.0) z) y)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.75e+275) {
tmp = fma(log(y), (x - 1.0), -t);
} else {
tmp = (fma(-0.5, y, -1.0) * z) * y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 1.75e+275) tmp = fma(log(y), Float64(x - 1.0), Float64(-t)); else tmp = Float64(Float64(fma(-0.5, y, -1.0) * z) * y); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.75e+275], N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + (-t)), $MachinePrecision], N[(N[(N[(-0.5 * y + -1.0), $MachinePrecision] * z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.75 \cdot 10^{+275}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x - 1, -t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-0.5, y, -1\right) \cdot z\right) \cdot y\\
\end{array}
\end{array}
if z < 1.74999999999999997e275Initial program 90.0%
Taylor expanded in y around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-subN/A
remove-double-negN/A
distribute-lft-neg-outN/A
log-recN/A
mul-1-negN/A
log-recN/A
mul-1-negN/A
associate-*r*N/A
mul-1-negN/A
log-recN/A
lower-fma.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-log.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f6489.1
Applied rewrites89.1%
if 1.74999999999999997e275 < z Initial program 2.2%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites6.1%
Taylor expanded in z around inf
Applied rewrites100.0%
(FPCore (x y z t) :precision binary64 (if (or (<= t -1.12e+32) (not (<= t 1.5e+21))) (- t) (* (* (fma -0.5 y -1.0) z) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.12e+32) || !(t <= 1.5e+21)) {
tmp = -t;
} else {
tmp = (fma(-0.5, y, -1.0) * z) * y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -1.12e+32) || !(t <= 1.5e+21)) tmp = Float64(-t); else tmp = Float64(Float64(fma(-0.5, y, -1.0) * z) * y); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.12e+32], N[Not[LessEqual[t, 1.5e+21]], $MachinePrecision]], (-t), N[(N[(N[(-0.5 * y + -1.0), $MachinePrecision] * z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.12 \cdot 10^{+32} \lor \neg \left(t \leq 1.5 \cdot 10^{+21}\right):\\
\;\;\;\;-t\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-0.5, y, -1\right) \cdot z\right) \cdot y\\
\end{array}
\end{array}
if t < -1.12000000000000007e32 or 1.5e21 < t Initial program 99.2%
Taylor expanded in t around inf
mul-1-negN/A
lower-neg.f6472.6
Applied rewrites72.6%
if -1.12000000000000007e32 < t < 1.5e21Initial program 78.0%
Taylor expanded in y around 0
Applied rewrites99.3%
Taylor expanded in y around inf
Applied rewrites3.9%
Taylor expanded in z around inf
Applied rewrites22.4%
Final simplification46.7%
(FPCore (x y z t) :precision binary64 (- t))
double code(double x, double y, double z, double t) {
return -t;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = -t
end function
public static double code(double x, double y, double z, double t) {
return -t;
}
def code(x, y, z, t): return -t
function code(x, y, z, t) return Float64(-t) end
function tmp = code(x, y, z, t) tmp = -t; end
code[x_, y_, z_, t_] := (-t)
\begin{array}{l}
\\
-t
\end{array}
Initial program 88.3%
Taylor expanded in t around inf
mul-1-negN/A
lower-neg.f6436.7
Applied rewrites36.7%
herbie shell --seed 2025008
(FPCore (x y z t)
:name "Statistics.Distribution.Beta:$cdensity from math-functions-0.1.5.2"
:precision binary64
(- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))