
(FPCore (x y z t) :precision binary64 (+ (+ (+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y))) (- (sqrt (+ z 1.0)) (sqrt z))) (- (sqrt (+ t 1.0)) (sqrt t))))
double code(double x, double y, double z, double t) {
return (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + (sqrt((z + 1.0)) - sqrt(z))) + (sqrt((t + 1.0)) - sqrt(t));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + (sqrt((z + 1.0d0)) - sqrt(z))) + (sqrt((t + 1.0d0)) - sqrt(t))
end function
public static double code(double x, double y, double z, double t) {
return (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + (Math.sqrt((z + 1.0)) - Math.sqrt(z))) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
}
def code(x, y, z, t): return (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + (math.sqrt((z + 1.0)) - math.sqrt(z))) + (math.sqrt((t + 1.0)) - math.sqrt(t))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + Float64(sqrt(Float64(z + 1.0)) - sqrt(z))) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) end
function tmp = code(x, y, z, t) tmp = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + (sqrt((z + 1.0)) - sqrt(z))) + (sqrt((t + 1.0)) - sqrt(t)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + \left(\sqrt{z + 1} - \sqrt{z}\right)\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 24 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (+ (+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y))) (- (sqrt (+ z 1.0)) (sqrt z))) (- (sqrt (+ t 1.0)) (sqrt t))))
double code(double x, double y, double z, double t) {
return (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + (sqrt((z + 1.0)) - sqrt(z))) + (sqrt((t + 1.0)) - sqrt(t));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + (sqrt((z + 1.0d0)) - sqrt(z))) + (sqrt((t + 1.0d0)) - sqrt(t))
end function
public static double code(double x, double y, double z, double t) {
return (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + (Math.sqrt((z + 1.0)) - Math.sqrt(z))) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
}
def code(x, y, z, t): return (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + (math.sqrt((z + 1.0)) - math.sqrt(z))) + (math.sqrt((t + 1.0)) - math.sqrt(t))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + Float64(sqrt(Float64(z + 1.0)) - sqrt(z))) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) end
function tmp = code(x, y, z, t) tmp = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + (sqrt((z + 1.0)) - sqrt(z))) + (sqrt((t + 1.0)) - sqrt(t)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + \left(\sqrt{z + 1} - \sqrt{z}\right)\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)
\end{array}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ y 1.0)))
(t_2 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_3 (sqrt (+ t 1.0)))
(t_4 (/ 1.0 (+ t_1 (sqrt y))))
(t_5 (- (sqrt (+ x 1.0)) (sqrt x)))
(t_6 (+ (+ t_5 (- t_1 (sqrt y))) t_2))
(t_7 (- t_3 (sqrt t)))
(t_8 (+ t_6 t_7)))
(if (<= t_8 0.001)
(+
(+
(+
(/
(fma
-0.125
(/ 1.0 (sqrt x))
(fma 0.0625 (sqrt (pow x -3.0)) (* 0.5 (sqrt x))))
x)
t_4)
t_2)
t_7)
(if (<= t_8 2.00005)
(+
(+ (+ t_5 t_4) (/ (fma -0.125 (/ 1.0 (sqrt z)) (* 0.5 (sqrt z))) z))
t_7)
(+ t_6 (/ (- (* t_3 t_3) (* (sqrt t) (sqrt t))) (+ t_3 (sqrt t))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((y + 1.0));
double t_2 = sqrt((z + 1.0)) - sqrt(z);
double t_3 = sqrt((t + 1.0));
double t_4 = 1.0 / (t_1 + sqrt(y));
double t_5 = sqrt((x + 1.0)) - sqrt(x);
double t_6 = (t_5 + (t_1 - sqrt(y))) + t_2;
double t_7 = t_3 - sqrt(t);
double t_8 = t_6 + t_7;
double tmp;
if (t_8 <= 0.001) {
tmp = (((fma(-0.125, (1.0 / sqrt(x)), fma(0.0625, sqrt(pow(x, -3.0)), (0.5 * sqrt(x)))) / x) + t_4) + t_2) + t_7;
} else if (t_8 <= 2.00005) {
tmp = ((t_5 + t_4) + (fma(-0.125, (1.0 / sqrt(z)), (0.5 * sqrt(z))) / z)) + t_7;
} else {
tmp = t_6 + (((t_3 * t_3) - (sqrt(t) * sqrt(t))) / (t_3 + sqrt(t)));
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(y + 1.0)) t_2 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_3 = sqrt(Float64(t + 1.0)) t_4 = Float64(1.0 / Float64(t_1 + sqrt(y))) t_5 = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) t_6 = Float64(Float64(t_5 + Float64(t_1 - sqrt(y))) + t_2) t_7 = Float64(t_3 - sqrt(t)) t_8 = Float64(t_6 + t_7) tmp = 0.0 if (t_8 <= 0.001) tmp = Float64(Float64(Float64(Float64(fma(-0.125, Float64(1.0 / sqrt(x)), fma(0.0625, sqrt((x ^ -3.0)), Float64(0.5 * sqrt(x)))) / x) + t_4) + t_2) + t_7); elseif (t_8 <= 2.00005) tmp = Float64(Float64(Float64(t_5 + t_4) + Float64(fma(-0.125, Float64(1.0 / sqrt(z)), Float64(0.5 * sqrt(z))) / z)) + t_7); else tmp = Float64(t_6 + Float64(Float64(Float64(t_3 * t_3) - Float64(sqrt(t) * sqrt(t))) / Float64(t_3 + sqrt(t)))); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(1.0 / N[(t$95$1 + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[(t$95$5 + N[(t$95$1 - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]}, Block[{t$95$7 = N[(t$95$3 - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$8 = N[(t$95$6 + t$95$7), $MachinePrecision]}, If[LessEqual[t$95$8, 0.001], N[(N[(N[(N[(N[(-0.125 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(0.0625 * N[Sqrt[N[Power[x, -3.0], $MachinePrecision]], $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + t$95$4), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$7), $MachinePrecision], If[LessEqual[t$95$8, 2.00005], N[(N[(N[(t$95$5 + t$95$4), $MachinePrecision] + N[(N[(-0.125 * N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] + t$95$7), $MachinePrecision], N[(t$95$6 + N[(N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[Sqrt[t], $MachinePrecision] * N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$3 + N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{y + 1}\\
t_2 := \sqrt{z + 1} - \sqrt{z}\\
t_3 := \sqrt{t + 1}\\
t_4 := \frac{1}{t\_1 + \sqrt{y}}\\
t_5 := \sqrt{x + 1} - \sqrt{x}\\
t_6 := \left(t\_5 + \left(t\_1 - \sqrt{y}\right)\right) + t\_2\\
t_7 := t\_3 - \sqrt{t}\\
t_8 := t\_6 + t\_7\\
\mathbf{if}\;t\_8 \leq 0.001:\\
\;\;\;\;\left(\left(\frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{x}}, \mathsf{fma}\left(0.0625, \sqrt{{x}^{-3}}, 0.5 \cdot \sqrt{x}\right)\right)}{x} + t\_4\right) + t\_2\right) + t\_7\\
\mathbf{elif}\;t\_8 \leq 2.00005:\\
\;\;\;\;\left(\left(t\_5 + t\_4\right) + \frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{z}}, 0.5 \cdot \sqrt{z}\right)}{z}\right) + t\_7\\
\mathbf{else}:\\
\;\;\;\;t\_6 + \frac{t\_3 \cdot t\_3 - \sqrt{t} \cdot \sqrt{t}}{t\_3 + \sqrt{t}}\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1e-3Initial program 7.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites6.9%
Taylor expanded in y around 0
Applied rewrites31.9%
Taylor expanded in x around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-fma.f64N/A
lower-sqrt.f64N/A
pow-flipN/A
lower-pow.f64N/A
metadata-evalN/A
lower-*.f64N/A
lift-sqrt.f6456.2
Applied rewrites56.2%
if 1e-3 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0000499999999999Initial program 95.2%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites95.2%
Taylor expanded in y around 0
Applied rewrites96.2%
Taylor expanded in z around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6461.0
Applied rewrites61.0%
if 2.0000499999999999 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites99.0%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_2 (- (sqrt (+ t 1.0)) (sqrt t)))
(t_3
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_1)
t_2)))
(if (<= t_3 0.001)
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_1) (- (sqrt t) (sqrt t)))
(if (<= t_3 1.00002)
(+ (+ (- (+ 1.0 (* 0.5 (/ 1.0 (sqrt y)))) (sqrt x)) t_1) t_2)
(if (<= t_3 2.01)
(-
(+ (sqrt (+ 1.0 x)) (+ (sqrt (+ 1.0 y)) (* 0.5 (/ 1.0 (sqrt z)))))
(+ (sqrt x) (sqrt y)))
(+
(+ (- (+ 2.0 (fma 0.5 x (* 0.5 y))) (+ (sqrt y) (sqrt x))) t_1)
t_2))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double t_2 = sqrt((t + 1.0)) - sqrt(t);
double t_3 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + t_2;
double tmp;
if (t_3 <= 0.001) {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
} else if (t_3 <= 1.00002) {
tmp = (((1.0 + (0.5 * (1.0 / sqrt(y)))) - sqrt(x)) + t_1) + t_2;
} else if (t_3 <= 2.01) {
tmp = (sqrt((1.0 + x)) + (sqrt((1.0 + y)) + (0.5 * (1.0 / sqrt(z))))) - (sqrt(x) + sqrt(y));
} else {
tmp = (((2.0 + fma(0.5, x, (0.5 * y))) - (sqrt(y) + sqrt(x))) + t_1) + t_2;
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_2 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) t_3 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + t_2) tmp = 0.0 if (t_3 <= 0.001) tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_1) + Float64(sqrt(t) - sqrt(t))); elseif (t_3 <= 1.00002) tmp = Float64(Float64(Float64(Float64(1.0 + Float64(0.5 * Float64(1.0 / sqrt(y)))) - sqrt(x)) + t_1) + t_2); elseif (t_3 <= 2.01) tmp = Float64(Float64(sqrt(Float64(1.0 + x)) + Float64(sqrt(Float64(1.0 + y)) + Float64(0.5 * Float64(1.0 / sqrt(z))))) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(Float64(Float64(2.0 + fma(0.5, x, Float64(0.5 * y))) - Float64(sqrt(y) + sqrt(x))) + t_1) + t_2); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision]}, If[LessEqual[t$95$3, 0.001], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 1.00002], N[(N[(N[(N[(1.0 + N[(0.5 * N[(1.0 / N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[t$95$3, 2.01], N[(N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[(N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision] + N[(0.5 * N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(2.0 + N[(0.5 * x + N[(0.5 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
t_2 := \sqrt{t + 1} - \sqrt{t}\\
t_3 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + t\_2\\
\mathbf{if}\;t\_3 \leq 0.001:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_3 \leq 1.00002:\\
\;\;\;\;\left(\left(\left(1 + 0.5 \cdot \frac{1}{\sqrt{y}}\right) - \sqrt{x}\right) + t\_1\right) + t\_2\\
\mathbf{elif}\;t\_3 \leq 2.01:\\
\;\;\;\;\left(\sqrt{1 + x} + \left(\sqrt{1 + y} + 0.5 \cdot \frac{1}{\sqrt{z}}\right)\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(2 + \mathsf{fma}\left(0.5, x, 0.5 \cdot y\right)\right) - \left(\sqrt{y} + \sqrt{x}\right)\right) + t\_1\right) + t\_2\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1e-3Initial program 7.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites6.9%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6429.0
Applied rewrites29.0%
if 1e-3 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1.00001999999999991Initial program 94.1%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites94.0%
Taylor expanded in y around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6453.2
Applied rewrites53.2%
Taylor expanded in x around 0
Applied rewrites18.2%
if 1.00001999999999991 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0099999999999998Initial program 95.6%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.2%
Taylor expanded in z around inf
lift-sqrt.f642.2
Applied rewrites2.2%
Taylor expanded in z around inf
lower--.f64N/A
Applied rewrites18.9%
if 2.0099999999999998 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.2%
Taylor expanded in x around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6465.9
Applied rewrites65.9%
Taylor expanded in y around 0
lower-+.f64N/A
lower-fma.f64N/A
lower-*.f6461.6
Applied rewrites61.6%
Final simplification33.2%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_2 (- (sqrt (+ t 1.0)) (sqrt t)))
(t_3
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_1)
t_2))
(t_4 (sqrt (+ 1.0 x)))
(t_5 (/ 1.0 (sqrt z))))
(if (<= t_3 0.0)
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_1) (- (sqrt t) (sqrt t)))
(if (<= t_3 1.0)
(+ (+ (- t_4 (sqrt x)) (* -0.5 t_5)) t_2)
(if (<= t_3 2.01)
(- (+ t_4 (+ (sqrt (+ 1.0 y)) (* 0.5 t_5))) (+ (sqrt x) (sqrt y)))
(+
(+ (- (+ 2.0 (fma 0.5 x (* 0.5 y))) (+ (sqrt y) (sqrt x))) t_1)
t_2))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double t_2 = sqrt((t + 1.0)) - sqrt(t);
double t_3 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + t_2;
double t_4 = sqrt((1.0 + x));
double t_5 = 1.0 / sqrt(z);
double tmp;
if (t_3 <= 0.0) {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
} else if (t_3 <= 1.0) {
tmp = ((t_4 - sqrt(x)) + (-0.5 * t_5)) + t_2;
} else if (t_3 <= 2.01) {
tmp = (t_4 + (sqrt((1.0 + y)) + (0.5 * t_5))) - (sqrt(x) + sqrt(y));
} else {
tmp = (((2.0 + fma(0.5, x, (0.5 * y))) - (sqrt(y) + sqrt(x))) + t_1) + t_2;
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_2 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) t_3 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + t_2) t_4 = sqrt(Float64(1.0 + x)) t_5 = Float64(1.0 / sqrt(z)) tmp = 0.0 if (t_3 <= 0.0) tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_1) + Float64(sqrt(t) - sqrt(t))); elseif (t_3 <= 1.0) tmp = Float64(Float64(Float64(t_4 - sqrt(x)) + Float64(-0.5 * t_5)) + t_2); elseif (t_3 <= 2.01) tmp = Float64(Float64(t_4 + Float64(sqrt(Float64(1.0 + y)) + Float64(0.5 * t_5))) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(Float64(Float64(2.0 + fma(0.5, x, Float64(0.5 * y))) - Float64(sqrt(y) + sqrt(x))) + t_1) + t_2); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, 0.0], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 1.0], N[(N[(N[(t$95$4 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * t$95$5), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[t$95$3, 2.01], N[(N[(t$95$4 + N[(N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision] + N[(0.5 * t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(2.0 + N[(0.5 * x + N[(0.5 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
t_2 := \sqrt{t + 1} - \sqrt{t}\\
t_3 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + t\_2\\
t_4 := \sqrt{1 + x}\\
t_5 := \frac{1}{\sqrt{z}}\\
\mathbf{if}\;t\_3 \leq 0:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_3 \leq 1:\\
\;\;\;\;\left(\left(t\_4 - \sqrt{x}\right) + -0.5 \cdot t\_5\right) + t\_2\\
\mathbf{elif}\;t\_3 \leq 2.01:\\
\;\;\;\;\left(t\_4 + \left(\sqrt{1 + y} + 0.5 \cdot t\_5\right)\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(2 + \mathsf{fma}\left(0.5, x, 0.5 \cdot y\right)\right) - \left(\sqrt{y} + \sqrt{x}\right)\right) + t\_1\right) + t\_2\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 0.0Initial program 3.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites3.4%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6430.1
Applied rewrites30.1%
if 0.0 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 96.3%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.3%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6451.1
Applied rewrites51.1%
Taylor expanded in z around -inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6440.4
Applied rewrites40.4%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0099999999999998Initial program 94.4%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lift-sqrt.f642.2
Applied rewrites2.2%
Taylor expanded in z around inf
lower--.f64N/A
Applied rewrites19.3%
if 2.0099999999999998 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.2%
Taylor expanded in x around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6465.9
Applied rewrites65.9%
Taylor expanded in y around 0
lower-+.f64N/A
lower-fma.f64N/A
lower-*.f6461.6
Applied rewrites61.6%
Final simplification37.4%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_2 (- (sqrt (+ t 1.0)) (sqrt t)))
(t_3
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_1)
t_2))
(t_4 (sqrt (+ 1.0 x)))
(t_5 (/ 1.0 (sqrt z))))
(if (<= t_3 0.0)
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_1) (- (sqrt t) (sqrt t)))
(if (<= t_3 1.0)
(+ (+ (- t_4 (sqrt x)) (* -0.5 t_5)) t_2)
(if (<= t_3 2.01)
(- (+ t_4 (+ (sqrt (+ 1.0 y)) (* 0.5 t_5))) (+ (sqrt x) (sqrt y)))
(+ (+ (- (+ 2.0 (* 0.5 x)) (+ (sqrt y) (sqrt x))) t_1) t_2))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double t_2 = sqrt((t + 1.0)) - sqrt(t);
double t_3 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + t_2;
double t_4 = sqrt((1.0 + x));
double t_5 = 1.0 / sqrt(z);
double tmp;
if (t_3 <= 0.0) {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
} else if (t_3 <= 1.0) {
tmp = ((t_4 - sqrt(x)) + (-0.5 * t_5)) + t_2;
} else if (t_3 <= 2.01) {
tmp = (t_4 + (sqrt((1.0 + y)) + (0.5 * t_5))) - (sqrt(x) + sqrt(y));
} else {
tmp = (((2.0 + (0.5 * x)) - (sqrt(y) + sqrt(x))) + t_1) + t_2;
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: t_5
real(8) :: tmp
t_1 = sqrt((z + 1.0d0)) - sqrt(z)
t_2 = sqrt((t + 1.0d0)) - sqrt(t)
t_3 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_1) + t_2
t_4 = sqrt((1.0d0 + x))
t_5 = 1.0d0 / sqrt(z)
if (t_3 <= 0.0d0) then
tmp = ((0.5d0 * (1.0d0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t))
else if (t_3 <= 1.0d0) then
tmp = ((t_4 - sqrt(x)) + ((-0.5d0) * t_5)) + t_2
else if (t_3 <= 2.01d0) then
tmp = (t_4 + (sqrt((1.0d0 + y)) + (0.5d0 * t_5))) - (sqrt(x) + sqrt(y))
else
tmp = (((2.0d0 + (0.5d0 * x)) - (sqrt(y) + sqrt(x))) + t_1) + t_2
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_2 = Math.sqrt((t + 1.0)) - Math.sqrt(t);
double t_3 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_1) + t_2;
double t_4 = Math.sqrt((1.0 + x));
double t_5 = 1.0 / Math.sqrt(z);
double tmp;
if (t_3 <= 0.0) {
tmp = ((0.5 * (1.0 / Math.sqrt(x))) + t_1) + (Math.sqrt(t) - Math.sqrt(t));
} else if (t_3 <= 1.0) {
tmp = ((t_4 - Math.sqrt(x)) + (-0.5 * t_5)) + t_2;
} else if (t_3 <= 2.01) {
tmp = (t_4 + (Math.sqrt((1.0 + y)) + (0.5 * t_5))) - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = (((2.0 + (0.5 * x)) - (Math.sqrt(y) + Math.sqrt(x))) + t_1) + t_2;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((z + 1.0)) - math.sqrt(z) t_2 = math.sqrt((t + 1.0)) - math.sqrt(t) t_3 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_1) + t_2 t_4 = math.sqrt((1.0 + x)) t_5 = 1.0 / math.sqrt(z) tmp = 0 if t_3 <= 0.0: tmp = ((0.5 * (1.0 / math.sqrt(x))) + t_1) + (math.sqrt(t) - math.sqrt(t)) elif t_3 <= 1.0: tmp = ((t_4 - math.sqrt(x)) + (-0.5 * t_5)) + t_2 elif t_3 <= 2.01: tmp = (t_4 + (math.sqrt((1.0 + y)) + (0.5 * t_5))) - (math.sqrt(x) + math.sqrt(y)) else: tmp = (((2.0 + (0.5 * x)) - (math.sqrt(y) + math.sqrt(x))) + t_1) + t_2 return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_2 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) t_3 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + t_2) t_4 = sqrt(Float64(1.0 + x)) t_5 = Float64(1.0 / sqrt(z)) tmp = 0.0 if (t_3 <= 0.0) tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_1) + Float64(sqrt(t) - sqrt(t))); elseif (t_3 <= 1.0) tmp = Float64(Float64(Float64(t_4 - sqrt(x)) + Float64(-0.5 * t_5)) + t_2); elseif (t_3 <= 2.01) tmp = Float64(Float64(t_4 + Float64(sqrt(Float64(1.0 + y)) + Float64(0.5 * t_5))) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(Float64(Float64(2.0 + Float64(0.5 * x)) - Float64(sqrt(y) + sqrt(x))) + t_1) + t_2); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((z + 1.0)) - sqrt(z);
t_2 = sqrt((t + 1.0)) - sqrt(t);
t_3 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + t_2;
t_4 = sqrt((1.0 + x));
t_5 = 1.0 / sqrt(z);
tmp = 0.0;
if (t_3 <= 0.0)
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
elseif (t_3 <= 1.0)
tmp = ((t_4 - sqrt(x)) + (-0.5 * t_5)) + t_2;
elseif (t_3 <= 2.01)
tmp = (t_4 + (sqrt((1.0 + y)) + (0.5 * t_5))) - (sqrt(x) + sqrt(y));
else
tmp = (((2.0 + (0.5 * x)) - (sqrt(y) + sqrt(x))) + t_1) + t_2;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, 0.0], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 1.0], N[(N[(N[(t$95$4 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * t$95$5), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[t$95$3, 2.01], N[(N[(t$95$4 + N[(N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision] + N[(0.5 * t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(2.0 + N[(0.5 * x), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
t_2 := \sqrt{t + 1} - \sqrt{t}\\
t_3 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + t\_2\\
t_4 := \sqrt{1 + x}\\
t_5 := \frac{1}{\sqrt{z}}\\
\mathbf{if}\;t\_3 \leq 0:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_3 \leq 1:\\
\;\;\;\;\left(\left(t\_4 - \sqrt{x}\right) + -0.5 \cdot t\_5\right) + t\_2\\
\mathbf{elif}\;t\_3 \leq 2.01:\\
\;\;\;\;\left(t\_4 + \left(\sqrt{1 + y} + 0.5 \cdot t\_5\right)\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(2 + 0.5 \cdot x\right) - \left(\sqrt{y} + \sqrt{x}\right)\right) + t\_1\right) + t\_2\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 0.0Initial program 3.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites3.4%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6430.1
Applied rewrites30.1%
if 0.0 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 96.3%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.3%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6451.1
Applied rewrites51.1%
Taylor expanded in z around -inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6440.4
Applied rewrites40.4%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0099999999999998Initial program 94.4%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lift-sqrt.f642.2
Applied rewrites2.2%
Taylor expanded in z around inf
lower--.f64N/A
Applied rewrites19.3%
if 2.0099999999999998 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.2%
Taylor expanded in x around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6465.9
Applied rewrites65.9%
Taylor expanded in y around 0
lower-+.f64N/A
lower-*.f6460.0
Applied rewrites60.0%
Final simplification36.9%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_2 (sqrt (+ 1.0 y)))
(t_3 (- (sqrt (+ t 1.0)) (sqrt t)))
(t_4
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_1)
t_3))
(t_5 (sqrt (+ 1.0 x)))
(t_6 (/ 1.0 (sqrt z))))
(if (<= t_4 0.0)
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_1) (- (sqrt t) (sqrt t)))
(if (<= t_4 1.0)
(+ (+ (- t_5 (sqrt x)) (* -0.5 t_6)) t_3)
(if (<= t_4 2.01)
(- (+ t_5 (+ t_2 (* 0.5 t_6))) (+ (sqrt x) (sqrt y)))
(-
(+ 1.0 (+ t_2 (sqrt (+ 1.0 z))))
(+ (sqrt x) (+ (sqrt y) (sqrt z)))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double t_2 = sqrt((1.0 + y));
double t_3 = sqrt((t + 1.0)) - sqrt(t);
double t_4 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + t_3;
double t_5 = sqrt((1.0 + x));
double t_6 = 1.0 / sqrt(z);
double tmp;
if (t_4 <= 0.0) {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
} else if (t_4 <= 1.0) {
tmp = ((t_5 - sqrt(x)) + (-0.5 * t_6)) + t_3;
} else if (t_4 <= 2.01) {
tmp = (t_5 + (t_2 + (0.5 * t_6))) - (sqrt(x) + sqrt(y));
} else {
tmp = (1.0 + (t_2 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: t_5
real(8) :: t_6
real(8) :: tmp
t_1 = sqrt((z + 1.0d0)) - sqrt(z)
t_2 = sqrt((1.0d0 + y))
t_3 = sqrt((t + 1.0d0)) - sqrt(t)
t_4 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_1) + t_3
t_5 = sqrt((1.0d0 + x))
t_6 = 1.0d0 / sqrt(z)
if (t_4 <= 0.0d0) then
tmp = ((0.5d0 * (1.0d0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t))
else if (t_4 <= 1.0d0) then
tmp = ((t_5 - sqrt(x)) + ((-0.5d0) * t_6)) + t_3
else if (t_4 <= 2.01d0) then
tmp = (t_5 + (t_2 + (0.5d0 * t_6))) - (sqrt(x) + sqrt(y))
else
tmp = (1.0d0 + (t_2 + sqrt((1.0d0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)))
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_2 = Math.sqrt((1.0 + y));
double t_3 = Math.sqrt((t + 1.0)) - Math.sqrt(t);
double t_4 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_1) + t_3;
double t_5 = Math.sqrt((1.0 + x));
double t_6 = 1.0 / Math.sqrt(z);
double tmp;
if (t_4 <= 0.0) {
tmp = ((0.5 * (1.0 / Math.sqrt(x))) + t_1) + (Math.sqrt(t) - Math.sqrt(t));
} else if (t_4 <= 1.0) {
tmp = ((t_5 - Math.sqrt(x)) + (-0.5 * t_6)) + t_3;
} else if (t_4 <= 2.01) {
tmp = (t_5 + (t_2 + (0.5 * t_6))) - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = (1.0 + (t_2 + Math.sqrt((1.0 + z)))) - (Math.sqrt(x) + (Math.sqrt(y) + Math.sqrt(z)));
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((z + 1.0)) - math.sqrt(z) t_2 = math.sqrt((1.0 + y)) t_3 = math.sqrt((t + 1.0)) - math.sqrt(t) t_4 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_1) + t_3 t_5 = math.sqrt((1.0 + x)) t_6 = 1.0 / math.sqrt(z) tmp = 0 if t_4 <= 0.0: tmp = ((0.5 * (1.0 / math.sqrt(x))) + t_1) + (math.sqrt(t) - math.sqrt(t)) elif t_4 <= 1.0: tmp = ((t_5 - math.sqrt(x)) + (-0.5 * t_6)) + t_3 elif t_4 <= 2.01: tmp = (t_5 + (t_2 + (0.5 * t_6))) - (math.sqrt(x) + math.sqrt(y)) else: tmp = (1.0 + (t_2 + math.sqrt((1.0 + z)))) - (math.sqrt(x) + (math.sqrt(y) + math.sqrt(z))) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_2 = sqrt(Float64(1.0 + y)) t_3 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) t_4 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + t_3) t_5 = sqrt(Float64(1.0 + x)) t_6 = Float64(1.0 / sqrt(z)) tmp = 0.0 if (t_4 <= 0.0) tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_1) + Float64(sqrt(t) - sqrt(t))); elseif (t_4 <= 1.0) tmp = Float64(Float64(Float64(t_5 - sqrt(x)) + Float64(-0.5 * t_6)) + t_3); elseif (t_4 <= 2.01) tmp = Float64(Float64(t_5 + Float64(t_2 + Float64(0.5 * t_6))) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(1.0 + Float64(t_2 + sqrt(Float64(1.0 + z)))) - Float64(sqrt(x) + Float64(sqrt(y) + sqrt(z)))); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((z + 1.0)) - sqrt(z);
t_2 = sqrt((1.0 + y));
t_3 = sqrt((t + 1.0)) - sqrt(t);
t_4 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + t_3;
t_5 = sqrt((1.0 + x));
t_6 = 1.0 / sqrt(z);
tmp = 0.0;
if (t_4 <= 0.0)
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
elseif (t_4 <= 1.0)
tmp = ((t_5 - sqrt(x)) + (-0.5 * t_6)) + t_3;
elseif (t_4 <= 2.01)
tmp = (t_5 + (t_2 + (0.5 * t_6))) - (sqrt(x) + sqrt(y));
else
tmp = (1.0 + (t_2 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + t$95$3), $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$6 = N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, 0.0], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 1.0], N[(N[(N[(t$95$5 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * t$95$6), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision], If[LessEqual[t$95$4, 2.01], N[(N[(t$95$5 + N[(t$95$2 + N[(0.5 * t$95$6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(t$95$2 + N[Sqrt[N[(1.0 + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
t_2 := \sqrt{1 + y}\\
t_3 := \sqrt{t + 1} - \sqrt{t}\\
t_4 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + t\_3\\
t_5 := \sqrt{1 + x}\\
t_6 := \frac{1}{\sqrt{z}}\\
\mathbf{if}\;t\_4 \leq 0:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_4 \leq 1:\\
\;\;\;\;\left(\left(t\_5 - \sqrt{x}\right) + -0.5 \cdot t\_6\right) + t\_3\\
\mathbf{elif}\;t\_4 \leq 2.01:\\
\;\;\;\;\left(t\_5 + \left(t\_2 + 0.5 \cdot t\_6\right)\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_2 + \sqrt{1 + z}\right)\right) - \left(\sqrt{x} + \left(\sqrt{y} + \sqrt{z}\right)\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 0.0Initial program 3.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites3.4%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6430.1
Applied rewrites30.1%
if 0.0 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 96.3%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.3%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6451.1
Applied rewrites51.1%
Taylor expanded in z around -inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6440.4
Applied rewrites40.4%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0099999999999998Initial program 94.4%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lift-sqrt.f642.2
Applied rewrites2.2%
Taylor expanded in z around inf
lower--.f64N/A
Applied rewrites19.3%
if 2.0099999999999998 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.2%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites23.4%
Taylor expanded in x around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6423.3
Applied rewrites23.3%
Final simplification25.1%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ 1.0 y)))
(t_2 (sqrt (+ 1.0 x)))
(t_3 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_4
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_3)
(- (sqrt (+ t 1.0)) (sqrt t))))
(t_5 (- (sqrt t) (sqrt t))))
(if (<= t_4 0.0)
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_3) t_5)
(if (<= t_4 1.0)
(+ (+ (- t_2 (sqrt x)) (- (sqrt z) (sqrt z))) t_5)
(if (<= t_4 2.01)
(- (+ t_2 (+ t_1 (* 0.5 (/ 1.0 (sqrt z))))) (+ (sqrt x) (sqrt y)))
(-
(+ 1.0 (+ t_1 (sqrt (+ 1.0 z))))
(+ (sqrt x) (+ (sqrt y) (sqrt z)))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((1.0 + y));
double t_2 = sqrt((1.0 + x));
double t_3 = sqrt((z + 1.0)) - sqrt(z);
double t_4 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_3) + (sqrt((t + 1.0)) - sqrt(t));
double t_5 = sqrt(t) - sqrt(t);
double tmp;
if (t_4 <= 0.0) {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_3) + t_5;
} else if (t_4 <= 1.0) {
tmp = ((t_2 - sqrt(x)) + (sqrt(z) - sqrt(z))) + t_5;
} else if (t_4 <= 2.01) {
tmp = (t_2 + (t_1 + (0.5 * (1.0 / sqrt(z))))) - (sqrt(x) + sqrt(y));
} else {
tmp = (1.0 + (t_1 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: t_5
real(8) :: tmp
t_1 = sqrt((1.0d0 + y))
t_2 = sqrt((1.0d0 + x))
t_3 = sqrt((z + 1.0d0)) - sqrt(z)
t_4 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_3) + (sqrt((t + 1.0d0)) - sqrt(t))
t_5 = sqrt(t) - sqrt(t)
if (t_4 <= 0.0d0) then
tmp = ((0.5d0 * (1.0d0 / sqrt(x))) + t_3) + t_5
else if (t_4 <= 1.0d0) then
tmp = ((t_2 - sqrt(x)) + (sqrt(z) - sqrt(z))) + t_5
else if (t_4 <= 2.01d0) then
tmp = (t_2 + (t_1 + (0.5d0 * (1.0d0 / sqrt(z))))) - (sqrt(x) + sqrt(y))
else
tmp = (1.0d0 + (t_1 + sqrt((1.0d0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)))
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((1.0 + y));
double t_2 = Math.sqrt((1.0 + x));
double t_3 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_4 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_3) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
double t_5 = Math.sqrt(t) - Math.sqrt(t);
double tmp;
if (t_4 <= 0.0) {
tmp = ((0.5 * (1.0 / Math.sqrt(x))) + t_3) + t_5;
} else if (t_4 <= 1.0) {
tmp = ((t_2 - Math.sqrt(x)) + (Math.sqrt(z) - Math.sqrt(z))) + t_5;
} else if (t_4 <= 2.01) {
tmp = (t_2 + (t_1 + (0.5 * (1.0 / Math.sqrt(z))))) - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = (1.0 + (t_1 + Math.sqrt((1.0 + z)))) - (Math.sqrt(x) + (Math.sqrt(y) + Math.sqrt(z)));
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((1.0 + y)) t_2 = math.sqrt((1.0 + x)) t_3 = math.sqrt((z + 1.0)) - math.sqrt(z) t_4 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_3) + (math.sqrt((t + 1.0)) - math.sqrt(t)) t_5 = math.sqrt(t) - math.sqrt(t) tmp = 0 if t_4 <= 0.0: tmp = ((0.5 * (1.0 / math.sqrt(x))) + t_3) + t_5 elif t_4 <= 1.0: tmp = ((t_2 - math.sqrt(x)) + (math.sqrt(z) - math.sqrt(z))) + t_5 elif t_4 <= 2.01: tmp = (t_2 + (t_1 + (0.5 * (1.0 / math.sqrt(z))))) - (math.sqrt(x) + math.sqrt(y)) else: tmp = (1.0 + (t_1 + math.sqrt((1.0 + z)))) - (math.sqrt(x) + (math.sqrt(y) + math.sqrt(z))) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(1.0 + y)) t_2 = sqrt(Float64(1.0 + x)) t_3 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_4 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_3) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) t_5 = Float64(sqrt(t) - sqrt(t)) tmp = 0.0 if (t_4 <= 0.0) tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_3) + t_5); elseif (t_4 <= 1.0) tmp = Float64(Float64(Float64(t_2 - sqrt(x)) + Float64(sqrt(z) - sqrt(z))) + t_5); elseif (t_4 <= 2.01) tmp = Float64(Float64(t_2 + Float64(t_1 + Float64(0.5 * Float64(1.0 / sqrt(z))))) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(1.0 + Float64(t_1 + sqrt(Float64(1.0 + z)))) - Float64(sqrt(x) + Float64(sqrt(y) + sqrt(z)))); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((1.0 + y));
t_2 = sqrt((1.0 + x));
t_3 = sqrt((z + 1.0)) - sqrt(z);
t_4 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_3) + (sqrt((t + 1.0)) - sqrt(t));
t_5 = sqrt(t) - sqrt(t);
tmp = 0.0;
if (t_4 <= 0.0)
tmp = ((0.5 * (1.0 / sqrt(x))) + t_3) + t_5;
elseif (t_4 <= 1.0)
tmp = ((t_2 - sqrt(x)) + (sqrt(z) - sqrt(z))) + t_5;
elseif (t_4 <= 2.01)
tmp = (t_2 + (t_1 + (0.5 * (1.0 / sqrt(z))))) - (sqrt(x) + sqrt(y));
else
tmp = (1.0 + (t_1 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, 0.0], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$5), $MachinePrecision], If[LessEqual[t$95$4, 1.0], N[(N[(N[(t$95$2 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[z], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$5), $MachinePrecision], If[LessEqual[t$95$4, 2.01], N[(N[(t$95$2 + N[(t$95$1 + N[(0.5 * N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(t$95$1 + N[Sqrt[N[(1.0 + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{1 + y}\\
t_2 := \sqrt{1 + x}\\
t_3 := \sqrt{z + 1} - \sqrt{z}\\
t_4 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_3\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
t_5 := \sqrt{t} - \sqrt{t}\\
\mathbf{if}\;t\_4 \leq 0:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_3\right) + t\_5\\
\mathbf{elif}\;t\_4 \leq 1:\\
\;\;\;\;\left(\left(t\_2 - \sqrt{x}\right) + \left(\sqrt{z} - \sqrt{z}\right)\right) + t\_5\\
\mathbf{elif}\;t\_4 \leq 2.01:\\
\;\;\;\;\left(t\_2 + \left(t\_1 + 0.5 \cdot \frac{1}{\sqrt{z}}\right)\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_1 + \sqrt{1 + z}\right)\right) - \left(\sqrt{x} + \left(\sqrt{y} + \sqrt{z}\right)\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 0.0Initial program 3.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites3.4%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6430.1
Applied rewrites30.1%
if 0.0 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 96.3%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.3%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6451.1
Applied rewrites51.1%
Taylor expanded in t around inf
Applied rewrites28.5%
Taylor expanded in z around inf
Applied rewrites18.7%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0099999999999998Initial program 94.4%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lift-sqrt.f642.2
Applied rewrites2.2%
Taylor expanded in z around inf
lower--.f64N/A
Applied rewrites19.3%
if 2.0099999999999998 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.2%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites23.4%
Taylor expanded in x around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6423.3
Applied rewrites23.3%
Final simplification21.2%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ 1.0 y)))
(t_2 (sqrt (+ 1.0 x)))
(t_3 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_4
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_3)
(- (sqrt (+ t 1.0)) (sqrt t))))
(t_5 (- (sqrt t) (sqrt t))))
(if (<= t_4 0.0)
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_3) t_5)
(if (<= t_4 1.0)
(+ (+ (- t_2 (sqrt x)) (- (sqrt z) (sqrt z))) t_5)
(if (<= t_4 2.0)
(- (+ t_2 t_1) (+ (sqrt x) (sqrt y)))
(-
(+ 1.0 (+ t_1 (sqrt (+ 1.0 z))))
(+ (sqrt x) (+ (sqrt y) (sqrt z)))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((1.0 + y));
double t_2 = sqrt((1.0 + x));
double t_3 = sqrt((z + 1.0)) - sqrt(z);
double t_4 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_3) + (sqrt((t + 1.0)) - sqrt(t));
double t_5 = sqrt(t) - sqrt(t);
double tmp;
if (t_4 <= 0.0) {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_3) + t_5;
} else if (t_4 <= 1.0) {
tmp = ((t_2 - sqrt(x)) + (sqrt(z) - sqrt(z))) + t_5;
} else if (t_4 <= 2.0) {
tmp = (t_2 + t_1) - (sqrt(x) + sqrt(y));
} else {
tmp = (1.0 + (t_1 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: t_5
real(8) :: tmp
t_1 = sqrt((1.0d0 + y))
t_2 = sqrt((1.0d0 + x))
t_3 = sqrt((z + 1.0d0)) - sqrt(z)
t_4 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_3) + (sqrt((t + 1.0d0)) - sqrt(t))
t_5 = sqrt(t) - sqrt(t)
if (t_4 <= 0.0d0) then
tmp = ((0.5d0 * (1.0d0 / sqrt(x))) + t_3) + t_5
else if (t_4 <= 1.0d0) then
tmp = ((t_2 - sqrt(x)) + (sqrt(z) - sqrt(z))) + t_5
else if (t_4 <= 2.0d0) then
tmp = (t_2 + t_1) - (sqrt(x) + sqrt(y))
else
tmp = (1.0d0 + (t_1 + sqrt((1.0d0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)))
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((1.0 + y));
double t_2 = Math.sqrt((1.0 + x));
double t_3 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_4 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_3) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
double t_5 = Math.sqrt(t) - Math.sqrt(t);
double tmp;
if (t_4 <= 0.0) {
tmp = ((0.5 * (1.0 / Math.sqrt(x))) + t_3) + t_5;
} else if (t_4 <= 1.0) {
tmp = ((t_2 - Math.sqrt(x)) + (Math.sqrt(z) - Math.sqrt(z))) + t_5;
} else if (t_4 <= 2.0) {
tmp = (t_2 + t_1) - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = (1.0 + (t_1 + Math.sqrt((1.0 + z)))) - (Math.sqrt(x) + (Math.sqrt(y) + Math.sqrt(z)));
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((1.0 + y)) t_2 = math.sqrt((1.0 + x)) t_3 = math.sqrt((z + 1.0)) - math.sqrt(z) t_4 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_3) + (math.sqrt((t + 1.0)) - math.sqrt(t)) t_5 = math.sqrt(t) - math.sqrt(t) tmp = 0 if t_4 <= 0.0: tmp = ((0.5 * (1.0 / math.sqrt(x))) + t_3) + t_5 elif t_4 <= 1.0: tmp = ((t_2 - math.sqrt(x)) + (math.sqrt(z) - math.sqrt(z))) + t_5 elif t_4 <= 2.0: tmp = (t_2 + t_1) - (math.sqrt(x) + math.sqrt(y)) else: tmp = (1.0 + (t_1 + math.sqrt((1.0 + z)))) - (math.sqrt(x) + (math.sqrt(y) + math.sqrt(z))) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(1.0 + y)) t_2 = sqrt(Float64(1.0 + x)) t_3 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_4 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_3) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) t_5 = Float64(sqrt(t) - sqrt(t)) tmp = 0.0 if (t_4 <= 0.0) tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_3) + t_5); elseif (t_4 <= 1.0) tmp = Float64(Float64(Float64(t_2 - sqrt(x)) + Float64(sqrt(z) - sqrt(z))) + t_5); elseif (t_4 <= 2.0) tmp = Float64(Float64(t_2 + t_1) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(1.0 + Float64(t_1 + sqrt(Float64(1.0 + z)))) - Float64(sqrt(x) + Float64(sqrt(y) + sqrt(z)))); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((1.0 + y));
t_2 = sqrt((1.0 + x));
t_3 = sqrt((z + 1.0)) - sqrt(z);
t_4 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_3) + (sqrt((t + 1.0)) - sqrt(t));
t_5 = sqrt(t) - sqrt(t);
tmp = 0.0;
if (t_4 <= 0.0)
tmp = ((0.5 * (1.0 / sqrt(x))) + t_3) + t_5;
elseif (t_4 <= 1.0)
tmp = ((t_2 - sqrt(x)) + (sqrt(z) - sqrt(z))) + t_5;
elseif (t_4 <= 2.0)
tmp = (t_2 + t_1) - (sqrt(x) + sqrt(y));
else
tmp = (1.0 + (t_1 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, 0.0], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$5), $MachinePrecision], If[LessEqual[t$95$4, 1.0], N[(N[(N[(t$95$2 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[z], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$5), $MachinePrecision], If[LessEqual[t$95$4, 2.0], N[(N[(t$95$2 + t$95$1), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(t$95$1 + N[Sqrt[N[(1.0 + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{1 + y}\\
t_2 := \sqrt{1 + x}\\
t_3 := \sqrt{z + 1} - \sqrt{z}\\
t_4 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_3\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
t_5 := \sqrt{t} - \sqrt{t}\\
\mathbf{if}\;t\_4 \leq 0:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_3\right) + t\_5\\
\mathbf{elif}\;t\_4 \leq 1:\\
\;\;\;\;\left(\left(t\_2 - \sqrt{x}\right) + \left(\sqrt{z} - \sqrt{z}\right)\right) + t\_5\\
\mathbf{elif}\;t\_4 \leq 2:\\
\;\;\;\;\left(t\_2 + t\_1\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_1 + \sqrt{1 + z}\right)\right) - \left(\sqrt{x} + \left(\sqrt{y} + \sqrt{z}\right)\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 0.0Initial program 3.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites3.4%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6430.1
Applied rewrites30.1%
if 0.0 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 96.3%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.3%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6451.1
Applied rewrites51.1%
Taylor expanded in t around inf
Applied rewrites28.5%
Taylor expanded in z around inf
Applied rewrites18.7%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2Initial program 96.1%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6418.9
Applied rewrites18.9%
if 2 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 96.9%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites21.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6421.5
Applied rewrites21.5%
Final simplification20.5%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ y 1.0)))
(t_2 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_3 (/ 1.0 (+ t_1 (sqrt y))))
(t_4 (sqrt (+ t 1.0)))
(t_5 (- (sqrt (+ x 1.0)) (sqrt x)))
(t_6 (+ (+ t_5 (- t_1 (sqrt y))) t_2))
(t_7 (- t_4 (sqrt t)))
(t_8 (+ t_6 t_7)))
(if (<= t_8 0.001)
(+
(+ (+ (/ (fma -0.125 (/ 1.0 (sqrt x)) (* 0.5 (sqrt x))) x) t_3) t_2)
t_7)
(if (<= t_8 2.00005)
(+
(+ (+ t_5 t_3) (/ (fma -0.125 (/ 1.0 (sqrt z)) (* 0.5 (sqrt z))) z))
t_7)
(+ t_6 (/ (- (* t_4 t_4) (* (sqrt t) (sqrt t))) (+ t_4 (sqrt t))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((y + 1.0));
double t_2 = sqrt((z + 1.0)) - sqrt(z);
double t_3 = 1.0 / (t_1 + sqrt(y));
double t_4 = sqrt((t + 1.0));
double t_5 = sqrt((x + 1.0)) - sqrt(x);
double t_6 = (t_5 + (t_1 - sqrt(y))) + t_2;
double t_7 = t_4 - sqrt(t);
double t_8 = t_6 + t_7;
double tmp;
if (t_8 <= 0.001) {
tmp = (((fma(-0.125, (1.0 / sqrt(x)), (0.5 * sqrt(x))) / x) + t_3) + t_2) + t_7;
} else if (t_8 <= 2.00005) {
tmp = ((t_5 + t_3) + (fma(-0.125, (1.0 / sqrt(z)), (0.5 * sqrt(z))) / z)) + t_7;
} else {
tmp = t_6 + (((t_4 * t_4) - (sqrt(t) * sqrt(t))) / (t_4 + sqrt(t)));
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(y + 1.0)) t_2 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_3 = Float64(1.0 / Float64(t_1 + sqrt(y))) t_4 = sqrt(Float64(t + 1.0)) t_5 = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) t_6 = Float64(Float64(t_5 + Float64(t_1 - sqrt(y))) + t_2) t_7 = Float64(t_4 - sqrt(t)) t_8 = Float64(t_6 + t_7) tmp = 0.0 if (t_8 <= 0.001) tmp = Float64(Float64(Float64(Float64(fma(-0.125, Float64(1.0 / sqrt(x)), Float64(0.5 * sqrt(x))) / x) + t_3) + t_2) + t_7); elseif (t_8 <= 2.00005) tmp = Float64(Float64(Float64(t_5 + t_3) + Float64(fma(-0.125, Float64(1.0 / sqrt(z)), Float64(0.5 * sqrt(z))) / z)) + t_7); else tmp = Float64(t_6 + Float64(Float64(Float64(t_4 * t_4) - Float64(sqrt(t) * sqrt(t))) / Float64(t_4 + sqrt(t)))); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 / N[(t$95$1 + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[(t$95$5 + N[(t$95$1 - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]}, Block[{t$95$7 = N[(t$95$4 - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$8 = N[(t$95$6 + t$95$7), $MachinePrecision]}, If[LessEqual[t$95$8, 0.001], N[(N[(N[(N[(N[(-0.125 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$7), $MachinePrecision], If[LessEqual[t$95$8, 2.00005], N[(N[(N[(t$95$5 + t$95$3), $MachinePrecision] + N[(N[(-0.125 * N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] + t$95$7), $MachinePrecision], N[(t$95$6 + N[(N[(N[(t$95$4 * t$95$4), $MachinePrecision] - N[(N[Sqrt[t], $MachinePrecision] * N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$4 + N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{y + 1}\\
t_2 := \sqrt{z + 1} - \sqrt{z}\\
t_3 := \frac{1}{t\_1 + \sqrt{y}}\\
t_4 := \sqrt{t + 1}\\
t_5 := \sqrt{x + 1} - \sqrt{x}\\
t_6 := \left(t\_5 + \left(t\_1 - \sqrt{y}\right)\right) + t\_2\\
t_7 := t\_4 - \sqrt{t}\\
t_8 := t\_6 + t\_7\\
\mathbf{if}\;t\_8 \leq 0.001:\\
\;\;\;\;\left(\left(\frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{x}}, 0.5 \cdot \sqrt{x}\right)}{x} + t\_3\right) + t\_2\right) + t\_7\\
\mathbf{elif}\;t\_8 \leq 2.00005:\\
\;\;\;\;\left(\left(t\_5 + t\_3\right) + \frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{z}}, 0.5 \cdot \sqrt{z}\right)}{z}\right) + t\_7\\
\mathbf{else}:\\
\;\;\;\;t\_6 + \frac{t\_4 \cdot t\_4 - \sqrt{t} \cdot \sqrt{t}}{t\_4 + \sqrt{t}}\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1e-3Initial program 7.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites6.9%
Taylor expanded in y around 0
Applied rewrites31.9%
Taylor expanded in x around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6456.2
Applied rewrites56.2%
if 1e-3 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0000499999999999Initial program 95.2%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites95.2%
Taylor expanded in y around 0
Applied rewrites96.2%
Taylor expanded in z around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6461.0
Applied rewrites61.0%
if 2.0000499999999999 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
flip--N/A
lower-/.f64N/A
Applied rewrites99.0%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ y 1.0)))
(t_2 (sqrt (+ z 1.0)))
(t_3 (- t_2 (sqrt z)))
(t_4 (/ 1.0 (+ t_1 (sqrt y))))
(t_5 (- (sqrt (+ x 1.0)) (sqrt x)))
(t_6 (- (sqrt (+ t 1.0)) (sqrt t)))
(t_7 (+ (+ (+ t_5 (- t_1 (sqrt y))) t_3) t_6)))
(if (<= t_7 0.0)
(+ (+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_4) t_3) t_6)
(if (<= t_7 2.01)
(+ (+ (+ t_5 t_4) (* 0.5 (/ 1.0 (sqrt z)))) (- (sqrt t) (sqrt t)))
(+
(- (+ (+ t_1 1.0) (fma 0.5 x t_2)) (+ (+ (sqrt z) (sqrt y)) (sqrt x)))
t_6)))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((y + 1.0));
double t_2 = sqrt((z + 1.0));
double t_3 = t_2 - sqrt(z);
double t_4 = 1.0 / (t_1 + sqrt(y));
double t_5 = sqrt((x + 1.0)) - sqrt(x);
double t_6 = sqrt((t + 1.0)) - sqrt(t);
double t_7 = ((t_5 + (t_1 - sqrt(y))) + t_3) + t_6;
double tmp;
if (t_7 <= 0.0) {
tmp = (((0.5 * (1.0 / sqrt(x))) + t_4) + t_3) + t_6;
} else if (t_7 <= 2.01) {
tmp = ((t_5 + t_4) + (0.5 * (1.0 / sqrt(z)))) + (sqrt(t) - sqrt(t));
} else {
tmp = (((t_1 + 1.0) + fma(0.5, x, t_2)) - ((sqrt(z) + sqrt(y)) + sqrt(x))) + t_6;
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(y + 1.0)) t_2 = sqrt(Float64(z + 1.0)) t_3 = Float64(t_2 - sqrt(z)) t_4 = Float64(1.0 / Float64(t_1 + sqrt(y))) t_5 = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) t_6 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) t_7 = Float64(Float64(Float64(t_5 + Float64(t_1 - sqrt(y))) + t_3) + t_6) tmp = 0.0 if (t_7 <= 0.0) tmp = Float64(Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_4) + t_3) + t_6); elseif (t_7 <= 2.01) tmp = Float64(Float64(Float64(t_5 + t_4) + Float64(0.5 * Float64(1.0 / sqrt(z)))) + Float64(sqrt(t) - sqrt(t))); else tmp = Float64(Float64(Float64(Float64(t_1 + 1.0) + fma(0.5, x, t_2)) - Float64(Float64(sqrt(z) + sqrt(y)) + sqrt(x))) + t_6); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(1.0 / N[(t$95$1 + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$7 = N[(N[(N[(t$95$5 + N[(t$95$1 - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$6), $MachinePrecision]}, If[LessEqual[t$95$7, 0.0], N[(N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$4), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$6), $MachinePrecision], If[LessEqual[t$95$7, 2.01], N[(N[(N[(t$95$5 + t$95$4), $MachinePrecision] + N[(0.5 * N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(t$95$1 + 1.0), $MachinePrecision] + N[(0.5 * x + t$95$2), $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sqrt[z], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$6), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{y + 1}\\
t_2 := \sqrt{z + 1}\\
t_3 := t\_2 - \sqrt{z}\\
t_4 := \frac{1}{t\_1 + \sqrt{y}}\\
t_5 := \sqrt{x + 1} - \sqrt{x}\\
t_6 := \sqrt{t + 1} - \sqrt{t}\\
t_7 := \left(\left(t\_5 + \left(t\_1 - \sqrt{y}\right)\right) + t\_3\right) + t\_6\\
\mathbf{if}\;t\_7 \leq 0:\\
\;\;\;\;\left(\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_4\right) + t\_3\right) + t\_6\\
\mathbf{elif}\;t\_7 \leq 2.01:\\
\;\;\;\;\left(\left(t\_5 + t\_4\right) + 0.5 \cdot \frac{1}{\sqrt{z}}\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(t\_1 + 1\right) + \mathsf{fma}\left(0.5, x, t\_2\right)\right) - \left(\left(\sqrt{z} + \sqrt{y}\right) + \sqrt{x}\right)\right) + t\_6\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 0.0Initial program 3.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites3.4%
Taylor expanded in y around 0
Applied rewrites28.3%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6453.9
Applied rewrites53.9%
if 0.0 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0099999999999998Initial program 95.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites95.0%
Taylor expanded in y around 0
Applied rewrites96.0%
Taylor expanded in z around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6462.7
Applied rewrites62.7%
Taylor expanded in t around inf
lift-sqrt.f6437.3
Applied rewrites37.3%
if 2.0099999999999998 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.2%
Taylor expanded in x around 0
lower--.f64N/A
Applied rewrites52.5%
Final simplification43.3%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ y 1.0)))
(t_2 (sqrt (+ z 1.0)))
(t_3 (- t_2 (sqrt z)))
(t_4 (- (sqrt t) (sqrt t)))
(t_5 (- (sqrt (+ x 1.0)) (sqrt x)))
(t_6 (- (sqrt (+ t 1.0)) (sqrt t)))
(t_7 (+ (+ (+ t_5 (- t_1 (sqrt y))) t_3) t_6)))
(if (<= t_7 0.001)
(+ (+ (/ (fma -0.125 (/ 1.0 (sqrt x)) (* 0.5 (sqrt x))) x) t_3) t_4)
(if (<= t_7 2.01)
(+ (+ (+ t_5 (/ 1.0 (+ t_1 (sqrt y)))) (* 0.5 (/ 1.0 (sqrt z)))) t_4)
(+
(- (+ (+ t_1 1.0) (fma 0.5 x t_2)) (+ (+ (sqrt z) (sqrt y)) (sqrt x)))
t_6)))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((y + 1.0));
double t_2 = sqrt((z + 1.0));
double t_3 = t_2 - sqrt(z);
double t_4 = sqrt(t) - sqrt(t);
double t_5 = sqrt((x + 1.0)) - sqrt(x);
double t_6 = sqrt((t + 1.0)) - sqrt(t);
double t_7 = ((t_5 + (t_1 - sqrt(y))) + t_3) + t_6;
double tmp;
if (t_7 <= 0.001) {
tmp = ((fma(-0.125, (1.0 / sqrt(x)), (0.5 * sqrt(x))) / x) + t_3) + t_4;
} else if (t_7 <= 2.01) {
tmp = ((t_5 + (1.0 / (t_1 + sqrt(y)))) + (0.5 * (1.0 / sqrt(z)))) + t_4;
} else {
tmp = (((t_1 + 1.0) + fma(0.5, x, t_2)) - ((sqrt(z) + sqrt(y)) + sqrt(x))) + t_6;
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(y + 1.0)) t_2 = sqrt(Float64(z + 1.0)) t_3 = Float64(t_2 - sqrt(z)) t_4 = Float64(sqrt(t) - sqrt(t)) t_5 = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) t_6 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) t_7 = Float64(Float64(Float64(t_5 + Float64(t_1 - sqrt(y))) + t_3) + t_6) tmp = 0.0 if (t_7 <= 0.001) tmp = Float64(Float64(Float64(fma(-0.125, Float64(1.0 / sqrt(x)), Float64(0.5 * sqrt(x))) / x) + t_3) + t_4); elseif (t_7 <= 2.01) tmp = Float64(Float64(Float64(t_5 + Float64(1.0 / Float64(t_1 + sqrt(y)))) + Float64(0.5 * Float64(1.0 / sqrt(z)))) + t_4); else tmp = Float64(Float64(Float64(Float64(t_1 + 1.0) + fma(0.5, x, t_2)) - Float64(Float64(sqrt(z) + sqrt(y)) + sqrt(x))) + t_6); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$7 = N[(N[(N[(t$95$5 + N[(t$95$1 - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$6), $MachinePrecision]}, If[LessEqual[t$95$7, 0.001], N[(N[(N[(N[(-0.125 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$4), $MachinePrecision], If[LessEqual[t$95$7, 2.01], N[(N[(N[(t$95$5 + N[(1.0 / N[(t$95$1 + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$4), $MachinePrecision], N[(N[(N[(N[(t$95$1 + 1.0), $MachinePrecision] + N[(0.5 * x + t$95$2), $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sqrt[z], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$6), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{y + 1}\\
t_2 := \sqrt{z + 1}\\
t_3 := t\_2 - \sqrt{z}\\
t_4 := \sqrt{t} - \sqrt{t}\\
t_5 := \sqrt{x + 1} - \sqrt{x}\\
t_6 := \sqrt{t + 1} - \sqrt{t}\\
t_7 := \left(\left(t\_5 + \left(t\_1 - \sqrt{y}\right)\right) + t\_3\right) + t\_6\\
\mathbf{if}\;t\_7 \leq 0.001:\\
\;\;\;\;\left(\frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{x}}, 0.5 \cdot \sqrt{x}\right)}{x} + t\_3\right) + t\_4\\
\mathbf{elif}\;t\_7 \leq 2.01:\\
\;\;\;\;\left(\left(t\_5 + \frac{1}{t\_1 + \sqrt{y}}\right) + 0.5 \cdot \frac{1}{\sqrt{z}}\right) + t\_4\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(t\_1 + 1\right) + \mathsf{fma}\left(0.5, x, t\_2\right)\right) - \left(\left(\sqrt{z} + \sqrt{y}\right) + \sqrt{x}\right)\right) + t\_6\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1e-3Initial program 7.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites6.9%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6428.9
Applied rewrites28.9%
if 1e-3 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.0099999999999998Initial program 95.1%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites95.1%
Taylor expanded in y around 0
Applied rewrites96.0%
Taylor expanded in z around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6462.5
Applied rewrites62.5%
Taylor expanded in t around inf
lift-sqrt.f6436.9
Applied rewrites36.9%
if 2.0099999999999998 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.2%
Taylor expanded in x around 0
lower--.f64N/A
Applied rewrites52.5%
Final simplification41.3%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ 1.0 x)))
(t_2
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
(- (sqrt (+ z 1.0)) (sqrt z)))
(- (sqrt (+ t 1.0)) (sqrt t))))
(t_3 (sqrt (+ 1.0 y))))
(if (<= t_2 1.0)
(+ (+ (- t_1 (sqrt x)) (- (sqrt z) (sqrt z))) (- (sqrt t) (sqrt t)))
(if (<= t_2 2.0)
(- (+ t_1 t_3) (+ (sqrt x) (sqrt y)))
(-
(+ 1.0 (+ t_3 (sqrt (+ 1.0 z))))
(+ (sqrt x) (+ (sqrt y) (sqrt z))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((1.0 + x));
double t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + (sqrt((z + 1.0)) - sqrt(z))) + (sqrt((t + 1.0)) - sqrt(t));
double t_3 = sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = ((t_1 - sqrt(x)) + (sqrt(z) - sqrt(z))) + (sqrt(t) - sqrt(t));
} else if (t_2 <= 2.0) {
tmp = (t_1 + t_3) - (sqrt(x) + sqrt(y));
} else {
tmp = (1.0 + (t_3 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = sqrt((1.0d0 + x))
t_2 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + (sqrt((z + 1.0d0)) - sqrt(z))) + (sqrt((t + 1.0d0)) - sqrt(t))
t_3 = sqrt((1.0d0 + y))
if (t_2 <= 1.0d0) then
tmp = ((t_1 - sqrt(x)) + (sqrt(z) - sqrt(z))) + (sqrt(t) - sqrt(t))
else if (t_2 <= 2.0d0) then
tmp = (t_1 + t_3) - (sqrt(x) + sqrt(y))
else
tmp = (1.0d0 + (t_3 + sqrt((1.0d0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)))
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((1.0 + x));
double t_2 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + (Math.sqrt((z + 1.0)) - Math.sqrt(z))) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
double t_3 = Math.sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = ((t_1 - Math.sqrt(x)) + (Math.sqrt(z) - Math.sqrt(z))) + (Math.sqrt(t) - Math.sqrt(t));
} else if (t_2 <= 2.0) {
tmp = (t_1 + t_3) - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = (1.0 + (t_3 + Math.sqrt((1.0 + z)))) - (Math.sqrt(x) + (Math.sqrt(y) + Math.sqrt(z)));
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((1.0 + x)) t_2 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + (math.sqrt((z + 1.0)) - math.sqrt(z))) + (math.sqrt((t + 1.0)) - math.sqrt(t)) t_3 = math.sqrt((1.0 + y)) tmp = 0 if t_2 <= 1.0: tmp = ((t_1 - math.sqrt(x)) + (math.sqrt(z) - math.sqrt(z))) + (math.sqrt(t) - math.sqrt(t)) elif t_2 <= 2.0: tmp = (t_1 + t_3) - (math.sqrt(x) + math.sqrt(y)) else: tmp = (1.0 + (t_3 + math.sqrt((1.0 + z)))) - (math.sqrt(x) + (math.sqrt(y) + math.sqrt(z))) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(1.0 + x)) t_2 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + Float64(sqrt(Float64(z + 1.0)) - sqrt(z))) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) t_3 = sqrt(Float64(1.0 + y)) tmp = 0.0 if (t_2 <= 1.0) tmp = Float64(Float64(Float64(t_1 - sqrt(x)) + Float64(sqrt(z) - sqrt(z))) + Float64(sqrt(t) - sqrt(t))); elseif (t_2 <= 2.0) tmp = Float64(Float64(t_1 + t_3) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(1.0 + Float64(t_3 + sqrt(Float64(1.0 + z)))) - Float64(sqrt(x) + Float64(sqrt(y) + sqrt(z)))); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((1.0 + x));
t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + (sqrt((z + 1.0)) - sqrt(z))) + (sqrt((t + 1.0)) - sqrt(t));
t_3 = sqrt((1.0 + y));
tmp = 0.0;
if (t_2 <= 1.0)
tmp = ((t_1 - sqrt(x)) + (sqrt(z) - sqrt(z))) + (sqrt(t) - sqrt(t));
elseif (t_2 <= 2.0)
tmp = (t_1 + t_3) - (sqrt(x) + sqrt(y));
else
tmp = (1.0 + (t_3 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$2, 1.0], N[(N[(N[(t$95$1 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[z], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[(N[(t$95$1 + t$95$3), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(t$95$3 + N[Sqrt[N[(1.0 + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{1 + x}\\
t_2 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + \left(\sqrt{z + 1} - \sqrt{z}\right)\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
t_3 := \sqrt{1 + y}\\
\mathbf{if}\;t\_2 \leq 1:\\
\;\;\;\;\left(\left(t\_1 - \sqrt{x}\right) + \left(\sqrt{z} - \sqrt{z}\right)\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;\left(t\_1 + t\_3\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_3 + \sqrt{1 + z}\right)\right) - \left(\sqrt{x} + \left(\sqrt{y} + \sqrt{z}\right)\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 70.2%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites70.2%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6437.7
Applied rewrites37.7%
Taylor expanded in t around inf
Applied rewrites21.5%
Taylor expanded in z around inf
Applied rewrites14.4%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2Initial program 96.1%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6418.9
Applied rewrites18.9%
if 2 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 96.9%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites21.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6421.5
Applied rewrites21.5%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_2
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_1)
(- (sqrt (+ t 1.0)) (sqrt t))))
(t_3 (sqrt (+ 1.0 y))))
(if (<= t_2 1.0)
(+ (+ (- (+ 1.0 (* 0.5 x)) (sqrt x)) t_1) (- (sqrt t) (sqrt t)))
(if (<= t_2 2.0)
(- (+ (sqrt (+ 1.0 x)) t_3) (+ (sqrt x) (sqrt y)))
(-
(+ 1.0 (+ t_3 (sqrt (+ 1.0 z))))
(+ (sqrt x) (+ (sqrt y) (sqrt z))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
double t_3 = sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = (((1.0 + (0.5 * x)) - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t));
} else if (t_2 <= 2.0) {
tmp = (sqrt((1.0 + x)) + t_3) - (sqrt(x) + sqrt(y));
} else {
tmp = (1.0 + (t_3 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = sqrt((z + 1.0d0)) - sqrt(z)
t_2 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0d0)) - sqrt(t))
t_3 = sqrt((1.0d0 + y))
if (t_2 <= 1.0d0) then
tmp = (((1.0d0 + (0.5d0 * x)) - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t))
else if (t_2 <= 2.0d0) then
tmp = (sqrt((1.0d0 + x)) + t_3) - (sqrt(x) + sqrt(y))
else
tmp = (1.0d0 + (t_3 + sqrt((1.0d0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)))
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_2 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_1) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
double t_3 = Math.sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = (((1.0 + (0.5 * x)) - Math.sqrt(x)) + t_1) + (Math.sqrt(t) - Math.sqrt(t));
} else if (t_2 <= 2.0) {
tmp = (Math.sqrt((1.0 + x)) + t_3) - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = (1.0 + (t_3 + Math.sqrt((1.0 + z)))) - (Math.sqrt(x) + (Math.sqrt(y) + Math.sqrt(z)));
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((z + 1.0)) - math.sqrt(z) t_2 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_1) + (math.sqrt((t + 1.0)) - math.sqrt(t)) t_3 = math.sqrt((1.0 + y)) tmp = 0 if t_2 <= 1.0: tmp = (((1.0 + (0.5 * x)) - math.sqrt(x)) + t_1) + (math.sqrt(t) - math.sqrt(t)) elif t_2 <= 2.0: tmp = (math.sqrt((1.0 + x)) + t_3) - (math.sqrt(x) + math.sqrt(y)) else: tmp = (1.0 + (t_3 + math.sqrt((1.0 + z)))) - (math.sqrt(x) + (math.sqrt(y) + math.sqrt(z))) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_2 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) t_3 = sqrt(Float64(1.0 + y)) tmp = 0.0 if (t_2 <= 1.0) tmp = Float64(Float64(Float64(Float64(1.0 + Float64(0.5 * x)) - sqrt(x)) + t_1) + Float64(sqrt(t) - sqrt(t))); elseif (t_2 <= 2.0) tmp = Float64(Float64(sqrt(Float64(1.0 + x)) + t_3) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(1.0 + Float64(t_3 + sqrt(Float64(1.0 + z)))) - Float64(sqrt(x) + Float64(sqrt(y) + sqrt(z)))); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((z + 1.0)) - sqrt(z);
t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
t_3 = sqrt((1.0 + y));
tmp = 0.0;
if (t_2 <= 1.0)
tmp = (((1.0 + (0.5 * x)) - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t));
elseif (t_2 <= 2.0)
tmp = (sqrt((1.0 + x)) + t_3) - (sqrt(x) + sqrt(y));
else
tmp = (1.0 + (t_3 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$2, 1.0], N[(N[(N[(N[(1.0 + N[(0.5 * x), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[(N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + t$95$3), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(t$95$3 + N[Sqrt[N[(1.0 + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
t_2 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
t_3 := \sqrt{1 + y}\\
\mathbf{if}\;t\_2 \leq 1:\\
\;\;\;\;\left(\left(\left(1 + 0.5 \cdot x\right) - \sqrt{x}\right) + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;\left(\sqrt{1 + x} + t\_3\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_3 + \sqrt{1 + z}\right)\right) - \left(\sqrt{x} + \left(\sqrt{y} + \sqrt{z}\right)\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 70.2%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites70.2%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6437.7
Applied rewrites37.7%
Taylor expanded in t around inf
Applied rewrites21.5%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f6416.0
Applied rewrites16.0%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2Initial program 96.1%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6418.9
Applied rewrites18.9%
if 2 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 96.9%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites21.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6421.5
Applied rewrites21.5%
Final simplification19.1%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_2
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_1)
(- (sqrt (+ t 1.0)) (sqrt t))))
(t_3 (sqrt (+ 1.0 y))))
(if (<= t_2 1.0)
(+ (+ (- 1.0 (sqrt x)) t_1) (- (sqrt t) (sqrt t)))
(if (<= t_2 2.0)
(- (+ (sqrt (+ 1.0 x)) t_3) (+ (sqrt x) (sqrt y)))
(-
(+ 1.0 (+ t_3 (sqrt (+ 1.0 z))))
(+ (sqrt x) (+ (sqrt y) (sqrt z))))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
double t_3 = sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = ((1.0 - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t));
} else if (t_2 <= 2.0) {
tmp = (sqrt((1.0 + x)) + t_3) - (sqrt(x) + sqrt(y));
} else {
tmp = (1.0 + (t_3 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = sqrt((z + 1.0d0)) - sqrt(z)
t_2 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0d0)) - sqrt(t))
t_3 = sqrt((1.0d0 + y))
if (t_2 <= 1.0d0) then
tmp = ((1.0d0 - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t))
else if (t_2 <= 2.0d0) then
tmp = (sqrt((1.0d0 + x)) + t_3) - (sqrt(x) + sqrt(y))
else
tmp = (1.0d0 + (t_3 + sqrt((1.0d0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)))
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_2 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_1) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
double t_3 = Math.sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = ((1.0 - Math.sqrt(x)) + t_1) + (Math.sqrt(t) - Math.sqrt(t));
} else if (t_2 <= 2.0) {
tmp = (Math.sqrt((1.0 + x)) + t_3) - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = (1.0 + (t_3 + Math.sqrt((1.0 + z)))) - (Math.sqrt(x) + (Math.sqrt(y) + Math.sqrt(z)));
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((z + 1.0)) - math.sqrt(z) t_2 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_1) + (math.sqrt((t + 1.0)) - math.sqrt(t)) t_3 = math.sqrt((1.0 + y)) tmp = 0 if t_2 <= 1.0: tmp = ((1.0 - math.sqrt(x)) + t_1) + (math.sqrt(t) - math.sqrt(t)) elif t_2 <= 2.0: tmp = (math.sqrt((1.0 + x)) + t_3) - (math.sqrt(x) + math.sqrt(y)) else: tmp = (1.0 + (t_3 + math.sqrt((1.0 + z)))) - (math.sqrt(x) + (math.sqrt(y) + math.sqrt(z))) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_2 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) t_3 = sqrt(Float64(1.0 + y)) tmp = 0.0 if (t_2 <= 1.0) tmp = Float64(Float64(Float64(1.0 - sqrt(x)) + t_1) + Float64(sqrt(t) - sqrt(t))); elseif (t_2 <= 2.0) tmp = Float64(Float64(sqrt(Float64(1.0 + x)) + t_3) - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(1.0 + Float64(t_3 + sqrt(Float64(1.0 + z)))) - Float64(sqrt(x) + Float64(sqrt(y) + sqrt(z)))); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((z + 1.0)) - sqrt(z);
t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
t_3 = sqrt((1.0 + y));
tmp = 0.0;
if (t_2 <= 1.0)
tmp = ((1.0 - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t));
elseif (t_2 <= 2.0)
tmp = (sqrt((1.0 + x)) + t_3) - (sqrt(x) + sqrt(y));
else
tmp = (1.0 + (t_3 + sqrt((1.0 + z)))) - (sqrt(x) + (sqrt(y) + sqrt(z)));
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$2, 1.0], N[(N[(N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[(N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + t$95$3), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(t$95$3 + N[Sqrt[N[(1.0 + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[(N[Sqrt[y], $MachinePrecision] + N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
t_2 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
t_3 := \sqrt{1 + y}\\
\mathbf{if}\;t\_2 \leq 1:\\
\;\;\;\;\left(\left(1 - \sqrt{x}\right) + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;\left(\sqrt{1 + x} + t\_3\right) - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_3 + \sqrt{1 + z}\right)\right) - \left(\sqrt{x} + \left(\sqrt{y} + \sqrt{z}\right)\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 70.2%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites70.2%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6437.7
Applied rewrites37.7%
Taylor expanded in t around inf
Applied rewrites21.5%
Taylor expanded in x around 0
Applied rewrites12.5%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2Initial program 96.1%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6418.9
Applied rewrites18.9%
if 2 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 96.9%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites21.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6421.5
Applied rewrites21.5%
Final simplification18.2%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_2
(+
(+
(+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y)))
t_1)
(- (sqrt (+ t 1.0)) (sqrt t))))
(t_3 (+ (sqrt (+ 1.0 x)) (sqrt (+ 1.0 y)))))
(if (<= t_2 1.0)
(+ (+ (- 1.0 (sqrt x)) t_1) (- (sqrt t) (sqrt t)))
(if (<= t_2 2.5)
(- t_3 (+ (sqrt x) (sqrt y)))
(- (- (+ 1.0 t_3) (sqrt x)) (sqrt y))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
double t_3 = sqrt((1.0 + x)) + sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = ((1.0 - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t));
} else if (t_2 <= 2.5) {
tmp = t_3 - (sqrt(x) + sqrt(y));
} else {
tmp = ((1.0 + t_3) - sqrt(x)) - sqrt(y);
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = sqrt((z + 1.0d0)) - sqrt(z)
t_2 = (((sqrt((x + 1.0d0)) - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0d0)) - sqrt(t))
t_3 = sqrt((1.0d0 + x)) + sqrt((1.0d0 + y))
if (t_2 <= 1.0d0) then
tmp = ((1.0d0 - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t))
else if (t_2 <= 2.5d0) then
tmp = t_3 - (sqrt(x) + sqrt(y))
else
tmp = ((1.0d0 + t_3) - sqrt(x)) - sqrt(y)
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_2 = (((Math.sqrt((x + 1.0)) - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_1) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
double t_3 = Math.sqrt((1.0 + x)) + Math.sqrt((1.0 + y));
double tmp;
if (t_2 <= 1.0) {
tmp = ((1.0 - Math.sqrt(x)) + t_1) + (Math.sqrt(t) - Math.sqrt(t));
} else if (t_2 <= 2.5) {
tmp = t_3 - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = ((1.0 + t_3) - Math.sqrt(x)) - Math.sqrt(y);
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((z + 1.0)) - math.sqrt(z) t_2 = (((math.sqrt((x + 1.0)) - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_1) + (math.sqrt((t + 1.0)) - math.sqrt(t)) t_3 = math.sqrt((1.0 + x)) + math.sqrt((1.0 + y)) tmp = 0 if t_2 <= 1.0: tmp = ((1.0 - math.sqrt(x)) + t_1) + (math.sqrt(t) - math.sqrt(t)) elif t_2 <= 2.5: tmp = t_3 - (math.sqrt(x) + math.sqrt(y)) else: tmp = ((1.0 + t_3) - math.sqrt(x)) - math.sqrt(y) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_2 = Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) t_3 = Float64(sqrt(Float64(1.0 + x)) + sqrt(Float64(1.0 + y))) tmp = 0.0 if (t_2 <= 1.0) tmp = Float64(Float64(Float64(1.0 - sqrt(x)) + t_1) + Float64(sqrt(t) - sqrt(t))); elseif (t_2 <= 2.5) tmp = Float64(t_3 - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(Float64(1.0 + t_3) - sqrt(x)) - sqrt(y)); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((z + 1.0)) - sqrt(z);
t_2 = (((sqrt((x + 1.0)) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
t_3 = sqrt((1.0 + x)) + sqrt((1.0 + y));
tmp = 0.0;
if (t_2 <= 1.0)
tmp = ((1.0 - sqrt(x)) + t_1) + (sqrt(t) - sqrt(t));
elseif (t_2 <= 2.5)
tmp = t_3 - (sqrt(x) + sqrt(y));
else
tmp = ((1.0 + t_3) - sqrt(x)) - sqrt(y);
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 1.0], N[(N[(N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.5], N[(t$95$3 - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 + t$95$3), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
t_2 := \left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
t_3 := \sqrt{1 + x} + \sqrt{1 + y}\\
\mathbf{if}\;t\_2 \leq 1:\\
\;\;\;\;\left(\left(1 - \sqrt{x}\right) + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{elif}\;t\_2 \leq 2.5:\\
\;\;\;\;t\_3 - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(1 + t\_3\right) - \sqrt{x}\right) - \sqrt{y}\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1Initial program 70.2%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites70.2%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6437.7
Applied rewrites37.7%
Taylor expanded in t around inf
Applied rewrites21.5%
Taylor expanded in x around 0
Applied rewrites12.5%
if 1 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 2.5Initial program 94.4%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites4.1%
Taylor expanded in z around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6418.6
Applied rewrites18.6%
if 2.5 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 99.3%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites23.7%
Taylor expanded in z around inf
lift-sqrt.f642.4
Applied rewrites2.4%
Taylor expanded in y around inf
lift-sqrt.f644.9
Applied rewrites4.9%
Taylor expanded in z around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f6438.8
Applied rewrites38.8%
Final simplification23.5%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ y 1.0)))
(t_2 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_3 (/ 1.0 (+ t_1 (sqrt y))))
(t_4 (- (sqrt (+ x 1.0)) (sqrt x)))
(t_5 (- (sqrt (+ t 1.0)) (sqrt t))))
(if (<= (+ (+ (+ t_4 (- t_1 (sqrt y))) t_2) t_5) 0.001)
(+
(+ (+ (/ (fma -0.125 (/ 1.0 (sqrt x)) (* 0.5 (sqrt x))) x) t_3) t_2)
t_5)
(+ (+ (+ t_4 t_3) t_2) t_5))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((y + 1.0));
double t_2 = sqrt((z + 1.0)) - sqrt(z);
double t_3 = 1.0 / (t_1 + sqrt(y));
double t_4 = sqrt((x + 1.0)) - sqrt(x);
double t_5 = sqrt((t + 1.0)) - sqrt(t);
double tmp;
if ((((t_4 + (t_1 - sqrt(y))) + t_2) + t_5) <= 0.001) {
tmp = (((fma(-0.125, (1.0 / sqrt(x)), (0.5 * sqrt(x))) / x) + t_3) + t_2) + t_5;
} else {
tmp = ((t_4 + t_3) + t_2) + t_5;
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(y + 1.0)) t_2 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_3 = Float64(1.0 / Float64(t_1 + sqrt(y))) t_4 = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) t_5 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) tmp = 0.0 if (Float64(Float64(Float64(t_4 + Float64(t_1 - sqrt(y))) + t_2) + t_5) <= 0.001) tmp = Float64(Float64(Float64(Float64(fma(-0.125, Float64(1.0 / sqrt(x)), Float64(0.5 * sqrt(x))) / x) + t_3) + t_2) + t_5); else tmp = Float64(Float64(Float64(t_4 + t_3) + t_2) + t_5); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 / N[(t$95$1 + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(t$95$4 + N[(t$95$1 - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$5), $MachinePrecision], 0.001], N[(N[(N[(N[(N[(-0.125 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$5), $MachinePrecision], N[(N[(N[(t$95$4 + t$95$3), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$5), $MachinePrecision]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{y + 1}\\
t_2 := \sqrt{z + 1} - \sqrt{z}\\
t_3 := \frac{1}{t\_1 + \sqrt{y}}\\
t_4 := \sqrt{x + 1} - \sqrt{x}\\
t_5 := \sqrt{t + 1} - \sqrt{t}\\
\mathbf{if}\;\left(\left(t\_4 + \left(t\_1 - \sqrt{y}\right)\right) + t\_2\right) + t\_5 \leq 0.001:\\
\;\;\;\;\left(\left(\frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{x}}, 0.5 \cdot \sqrt{x}\right)}{x} + t\_3\right) + t\_2\right) + t\_5\\
\mathbf{else}:\\
\;\;\;\;\left(\left(t\_4 + t\_3\right) + t\_2\right) + t\_5\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1e-3Initial program 7.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites6.9%
Taylor expanded in y around 0
Applied rewrites31.9%
Taylor expanded in x around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6456.2
Applied rewrites56.2%
if 1e-3 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 96.5%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.7%
Taylor expanded in y around 0
Applied rewrites97.3%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ y 1.0)))
(t_2 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_3 (/ 1.0 (+ t_1 (sqrt y))))
(t_4 (- (sqrt (+ x 1.0)) (sqrt x)))
(t_5 (- (sqrt (+ t 1.0)) (sqrt t))))
(if (<= (+ (+ (+ t_4 (- t_1 (sqrt y))) t_2) t_5) 0.0)
(+ (+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_3) t_2) t_5)
(+ (+ (+ t_4 t_3) t_2) t_5))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((y + 1.0));
double t_2 = sqrt((z + 1.0)) - sqrt(z);
double t_3 = 1.0 / (t_1 + sqrt(y));
double t_4 = sqrt((x + 1.0)) - sqrt(x);
double t_5 = sqrt((t + 1.0)) - sqrt(t);
double tmp;
if ((((t_4 + (t_1 - sqrt(y))) + t_2) + t_5) <= 0.0) {
tmp = (((0.5 * (1.0 / sqrt(x))) + t_3) + t_2) + t_5;
} else {
tmp = ((t_4 + t_3) + t_2) + t_5;
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: t_5
real(8) :: tmp
t_1 = sqrt((y + 1.0d0))
t_2 = sqrt((z + 1.0d0)) - sqrt(z)
t_3 = 1.0d0 / (t_1 + sqrt(y))
t_4 = sqrt((x + 1.0d0)) - sqrt(x)
t_5 = sqrt((t + 1.0d0)) - sqrt(t)
if ((((t_4 + (t_1 - sqrt(y))) + t_2) + t_5) <= 0.0d0) then
tmp = (((0.5d0 * (1.0d0 / sqrt(x))) + t_3) + t_2) + t_5
else
tmp = ((t_4 + t_3) + t_2) + t_5
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((y + 1.0));
double t_2 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double t_3 = 1.0 / (t_1 + Math.sqrt(y));
double t_4 = Math.sqrt((x + 1.0)) - Math.sqrt(x);
double t_5 = Math.sqrt((t + 1.0)) - Math.sqrt(t);
double tmp;
if ((((t_4 + (t_1 - Math.sqrt(y))) + t_2) + t_5) <= 0.0) {
tmp = (((0.5 * (1.0 / Math.sqrt(x))) + t_3) + t_2) + t_5;
} else {
tmp = ((t_4 + t_3) + t_2) + t_5;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((y + 1.0)) t_2 = math.sqrt((z + 1.0)) - math.sqrt(z) t_3 = 1.0 / (t_1 + math.sqrt(y)) t_4 = math.sqrt((x + 1.0)) - math.sqrt(x) t_5 = math.sqrt((t + 1.0)) - math.sqrt(t) tmp = 0 if (((t_4 + (t_1 - math.sqrt(y))) + t_2) + t_5) <= 0.0: tmp = (((0.5 * (1.0 / math.sqrt(x))) + t_3) + t_2) + t_5 else: tmp = ((t_4 + t_3) + t_2) + t_5 return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(y + 1.0)) t_2 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_3 = Float64(1.0 / Float64(t_1 + sqrt(y))) t_4 = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) t_5 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) tmp = 0.0 if (Float64(Float64(Float64(t_4 + Float64(t_1 - sqrt(y))) + t_2) + t_5) <= 0.0) tmp = Float64(Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_3) + t_2) + t_5); else tmp = Float64(Float64(Float64(t_4 + t_3) + t_2) + t_5); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((y + 1.0));
t_2 = sqrt((z + 1.0)) - sqrt(z);
t_3 = 1.0 / (t_1 + sqrt(y));
t_4 = sqrt((x + 1.0)) - sqrt(x);
t_5 = sqrt((t + 1.0)) - sqrt(t);
tmp = 0.0;
if ((((t_4 + (t_1 - sqrt(y))) + t_2) + t_5) <= 0.0)
tmp = (((0.5 * (1.0 / sqrt(x))) + t_3) + t_2) + t_5;
else
tmp = ((t_4 + t_3) + t_2) + t_5;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 / N[(t$95$1 + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(t$95$4 + N[(t$95$1 - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$5), $MachinePrecision], 0.0], N[(N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$5), $MachinePrecision], N[(N[(N[(t$95$4 + t$95$3), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$5), $MachinePrecision]]]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{y + 1}\\
t_2 := \sqrt{z + 1} - \sqrt{z}\\
t_3 := \frac{1}{t\_1 + \sqrt{y}}\\
t_4 := \sqrt{x + 1} - \sqrt{x}\\
t_5 := \sqrt{t + 1} - \sqrt{t}\\
\mathbf{if}\;\left(\left(t\_4 + \left(t\_1 - \sqrt{y}\right)\right) + t\_2\right) + t\_5 \leq 0:\\
\;\;\;\;\left(\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_3\right) + t\_2\right) + t\_5\\
\mathbf{else}:\\
\;\;\;\;\left(\left(t\_4 + t\_3\right) + t\_2\right) + t\_5\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 0.0Initial program 3.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites3.4%
Taylor expanded in y around 0
Applied rewrites28.3%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6453.9
Applied rewrites53.9%
if 0.0 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 96.4%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.5%
Taylor expanded in y around 0
Applied rewrites97.3%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (sqrt (+ y 1.0)))
(t_2 (- (sqrt (+ z 1.0)) (sqrt z)))
(t_3 (- (sqrt (+ t 1.0)) (sqrt t))))
(if (<=
(+ (+ (+ (- (sqrt (+ x 1.0)) (sqrt x)) (- t_1 (sqrt y))) t_2) t_3)
0.001)
(+
(+ (/ (fma -0.125 (/ 1.0 (sqrt x)) (* 0.5 (sqrt x))) x) t_2)
(- (sqrt t) (sqrt t)))
(+ (+ (+ (- 1.0 (sqrt x)) (/ 1.0 (+ t_1 (sqrt y)))) t_2) t_3))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((y + 1.0));
double t_2 = sqrt((z + 1.0)) - sqrt(z);
double t_3 = sqrt((t + 1.0)) - sqrt(t);
double tmp;
if (((((sqrt((x + 1.0)) - sqrt(x)) + (t_1 - sqrt(y))) + t_2) + t_3) <= 0.001) {
tmp = ((fma(-0.125, (1.0 / sqrt(x)), (0.5 * sqrt(x))) / x) + t_2) + (sqrt(t) - sqrt(t));
} else {
tmp = (((1.0 - sqrt(x)) + (1.0 / (t_1 + sqrt(y)))) + t_2) + t_3;
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = sqrt(Float64(y + 1.0)) t_2 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) t_3 = Float64(sqrt(Float64(t + 1.0)) - sqrt(t)) tmp = 0.0 if (Float64(Float64(Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) + Float64(t_1 - sqrt(y))) + t_2) + t_3) <= 0.001) tmp = Float64(Float64(Float64(fma(-0.125, Float64(1.0 / sqrt(x)), Float64(0.5 * sqrt(x))) / x) + t_2) + Float64(sqrt(t) - sqrt(t))); else tmp = Float64(Float64(Float64(Float64(1.0 - sqrt(x)) + Float64(1.0 / Float64(t_1 + sqrt(y)))) + t_2) + t_3); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(t$95$1 - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$3), $MachinePrecision], 0.001], N[(N[(N[(N[(-0.125 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + t$95$2), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(t$95$1 + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision] + t$95$3), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{y + 1}\\
t_2 := \sqrt{z + 1} - \sqrt{z}\\
t_3 := \sqrt{t + 1} - \sqrt{t}\\
\mathbf{if}\;\left(\left(\left(\sqrt{x + 1} - \sqrt{x}\right) + \left(t\_1 - \sqrt{y}\right)\right) + t\_2\right) + t\_3 \leq 0.001:\\
\;\;\;\;\left(\frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{x}}, 0.5 \cdot \sqrt{x}\right)}{x} + t\_2\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(1 - \sqrt{x}\right) + \frac{1}{t\_1 + \sqrt{y}}\right) + t\_2\right) + t\_3\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) < 1e-3Initial program 7.0%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites6.9%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f643.4
Applied rewrites3.4%
Taylor expanded in t around inf
Applied rewrites3.4%
Taylor expanded in x around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6428.9
Applied rewrites28.9%
if 1e-3 < (+.f64 (+.f64 (+.f64 (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) (-.f64 (sqrt.f64 (+.f64 y #s(literal 1 binary64))) (sqrt.f64 y))) (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z))) (-.f64 (sqrt.f64 (+.f64 t #s(literal 1 binary64))) (sqrt.f64 t))) Initial program 96.5%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites96.7%
Taylor expanded in y around 0
Applied rewrites97.3%
Taylor expanded in x around 0
Applied rewrites46.8%
Final simplification45.5%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z))))
(if (<= x 4.0)
(+
(+ (+ (- (fma 0.5 x 1.0) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y))) t_1)
(- (sqrt (+ t 1.0)) (sqrt t)))
(+
(+ (/ (fma -0.125 (/ 1.0 (sqrt x)) (* 0.5 (sqrt x))) x) t_1)
(- (sqrt t) (sqrt t))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double tmp;
if (x <= 4.0) {
tmp = (((fma(0.5, x, 1.0) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
} else {
tmp = ((fma(-0.125, (1.0 / sqrt(x)), (0.5 * sqrt(x))) / x) + t_1) + (sqrt(t) - sqrt(t));
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) tmp = 0.0 if (x <= 4.0) tmp = Float64(Float64(Float64(Float64(fma(0.5, x, 1.0) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))); else tmp = Float64(Float64(Float64(fma(-0.125, Float64(1.0 / sqrt(x)), Float64(0.5 * sqrt(x))) / x) + t_1) + Float64(sqrt(t) - sqrt(t))); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 4.0], N[(N[(N[(N[(N[(0.5 * x + 1.0), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-0.125 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
\mathbf{if}\;x \leq 4:\\
\;\;\;\;\left(\left(\left(\mathsf{fma}\left(0.5, x, 1\right) - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{\mathsf{fma}\left(-0.125, \frac{1}{\sqrt{x}}, 0.5 \cdot \sqrt{x}\right)}{x} + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\end{array}
\end{array}
if x < 4Initial program 97.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6496.9
Applied rewrites96.9%
if 4 < x Initial program 83.9%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites83.9%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6435.9
Applied rewrites35.9%
Taylor expanded in t around inf
Applied rewrites13.4%
Taylor expanded in x around inf
lower-/.f64N/A
lower-fma.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f6418.2
Applied rewrites18.2%
Final simplification52.9%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z))))
(if (<= x 4.0)
(+
(+ (+ (- (fma 0.5 x 1.0) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y))) t_1)
(- (sqrt (+ t 1.0)) (sqrt t)))
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_1) (- (sqrt t) (sqrt t))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double tmp;
if (x <= 4.0) {
tmp = (((fma(0.5, x, 1.0) - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
} else {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
}
return tmp;
}
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) tmp = 0.0 if (x <= 4.0) tmp = Float64(Float64(Float64(Float64(fma(0.5, x, 1.0) - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))); else tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_1) + Float64(sqrt(t) - sqrt(t))); end return tmp end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 4.0], N[(N[(N[(N[(N[(0.5 * x + 1.0), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
\mathbf{if}\;x \leq 4:\\
\;\;\;\;\left(\left(\left(\mathsf{fma}\left(0.5, x, 1\right) - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\end{array}
\end{array}
if x < 4Initial program 97.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6496.9
Applied rewrites96.9%
if 4 < x Initial program 83.9%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites83.9%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6435.9
Applied rewrites35.9%
Taylor expanded in t around inf
Applied rewrites13.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6418.2
Applied rewrites18.2%
Final simplification52.9%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (sqrt (+ z 1.0)) (sqrt z))))
(if (<= x 0.77)
(+
(+ (+ (- 1.0 (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y))) t_1)
(- (sqrt (+ t 1.0)) (sqrt t)))
(+ (+ (* 0.5 (/ 1.0 (sqrt x))) t_1) (- (sqrt t) (sqrt t))))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((z + 1.0)) - sqrt(z);
double tmp;
if (x <= 0.77) {
tmp = (((1.0 - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
} else {
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = sqrt((z + 1.0d0)) - sqrt(z)
if (x <= 0.77d0) then
tmp = (((1.0d0 - sqrt(x)) + (sqrt((y + 1.0d0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0d0)) - sqrt(t))
else
tmp = ((0.5d0 * (1.0d0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t))
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((z + 1.0)) - Math.sqrt(z);
double tmp;
if (x <= 0.77) {
tmp = (((1.0 - Math.sqrt(x)) + (Math.sqrt((y + 1.0)) - Math.sqrt(y))) + t_1) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
} else {
tmp = ((0.5 * (1.0 / Math.sqrt(x))) + t_1) + (Math.sqrt(t) - Math.sqrt(t));
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((z + 1.0)) - math.sqrt(z) tmp = 0 if x <= 0.77: tmp = (((1.0 - math.sqrt(x)) + (math.sqrt((y + 1.0)) - math.sqrt(y))) + t_1) + (math.sqrt((t + 1.0)) - math.sqrt(t)) else: tmp = ((0.5 * (1.0 / math.sqrt(x))) + t_1) + (math.sqrt(t) - math.sqrt(t)) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) tmp = 0.0 if (x <= 0.77) tmp = Float64(Float64(Float64(Float64(1.0 - sqrt(x)) + Float64(sqrt(Float64(y + 1.0)) - sqrt(y))) + t_1) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))); else tmp = Float64(Float64(Float64(0.5 * Float64(1.0 / sqrt(x))) + t_1) + Float64(sqrt(t) - sqrt(t))); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((z + 1.0)) - sqrt(z);
tmp = 0.0;
if (x <= 0.77)
tmp = (((1.0 - sqrt(x)) + (sqrt((y + 1.0)) - sqrt(y))) + t_1) + (sqrt((t + 1.0)) - sqrt(t));
else
tmp = ((0.5 * (1.0 / sqrt(x))) + t_1) + (sqrt(t) - sqrt(t));
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 0.77], N[(N[(N[(N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(N[Sqrt[t], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{z + 1} - \sqrt{z}\\
\mathbf{if}\;x \leq 0.77:\\
\;\;\;\;\left(\left(\left(1 - \sqrt{x}\right) + \left(\sqrt{y + 1} - \sqrt{y}\right)\right) + t\_1\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \frac{1}{\sqrt{x}} + t\_1\right) + \left(\sqrt{t} - \sqrt{t}\right)\\
\end{array}
\end{array}
if x < 0.77000000000000002Initial program 97.4%
Taylor expanded in x around 0
Applied rewrites96.4%
if 0.77000000000000002 < x Initial program 83.9%
lift--.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
+-commutativeN/A
flip--N/A
lower-/.f64N/A
Applied rewrites83.9%
Taylor expanded in y around inf
lower--.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f6435.9
Applied rewrites35.9%
Taylor expanded in t around inf
Applied rewrites13.4%
Taylor expanded in x around inf
lower-*.f64N/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lift-sqrt.f6418.2
Applied rewrites18.2%
Final simplification52.7%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ (sqrt (+ 1.0 x)) (sqrt (+ 1.0 y)))))
(if (<= (- (sqrt (+ z 1.0)) (sqrt z)) 0.02)
(- t_1 (+ (sqrt x) (sqrt y)))
(- (- (+ 1.0 t_1) (sqrt x)) (sqrt y)))))assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double t_1 = sqrt((1.0 + x)) + sqrt((1.0 + y));
double tmp;
if ((sqrt((z + 1.0)) - sqrt(z)) <= 0.02) {
tmp = t_1 - (sqrt(x) + sqrt(y));
} else {
tmp = ((1.0 + t_1) - sqrt(x)) - sqrt(y);
}
return tmp;
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = sqrt((1.0d0 + x)) + sqrt((1.0d0 + y))
if ((sqrt((z + 1.0d0)) - sqrt(z)) <= 0.02d0) then
tmp = t_1 - (sqrt(x) + sqrt(y))
else
tmp = ((1.0d0 + t_1) - sqrt(x)) - sqrt(y)
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double t_1 = Math.sqrt((1.0 + x)) + Math.sqrt((1.0 + y));
double tmp;
if ((Math.sqrt((z + 1.0)) - Math.sqrt(z)) <= 0.02) {
tmp = t_1 - (Math.sqrt(x) + Math.sqrt(y));
} else {
tmp = ((1.0 + t_1) - Math.sqrt(x)) - Math.sqrt(y);
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): t_1 = math.sqrt((1.0 + x)) + math.sqrt((1.0 + y)) tmp = 0 if (math.sqrt((z + 1.0)) - math.sqrt(z)) <= 0.02: tmp = t_1 - (math.sqrt(x) + math.sqrt(y)) else: tmp = ((1.0 + t_1) - math.sqrt(x)) - math.sqrt(y) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) t_1 = Float64(sqrt(Float64(1.0 + x)) + sqrt(Float64(1.0 + y))) tmp = 0.0 if (Float64(sqrt(Float64(z + 1.0)) - sqrt(z)) <= 0.02) tmp = Float64(t_1 - Float64(sqrt(x) + sqrt(y))); else tmp = Float64(Float64(Float64(1.0 + t_1) - sqrt(x)) - sqrt(y)); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
t_1 = sqrt((1.0 + x)) + sqrt((1.0 + y));
tmp = 0.0;
if ((sqrt((z + 1.0)) - sqrt(z)) <= 0.02)
tmp = t_1 - (sqrt(x) + sqrt(y));
else
tmp = ((1.0 + t_1) - sqrt(x)) - sqrt(y);
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[z], $MachinePrecision]), $MachinePrecision], 0.02], N[(t$95$1 - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 + t$95$1), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
t_1 := \sqrt{1 + x} + \sqrt{1 + y}\\
\mathbf{if}\;\sqrt{z + 1} - \sqrt{z} \leq 0.02:\\
\;\;\;\;t\_1 - \left(\sqrt{x} + \sqrt{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(1 + t\_1\right) - \sqrt{x}\right) - \sqrt{y}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z)) < 0.0200000000000000004Initial program 82.4%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites3.0%
Taylor expanded in z around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6418.6
Applied rewrites18.6%
if 0.0200000000000000004 < (-.f64 (sqrt.f64 (+.f64 z #s(literal 1 binary64))) (sqrt.f64 z)) Initial program 97.6%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites17.1%
Taylor expanded in z around inf
lift-sqrt.f642.0
Applied rewrites2.0%
Taylor expanded in y around inf
lift-sqrt.f643.7
Applied rewrites3.7%
Taylor expanded in z around 0
lower--.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lift-sqrt.f6416.7
Applied rewrites16.7%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (- (+ (sqrt (+ 1.0 x)) (sqrt (+ 1.0 y))) (+ (sqrt x) (sqrt y))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
return (sqrt((1.0 + x)) + sqrt((1.0 + y))) - (sqrt(x) + sqrt(y));
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (sqrt((1.0d0 + x)) + sqrt((1.0d0 + y))) - (sqrt(x) + sqrt(y))
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
return (Math.sqrt((1.0 + x)) + Math.sqrt((1.0 + y))) - (Math.sqrt(x) + Math.sqrt(y));
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): return (math.sqrt((1.0 + x)) + math.sqrt((1.0 + y))) - (math.sqrt(x) + math.sqrt(y))
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) return Float64(Float64(sqrt(Float64(1.0 + x)) + sqrt(Float64(1.0 + y))) - Float64(sqrt(x) + sqrt(y))) end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp = code(x, y, z, t)
tmp = (sqrt((1.0 + x)) + sqrt((1.0 + y))) - (sqrt(x) + sqrt(y));
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\left(\sqrt{1 + x} + \sqrt{1 + y}\right) - \left(\sqrt{x} + \sqrt{y}\right)
\end{array}
Initial program 89.9%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites9.9%
Taylor expanded in z around inf
lower--.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f6413.4
Applied rewrites13.4%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (- (+ (sqrt (+ 1.0 y)) (sqrt (+ 1.0 z))) (sqrt y)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
return (sqrt((1.0 + y)) + sqrt((1.0 + z))) - sqrt(y);
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (sqrt((1.0d0 + y)) + sqrt((1.0d0 + z))) - sqrt(y)
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
return (Math.sqrt((1.0 + y)) + Math.sqrt((1.0 + z))) - Math.sqrt(y);
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): return (math.sqrt((1.0 + y)) + math.sqrt((1.0 + z))) - math.sqrt(y)
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) return Float64(Float64(sqrt(Float64(1.0 + y)) + sqrt(Float64(1.0 + z))) - sqrt(y)) end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp = code(x, y, z, t)
tmp = (sqrt((1.0 + y)) + sqrt((1.0 + z))) - sqrt(y);
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[(N[Sqrt[N[(1.0 + y), $MachinePrecision]], $MachinePrecision] + N[Sqrt[N[(1.0 + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\left(\sqrt{1 + y} + \sqrt{1 + z}\right) - \sqrt{y}
\end{array}
Initial program 89.9%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites9.9%
Taylor expanded in z around inf
lift-sqrt.f642.3
Applied rewrites2.3%
Taylor expanded in y around inf
lift-sqrt.f644.3
Applied rewrites4.3%
Taylor expanded in x around inf
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-+.f6416.1
Applied rewrites16.1%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (- (sqrt z) (sqrt y)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
return sqrt(z) - sqrt(y);
}
NOTE: x, y, z, and t 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = sqrt(z) - sqrt(y)
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
return Math.sqrt(z) - Math.sqrt(y);
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): return math.sqrt(z) - math.sqrt(y)
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) return Float64(sqrt(z) - sqrt(y)) end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp = code(x, y, z, t)
tmp = sqrt(z) - sqrt(y);
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[Sqrt[z], $MachinePrecision] - N[Sqrt[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\sqrt{z} - \sqrt{y}
\end{array}
Initial program 89.9%
Taylor expanded in t around inf
associate--r+N/A
lower--.f64N/A
Applied rewrites9.9%
Taylor expanded in z around inf
lift-sqrt.f642.3
Applied rewrites2.3%
Taylor expanded in y around inf
lift-sqrt.f644.3
Applied rewrites4.3%
(FPCore (x y z t)
:precision binary64
(+
(+
(+
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(/ 1.0 (+ (sqrt (+ y 1.0)) (sqrt y))))
(/ 1.0 (+ (sqrt (+ z 1.0)) (sqrt z))))
(- (sqrt (+ t 1.0)) (sqrt t))))
double code(double x, double y, double z, double t) {
return (((1.0 / (sqrt((x + 1.0)) + sqrt(x))) + (1.0 / (sqrt((y + 1.0)) + sqrt(y)))) + (1.0 / (sqrt((z + 1.0)) + sqrt(z)))) + (sqrt((t + 1.0)) - sqrt(t));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((1.0d0 / (sqrt((x + 1.0d0)) + sqrt(x))) + (1.0d0 / (sqrt((y + 1.0d0)) + sqrt(y)))) + (1.0d0 / (sqrt((z + 1.0d0)) + sqrt(z)))) + (sqrt((t + 1.0d0)) - sqrt(t))
end function
public static double code(double x, double y, double z, double t) {
return (((1.0 / (Math.sqrt((x + 1.0)) + Math.sqrt(x))) + (1.0 / (Math.sqrt((y + 1.0)) + Math.sqrt(y)))) + (1.0 / (Math.sqrt((z + 1.0)) + Math.sqrt(z)))) + (Math.sqrt((t + 1.0)) - Math.sqrt(t));
}
def code(x, y, z, t): return (((1.0 / (math.sqrt((x + 1.0)) + math.sqrt(x))) + (1.0 / (math.sqrt((y + 1.0)) + math.sqrt(y)))) + (1.0 / (math.sqrt((z + 1.0)) + math.sqrt(z)))) + (math.sqrt((t + 1.0)) - math.sqrt(t))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(1.0 / Float64(sqrt(Float64(x + 1.0)) + sqrt(x))) + Float64(1.0 / Float64(sqrt(Float64(y + 1.0)) + sqrt(y)))) + Float64(1.0 / Float64(sqrt(Float64(z + 1.0)) + sqrt(z)))) + Float64(sqrt(Float64(t + 1.0)) - sqrt(t))) end
function tmp = code(x, y, z, t) tmp = (((1.0 / (sqrt((x + 1.0)) + sqrt(x))) + (1.0 / (sqrt((y + 1.0)) + sqrt(y)))) + (1.0 / (sqrt((z + 1.0)) + sqrt(z)))) + (sqrt((t + 1.0)) - sqrt(t)); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(1.0 / N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(N[Sqrt[N[(y + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(N[Sqrt[N[(z + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(t + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\frac{1}{\sqrt{x + 1} + \sqrt{x}} + \frac{1}{\sqrt{y + 1} + \sqrt{y}}\right) + \frac{1}{\sqrt{z + 1} + \sqrt{z}}\right) + \left(\sqrt{t + 1} - \sqrt{t}\right)
\end{array}
herbie shell --seed 2025037
(FPCore (x y z t)
:name "Main:z from "
:precision binary64
:alt
(! :herbie-platform default (+ (+ (+ (/ 1 (+ (sqrt (+ x 1)) (sqrt x))) (/ 1 (+ (sqrt (+ y 1)) (sqrt y)))) (/ 1 (+ (sqrt (+ z 1)) (sqrt z)))) (- (sqrt (+ t 1)) (sqrt t))))
(+ (+ (+ (- (sqrt (+ x 1.0)) (sqrt x)) (- (sqrt (+ y 1.0)) (sqrt y))) (- (sqrt (+ z 1.0)) (sqrt z))) (- (sqrt (+ t 1.0)) (sqrt t))))