
(FPCore (x y) :precision binary64 (/ (- x y) (* (* x 2.0) y)))
double code(double x, double y) {
return (x - y) / ((x * 2.0) * 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 = (x - y) / ((x * 2.0d0) * y)
end function
public static double code(double x, double y) {
return (x - y) / ((x * 2.0) * y);
}
def code(x, y): return (x - y) / ((x * 2.0) * y)
function code(x, y) return Float64(Float64(x - y) / Float64(Float64(x * 2.0) * y)) end
function tmp = code(x, y) tmp = (x - y) / ((x * 2.0) * y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\left(x \cdot 2\right) \cdot y}
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (- x y) (* (* x 2.0) y)))
double code(double x, double y) {
return (x - y) / ((x * 2.0) * 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 = (x - y) / ((x * 2.0d0) * y)
end function
public static double code(double x, double y) {
return (x - y) / ((x * 2.0) * y);
}
def code(x, y): return (x - y) / ((x * 2.0) * y)
function code(x, y) return Float64(Float64(x - y) / Float64(Float64(x * 2.0) * y)) end
function tmp = code(x, y) tmp = (x - y) / ((x * 2.0) * y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{\left(x \cdot 2\right) \cdot y}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ 0.5 (* -0.5 (/ y x))) y)))
(if (<= x -2e-8)
t_0
(if (<= x 470000000000.0) (/ (- (* 0.5 (/ x y)) 0.5) x) t_0))))
double code(double x, double y) {
double t_0 = (0.5 + (-0.5 * (y / x))) / y;
double tmp;
if (x <= -2e-8) {
tmp = t_0;
} else if (x <= 470000000000.0) {
tmp = ((0.5 * (x / y)) - 0.5) / x;
} else {
tmp = t_0;
}
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 = (0.5d0 + ((-0.5d0) * (y / x))) / y
if (x <= (-2d-8)) then
tmp = t_0
else if (x <= 470000000000.0d0) then
tmp = ((0.5d0 * (x / y)) - 0.5d0) / x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (0.5 + (-0.5 * (y / x))) / y;
double tmp;
if (x <= -2e-8) {
tmp = t_0;
} else if (x <= 470000000000.0) {
tmp = ((0.5 * (x / y)) - 0.5) / x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (0.5 + (-0.5 * (y / x))) / y tmp = 0 if x <= -2e-8: tmp = t_0 elif x <= 470000000000.0: tmp = ((0.5 * (x / y)) - 0.5) / x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(0.5 + Float64(-0.5 * Float64(y / x))) / y) tmp = 0.0 if (x <= -2e-8) tmp = t_0; elseif (x <= 470000000000.0) tmp = Float64(Float64(Float64(0.5 * Float64(x / y)) - 0.5) / x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (0.5 + (-0.5 * (y / x))) / y; tmp = 0.0; if (x <= -2e-8) tmp = t_0; elseif (x <= 470000000000.0) tmp = ((0.5 * (x / y)) - 0.5) / x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(0.5 + N[(-0.5 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[x, -2e-8], t$95$0, If[LessEqual[x, 470000000000.0], N[(N[(N[(0.5 * N[(x / y), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{0.5 + -0.5 \cdot \frac{y}{x}}{y}\\
\mathbf{if}\;x \leq -2 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 470000000000:\\
\;\;\;\;\frac{0.5 \cdot \frac{x}{y} - 0.5}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2e-8 or 4.7e11 < x Initial program 76.0%
Taylor expanded in y around 0
Applied rewrites88.5%
if -2e-8 < x < 4.7e11Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites88.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) (* (* x 2.0) y)))
(t_1 (/ (- x y) (* (+ y y) x)))
(t_2 (/ (- (* 0.5 (/ x y)) 0.5) x)))
(if (<= t_0 (- INFINITY))
t_2
(if (<= t_0 -1e+59)
t_1
(if (<= t_0 4e-45) t_2 (if (<= t_0 4e+299) t_1 t_2))))))
double code(double x, double y) {
double t_0 = (x - y) / ((x * 2.0) * y);
double t_1 = (x - y) / ((y + y) * x);
double t_2 = ((0.5 * (x / y)) - 0.5) / x;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_2;
} else if (t_0 <= -1e+59) {
tmp = t_1;
} else if (t_0 <= 4e-45) {
tmp = t_2;
} else if (t_0 <= 4e+299) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
public static double code(double x, double y) {
double t_0 = (x - y) / ((x * 2.0) * y);
double t_1 = (x - y) / ((y + y) * x);
double t_2 = ((0.5 * (x / y)) - 0.5) / x;
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_2;
} else if (t_0 <= -1e+59) {
tmp = t_1;
} else if (t_0 <= 4e-45) {
tmp = t_2;
} else if (t_0 <= 4e+299) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / ((x * 2.0) * y) t_1 = (x - y) / ((y + y) * x) t_2 = ((0.5 * (x / y)) - 0.5) / x tmp = 0 if t_0 <= -math.inf: tmp = t_2 elif t_0 <= -1e+59: tmp = t_1 elif t_0 <= 4e-45: tmp = t_2 elif t_0 <= 4e+299: tmp = t_1 else: tmp = t_2 return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(Float64(x * 2.0) * y)) t_1 = Float64(Float64(x - y) / Float64(Float64(y + y) * x)) t_2 = Float64(Float64(Float64(0.5 * Float64(x / y)) - 0.5) / x) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_2; elseif (t_0 <= -1e+59) tmp = t_1; elseif (t_0 <= 4e-45) tmp = t_2; elseif (t_0 <= 4e+299) tmp = t_1; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / ((x * 2.0) * y); t_1 = (x - y) / ((y + y) * x); t_2 = ((0.5 * (x / y)) - 0.5) / x; tmp = 0.0; if (t_0 <= -Inf) tmp = t_2; elseif (t_0 <= -1e+59) tmp = t_1; elseif (t_0 <= 4e-45) tmp = t_2; elseif (t_0 <= 4e+299) tmp = t_1; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - y), $MachinePrecision] / N[(N[(y + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(0.5 * N[(x / y), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision] / x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$2, If[LessEqual[t$95$0, -1e+59], t$95$1, If[LessEqual[t$95$0, 4e-45], t$95$2, If[LessEqual[t$95$0, 4e+299], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{\left(x \cdot 2\right) \cdot y}\\
t_1 := \frac{x - y}{\left(y + y\right) \cdot x}\\
t_2 := \frac{0.5 \cdot \frac{x}{y} - 0.5}{x}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+59}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-45}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+299}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < -inf.0 or -9.99999999999999972e58 < (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < 3.99999999999999994e-45 or 4.0000000000000002e299 < (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites88.4%
if -inf.0 < (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < -9.99999999999999972e58 or 3.99999999999999994e-45 < (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < 4.0000000000000002e299Initial program 76.0%
Applied rewrites76.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) (* (+ y y) x))))
(if (<= x -5.8e+148)
(/ 0.5 y)
(if (<= x -2.15e-179)
t_0
(if (<= x 3.7e-168) (/ -0.5 x) (if (<= x 1.16e+69) t_0 (/ 0.5 y)))))))
double code(double x, double y) {
double t_0 = (x - y) / ((y + y) * x);
double tmp;
if (x <= -5.8e+148) {
tmp = 0.5 / y;
} else if (x <= -2.15e-179) {
tmp = t_0;
} else if (x <= 3.7e-168) {
tmp = -0.5 / x;
} else if (x <= 1.16e+69) {
tmp = t_0;
} else {
tmp = 0.5 / 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 = (x - y) / ((y + y) * x)
if (x <= (-5.8d+148)) then
tmp = 0.5d0 / y
else if (x <= (-2.15d-179)) then
tmp = t_0
else if (x <= 3.7d-168) then
tmp = (-0.5d0) / x
else if (x <= 1.16d+69) then
tmp = t_0
else
tmp = 0.5d0 / y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / ((y + y) * x);
double tmp;
if (x <= -5.8e+148) {
tmp = 0.5 / y;
} else if (x <= -2.15e-179) {
tmp = t_0;
} else if (x <= 3.7e-168) {
tmp = -0.5 / x;
} else if (x <= 1.16e+69) {
tmp = t_0;
} else {
tmp = 0.5 / y;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / ((y + y) * x) tmp = 0 if x <= -5.8e+148: tmp = 0.5 / y elif x <= -2.15e-179: tmp = t_0 elif x <= 3.7e-168: tmp = -0.5 / x elif x <= 1.16e+69: tmp = t_0 else: tmp = 0.5 / y return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(Float64(y + y) * x)) tmp = 0.0 if (x <= -5.8e+148) tmp = Float64(0.5 / y); elseif (x <= -2.15e-179) tmp = t_0; elseif (x <= 3.7e-168) tmp = Float64(-0.5 / x); elseif (x <= 1.16e+69) tmp = t_0; else tmp = Float64(0.5 / y); end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / ((y + y) * x); tmp = 0.0; if (x <= -5.8e+148) tmp = 0.5 / y; elseif (x <= -2.15e-179) tmp = t_0; elseif (x <= 3.7e-168) tmp = -0.5 / x; elseif (x <= 1.16e+69) tmp = t_0; else tmp = 0.5 / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(N[(y + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.8e+148], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, -2.15e-179], t$95$0, If[LessEqual[x, 3.7e-168], N[(-0.5 / x), $MachinePrecision], If[LessEqual[x, 1.16e+69], t$95$0, N[(0.5 / y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{\left(y + y\right) \cdot x}\\
\mathbf{if}\;x \leq -5.8 \cdot 10^{+148}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;x \leq -2.15 \cdot 10^{-179}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-168}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{elif}\;x \leq 1.16 \cdot 10^{+69}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{y}\\
\end{array}
\end{array}
if x < -5.7999999999999999e148 or 1.16000000000000005e69 < x Initial program 76.0%
Taylor expanded in x around inf
Applied rewrites50.2%
if -5.7999999999999999e148 < x < -2.15000000000000013e-179 or 3.69999999999999997e-168 < x < 1.16000000000000005e69Initial program 76.0%
Applied rewrites76.0%
if -2.15000000000000013e-179 < x < 3.69999999999999997e-168Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites51.1%
(FPCore (x y) :precision binary64 (if (<= x -61000.0) (/ 0.5 y) (if (<= x 1.8e-110) (/ -0.5 x) (/ 0.5 y))))
double code(double x, double y) {
double tmp;
if (x <= -61000.0) {
tmp = 0.5 / y;
} else if (x <= 1.8e-110) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / 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 (x <= (-61000.0d0)) then
tmp = 0.5d0 / y
else if (x <= 1.8d-110) then
tmp = (-0.5d0) / x
else
tmp = 0.5d0 / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -61000.0) {
tmp = 0.5 / y;
} else if (x <= 1.8e-110) {
tmp = -0.5 / x;
} else {
tmp = 0.5 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -61000.0: tmp = 0.5 / y elif x <= 1.8e-110: tmp = -0.5 / x else: tmp = 0.5 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -61000.0) tmp = Float64(0.5 / y); elseif (x <= 1.8e-110) tmp = Float64(-0.5 / x); else tmp = Float64(0.5 / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -61000.0) tmp = 0.5 / y; elseif (x <= 1.8e-110) tmp = -0.5 / x; else tmp = 0.5 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -61000.0], N[(0.5 / y), $MachinePrecision], If[LessEqual[x, 1.8e-110], N[(-0.5 / x), $MachinePrecision], N[(0.5 / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -61000:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-110}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{y}\\
\end{array}
\end{array}
if x < -61000 or 1.79999999999999997e-110 < x Initial program 76.0%
Taylor expanded in x around inf
Applied rewrites50.2%
if -61000 < x < 1.79999999999999997e-110Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites51.1%
(FPCore (x y) :precision binary64 (/ -0.5 x))
double code(double x, double y) {
return -0.5 / 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 = (-0.5d0) / x
end function
public static double code(double x, double y) {
return -0.5 / x;
}
def code(x, y): return -0.5 / x
function code(x, y) return Float64(-0.5 / x) end
function tmp = code(x, y) tmp = -0.5 / x; end
code[x_, y_] := N[(-0.5 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5}{x}
\end{array}
Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites51.1%
(FPCore (x y) :precision binary64 (* 2.0 0.5))
double code(double x, double y) {
return 2.0 * 0.5;
}
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 = 2.0d0 * 0.5d0
end function
public static double code(double x, double y) {
return 2.0 * 0.5;
}
def code(x, y): return 2.0 * 0.5
function code(x, y) return Float64(2.0 * 0.5) end
function tmp = code(x, y) tmp = 2.0 * 0.5; end
code[x_, y_] := N[(2.0 * 0.5), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot 0.5
\end{array}
Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites88.4%
Applied rewrites3.4%
(FPCore (x y) :precision binary64 2.0)
double code(double x, double y) {
return 2.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 = 2.0d0
end function
public static double code(double x, double y) {
return 2.0;
}
def code(x, y): return 2.0
function code(x, y) return 2.0 end
function tmp = code(x, y) tmp = 2.0; end
code[x_, y_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites88.4%
Applied rewrites3.4%
Applied rewrites3.4%
herbie shell --seed 2025159
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, B"
:precision binary64
(/ (- x y) (* (* x 2.0) y)))