
(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 10 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 -9.5e+46)
(* 2.0 (exp (* (+ (- (log (/ -1.0 x))) (log (- (+ z y)))) 0.5)))
(if (<= y 4.7e+17)
(* (sqrt (fma (+ y x) z (* y x))) 2.0)
(*
(fma
(* y x)
(sqrt (/ 1.0 (* (+ y x) (* (* z z) z))))
(* (sqrt (/ (+ y x) z)) 2.0))
z))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -9.5e+46) {
tmp = 2.0 * exp(((-log((-1.0 / x)) + log(-(z + y))) * 0.5));
} else if (y <= 4.7e+17) {
tmp = sqrt(fma((y + x), z, (y * x))) * 2.0;
} else {
tmp = fma((y * x), sqrt((1.0 / ((y + x) * ((z * z) * z)))), (sqrt(((y + x) / z)) * 2.0)) * z;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -9.5e+46) tmp = Float64(2.0 * exp(Float64(Float64(Float64(-log(Float64(-1.0 / x))) + log(Float64(-Float64(z + y)))) * 0.5))); elseif (y <= 4.7e+17) tmp = Float64(sqrt(fma(Float64(y + x), z, Float64(y * x))) * 2.0); else tmp = Float64(fma(Float64(y * x), sqrt(Float64(1.0 / Float64(Float64(y + x) * Float64(Float64(z * z) * z)))), Float64(sqrt(Float64(Float64(y + x) / z)) * 2.0)) * 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, -9.5e+46], N[(2.0 * N[Exp[N[(N[((-N[Log[N[(-1.0 / x), $MachinePrecision]], $MachinePrecision]) + N[Log[(-N[(z + y), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.7e+17], N[(N[Sqrt[N[(N[(y + x), $MachinePrecision] * z + N[(y * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(N[(y * x), $MachinePrecision] * N[Sqrt[N[(1.0 / N[(N[(y + x), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(N[Sqrt[N[(N[(y + x), $MachinePrecision] / z), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+46}:\\
\;\;\;\;2 \cdot e^{\left(\left(-\log \left(\frac{-1}{x}\right)\right) + \log \left(-\left(z + y\right)\right)\right) \cdot 0.5}\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+17}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(y + x, z, y \cdot x\right)} \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot x, \sqrt{\frac{1}{\left(y + x\right) \cdot \left(\left(z \cdot z\right) \cdot z\right)}}, \sqrt{\frac{y + x}{z}} \cdot 2\right) \cdot z\\
\end{array}
\end{array}
if y < -9.5000000000000008e46Initial program 34.3%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites32.2%
Taylor expanded in x around -inf
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-log.f64N/A
distribute-lft-inN/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f6489.7
Applied rewrites89.7%
if -9.5000000000000008e46 < y < 4.7e17Initial program 94.5%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.5%
if 4.7e17 < y Initial program 42.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -2.3e+66)
(* 2.0 (exp (* (+ (- (log (/ -1.0 x))) (log (- y))) 0.5)))
(if (<= y -5.5e-283)
(* (sqrt (* (+ (* (/ z y) x) x) y)) 2.0)
(* 2.0 (exp (* (+ (- (- (log z))) (log (+ x y))) 0.5))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e+66) {
tmp = 2.0 * exp(((-log((-1.0 / x)) + log(-y)) * 0.5));
} else if (y <= -5.5e-283) {
tmp = sqrt(((((z / y) * x) + x) * y)) * 2.0;
} else {
tmp = 2.0 * exp(((-(-log(z)) + log((x + y))) * 0.5));
}
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 <= (-2.3d+66)) then
tmp = 2.0d0 * exp(((-log(((-1.0d0) / x)) + log(-y)) * 0.5d0))
else if (y <= (-5.5d-283)) then
tmp = sqrt(((((z / y) * x) + x) * y)) * 2.0d0
else
tmp = 2.0d0 * exp(((-(-log(z)) + log((x + y))) * 0.5d0))
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 <= -2.3e+66) {
tmp = 2.0 * Math.exp(((-Math.log((-1.0 / x)) + Math.log(-y)) * 0.5));
} else if (y <= -5.5e-283) {
tmp = Math.sqrt(((((z / y) * x) + x) * y)) * 2.0;
} else {
tmp = 2.0 * Math.exp(((-(-Math.log(z)) + Math.log((x + y))) * 0.5));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -2.3e+66: tmp = 2.0 * math.exp(((-math.log((-1.0 / x)) + math.log(-y)) * 0.5)) elif y <= -5.5e-283: tmp = math.sqrt(((((z / y) * x) + x) * y)) * 2.0 else: tmp = 2.0 * math.exp(((-(-math.log(z)) + math.log((x + y))) * 0.5)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -2.3e+66) tmp = Float64(2.0 * exp(Float64(Float64(Float64(-log(Float64(-1.0 / x))) + log(Float64(-y))) * 0.5))); elseif (y <= -5.5e-283) tmp = Float64(sqrt(Float64(Float64(Float64(Float64(z / y) * x) + x) * y)) * 2.0); else tmp = Float64(2.0 * exp(Float64(Float64(Float64(-Float64(-log(z))) + log(Float64(x + y))) * 0.5))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= -2.3e+66)
tmp = 2.0 * exp(((-log((-1.0 / x)) + log(-y)) * 0.5));
elseif (y <= -5.5e-283)
tmp = sqrt(((((z / y) * x) + x) * y)) * 2.0;
else
tmp = 2.0 * exp(((-(-log(z)) + log((x + y))) * 0.5));
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, -2.3e+66], N[(2.0 * N[Exp[N[(N[((-N[Log[N[(-1.0 / x), $MachinePrecision]], $MachinePrecision]) + N[Log[(-y)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -5.5e-283], N[(N[Sqrt[N[(N[(N[(N[(z / y), $MachinePrecision] * x), $MachinePrecision] + x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision], N[(2.0 * N[Exp[N[(N[((-(-N[Log[z], $MachinePrecision])) + N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+66}:\\
\;\;\;\;2 \cdot e^{\left(\left(-\log \left(\frac{-1}{x}\right)\right) + \log \left(-y\right)\right) \cdot 0.5}\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{-283}:\\
\;\;\;\;\sqrt{\left(\frac{z}{y} \cdot x + x\right) \cdot y} \cdot 2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot e^{\left(\left(-\left(-\log z\right)\right) + \log \left(x + y\right)\right) \cdot 0.5}\\
\end{array}
\end{array}
if y < -2.3e66Initial program 28.5%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites26.9%
Taylor expanded in x around -inf
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-log.f64N/A
distribute-lft-inN/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f6489.6
Applied rewrites89.6%
Taylor expanded in y around inf
Applied rewrites88.5%
if -2.3e66 < y < -5.49999999999999953e-283Initial program 94.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-+l+N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6494.0
Applied rewrites94.0%
Taylor expanded in x around inf
associate-*r/N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6493.9
Applied rewrites93.9%
if -5.49999999999999953e-283 < y Initial program 70.6%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites65.8%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
log-recN/A
lower-neg.f64N/A
lower-log.f64N/A
lower-log.f64N/A
lower-+.f6490.2
Applied rewrites90.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.1e-301) (* 2.0 (exp (* (+ (- (log (/ -1.0 x))) (log (- (+ z y)))) 0.5))) (* 2.0 (exp (* (+ (- (- (log z))) (log (+ x y))) 0.5)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= 3.1e-301) {
tmp = 2.0 * exp(((-log((-1.0 / x)) + log(-(z + y))) * 0.5));
} else {
tmp = 2.0 * exp(((-(-log(z)) + log((x + y))) * 0.5));
}
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.1d-301) then
tmp = 2.0d0 * exp(((-log(((-1.0d0) / x)) + log(-(z + y))) * 0.5d0))
else
tmp = 2.0d0 * exp(((-(-log(z)) + log((x + y))) * 0.5d0))
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.1e-301) {
tmp = 2.0 * Math.exp(((-Math.log((-1.0 / x)) + Math.log(-(z + y))) * 0.5));
} else {
tmp = 2.0 * Math.exp(((-(-Math.log(z)) + Math.log((x + y))) * 0.5));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= 3.1e-301: tmp = 2.0 * math.exp(((-math.log((-1.0 / x)) + math.log(-(z + y))) * 0.5)) else: tmp = 2.0 * math.exp(((-(-math.log(z)) + math.log((x + y))) * 0.5)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= 3.1e-301) tmp = Float64(2.0 * exp(Float64(Float64(Float64(-log(Float64(-1.0 / x))) + log(Float64(-Float64(z + y)))) * 0.5))); else tmp = Float64(2.0 * exp(Float64(Float64(Float64(-Float64(-log(z))) + log(Float64(x + y))) * 0.5))); 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.1e-301)
tmp = 2.0 * exp(((-log((-1.0 / x)) + log(-(z + y))) * 0.5));
else
tmp = 2.0 * exp(((-(-log(z)) + log((x + y))) * 0.5));
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.1e-301], N[(2.0 * N[Exp[N[(N[((-N[Log[N[(-1.0 / x), $MachinePrecision]], $MachinePrecision]) + N[Log[(-N[(z + y), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Exp[N[(N[((-(-N[Log[z], $MachinePrecision])) + N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.1 \cdot 10^{-301}:\\
\;\;\;\;2 \cdot e^{\left(\left(-\log \left(\frac{-1}{x}\right)\right) + \log \left(-\left(z + y\right)\right)\right) \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot e^{\left(\left(-\left(-\log z\right)\right) + \log \left(x + y\right)\right) \cdot 0.5}\\
\end{array}
\end{array}
if y < 3.10000000000000014e-301Initial program 71.8%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites67.0%
Taylor expanded in x around -inf
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-log.f64N/A
distribute-lft-inN/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f6490.7
Applied rewrites90.7%
if 3.10000000000000014e-301 < y Initial program 70.7%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites65.9%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
log-recN/A
lower-neg.f64N/A
lower-log.f64N/A
lower-log.f64N/A
lower-+.f6490.7
Applied rewrites90.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 2.0 (exp (log (* (sqrt z) (sqrt y))))))
(t_1 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z))))))
(if (<= t_1 5e-157)
t_0
(if (<= t_1 2e+153) (* (sqrt (fma (+ y x) z (* y x))) 2.0) t_0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = 2.0 * exp(log((sqrt(z) * sqrt(y))));
double t_1 = 2.0 * sqrt((((x * y) + (x * z)) + (y * z)));
double tmp;
if (t_1 <= 5e-157) {
tmp = t_0;
} else if (t_1 <= 2e+153) {
tmp = sqrt(fma((y + x), z, (y * x))) * 2.0;
} else {
tmp = t_0;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(2.0 * exp(log(Float64(sqrt(z) * sqrt(y))))) t_1 = Float64(2.0 * sqrt(Float64(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z)))) tmp = 0.0 if (t_1 <= 5e-157) tmp = t_0; elseif (t_1 <= 2e+153) tmp = Float64(sqrt(fma(Float64(y + x), z, Float64(y * x))) * 2.0); else tmp = t_0; end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(2.0 * N[Exp[N[Log[N[(N[Sqrt[z], $MachinePrecision] * N[Sqrt[y], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(2.0 * N[Sqrt[N[(N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e-157], t$95$0, If[LessEqual[t$95$1, 2e+153], N[(N[Sqrt[N[(N[(y + x), $MachinePrecision] * z + N[(y * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := 2 \cdot e^{\log \left(\sqrt{z} \cdot \sqrt{y}\right)}\\
t_1 := 2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{-157}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+153}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(y + x, z, y \cdot x\right)} \cdot 2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) (sqrt.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 y z)))) < 5.0000000000000002e-157 or 2e153 < (*.f64 #s(literal 2 binary64) (sqrt.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 y z)))) Initial program 6.7%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites7.1%
Taylor expanded in x around 0
log-pow-revN/A
pow1/2N/A
lower-log.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f645.0
Applied rewrites5.0%
lift-*.f64N/A
lift-sqrt.f64N/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6444.7
Applied rewrites44.7%
if 5.0000000000000002e-157 < (*.f64 #s(literal 2 binary64) (sqrt.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 y z)))) < 2e153Initial program 99.8%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -5.5e-283) (* (sqrt (* (+ (* (/ z y) x) x) y)) 2.0) (* 2.0 (exp (* (+ (- (- (log z))) (log (+ x y))) 0.5)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e-283) {
tmp = sqrt(((((z / y) * x) + x) * y)) * 2.0;
} else {
tmp = 2.0 * exp(((-(-log(z)) + log((x + y))) * 0.5));
}
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.5d-283)) then
tmp = sqrt(((((z / y) * x) + x) * y)) * 2.0d0
else
tmp = 2.0d0 * exp(((-(-log(z)) + log((x + y))) * 0.5d0))
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.5e-283) {
tmp = Math.sqrt(((((z / y) * x) + x) * y)) * 2.0;
} else {
tmp = 2.0 * Math.exp(((-(-Math.log(z)) + Math.log((x + y))) * 0.5));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= -5.5e-283: tmp = math.sqrt(((((z / y) * x) + x) * y)) * 2.0 else: tmp = 2.0 * math.exp(((-(-math.log(z)) + math.log((x + y))) * 0.5)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5.5e-283) tmp = Float64(sqrt(Float64(Float64(Float64(Float64(z / y) * x) + x) * y)) * 2.0); else tmp = Float64(2.0 * exp(Float64(Float64(Float64(-Float64(-log(z))) + log(Float64(x + y))) * 0.5))); 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.5e-283)
tmp = sqrt(((((z / y) * x) + x) * y)) * 2.0;
else
tmp = 2.0 * exp(((-(-log(z)) + log((x + y))) * 0.5));
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.5e-283], N[(N[Sqrt[N[(N[(N[(N[(z / y), $MachinePrecision] * x), $MachinePrecision] + x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision], N[(2.0 * N[Exp[N[(N[((-(-N[Log[z], $MachinePrecision])) + N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-283}:\\
\;\;\;\;\sqrt{\left(\frac{z}{y} \cdot x + x\right) \cdot y} \cdot 2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot e^{\left(\left(-\left(-\log z\right)\right) + \log \left(x + y\right)\right) \cdot 0.5}\\
\end{array}
\end{array}
if y < -5.49999999999999953e-283Initial program 72.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.2%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-+l+N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6472.2
Applied rewrites72.2%
Taylor expanded in x around inf
associate-*r/N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6472.1
Applied rewrites72.1%
if -5.49999999999999953e-283 < y Initial program 70.6%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow1/2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites65.8%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
log-recN/A
lower-neg.f64N/A
lower-log.f64N/A
lower-log.f64N/A
lower-+.f6490.2
Applied rewrites90.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 6.5e-301) (* 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 <= 6.5e-301) {
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 <= 6.5d-301) 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 <= 6.5e-301) {
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 <= 6.5e-301: 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 <= 6.5e-301) 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 <= 6.5e-301)
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, 6.5e-301], 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 6.5 \cdot 10^{-301}:\\
\;\;\;\;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 < 6.49999999999999991e-301Initial program 71.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6472.0
Applied rewrites72.0%
if 6.49999999999999991e-301 < y Initial program 70.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6470.8
Applied rewrites70.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* (sqrt (fma (+ y x) z (* y x))) 2.0))
assert(x < y && y < z);
double code(double x, double y, double z) {
return sqrt(fma((y + x), z, (y * x))) * 2.0;
}
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(sqrt(fma(Float64(y + x), z, Float64(y * x))) * 2.0) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[Sqrt[N[(N[(y + x), $MachinePrecision] * z + N[(y * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\sqrt{\mathsf{fma}\left(y + x, z, y \cdot x\right)} \cdot 2
\end{array}
Initial program 71.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites71.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -4.5e-268) (* 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 <= -4.5e-268) {
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 <= (-4.5d-268)) 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 <= -4.5e-268) {
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 <= -4.5e-268: 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 <= -4.5e-268) 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 <= -4.5e-268)
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, -4.5e-268], 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 -4.5 \cdot 10^{-268}:\\
\;\;\;\;2 \cdot \sqrt{y \cdot x}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sqrt{\left(y + x\right) \cdot z}\\
\end{array}
\end{array}
if y < -4.5000000000000001e-268Initial program 72.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6470.0
Applied rewrites70.0%
if -4.5000000000000001e-268 < y Initial program 70.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6470.1
Applied rewrites70.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -4.6e-268) (* 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 <= -4.6e-268) {
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 <= (-4.6d-268)) 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 <= -4.6e-268) {
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 <= -4.6e-268: 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 <= -4.6e-268) 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 <= -4.6e-268)
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, -4.6e-268], 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 -4.6 \cdot 10^{-268}:\\
\;\;\;\;2 \cdot \sqrt{y \cdot x}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \sqrt{z \cdot y}\\
\end{array}
\end{array}
if y < -4.60000000000000021e-268Initial program 72.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6470.0
Applied rewrites70.0%
if -4.60000000000000021e-268 < y Initial program 70.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6467.9
Applied rewrites67.9%
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.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6436.5
Applied rewrites36.5%
herbie shell --seed 2025111
(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)))))