
(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 11 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 (fma (- y z) (- t x) x))
double code(double x, double y, double z, double t) {
return fma((y - z), (t - x), x);
}
function code(x, y, z, t) return fma(Float64(y - z), Float64(t - x), x) end
code[x_, y_, z_, t_] := N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - z, t - x, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- x t) z)))
(if (<= z -2.1e+79)
t_1
(if (<= z -2.4e-20)
(* (- y z) t)
(if (<= z 6e-154) (fma t y x) (if (<= z 1e+34) (* (- t x) y) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = (x - t) * z;
double tmp;
if (z <= -2.1e+79) {
tmp = t_1;
} else if (z <= -2.4e-20) {
tmp = (y - z) * t;
} else if (z <= 6e-154) {
tmp = fma(t, y, x);
} else if (z <= 1e+34) {
tmp = (t - x) * y;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x - t) * z) tmp = 0.0 if (z <= -2.1e+79) tmp = t_1; elseif (z <= -2.4e-20) tmp = Float64(Float64(y - z) * t); elseif (z <= 6e-154) tmp = fma(t, y, x); elseif (z <= 1e+34) tmp = Float64(Float64(t - x) * y); 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, -2.1e+79], t$95$1, If[LessEqual[z, -2.4e-20], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[z, 6e-154], N[(t * y + x), $MachinePrecision], If[LessEqual[z, 1e+34], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x - t\right) \cdot z\\
\mathbf{if}\;z \leq -2.1 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -2.4 \cdot 10^{-20}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-154}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\mathbf{elif}\;z \leq 10^{+34}:\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -2.10000000000000008e79 or 9.99999999999999946e33 < z Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
lower--.f6484.2
Applied rewrites84.2%
if -2.10000000000000008e79 < z < -2.39999999999999993e-20Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6478.6
Applied rewrites78.6%
if -2.39999999999999993e-20 < z < 6.0000000000000005e-154Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6495.0
Applied rewrites95.0%
Taylor expanded in x around 0
Applied rewrites73.9%
if 6.0000000000000005e-154 < z < 9.99999999999999946e33Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6471.8
Applied rewrites71.8%
Final simplification78.3%
(FPCore (x y z t)
:precision binary64
(if (<= z -2.15e+79)
(* x z)
(if (<= z -3.8e-141)
(* t y)
(if (<= z -4.55e-243) x (if (<= z 1.9e+54) (* t y) (* x z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.15e+79) {
tmp = x * z;
} else if (z <= -3.8e-141) {
tmp = t * y;
} else if (z <= -4.55e-243) {
tmp = x;
} else if (z <= 1.9e+54) {
tmp = t * y;
} else {
tmp = x * 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 (z <= (-2.15d+79)) then
tmp = x * z
else if (z <= (-3.8d-141)) then
tmp = t * y
else if (z <= (-4.55d-243)) then
tmp = x
else if (z <= 1.9d+54) then
tmp = t * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.15e+79) {
tmp = x * z;
} else if (z <= -3.8e-141) {
tmp = t * y;
} else if (z <= -4.55e-243) {
tmp = x;
} else if (z <= 1.9e+54) {
tmp = t * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.15e+79: tmp = x * z elif z <= -3.8e-141: tmp = t * y elif z <= -4.55e-243: tmp = x elif z <= 1.9e+54: tmp = t * y else: tmp = x * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.15e+79) tmp = Float64(x * z); elseif (z <= -3.8e-141) tmp = Float64(t * y); elseif (z <= -4.55e-243) tmp = x; elseif (z <= 1.9e+54) tmp = Float64(t * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -2.15e+79) tmp = x * z; elseif (z <= -3.8e-141) tmp = t * y; elseif (z <= -4.55e-243) tmp = x; elseif (z <= 1.9e+54) tmp = t * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.15e+79], N[(x * z), $MachinePrecision], If[LessEqual[z, -3.8e-141], N[(t * y), $MachinePrecision], If[LessEqual[z, -4.55e-243], x, If[LessEqual[z, 1.9e+54], N[(t * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{+79}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -3.8 \cdot 10^{-141}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;z \leq -4.55 \cdot 10^{-243}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{+54}:\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -2.1500000000000002e79 or 1.9000000000000001e54 < z Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
lower--.f6485.0
Applied rewrites85.0%
Taylor expanded in x around inf
Applied rewrites49.5%
if -2.1500000000000002e79 < z < -3.79999999999999987e-141 or -4.55000000000000009e-243 < z < 1.9000000000000001e54Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.6
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites40.1%
if -3.79999999999999987e-141 < z < -4.55000000000000009e-243Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6466.8
Applied rewrites66.8%
Taylor expanded in z around 0
Applied rewrites62.7%
Final simplification46.1%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- x t) z)))
(if (<= z -2.1e+79)
t_1
(if (<= z -1.35e-10)
(* (- y z) t)
(if (<= z 1e+34) (fma (- t x) y x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (x - t) * z;
double tmp;
if (z <= -2.1e+79) {
tmp = t_1;
} else if (z <= -1.35e-10) {
tmp = (y - z) * t;
} else if (z <= 1e+34) {
tmp = fma((t - x), y, 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 <= -2.1e+79) tmp = t_1; elseif (z <= -1.35e-10) tmp = Float64(Float64(y - z) * t); elseif (z <= 1e+34) tmp = fma(Float64(t - x), y, 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, -2.1e+79], t$95$1, If[LessEqual[z, -1.35e-10], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[z, 1e+34], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x - t\right) \cdot z\\
\mathbf{if}\;z \leq -2.1 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-10}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{elif}\;z \leq 10^{+34}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -2.10000000000000008e79 or 9.99999999999999946e33 < z Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
lower--.f6484.2
Applied rewrites84.2%
if -2.10000000000000008e79 < z < -1.35e-10Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6481.8
Applied rewrites81.8%
if -1.35e-10 < z < 9.99999999999999946e33Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6492.5
Applied rewrites92.5%
Final simplification88.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -1.2e+40)
t_1
(if (<= y -1.05e-19) (* (- y z) t) (if (<= y 6.5e+32) (fma x z x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -1.2e+40) {
tmp = t_1;
} else if (y <= -1.05e-19) {
tmp = (y - z) * t;
} else if (y <= 6.5e+32) {
tmp = fma(x, 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 <= -1.2e+40) tmp = t_1; elseif (y <= -1.05e-19) tmp = Float64(Float64(y - z) * t); elseif (y <= 6.5e+32) tmp = fma(x, 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, -1.2e+40], t$95$1, If[LessEqual[y, -1.05e-19], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[y, 6.5e+32], N[(x * z + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -1.2 \cdot 10^{+40}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -1.05 \cdot 10^{-19}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+32}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.2e40 or 6.4999999999999994e32 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.7
Applied rewrites82.7%
if -1.2e40 < y < -1.0499999999999999e-19Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.4
Applied rewrites82.4%
if -1.0499999999999999e-19 < y < 6.4999999999999994e32Initial program 99.9%
Taylor expanded in y around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6490.7
Applied rewrites90.7%
Taylor expanded in x around inf
distribute-rgt-out--N/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sign-subN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f6461.5
Applied rewrites61.5%
Final simplification72.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.9e+38) (not (<= y 1.85e-16))) (* (- t x) y) (- x (* t z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.9e+38) || !(y <= 1.85e-16)) {
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 <= (-2.9d+38)) .or. (.not. (y <= 1.85d-16))) 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 <= -2.9e+38) || !(y <= 1.85e-16)) {
tmp = (t - x) * y;
} else {
tmp = x - (t * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.9e+38) or not (y <= 1.85e-16): tmp = (t - x) * y else: tmp = x - (t * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.9e+38) || !(y <= 1.85e-16)) tmp = Float64(Float64(t - x) * y); else tmp = Float64(x - Float64(t * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -2.9e+38) || ~((y <= 1.85e-16))) tmp = (t - x) * y; else tmp = x - (t * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.9e+38], N[Not[LessEqual[y, 1.85e-16]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(x - N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+38} \lor \neg \left(y \leq 1.85 \cdot 10^{-16}\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x - t \cdot z\\
\end{array}
\end{array}
if y < -2.90000000000000007e38 or 1.85e-16 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6479.4
Applied rewrites79.4%
if -2.90000000000000007e38 < y < 1.85e-16Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.3
Applied rewrites91.3%
Taylor expanded in x around 0
Applied rewrites68.1%
Final simplification73.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.32e-18) (not (<= y 6.5e+32))) (* (- t x) y) (fma x z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.32e-18) || !(y <= 6.5e+32)) {
tmp = (t - x) * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.32e-18) || !(y <= 6.5e+32)) tmp = Float64(Float64(t - x) * y); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.32e-18], N[Not[LessEqual[y, 6.5e+32]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.32 \cdot 10^{-18} \lor \neg \left(y \leq 6.5 \cdot 10^{+32}\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -1.3199999999999999e-18 or 6.4999999999999994e32 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6478.4
Applied rewrites78.4%
if -1.3199999999999999e-18 < y < 6.4999999999999994e32Initial program 99.9%
Taylor expanded in y around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6490.7
Applied rewrites90.7%
Taylor expanded in x around inf
distribute-rgt-out--N/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sign-subN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f6461.5
Applied rewrites61.5%
Final simplification70.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.15e+79) (not (<= z 3e+54))) (* x z) (fma t y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.15e+79) || !(z <= 3e+54)) {
tmp = x * z;
} else {
tmp = fma(t, y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.15e+79) || !(z <= 3e+54)) tmp = Float64(x * z); else tmp = fma(t, y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.15e+79], N[Not[LessEqual[z, 3e+54]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(t * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{+79} \lor \neg \left(z \leq 3 \cdot 10^{+54}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\end{array}
\end{array}
if z < -2.1500000000000002e79 or 2.9999999999999999e54 < z Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
lower--.f6485.0
Applied rewrites85.0%
Taylor expanded in x around inf
Applied rewrites49.5%
if -2.1500000000000002e79 < z < 2.9999999999999999e54Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6486.1
Applied rewrites86.1%
Taylor expanded in x around 0
Applied rewrites63.8%
Final simplification58.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -5.5e+56) (not (<= y 7.5e+35))) (* t y) (fma x z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.5e+56) || !(y <= 7.5e+35)) {
tmp = t * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.5e+56) || !(y <= 7.5e+35)) tmp = Float64(t * y); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.5e+56], N[Not[LessEqual[y, 7.5e+35]], $MachinePrecision]], N[(t * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+56} \lor \neg \left(y \leq 7.5 \cdot 10^{+35}\right):\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -5.5000000000000002e56 or 7.4999999999999999e35 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.3
Applied rewrites82.3%
Taylor expanded in x around 0
Applied rewrites48.0%
if -5.5000000000000002e56 < y < 7.4999999999999999e35Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6487.3
Applied rewrites87.3%
Taylor expanded in x around inf
distribute-rgt-out--N/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sign-subN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f6457.6
Applied rewrites57.6%
Final simplification53.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.35e-37) (not (<= y 5e-31))) (* t y) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.35e-37) || !(y <= 5e-31)) {
tmp = t * y;
} else {
tmp = x;
}
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 <= (-1.35d-37)) .or. (.not. (y <= 5d-31))) then
tmp = t * y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.35e-37) || !(y <= 5e-31)) {
tmp = t * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.35e-37) or not (y <= 5e-31): tmp = t * y else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.35e-37) || !(y <= 5e-31)) tmp = Float64(t * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.35e-37) || ~((y <= 5e-31))) tmp = t * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.35e-37], N[Not[LessEqual[y, 5e-31]], $MachinePrecision]], N[(t * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-37} \lor \neg \left(y \leq 5 \cdot 10^{-31}\right):\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.35000000000000008e-37 or 5e-31 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6474.5
Applied rewrites74.5%
Taylor expanded in x around 0
Applied rewrites43.5%
if -1.35000000000000008e-37 < y < 5e-31Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6494.8
Applied rewrites94.8%
Taylor expanded in z around 0
Applied rewrites38.8%
Final simplification41.5%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return 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
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6459.9
Applied rewrites59.9%
Taylor expanded in z around 0
Applied rewrites19.1%
Final simplification19.1%
(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 2025026
(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))))