
(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}
Sampling outcomes in binary64 precision:
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 -5e+20)
(* 2.0 (* (* (pow (/ (+ x z) y) 0.5) -1.0) y))
(if (<= y 7.5e-291)
(* 2.0 (pow (fma z y (fma z x (* y x))) 0.5))
(* 2.0 (fma (sqrt y) (sqrt z) (* 0.5 (* x (pow (/ y z) 0.5))))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5e+20) {
tmp = 2.0 * ((pow(((x + z) / y), 0.5) * -1.0) * y);
} else if (y <= 7.5e-291) {
tmp = 2.0 * pow(fma(z, y, fma(z, x, (y * x))), 0.5);
} else {
tmp = 2.0 * fma(sqrt(y), sqrt(z), (0.5 * (x * pow((y / z), 0.5))));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5e+20) tmp = Float64(2.0 * Float64(Float64((Float64(Float64(x + z) / y) ^ 0.5) * -1.0) * y)); elseif (y <= 7.5e-291) tmp = Float64(2.0 * (fma(z, y, fma(z, x, Float64(y * x))) ^ 0.5)); else tmp = Float64(2.0 * fma(sqrt(y), sqrt(z), Float64(0.5 * Float64(x * (Float64(y / z) ^ 0.5))))); 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, -5e+20], N[(2.0 * N[(N[(N[Power[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision], 0.5], $MachinePrecision] * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.5e-291], N[(2.0 * N[Power[N[(z * y + N[(z * x + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[y], $MachinePrecision] * N[Sqrt[z], $MachinePrecision] + N[(0.5 * N[(x * N[Power[N[(y / z), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+20}:\\
\;\;\;\;2 \cdot \left(\left({\left(\frac{x + z}{y}\right)}^{0.5} \cdot -1\right) \cdot y\right)\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-291}:\\
\;\;\;\;2 \cdot {\left(\mathsf{fma}\left(z, y, \mathsf{fma}\left(z, x, y \cdot x\right)\right)\right)}^{0.5}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(\sqrt{y}, \sqrt{z}, 0.5 \cdot \left(x \cdot {\left(\frac{y}{z}\right)}^{0.5}\right)\right)\\
\end{array}
\end{array}
if y < -5e20Initial program 59.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.1%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6482.2
Applied rewrites82.2%
if -5e20 < y < 7.49999999999999981e-291Initial program 90.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 rewrites84.0%
lift-exp.f64N/A
lift-*.f64N/A
lift-log.f64N/A
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
exp-to-powN/A
lower-pow.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f6490.3
Applied rewrites90.3%
if 7.49999999999999981e-291 < y Initial program 67.5%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
distribute-rgt-inN/A
flip-+N/A
sqrt-divN/A
lower-/.f64N/A
Applied rewrites11.5%
Taylor expanded in y around inf
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6428.8
Applied rewrites28.8%
Taylor expanded in x around 0
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f6427.3
Applied rewrites27.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -5e+20)
(* 2.0 (* (* (pow (/ (+ x z) y) 0.5) -1.0) y))
(if (<= y 7.5e-291)
(* 2.0 (sqrt (+ (* (+ (/ (* z x) y) x) y) (* y z))))
(* 2.0 (fma (sqrt y) (sqrt z) (* 0.5 (* x (pow (/ y z) 0.5))))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -5e+20) {
tmp = 2.0 * ((pow(((x + z) / y), 0.5) * -1.0) * y);
} else if (y <= 7.5e-291) {
tmp = 2.0 * sqrt((((((z * x) / y) + x) * y) + (y * z)));
} else {
tmp = 2.0 * fma(sqrt(y), sqrt(z), (0.5 * (x * pow((y / z), 0.5))));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -5e+20) tmp = Float64(2.0 * Float64(Float64((Float64(Float64(x + z) / y) ^ 0.5) * -1.0) * y)); elseif (y <= 7.5e-291) tmp = Float64(2.0 * sqrt(Float64(Float64(Float64(Float64(Float64(z * x) / y) + x) * y) + Float64(y * z)))); else tmp = Float64(2.0 * fma(sqrt(y), sqrt(z), Float64(0.5 * Float64(x * (Float64(y / z) ^ 0.5))))); 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, -5e+20], N[(2.0 * N[(N[(N[Power[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision], 0.5], $MachinePrecision] * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.5e-291], N[(2.0 * N[Sqrt[N[(N[(N[(N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision] + x), $MachinePrecision] * y), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[y], $MachinePrecision] * N[Sqrt[z], $MachinePrecision] + N[(0.5 * N[(x * N[Power[N[(y / z), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+20}:\\
\;\;\;\;2 \cdot \left(\left({\left(\frac{x + z}{y}\right)}^{0.5} \cdot -1\right) \cdot y\right)\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-291}:\\
\;\;\;\;2 \cdot \sqrt{\left(\frac{z \cdot x}{y} + x\right) \cdot y + y \cdot z}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(\sqrt{y}, \sqrt{z}, 0.5 \cdot \left(x \cdot {\left(\frac{y}{z}\right)}^{0.5}\right)\right)\\
\end{array}
\end{array}
if y < -5e20Initial program 59.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.1%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6482.2
Applied rewrites82.2%
if -5e20 < y < 7.49999999999999981e-291Initial program 90.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6477.2
Applied rewrites77.2%
if 7.49999999999999981e-291 < y Initial program 67.5%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
distribute-rgt-inN/A
flip-+N/A
sqrt-divN/A
lower-/.f64N/A
Applied rewrites11.5%
Taylor expanded in y around inf
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6428.8
Applied rewrites28.8%
Taylor expanded in x around 0
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f6427.3
Applied rewrites27.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -2.2e-81)
(* 2.0 (* (* (pow (/ (+ x z) y) 0.5) -1.0) y))
(if (<= y 7.5e-291)
(*
2.0
(exp
(* (+ (log (fma -1.0 y (* -1.0 z))) (log (pow (/ -1.0 x) -1.0))) 0.5)))
(* 2.0 (fma (sqrt y) (sqrt z) (* 0.5 (* x (pow (/ y z) 0.5))))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -2.2e-81) {
tmp = 2.0 * ((pow(((x + z) / y), 0.5) * -1.0) * y);
} else if (y <= 7.5e-291) {
tmp = 2.0 * exp(((log(fma(-1.0, y, (-1.0 * z))) + log(pow((-1.0 / x), -1.0))) * 0.5));
} else {
tmp = 2.0 * fma(sqrt(y), sqrt(z), (0.5 * (x * pow((y / z), 0.5))));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -2.2e-81) tmp = Float64(2.0 * Float64(Float64((Float64(Float64(x + z) / y) ^ 0.5) * -1.0) * y)); elseif (y <= 7.5e-291) tmp = Float64(2.0 * exp(Float64(Float64(log(fma(-1.0, y, Float64(-1.0 * z))) + log((Float64(-1.0 / x) ^ -1.0))) * 0.5))); else tmp = Float64(2.0 * fma(sqrt(y), sqrt(z), Float64(0.5 * Float64(x * (Float64(y / z) ^ 0.5))))); 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, -2.2e-81], N[(2.0 * N[(N[(N[Power[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision], 0.5], $MachinePrecision] * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.5e-291], N[(2.0 * N[Exp[N[(N[(N[Log[N[(-1.0 * y + N[(-1.0 * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[N[(-1.0 / x), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[y], $MachinePrecision] * N[Sqrt[z], $MachinePrecision] + N[(0.5 * N[(x * N[Power[N[(y / z), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-81}:\\
\;\;\;\;2 \cdot \left(\left({\left(\frac{x + z}{y}\right)}^{0.5} \cdot -1\right) \cdot y\right)\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-291}:\\
\;\;\;\;2 \cdot e^{\left(\log \left(\mathsf{fma}\left(-1, y, -1 \cdot z\right)\right) + \log \left({\left(\frac{-1}{x}\right)}^{-1}\right)\right) \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(\sqrt{y}, \sqrt{z}, 0.5 \cdot \left(x \cdot {\left(\frac{y}{z}\right)}^{0.5}\right)\right)\\
\end{array}
\end{array}
if y < -2.1999999999999999e-81Initial program 68.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.2%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6484.9
Applied rewrites84.9%
if -2.1999999999999999e-81 < y < 7.49999999999999981e-291Initial program 86.0%
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 rewrites80.3%
Taylor expanded in x around -inf
lower-+.f64N/A
lower-log.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
log-pow-revN/A
lower-log.f64N/A
lower-pow.f64N/A
lower-/.f6443.8
Applied rewrites43.8%
if 7.49999999999999981e-291 < y Initial program 67.5%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
distribute-rgt-inN/A
flip-+N/A
sqrt-divN/A
lower-/.f64N/A
Applied rewrites11.5%
Taylor expanded in y around inf
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6428.8
Applied rewrites28.8%
Taylor expanded in x around 0
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f6427.3
Applied rewrites27.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y -4e-310) (* 2.0 (* (* (pow (/ (+ x z) y) 0.5) -1.0) y)) (* 2.0 (fma (sqrt y) (sqrt z) (* 0.5 (* x (pow (/ y z) 0.5)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-310) {
tmp = 2.0 * ((pow(((x + z) / y), 0.5) * -1.0) * y);
} else {
tmp = 2.0 * fma(sqrt(y), sqrt(z), (0.5 * (x * pow((y / z), 0.5))));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -4e-310) tmp = Float64(2.0 * Float64(Float64((Float64(Float64(x + z) / y) ^ 0.5) * -1.0) * y)); else tmp = Float64(2.0 * fma(sqrt(y), sqrt(z), Float64(0.5 * Float64(x * (Float64(y / z) ^ 0.5))))); 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, -4e-310], N[(2.0 * N[(N[(N[Power[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision], 0.5], $MachinePrecision] * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[y], $MachinePrecision] * N[Sqrt[z], $MachinePrecision] + N[(0.5 * N[(x * N[Power[N[(y / z), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-310}:\\
\;\;\;\;2 \cdot \left(\left({\left(\frac{x + z}{y}\right)}^{0.5} \cdot -1\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(\sqrt{y}, \sqrt{z}, 0.5 \cdot \left(x \cdot {\left(\frac{y}{z}\right)}^{0.5}\right)\right)\\
\end{array}
\end{array}
if y < -3.999999999999988e-310Initial program 73.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.1%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6467.0
Applied rewrites67.0%
if -3.999999999999988e-310 < y Initial program 68.5%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
distribute-rgt-inN/A
flip-+N/A
sqrt-divN/A
lower-/.f64N/A
Applied rewrites10.9%
Taylor expanded in y around inf
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6427.5
Applied rewrites27.5%
Taylor expanded in x around 0
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f6426.0
Applied rewrites26.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (pow (/ (+ x z) y) 0.5)))
(if (<= y 5.6e-281)
(* 2.0 (* (* t_0 -1.0) y))
(if (<= y 1e-45)
(*
2.0
(fma
(pow z 0.5)
(pow y 0.5)
(* (* 0.5 (fma z x (* y x))) (pow (pow (* z y) -1.0) 0.5))))
(* 2.0 (* t_0 y))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = pow(((x + z) / y), 0.5);
double tmp;
if (y <= 5.6e-281) {
tmp = 2.0 * ((t_0 * -1.0) * y);
} else if (y <= 1e-45) {
tmp = 2.0 * fma(pow(z, 0.5), pow(y, 0.5), ((0.5 * fma(z, x, (y * x))) * pow(pow((z * y), -1.0), 0.5)));
} else {
tmp = 2.0 * (t_0 * y);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x + z) / y) ^ 0.5 tmp = 0.0 if (y <= 5.6e-281) tmp = Float64(2.0 * Float64(Float64(t_0 * -1.0) * y)); elseif (y <= 1e-45) tmp = Float64(2.0 * fma((z ^ 0.5), (y ^ 0.5), Float64(Float64(0.5 * fma(z, x, Float64(y * x))) * ((Float64(z * y) ^ -1.0) ^ 0.5)))); else tmp = Float64(2.0 * Float64(t_0 * y)); 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[Power[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision], 0.5], $MachinePrecision]}, If[LessEqual[y, 5.6e-281], N[(2.0 * N[(N[(t$95$0 * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1e-45], N[(2.0 * N[(N[Power[z, 0.5], $MachinePrecision] * N[Power[y, 0.5], $MachinePrecision] + N[(N[(0.5 * N[(z * x + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[N[Power[N[(z * y), $MachinePrecision], -1.0], $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(t$95$0 * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{x + z}{y}\right)}^{0.5}\\
\mathbf{if}\;y \leq 5.6 \cdot 10^{-281}:\\
\;\;\;\;2 \cdot \left(\left(t\_0 \cdot -1\right) \cdot y\right)\\
\mathbf{elif}\;y \leq 10^{-45}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left({z}^{0.5}, {y}^{0.5}, \left(0.5 \cdot \mathsf{fma}\left(z, x, y \cdot x\right)\right) \cdot {\left({\left(z \cdot y\right)}^{-1}\right)}^{0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t\_0 \cdot y\right)\\
\end{array}
\end{array}
if y < 5.6000000000000001e-281Initial program 74.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.2%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6461.7
Applied rewrites61.7%
if 5.6000000000000001e-281 < y < 9.99999999999999984e-46Initial program 80.8%
Taylor expanded in x around 0
pow1/2N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
distribute-lft-inN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
Applied rewrites17.2%
if 9.99999999999999984e-46 < y Initial program 58.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.4%
Taylor expanded in y around inf
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6484.7
Applied rewrites84.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 (pow (/ (+ x z) y) 0.5))) (if (<= y -4e-310) (* 2.0 (* (* t_0 -1.0) y)) (* 2.0 (* t_0 y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = pow(((x + z) / y), 0.5);
double tmp;
if (y <= -4e-310) {
tmp = 2.0 * ((t_0 * -1.0) * y);
} else {
tmp = 2.0 * (t_0 * 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) :: t_0
real(8) :: tmp
t_0 = ((x + z) / y) ** 0.5d0
if (y <= (-4d-310)) then
tmp = 2.0d0 * ((t_0 * (-1.0d0)) * y)
else
tmp = 2.0d0 * (t_0 * y)
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = Math.pow(((x + z) / y), 0.5);
double tmp;
if (y <= -4e-310) {
tmp = 2.0 * ((t_0 * -1.0) * y);
} else {
tmp = 2.0 * (t_0 * y);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = math.pow(((x + z) / y), 0.5) tmp = 0 if y <= -4e-310: tmp = 2.0 * ((t_0 * -1.0) * y) else: tmp = 2.0 * (t_0 * y) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(x + z) / y) ^ 0.5 tmp = 0.0 if (y <= -4e-310) tmp = Float64(2.0 * Float64(Float64(t_0 * -1.0) * y)); else tmp = Float64(2.0 * Float64(t_0 * y)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = ((x + z) / y) ^ 0.5;
tmp = 0.0;
if (y <= -4e-310)
tmp = 2.0 * ((t_0 * -1.0) * y);
else
tmp = 2.0 * (t_0 * 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_] := Block[{t$95$0 = N[Power[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision], 0.5], $MachinePrecision]}, If[LessEqual[y, -4e-310], N[(2.0 * N[(N[(t$95$0 * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(t$95$0 * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{x + z}{y}\right)}^{0.5}\\
\mathbf{if}\;y \leq -4 \cdot 10^{-310}:\\
\;\;\;\;2 \cdot \left(\left(t\_0 \cdot -1\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t\_0 \cdot y\right)\\
\end{array}
\end{array}
if y < -3.999999999999988e-310Initial program 73.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.1%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6467.0
Applied rewrites67.0%
if -3.999999999999988e-310 < y Initial program 68.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites47.2%
Taylor expanded in y around inf
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6458.5
Applied rewrites58.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= x -2.9e-300)
(*
2.0
(*
(* (pow (* (* -1.0 x) (- (* -1.0 (/ z (* x y))) (pow y -1.0))) 0.5) -1.0)
y))
(fma (* (pow (pow (* z x) -1.0) 0.5) y) (+ z x) (* (pow (* z x) 0.5) 2.0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -2.9e-300) {
tmp = 2.0 * ((pow(((-1.0 * x) * ((-1.0 * (z / (x * y))) - pow(y, -1.0))), 0.5) * -1.0) * y);
} else {
tmp = fma((pow(pow((z * x), -1.0), 0.5) * y), (z + x), (pow((z * x), 0.5) * 2.0));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -2.9e-300) tmp = Float64(2.0 * Float64(Float64((Float64(Float64(-1.0 * x) * Float64(Float64(-1.0 * Float64(z / Float64(x * y))) - (y ^ -1.0))) ^ 0.5) * -1.0) * y)); else tmp = fma(Float64(((Float64(z * x) ^ -1.0) ^ 0.5) * y), Float64(z + x), Float64((Float64(z * x) ^ 0.5) * 2.0)); 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[x, -2.9e-300], N[(2.0 * N[(N[(N[Power[N[(N[(-1.0 * x), $MachinePrecision] * N[(N[(-1.0 * N[(z / N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[y, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[Power[N[(z * x), $MachinePrecision], -1.0], $MachinePrecision], 0.5], $MachinePrecision] * y), $MachinePrecision] * N[(z + x), $MachinePrecision] + N[(N[Power[N[(z * x), $MachinePrecision], 0.5], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{-300}:\\
\;\;\;\;2 \cdot \left(\left({\left(\left(-1 \cdot x\right) \cdot \left(-1 \cdot \frac{z}{x \cdot y} - {y}^{-1}\right)\right)}^{0.5} \cdot -1\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\left({\left(z \cdot x\right)}^{-1}\right)}^{0.5} \cdot y, z + x, {\left(z \cdot x\right)}^{0.5} \cdot 2\right)\\
\end{array}
\end{array}
if x < -2.89999999999999992e-300Initial program 74.1%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites12.8%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6442.1
Applied rewrites42.1%
Taylor expanded in x around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f6436.5
Applied rewrites36.5%
if -2.89999999999999992e-300 < x Initial program 67.4%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f6420.9
Applied rewrites20.9%
Final simplification28.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* 2.0 (* (* (pow (/ (+ x z) y) 0.5) -1.0) y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return 2.0 * ((pow(((x + z) / y), 0.5) * -1.0) * y);
}
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 * (((((x + z) / y) ** 0.5d0) * (-1.0d0)) * y)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return 2.0 * ((Math.pow(((x + z) / y), 0.5) * -1.0) * y);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return 2.0 * ((math.pow(((x + z) / y), 0.5) * -1.0) * y)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(2.0 * Float64(Float64((Float64(Float64(x + z) / y) ^ 0.5) * -1.0) * y)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = 2.0 * (((((x + z) / y) ^ 0.5) * -1.0) * y);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(2.0 * N[(N[(N[Power[N[(N[(x + z), $MachinePrecision] / y), $MachinePrecision], 0.5], $MachinePrecision] * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
2 \cdot \left(\left({\left(\frac{x + z}{y}\right)}^{0.5} \cdot -1\right) \cdot y\right)
\end{array}
Initial program 70.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites26.5%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6430.7
Applied rewrites30.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= y -3.7e-146)
(*
2.0
(*
(*
(pow
(* (* -1.0 x) (* (* -1.0 z) (+ (pow (* x y) -1.0) (pow (* y z) -1.0))))
0.5)
-1.0)
y))
(fma (* (pow (pow (* z x) -1.0) 0.5) y) (+ z x) (* (pow (* z x) 0.5) 2.0))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e-146) {
tmp = 2.0 * ((pow(((-1.0 * x) * ((-1.0 * z) * (pow((x * y), -1.0) + pow((y * z), -1.0)))), 0.5) * -1.0) * y);
} else {
tmp = fma((pow(pow((z * x), -1.0), 0.5) * y), (z + x), (pow((z * x), 0.5) * 2.0));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= -3.7e-146) tmp = Float64(2.0 * Float64(Float64((Float64(Float64(-1.0 * x) * Float64(Float64(-1.0 * z) * Float64((Float64(x * y) ^ -1.0) + (Float64(y * z) ^ -1.0)))) ^ 0.5) * -1.0) * y)); else tmp = fma(Float64(((Float64(z * x) ^ -1.0) ^ 0.5) * y), Float64(z + x), Float64((Float64(z * x) ^ 0.5) * 2.0)); 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.7e-146], N[(2.0 * N[(N[(N[Power[N[(N[(-1.0 * x), $MachinePrecision] * N[(N[(-1.0 * z), $MachinePrecision] * N[(N[Power[N[(x * y), $MachinePrecision], -1.0], $MachinePrecision] + N[Power[N[(y * z), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] * -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[Power[N[(z * x), $MachinePrecision], -1.0], $MachinePrecision], 0.5], $MachinePrecision] * y), $MachinePrecision] * N[(z + x), $MachinePrecision] + N[(N[Power[N[(z * x), $MachinePrecision], 0.5], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-146}:\\
\;\;\;\;2 \cdot \left(\left({\left(\left(-1 \cdot x\right) \cdot \left(\left(-1 \cdot z\right) \cdot \left({\left(x \cdot y\right)}^{-1} + {\left(y \cdot z\right)}^{-1}\right)\right)\right)}^{0.5} \cdot -1\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\left({\left(z \cdot x\right)}^{-1}\right)}^{0.5} \cdot y, z + x, {\left(z \cdot x\right)}^{0.5} \cdot 2\right)\\
\end{array}
\end{array}
if y < -3.69999999999999986e-146Initial program 69.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites1.2%
Taylor expanded in y around -inf
sqrt-pow2N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-+.f6482.1
Applied rewrites82.1%
Taylor expanded in x around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f6468.2
Applied rewrites68.2%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f64N/A
lower-+.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-*.f6463.5
Applied rewrites63.5%
if -3.69999999999999986e-146 < y Initial program 71.2%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f6432.6
Applied rewrites32.6%
Final simplification43.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (* (pow (pow (* z x) -1.0) 0.5) y) (+ z x) (* (pow (* z x) 0.5) 2.0)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((pow(pow((z * x), -1.0), 0.5) * y), (z + x), (pow((z * x), 0.5) * 2.0));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(((Float64(z * x) ^ -1.0) ^ 0.5) * y), Float64(z + x), Float64((Float64(z * x) ^ 0.5) * 2.0)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(N[Power[N[Power[N[(z * x), $MachinePrecision], -1.0], $MachinePrecision], 0.5], $MachinePrecision] * y), $MachinePrecision] * N[(z + x), $MachinePrecision] + N[(N[Power[N[(z * x), $MachinePrecision], 0.5], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left({\left({\left(z \cdot x\right)}^{-1}\right)}^{0.5} \cdot y, z + x, {\left(z \cdot x\right)}^{0.5} \cdot 2\right)
\end{array}
Initial program 70.7%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f6423.7
Applied rewrites23.7%
herbie shell --seed 2025065
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:descartes from diagrams-contrib-1.3.0.5"
:precision binary64
:alt
(! :herbie-platform default (if (< z 763695009057367500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (* 2 (sqrt (+ (* (+ x y) z) (* x y)))) (* (* (+ (* 1/4 (* (* (pow y -3/4) (* (pow z -3/4) x)) (+ y z))) (* (pow z 1/4) (pow y 1/4))) (+ (* 1/4 (* (* (pow y -3/4) (* (pow z -3/4) x)) (+ y z))) (* (pow z 1/4) (pow y 1/4)))) 2)))
(* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))