
(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 13 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.4e+31)
t_1
(if (<= y -3.5e-239)
t_2
(if (<= y 7e-23) (fma z x x) (if (<= y 4.4e+21) 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.4e+31) {
tmp = t_1;
} else if (y <= -3.5e-239) {
tmp = t_2;
} else if (y <= 7e-23) {
tmp = fma(z, x, x);
} else if (y <= 4.4e+21) {
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.4e+31) tmp = t_1; elseif (y <= -3.5e-239) tmp = t_2; elseif (y <= 7e-23) tmp = fma(z, x, x); elseif (y <= 4.4e+21) tmp = t_2; else tmp = t_1; end return 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.4e+31], t$95$1, If[LessEqual[y, -3.5e-239], t$95$2, If[LessEqual[y, 7e-23], N[(z * x + x), $MachinePrecision], If[LessEqual[y, 4.4e+21], 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.4 \cdot 10^{+31}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{-239}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{+21}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.40000000000000008e31 or 4.4e21 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites87.3%
if -1.40000000000000008e31 < y < -3.50000000000000005e-239 or 6.99999999999999987e-23 < y < 4.4e21Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites60.8%
if -3.50000000000000005e-239 < y < 6.99999999999999987e-23Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites67.4%
Taylor expanded in y around 0
Applied rewrites67.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -9e+41) (not (<= y 1.45e+22))) (* (- t x) y) (- x (* (- t x) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -9e+41) || !(y <= 1.45e+22)) {
tmp = (t - x) * y;
} else {
tmp = x - ((t - 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 ((y <= (-9d+41)) .or. (.not. (y <= 1.45d+22))) then
tmp = (t - x) * y
else
tmp = x - ((t - x) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -9e+41) || !(y <= 1.45e+22)) {
tmp = (t - x) * y;
} else {
tmp = x - ((t - x) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -9e+41) or not (y <= 1.45e+22): tmp = (t - x) * y else: tmp = x - ((t - x) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -9e+41) || !(y <= 1.45e+22)) tmp = Float64(Float64(t - x) * y); else tmp = Float64(x - Float64(Float64(t - x) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -9e+41) || ~((y <= 1.45e+22))) tmp = (t - x) * y; else tmp = x - ((t - x) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -9e+41], N[Not[LessEqual[y, 1.45e+22]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(x - N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+41} \lor \neg \left(y \leq 1.45 \cdot 10^{+22}\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x - \left(t - x\right) \cdot z\\
\end{array}
\end{array}
if y < -9.0000000000000002e41 or 1.45e22 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites89.7%
if -9.0000000000000002e41 < y < 1.45e22Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites85.2%
Final simplification87.2%
(FPCore (x y z t) :precision binary64 (if (<= (- y z) -5e+34) (* z x) (if (<= (- y z) 5e-19) x (* y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y - z) <= -5e+34) {
tmp = z * x;
} else if ((y - z) <= 5e-19) {
tmp = x;
} else {
tmp = y * t;
}
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 - z) <= (-5d+34)) then
tmp = z * x
else if ((y - z) <= 5d-19) then
tmp = x
else
tmp = y * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y - z) <= -5e+34) {
tmp = z * x;
} else if ((y - z) <= 5e-19) {
tmp = x;
} else {
tmp = y * t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y - z) <= -5e+34: tmp = z * x elif (y - z) <= 5e-19: tmp = x else: tmp = y * t return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(y - z) <= -5e+34) tmp = Float64(z * x); elseif (Float64(y - z) <= 5e-19) tmp = x; else tmp = Float64(y * t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y - z) <= -5e+34) tmp = z * x; elseif ((y - z) <= 5e-19) tmp = x; else tmp = y * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(y - z), $MachinePrecision], -5e+34], N[(z * x), $MachinePrecision], If[LessEqual[N[(y - z), $MachinePrecision], 5e-19], x, N[(y * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y - z \leq -5 \cdot 10^{+34}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;y - z \leq 5 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot t\\
\end{array}
\end{array}
if (-.f64 y z) < -4.9999999999999998e34Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites58.3%
Taylor expanded in z around inf
Applied rewrites31.6%
if -4.9999999999999998e34 < (-.f64 y z) < 5.0000000000000004e-19Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites84.2%
Taylor expanded in y around 0
Applied rewrites62.1%
if 5.0000000000000004e-19 < (-.f64 y z) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites53.7%
Taylor expanded in y around inf
Applied rewrites32.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5.2e+31) (not (<= z 6e+21))) (* (- z) (- t x)) (fma (- t x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.2e+31) || !(z <= 6e+21)) {
tmp = -z * (t - x);
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -5.2e+31) || !(z <= 6e+21)) 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, -5.2e+31], N[Not[LessEqual[z, 6e+21]], $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 -5.2 \cdot 10^{+31} \lor \neg \left(z \leq 6 \cdot 10^{+21}\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 < -5.2e31 or 6e21 < z Initial program 100.0%
Taylor expanded in z around inf
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites78.0%
if -5.2e31 < z < 6e21Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites92.6%
Final simplification85.9%
(FPCore (x y z t) :precision binary64 (if (or (<= t -1.12e-60) (not (<= t 1.7e-68))) (* (- y z) t) (fma (- z y) x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.12e-60) || !(t <= 1.7e-68)) {
tmp = (y - z) * t;
} else {
tmp = fma((z - y), x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -1.12e-60) || !(t <= 1.7e-68)) tmp = Float64(Float64(y - z) * t); else tmp = fma(Float64(z - y), x, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.12e-60], N[Not[LessEqual[t, 1.7e-68]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], N[(N[(z - y), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.12 \cdot 10^{-60} \lor \neg \left(t \leq 1.7 \cdot 10^{-68}\right):\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z - y, x, x\right)\\
\end{array}
\end{array}
if t < -1.12e-60 or 1.70000000000000009e-68 < t Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.5%
if -1.12e-60 < t < 1.70000000000000009e-68Initial program 100.0%
Taylor expanded in z around inf
Applied rewrites84.2%
Taylor expanded in x around inf
Applied rewrites86.2%
Final simplification81.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1800000.0) (not (<= z 7.2e+98))) (* (- y z) t) (fma (- t x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1800000.0) || !(z <= 7.2e+98)) {
tmp = (y - z) * t;
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -1800000.0) || !(z <= 7.2e+98)) tmp = Float64(Float64(y - z) * t); else tmp = fma(Float64(t - x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1800000.0], N[Not[LessEqual[z, 7.2e+98]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1800000 \lor \neg \left(z \leq 7.2 \cdot 10^{+98}\right):\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\end{array}
\end{array}
if z < -1.8e6 or 7.19999999999999962e98 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites58.7%
if -1.8e6 < z < 7.19999999999999962e98Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites84.7%
Final simplification74.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -63000000000000.0) (not (<= y 1.15e-16))) (* (- t x) y) (fma z x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -63000000000000.0) || !(y <= 1.15e-16)) {
tmp = (t - x) * y;
} else {
tmp = fma(z, x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -63000000000000.0) || !(y <= 1.15e-16)) tmp = Float64(Float64(t - x) * y); else tmp = fma(z, x, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -63000000000000.0], N[Not[LessEqual[y, 1.15e-16]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(z * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -63000000000000 \lor \neg \left(y \leq 1.15 \cdot 10^{-16}\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\end{array}
\end{array}
if y < -6.3e13 or 1.15e-16 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites81.7%
if -6.3e13 < y < 1.15e-16Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites60.2%
Taylor expanded in y around 0
Applied rewrites59.6%
Final simplification71.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.8e+41) (not (<= y 3.2e+22))) (* (- x) y) (fma z x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.8e+41) || !(y <= 3.2e+22)) {
tmp = -x * y;
} else {
tmp = fma(z, x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.8e+41) || !(y <= 3.2e+22)) tmp = Float64(Float64(-x) * y); else tmp = fma(z, x, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.8e+41], N[Not[LessEqual[y, 3.2e+22]], $MachinePrecision]], N[((-x) * y), $MachinePrecision], N[(z * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+41} \lor \neg \left(y \leq 3.2 \cdot 10^{+22}\right):\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\end{array}
\end{array}
if y < -4.8000000000000003e41 or 3.2e22 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites89.0%
Taylor expanded in x around inf
Applied rewrites54.0%
if -4.8000000000000003e41 < y < 3.2e22Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites56.4%
Taylor expanded in y around 0
Applied rewrites54.5%
Final simplification54.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.2e+36) (not (<= z 6e+20))) (* z x) (fma t y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.2e+36) || !(z <= 6e+20)) {
tmp = z * x;
} else {
tmp = fma(t, y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.2e+36) || !(z <= 6e+20)) tmp = Float64(z * x); else tmp = fma(t, y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.2e+36], N[Not[LessEqual[z, 6e+20]], $MachinePrecision]], N[(z * x), $MachinePrecision], N[(t * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+36} \lor \neg \left(z \leq 6 \cdot 10^{+20}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\end{array}
\end{array}
if z < -9.19999999999999986e36 or 6e20 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites52.8%
Taylor expanded in z around inf
Applied rewrites39.3%
if -9.19999999999999986e36 < z < 6e20Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites92.6%
Taylor expanded in x around 0
Applied rewrites61.3%
Final simplification51.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.05e+67) (not (<= y 1.15e-16))) (* y t) (fma z x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.05e+67) || !(y <= 1.15e-16)) {
tmp = y * t;
} else {
tmp = fma(z, x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.05e+67) || !(y <= 1.15e-16)) tmp = Float64(y * t); else tmp = fma(z, x, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.05e+67], N[Not[LessEqual[y, 1.15e-16]], $MachinePrecision]], N[(y * t), $MachinePrecision], N[(z * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{+67} \lor \neg \left(y \leq 1.15 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\end{array}
\end{array}
if y < -2.0499999999999999e67 or 1.15e-16 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites49.7%
Taylor expanded in y around inf
Applied rewrites41.3%
if -2.0499999999999999e67 < y < 1.15e-16Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites59.5%
Taylor expanded in y around 0
Applied rewrites55.5%
Final simplification49.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1600.0) (not (<= z 1.95e+34))) (* z x) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1600.0) || !(z <= 1.95e+34)) {
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 <= (-1600.0d0)) .or. (.not. (z <= 1.95d+34))) 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 <= -1600.0) || !(z <= 1.95e+34)) {
tmp = z * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1600.0) or not (z <= 1.95e+34): tmp = z * x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1600.0) || !(z <= 1.95e+34)) tmp = Float64(z * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1600.0) || ~((z <= 1.95e+34))) tmp = z * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1600.0], N[Not[LessEqual[z, 1.95e+34]], $MachinePrecision]], N[(z * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1600 \lor \neg \left(z \leq 1.95 \cdot 10^{+34}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1600 or 1.9500000000000001e34 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites52.0%
Taylor expanded in z around inf
Applied rewrites39.3%
if -1600 < z < 1.9500000000000001e34Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites91.9%
Taylor expanded in y around 0
Applied rewrites29.5%
Final simplification34.0%
(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
Applied rewrites63.9%
Taylor expanded in y around 0
Applied rewrites17.2%
(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 2025022
(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))))