
(FPCore (x y) :precision binary64 (/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))
double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0d0))
end function
public static double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
def code(x, y): return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0))
function code(x, y) return Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * Float64(Float64(x + y) + 1.0))) end
function tmp = code(x, y) tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0)); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)}
\end{array}
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))
double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0d0))
end function
public static double code(double x, double y) {
return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0));
}
def code(x, y): return (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0))
function code(x, y) return Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * Float64(Float64(x + y) + 1.0))) end
function tmp = code(x, y) tmp = (x * y) / (((x + y) * (x + y)) * ((x + y) + 1.0)); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * N[(N[(x + y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x + y\right) + 1\right)}
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= y 2.95e-136)
(* 2.0 (/ y (fma 2.0 x (* 2.0 (* x x)))))
(if (<= y 1.5e+97)
(* x (/ y (* (+ (+ y x) 1.0) (fma y (- y (* -2.0 x)) (* x x)))))
(/ (/ (+ (* (* x (/ x y)) -3.0) x) y) y))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.95e-136) {
tmp = 2.0 * (y / fma(2.0, x, (2.0 * (x * x))));
} else if (y <= 1.5e+97) {
tmp = x * (y / (((y + x) + 1.0) * fma(y, (y - (-2.0 * x)), (x * x))));
} else {
tmp = ((((x * (x / y)) * -3.0) + x) / y) / y;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 2.95e-136) tmp = Float64(2.0 * Float64(y / fma(2.0, x, Float64(2.0 * Float64(x * x))))); elseif (y <= 1.5e+97) tmp = Float64(x * Float64(y / Float64(Float64(Float64(y + x) + 1.0) * fma(y, Float64(y - Float64(-2.0 * x)), Float64(x * x))))); else tmp = Float64(Float64(Float64(Float64(Float64(x * Float64(x / y)) * -3.0) + x) / y) / y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 2.95e-136], N[(2.0 * N[(y / N[(2.0 * x + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.5e+97], N[(x * N[(y / N[(N[(N[(y + x), $MachinePrecision] + 1.0), $MachinePrecision] * N[(y * N[(y - N[(-2.0 * x), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] * -3.0), $MachinePrecision] + x), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.95 \cdot 10^{-136}:\\
\;\;\;\;2 \cdot \frac{y}{\mathsf{fma}\left(2, x, 2 \cdot \left(x \cdot x\right)\right)}\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+97}:\\
\;\;\;\;x \cdot \frac{y}{\left(\left(y + x\right) + 1\right) \cdot \mathsf{fma}\left(y, y - -2 \cdot x, x \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x \cdot \frac{x}{y}\right) \cdot -3 + x}{y}}{y}\\
\end{array}
\end{array}
if y < 2.95000000000000007e-136Initial program 64.3%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6464.2
Applied rewrites64.2%
Taylor expanded in y around 0
lower-*.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6485.8
Applied rewrites85.8%
if 2.95000000000000007e-136 < y < 1.4999999999999999e97Initial program 84.9%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6493.3
Applied rewrites93.3%
Taylor expanded in y around 0
lower-fma.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6493.2
Applied rewrites93.2%
if 1.4999999999999999e97 < y Initial program 60.4%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in x around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6476.2
Applied rewrites76.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites90.2%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= y 2.95e-136)
(* 2.0 (/ y (fma 2.0 x (* 2.0 (* x x)))))
(if (<= y 1.5e+97)
(* x (/ y (* (+ (+ y x) 1.0) (* (+ y x) (+ y x)))))
(/ (/ (+ (* (* x (/ x y)) -3.0) x) y) y))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.95e-136) {
tmp = 2.0 * (y / fma(2.0, x, (2.0 * (x * x))));
} else if (y <= 1.5e+97) {
tmp = x * (y / (((y + x) + 1.0) * ((y + x) * (y + x))));
} else {
tmp = ((((x * (x / y)) * -3.0) + x) / y) / y;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 2.95e-136) tmp = Float64(2.0 * Float64(y / fma(2.0, x, Float64(2.0 * Float64(x * x))))); elseif (y <= 1.5e+97) tmp = Float64(x * Float64(y / Float64(Float64(Float64(y + x) + 1.0) * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(Float64(Float64(Float64(Float64(x * Float64(x / y)) * -3.0) + x) / y) / y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 2.95e-136], N[(2.0 * N[(y / N[(2.0 * x + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.5e+97], N[(x * N[(y / N[(N[(N[(y + x), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] * -3.0), $MachinePrecision] + x), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.95 \cdot 10^{-136}:\\
\;\;\;\;2 \cdot \frac{y}{\mathsf{fma}\left(2, x, 2 \cdot \left(x \cdot x\right)\right)}\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+97}:\\
\;\;\;\;x \cdot \frac{y}{\left(\left(y + x\right) + 1\right) \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x \cdot \frac{x}{y}\right) \cdot -3 + x}{y}}{y}\\
\end{array}
\end{array}
if y < 2.95000000000000007e-136Initial program 64.3%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6464.2
Applied rewrites64.2%
Taylor expanded in y around 0
lower-*.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6485.8
Applied rewrites85.8%
if 2.95000000000000007e-136 < y < 1.4999999999999999e97Initial program 84.9%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6493.3
Applied rewrites93.3%
if 1.4999999999999999e97 < y Initial program 60.4%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in x around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6476.2
Applied rewrites76.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites90.2%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= y 3e-136)
(* 2.0 (/ y (fma 2.0 x (* 2.0 (* x x)))))
(if (<= y 1.15e+139)
(* x (/ (/ y (+ 1.0 y)) (* (+ y x) (+ y x))))
(/ (/ (+ (* (* x (/ x y)) -3.0) x) y) y))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3e-136) {
tmp = 2.0 * (y / fma(2.0, x, (2.0 * (x * x))));
} else if (y <= 1.15e+139) {
tmp = x * ((y / (1.0 + y)) / ((y + x) * (y + x)));
} else {
tmp = ((((x * (x / y)) * -3.0) + x) / y) / y;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3e-136) tmp = Float64(2.0 * Float64(y / fma(2.0, x, Float64(2.0 * Float64(x * x))))); elseif (y <= 1.15e+139) tmp = Float64(x * Float64(Float64(y / Float64(1.0 + y)) / Float64(Float64(y + x) * Float64(y + x)))); else tmp = Float64(Float64(Float64(Float64(Float64(x * Float64(x / y)) * -3.0) + x) / y) / y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 3e-136], N[(2.0 * N[(y / N[(2.0 * x + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.15e+139], N[(x * N[(N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision] / N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] * -3.0), $MachinePrecision] + x), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-136}:\\
\;\;\;\;2 \cdot \frac{y}{\mathsf{fma}\left(2, x, 2 \cdot \left(x \cdot x\right)\right)}\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+139}:\\
\;\;\;\;x \cdot \frac{\frac{y}{1 + y}}{\left(y + x\right) \cdot \left(y + x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x \cdot \frac{x}{y}\right) \cdot -3 + x}{y}}{y}\\
\end{array}
\end{array}
if y < 2.9999999999999998e-136Initial program 64.3%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6464.2
Applied rewrites64.2%
Taylor expanded in y around 0
lower-*.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6485.8
Applied rewrites85.8%
if 2.9999999999999998e-136 < y < 1.15e139Initial program 79.5%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6488.0
Applied rewrites88.0%
Taylor expanded in x around 0
lower-+.f6480.6
Applied rewrites80.6%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f6485.6
Applied rewrites85.6%
if 1.15e139 < y Initial program 61.8%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6474.5
Applied rewrites74.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6474.5
Applied rewrites74.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites91.7%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= y 3e-136)
(* 2.0 (/ y (fma 2.0 x (* 2.0 (* x x)))))
(if (<= y 1.5e+97)
(* x (/ y (* (+ 1.0 y) (* (+ y x) (+ y x)))))
(/ (/ (+ (* (* x (/ x y)) -3.0) x) y) y))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3e-136) {
tmp = 2.0 * (y / fma(2.0, x, (2.0 * (x * x))));
} else if (y <= 1.5e+97) {
tmp = x * (y / ((1.0 + y) * ((y + x) * (y + x))));
} else {
tmp = ((((x * (x / y)) * -3.0) + x) / y) / y;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3e-136) tmp = Float64(2.0 * Float64(y / fma(2.0, x, Float64(2.0 * Float64(x * x))))); elseif (y <= 1.5e+97) tmp = Float64(x * Float64(y / Float64(Float64(1.0 + y) * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(Float64(Float64(Float64(Float64(x * Float64(x / y)) * -3.0) + x) / y) / y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 3e-136], N[(2.0 * N[(y / N[(2.0 * x + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.5e+97], N[(x * N[(y / N[(N[(1.0 + y), $MachinePrecision] * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] * -3.0), $MachinePrecision] + x), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-136}:\\
\;\;\;\;2 \cdot \frac{y}{\mathsf{fma}\left(2, x, 2 \cdot \left(x \cdot x\right)\right)}\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+97}:\\
\;\;\;\;x \cdot \frac{y}{\left(1 + y\right) \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x \cdot \frac{x}{y}\right) \cdot -3 + x}{y}}{y}\\
\end{array}
\end{array}
if y < 2.9999999999999998e-136Initial program 64.3%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6464.2
Applied rewrites64.2%
Taylor expanded in y around 0
lower-*.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6485.8
Applied rewrites85.8%
if 2.9999999999999998e-136 < y < 1.4999999999999999e97Initial program 84.9%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6493.3
Applied rewrites93.3%
Taylor expanded in x around 0
lower-+.f6484.4
Applied rewrites84.4%
if 1.4999999999999999e97 < y Initial program 60.4%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in x around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6476.2
Applied rewrites76.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites90.2%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= y 3e-136)
(* 2.0 (/ y (fma 2.0 x (* 2.0 (* x x)))))
(if (<= y 2.9e-112)
(* x (/ y (* 1.0 (* (+ y x) (+ y x)))))
(if (<= y 21000000.0)
(/ (* x y) (* (* (+ x y) (+ x y)) (+ 1.0 x)))
(/ (/ (+ (* (* x (/ x y)) -3.0) x) y) y)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3e-136) {
tmp = 2.0 * (y / fma(2.0, x, (2.0 * (x * x))));
} else if (y <= 2.9e-112) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else if (y <= 21000000.0) {
tmp = (x * y) / (((x + y) * (x + y)) * (1.0 + x));
} else {
tmp = ((((x * (x / y)) * -3.0) + x) / y) / y;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3e-136) tmp = Float64(2.0 * Float64(y / fma(2.0, x, Float64(2.0 * Float64(x * x))))); elseif (y <= 2.9e-112) tmp = Float64(x * Float64(y / Float64(1.0 * Float64(Float64(y + x) * Float64(y + x))))); elseif (y <= 21000000.0) tmp = Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * Float64(1.0 + x))); else tmp = Float64(Float64(Float64(Float64(Float64(x * Float64(x / y)) * -3.0) + x) / y) / y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 3e-136], N[(2.0 * N[(y / N[(2.0 * x + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.9e-112], N[(x * N[(y / N[(1.0 * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 21000000.0], N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] * -3.0), $MachinePrecision] + x), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-136}:\\
\;\;\;\;2 \cdot \frac{y}{\mathsf{fma}\left(2, x, 2 \cdot \left(x \cdot x\right)\right)}\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-112}:\\
\;\;\;\;x \cdot \frac{y}{1 \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{elif}\;y \leq 21000000:\\
\;\;\;\;\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(1 + x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x \cdot \frac{x}{y}\right) \cdot -3 + x}{y}}{y}\\
\end{array}
\end{array}
if y < 2.9999999999999998e-136Initial program 64.3%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6464.2
Applied rewrites64.2%
Taylor expanded in y around 0
lower-*.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6485.8
Applied rewrites85.8%
if 2.9999999999999998e-136 < y < 2.89999999999999992e-112Initial program 70.4%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6498.9
Applied rewrites98.9%
Taylor expanded in x around 0
lower-+.f6489.8
Applied rewrites89.8%
Taylor expanded in y around 0
Applied rewrites89.8%
if 2.89999999999999992e-112 < y < 2.1e7Initial program 86.3%
Taylor expanded in y around 0
lower-+.f6479.0
Applied rewrites79.0%
if 2.1e7 < y Initial program 67.1%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6475.1
Applied rewrites75.1%
Taylor expanded in x around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6474.8
Applied rewrites74.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites85.2%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= y 3e-136)
(* 2.0 (/ y (fma 2.0 x (* 2.0 (* x x)))))
(if (<= y 10500000.0)
(* x (/ y (* 1.0 (* (+ y x) (+ y x)))))
(/ (/ (+ (* (* x (/ x y)) -3.0) x) y) y))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3e-136) {
tmp = 2.0 * (y / fma(2.0, x, (2.0 * (x * x))));
} else if (y <= 10500000.0) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else {
tmp = ((((x * (x / y)) * -3.0) + x) / y) / y;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3e-136) tmp = Float64(2.0 * Float64(y / fma(2.0, x, Float64(2.0 * Float64(x * x))))); elseif (y <= 10500000.0) tmp = Float64(x * Float64(y / Float64(1.0 * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(Float64(Float64(Float64(Float64(x * Float64(x / y)) * -3.0) + x) / y) / y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 3e-136], N[(2.0 * N[(y / N[(2.0 * x + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 10500000.0], N[(x * N[(y / N[(1.0 * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] * -3.0), $MachinePrecision] + x), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{-136}:\\
\;\;\;\;2 \cdot \frac{y}{\mathsf{fma}\left(2, x, 2 \cdot \left(x \cdot x\right)\right)}\\
\mathbf{elif}\;y \leq 10500000:\\
\;\;\;\;x \cdot \frac{y}{1 \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x \cdot \frac{x}{y}\right) \cdot -3 + x}{y}}{y}\\
\end{array}
\end{array}
if y < 2.9999999999999998e-136Initial program 64.3%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6464.2
Applied rewrites64.2%
Taylor expanded in y around 0
lower-*.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6485.8
Applied rewrites85.8%
if 2.9999999999999998e-136 < y < 1.05e7Initial program 84.2%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6494.8
Applied rewrites94.8%
Taylor expanded in x around 0
lower-+.f6483.6
Applied rewrites83.6%
Taylor expanded in y around 0
Applied rewrites77.8%
if 1.05e7 < y Initial program 67.1%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6475.1
Applied rewrites75.1%
Taylor expanded in x around inf
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6474.8
Applied rewrites74.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites85.1%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -5.5e+102)
(/ (/ (+ (/ y (- x)) y) x) x)
(if (<= x -75.0)
(/ (* x y) (* (* (+ x y) (+ x y)) x))
(if (<= x -2e-129)
(* x (/ y (* 1.0 (* (+ y x) (+ y x)))))
(/ x (* (+ 1.0 y) y))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -5.5e+102) {
tmp = (((y / -x) + y) / x) / x;
} else if (x <= -75.0) {
tmp = (x * y) / (((x + y) * (x + y)) * x);
} else if (x <= -2e-129) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5.5d+102)) then
tmp = (((y / -x) + y) / x) / x
else if (x <= (-75.0d0)) then
tmp = (x * y) / (((x + y) * (x + y)) * x)
else if (x <= (-2d-129)) then
tmp = x * (y / (1.0d0 * ((y + x) * (y + x))))
else
tmp = x / ((1.0d0 + y) * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -5.5e+102) {
tmp = (((y / -x) + y) / x) / x;
} else if (x <= -75.0) {
tmp = (x * y) / (((x + y) * (x + y)) * x);
} else if (x <= -2e-129) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -5.5e+102: tmp = (((y / -x) + y) / x) / x elif x <= -75.0: tmp = (x * y) / (((x + y) * (x + y)) * x) elif x <= -2e-129: tmp = x * (y / (1.0 * ((y + x) * (y + x)))) else: tmp = x / ((1.0 + y) * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -5.5e+102) tmp = Float64(Float64(Float64(Float64(y / Float64(-x)) + y) / x) / x); elseif (x <= -75.0) tmp = Float64(Float64(x * y) / Float64(Float64(Float64(x + y) * Float64(x + y)) * x)); elseif (x <= -2e-129) tmp = Float64(x * Float64(y / Float64(1.0 * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(x / Float64(Float64(1.0 + y) * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -5.5e+102)
tmp = (((y / -x) + y) / x) / x;
elseif (x <= -75.0)
tmp = (x * y) / (((x + y) * (x + y)) * x);
elseif (x <= -2e-129)
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
else
tmp = x / ((1.0 + y) * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -5.5e+102], N[(N[(N[(N[(y / (-x)), $MachinePrecision] + y), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, -75.0], N[(N[(x * y), $MachinePrecision] / N[(N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2e-129], N[(x * N[(y / N[(1.0 * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(1.0 + y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{\frac{\frac{y}{-x} + y}{x}}{x}\\
\mathbf{elif}\;x \leq -75:\\
\;\;\;\;\frac{x \cdot y}{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot x}\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-129}:\\
\;\;\;\;x \cdot \frac{y}{1 \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if x < -5.49999999999999981e102Initial program 58.7%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6475.2
Applied rewrites75.2%
Taylor expanded in y around 0
Applied rewrites83.4%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6490.5
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-neg.f6490.5
Applied rewrites90.5%
if -5.49999999999999981e102 < x < -75Initial program 86.2%
Taylor expanded in x around inf
Applied rewrites76.9%
if -75 < x < -1.9999999999999999e-129Initial program 83.8%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6496.7
Applied rewrites96.7%
Taylor expanded in x around 0
lower-+.f6492.5
Applied rewrites92.5%
Taylor expanded in y around 0
Applied rewrites78.3%
if -1.9999999999999999e-129 < x Initial program 65.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6485.8
Applied rewrites85.8%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -75.0)
(* (/ x (* (+ x y) (+ x y))) (/ y x))
(if (<= x -2e-129)
(* x (/ y (* 1.0 (* (+ y x) (+ y x)))))
(/ x (* (+ 1.0 y) y)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -75.0) {
tmp = (x / ((x + y) * (x + y))) * (y / x);
} else if (x <= -2e-129) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-75.0d0)) then
tmp = (x / ((x + y) * (x + y))) * (y / x)
else if (x <= (-2d-129)) then
tmp = x * (y / (1.0d0 * ((y + x) * (y + x))))
else
tmp = x / ((1.0d0 + y) * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -75.0) {
tmp = (x / ((x + y) * (x + y))) * (y / x);
} else if (x <= -2e-129) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -75.0: tmp = (x / ((x + y) * (x + y))) * (y / x) elif x <= -2e-129: tmp = x * (y / (1.0 * ((y + x) * (y + x)))) else: tmp = x / ((1.0 + y) * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -75.0) tmp = Float64(Float64(x / Float64(Float64(x + y) * Float64(x + y))) * Float64(y / x)); elseif (x <= -2e-129) tmp = Float64(x * Float64(y / Float64(1.0 * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(x / Float64(Float64(1.0 + y) * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -75.0)
tmp = (x / ((x + y) * (x + y))) * (y / x);
elseif (x <= -2e-129)
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
else
tmp = x / ((1.0 + y) * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -75.0], N[(N[(x / N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2e-129], N[(x * N[(y / N[(1.0 * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(1.0 + y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -75:\\
\;\;\;\;\frac{x}{\left(x + y\right) \cdot \left(x + y\right)} \cdot \frac{y}{x}\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-129}:\\
\;\;\;\;x \cdot \frac{y}{1 \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if x < -75Initial program 66.7%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6466.6
Applied rewrites66.6%
Taylor expanded in x around inf
Applied rewrites64.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites84.6%
if -75 < x < -1.9999999999999999e-129Initial program 83.8%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6496.7
Applied rewrites96.7%
Taylor expanded in x around 0
lower-+.f6492.5
Applied rewrites92.5%
Taylor expanded in y around 0
Applied rewrites78.3%
if -1.9999999999999999e-129 < x Initial program 65.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6485.8
Applied rewrites85.8%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -10600000.0)
(/ (/ (+ (/ y (- x)) y) x) x)
(if (<= x -2e-129)
(* x (/ y (* 1.0 (* (+ y x) (+ y x)))))
(/ x (* (+ 1.0 y) y)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -10600000.0) {
tmp = (((y / -x) + y) / x) / x;
} else if (x <= -2e-129) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-10600000.0d0)) then
tmp = (((y / -x) + y) / x) / x
else if (x <= (-2d-129)) then
tmp = x * (y / (1.0d0 * ((y + x) * (y + x))))
else
tmp = x / ((1.0d0 + y) * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -10600000.0) {
tmp = (((y / -x) + y) / x) / x;
} else if (x <= -2e-129) {
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -10600000.0: tmp = (((y / -x) + y) / x) / x elif x <= -2e-129: tmp = x * (y / (1.0 * ((y + x) * (y + x)))) else: tmp = x / ((1.0 + y) * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -10600000.0) tmp = Float64(Float64(Float64(Float64(y / Float64(-x)) + y) / x) / x); elseif (x <= -2e-129) tmp = Float64(x * Float64(y / Float64(1.0 * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(x / Float64(Float64(1.0 + y) * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -10600000.0)
tmp = (((y / -x) + y) / x) / x;
elseif (x <= -2e-129)
tmp = x * (y / (1.0 * ((y + x) * (y + x))));
else
tmp = x / ((1.0 + y) * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -10600000.0], N[(N[(N[(N[(y / (-x)), $MachinePrecision] + y), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, -2e-129], N[(x * N[(y / N[(1.0 * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(1.0 + y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10600000:\\
\;\;\;\;\frac{\frac{\frac{y}{-x} + y}{x}}{x}\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-129}:\\
\;\;\;\;x \cdot \frac{y}{1 \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if x < -1.06e7Initial program 66.4%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6474.9
Applied rewrites74.9%
Taylor expanded in y around 0
Applied rewrites80.6%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6485.7
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-frac2N/A
lower-/.f64N/A
lower-neg.f6485.7
Applied rewrites85.7%
if -1.06e7 < x < -1.9999999999999999e-129Initial program 84.1%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6496.5
Applied rewrites96.5%
Taylor expanded in x around 0
lower-+.f6490.1
Applied rewrites90.1%
Taylor expanded in y around 0
Applied rewrites76.0%
if -1.9999999999999999e-129 < x Initial program 65.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6485.8
Applied rewrites85.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 3.6e-72) (* 2.0 (/ y (fma 2.0 x (* 2.0 (* x x))))) (/ x (* (+ 1.0 y) y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3.6e-72) {
tmp = 2.0 * (y / fma(2.0, x, (2.0 * (x * x))));
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3.6e-72) tmp = Float64(2.0 * Float64(y / fma(2.0, x, Float64(2.0 * Float64(x * x))))); else tmp = Float64(x / Float64(Float64(1.0 + y) * y)); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 3.6e-72], N[(2.0 * N[(y / N[(2.0 * x + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(1.0 + y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.6 \cdot 10^{-72}:\\
\;\;\;\;2 \cdot \frac{y}{\mathsf{fma}\left(2, x, 2 \cdot \left(x \cdot x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if y < 3.6e-72Initial program 66.2%
lift-+.f64N/A
lift-+.f64N/A
flip-+N/A
metadata-evalN/A
frac-addN/A
lower-/.f64N/A
lower-fma.f64N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f6466.1
Applied rewrites66.1%
Taylor expanded in y around 0
lower-*.f64N/A
lower-/.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6480.5
Applied rewrites80.5%
if 3.6e-72 < y Initial program 71.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6476.8
Applied rewrites76.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 3.6e-72) (/ y (* (+ 1.0 x) x)) (/ x (* (+ 1.0 y) y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3.6e-72) {
tmp = y / ((1.0 + x) * x);
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 3.6d-72) then
tmp = y / ((1.0d0 + x) * x)
else
tmp = x / ((1.0d0 + y) * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= 3.6e-72) {
tmp = y / ((1.0 + x) * x);
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 3.6e-72: tmp = y / ((1.0 + x) * x) else: tmp = x / ((1.0 + y) * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3.6e-72) tmp = Float64(y / Float64(Float64(1.0 + x) * x)); else tmp = Float64(x / Float64(Float64(1.0 + y) * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= 3.6e-72)
tmp = y / ((1.0 + x) * x);
else
tmp = x / ((1.0 + y) * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 3.6e-72], N[(y / N[(N[(1.0 + x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(1.0 + y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.6 \cdot 10^{-72}:\\
\;\;\;\;\frac{y}{\left(1 + x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if y < 3.6e-72Initial program 66.2%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6480.5
Applied rewrites80.5%
if 3.6e-72 < y Initial program 71.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6476.8
Applied rewrites76.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -5100000000.0) (/ y (* x x)) (/ x (* (+ 1.0 y) y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -5100000000.0) {
tmp = y / (x * x);
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5100000000.0d0)) then
tmp = y / (x * x)
else
tmp = x / ((1.0d0 + y) * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -5100000000.0) {
tmp = y / (x * x);
} else {
tmp = x / ((1.0 + y) * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -5100000000.0: tmp = y / (x * x) else: tmp = x / ((1.0 + y) * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -5100000000.0) tmp = Float64(y / Float64(x * x)); else tmp = Float64(x / Float64(Float64(1.0 + y) * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -5100000000.0)
tmp = y / (x * x);
else
tmp = x / ((1.0 + y) * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -5100000000.0], N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(1.0 + y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5100000000:\\
\;\;\;\;\frac{y}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if x < -5.1e9Initial program 66.3%
Taylor expanded in x around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6480.6
Applied rewrites80.6%
if -5.1e9 < x Initial program 70.5%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6474.4
Applied rewrites74.4%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (* y y))))
(if (<= x -5100000000.0)
(/ y (* x x))
(if (<= x -3.7e-180) t_0 (if (<= x 1.75e-163) (* x (/ 1.0 y)) t_0)))))assert(x < y);
double code(double x, double y) {
double t_0 = x / (y * y);
double tmp;
if (x <= -5100000000.0) {
tmp = y / (x * x);
} else if (x <= -3.7e-180) {
tmp = t_0;
} else if (x <= 1.75e-163) {
tmp = x * (1.0 / y);
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x / (y * y)
if (x <= (-5100000000.0d0)) then
tmp = y / (x * x)
else if (x <= (-3.7d-180)) then
tmp = t_0
else if (x <= 1.75d-163) then
tmp = x * (1.0d0 / y)
else
tmp = t_0
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = x / (y * y);
double tmp;
if (x <= -5100000000.0) {
tmp = y / (x * x);
} else if (x <= -3.7e-180) {
tmp = t_0;
} else if (x <= 1.75e-163) {
tmp = x * (1.0 / y);
} else {
tmp = t_0;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = x / (y * y) tmp = 0 if x <= -5100000000.0: tmp = y / (x * x) elif x <= -3.7e-180: tmp = t_0 elif x <= 1.75e-163: tmp = x * (1.0 / y) else: tmp = t_0 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(x / Float64(y * y)) tmp = 0.0 if (x <= -5100000000.0) tmp = Float64(y / Float64(x * x)); elseif (x <= -3.7e-180) tmp = t_0; elseif (x <= 1.75e-163) tmp = Float64(x * Float64(1.0 / y)); else tmp = t_0; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = x / (y * y);
tmp = 0.0;
if (x <= -5100000000.0)
tmp = y / (x * x);
elseif (x <= -3.7e-180)
tmp = t_0;
elseif (x <= 1.75e-163)
tmp = x * (1.0 / y);
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5100000000.0], N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -3.7e-180], t$95$0, If[LessEqual[x, 1.75e-163], N[(x * N[(1.0 / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \frac{x}{y \cdot y}\\
\mathbf{if}\;x \leq -5100000000:\\
\;\;\;\;\frac{y}{x \cdot x}\\
\mathbf{elif}\;x \leq -3.7 \cdot 10^{-180}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{-163}:\\
\;\;\;\;x \cdot \frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.1e9Initial program 66.3%
Taylor expanded in x around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6480.6
Applied rewrites80.6%
if -5.1e9 < x < -3.70000000000000016e-180 or 1.75000000000000014e-163 < x Initial program 74.3%
Taylor expanded in y around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6453.8
Applied rewrites53.8%
if -3.70000000000000016e-180 < x < 1.75000000000000014e-163Initial program 64.3%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6478.2
Applied rewrites78.2%
Taylor expanded in x around 0
lower-/.f64N/A
lower-*.f64N/A
lower-+.f6489.5
Applied rewrites89.5%
Taylor expanded in y around 0
Applied rewrites78.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -5100000000.0) (/ y (* x x)) (/ x (* y y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -5100000000.0) {
tmp = y / (x * x);
} else {
tmp = x / (y * y);
}
return tmp;
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5100000000.0d0)) then
tmp = y / (x * x)
else
tmp = x / (y * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -5100000000.0) {
tmp = y / (x * x);
} else {
tmp = x / (y * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -5100000000.0: tmp = y / (x * x) else: tmp = x / (y * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -5100000000.0) tmp = Float64(y / Float64(x * x)); else tmp = Float64(x / Float64(y * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -5100000000.0)
tmp = y / (x * x);
else
tmp = x / (y * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -5100000000.0], N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5100000000:\\
\;\;\;\;\frac{y}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot y}\\
\end{array}
\end{array}
if x < -5.1e9Initial program 66.3%
Taylor expanded in x around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6480.6
Applied rewrites80.6%
if -5.1e9 < x Initial program 70.5%
Taylor expanded in y around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6453.7
Applied rewrites53.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (/ x (* y y)))
assert(x < y);
double code(double x, double y) {
return x / (y * y);
}
NOTE: x and y 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / (y * y)
end function
assert x < y;
public static double code(double x, double y) {
return x / (y * y);
}
[x, y] = sort([x, y]) def code(x, y): return x / (y * y)
x, y = sort([x, y]) function code(x, y) return Float64(x / Float64(y * y)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x / (y * y);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{x}{y \cdot y}
\end{array}
Initial program 68.7%
Taylor expanded in y around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6437.3
Applied rewrites37.3%
herbie shell --seed 2025120
(FPCore (x y)
:name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, A"
:precision binary64
(/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))