
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - 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, 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 + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - 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, 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 + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - 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, 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 + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
Initial program 100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -4.1e+16)
t_1
(if (<= y -1.25e-121)
(* (- x t) z)
(if (<= y 4.7e+53) (fma (- t) z x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -4.1e+16) {
tmp = t_1;
} else if (y <= -1.25e-121) {
tmp = (x - t) * z;
} else if (y <= 4.7e+53) {
tmp = fma(-t, z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) tmp = 0.0 if (y <= -4.1e+16) tmp = t_1; elseif (y <= -1.25e-121) tmp = Float64(Float64(x - t) * z); elseif (y <= 4.7e+53) tmp = fma(Float64(-t), z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -4.1e+16], t$95$1, If[LessEqual[y, -1.25e-121], N[(N[(x - t), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 4.7e+53], N[((-t) * z + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -4.1 \cdot 10^{+16}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-121}:\\
\;\;\;\;\left(x - t\right) \cdot z\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+53}:\\
\;\;\;\;\mathsf{fma}\left(-t, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.1e16 or 4.69999999999999976e53 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.3
Applied rewrites86.3%
if -4.1e16 < y < -1.24999999999999997e-121Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f6482.7
Applied rewrites82.7%
Taylor expanded in z around inf
Applied rewrites63.0%
if -1.24999999999999997e-121 < y < 4.69999999999999976e53Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f6489.0
Applied rewrites89.0%
Taylor expanded in x around 0
Applied rewrites72.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -4.1e+16)
t_1
(if (<= y 1.04e-94)
(* (- x t) z)
(if (<= y 5.9e+53) (* (- y z) t) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -4.1e+16) {
tmp = t_1;
} else if (y <= 1.04e-94) {
tmp = (x - t) * z;
} else if (y <= 5.9e+53) {
tmp = (y - z) * t;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = (t - x) * y
if (y <= (-4.1d+16)) then
tmp = t_1
else if (y <= 1.04d-94) then
tmp = (x - t) * z
else if (y <= 5.9d+53) then
tmp = (y - z) * t
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -4.1e+16) {
tmp = t_1;
} else if (y <= 1.04e-94) {
tmp = (x - t) * z;
} else if (y <= 5.9e+53) {
tmp = (y - z) * t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (t - x) * y tmp = 0 if y <= -4.1e+16: tmp = t_1 elif y <= 1.04e-94: tmp = (x - t) * z elif y <= 5.9e+53: tmp = (y - z) * t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) tmp = 0.0 if (y <= -4.1e+16) tmp = t_1; elseif (y <= 1.04e-94) tmp = Float64(Float64(x - t) * z); elseif (y <= 5.9e+53) tmp = Float64(Float64(y - z) * t); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (t - x) * y; tmp = 0.0; if (y <= -4.1e+16) tmp = t_1; elseif (y <= 1.04e-94) tmp = (x - t) * z; elseif (y <= 5.9e+53) tmp = (y - z) * t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -4.1e+16], t$95$1, If[LessEqual[y, 1.04e-94], N[(N[(x - t), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 5.9e+53], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -4.1 \cdot 10^{+16}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.04 \cdot 10^{-94}:\\
\;\;\;\;\left(x - t\right) \cdot z\\
\mathbf{elif}\;y \leq 5.9 \cdot 10^{+53}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.1e16 or 5.8999999999999997e53 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.3
Applied rewrites86.3%
if -4.1e16 < y < 1.04e-94Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f6491.5
Applied rewrites91.5%
Taylor expanded in z around inf
Applied rewrites63.2%
if 1.04e-94 < y < 5.8999999999999997e53Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6466.6
Applied rewrites66.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- x t) z)))
(if (<= z -800.0)
t_1
(if (<= z -1.35e-137) (* t y) (if (<= z 3e-59) (fma x z x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (x - t) * z;
double tmp;
if (z <= -800.0) {
tmp = t_1;
} else if (z <= -1.35e-137) {
tmp = t * y;
} else if (z <= 3e-59) {
tmp = fma(x, z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x - t) * z) tmp = 0.0 if (z <= -800.0) tmp = t_1; elseif (z <= -1.35e-137) tmp = Float64(t * y); elseif (z <= 3e-59) tmp = fma(x, z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x - t), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -800.0], t$95$1, If[LessEqual[z, -1.35e-137], N[(t * y), $MachinePrecision], If[LessEqual[z, 3e-59], N[(x * z + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x - t\right) \cdot z\\
\mathbf{if}\;z \leq -800:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-137}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-59}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -800 or 3.0000000000000001e-59 < z Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f6477.9
Applied rewrites77.9%
Taylor expanded in z around inf
Applied rewrites75.7%
if -800 < z < -1.34999999999999996e-137Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6462.9
Applied rewrites62.9%
Taylor expanded in x around 0
Applied rewrites39.4%
if -1.34999999999999996e-137 < z < 3.0000000000000001e-59Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
distribute-lft-out--N/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6466.9
Applied rewrites66.9%
Taylor expanded in y around 0
Applied rewrites41.3%
(FPCore (x y z t) :precision binary64 (if (<= y -1.95e+236) (* (- x) y) (if (or (<= y -1.6e+39) (not (<= y 5e-31))) (* t y) (fma x z x))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.95e+236) {
tmp = -x * y;
} else if ((y <= -1.6e+39) || !(y <= 5e-31)) {
tmp = t * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -1.95e+236) tmp = Float64(Float64(-x) * y); elseif ((y <= -1.6e+39) || !(y <= 5e-31)) tmp = Float64(t * y); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.95e+236], N[((-x) * y), $MachinePrecision], If[Or[LessEqual[y, -1.6e+39], N[Not[LessEqual[y, 5e-31]], $MachinePrecision]], N[(t * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+236}:\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{+39} \lor \neg \left(y \leq 5 \cdot 10^{-31}\right):\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -1.95e236Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6496.0
Applied rewrites96.0%
Taylor expanded in x around inf
Applied rewrites82.7%
if -1.95e236 < y < -1.59999999999999996e39 or 5e-31 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.8
Applied rewrites76.8%
Taylor expanded in x around 0
Applied rewrites51.0%
if -1.59999999999999996e39 < y < 5e-31Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
distribute-lft-out--N/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6457.8
Applied rewrites57.8%
Taylor expanded in y around 0
Applied rewrites55.2%
Final simplification55.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.1e+16) (not (<= y 2.7e+54))) (* (- t x) y) (fma (- x t) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.1e+16) || !(y <= 2.7e+54)) {
tmp = (t - x) * y;
} else {
tmp = fma((x - t), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.1e+16) || !(y <= 2.7e+54)) tmp = Float64(Float64(t - x) * y); else tmp = fma(Float64(x - t), z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.1e+16], N[Not[LessEqual[y, 2.7e+54]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(N[(x - t), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+16} \lor \neg \left(y \leq 2.7 \cdot 10^{+54}\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - t, z, x\right)\\
\end{array}
\end{array}
if y < -4.1e16 or 2.70000000000000011e54 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.3
Applied rewrites86.3%
if -4.1e16 < y < 2.70000000000000011e54Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f6487.3
Applied rewrites87.3%
Final simplification86.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.1e+16) (not (<= y 2.7e+54))) (* (- t x) y) (* (- x t) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.1e+16) || !(y <= 2.7e+54)) {
tmp = (t - x) * y;
} else {
tmp = (x - t) * 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, 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 ((y <= (-4.1d+16)) .or. (.not. (y <= 2.7d+54))) then
tmp = (t - x) * y
else
tmp = (x - t) * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.1e+16) || !(y <= 2.7e+54)) {
tmp = (t - x) * y;
} else {
tmp = (x - t) * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.1e+16) or not (y <= 2.7e+54): tmp = (t - x) * y else: tmp = (x - t) * z return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.1e+16) || !(y <= 2.7e+54)) tmp = Float64(Float64(t - x) * y); else tmp = Float64(Float64(x - t) * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4.1e+16) || ~((y <= 2.7e+54))) tmp = (t - x) * y; else tmp = (x - t) * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.1e+16], N[Not[LessEqual[y, 2.7e+54]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(N[(x - t), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+16} \lor \neg \left(y \leq 2.7 \cdot 10^{+54}\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(x - t\right) \cdot z\\
\end{array}
\end{array}
if y < -4.1e16 or 2.70000000000000011e54 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.3
Applied rewrites86.3%
if -4.1e16 < y < 2.70000000000000011e54Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
metadata-evalN/A
distribute-lft-out--N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f6487.3
Applied rewrites87.3%
Taylor expanded in z around inf
Applied rewrites59.8%
Final simplification71.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.6e+39) (not (<= y 5e-31))) (* t y) (fma x z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.6e+39) || !(y <= 5e-31)) {
tmp = t * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.6e+39) || !(y <= 5e-31)) tmp = Float64(t * y); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.6e+39], N[Not[LessEqual[y, 5e-31]], $MachinePrecision]], N[(t * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+39} \lor \neg \left(y \leq 5 \cdot 10^{-31}\right):\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -1.59999999999999996e39 or 5e-31 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.1
Applied rewrites80.1%
Taylor expanded in x around 0
Applied rewrites45.6%
if -1.59999999999999996e39 < y < 5e-31Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
distribute-lft-out--N/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6457.8
Applied rewrites57.8%
Taylor expanded in y around 0
Applied rewrites55.2%
Final simplification50.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.55e+44) (not (<= z 5e+38))) (* x z) (* t y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.55e+44) || !(z <= 5e+38)) {
tmp = x * z;
} else {
tmp = t * 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 ((z <= (-1.55d+44)) .or. (.not. (z <= 5d+38))) then
tmp = x * z
else
tmp = 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.55e+44) || !(z <= 5e+38)) {
tmp = x * z;
} else {
tmp = t * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.55e+44) or not (z <= 5e+38): tmp = x * z else: tmp = t * y return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.55e+44) || !(z <= 5e+38)) tmp = Float64(x * z); else tmp = Float64(t * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.55e+44) || ~((z <= 5e+38))) tmp = x * z; else tmp = t * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.55e+44], N[Not[LessEqual[z, 5e+38]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(t * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+44} \lor \neg \left(z \leq 5 \cdot 10^{+38}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t \cdot y\\
\end{array}
\end{array}
if z < -1.54999999999999998e44 or 4.9999999999999997e38 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
mul-1-negN/A
distribute-lft-out--N/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
remove-double-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower--.f6453.6
Applied rewrites53.6%
Taylor expanded in z around inf
Applied rewrites44.4%
if -1.54999999999999998e44 < z < 4.9999999999999997e38Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6457.5
Applied rewrites57.5%
Taylor expanded in x around 0
Applied rewrites35.0%
Final simplification39.1%
(FPCore (x y z t) :precision binary64 (* t y))
double code(double x, double y, double z, double t) {
return t * y;
}
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 * y
end function
public static double code(double x, double y, double z, double t) {
return t * y;
}
def code(x, y, z, t): return t * y
function code(x, y, z, t) return Float64(t * y) end
function tmp = code(x, y, z, t) tmp = t * y; end
code[x_, y_, z_, t_] := N[(t * y), $MachinePrecision]
\begin{array}{l}
\\
t \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6445.9
Applied rewrites45.9%
Taylor expanded in x around 0
Applied rewrites27.9%
(FPCore (x y z t) :precision binary64 (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - 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, 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 + ((t * (y - z)) + (-x * (y - z)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
def code(x, y, z, t): return x + ((t * (y - z)) + (-x * (y - z)))
function code(x, y, z, t) return Float64(x + Float64(Float64(t * Float64(y - z)) + Float64(Float64(-x) * Float64(y - z)))) end
function tmp = code(x, y, z, t) tmp = x + ((t * (y - z)) + (-x * (y - z))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision] + N[((-x) * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right)
\end{array}
herbie shell --seed 2024364
(FPCore (x y z t)
:name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
(+ x (* (- y z) (- t x))))