
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
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 = abs((x - y)) / abs(y)
end function
public static double code(double x, double y) {
return Math.abs((x - y)) / Math.abs(y);
}
def code(x, y): return math.fabs((x - y)) / math.fabs(y)
function code(x, y) return Float64(abs(Float64(x - y)) / abs(y)) end
function tmp = code(x, y) tmp = abs((x - y)) / abs(y); end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
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 = abs((x - y)) / abs(y)
end function
public static double code(double x, double y) {
return Math.abs((x - y)) / Math.abs(y);
}
def code(x, y): return math.fabs((x - y)) / math.fabs(y)
function code(x, y) return Float64(abs(Float64(x - y)) / abs(y)) end
function tmp = code(x, y) tmp = abs((x - y)) / abs(y); end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
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 = abs((x - y)) / abs(y)
end function
public static double code(double x, double y) {
return Math.abs((x - y)) / Math.abs(y);
}
def code(x, y): return math.fabs((x - y)) / math.fabs(y)
function code(x, y) return Float64(abs(Float64(x - y)) / abs(y)) end
function tmp = code(x, y) tmp = abs((x - y)) / abs(y); end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= (/ (fabs (- x y)) (fabs y)) 1000.0) (- 1.0 (/ x y)) (/ (fabs x) (fabs y))))
double code(double x, double y) {
double tmp;
if ((fabs((x - y)) / fabs(y)) <= 1000.0) {
tmp = 1.0 - (x / y);
} else {
tmp = fabs(x) / fabs(y);
}
return tmp;
}
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 ((abs((x - y)) / abs(y)) <= 1000.0d0) then
tmp = 1.0d0 - (x / y)
else
tmp = abs(x) / abs(y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.abs((x - y)) / Math.abs(y)) <= 1000.0) {
tmp = 1.0 - (x / y);
} else {
tmp = Math.abs(x) / Math.abs(y);
}
return tmp;
}
def code(x, y): tmp = 0 if (math.fabs((x - y)) / math.fabs(y)) <= 1000.0: tmp = 1.0 - (x / y) else: tmp = math.fabs(x) / math.fabs(y) return tmp
function code(x, y) tmp = 0.0 if (Float64(abs(Float64(x - y)) / abs(y)) <= 1000.0) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(abs(x) / abs(y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((abs((x - y)) / abs(y)) <= 1000.0) tmp = 1.0 - (x / y); else tmp = abs(x) / abs(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision], 1000.0], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(N[Abs[x], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left|x - y\right|}{\left|y\right|} \leq 1000:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|x\right|}{\left|y\right|}\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 1e3Initial program 100.0%
Applied rewrites99.4%
if 1e3 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
Taylor expanded in x around inf
rem-square-sqrt98.7
sqrt-prod98.7
rem-sqrt-square-rev98.7
Applied rewrites98.7%
(FPCore (x y) :precision binary64 (if (<= (/ (fabs (- x y)) (fabs y)) 2.0) 1.0 (/ (fabs x) (fabs y))))
double code(double x, double y) {
double tmp;
if ((fabs((x - y)) / fabs(y)) <= 2.0) {
tmp = 1.0;
} else {
tmp = fabs(x) / fabs(y);
}
return tmp;
}
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 ((abs((x - y)) / abs(y)) <= 2.0d0) then
tmp = 1.0d0
else
tmp = abs(x) / abs(y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.abs((x - y)) / Math.abs(y)) <= 2.0) {
tmp = 1.0;
} else {
tmp = Math.abs(x) / Math.abs(y);
}
return tmp;
}
def code(x, y): tmp = 0 if (math.fabs((x - y)) / math.fabs(y)) <= 2.0: tmp = 1.0 else: tmp = math.fabs(x) / math.fabs(y) return tmp
function code(x, y) tmp = 0.0 if (Float64(abs(Float64(x - y)) / abs(y)) <= 2.0) tmp = 1.0; else tmp = Float64(abs(x) / abs(y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((abs((x - y)) / abs(y)) <= 2.0) tmp = 1.0; else tmp = abs(x) / abs(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision], 2.0], 1.0, N[(N[Abs[x], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left|x - y\right|}{\left|y\right|} \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|x\right|}{\left|y\right|}\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 2Initial program 100.0%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites97.8%
if 2 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
Taylor expanded in x around inf
rem-square-sqrt98.0
sqrt-prod98.0
rem-sqrt-square-rev98.0
Applied rewrites98.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (fabs (- x y)) (fabs y)))) (if (<= t_0 1000.0) 1.0 (if (<= t_0 2e+240) (/ x y) (/ (- x) y)))))
double code(double x, double y) {
double t_0 = fabs((x - y)) / fabs(y);
double tmp;
if (t_0 <= 1000.0) {
tmp = 1.0;
} else if (t_0 <= 2e+240) {
tmp = x / y;
} else {
tmp = -x / y;
}
return tmp;
}
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 = abs((x - y)) / abs(y)
if (t_0 <= 1000.0d0) then
tmp = 1.0d0
else if (t_0 <= 2d+240) then
tmp = x / y
else
tmp = -x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.abs((x - y)) / Math.abs(y);
double tmp;
if (t_0 <= 1000.0) {
tmp = 1.0;
} else if (t_0 <= 2e+240) {
tmp = x / y;
} else {
tmp = -x / y;
}
return tmp;
}
def code(x, y): t_0 = math.fabs((x - y)) / math.fabs(y) tmp = 0 if t_0 <= 1000.0: tmp = 1.0 elif t_0 <= 2e+240: tmp = x / y else: tmp = -x / y return tmp
function code(x, y) t_0 = Float64(abs(Float64(x - y)) / abs(y)) tmp = 0.0 if (t_0 <= 1000.0) tmp = 1.0; elseif (t_0 <= 2e+240) tmp = Float64(x / y); else tmp = Float64(Float64(-x) / y); end return tmp end
function tmp_2 = code(x, y) t_0 = abs((x - y)) / abs(y); tmp = 0.0; if (t_0 <= 1000.0) tmp = 1.0; elseif (t_0 <= 2e+240) tmp = x / y; else tmp = -x / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1000.0], 1.0, If[LessEqual[t$95$0, 2e+240], N[(x / y), $MachinePrecision], N[((-x) / y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left|x - y\right|}{\left|y\right|}\\
\mathbf{if}\;t\_0 \leq 1000:\\
\;\;\;\;1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+240}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{y}\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 1e3Initial program 100.0%
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites97.2%
if 1e3 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 2.00000000000000003e240Initial program 100.0%
Applied rewrites50.1%
Taylor expanded in x around inf
lift-/.f6449.2
Applied rewrites49.2%
if 2.00000000000000003e240 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
Applied rewrites47.6%
Taylor expanded in x around inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6447.6
Applied rewrites47.6%
(FPCore (x y) :precision binary64 (if (<= (/ (fabs (- x y)) (fabs y)) 1000.0) 1.0 (/ x y)))
double code(double x, double y) {
double tmp;
if ((fabs((x - y)) / fabs(y)) <= 1000.0) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
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 ((abs((x - y)) / abs(y)) <= 1000.0d0) then
tmp = 1.0d0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((Math.abs((x - y)) / Math.abs(y)) <= 1000.0) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (math.fabs((x - y)) / math.fabs(y)) <= 1000.0: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (Float64(abs(Float64(x - y)) / abs(y)) <= 1000.0) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((abs((x - y)) / abs(y)) <= 1000.0) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision], 1000.0], 1.0, N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left|x - y\right|}{\left|y\right|} \leq 1000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 1e3Initial program 100.0%
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites97.2%
if 1e3 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
Applied rewrites51.0%
Taylor expanded in x around inf
lift-/.f6450.5
Applied rewrites50.5%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 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 = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Applied rewrites75.0%
Taylor expanded in x around 0
Applied rewrites52.0%
herbie shell --seed 2025119
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))