
(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 16 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 (fma (- z 1.0) (* (fma (fma (fma -0.25 y -0.3333333333333333) y -0.5) y -1.0) y) (- (* (log y) (- x 1.0)) t)))
double code(double x, double y, double z, double t) {
return fma((z - 1.0), (fma(fma(fma(-0.25, y, -0.3333333333333333), y, -0.5), y, -1.0) * y), ((log(y) * (x - 1.0)) - t));
}
function code(x, y, z, t) return fma(Float64(z - 1.0), Float64(fma(fma(fma(-0.25, y, -0.3333333333333333), y, -0.5), y, -1.0) * y), Float64(Float64(log(y) * Float64(x - 1.0)) - t)) end
code[x_, y_, z_, t_] := N[(N[(z - 1.0), $MachinePrecision] * N[(N[(N[(N[(-0.25 * y + -0.3333333333333333), $MachinePrecision] * y + -0.5), $MachinePrecision] * y + -1.0), $MachinePrecision] * y), $MachinePrecision] + N[(N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - 1, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.25, y, -0.3333333333333333\right), y, -0.5\right), y, -1\right) \cdot y, \log y \cdot \left(x - 1\right) - t\right)
\end{array}
Initial program 91.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.3%
lift--.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate--l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower--.f6499.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
(FPCore (x y z t) :precision binary64 (- (fma (log y) (- x 1.0) (* (fma (* (- z 1.0) (fma -0.3333333333333333 y -0.5)) y (- (- z 1.0))) y)) t))
double code(double x, double y, double z, double t) {
return fma(log(y), (x - 1.0), (fma(((z - 1.0) * fma(-0.3333333333333333, y, -0.5)), y, -(z - 1.0)) * y)) - t;
}
function code(x, y, z, t) return Float64(fma(log(y), Float64(x - 1.0), Float64(fma(Float64(Float64(z - 1.0) * fma(-0.3333333333333333, y, -0.5)), y, Float64(-Float64(z - 1.0))) * y)) - t) end
code[x_, y_, z_, t_] := N[(N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + N[(N[(N[(N[(z - 1.0), $MachinePrecision] * N[(-0.3333333333333333 * y + -0.5), $MachinePrecision]), $MachinePrecision] * y + (-N[(z - 1.0), $MachinePrecision])), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log y, x - 1, \mathsf{fma}\left(\left(z - 1\right) \cdot \mathsf{fma}\left(-0.3333333333333333, y, -0.5\right), y, -\left(z - 1\right)\right) \cdot y\right) - t
\end{array}
Initial program 91.2%
Taylor expanded in y around 0
+-commutativeN/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
Applied rewrites99.3%
(FPCore (x y z t) :precision binary64 (fma (- z 1.0) (* (fma (fma -0.3333333333333333 y -0.5) y -1.0) y) (- (* (log y) (- x 1.0)) t)))
double code(double x, double y, double z, double t) {
return fma((z - 1.0), (fma(fma(-0.3333333333333333, y, -0.5), y, -1.0) * y), ((log(y) * (x - 1.0)) - t));
}
function code(x, y, z, t) return fma(Float64(z - 1.0), Float64(fma(fma(-0.3333333333333333, y, -0.5), y, -1.0) * y), Float64(Float64(log(y) * Float64(x - 1.0)) - t)) end
code[x_, y_, z_, t_] := N[(N[(z - 1.0), $MachinePrecision] * N[(N[(N[(-0.3333333333333333 * y + -0.5), $MachinePrecision] * y + -1.0), $MachinePrecision] * y), $MachinePrecision] + N[(N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - 1, \mathsf{fma}\left(\mathsf{fma}\left(-0.3333333333333333, y, -0.5\right), y, -1\right) \cdot y, \log y \cdot \left(x - 1\right) - t\right)
\end{array}
Initial program 91.2%
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.3
Applied rewrites99.3%
lift--.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate--l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower--.f6499.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
(FPCore (x y z t) :precision binary64 (- (fma (log y) (- x 1.0) (* (* (- z 1.0) y) (fma -0.5 y -1.0))) t))
double code(double x, double y, double z, double t) {
return fma(log(y), (x - 1.0), (((z - 1.0) * y) * fma(-0.5, y, -1.0))) - t;
}
function code(x, y, z, t) return Float64(fma(log(y), Float64(x - 1.0), Float64(Float64(Float64(z - 1.0) * y) * fma(-0.5, y, -1.0))) - t) end
code[x_, y_, z_, t_] := N[(N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + N[(N[(N[(z - 1.0), $MachinePrecision] * y), $MachinePrecision] * N[(-0.5 * y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log y, x - 1, \left(\left(z - 1\right) \cdot y\right) \cdot \mathsf{fma}\left(-0.5, y, -1\right)\right) - t
\end{array}
Initial program 91.2%
Taylor expanded in y around 0
+-commutativeN/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
Applied rewrites99.1%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* (log y) x) t)))
(if (<= x -4.4e+17)
t_1
(if (<= x -2.4e-67)
(- (* (fma (* z (fma -0.3333333333333333 y -0.5)) y (- z)) y) t)
(if (<= x 0.0012) (- (- (log y)) t) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (log(y) * x) - t;
double tmp;
if (x <= -4.4e+17) {
tmp = t_1;
} else if (x <= -2.4e-67) {
tmp = (fma((z * fma(-0.3333333333333333, y, -0.5)), y, -z) * y) - t;
} else if (x <= 0.0012) {
tmp = -log(y) - t;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(log(y) * x) - t) tmp = 0.0 if (x <= -4.4e+17) tmp = t_1; elseif (x <= -2.4e-67) tmp = Float64(Float64(fma(Float64(z * fma(-0.3333333333333333, y, -0.5)), y, Float64(-z)) * y) - t); elseif (x <= 0.0012) tmp = Float64(Float64(-log(y)) - 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]}, If[LessEqual[x, -4.4e+17], t$95$1, If[LessEqual[x, -2.4e-67], N[(N[(N[(N[(z * N[(-0.3333333333333333 * y + -0.5), $MachinePrecision]), $MachinePrecision] * y + (-z)), $MachinePrecision] * y), $MachinePrecision] - t), $MachinePrecision], If[LessEqual[x, 0.0012], N[((-N[Log[y], $MachinePrecision]) - t), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log y \cdot x - t\\
\mathbf{if}\;x \leq -4.4 \cdot 10^{+17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{-67}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \mathsf{fma}\left(-0.3333333333333333, y, -0.5\right), y, -z\right) \cdot y - t\\
\mathbf{elif}\;x \leq 0.0012:\\
\;\;\;\;\left(-\log y\right) - t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -4.4e17 or 0.00119999999999999989 < x Initial program 94.6%
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.f6493.1
Applied rewrites93.1%
if -4.4e17 < x < -2.4e-67Initial program 78.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6473.5
Applied rewrites73.5%
Taylor expanded in y around 0
Applied rewrites95.9%
if -2.4e-67 < x < 0.00119999999999999989Initial program 90.3%
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--.f6488.7
Applied rewrites88.7%
Taylor expanded in x around 0
Applied rewrites88.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (log y) x)))
(if (<= x -1.52e+19)
t_1
(if (<= x -2.4e-67)
(- (* (fma (* z (fma -0.3333333333333333 y -0.5)) y (- z)) y) t)
(if (<= x 1.32e+23) (- (- (log y)) t) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = log(y) * x;
double tmp;
if (x <= -1.52e+19) {
tmp = t_1;
} else if (x <= -2.4e-67) {
tmp = (fma((z * fma(-0.3333333333333333, y, -0.5)), y, -z) * y) - t;
} else if (x <= 1.32e+23) {
tmp = -log(y) - t;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(log(y) * x) tmp = 0.0 if (x <= -1.52e+19) tmp = t_1; elseif (x <= -2.4e-67) tmp = Float64(Float64(fma(Float64(z * fma(-0.3333333333333333, y, -0.5)), y, Float64(-z)) * y) - t); elseif (x <= 1.32e+23) tmp = Float64(Float64(-log(y)) - t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.52e+19], t$95$1, If[LessEqual[x, -2.4e-67], N[(N[(N[(N[(z * N[(-0.3333333333333333 * y + -0.5), $MachinePrecision]), $MachinePrecision] * y + (-z)), $MachinePrecision] * y), $MachinePrecision] - t), $MachinePrecision], If[LessEqual[x, 1.32e+23], N[((-N[Log[y], $MachinePrecision]) - t), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log y \cdot x\\
\mathbf{if}\;x \leq -1.52 \cdot 10^{+19}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{-67}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \mathsf{fma}\left(-0.3333333333333333, y, -0.5\right), y, -z\right) \cdot y - t\\
\mathbf{elif}\;x \leq 1.32 \cdot 10^{+23}:\\
\;\;\;\;\left(-\log y\right) - t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -1.52e19 or 1.3199999999999999e23 < x Initial program 94.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.6%
lift--.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate--l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower--.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f6470.5
Applied rewrites70.5%
if -1.52e19 < x < -2.4e-67Initial program 78.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6473.5
Applied rewrites73.5%
Taylor expanded in y around 0
Applied rewrites95.9%
if -2.4e-67 < x < 1.3199999999999999e23Initial program 90.9%
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--.f6489.4
Applied rewrites89.4%
Taylor expanded in x around 0
Applied rewrites87.1%
(FPCore (x y z t)
:precision binary64
(if (or (<= (- x 1.0) -1e+19) (not (<= (- x 1.0) 1e+50)))
(* (log y) x)
(-
(* (* (- (* (fma (fma -0.25 y -0.3333333333333333) y -0.5) y) 1.0) y) z)
t)))
double code(double x, double y, double z, double t) {
double tmp;
if (((x - 1.0) <= -1e+19) || !((x - 1.0) <= 1e+50)) {
tmp = log(y) * x;
} else {
tmp = ((((fma(fma(-0.25, y, -0.3333333333333333), y, -0.5) * y) - 1.0) * y) * z) - t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((Float64(x - 1.0) <= -1e+19) || !(Float64(x - 1.0) <= 1e+50)) tmp = Float64(log(y) * x); else tmp = Float64(Float64(Float64(Float64(Float64(fma(fma(-0.25, y, -0.3333333333333333), y, -0.5) * y) - 1.0) * y) * z) - t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x - 1.0), $MachinePrecision], -1e+19], N[Not[LessEqual[N[(x - 1.0), $MachinePrecision], 1e+50]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(N[(N[(N[(-0.25 * y + -0.3333333333333333), $MachinePrecision] * y + -0.5), $MachinePrecision] * y), $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision] * z), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - 1 \leq -1 \cdot 10^{+19} \lor \neg \left(x - 1 \leq 10^{+50}\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.25, y, -0.3333333333333333\right), y, -0.5\right) \cdot y - 1\right) \cdot y\right) \cdot z - t\\
\end{array}
\end{array}
if (-.f64 x #s(literal 1 binary64)) < -1e19 or 1.0000000000000001e50 < (-.f64 x #s(literal 1 binary64)) Initial program 94.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.6%
lift--.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate--l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower--.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f6471.9
Applied rewrites71.9%
if -1e19 < (-.f64 x #s(literal 1 binary64)) < 1.0000000000000001e50Initial program 88.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6456.1
Applied rewrites56.1%
Taylor expanded in y around 0
Applied rewrites66.7%
Final simplification68.8%
(FPCore (x y z t)
:precision binary64
(if (<= z -8.2e+205)
(-
(* (* (- (* (fma (fma -0.25 y -0.3333333333333333) y -0.5) y) 1.0) y) z)
t)
(if (<= z 3.6e+229)
(- (* (log y) (- x 1.0)) t)
(- (* (fma (* z (fma -0.3333333333333333 y -0.5)) y (- z)) y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -8.2e+205) {
tmp = ((((fma(fma(-0.25, y, -0.3333333333333333), y, -0.5) * y) - 1.0) * y) * z) - t;
} else if (z <= 3.6e+229) {
tmp = (log(y) * (x - 1.0)) - t;
} else {
tmp = (fma((z * fma(-0.3333333333333333, y, -0.5)), y, -z) * y) - t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -8.2e+205) tmp = Float64(Float64(Float64(Float64(Float64(fma(fma(-0.25, y, -0.3333333333333333), y, -0.5) * y) - 1.0) * y) * z) - t); elseif (z <= 3.6e+229) tmp = Float64(Float64(log(y) * Float64(x - 1.0)) - t); else tmp = Float64(Float64(fma(Float64(z * fma(-0.3333333333333333, y, -0.5)), y, Float64(-z)) * y) - t); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -8.2e+205], N[(N[(N[(N[(N[(N[(N[(-0.25 * y + -0.3333333333333333), $MachinePrecision] * y + -0.5), $MachinePrecision] * y), $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision] * z), $MachinePrecision] - t), $MachinePrecision], If[LessEqual[z, 3.6e+229], N[(N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], N[(N[(N[(N[(z * N[(-0.3333333333333333 * y + -0.5), $MachinePrecision]), $MachinePrecision] * y + (-z)), $MachinePrecision] * y), $MachinePrecision] - t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{+205}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.25, y, -0.3333333333333333\right), y, -0.5\right) \cdot y - 1\right) \cdot y\right) \cdot z - t\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+229}:\\
\;\;\;\;\log y \cdot \left(x - 1\right) - t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \mathsf{fma}\left(-0.3333333333333333, y, -0.5\right), y, -z\right) \cdot y - t\\
\end{array}
\end{array}
if z < -8.2000000000000006e205Initial program 57.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6440.5
Applied rewrites40.5%
Taylor expanded in y around 0
Applied rewrites80.0%
if -8.2000000000000006e205 < z < 3.59999999999999986e229Initial program 96.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--.f6495.8
Applied rewrites95.8%
if 3.59999999999999986e229 < z Initial program 55.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6436.5
Applied rewrites36.5%
Taylor expanded in y around 0
Applied rewrites78.1%
(FPCore (x y z t) :precision binary64 (fma (log y) (- x 1.0) (- (+ (* y (- z 1.0)) t))))
double code(double x, double y, double z, double t) {
return fma(log(y), (x - 1.0), -((y * (z - 1.0)) + t));
}
function code(x, y, z, t) return fma(log(y), Float64(x - 1.0), Float64(-Float64(Float64(y * Float64(z - 1.0)) + t))) end
code[x_, y_, z_, t_] := N[(N[Log[y], $MachinePrecision] * N[(x - 1.0), $MachinePrecision] + (-N[(N[(y * N[(z - 1.0), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log y, x - 1, -\left(y \cdot \left(z - 1\right) + t\right)\right)
\end{array}
Initial program 91.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.3%
Taylor expanded in y around 0
+-commutativeN/A
associate--l+N/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
log-recN/A
lower-fma.f64N/A
log-recN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-log.f64N/A
lower--.f64N/A
lower--.f64N/A
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f6498.8
Applied rewrites98.8%
Final simplification98.8%
(FPCore (x y z t) :precision binary64 (- (* (* (- (* (fma (fma -0.25 y -0.3333333333333333) y -0.5) y) 1.0) y) z) t))
double code(double x, double y, double z, double t) {
return ((((fma(fma(-0.25, y, -0.3333333333333333), y, -0.5) * y) - 1.0) * y) * z) - t;
}
function code(x, y, z, t) return Float64(Float64(Float64(Float64(Float64(fma(fma(-0.25, y, -0.3333333333333333), y, -0.5) * y) - 1.0) * y) * z) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(N[(N[(N[(-0.25 * y + -0.3333333333333333), $MachinePrecision] * y + -0.5), $MachinePrecision] * y), $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision] * z), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.25, y, -0.3333333333333333\right), y, -0.5\right) \cdot y - 1\right) \cdot y\right) \cdot z - t
\end{array}
Initial program 91.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6443.1
Applied rewrites43.1%
Taylor expanded in y around 0
Applied rewrites51.0%
(FPCore (x y z t) :precision binary64 (- (* (fma (* z (fma -0.3333333333333333 y -0.5)) y (- z)) y) t))
double code(double x, double y, double z, double t) {
return (fma((z * fma(-0.3333333333333333, y, -0.5)), y, -z) * y) - t;
}
function code(x, y, z, t) return Float64(Float64(fma(Float64(z * fma(-0.3333333333333333, y, -0.5)), y, Float64(-z)) * y) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(z * N[(-0.3333333333333333 * y + -0.5), $MachinePrecision]), $MachinePrecision] * y + (-z)), $MachinePrecision] * y), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot \mathsf{fma}\left(-0.3333333333333333, y, -0.5\right), y, -z\right) \cdot y - t
\end{array}
Initial program 91.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6443.1
Applied rewrites43.1%
Taylor expanded in y around 0
Applied rewrites51.0%
(FPCore (x y z t) :precision binary64 (- (fma (* (* -0.5 y) z) y (* (- z) y)) t))
double code(double x, double y, double z, double t) {
return fma(((-0.5 * y) * z), y, (-z * y)) - t;
}
function code(x, y, z, t) return Float64(fma(Float64(Float64(-0.5 * y) * z), y, Float64(Float64(-z) * y)) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(-0.5 * y), $MachinePrecision] * z), $MachinePrecision] * y + N[((-z) * y), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(-0.5 \cdot y\right) \cdot z, y, \left(-z\right) \cdot y\right) - t
\end{array}
Initial program 91.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6443.1
Applied rewrites43.1%
Taylor expanded in y around 0
Applied rewrites50.8%
Applied rewrites50.8%
(FPCore (x y z t) :precision binary64 (if (or (<= t -16500000000.0) (not (<= t 7.4e-10))) (- t) (* (- 1.0 z) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -16500000000.0) || !(t <= 7.4e-10)) {
tmp = -t;
} else {
tmp = (1.0 - z) * y;
}
return tmp;
}
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
real(8) :: tmp
if ((t <= (-16500000000.0d0)) .or. (.not. (t <= 7.4d-10))) then
tmp = -t
else
tmp = (1.0d0 - z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -16500000000.0) || !(t <= 7.4e-10)) {
tmp = -t;
} else {
tmp = (1.0 - z) * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -16500000000.0) or not (t <= 7.4e-10): tmp = -t else: tmp = (1.0 - z) * y return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -16500000000.0) || !(t <= 7.4e-10)) tmp = Float64(-t); else tmp = Float64(Float64(1.0 - z) * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -16500000000.0) || ~((t <= 7.4e-10))) tmp = -t; else tmp = (1.0 - z) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -16500000000.0], N[Not[LessEqual[t, 7.4e-10]], $MachinePrecision]], (-t), N[(N[(1.0 - z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -16500000000 \lor \neg \left(t \leq 7.4 \cdot 10^{-10}\right):\\
\;\;\;\;-t\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot y\\
\end{array}
\end{array}
if t < -1.65e10 or 7.4000000000000003e-10 < t Initial program 97.8%
Taylor expanded in t around inf
mul-1-negN/A
lower-neg.f6476.5
Applied rewrites76.5%
if -1.65e10 < t < 7.4000000000000003e-10Initial program 83.6%
Taylor expanded in t around inf
Applied rewrites62.3%
Taylor expanded in y around 0
Applied rewrites76.8%
Taylor expanded in y around inf
Applied rewrites72.1%
Taylor expanded in y around inf
Applied rewrites19.3%
Final simplification49.7%
(FPCore (x y z t) :precision binary64 (- (* (* z (fma -0.5 y -1.0)) y) t))
double code(double x, double y, double z, double t) {
return ((z * fma(-0.5, y, -1.0)) * y) - t;
}
function code(x, y, z, t) return Float64(Float64(Float64(z * fma(-0.5, y, -1.0)) * y) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(z * N[(-0.5 * y + -1.0), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(z \cdot \mathsf{fma}\left(-0.5, y, -1\right)\right) \cdot y - t
\end{array}
Initial program 91.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6443.1
Applied rewrites43.1%
Taylor expanded in y around 0
Applied rewrites50.8%
(FPCore (x y z t) :precision binary64 (- (* (- y) z) t))
double code(double x, double y, double z, double t) {
return (-y * z) - 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 = (-y * z) - t
end function
public static double code(double x, double y, double z, double t) {
return (-y * z) - t;
}
def code(x, y, z, t): return (-y * z) - t
function code(x, y, z, t) return Float64(Float64(Float64(-y) * z) - t) end
function tmp = code(x, y, z, t) tmp = (-y * z) - t; end
code[x_, y_, z_, t_] := N[(N[((-y) * z), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(-y\right) \cdot z - t
\end{array}
Initial program 91.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower--.f6443.1
Applied rewrites43.1%
Taylor expanded in y around 0
Applied rewrites50.6%
(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 91.2%
Taylor expanded in t around inf
mul-1-negN/A
lower-neg.f6442.1
Applied rewrites42.1%
Final simplification42.1%
herbie shell --seed 2025015
(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))