
(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 (+ 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)) (t_2 (* (- y z) t)))
(if (<= y -1.75e+64)
t_1
(if (<= y -8.2e-73)
t_2
(if (<= y 4.4e-246) (* (+ 1.0 z) x) (if (<= y 2.7e+31) t_2 t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double t_2 = (y - z) * t;
double tmp;
if (y <= -1.75e+64) {
tmp = t_1;
} else if (y <= -8.2e-73) {
tmp = t_2;
} else if (y <= 4.4e-246) {
tmp = (1.0 + z) * x;
} else if (y <= 2.7e+31) {
tmp = t_2;
} 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) :: t_2
real(8) :: tmp
t_1 = (t - x) * y
t_2 = (y - z) * t
if (y <= (-1.75d+64)) then
tmp = t_1
else if (y <= (-8.2d-73)) then
tmp = t_2
else if (y <= 4.4d-246) then
tmp = (1.0d0 + z) * x
else if (y <= 2.7d+31) then
tmp = t_2
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 t_2 = (y - z) * t;
double tmp;
if (y <= -1.75e+64) {
tmp = t_1;
} else if (y <= -8.2e-73) {
tmp = t_2;
} else if (y <= 4.4e-246) {
tmp = (1.0 + z) * x;
} else if (y <= 2.7e+31) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (t - x) * y t_2 = (y - z) * t tmp = 0 if y <= -1.75e+64: tmp = t_1 elif y <= -8.2e-73: tmp = t_2 elif y <= 4.4e-246: tmp = (1.0 + z) * x elif y <= 2.7e+31: tmp = t_2 else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) t_2 = Float64(Float64(y - z) * t) tmp = 0.0 if (y <= -1.75e+64) tmp = t_1; elseif (y <= -8.2e-73) tmp = t_2; elseif (y <= 4.4e-246) tmp = Float64(Float64(1.0 + z) * x); elseif (y <= 2.7e+31) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (t - x) * y; t_2 = (y - z) * t; tmp = 0.0; if (y <= -1.75e+64) tmp = t_1; elseif (y <= -8.2e-73) tmp = t_2; elseif (y <= 4.4e-246) tmp = (1.0 + z) * x; elseif (y <= 2.7e+31) tmp = t_2; 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]}, Block[{t$95$2 = N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]}, If[LessEqual[y, -1.75e+64], t$95$1, If[LessEqual[y, -8.2e-73], t$95$2, If[LessEqual[y, 4.4e-246], N[(N[(1.0 + z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 2.7e+31], t$95$2, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
t_2 := \left(y - z\right) \cdot t\\
\mathbf{if}\;y \leq -1.75 \cdot 10^{+64}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -8.2 \cdot 10^{-73}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{-246}:\\
\;\;\;\;\left(1 + z\right) \cdot x\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{+31}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.7499999999999999e64 or 2.69999999999999986e31 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lift--.f6485.7
Applied rewrites85.7%
if -1.7499999999999999e64 < y < -8.20000000000000032e-73 or 4.39999999999999996e-246 < y < 2.69999999999999986e31Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lift--.f6457.6
Applied rewrites57.6%
if -8.20000000000000032e-73 < y < 4.39999999999999996e-246Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lift--.f6465.0
Applied rewrites65.0%
Taylor expanded in y around 0
lower-+.f6465.0
Applied rewrites65.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- z) t)))
(if (<= z -1.8e+176)
t_1
(if (<= z -2.12e+77) (* z x) (if (<= z 3.6e-58) (fma t y x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = -z * t;
double tmp;
if (z <= -1.8e+176) {
tmp = t_1;
} else if (z <= -2.12e+77) {
tmp = z * x;
} else if (z <= 3.6e-58) {
tmp = fma(t, y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(-z) * t) tmp = 0.0 if (z <= -1.8e+176) tmp = t_1; elseif (z <= -2.12e+77) tmp = Float64(z * x); elseif (z <= 3.6e-58) tmp = fma(t, y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[((-z) * t), $MachinePrecision]}, If[LessEqual[z, -1.8e+176], t$95$1, If[LessEqual[z, -2.12e+77], N[(z * x), $MachinePrecision], If[LessEqual[z, 3.6e-58], N[(t * y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(-z\right) \cdot t\\
\mathbf{if}\;z \leq -1.8 \cdot 10^{+176}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -2.12 \cdot 10^{+77}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-58}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.79999999999999996e176 or 3.60000000000000009e-58 < 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--.f6475.3
Applied rewrites75.3%
Taylor expanded in x around 0
Applied rewrites50.2%
if -1.79999999999999996e176 < z < -2.12000000000000006e77Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lift--.f6466.2
Applied rewrites66.2%
Taylor expanded in z around inf
Applied rewrites45.8%
if -2.12000000000000006e77 < z < 3.60000000000000009e-58Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6489.8
Applied rewrites89.8%
Taylor expanded in x around 0
Applied rewrites64.4%
(FPCore (x y z t) :precision binary64 (if (<= t -6.5e-36) (* t y) (if (<= t -1.6e-246) x (if (<= t 5.5e+16) (* z x) (* t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -6.5e-36) {
tmp = t * y;
} else if (t <= -1.6e-246) {
tmp = x;
} else if (t <= 5.5e+16) {
tmp = z * x;
} 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 (t <= (-6.5d-36)) then
tmp = t * y
else if (t <= (-1.6d-246)) then
tmp = x
else if (t <= 5.5d+16) then
tmp = z * x
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 (t <= -6.5e-36) {
tmp = t * y;
} else if (t <= -1.6e-246) {
tmp = x;
} else if (t <= 5.5e+16) {
tmp = z * x;
} else {
tmp = t * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -6.5e-36: tmp = t * y elif t <= -1.6e-246: tmp = x elif t <= 5.5e+16: tmp = z * x else: tmp = t * y return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -6.5e-36) tmp = Float64(t * y); elseif (t <= -1.6e-246) tmp = x; elseif (t <= 5.5e+16) tmp = Float64(z * x); else tmp = Float64(t * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -6.5e-36) tmp = t * y; elseif (t <= -1.6e-246) tmp = x; elseif (t <= 5.5e+16) tmp = z * x; else tmp = t * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -6.5e-36], N[(t * y), $MachinePrecision], If[LessEqual[t, -1.6e-246], x, If[LessEqual[t, 5.5e+16], N[(z * x), $MachinePrecision], N[(t * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -6.5 \cdot 10^{-36}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;t \leq -1.6 \cdot 10^{-246}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.5 \cdot 10^{+16}:\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;t \cdot y\\
\end{array}
\end{array}
if t < -6.50000000000000012e-36 or 5.5e16 < t Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lift--.f6455.3
Applied rewrites55.3%
Taylor expanded in x around 0
Applied rewrites47.2%
if -6.50000000000000012e-36 < t < -1.6e-246Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6464.0
Applied rewrites64.0%
Taylor expanded in y around 0
Applied rewrites35.1%
if -1.6e-246 < t < 5.5e16Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lift--.f6487.8
Applied rewrites87.8%
Taylor expanded in z around inf
Applied rewrites33.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.25e+52) (not (<= z 3.7e+50))) (* (- z) (- t x)) (fma (- t x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.25e+52) || !(z <= 3.7e+50)) {
tmp = -z * (t - x);
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.25e+52) || !(z <= 3.7e+50)) 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, -2.25e+52], N[Not[LessEqual[z, 3.7e+50]], $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 -2.25 \cdot 10^{+52} \lor \neg \left(z \leq 3.7 \cdot 10^{+50}\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 < -2.25e52 or 3.7000000000000001e50 < 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--.f6478.7
Applied rewrites78.7%
if -2.25e52 < z < 3.7000000000000001e50Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6487.5
Applied rewrites87.5%
Final simplification83.7%
(FPCore (x y z t) :precision binary64 (if (or (<= x -8.2e-59) (not (<= x 8.5e-89))) (fma (- t x) y x) (* (- y z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -8.2e-59) || !(x <= 8.5e-89)) {
tmp = fma((t - x), y, x);
} else {
tmp = (y - z) * t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((x <= -8.2e-59) || !(x <= 8.5e-89)) tmp = fma(Float64(t - x), y, x); else tmp = Float64(Float64(y - z) * t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -8.2e-59], N[Not[LessEqual[x, 8.5e-89]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-59} \lor \neg \left(x \leq 8.5 \cdot 10^{-89}\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\end{array}
\end{array}
if x < -8.1999999999999991e-59 or 8.49999999999999937e-89 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6470.2
Applied rewrites70.2%
if -8.1999999999999991e-59 < x < 8.49999999999999937e-89Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lift--.f6488.4
Applied rewrites88.4%
Final simplification77.2%
(FPCore (x y z t) :precision binary64 (if (or (<= t -3.9e-36) (not (<= t 5.8e-14))) (* (- y z) t) (fma (- x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -3.9e-36) || !(t <= 5.8e-14)) {
tmp = (y - z) * t;
} else {
tmp = fma(-x, y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -3.9e-36) || !(t <= 5.8e-14)) 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.9e-36], N[Not[LessEqual[t, 5.8e-14]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], N[((-x) * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.9 \cdot 10^{-36} \lor \neg \left(t \leq 5.8 \cdot 10^{-14}\right):\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\end{array}
\end{array}
if t < -3.9000000000000001e-36 or 5.8000000000000005e-14 < t Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lift--.f6477.3
Applied rewrites77.3%
if -3.9000000000000001e-36 < t < 5.8000000000000005e-14Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6466.0
Applied rewrites66.0%
Taylor expanded in x around inf
mul-1-negN/A
lift-neg.f6461.5
Applied rewrites61.5%
Final simplification70.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.2e+15) (not (<= y 14000000.0))) (* (- t x) y) (* (+ 1.0 z) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.2e+15) || !(y <= 14000000.0)) {
tmp = (t - x) * y;
} else {
tmp = (1.0 + 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 ((y <= (-1.2d+15)) .or. (.not. (y <= 14000000.0d0))) then
tmp = (t - x) * y
else
tmp = (1.0d0 + z) * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.2e+15) || !(y <= 14000000.0)) {
tmp = (t - x) * y;
} else {
tmp = (1.0 + z) * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.2e+15) or not (y <= 14000000.0): tmp = (t - x) * y else: tmp = (1.0 + z) * x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.2e+15) || !(y <= 14000000.0)) tmp = Float64(Float64(t - x) * y); else tmp = Float64(Float64(1.0 + z) * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.2e+15) || ~((y <= 14000000.0))) tmp = (t - x) * y; else tmp = (1.0 + z) * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.2e+15], N[Not[LessEqual[y, 14000000.0]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(N[(1.0 + z), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+15} \lor \neg \left(y \leq 14000000\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 + z\right) \cdot x\\
\end{array}
\end{array}
if y < -1.2e15 or 1.4e7 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lift--.f6479.1
Applied rewrites79.1%
if -1.2e15 < y < 1.4e7Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lift--.f6455.2
Applied rewrites55.2%
Taylor expanded in y around 0
lower-+.f6453.5
Applied rewrites53.5%
Final simplification67.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.12e+77) (not (<= z 2.65e+103))) (* z x) (fma t y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.12e+77) || !(z <= 2.65e+103)) {
tmp = z * x;
} else {
tmp = fma(t, y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.12e+77) || !(z <= 2.65e+103)) tmp = Float64(z * x); else tmp = fma(t, y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.12e+77], N[Not[LessEqual[z, 2.65e+103]], $MachinePrecision]], N[(z * x), $MachinePrecision], N[(t * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.12 \cdot 10^{+77} \lor \neg \left(z \leq 2.65 \cdot 10^{+103}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\end{array}
\end{array}
if z < -2.12000000000000006e77 or 2.64999999999999985e103 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lift--.f6446.7
Applied rewrites46.7%
Taylor expanded in z around inf
Applied rewrites38.7%
if -2.12000000000000006e77 < z < 2.64999999999999985e103Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6482.8
Applied rewrites82.8%
Taylor expanded in x around 0
Applied rewrites57.0%
Final simplification50.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.3e-10) (not (<= z 1.6e-37))) (* z x) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.3e-10) || !(z <= 1.6e-37)) {
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 <= (-4.3d-10)) .or. (.not. (z <= 1.6d-37))) 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 <= -4.3e-10) || !(z <= 1.6e-37)) {
tmp = z * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.3e-10) or not (z <= 1.6e-37): tmp = z * x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.3e-10) || !(z <= 1.6e-37)) tmp = Float64(z * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.3e-10) || ~((z <= 1.6e-37))) tmp = z * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.3e-10], N[Not[LessEqual[z, 1.6e-37]], $MachinePrecision]], N[(z * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3 \cdot 10^{-10} \lor \neg \left(z \leq 1.6 \cdot 10^{-37}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.30000000000000014e-10 or 1.5999999999999999e-37 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lift--.f6447.0
Applied rewrites47.0%
Taylor expanded in z around inf
Applied rewrites31.1%
if -4.30000000000000014e-10 < z < 1.5999999999999999e-37Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f6493.2
Applied rewrites93.2%
Taylor expanded in y around 0
Applied rewrites32.8%
Final simplification31.9%
(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--.f6463.9
Applied rewrites63.9%
Taylor expanded in y around 0
Applied rewrites16.5%
(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 2025051
(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))))