
(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 6 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 (if (<= y -4.6e+33) (/ 1.0 (* (+ x x) (/ y (- x y)))) (if (<= y 500000.0) (/ (/ (- x y) (+ x x)) y) (/ (/ (- x y) y) (+ x x)))))
double code(double x, double y) {
double tmp;
if (y <= -4.6e+33) {
tmp = 1.0 / ((x + x) * (y / (x - y)));
} else if (y <= 500000.0) {
tmp = ((x - y) / (x + x)) / y;
} else {
tmp = ((x - y) / y) / (x + x);
}
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 (y <= (-4.6d+33)) then
tmp = 1.0d0 / ((x + x) * (y / (x - y)))
else if (y <= 500000.0d0) then
tmp = ((x - y) / (x + x)) / y
else
tmp = ((x - y) / y) / (x + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.6e+33) {
tmp = 1.0 / ((x + x) * (y / (x - y)));
} else if (y <= 500000.0) {
tmp = ((x - y) / (x + x)) / y;
} else {
tmp = ((x - y) / y) / (x + x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.6e+33: tmp = 1.0 / ((x + x) * (y / (x - y))) elif y <= 500000.0: tmp = ((x - y) / (x + x)) / y else: tmp = ((x - y) / y) / (x + x) return tmp
function code(x, y) tmp = 0.0 if (y <= -4.6e+33) tmp = Float64(1.0 / Float64(Float64(x + x) * Float64(y / Float64(x - y)))); elseif (y <= 500000.0) tmp = Float64(Float64(Float64(x - y) / Float64(x + x)) / y); else tmp = Float64(Float64(Float64(x - y) / y) / Float64(x + x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.6e+33) tmp = 1.0 / ((x + x) * (y / (x - y))); elseif (y <= 500000.0) tmp = ((x - y) / (x + x)) / y; else tmp = ((x - y) / y) / (x + x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.6e+33], N[(1.0 / N[(N[(x + x), $MachinePrecision] * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 500000.0], N[(N[(N[(x - y), $MachinePrecision] / N[(x + x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision] / N[(x + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{+33}:\\
\;\;\;\;\frac{1}{\left(x + x\right) \cdot \frac{y}{x - y}}\\
\mathbf{elif}\;y \leq 500000:\\
\;\;\;\;\frac{\frac{x - y}{x + x}}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x - y}{y}}{x + x}\\
\end{array}
\end{array}
if y < -4.60000000000000021e33Initial program 76.9%
lift-/.f64N/A
div-flipN/A
lower-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f64N/A
lower-/.f6488.9
Applied rewrites88.9%
if -4.60000000000000021e33 < y < 5e5Initial program 76.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6488.5
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6488.5
Applied rewrites88.5%
if 5e5 < y Initial program 76.9%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6488.0
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6488.0
Applied rewrites88.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (/ (- x y) y) (+ x x))))
(if (<= y -5.5e+35)
t_0
(if (<= y 500000.0) (/ (/ (- x y) (+ x x)) y) t_0))))
double code(double x, double y) {
double t_0 = ((x - y) / y) / (x + x);
double tmp;
if (y <= -5.5e+35) {
tmp = t_0;
} else if (y <= 500000.0) {
tmp = ((x - y) / (x + x)) / y;
} 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 = ((x - y) / y) / (x + x)
if (y <= (-5.5d+35)) then
tmp = t_0
else if (y <= 500000.0d0) then
tmp = ((x - y) / (x + x)) / y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x - y) / y) / (x + x);
double tmp;
if (y <= -5.5e+35) {
tmp = t_0;
} else if (y <= 500000.0) {
tmp = ((x - y) / (x + x)) / y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = ((x - y) / y) / (x + x) tmp = 0 if y <= -5.5e+35: tmp = t_0 elif y <= 500000.0: tmp = ((x - y) / (x + x)) / y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x - y) / y) / Float64(x + x)) tmp = 0.0 if (y <= -5.5e+35) tmp = t_0; elseif (y <= 500000.0) tmp = Float64(Float64(Float64(x - y) / Float64(x + x)) / y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = ((x - y) / y) / (x + x); tmp = 0.0; if (y <= -5.5e+35) tmp = t_0; elseif (y <= 500000.0) tmp = ((x - y) / (x + x)) / y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision] / N[(x + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.5e+35], t$95$0, If[LessEqual[y, 500000.0], N[(N[(N[(x - y), $MachinePrecision] / N[(x + x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{x - y}{y}}{x + x}\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 500000:\\
\;\;\;\;\frac{\frac{x - y}{x + x}}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.50000000000000001e35 or 5e5 < y Initial program 76.9%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6488.0
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6488.0
Applied rewrites88.0%
if -5.50000000000000001e35 < y < 5e5Initial program 76.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6488.5
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6488.5
Applied rewrites88.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (- x y) (* (* x 2.0) y))) (t_1 (/ (/ (- x y) y) (+ x x)))) (if (<= t_0 5e+64) t_1 (if (<= t_0 4e+303) (/ (- x y) (* (+ y y) x)) t_1))))
double code(double x, double y) {
double t_0 = (x - y) / ((x * 2.0) * y);
double t_1 = ((x - y) / y) / (x + x);
double tmp;
if (t_0 <= 5e+64) {
tmp = t_1;
} else if (t_0 <= 4e+303) {
tmp = (x - y) / ((y + y) * x);
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = (x - y) / ((x * 2.0d0) * y)
t_1 = ((x - y) / y) / (x + x)
if (t_0 <= 5d+64) then
tmp = t_1
else if (t_0 <= 4d+303) then
tmp = (x - y) / ((y + y) * x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / ((x * 2.0) * y);
double t_1 = ((x - y) / y) / (x + x);
double tmp;
if (t_0 <= 5e+64) {
tmp = t_1;
} else if (t_0 <= 4e+303) {
tmp = (x - y) / ((y + y) * x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / ((x * 2.0) * y) t_1 = ((x - y) / y) / (x + x) tmp = 0 if t_0 <= 5e+64: tmp = t_1 elif t_0 <= 4e+303: tmp = (x - y) / ((y + y) * x) else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(Float64(x * 2.0) * y)) t_1 = Float64(Float64(Float64(x - y) / y) / Float64(x + x)) tmp = 0.0 if (t_0 <= 5e+64) tmp = t_1; elseif (t_0 <= 4e+303) tmp = Float64(Float64(x - y) / Float64(Float64(y + y) * x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / ((x * 2.0) * y); t_1 = ((x - y) / y) / (x + x); tmp = 0.0; if (t_0 <= 5e+64) tmp = t_1; elseif (t_0 <= 4e+303) tmp = (x - y) / ((y + y) * x); else tmp = t_1; 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[(N[(x - y), $MachinePrecision] / y), $MachinePrecision] / N[(x + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+64], t$95$1, If[LessEqual[t$95$0, 4e+303], N[(N[(x - y), $MachinePrecision] / N[(N[(y + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{\left(x \cdot 2\right) \cdot y}\\
t_1 := \frac{\frac{x - y}{y}}{x + x}\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{+64}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+303}:\\
\;\;\;\;\frac{x - y}{\left(y + y\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < 5e64 or 4e303 < (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) Initial program 76.9%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6488.0
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6488.0
Applied rewrites88.0%
if 5e64 < (/.f64 (-.f64 x y) (*.f64 (*.f64 x #s(literal 2 binary64)) y)) < 4e303Initial program 76.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6476.9
Applied rewrites76.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) (* (+ y y) x))))
(if (<= y -7.6e+92)
(/ -0.5 x)
(if (<= y -4.6e-206)
t_0
(if (<= y 1.35e-182) (/ 0.5 y) (if (<= y 6.2e+186) t_0 (/ -0.5 x)))))))
double code(double x, double y) {
double t_0 = (x - y) / ((y + y) * x);
double tmp;
if (y <= -7.6e+92) {
tmp = -0.5 / x;
} else if (y <= -4.6e-206) {
tmp = t_0;
} else if (y <= 1.35e-182) {
tmp = 0.5 / y;
} else if (y <= 6.2e+186) {
tmp = t_0;
} else {
tmp = -0.5 / x;
}
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 (y <= (-7.6d+92)) then
tmp = (-0.5d0) / x
else if (y <= (-4.6d-206)) then
tmp = t_0
else if (y <= 1.35d-182) then
tmp = 0.5d0 / y
else if (y <= 6.2d+186) then
tmp = t_0
else
tmp = (-0.5d0) / x
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 (y <= -7.6e+92) {
tmp = -0.5 / x;
} else if (y <= -4.6e-206) {
tmp = t_0;
} else if (y <= 1.35e-182) {
tmp = 0.5 / y;
} else if (y <= 6.2e+186) {
tmp = t_0;
} else {
tmp = -0.5 / x;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / ((y + y) * x) tmp = 0 if y <= -7.6e+92: tmp = -0.5 / x elif y <= -4.6e-206: tmp = t_0 elif y <= 1.35e-182: tmp = 0.5 / y elif y <= 6.2e+186: tmp = t_0 else: tmp = -0.5 / x return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(Float64(y + y) * x)) tmp = 0.0 if (y <= -7.6e+92) tmp = Float64(-0.5 / x); elseif (y <= -4.6e-206) tmp = t_0; elseif (y <= 1.35e-182) tmp = Float64(0.5 / y); elseif (y <= 6.2e+186) tmp = t_0; else tmp = Float64(-0.5 / x); end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / ((y + y) * x); tmp = 0.0; if (y <= -7.6e+92) tmp = -0.5 / x; elseif (y <= -4.6e-206) tmp = t_0; elseif (y <= 1.35e-182) tmp = 0.5 / y; elseif (y <= 6.2e+186) tmp = t_0; else tmp = -0.5 / x; 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[y, -7.6e+92], N[(-0.5 / x), $MachinePrecision], If[LessEqual[y, -4.6e-206], t$95$0, If[LessEqual[y, 1.35e-182], N[(0.5 / y), $MachinePrecision], If[LessEqual[y, 6.2e+186], t$95$0, N[(-0.5 / x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{\left(y + y\right) \cdot x}\\
\mathbf{if}\;y \leq -7.6 \cdot 10^{+92}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{elif}\;y \leq -4.6 \cdot 10^{-206}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-182}:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+186}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{x}\\
\end{array}
\end{array}
if y < -7.6000000000000001e92 or 6.2000000000000002e186 < y Initial program 76.9%
Taylor expanded in x around 0
lower-/.f6450.3
Applied rewrites50.3%
if -7.6000000000000001e92 < y < -4.6e-206 or 1.35e-182 < y < 6.2000000000000002e186Initial program 76.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
count-2-revN/A
lower-+.f6476.9
Applied rewrites76.9%
if -4.6e-206 < y < 1.35e-182Initial program 76.9%
Taylor expanded in x around inf
lower-/.f6451.2
Applied rewrites51.2%
(FPCore (x y) :precision binary64 (if (<= y -3.7e-13) (/ -0.5 x) (if (<= y 1050000.0) (/ 0.5 y) (/ -0.5 x))))
double code(double x, double y) {
double tmp;
if (y <= -3.7e-13) {
tmp = -0.5 / x;
} else if (y <= 1050000.0) {
tmp = 0.5 / y;
} else {
tmp = -0.5 / x;
}
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 (y <= (-3.7d-13)) then
tmp = (-0.5d0) / x
else if (y <= 1050000.0d0) then
tmp = 0.5d0 / y
else
tmp = (-0.5d0) / x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.7e-13) {
tmp = -0.5 / x;
} else if (y <= 1050000.0) {
tmp = 0.5 / y;
} else {
tmp = -0.5 / x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.7e-13: tmp = -0.5 / x elif y <= 1050000.0: tmp = 0.5 / y else: tmp = -0.5 / x return tmp
function code(x, y) tmp = 0.0 if (y <= -3.7e-13) tmp = Float64(-0.5 / x); elseif (y <= 1050000.0) tmp = Float64(0.5 / y); else tmp = Float64(-0.5 / x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.7e-13) tmp = -0.5 / x; elseif (y <= 1050000.0) tmp = 0.5 / y; else tmp = -0.5 / x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.7e-13], N[(-0.5 / x), $MachinePrecision], If[LessEqual[y, 1050000.0], N[(0.5 / y), $MachinePrecision], N[(-0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-13}:\\
\;\;\;\;\frac{-0.5}{x}\\
\mathbf{elif}\;y \leq 1050000:\\
\;\;\;\;\frac{0.5}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{x}\\
\end{array}
\end{array}
if y < -3.69999999999999989e-13 or 1.05e6 < y Initial program 76.9%
Taylor expanded in x around 0
lower-/.f6450.3
Applied rewrites50.3%
if -3.69999999999999989e-13 < y < 1.05e6Initial program 76.9%
Taylor expanded in x around inf
lower-/.f6451.2
Applied rewrites51.2%
(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.9%
Taylor expanded in x around 0
lower-/.f6450.3
Applied rewrites50.3%
herbie shell --seed 2025156
(FPCore (x y)
:name "Linear.Projection:inversePerspective from linear-1.19.1.3, B"
:precision binary64
(/ (- x y) (* (* x 2.0) y)))