
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + log(z)));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z): return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z)))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * ((1.0 - z) + log(z))); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + log(z)));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z): return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z)))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * ((1.0 - z) + log(z))); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (* (expm1 (- (log z))) z) y (fma (log z) y (* 0.5 x))))
double code(double x, double y, double z) {
return fma((expm1(-log(z)) * z), y, fma(log(z), y, (0.5 * x)));
}
function code(x, y, z) return fma(Float64(expm1(Float64(-log(z))) * z), y, fma(log(z), y, Float64(0.5 * x))) end
code[x_, y_, z_] := N[(N[(N[(Exp[(-N[Log[z], $MachinePrecision])] - 1), $MachinePrecision] * z), $MachinePrecision] * y + N[(N[Log[z], $MachinePrecision] * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{expm1}\left(-\log z\right) \cdot z, y, \mathsf{fma}\left(\log z, y, 0.5 \cdot x\right)\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-log.f64N/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
lower-expm1.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-log.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z 1e-217) (not (or (<= z 8.2e-131) (not (<= z 1.6e-8))))) (fma (log z) y y) (fma (- z) y (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 1e-217) || !((z <= 8.2e-131) || !(z <= 1.6e-8))) {
tmp = fma(log(z), y, y);
} else {
tmp = fma(-z, y, (0.5 * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= 1e-217) || !((z <= 8.2e-131) || !(z <= 1.6e-8))) tmp = fma(log(z), y, y); else tmp = fma(Float64(-z), y, Float64(0.5 * x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, 1e-217], N[Not[Or[LessEqual[z, 8.2e-131], N[Not[LessEqual[z, 1.6e-8]], $MachinePrecision]]], $MachinePrecision]], N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision], N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 10^{-217} \lor \neg \left(z \leq 8.2 \cdot 10^{-131} \lor \neg \left(z \leq 1.6 \cdot 10^{-8}\right)\right):\\
\;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\
\end{array}
\end{array}
if z < 1.00000000000000008e-217 or 8.2000000000000004e-131 < z < 1.6000000000000001e-8Initial program 99.8%
Taylor expanded in z around 0
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lift-log.f6498.9
Applied rewrites98.9%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
lift-fma.f64N/A
lift-log.f6463.5
Applied rewrites63.5%
if 1.00000000000000008e-217 < z < 8.2000000000000004e-131 or 1.6000000000000001e-8 < z Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-log.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
associate-+r-N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6492.7
Applied rewrites92.7%
Final simplification81.9%
(FPCore (x y z)
:precision binary64
(if (<= z 1e-217)
(+ (* (log z) y) y)
(if (or (<= z 8.2e-131) (not (<= z 1.6e-8)))
(fma (- z) y (* 0.5 x))
(fma (log z) y y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1e-217) {
tmp = (log(z) * y) + y;
} else if ((z <= 8.2e-131) || !(z <= 1.6e-8)) {
tmp = fma(-z, y, (0.5 * x));
} else {
tmp = fma(log(z), y, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 1e-217) tmp = Float64(Float64(log(z) * y) + y); elseif ((z <= 8.2e-131) || !(z <= 1.6e-8)) tmp = fma(Float64(-z), y, Float64(0.5 * x)); else tmp = fma(log(z), y, y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 1e-217], N[(N[(N[Log[z], $MachinePrecision] * y), $MachinePrecision] + y), $MachinePrecision], If[Or[LessEqual[z, 8.2e-131], N[Not[LessEqual[z, 1.6e-8]], $MachinePrecision]], N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 10^{-217}:\\
\;\;\;\;\log z \cdot y + y\\
\mathbf{elif}\;z \leq 8.2 \cdot 10^{-131} \lor \neg \left(z \leq 1.6 \cdot 10^{-8}\right):\\
\;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\
\end{array}
\end{array}
if z < 1.00000000000000008e-217Initial program 99.9%
Taylor expanded in z around 0
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lift-log.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
lift-fma.f64N/A
lift-log.f6461.2
Applied rewrites61.2%
lift-log.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-log.f6461.3
Applied rewrites61.3%
if 1.00000000000000008e-217 < z < 8.2000000000000004e-131 or 1.6000000000000001e-8 < z Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-log.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
associate-+r-N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6492.7
Applied rewrites92.7%
if 8.2000000000000004e-131 < z < 1.6000000000000001e-8Initial program 99.7%
Taylor expanded in z around 0
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lift-log.f6498.0
Applied rewrites98.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
lift-fma.f64N/A
lift-log.f6465.4
Applied rewrites65.4%
Final simplification81.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e+23) (not (<= y 2.6e+61))) (* (- (- (log z) -1.0) z) y) (fma (- z) y (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+23) || !(y <= 2.6e+61)) {
tmp = ((log(z) - -1.0) - z) * y;
} else {
tmp = fma(-z, y, (0.5 * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e+23) || !(y <= 2.6e+61)) tmp = Float64(Float64(Float64(log(z) - -1.0) - z) * y); else tmp = fma(Float64(-z), y, Float64(0.5 * x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+23], N[Not[LessEqual[y, 2.6e+61]], $MachinePrecision]], N[(N[(N[(N[Log[z], $MachinePrecision] - -1.0), $MachinePrecision] - z), $MachinePrecision] * y), $MachinePrecision], N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+23} \lor \neg \left(y \leq 2.6 \cdot 10^{+61}\right):\\
\;\;\;\;\left(\left(\log z - -1\right) - z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\
\end{array}
\end{array}
if y < -2.5e23 or 2.59999999999999973e61 < y Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lift-log.f6487.9
Applied rewrites87.9%
if -2.5e23 < y < 2.59999999999999973e61Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-log.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
associate-+r-N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.9%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6487.7
Applied rewrites87.7%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (<= z 0.0068) (fma 0.5 x (fma (log z) y y)) (fma (- 1.0 z) y (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.0068) {
tmp = fma(0.5, x, fma(log(z), y, y));
} else {
tmp = fma((1.0 - z), y, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 0.0068) tmp = fma(0.5, x, fma(log(z), y, y)); else tmp = fma(Float64(1.0 - z), y, Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 0.0068], N[(0.5 * x + N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - z), $MachinePrecision] * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.0068:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1 - z, y, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 0.00679999999999999962Initial program 99.8%
Taylor expanded in z around 0
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lift-log.f6498.7
Applied rewrites98.7%
if 0.00679999999999999962 < z Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-log.f64N/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-log.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
(FPCore (x y z) :precision binary64 (fma (- (- (log z) -1.0) z) y (* 0.5 x)))
double code(double x, double y, double z) {
return fma(((log(z) - -1.0) - z), y, (0.5 * x));
}
function code(x, y, z) return fma(Float64(Float64(log(z) - -1.0) - z), y, Float64(0.5 * x)) end
code[x_, y_, z_] := N[(N[(N[(N[Log[z], $MachinePrecision] - -1.0), $MachinePrecision] - z), $MachinePrecision] * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\log z - -1\right) - z, y, 0.5 \cdot x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-log.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
associate-+r-N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (<= z 5.2e+53) (* 0.5 x) (* (- y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 5.2e+53) {
tmp = 0.5 * x;
} else {
tmp = -y * z;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= 5.2d+53) then
tmp = 0.5d0 * x
else
tmp = -y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 5.2e+53) {
tmp = 0.5 * x;
} else {
tmp = -y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5.2e+53: tmp = 0.5 * x else: tmp = -y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5.2e+53) tmp = Float64(0.5 * x); else tmp = Float64(Float64(-y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 5.2e+53) tmp = 0.5 * x; else tmp = -y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5.2e+53], N[(0.5 * x), $MachinePrecision], N[((-y) * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.2 \cdot 10^{+53}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot z\\
\end{array}
\end{array}
if z < 5.19999999999999996e53Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6446.9
Applied rewrites46.9%
if 5.19999999999999996e53 < z Initial program 100.0%
Taylor expanded in z around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6478.9
Applied rewrites78.9%
(FPCore (x y z) :precision binary64 (fma (- z) y (* 0.5 x)))
double code(double x, double y, double z) {
return fma(-z, y, (0.5 * x));
}
function code(x, y, z) return fma(Float64(-z), y, Float64(0.5 * x)) end
code[x_, y_, z_] := N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-log.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
associate-+r-N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.9%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6472.4
Applied rewrites72.4%
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
return 0.5 * x;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
return 0.5 * x;
}
def code(x, y, z): return 0.5 * x
function code(x, y, z) return Float64(0.5 * x) end
function tmp = code(x, y, z) tmp = 0.5 * x; end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6437.1
Applied rewrites37.1%
(FPCore (x y z) :precision binary64 (- (+ y (* 0.5 x)) (* y (- z (log z)))))
double code(double x, double y, double z) {
return (y + (0.5 * x)) - (y * (z - log(z)));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (0.5d0 * x)) - (y * (z - log(z)))
end function
public static double code(double x, double y, double z) {
return (y + (0.5 * x)) - (y * (z - Math.log(z)));
}
def code(x, y, z): return (y + (0.5 * x)) - (y * (z - math.log(z)))
function code(x, y, z) return Float64(Float64(y + Float64(0.5 * x)) - Float64(y * Float64(z - log(z)))) end
function tmp = code(x, y, z) tmp = (y + (0.5 * x)) - (y * (z - log(z))); end
code[x_, y_, z_] := N[(N[(y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision] - N[(y * N[(z - N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + 0.5 \cdot x\right) - y \cdot \left(z - \log z\right)
\end{array}
herbie shell --seed 2025064
(FPCore (x y z)
:name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
:precision binary64
:alt
(! :herbie-platform default (- (+ y (* 1/2 x)) (* y (- z (log z)))))
(+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))