
(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 12 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 (* (- y z) t)))
(if (<= z -1.02e+62)
t_1
(if (<= z 2.3e+107) (fma (- t x) y x) (if (<= z 7e+182) t_1 (* z x))))))
double code(double x, double y, double z, double t) {
double t_1 = (y - z) * t;
double tmp;
if (z <= -1.02e+62) {
tmp = t_1;
} else if (z <= 2.3e+107) {
tmp = fma((t - x), y, x);
} else if (z <= 7e+182) {
tmp = t_1;
} else {
tmp = z * x;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(y - z) * t) tmp = 0.0 if (z <= -1.02e+62) tmp = t_1; elseif (z <= 2.3e+107) tmp = fma(Float64(t - x), y, x); elseif (z <= 7e+182) tmp = t_1; else tmp = Float64(z * x); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]}, If[LessEqual[z, -1.02e+62], t$95$1, If[LessEqual[z, 2.3e+107], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 7e+182], t$95$1, N[(z * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y - z\right) \cdot t\\
\mathbf{if}\;z \leq -1.02 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+107}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+182}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -1.02000000000000002e62 or 2.3e107 < z < 7.00000000000000045e182Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lift--.f6464.1
Applied rewrites64.1%
if -1.02000000000000002e62 < z < 2.3e107Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6486.5
Applied rewrites86.5%
if 7.00000000000000045e182 < z Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6492.4
Applied rewrites92.4%
Taylor expanded in t around 0
+-commutativeN/A
lower-fma.f6458.8
Applied rewrites58.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6458.8
Applied rewrites58.8%
(FPCore (x y z t)
:precision binary64
(if (<= y -1.8e+217)
(* t y)
(if (or (<= y -1700000000000.0) (not (<= y 26.0)))
(* (- x) y)
(fma x z x))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.8e+217) {
tmp = t * y;
} else if ((y <= -1700000000000.0) || !(y <= 26.0)) {
tmp = -x * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -1.8e+217) tmp = Float64(t * y); elseif ((y <= -1700000000000.0) || !(y <= 26.0)) tmp = Float64(Float64(-x) * y); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.8e+217], N[(t * y), $MachinePrecision], If[Or[LessEqual[y, -1700000000000.0], N[Not[LessEqual[y, 26.0]], $MachinePrecision]], N[((-x) * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+217}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;y \leq -1700000000000 \lor \neg \left(y \leq 26\right):\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -1.8000000000000001e217Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6494.4
Applied rewrites94.4%
Taylor expanded in x around 0
lower-*.f6473.6
Applied rewrites73.6%
if -1.8000000000000001e217 < y < -1.7e12 or 26 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lift--.f6480.0
Applied rewrites80.0%
Taylor expanded in x around inf
mul-1-negN/A
lift-neg.f6449.1
Applied rewrites49.1%
if -1.7e12 < y < 26Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6488.4
Applied rewrites88.4%
Taylor expanded in t around 0
+-commutativeN/A
lower-fma.f6456.2
Applied rewrites56.2%
Final simplification54.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -0.5) (not (<= y 100.0))) (fma (- t x) y x) (fma (- z) (- t x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -0.5) || !(y <= 100.0)) {
tmp = fma((t - x), y, x);
} else {
tmp = fma(-z, (t - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -0.5) || !(y <= 100.0)) tmp = fma(Float64(t - x), y, x); else tmp = fma(Float64(-z), Float64(t - x), x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 100.0]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], N[((-z) * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 100\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, t - x, x\right)\\
\end{array}
\end{array}
if y < -0.5 or 100 < y Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6482.3
Applied rewrites82.3%
if -0.5 < y < 100Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6491.5
Applied rewrites91.5%
Final simplification86.5%
(FPCore (x y z t) :precision binary64 (if (<= z -1.16e+44) (* z x) (if (<= z 2.5e-276) (* t y) (if (<= z 3.2e-21) x (* z x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.16e+44) {
tmp = z * x;
} else if (z <= 2.5e-276) {
tmp = t * y;
} else if (z <= 3.2e-21) {
tmp = x;
} else {
tmp = z * 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 (z <= (-1.16d+44)) then
tmp = z * x
else if (z <= 2.5d-276) then
tmp = t * y
else if (z <= 3.2d-21) then
tmp = x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.16e+44) {
tmp = z * x;
} else if (z <= 2.5e-276) {
tmp = t * y;
} else if (z <= 3.2e-21) {
tmp = x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.16e+44: tmp = z * x elif z <= 2.5e-276: tmp = t * y elif z <= 3.2e-21: tmp = x else: tmp = z * x return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.16e+44) tmp = Float64(z * x); elseif (z <= 2.5e-276) tmp = Float64(t * y); elseif (z <= 3.2e-21) tmp = x; else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.16e+44) tmp = z * x; elseif (z <= 2.5e-276) tmp = t * y; elseif (z <= 3.2e-21) tmp = x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.16e+44], N[(z * x), $MachinePrecision], If[LessEqual[z, 2.5e-276], N[(t * y), $MachinePrecision], If[LessEqual[z, 3.2e-21], x, N[(z * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.16 \cdot 10^{+44}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-276}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{-21}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -1.1600000000000001e44 or 3.2000000000000002e-21 < z Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6477.3
Applied rewrites77.3%
Taylor expanded in t around 0
+-commutativeN/A
lower-fma.f6440.1
Applied rewrites40.1%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6439.6
Applied rewrites39.6%
if -1.1600000000000001e44 < z < 2.49999999999999984e-276Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6490.3
Applied rewrites90.3%
Taylor expanded in x around 0
lower-*.f6441.8
Applied rewrites41.8%
if 2.49999999999999984e-276 < z < 3.2000000000000002e-21Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6491.5
Applied rewrites91.5%
Taylor expanded in y around 0
Applied rewrites44.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.8e+61) (not (<= z 2.9e+75))) (* (- z) (- t x)) (fma (- t x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.8e+61) || !(z <= 2.9e+75)) {
tmp = -z * (t - x);
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.8e+61) || !(z <= 2.9e+75)) tmp = Float64(Float64(-z) * Float64(t - x)); else tmp = fma(Float64(t - x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.8e+61], N[Not[LessEqual[z, 2.9e+75]], $MachinePrecision]], N[((-z) * N[(t - x), $MachinePrecision]), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.8 \cdot 10^{+61} \lor \neg \left(z \leq 2.9 \cdot 10^{+75}\right):\\
\;\;\;\;\left(-z\right) \cdot \left(t - x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\end{array}
\end{array}
if z < -9.8000000000000005e61 or 2.8999999999999998e75 < z Initial program 100.0%
Taylor expanded in z around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6482.1
Applied rewrites82.1%
if -9.8000000000000005e61 < z < 2.8999999999999998e75Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6488.5
Applied rewrites88.5%
Final simplification86.0%
(FPCore (x y z t) :precision binary64 (if (or (<= t -3.15e-37) (not (<= t 1.1e-23))) (fma (- y z) t x) (fma (- t x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -3.15e-37) || !(t <= 1.1e-23)) {
tmp = fma((y - z), t, x);
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -3.15e-37) || !(t <= 1.1e-23)) tmp = fma(Float64(y - z), t, x); else tmp = fma(Float64(t - x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -3.15e-37], N[Not[LessEqual[t, 1.1e-23]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * t + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.15 \cdot 10^{-37} \lor \neg \left(t \leq 1.1 \cdot 10^{-23}\right):\\
\;\;\;\;\mathsf{fma}\left(y - z, t, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\end{array}
\end{array}
if t < -3.15000000000000011e-37 or 1.1e-23 < t Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites85.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift--.f6485.0
Applied rewrites85.0%
if -3.15000000000000011e-37 < t < 1.1e-23Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6475.7
Applied rewrites75.7%
Final simplification80.8%
(FPCore (x y z t) :precision binary64 (if (or (<= t -3.15e-37) (not (<= t 9.8e-45))) (* (- y z) t) (fma (- x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -3.15e-37) || !(t <= 9.8e-45)) {
tmp = (y - z) * t;
} else {
tmp = fma(-x, y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -3.15e-37) || !(t <= 9.8e-45)) tmp = Float64(Float64(y - z) * t); else tmp = fma(Float64(-x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -3.15e-37], N[Not[LessEqual[t, 9.8e-45]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], N[((-x) * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.15 \cdot 10^{-37} \lor \neg \left(t \leq 9.8 \cdot 10^{-45}\right):\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\end{array}
\end{array}
if t < -3.15000000000000011e-37 or 9.7999999999999996e-45 < t Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lift--.f6474.2
Applied rewrites74.2%
if -3.15000000000000011e-37 < t < 9.7999999999999996e-45Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6475.5
Applied rewrites75.5%
Taylor expanded in x around inf
mul-1-negN/A
lift-neg.f6469.6
Applied rewrites69.6%
Final simplification72.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.4e-21) (not (<= y 1.1))) (* (- t x) y) (fma x z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.4e-21) || !(y <= 1.1)) {
tmp = (t - x) * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.4e-21) || !(y <= 1.1)) 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, -2.4e-21], N[Not[LessEqual[y, 1.1]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-21} \lor \neg \left(y \leq 1.1\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -2.3999999999999999e-21 or 1.1000000000000001 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lift--.f6478.7
Applied rewrites78.7%
if -2.3999999999999999e-21 < y < 1.1000000000000001Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6492.8
Applied rewrites92.8%
Taylor expanded in t around 0
+-commutativeN/A
lower-fma.f6459.9
Applied rewrites59.9%
Final simplification70.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.7e+123) (not (<= y 5.5e+79))) (* t y) (fma x z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.7e+123) || !(y <= 5.5e+79)) {
tmp = t * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.7e+123) || !(y <= 5.5e+79)) tmp = Float64(t * y); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.7e+123], N[Not[LessEqual[y, 5.5e+79]], $MachinePrecision]], N[(t * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+123} \lor \neg \left(y \leq 5.5 \cdot 10^{+79}\right):\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -1.70000000000000001e123 or 5.50000000000000007e79 < y Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6488.8
Applied rewrites88.8%
Taylor expanded in x around 0
lower-*.f6448.9
Applied rewrites48.9%
if -1.70000000000000001e123 < y < 5.50000000000000007e79Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6478.4
Applied rewrites78.4%
Taylor expanded in t around 0
+-commutativeN/A
lower-fma.f6449.6
Applied rewrites49.6%
Final simplification49.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.8e-20) (not (<= z 3.2e-21))) (* z x) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.8e-20) || !(z <= 3.2e-21)) {
tmp = z * x;
} 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 ((z <= (-9.8d-20)) .or. (.not. (z <= 3.2d-21))) then
tmp = z * x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.8e-20) || !(z <= 3.2e-21)) {
tmp = z * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9.8e-20) or not (z <= 3.2e-21): tmp = z * x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.8e-20) || !(z <= 3.2e-21)) tmp = Float64(z * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -9.8e-20) || ~((z <= 3.2e-21))) tmp = z * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.8e-20], N[Not[LessEqual[z, 3.2e-21]], $MachinePrecision]], N[(z * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.8 \cdot 10^{-20} \lor \neg \left(z \leq 3.2 \cdot 10^{-21}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.8000000000000003e-20 or 3.2000000000000002e-21 < z Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6473.0
Applied rewrites73.0%
Taylor expanded in t around 0
+-commutativeN/A
lower-fma.f6437.1
Applied rewrites37.1%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6436.6
Applied rewrites36.6%
if -9.8000000000000003e-20 < z < 3.2000000000000002e-21Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6492.9
Applied rewrites92.9%
Taylor expanded in y around 0
Applied rewrites33.8%
Final simplification35.2%
(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 z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6464.6
Applied rewrites64.6%
Taylor expanded in y around 0
Applied rewrites18.4%
(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 2025038
(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))))