
(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}
Sampling outcomes in binary64 precision:
Herbie found 11 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 (<= x -2.25e+45)
(/ (/ (fma (* (* 3.0 y) (/ y x)) -1.0 y) x) x)
(if (<= x -1.6e-164)
(* x (/ y (* (+ (+ y x) 1.0) (* (+ y x) (+ y x)))))
(/ (/ x y) (+ 1.0 y)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.25e+45) {
tmp = (fma(((3.0 * y) * (y / x)), -1.0, y) / x) / x;
} else if (x <= -1.6e-164) {
tmp = x * (y / (((y + x) + 1.0) * ((y + x) * (y + x))));
} else {
tmp = (x / y) / (1.0 + y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.25e+45) tmp = Float64(Float64(fma(Float64(Float64(3.0 * y) * Float64(y / x)), -1.0, y) / x) / x); elseif (x <= -1.6e-164) tmp = Float64(x * Float64(y / Float64(Float64(Float64(y + x) + 1.0) * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(Float64(x / y) / Float64(1.0 + y)); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -2.25e+45], N[(N[(N[(N[(N[(3.0 * y), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] * -1.0 + y), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, -1.6e-164], 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[(x / y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.25 \cdot 10^{+45}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\left(3 \cdot y\right) \cdot \frac{y}{x}, -1, y\right)}{x}}{x}\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{-164}:\\
\;\;\;\;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{x}{y}}{1 + y}\\
\end{array}
\end{array}
if x < -2.2499999999999999e45Initial program 59.4%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.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-*.f6463.1
Applied rewrites63.1%
Taylor expanded in y around inf
lower-*.f6463.1
Applied rewrites63.1%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6474.5
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6480.9
Applied rewrites80.9%
if -2.2499999999999999e45 < x < -1.6e-164Initial program 88.7%
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
pow2N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f6493.5
Applied rewrites93.5%
lift-+.f64N/A
+-commutativeN/A
lower-pow.f64N/A
pow2N/A
lower-*.f64N/A
+-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
lift-+.f6493.5
Applied rewrites93.5%
if -1.6e-164 < x Initial program 68.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6454.6
Applied rewrites54.6%
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-+.f6457.0
Applied rewrites57.0%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -2.25e+45)
(/ (/ y x) x)
(if (<= x -1.6e-164)
(* x (/ y (* (+ (+ y x) 1.0) (* (+ y x) (+ y x)))))
(/ (/ x y) (+ 1.0 y)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.25e+45) {
tmp = (y / x) / x;
} else if (x <= -1.6e-164) {
tmp = x * (y / (((y + x) + 1.0) * ((y + x) * (y + x))));
} else {
tmp = (x / y) / (1.0 + 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 <= (-2.25d+45)) then
tmp = (y / x) / x
else if (x <= (-1.6d-164)) then
tmp = x * (y / (((y + x) + 1.0d0) * ((y + x) * (y + x))))
else
tmp = (x / y) / (1.0d0 + y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -2.25e+45) {
tmp = (y / x) / x;
} else if (x <= -1.6e-164) {
tmp = x * (y / (((y + x) + 1.0) * ((y + x) * (y + x))));
} else {
tmp = (x / y) / (1.0 + y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.25e+45: tmp = (y / x) / x elif x <= -1.6e-164: tmp = x * (y / (((y + x) + 1.0) * ((y + x) * (y + x)))) else: tmp = (x / y) / (1.0 + y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.25e+45) tmp = Float64(Float64(y / x) / x); elseif (x <= -1.6e-164) tmp = Float64(x * Float64(y / Float64(Float64(Float64(y + x) + 1.0) * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(Float64(x / y) / Float64(1.0 + y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -2.25e+45)
tmp = (y / x) / x;
elseif (x <= -1.6e-164)
tmp = x * (y / (((y + x) + 1.0) * ((y + x) * (y + x))));
else
tmp = (x / y) / (1.0 + 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, -2.25e+45], N[(N[(y / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, -1.6e-164], 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[(x / y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.25 \cdot 10^{+45}:\\
\;\;\;\;\frac{\frac{y}{x}}{x}\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{-164}:\\
\;\;\;\;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{x}{y}}{1 + y}\\
\end{array}
\end{array}
if x < -2.2499999999999999e45Initial program 59.4%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.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-*.f6463.1
Applied rewrites63.1%
Taylor expanded in x around inf
Applied rewrites73.4%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6481.3
Applied rewrites81.3%
if -2.2499999999999999e45 < x < -1.6e-164Initial program 88.7%
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
pow2N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f6493.5
Applied rewrites93.5%
lift-+.f64N/A
+-commutativeN/A
lower-pow.f64N/A
pow2N/A
lower-*.f64N/A
+-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
lift-+.f6493.5
Applied rewrites93.5%
if -1.6e-164 < x Initial program 68.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6454.6
Applied rewrites54.6%
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-+.f6457.0
Applied rewrites57.0%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -2.8e+22)
(/ (/ y x) x)
(if (<= x -1.6e-164)
(* x (/ y (* (+ y 1.0) (* (+ y x) (+ y x)))))
(/ (/ x y) (+ 1.0 y)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.8e+22) {
tmp = (y / x) / x;
} else if (x <= -1.6e-164) {
tmp = x * (y / ((y + 1.0) * ((y + x) * (y + x))));
} else {
tmp = (x / y) / (1.0 + 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 <= (-2.8d+22)) then
tmp = (y / x) / x
else if (x <= (-1.6d-164)) then
tmp = x * (y / ((y + 1.0d0) * ((y + x) * (y + x))))
else
tmp = (x / y) / (1.0d0 + y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -2.8e+22) {
tmp = (y / x) / x;
} else if (x <= -1.6e-164) {
tmp = x * (y / ((y + 1.0) * ((y + x) * (y + x))));
} else {
tmp = (x / y) / (1.0 + y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.8e+22: tmp = (y / x) / x elif x <= -1.6e-164: tmp = x * (y / ((y + 1.0) * ((y + x) * (y + x)))) else: tmp = (x / y) / (1.0 + y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.8e+22) tmp = Float64(Float64(y / x) / x); elseif (x <= -1.6e-164) tmp = Float64(x * Float64(y / Float64(Float64(y + 1.0) * Float64(Float64(y + x) * Float64(y + x))))); else tmp = Float64(Float64(x / y) / Float64(1.0 + y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -2.8e+22)
tmp = (y / x) / x;
elseif (x <= -1.6e-164)
tmp = x * (y / ((y + 1.0) * ((y + x) * (y + x))));
else
tmp = (x / y) / (1.0 + 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, -2.8e+22], N[(N[(y / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, -1.6e-164], N[(x * N[(y / N[(N[(y + 1.0), $MachinePrecision] * N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+22}:\\
\;\;\;\;\frac{\frac{y}{x}}{x}\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{-164}:\\
\;\;\;\;x \cdot \frac{y}{\left(y + 1\right) \cdot \left(\left(y + x\right) \cdot \left(y + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{y}}{1 + y}\\
\end{array}
\end{array}
if x < -2.8e22Initial program 61.1%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.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-*.f6464.4
Applied rewrites64.4%
Taylor expanded in x around inf
Applied rewrites73.9%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6481.3
Applied rewrites81.3%
if -2.8e22 < x < -1.6e-164Initial program 89.7%
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
pow2N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f6495.2
Applied rewrites95.2%
lift-+.f64N/A
+-commutativeN/A
lower-pow.f64N/A
pow2N/A
lower-*.f64N/A
+-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
lift-+.f6495.2
Applied rewrites95.2%
Taylor expanded in x around 0
Applied rewrites93.9%
if -1.6e-164 < x Initial program 68.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6454.6
Applied rewrites54.6%
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-+.f6457.0
Applied rewrites57.0%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -2.45e+31)
(/ (/ y x) x)
(if (<= x -0.0105)
(/ x (* y y))
(if (<= x -3.05e-64) (/ y (* (+ 1.0 x) x)) (/ (/ x y) (+ 1.0 y))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.45e+31) {
tmp = (y / x) / x;
} else if (x <= -0.0105) {
tmp = x / (y * y);
} else if (x <= -3.05e-64) {
tmp = y / ((1.0 + x) * x);
} else {
tmp = (x / y) / (1.0 + 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 <= (-2.45d+31)) then
tmp = (y / x) / x
else if (x <= (-0.0105d0)) then
tmp = x / (y * y)
else if (x <= (-3.05d-64)) then
tmp = y / ((1.0d0 + x) * x)
else
tmp = (x / y) / (1.0d0 + y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -2.45e+31) {
tmp = (y / x) / x;
} else if (x <= -0.0105) {
tmp = x / (y * y);
} else if (x <= -3.05e-64) {
tmp = y / ((1.0 + x) * x);
} else {
tmp = (x / y) / (1.0 + y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.45e+31: tmp = (y / x) / x elif x <= -0.0105: tmp = x / (y * y) elif x <= -3.05e-64: tmp = y / ((1.0 + x) * x) else: tmp = (x / y) / (1.0 + y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.45e+31) tmp = Float64(Float64(y / x) / x); elseif (x <= -0.0105) tmp = Float64(x / Float64(y * y)); elseif (x <= -3.05e-64) tmp = Float64(y / Float64(Float64(1.0 + x) * x)); else tmp = Float64(Float64(x / y) / Float64(1.0 + y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -2.45e+31)
tmp = (y / x) / x;
elseif (x <= -0.0105)
tmp = x / (y * y);
elseif (x <= -3.05e-64)
tmp = y / ((1.0 + x) * x);
else
tmp = (x / y) / (1.0 + 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, -2.45e+31], N[(N[(y / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, -0.0105], N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -3.05e-64], N[(y / N[(N[(1.0 + x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{+31}:\\
\;\;\;\;\frac{\frac{y}{x}}{x}\\
\mathbf{elif}\;x \leq -0.0105:\\
\;\;\;\;\frac{x}{y \cdot y}\\
\mathbf{elif}\;x \leq -3.05 \cdot 10^{-64}:\\
\;\;\;\;\frac{y}{\left(1 + x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{y}}{1 + y}\\
\end{array}
\end{array}
if x < -2.44999999999999998e31Initial program 61.3%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.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-*.f6464.8
Applied rewrites64.8%
Taylor expanded in x around inf
Applied rewrites74.6%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2
Applied rewrites82.2%
if -2.44999999999999998e31 < x < -0.0105000000000000007Initial program 83.7%
Taylor expanded in y around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
if -0.0105000000000000007 < x < -3.0499999999999998e-64Initial program 83.0%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6467.4
Applied rewrites67.4%
if -3.0499999999999998e-64 < x Initial program 71.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6459.3
Applied rewrites59.3%
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-+.f6461.3
Applied rewrites61.3%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -2.45e+31)
(/ (/ y x) x)
(if (<= x -0.0105)
(/ x (* y y))
(if (<= x -3.05e-64) (/ y (* (+ 1.0 x) x)) (/ x (fma y 1.0 (* y y)))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.45e+31) {
tmp = (y / x) / x;
} else if (x <= -0.0105) {
tmp = x / (y * y);
} else if (x <= -3.05e-64) {
tmp = y / ((1.0 + x) * x);
} else {
tmp = x / fma(y, 1.0, (y * y));
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.45e+31) tmp = Float64(Float64(y / x) / x); elseif (x <= -0.0105) tmp = Float64(x / Float64(y * y)); elseif (x <= -3.05e-64) tmp = Float64(y / Float64(Float64(1.0 + x) * x)); else tmp = Float64(x / fma(y, 1.0, Float64(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[x, -2.45e+31], N[(N[(y / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, -0.0105], N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -3.05e-64], N[(y / N[(N[(1.0 + x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(x / N[(y * 1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{+31}:\\
\;\;\;\;\frac{\frac{y}{x}}{x}\\
\mathbf{elif}\;x \leq -0.0105:\\
\;\;\;\;\frac{x}{y \cdot y}\\
\mathbf{elif}\;x \leq -3.05 \cdot 10^{-64}:\\
\;\;\;\;\frac{y}{\left(1 + x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(y, 1, y \cdot y\right)}\\
\end{array}
\end{array}
if x < -2.44999999999999998e31Initial program 61.3%
Taylor expanded in x around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.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-*.f6464.8
Applied rewrites64.8%
Taylor expanded in x around inf
Applied rewrites74.6%
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.2
Applied rewrites82.2%
if -2.44999999999999998e31 < x < -0.0105000000000000007Initial program 83.7%
Taylor expanded in y around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
if -0.0105000000000000007 < x < -3.0499999999999998e-64Initial program 83.0%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6467.4
Applied rewrites67.4%
if -3.0499999999999998e-64 < x Initial program 71.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6459.3
Applied rewrites59.3%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-inN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.3
Applied rewrites59.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -2.45e+31) (/ y (* x x)) (if (or (<= x -8.2e-202) (not (<= x 4.9e-55))) (/ x (* y y)) (/ x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.45e+31) {
tmp = y / (x * x);
} else if ((x <= -8.2e-202) || !(x <= 4.9e-55)) {
tmp = x / (y * y);
} else {
tmp = x / 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 <= (-2.45d+31)) then
tmp = y / (x * x)
else if ((x <= (-8.2d-202)) .or. (.not. (x <= 4.9d-55))) then
tmp = x / (y * y)
else
tmp = x / y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -2.45e+31) {
tmp = y / (x * x);
} else if ((x <= -8.2e-202) || !(x <= 4.9e-55)) {
tmp = x / (y * y);
} else {
tmp = x / y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.45e+31: tmp = y / (x * x) elif (x <= -8.2e-202) or not (x <= 4.9e-55): tmp = x / (y * y) else: tmp = x / y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.45e+31) tmp = Float64(y / Float64(x * x)); elseif ((x <= -8.2e-202) || !(x <= 4.9e-55)) tmp = Float64(x / Float64(y * y)); else tmp = Float64(x / y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -2.45e+31)
tmp = y / (x * x);
elseif ((x <= -8.2e-202) || ~((x <= 4.9e-55)))
tmp = x / (y * y);
else
tmp = x / 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, -2.45e+31], N[(y / N[(x * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -8.2e-202], N[Not[LessEqual[x, 4.9e-55]], $MachinePrecision]], N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{+31}:\\
\;\;\;\;\frac{y}{x \cdot x}\\
\mathbf{elif}\;x \leq -8.2 \cdot 10^{-202} \lor \neg \left(x \leq 4.9 \cdot 10^{-55}\right):\\
\;\;\;\;\frac{x}{y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -2.44999999999999998e31Initial program 61.3%
Taylor expanded in x around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6474.6
Applied rewrites74.6%
if -2.44999999999999998e31 < x < -8.2000000000000008e-202 or 4.90000000000000035e-55 < x Initial program 74.7%
Taylor expanded in y around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6438.0
Applied rewrites38.0%
if -8.2000000000000008e-202 < x < 4.90000000000000035e-55Initial program 68.4%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6482.8
Applied rewrites82.8%
Taylor expanded in y around 0
Applied rewrites69.8%
Final simplification56.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -3.05e-64) (/ y (* (+ 1.0 x) x)) (/ x (fma y 1.0 (* y y)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.05e-64) {
tmp = y / ((1.0 + x) * x);
} else {
tmp = x / fma(y, 1.0, (y * y));
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -3.05e-64) tmp = Float64(y / Float64(Float64(1.0 + x) * x)); else tmp = Float64(x / fma(y, 1.0, Float64(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[x, -3.05e-64], N[(y / N[(N[(1.0 + x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(x / N[(y * 1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.05 \cdot 10^{-64}:\\
\;\;\;\;\frac{y}{\left(1 + x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(y, 1, y \cdot y\right)}\\
\end{array}
\end{array}
if x < -3.0499999999999998e-64Initial program 66.1%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6469.6
Applied rewrites69.6%
if -3.0499999999999998e-64 < x Initial program 71.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6459.3
Applied rewrites59.3%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-inN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.3
Applied rewrites59.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -3.05e-64) (/ y (* (+ 1.0 x) x)) (/ x (* (+ 1.0 y) y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.05e-64) {
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 (x <= (-3.05d-64)) 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 (x <= -3.05e-64) {
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 x <= -3.05e-64: 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 (x <= -3.05e-64) 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 (x <= -3.05e-64)
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[x, -3.05e-64], 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}\;x \leq -3.05 \cdot 10^{-64}:\\
\;\;\;\;\frac{y}{\left(1 + x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if x < -3.0499999999999998e-64Initial program 66.1%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6469.6
Applied rewrites69.6%
if -3.0499999999999998e-64 < x Initial program 71.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6459.3
Applied rewrites59.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -2.45e+31) (/ y (* x x)) (/ x (* (+ 1.0 y) y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.45e+31) {
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 <= (-2.45d+31)) 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 <= -2.45e+31) {
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 <= -2.45e+31: 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 <= -2.45e+31) 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 <= -2.45e+31)
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, -2.45e+31], 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 -2.45 \cdot 10^{+31}:\\
\;\;\;\;\frac{y}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(1 + y\right) \cdot y}\\
\end{array}
\end{array}
if x < -2.44999999999999998e31Initial program 61.3%
Taylor expanded in x around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6474.6
Applied rewrites74.6%
if -2.44999999999999998e31 < x Initial program 72.4%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6458.6
Applied rewrites58.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 1.0) (/ x y) (/ x (* y y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x / y;
} 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 (y <= 1.0d0) then
tmp = x / y
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 (y <= 1.0) {
tmp = x / y;
} else {
tmp = x / (y * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 1.0: tmp = x / y else: tmp = x / (y * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = Float64(x / y); 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 (y <= 1.0)
tmp = x / y;
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[y, 1.0], N[(x / y), $MachinePrecision], N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot y}\\
\end{array}
\end{array}
if y < 1Initial program 71.8%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6443.4
Applied rewrites43.4%
Taylor expanded in y around 0
Applied rewrites25.8%
if 1 < y Initial program 61.9%
Taylor expanded in y around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6466.7
Applied rewrites66.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (/ x y))
assert(x < y);
double code(double x, double y) {
return x / 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
end function
assert x < y;
public static double code(double x, double y) {
return x / y;
}
[x, y] = sort([x, y]) def code(x, y): return x / y
x, y = sort([x, y]) function code(x, y) return Float64(x / y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x / y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x / y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{x}{y}
\end{array}
Initial program 69.6%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6448.7
Applied rewrites48.7%
Taylor expanded in y around 0
Applied rewrites25.1%
(FPCore (x y) :precision binary64 (/ (/ (/ x (+ (+ y 1.0) x)) (+ y x)) (/ 1.0 (/ y (+ y x)))))
double code(double x, double y) {
return ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x)));
}
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 + 1.0d0) + x)) / (y + x)) / (1.0d0 / (y / (y + x)))
end function
public static double code(double x, double y) {
return ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x)));
}
def code(x, y): return ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x)))
function code(x, y) return Float64(Float64(Float64(x / Float64(Float64(y + 1.0) + x)) / Float64(y + x)) / Float64(1.0 / Float64(y / Float64(y + x)))) end
function tmp = code(x, y) tmp = ((x / ((y + 1.0) + x)) / (y + x)) / (1.0 / (y / (y + x))); end
code[x_, y_] := N[(N[(N[(x / N[(N[(y + 1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision] / N[(1.0 / N[(y / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{x}{\left(y + 1\right) + x}}{y + x}}{\frac{1}{\frac{y}{y + x}}}
\end{array}
herbie shell --seed 2025037
(FPCore (x y)
:name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, A"
:precision binary64
:alt
(! :herbie-platform default (/ (/ (/ x (+ (+ y 1) x)) (+ y x)) (/ 1 (/ y (+ y x)))))
(/ (* x y) (* (* (+ x y) (+ x y)) (+ (+ x y) 1.0))))