
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
Initial program 100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- y z) t)))
(if (<= z -1.15e+165)
(* z x)
(if (<= z -2.85e-21)
t_1
(if (<= z 3.8e-159)
(fma t y x)
(if (<= z 6e-13) (* (- t x) y) (if (<= z 1.06e+191) 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.15e+165) {
tmp = z * x;
} else if (z <= -2.85e-21) {
tmp = t_1;
} else if (z <= 3.8e-159) {
tmp = fma(t, y, x);
} else if (z <= 6e-13) {
tmp = (t - x) * y;
} else if (z <= 1.06e+191) {
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.15e+165) tmp = Float64(z * x); elseif (z <= -2.85e-21) tmp = t_1; elseif (z <= 3.8e-159) tmp = fma(t, y, x); elseif (z <= 6e-13) tmp = Float64(Float64(t - x) * y); elseif (z <= 1.06e+191) 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.15e+165], N[(z * x), $MachinePrecision], If[LessEqual[z, -2.85e-21], t$95$1, If[LessEqual[z, 3.8e-159], N[(t * y + x), $MachinePrecision], If[LessEqual[z, 6e-13], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[z, 1.06e+191], 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.15 \cdot 10^{+165}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq -2.85 \cdot 10^{-21}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-159}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-13}:\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{elif}\;z \leq 1.06 \cdot 10^{+191}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -1.15000000000000008e165 or 1.06000000000000003e191 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites64.9%
Taylor expanded in z around inf
Applied rewrites61.6%
if -1.15000000000000008e165 < z < -2.8499999999999998e-21 or 5.99999999999999968e-13 < z < 1.06000000000000003e191Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites64.4%
if -2.8499999999999998e-21 < z < 3.8000000000000001e-159Initial program 99.9%
Taylor expanded in z around 0
Applied rewrites95.0%
Taylor expanded in x around 0
Applied rewrites73.9%
if 3.8000000000000001e-159 < z < 5.99999999999999968e-13Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites71.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- y z) t)))
(if (<= z -1.15e+165)
(* z x)
(if (<= z -1.35e-10)
t_1
(if (<= z 6.2e-13)
(fma (- t x) y x)
(if (<= z 1.06e+191) 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.15e+165) {
tmp = z * x;
} else if (z <= -1.35e-10) {
tmp = t_1;
} else if (z <= 6.2e-13) {
tmp = fma((t - x), y, x);
} else if (z <= 1.06e+191) {
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.15e+165) tmp = Float64(z * x); elseif (z <= -1.35e-10) tmp = t_1; elseif (z <= 6.2e-13) tmp = fma(Float64(t - x), y, x); elseif (z <= 1.06e+191) 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.15e+165], N[(z * x), $MachinePrecision], If[LessEqual[z, -1.35e-10], t$95$1, If[LessEqual[z, 6.2e-13], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 1.06e+191], 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.15 \cdot 10^{+165}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-10}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\mathbf{elif}\;z \leq 1.06 \cdot 10^{+191}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -1.15000000000000008e165 or 1.06000000000000003e191 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites64.9%
Taylor expanded in z around inf
Applied rewrites61.6%
if -1.15000000000000008e165 < z < -1.35e-10 or 6.1999999999999998e-13 < z < 1.06000000000000003e191Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites64.7%
if -1.35e-10 < z < 6.1999999999999998e-13Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites93.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -1.3e+14)
t_1
(if (<= y -7e-258)
(* (- z) t)
(if (<= y -1.75e-296)
(* z x)
(if (<= y 150000000000.0) (fma t y x) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -1.3e+14) {
tmp = t_1;
} else if (y <= -7e-258) {
tmp = -z * t;
} else if (y <= -1.75e-296) {
tmp = z * x;
} else if (y <= 150000000000.0) {
tmp = fma(t, y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) tmp = 0.0 if (y <= -1.3e+14) tmp = t_1; elseif (y <= -7e-258) tmp = Float64(Float64(-z) * t); elseif (y <= -1.75e-296) tmp = Float64(z * x); elseif (y <= 150000000000.0) tmp = fma(t, y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.3e+14], t$95$1, If[LessEqual[y, -7e-258], N[((-z) * t), $MachinePrecision], If[LessEqual[y, -1.75e-296], N[(z * x), $MachinePrecision], If[LessEqual[y, 150000000000.0], N[(t * y + x), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -1.3 \cdot 10^{+14}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -7 \cdot 10^{-258}:\\
\;\;\;\;\left(-z\right) \cdot t\\
\mathbf{elif}\;y \leq -1.75 \cdot 10^{-296}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;y \leq 150000000000:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.3e14 or 1.5e11 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites80.5%
if -1.3e14 < y < -7.00000000000000003e-258Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-outN/A
associate-*r*N/A
associate-+l+N/A
+-commutativeN/A
*-lft-identityN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt-inN/A
Applied rewrites97.8%
Taylor expanded in x around 0
Applied rewrites49.5%
Taylor expanded in y around 0
Applied rewrites43.0%
if -7.00000000000000003e-258 < y < -1.7499999999999999e-296Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites85.0%
Taylor expanded in z around inf
Applied rewrites85.0%
if -1.7499999999999999e-296 < y < 1.5e11Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites50.2%
Taylor expanded in x around 0
Applied rewrites50.3%
(FPCore (x y z t)
:precision binary64
(if (<= z -2.15e+79)
(* z x)
(if (<= z -2.9e-142)
(* t y)
(if (<= z -3.25e-243) x (if (<= z 1.15e+54) (* t y) (* z x))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.15e+79) {
tmp = z * x;
} else if (z <= -2.9e-142) {
tmp = t * y;
} else if (z <= -3.25e-243) {
tmp = x;
} else if (z <= 1.15e+54) {
tmp = t * y;
} 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 <= (-2.15d+79)) then
tmp = z * x
else if (z <= (-2.9d-142)) then
tmp = t * y
else if (z <= (-3.25d-243)) then
tmp = x
else if (z <= 1.15d+54) then
tmp = t * y
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 <= -2.15e+79) {
tmp = z * x;
} else if (z <= -2.9e-142) {
tmp = t * y;
} else if (z <= -3.25e-243) {
tmp = x;
} else if (z <= 1.15e+54) {
tmp = t * y;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.15e+79: tmp = z * x elif z <= -2.9e-142: tmp = t * y elif z <= -3.25e-243: tmp = x elif z <= 1.15e+54: tmp = t * y else: tmp = z * x return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.15e+79) tmp = Float64(z * x); elseif (z <= -2.9e-142) tmp = Float64(t * y); elseif (z <= -3.25e-243) tmp = x; elseif (z <= 1.15e+54) tmp = Float64(t * y); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -2.15e+79) tmp = z * x; elseif (z <= -2.9e-142) tmp = t * y; elseif (z <= -3.25e-243) tmp = x; elseif (z <= 1.15e+54) tmp = t * y; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.15e+79], N[(z * x), $MachinePrecision], If[LessEqual[z, -2.9e-142], N[(t * y), $MachinePrecision], If[LessEqual[z, -3.25e-243], x, If[LessEqual[z, 1.15e+54], N[(t * y), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{+79}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq -2.9 \cdot 10^{-142}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;z \leq -3.25 \cdot 10^{-243}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+54}:\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -2.1500000000000002e79 or 1.14999999999999997e54 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites58.9%
Taylor expanded in z around inf
Applied rewrites49.5%
if -2.1500000000000002e79 < z < -2.8999999999999999e-142 or -3.25000000000000021e-243 < z < 1.14999999999999997e54Initial program 99.9%
Taylor expanded in y around inf
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites40.1%
if -2.8999999999999999e-142 < z < -3.25000000000000021e-243Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites96.2%
Taylor expanded in y around 0
Applied rewrites62.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- z) (- t x))))
(if (<= z -2.1e+79)
t_1
(if (<= z -1.35e-10)
(* (- y z) t)
(if (<= z 1e+34) (fma (- t x) y x) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = -z * (t - x);
double tmp;
if (z <= -2.1e+79) {
tmp = t_1;
} else if (z <= -1.35e-10) {
tmp = (y - z) * t;
} else if (z <= 1e+34) {
tmp = fma((t - x), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(-z) * Float64(t - x)) tmp = 0.0 if (z <= -2.1e+79) tmp = t_1; elseif (z <= -1.35e-10) tmp = Float64(Float64(y - z) * t); elseif (z <= 1e+34) tmp = fma(Float64(t - x), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[((-z) * N[(t - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.1e+79], t$95$1, If[LessEqual[z, -1.35e-10], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[z, 1e+34], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(-z\right) \cdot \left(t - x\right)\\
\mathbf{if}\;z \leq -2.1 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-10}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{elif}\;z \leq 10^{+34}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -2.10000000000000008e79 or 9.99999999999999946e33 < z Initial program 100.0%
Taylor expanded in z around inf
Applied rewrites84.2%
if -2.10000000000000008e79 < z < -1.35e-10Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites81.8%
if -1.35e-10 < z < 9.99999999999999946e33Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites92.5%
(FPCore (x y z t) :precision binary64 (if (<= x -1.1e+57) (fma (- x) y x) (if (<= x 2.5e-80) (* (- y z) t) (* (- t x) y))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.1e+57) {
tmp = fma(-x, y, x);
} else if (x <= 2.5e-80) {
tmp = (y - z) * t;
} else {
tmp = (t - x) * y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= -1.1e+57) tmp = fma(Float64(-x), y, x); elseif (x <= 2.5e-80) tmp = Float64(Float64(y - z) * t); else tmp = Float64(Float64(t - x) * y); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.1e+57], N[((-x) * y + x), $MachinePrecision], If[LessEqual[x, 2.5e-80], N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+57}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-80}:\\
\;\;\;\;\left(y - z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;\left(t - x\right) \cdot y\\
\end{array}
\end{array}
if x < -1.1e57Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites65.9%
Taylor expanded in x around inf
Applied rewrites64.1%
if -1.1e57 < x < 2.5e-80Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites68.2%
if 2.5e-80 < x Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites60.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.15e+79) (not (<= z 1.15e+54))) (* z x) (fma t y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.15e+79) || !(z <= 1.15e+54)) {
tmp = z * x;
} else {
tmp = fma(t, y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.15e+79) || !(z <= 1.15e+54)) tmp = Float64(z * x); else tmp = fma(t, y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.15e+79], N[Not[LessEqual[z, 1.15e+54]], $MachinePrecision]], N[(z * x), $MachinePrecision], N[(t * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{+79} \lor \neg \left(z \leq 1.15 \cdot 10^{+54}\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, y, x\right)\\
\end{array}
\end{array}
if z < -2.1500000000000002e79 or 1.14999999999999997e54 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites58.9%
Taylor expanded in z around inf
Applied rewrites49.5%
if -2.1500000000000002e79 < z < 1.14999999999999997e54Initial program 99.9%
Taylor expanded in z around 0
Applied rewrites86.1%
Taylor expanded in x around 0
Applied rewrites63.8%
Final simplification58.1%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.1e+43) (not (<= z 48000000000.0))) (* z x) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.1e+43) || !(z <= 48000000000.0)) {
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.1d+43)) .or. (.not. (z <= 48000000000.0d0))) 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.1e+43) || !(z <= 48000000000.0)) {
tmp = z * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.1e+43) or not (z <= 48000000000.0): tmp = z * x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.1e+43) || !(z <= 48000000000.0)) 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.1e+43) || ~((z <= 48000000000.0))) tmp = z * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.1e+43], N[Not[LessEqual[z, 48000000000.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{+43} \lor \neg \left(z \leq 48000000000\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.1e43 or 4.8e10 < z Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites56.2%
Taylor expanded in z around inf
Applied rewrites44.9%
if -4.1e43 < z < 4.8e10Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites88.9%
Taylor expanded in y around 0
Applied rewrites32.9%
Final simplification38.4%
(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 rewrites61.5%
Taylor expanded in y around 0
Applied rewrites19.1%
(FPCore (x y z t) :precision binary64 (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((t * (y - z)) + (-x * (y - z)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
def code(x, y, z, t): return x + ((t * (y - z)) + (-x * (y - z)))
function code(x, y, z, t) return Float64(x + Float64(Float64(t * Float64(y - z)) + Float64(Float64(-x) * Float64(y - z)))) end
function tmp = code(x, y, z, t) tmp = x + ((t * (y - z)) + (-x * (y - z))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision] + N[((-x) * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right)
\end{array}
herbie shell --seed 2025026
(FPCore (x y z t)
:name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
(+ x (* (- y z) (- t x))))