
(FPCore (x y z t) :precision binary64 (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
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 * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
end function
public static double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
def code(x, y, z, t): return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t)))) end
function tmp = code(x, y, z, t) tmp = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
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 * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
end function
public static double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
def code(x, y, z, t): return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t)))) end
function tmp = code(x, y, z, t) tmp = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
\end{array}
(FPCore (x y z t)
:precision binary64
(if (<= z -3.4e-128)
(- x (* (/ z (fma (- t) y (* (* z z) 2.0))) (+ y y)))
(if (<= z 2e-181)
(fma (/ z t) 2.0 x)
(if (<= z 8e+154)
(- x (* (+ y y) (/ z (fma (+ z z) z (* (- y) t)))))
(- x (/ (fma (* t (* (/ y z) (/ y z))) 0.5 y) z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.4e-128) {
tmp = x - ((z / fma(-t, y, ((z * z) * 2.0))) * (y + y));
} else if (z <= 2e-181) {
tmp = fma((z / t), 2.0, x);
} else if (z <= 8e+154) {
tmp = x - ((y + y) * (z / fma((z + z), z, (-y * t))));
} else {
tmp = x - (fma((t * ((y / z) * (y / z))), 0.5, y) / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3.4e-128) tmp = Float64(x - Float64(Float64(z / fma(Float64(-t), y, Float64(Float64(z * z) * 2.0))) * Float64(y + y))); elseif (z <= 2e-181) tmp = fma(Float64(z / t), 2.0, x); elseif (z <= 8e+154) tmp = Float64(x - Float64(Float64(y + y) * Float64(z / fma(Float64(z + z), z, Float64(Float64(-y) * t))))); else tmp = Float64(x - Float64(fma(Float64(t * Float64(Float64(y / z) * Float64(y / z))), 0.5, y) / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.4e-128], N[(x - N[(N[(z / N[((-t) * y + N[(N[(z * z), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(y + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e-181], N[(N[(z / t), $MachinePrecision] * 2.0 + x), $MachinePrecision], If[LessEqual[z, 8e+154], N[(x - N[(N[(y + y), $MachinePrecision] * N[(z / N[(N[(z + z), $MachinePrecision] * z + N[((-y) * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(N[(t * N[(N[(y / z), $MachinePrecision] * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5 + y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-128}:\\
\;\;\;\;x - \frac{z}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)} \cdot \left(y + y\right)\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-181}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+154}:\\
\;\;\;\;x - \left(y + y\right) \cdot \frac{z}{\mathsf{fma}\left(z + z, z, \left(-y\right) \cdot t\right)}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\mathsf{fma}\left(t \cdot \left(\frac{y}{z} \cdot \frac{y}{z}\right), 0.5, y\right)}{z}\\
\end{array}
\end{array}
if z < -3.39999999999999975e-128Initial program 79.8%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites95.8%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lift-+.f6495.8
Applied rewrites95.8%
if -3.39999999999999975e-128 < z < 2.00000000000000009e-181Initial program 85.9%
Taylor expanded in y around inf
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
if 2.00000000000000009e-181 < z < 8.0000000000000003e154Initial program 82.4%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.9
Applied rewrites95.9%
lift-*.f64N/A
count-2-revN/A
lower-+.f6495.9
Applied rewrites95.9%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6495.9
Applied rewrites95.9%
if 8.0000000000000003e154 < z Initial program 39.8%
Taylor expanded in z around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
associate-/l*N/A
unpow2N/A
unpow2N/A
frac-timesN/A
lower-*.f64N/A
pow2N/A
lower-pow.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lift-/.f64N/A
lift-/.f6499.9
Applied rewrites99.9%
(FPCore (x y z t)
:precision binary64
(if (<= z -3.4e-128)
(- x (* (/ z (fma (- t) y (* (* z z) 2.0))) (+ y y)))
(if (<= z 2e-181)
(fma (/ z t) 2.0 x)
(if (<= z 1.6e+153)
(- x (* (+ y y) (/ z (fma (+ z z) z (* (- y) t)))))
(- x (/ y z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.4e-128) {
tmp = x - ((z / fma(-t, y, ((z * z) * 2.0))) * (y + y));
} else if (z <= 2e-181) {
tmp = fma((z / t), 2.0, x);
} else if (z <= 1.6e+153) {
tmp = x - ((y + y) * (z / fma((z + z), z, (-y * t))));
} else {
tmp = x - (y / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3.4e-128) tmp = Float64(x - Float64(Float64(z / fma(Float64(-t), y, Float64(Float64(z * z) * 2.0))) * Float64(y + y))); elseif (z <= 2e-181) tmp = fma(Float64(z / t), 2.0, x); elseif (z <= 1.6e+153) tmp = Float64(x - Float64(Float64(y + y) * Float64(z / fma(Float64(z + z), z, Float64(Float64(-y) * t))))); else tmp = Float64(x - Float64(y / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.4e-128], N[(x - N[(N[(z / N[((-t) * y + N[(N[(z * z), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(y + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e-181], N[(N[(z / t), $MachinePrecision] * 2.0 + x), $MachinePrecision], If[LessEqual[z, 1.6e+153], N[(x - N[(N[(y + y), $MachinePrecision] * N[(z / N[(N[(z + z), $MachinePrecision] * z + N[((-y) * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-128}:\\
\;\;\;\;x - \frac{z}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)} \cdot \left(y + y\right)\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-181}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+153}:\\
\;\;\;\;x - \left(y + y\right) \cdot \frac{z}{\mathsf{fma}\left(z + z, z, \left(-y\right) \cdot t\right)}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
\end{array}
if z < -3.39999999999999975e-128Initial program 79.8%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites95.8%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lift-+.f6495.8
Applied rewrites95.8%
if -3.39999999999999975e-128 < z < 2.00000000000000009e-181Initial program 85.9%
Taylor expanded in y around inf
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
if 2.00000000000000009e-181 < z < 1.6000000000000001e153Initial program 84.7%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
lift-*.f64N/A
count-2-revN/A
lower-+.f6495.8
Applied rewrites95.8%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6495.8
Applied rewrites95.8%
if 1.6000000000000001e153 < z Initial program 37.4%
Taylor expanded in y around 0
lower-/.f6499.3
Applied rewrites99.3%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (* (+ y y) (/ z (fma (+ z z) z (* (- y) t)))))))
(if (<= z -3.4e-128)
t_1
(if (<= z 2e-181)
(fma (/ z t) 2.0 x)
(if (<= z 1.6e+153) t_1 (- x (/ y z)))))))
double code(double x, double y, double z, double t) {
double t_1 = x - ((y + y) * (z / fma((z + z), z, (-y * t))));
double tmp;
if (z <= -3.4e-128) {
tmp = t_1;
} else if (z <= 2e-181) {
tmp = fma((z / t), 2.0, x);
} else if (z <= 1.6e+153) {
tmp = t_1;
} else {
tmp = x - (y / z);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(Float64(y + y) * Float64(z / fma(Float64(z + z), z, Float64(Float64(-y) * t))))) tmp = 0.0 if (z <= -3.4e-128) tmp = t_1; elseif (z <= 2e-181) tmp = fma(Float64(z / t), 2.0, x); elseif (z <= 1.6e+153) tmp = t_1; else tmp = Float64(x - Float64(y / z)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(N[(y + y), $MachinePrecision] * N[(z / N[(N[(z + z), $MachinePrecision] * z + N[((-y) * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.4e-128], t$95$1, If[LessEqual[z, 2e-181], N[(N[(z / t), $MachinePrecision] * 2.0 + x), $MachinePrecision], If[LessEqual[z, 1.6e+153], t$95$1, N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \left(y + y\right) \cdot \frac{z}{\mathsf{fma}\left(z + z, z, \left(-y\right) \cdot t\right)}\\
\mathbf{if}\;z \leq -3.4 \cdot 10^{-128}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-181}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+153}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
\end{array}
if z < -3.39999999999999975e-128 or 2.00000000000000009e-181 < z < 1.6000000000000001e153Initial program 81.9%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
lift-*.f64N/A
count-2-revN/A
lower-+.f6495.8
Applied rewrites95.8%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6495.8
Applied rewrites95.8%
if -3.39999999999999975e-128 < z < 2.00000000000000009e-181Initial program 85.9%
Taylor expanded in y around inf
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
if 1.6000000000000001e153 < z Initial program 37.4%
Taylor expanded in y around 0
lower-/.f6499.3
Applied rewrites99.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.35e-8) (not (<= z 9.5e+55))) (- x (/ y z)) (fma (/ z t) 2.0 x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.35e-8) || !(z <= 9.5e+55)) {
tmp = x - (y / z);
} else {
tmp = fma((z / t), 2.0, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.35e-8) || !(z <= 9.5e+55)) tmp = Float64(x - Float64(y / z)); else tmp = fma(Float64(z / t), 2.0, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.35e-8], N[Not[LessEqual[z, 9.5e+55]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * 2.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{-8} \lor \neg \left(z \leq 9.5 \cdot 10^{+55}\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\
\end{array}
\end{array}
if z < -1.35000000000000001e-8 or 9.49999999999999989e55 < z Initial program 66.3%
Taylor expanded in y around 0
lower-/.f6494.3
Applied rewrites94.3%
if -1.35000000000000001e-8 < z < 9.49999999999999989e55Initial program 88.0%
Taylor expanded in y around inf
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.8
Applied rewrites88.8%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -0.18) (not (<= z 360000000.0))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -0.18) || !(z <= 360000000.0)) {
tmp = x - (y / z);
} 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 <= (-0.18d0)) .or. (.not. (z <= 360000000.0d0))) then
tmp = x - (y / z)
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 <= -0.18) || !(z <= 360000000.0)) {
tmp = x - (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -0.18) or not (z <= 360000000.0): tmp = x - (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -0.18) || !(z <= 360000000.0)) tmp = Float64(x - Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -0.18) || ~((z <= 360000000.0))) tmp = x - (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -0.18], N[Not[LessEqual[z, 360000000.0]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.18 \lor \neg \left(z \leq 360000000\right):\\
\;\;\;\;x - \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.17999999999999999 or 3.6e8 < z Initial program 66.8%
Taylor expanded in y around 0
lower-/.f6490.4
Applied rewrites90.4%
if -0.17999999999999999 < z < 3.6e8Initial program 88.9%
Taylor expanded in x around inf
Applied rewrites75.0%
Final simplification83.3%
(FPCore (x y z t) :precision binary64 (if (or (<= x -2.9e-183) (not (<= x 2.2e-175))) x (/ (- y) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.9e-183) || !(x <= 2.2e-175)) {
tmp = x;
} else {
tmp = -y / 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 ((x <= (-2.9d-183)) .or. (.not. (x <= 2.2d-175))) then
tmp = x
else
tmp = -y / z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.9e-183) || !(x <= 2.2e-175)) {
tmp = x;
} else {
tmp = -y / z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -2.9e-183) or not (x <= 2.2e-175): tmp = x else: tmp = -y / z return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -2.9e-183) || !(x <= 2.2e-175)) tmp = x; else tmp = Float64(Float64(-y) / z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -2.9e-183) || ~((x <= 2.2e-175))) tmp = x; else tmp = -y / z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -2.9e-183], N[Not[LessEqual[x, 2.2e-175]], $MachinePrecision]], x, N[((-y) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{-183} \lor \neg \left(x \leq 2.2 \cdot 10^{-175}\right):\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{-y}{z}\\
\end{array}
\end{array}
if x < -2.9e-183 or 2.2e-175 < x Initial program 82.3%
Taylor expanded in x around inf
Applied rewrites86.9%
if -2.9e-183 < x < 2.2e-175Initial program 57.6%
Taylor expanded in x around 0
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6443.3
Applied rewrites43.3%
Taylor expanded in y around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6453.7
Applied rewrites53.7%
Final simplification79.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 77.1%
Taylor expanded in x around inf
Applied rewrites72.1%
(FPCore (x y z t) :precision binary64 (- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z)))))
double code(double x, double y, double z, double t) {
return x - (1.0 / ((z / y) - ((t / 2.0) / 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 - (1.0d0 / ((z / y) - ((t / 2.0d0) / z)))
end function
public static double code(double x, double y, double z, double t) {
return x - (1.0 / ((z / y) - ((t / 2.0) / z)));
}
def code(x, y, z, t): return x - (1.0 / ((z / y) - ((t / 2.0) / z)))
function code(x, y, z, t) return Float64(x - Float64(1.0 / Float64(Float64(z / y) - Float64(Float64(t / 2.0) / z)))) end
function tmp = code(x, y, z, t) tmp = x - (1.0 / ((z / y) - ((t / 2.0) / z))); end
code[x_, y_, z_, t_] := N[(x - N[(1.0 / N[(N[(z / y), $MachinePrecision] - N[(N[(t / 2.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{1}{\frac{z}{y} - \frac{\frac{t}{2}}{z}}
\end{array}
herbie shell --seed 2025057
(FPCore (x y z t)
:name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
:precision binary64
:alt
(! :herbie-platform default (- x (/ 1 (- (/ z y) (/ (/ t 2) z)))))
(- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))