
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
double code(double x, double y, double z) {
return (x + y) / (1.0 - (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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) / (1.0d0 - (y / z))
end function
public static double code(double x, double y, double z) {
return (x + y) / (1.0 - (y / z));
}
def code(x, y, z): return (x + y) / (1.0 - (y / z))
function code(x, y, z) return Float64(Float64(x + y) / Float64(1.0 - Float64(y / z))) end
function tmp = code(x, y, z) tmp = (x + y) / (1.0 - (y / z)); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{1 - \frac{y}{z}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
double code(double x, double y, double z) {
return (x + y) / (1.0 - (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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) / (1.0d0 - (y / z))
end function
public static double code(double x, double y, double z) {
return (x + y) / (1.0 - (y / z));
}
def code(x, y, z): return (x + y) / (1.0 - (y / z))
function code(x, y, z) return Float64(Float64(x + y) / Float64(1.0 - Float64(y / z))) end
function tmp = code(x, y, z) tmp = (x + y) / (1.0 - (y / z)); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{1 - \frac{y}{z}}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (+ x y) (- 1.0 (/ y z)))))
(if (or (<= t_0 -5e-267) (not (<= t_0 0.0)))
t_0
(fma z (/ (- (- z) x) y) (- z)))))
double code(double x, double y, double z) {
double t_0 = (x + y) / (1.0 - (y / z));
double tmp;
if ((t_0 <= -5e-267) || !(t_0 <= 0.0)) {
tmp = t_0;
} else {
tmp = fma(z, ((-z - x) / y), -z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x + y) / Float64(1.0 - Float64(y / z))) tmp = 0.0 if ((t_0 <= -5e-267) || !(t_0 <= 0.0)) tmp = t_0; else tmp = fma(z, Float64(Float64(Float64(-z) - x) / y), Float64(-z)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5e-267], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[(z * N[(N[((-z) - x), $MachinePrecision] / y), $MachinePrecision] + (-z)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-267} \lor \neg \left(t\_0 \leq 0\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{\left(-z\right) - x}{y}, -z\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z))) < -4.9999999999999999e-267 or 0.0 < (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z))) Initial program 99.8%
if -4.9999999999999999e-267 < (/.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) (/.f64 y z))) < 0.0Initial program 10.8%
Taylor expanded in y around inf
associate--l+N/A
lower-fma.f64N/A
associate-*r/N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in y around inf
associate--l+N/A
associate-*r/N/A
mul-1-negN/A
*-commutativeN/A
div-subN/A
pow2N/A
+-commutativeN/A
Applied rewrites99.9%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.15e-13) (+ y x) (if (<= z 6.8e+14) (- (/ (* (- z) x) y) z) (fma (+ 1.0 (/ x z)) y x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.15e-13) {
tmp = y + x;
} else if (z <= 6.8e+14) {
tmp = ((-z * x) / y) - z;
} else {
tmp = fma((1.0 + (x / z)), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.15e-13) tmp = Float64(y + x); elseif (z <= 6.8e+14) tmp = Float64(Float64(Float64(Float64(-z) * x) / y) - z); else tmp = fma(Float64(1.0 + Float64(x / z)), y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.15e-13], N[(y + x), $MachinePrecision], If[LessEqual[z, 6.8e+14], N[(N[(N[((-z) * x), $MachinePrecision] / y), $MachinePrecision] - z), $MachinePrecision], N[(N[(1.0 + N[(x / z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{-13}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+14}:\\
\;\;\;\;\frac{\left(-z\right) \cdot x}{y} - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1 + \frac{x}{z}, y, x\right)\\
\end{array}
\end{array}
if z < -2.1499999999999999e-13Initial program 99.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6476.3
Applied rewrites76.3%
if -2.1499999999999999e-13 < z < 6.8e14Initial program 71.1%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6484.2
Applied rewrites84.2%
Taylor expanded in x around 0
lower--.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6486.8
Applied rewrites86.8%
if 6.8e14 < z Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6471.8
Applied rewrites71.8%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (if (<= z -2.15e-13) (+ y x) (if (<= z 6.8e+14) (- (/ (* (- z) x) y) z) (+ (fma y (/ y z) y) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.15e-13) {
tmp = y + x;
} else if (z <= 6.8e+14) {
tmp = ((-z * x) / y) - z;
} else {
tmp = fma(y, (y / z), y) + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.15e-13) tmp = Float64(y + x); elseif (z <= 6.8e+14) tmp = Float64(Float64(Float64(Float64(-z) * x) / y) - z); else tmp = Float64(fma(y, Float64(y / z), y) + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.15e-13], N[(y + x), $MachinePrecision], If[LessEqual[z, 6.8e+14], N[(N[(N[((-z) * x), $MachinePrecision] / y), $MachinePrecision] - z), $MachinePrecision], N[(N[(y * N[(y / z), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{-13}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+14}:\\
\;\;\;\;\frac{\left(-z\right) \cdot x}{y} - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{y}{z}, y\right) + x\\
\end{array}
\end{array}
if z < -2.1499999999999999e-13Initial program 99.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6476.3
Applied rewrites76.3%
if -2.1499999999999999e-13 < z < 6.8e14Initial program 71.1%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6484.2
Applied rewrites84.2%
Taylor expanded in x around 0
lower--.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6486.8
Applied rewrites86.8%
if 6.8e14 < z Initial program 99.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6471.7
Applied rewrites71.7%
Taylor expanded in x around 0
lift-/.f6471.7
Applied rewrites71.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.66e+53) (+ y x) (if (<= z 6.8e+14) (- (fma x (/ z y) z)) (+ (fma y (/ y z) y) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.66e+53) {
tmp = y + x;
} else if (z <= 6.8e+14) {
tmp = -fma(x, (z / y), z);
} else {
tmp = fma(y, (y / z), y) + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.66e+53) tmp = Float64(y + x); elseif (z <= 6.8e+14) tmp = Float64(-fma(x, Float64(z / y), z)); else tmp = Float64(fma(y, Float64(y / z), y) + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.66e+53], N[(y + x), $MachinePrecision], If[LessEqual[z, 6.8e+14], (-N[(x * N[(z / y), $MachinePrecision] + z), $MachinePrecision]), N[(N[(y * N[(y / z), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.66 \cdot 10^{+53}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+14}:\\
\;\;\;\;-\mathsf{fma}\left(x, \frac{z}{y}, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{y}{z}, y\right) + x\\
\end{array}
\end{array}
if z < -1.65999999999999999e53Initial program 100.0%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6484.3
Applied rewrites84.3%
if -1.65999999999999999e53 < z < 6.8e14Initial program 73.3%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6481.1
Applied rewrites81.1%
Taylor expanded in x around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
if 6.8e14 < z Initial program 99.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6471.7
Applied rewrites71.7%
Taylor expanded in x around 0
lift-/.f6471.7
Applied rewrites71.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.66e+53) (not (<= z 6.8e+14))) (+ y x) (- (fma x (/ z y) z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.66e+53) || !(z <= 6.8e+14)) {
tmp = y + x;
} else {
tmp = -fma(x, (z / y), z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -1.66e+53) || !(z <= 6.8e+14)) tmp = Float64(y + x); else tmp = Float64(-fma(x, Float64(z / y), z)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.66e+53], N[Not[LessEqual[z, 6.8e+14]], $MachinePrecision]], N[(y + x), $MachinePrecision], (-N[(x * N[(z / y), $MachinePrecision] + z), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.66 \cdot 10^{+53} \lor \neg \left(z \leq 6.8 \cdot 10^{+14}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-\mathsf{fma}\left(x, \frac{z}{y}, z\right)\\
\end{array}
\end{array}
if z < -1.65999999999999999e53 or 6.8e14 < z Initial program 99.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6477.8
Applied rewrites77.8%
if -1.65999999999999999e53 < z < 6.8e14Initial program 73.3%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6481.1
Applied rewrites81.1%
Taylor expanded in x around 0
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e+34) (- z) (if (<= y -1.9e-58) (/ (* z x) (- y)) (if (<= y 8.2e+51) (+ y x) (- z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+34) {
tmp = -z;
} else if (y <= -1.9e-58) {
tmp = (z * x) / -y;
} else if (y <= 8.2e+51) {
tmp = y + x;
} else {
tmp = -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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-5.2d+34)) then
tmp = -z
else if (y <= (-1.9d-58)) then
tmp = (z * x) / -y
else if (y <= 8.2d+51) then
tmp = y + x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+34) {
tmp = -z;
} else if (y <= -1.9e-58) {
tmp = (z * x) / -y;
} else if (y <= 8.2e+51) {
tmp = y + x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e+34: tmp = -z elif y <= -1.9e-58: tmp = (z * x) / -y elif y <= 8.2e+51: tmp = y + x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e+34) tmp = Float64(-z); elseif (y <= -1.9e-58) tmp = Float64(Float64(z * x) / Float64(-y)); elseif (y <= 8.2e+51) tmp = Float64(y + x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e+34) tmp = -z; elseif (y <= -1.9e-58) tmp = (z * x) / -y; elseif (y <= 8.2e+51) tmp = y + x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e+34], (-z), If[LessEqual[y, -1.9e-58], N[(N[(z * x), $MachinePrecision] / (-y)), $MachinePrecision], If[LessEqual[y, 8.2e+51], N[(y + x), $MachinePrecision], (-z)]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+34}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{-58}:\\
\;\;\;\;\frac{z \cdot x}{-y}\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+51}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -5.19999999999999995e34 or 8.20000000000000021e51 < y Initial program 67.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6468.6
Applied rewrites68.6%
if -5.19999999999999995e34 < y < -1.8999999999999999e-58Initial program 95.9%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6475.1
Applied rewrites75.1%
Taylor expanded in x around inf
*-commutativeN/A
lift-*.f6450.1
Applied rewrites50.1%
if -1.8999999999999999e-58 < y < 8.20000000000000021e51Initial program 99.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6468.6
Applied rewrites68.6%
Final simplification66.8%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e+34) (- z) (if (<= y -1.9e-58) (* (/ (- x) y) z) (if (<= y 8.2e+51) (+ y x) (- z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+34) {
tmp = -z;
} else if (y <= -1.9e-58) {
tmp = (-x / y) * z;
} else if (y <= 8.2e+51) {
tmp = y + x;
} else {
tmp = -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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-5.2d+34)) then
tmp = -z
else if (y <= (-1.9d-58)) then
tmp = (-x / y) * z
else if (y <= 8.2d+51) then
tmp = y + x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+34) {
tmp = -z;
} else if (y <= -1.9e-58) {
tmp = (-x / y) * z;
} else if (y <= 8.2e+51) {
tmp = y + x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e+34: tmp = -z elif y <= -1.9e-58: tmp = (-x / y) * z elif y <= 8.2e+51: tmp = y + x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e+34) tmp = Float64(-z); elseif (y <= -1.9e-58) tmp = Float64(Float64(Float64(-x) / y) * z); elseif (y <= 8.2e+51) tmp = Float64(y + x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e+34) tmp = -z; elseif (y <= -1.9e-58) tmp = (-x / y) * z; elseif (y <= 8.2e+51) tmp = y + x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e+34], (-z), If[LessEqual[y, -1.9e-58], N[(N[((-x) / y), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 8.2e+51], N[(y + x), $MachinePrecision], (-z)]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+34}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{-58}:\\
\;\;\;\;\frac{-x}{y} \cdot z\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+51}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -5.19999999999999995e34 or 8.20000000000000021e51 < y Initial program 67.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6468.6
Applied rewrites68.6%
if -5.19999999999999995e34 < y < -1.8999999999999999e-58Initial program 95.9%
Taylor expanded in y around inf
associate--l+N/A
lower-fma.f64N/A
associate-*r/N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6474.7
Applied rewrites74.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6471.5
Applied rewrites71.5%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-fracN/A
lower-/.f64N/A
lower-neg.f6446.6
Applied rewrites46.6%
if -1.8999999999999999e-58 < y < 8.20000000000000021e51Initial program 99.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6468.6
Applied rewrites68.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.7e+67) (not (<= y 8.2e+51))) (- z) (+ y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e+67) || !(y <= 8.2e+51)) {
tmp = -z;
} else {
tmp = y + 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-3.7d+67)) .or. (.not. (y <= 8.2d+51))) then
tmp = -z
else
tmp = y + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e+67) || !(y <= 8.2e+51)) {
tmp = -z;
} else {
tmp = y + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7e+67) or not (y <= 8.2e+51): tmp = -z else: tmp = y + x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7e+67) || !(y <= 8.2e+51)) tmp = Float64(-z); else tmp = Float64(y + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.7e+67) || ~((y <= 8.2e+51))) tmp = -z; else tmp = y + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7e+67], N[Not[LessEqual[y, 8.2e+51]], $MachinePrecision]], (-z), N[(y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{+67} \lor \neg \left(y \leq 8.2 \cdot 10^{+51}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if y < -3.6999999999999997e67 or 8.20000000000000021e51 < y Initial program 65.8%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6470.8
Applied rewrites70.8%
if -3.6999999999999997e67 < y < 8.20000000000000021e51Initial program 98.6%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6460.0
Applied rewrites60.0%
Final simplification64.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.2e-50) (not (<= y 8.8e-89))) (- z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e-50) || !(y <= 8.8e-89)) {
tmp = -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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-2.2d-50)) .or. (.not. (y <= 8.8d-89))) then
tmp = -z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e-50) || !(y <= 8.8e-89)) {
tmp = -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.2e-50) or not (y <= 8.8e-89): tmp = -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.2e-50) || !(y <= 8.8e-89)) tmp = Float64(-z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.2e-50) || ~((y <= 8.8e-89))) tmp = -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e-50], N[Not[LessEqual[y, 8.8e-89]], $MachinePrecision]], (-z), x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-50} \lor \neg \left(y \leq 8.8 \cdot 10^{-89}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.1999999999999999e-50 or 8.80000000000000048e-89 < y Initial program 76.1%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6455.9
Applied rewrites55.9%
if -2.1999999999999999e-50 < y < 8.80000000000000048e-89Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites62.8%
Final simplification58.1%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 83.8%
Taylor expanded in y around 0
Applied rewrites27.4%
herbie shell --seed 2025085
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"
:precision binary64
:alt
(! :herbie-platform default (if (< y -3742931076268985600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (* (/ (+ y x) (- y)) z) (if (< y 3553466245608673400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (+ x y) (- 1 (/ y z))) (* (/ (+ y x) (- y)) z))))
(/ (+ x y) (- 1.0 (/ y z))))