
(FPCore (x y z) :precision binary64 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
double code(double x, double y, double z) {
return 2.0 * sqrt((((x * y) + (x * z)) + (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 = 2.0d0 * sqrt((((x * y) + (x * z)) + (y * z)))
end function
public static double code(double x, double y, double z) {
return 2.0 * Math.sqrt((((x * y) + (x * z)) + (y * z)));
}
def code(x, y, z): return 2.0 * math.sqrt((((x * y) + (x * z)) + (y * z)))
function code(x, y, z) return Float64(2.0 * sqrt(Float64(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z)))) end
function tmp = code(x, y, z) tmp = 2.0 * sqrt((((x * y) + (x * z)) + (y * z))); end
code[x_, y_, z_] := N[(2.0 * N[Sqrt[N[(N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
double code(double x, double y, double z) {
return 2.0 * sqrt((((x * y) + (x * z)) + (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 = 2.0d0 * sqrt((((x * y) + (x * z)) + (y * z)))
end function
public static double code(double x, double y, double z) {
return 2.0 * Math.sqrt((((x * y) + (x * z)) + (y * z)));
}
def code(x, y, z): return 2.0 * math.sqrt((((x * y) + (x * z)) + (y * z)))
function code(x, y, z) return Float64(2.0 * sqrt(Float64(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z)))) end
function tmp = code(x, y, z) tmp = 2.0 * sqrt((((x * y) + (x * z)) + (y * z))); end
code[x_, y_, z_] := N[(2.0 * N[Sqrt[N[(N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -3.2e+29)
(* (* 2.0 (* (sqrt (/ (+ x z) y)) -1.0)) y)
(if (<= y 0.0009)
(* 2.0 (sqrt (fma z y (* (+ z y) x))))
(* (* 2.0 (sqrt (/ (+ x y) z))) z))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+29) {
tmp = (2.0 * (sqrt(((x + z) / y)) * -1.0)) * y;
} else if (y <= 0.0009) {
tmp = 2.0 * sqrt(fma(z, y, ((z + y) * x)));
} else {
tmp = (2.0 * sqrt(((x + y) / z))) * z;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.2e+29) tmp = Float64(Float64(2.0 * Float64(sqrt(Float64(Float64(x + z) / y)) * -1.0)) * y); elseif (y <= 0.0009) tmp = Float64(2.0 * sqrt(fma(z, y, Float64(Float64(z + y) * x)))); else tmp = Float64(Float64(2.0 * sqrt(Float64(Float64(x + y) / z))) * z); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -3.2e+29], N[(N[(2.0 * N[(N[Sqrt[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision] * -1.0), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 0.0009], N[(2.0 * N[Sqrt[N[(z * y + N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Sqrt[N[(N[(x + y), $MachinePrecision] / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+29}:\\
\;\;\;\;\left(2 \cdot \left(\sqrt{\frac{x + z}{y}} \cdot -1\right)\right) \cdot y\\
\mathbf{elif}\;y \leq 0.0009:\\
\;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(z, y, \left(z + y\right) \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \sqrt{\frac{x + y}{z}}\right) \cdot z\\
\end{array}
\end{array}
if y < -3.19999999999999987e29Initial program 41.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites0.5%
Taylor expanded in y around -inf
lower-*.f64N/A
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lift-+.f6498.5
Applied rewrites98.5%
if -3.19999999999999987e29 < y < 8.9999999999999998e-4Initial program 94.6%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6494.6
Applied rewrites94.6%
if 8.9999999999999998e-4 < y Initial program 47.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.6%
Taylor expanded in z around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-+.f6499.5
Applied rewrites99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 0.0009) (* 2.0 (sqrt (fma z y (* (+ z y) x)))) (* (* 2.0 (sqrt (/ (+ x y) z))) z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= 0.0009) {
tmp = 2.0 * sqrt(fma(z, y, ((z + y) * x)));
} else {
tmp = (2.0 * sqrt(((x + y) / z))) * z;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= 0.0009) tmp = Float64(2.0 * sqrt(fma(z, y, Float64(Float64(z + y) * x)))); else tmp = Float64(Float64(2.0 * sqrt(Float64(Float64(x + y) / z))) * z); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, 0.0009], N[(2.0 * N[Sqrt[N[(z * y + N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Sqrt[N[(N[(x + y), $MachinePrecision] / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0009:\\
\;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(z, y, \left(z + y\right) \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \sqrt{\frac{x + y}{z}}\right) \cdot z\\
\end{array}
\end{array}
if y < 8.9999999999999998e-4Initial program 79.4%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6479.5
Applied rewrites79.5%
if 8.9999999999999998e-4 < y Initial program 47.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.6%
Taylor expanded in z around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-+.f6499.5
Applied rewrites99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -3.2e-255)
(* 2.0 (sqrt (* (+ z y) x)))
(if (<= y 0.0009)
(* 2.0 (sqrt (fma z y (* z x))))
(* (* 2.0 (sqrt (/ (+ x y) z))) z))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e-255) {
tmp = 2.0 * sqrt(((z + y) * x));
} else if (y <= 0.0009) {
tmp = 2.0 * sqrt(fma(z, y, (z * x)));
} else {
tmp = (2.0 * sqrt(((x + y) / z))) * z;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.2e-255) tmp = Float64(2.0 * sqrt(Float64(Float64(z + y) * x))); elseif (y <= 0.0009) tmp = Float64(2.0 * sqrt(fma(z, y, Float64(z * x)))); else tmp = Float64(Float64(2.0 * sqrt(Float64(Float64(x + y) / z))) * z); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -3.2e-255], N[(2.0 * N[Sqrt[N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.0009], N[(2.0 * N[Sqrt[N[(z * y + N[(z * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Sqrt[N[(N[(x + y), $MachinePrecision] / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-255}:\\
\;\;\;\;2 \cdot \sqrt{\left(z + y\right) \cdot x}\\
\mathbf{elif}\;y \leq 0.0009:\\
\;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(z, y, z \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \sqrt{\frac{x + y}{z}}\right) \cdot z\\
\end{array}
\end{array}
if y < -3.19999999999999993e-255Initial program 72.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6472.4
Applied rewrites72.4%
if -3.19999999999999993e-255 < y < 8.9999999999999998e-4Initial program 92.5%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6492.5
Applied rewrites92.5%
Taylor expanded in y around 0
Applied rewrites90.1%
if 8.9999999999999998e-4 < y Initial program 47.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.6%
Taylor expanded in z around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-+.f6499.5
Applied rewrites99.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -3.2e-255)
(* 2.0 (sqrt (* (+ z y) x)))
(if (<= y 0.00095)
(* 2.0 (sqrt (fma z y (* z x))))
(* (* 2.0 (sqrt (/ y z))) z))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e-255) {
tmp = 2.0 * sqrt(((z + y) * x));
} else if (y <= 0.00095) {
tmp = 2.0 * sqrt(fma(z, y, (z * x)));
} else {
tmp = (2.0 * sqrt((y / z))) * z;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.2e-255) tmp = Float64(2.0 * sqrt(Float64(Float64(z + y) * x))); elseif (y <= 0.00095) tmp = Float64(2.0 * sqrt(fma(z, y, Float64(z * x)))); else tmp = Float64(Float64(2.0 * sqrt(Float64(y / z))) * z); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -3.2e-255], N[(2.0 * N[Sqrt[N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.00095], N[(2.0 * N[Sqrt[N[(z * y + N[(z * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Sqrt[N[(y / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-255}:\\
\;\;\;\;2 \cdot \sqrt{\left(z + y\right) \cdot x}\\
\mathbf{elif}\;y \leq 0.00095:\\
\;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(z, y, z \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \sqrt{\frac{y}{z}}\right) \cdot z\\
\end{array}
\end{array}
if y < -3.19999999999999993e-255Initial program 72.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6472.4
Applied rewrites72.4%
if -3.19999999999999993e-255 < y < 9.49999999999999998e-4Initial program 92.5%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6492.5
Applied rewrites92.5%
Taylor expanded in y around 0
Applied rewrites90.1%
if 9.49999999999999998e-4 < y Initial program 47.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -3.2e-255)
(* 2.0 (sqrt (* (+ z y) x)))
(if (<= y 0.00095)
(* 2.0 (sqrt (* (+ y x) z)))
(* (* 2.0 (sqrt (/ y z))) z))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e-255) {
tmp = 2.0 * sqrt(((z + y) * x));
} else if (y <= 0.00095) {
tmp = 2.0 * sqrt(((y + x) * z));
} else {
tmp = (2.0 * sqrt((y / z))) * z;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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.2d-255)) then
tmp = 2.0d0 * sqrt(((z + y) * x))
else if (y <= 0.00095d0) then
tmp = 2.0d0 * sqrt(((y + x) * z))
else
tmp = (2.0d0 * sqrt((y / z))) * z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e-255) {
tmp = 2.0 * Math.sqrt(((z + y) * x));
} else if (y <= 0.00095) {
tmp = 2.0 * Math.sqrt(((y + x) * z));
} else {
tmp = (2.0 * Math.sqrt((y / z))) * z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -3.2e-255: tmp = 2.0 * math.sqrt(((z + y) * x)) elif y <= 0.00095: tmp = 2.0 * math.sqrt(((y + x) * z)) else: tmp = (2.0 * math.sqrt((y / z))) * z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.2e-255) tmp = Float64(2.0 * sqrt(Float64(Float64(z + y) * x))); elseif (y <= 0.00095) tmp = Float64(2.0 * sqrt(Float64(Float64(y + x) * z))); else tmp = Float64(Float64(2.0 * sqrt(Float64(y / z))) * z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -3.2e-255)
tmp = 2.0 * sqrt(((z + y) * x));
elseif (y <= 0.00095)
tmp = 2.0 * sqrt(((y + x) * z));
else
tmp = (2.0 * sqrt((y / z))) * z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -3.2e-255], N[(2.0 * N[Sqrt[N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.00095], N[(2.0 * N[Sqrt[N[(N[(y + x), $MachinePrecision] * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Sqrt[N[(y / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-255}:\\
\;\;\;\;2 \cdot \sqrt{\left(z + y\right) \cdot x}\\
\mathbf{elif}\;y \leq 0.00095:\\
\;\;\;\;2 \cdot \sqrt{\left(y + x\right) \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \sqrt{\frac{y}{z}}\right) \cdot z\\
\end{array}
\end{array}
if y < -3.19999999999999993e-255Initial program 72.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6472.4
Applied rewrites72.4%
if -3.19999999999999993e-255 < y < 9.49999999999999998e-4Initial program 92.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6490.1
Applied rewrites90.1%
if 9.49999999999999998e-4 < y Initial program 47.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -5.2e-253) (* 2.0 (sqrt (* (+ z y) x))) (* 2.0 (sqrt (* (+ y x) z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-253) {
tmp = 2.0 * sqrt(((z + y) * x));
} else {
tmp = 2.0 * sqrt(((y + x) * z));
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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-253)) then
tmp = 2.0d0 * sqrt(((z + y) * x))
else
tmp = 2.0d0 * sqrt(((y + x) * z))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-253) {
tmp = 2.0 * Math.sqrt(((z + y) * x));
} else {
tmp = 2.0 * Math.sqrt(((y + x) * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -5.2e-253: tmp = 2.0 * math.sqrt(((z + y) * x)) else: tmp = 2.0 * math.sqrt(((y + x) * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5.2e-253) tmp = Float64(2.0 * sqrt(Float64(Float64(z + y) * x))); else tmp = Float64(2.0 * sqrt(Float64(Float64(y + x) * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -5.2e-253)
tmp = 2.0 * sqrt(((z + y) * x));
else
tmp = 2.0 * sqrt(((y + x) * z));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -5.2e-253], N[(2.0 * N[Sqrt[N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Sqrt[N[(N[(y + x), $MachinePrecision] * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-253}:\\
\;\;\;\;2 \cdot \sqrt{\left(z + y\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sqrt{\left(y + x\right) \cdot z}\\
\end{array}
\end{array}
if y < -5.2e-253Initial program 72.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6472.4
Applied rewrites72.4%
if -5.2e-253 < y Initial program 70.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6469.5
Applied rewrites69.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -5e-253) (* 2.0 (sqrt (* y x))) (* 2.0 (sqrt (* (+ y x) z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5e-253) {
tmp = 2.0 * sqrt((y * x));
} else {
tmp = 2.0 * sqrt(((y + x) * z));
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-5d-253)) then
tmp = 2.0d0 * sqrt((y * x))
else
tmp = 2.0d0 * sqrt(((y + x) * z))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5e-253) {
tmp = 2.0 * Math.sqrt((y * x));
} else {
tmp = 2.0 * Math.sqrt(((y + x) * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -5e-253: tmp = 2.0 * math.sqrt((y * x)) else: tmp = 2.0 * math.sqrt(((y + x) * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5e-253) tmp = Float64(2.0 * sqrt(Float64(y * x))); else tmp = Float64(2.0 * sqrt(Float64(Float64(y + x) * z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -5e-253)
tmp = 2.0 * sqrt((y * x));
else
tmp = 2.0 * sqrt(((y + x) * z));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -5e-253], N[(2.0 * N[Sqrt[N[(y * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Sqrt[N[(N[(y + x), $MachinePrecision] * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-253}:\\
\;\;\;\;2 \cdot \sqrt{y \cdot x}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sqrt{\left(y + x\right) \cdot z}\\
\end{array}
\end{array}
if y < -4.99999999999999971e-253Initial program 72.1%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6470.3
Applied rewrites70.3%
if -4.99999999999999971e-253 < y Initial program 70.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6469.5
Applied rewrites69.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -5.2e-253) (* 2.0 (sqrt (* y x))) (* 2.0 (sqrt (* z y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-253) {
tmp = 2.0 * sqrt((y * x));
} else {
tmp = 2.0 * sqrt((z * y));
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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-253)) then
tmp = 2.0d0 * sqrt((y * x))
else
tmp = 2.0d0 * sqrt((z * y))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-253) {
tmp = 2.0 * Math.sqrt((y * x));
} else {
tmp = 2.0 * Math.sqrt((z * y));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -5.2e-253: tmp = 2.0 * math.sqrt((y * x)) else: tmp = 2.0 * math.sqrt((z * y)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5.2e-253) tmp = Float64(2.0 * sqrt(Float64(y * x))); else tmp = Float64(2.0 * sqrt(Float64(z * y))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -5.2e-253)
tmp = 2.0 * sqrt((y * x));
else
tmp = 2.0 * sqrt((z * y));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, -5.2e-253], N[(2.0 * N[Sqrt[N[(y * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Sqrt[N[(z * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-253}:\\
\;\;\;\;2 \cdot \sqrt{y \cdot x}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sqrt{z \cdot y}\\
\end{array}
\end{array}
if y < -5.2e-253Initial program 72.1%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6470.3
Applied rewrites70.3%
if -5.2e-253 < y Initial program 70.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6467.4
Applied rewrites67.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* 2.0 (sqrt (* y x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return 2.0 * sqrt((y * x));
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 = 2.0d0 * sqrt((y * x))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return 2.0 * Math.sqrt((y * x));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return 2.0 * math.sqrt((y * x))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(2.0 * sqrt(Float64(y * x))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = 2.0 * sqrt((y * x));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(2.0 * N[Sqrt[N[(y * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
2 \cdot \sqrt{y \cdot x}
\end{array}
Initial program 71.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6436.1
Applied rewrites36.1%
herbie shell --seed 2025113
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:descartes from diagrams-contrib-1.3.0.5"
:precision binary64
(* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))