
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2): return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2) return Float64(Float64(a1 * a2) / Float64(b1 * b2)) end
function tmp = code(a1, a2, b1, b2) tmp = (a1 * a2) / (b1 * b2); end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2): return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2) return Float64(Float64(a1 * a2) / Float64(b1 * b2)) end
function tmp = code(a1, a2, b1, b2) tmp = (a1 * a2) / (b1 * b2); end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (/ (* (/ a2 b2) a1) b1)))
(if (<= (* b1 b2) -4e+105)
t_0
(if (<= (* b1 b2) -2e-260)
(/ (* a1 a2) (* b1 b2))
(if (<= (* b1 b2) 5e-294)
t_0
(if (<= (* b1 b2) 1e+172) (* (/ a2 (* b1 b2)) a1) t_0))))))assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = ((a2 / b2) * a1) / b1;
double tmp;
if ((b1 * b2) <= -4e+105) {
tmp = t_0;
} else if ((b1 * b2) <= -2e-260) {
tmp = (a1 * a2) / (b1 * b2);
} else if ((b1 * b2) <= 5e-294) {
tmp = t_0;
} else if ((b1 * b2) <= 1e+172) {
tmp = (a2 / (b1 * b2)) * a1;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: t_0
real(8) :: tmp
t_0 = ((a2 / b2) * a1) / b1
if ((b1 * b2) <= (-4d+105)) then
tmp = t_0
else if ((b1 * b2) <= (-2d-260)) then
tmp = (a1 * a2) / (b1 * b2)
else if ((b1 * b2) <= 5d-294) then
tmp = t_0
else if ((b1 * b2) <= 1d+172) then
tmp = (a2 / (b1 * b2)) * a1
else
tmp = t_0
end if
code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = ((a2 / b2) * a1) / b1;
double tmp;
if ((b1 * b2) <= -4e+105) {
tmp = t_0;
} else if ((b1 * b2) <= -2e-260) {
tmp = (a1 * a2) / (b1 * b2);
} else if ((b1 * b2) <= 5e-294) {
tmp = t_0;
} else if ((b1 * b2) <= 1e+172) {
tmp = (a2 / (b1 * b2)) * a1;
} else {
tmp = t_0;
}
return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): t_0 = ((a2 / b2) * a1) / b1 tmp = 0 if (b1 * b2) <= -4e+105: tmp = t_0 elif (b1 * b2) <= -2e-260: tmp = (a1 * a2) / (b1 * b2) elif (b1 * b2) <= 5e-294: tmp = t_0 elif (b1 * b2) <= 1e+172: tmp = (a2 / (b1 * b2)) * a1 else: tmp = t_0 return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(Float64(a2 / b2) * a1) / b1) tmp = 0.0 if (Float64(b1 * b2) <= -4e+105) tmp = t_0; elseif (Float64(b1 * b2) <= -2e-260) tmp = Float64(Float64(a1 * a2) / Float64(b1 * b2)); elseif (Float64(b1 * b2) <= 5e-294) tmp = t_0; elseif (Float64(b1 * b2) <= 1e+172) tmp = Float64(Float64(a2 / Float64(b1 * b2)) * a1); else tmp = t_0; end return tmp end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = ((a2 / b2) * a1) / b1;
tmp = 0.0;
if ((b1 * b2) <= -4e+105)
tmp = t_0;
elseif ((b1 * b2) <= -2e-260)
tmp = (a1 * a2) / (b1 * b2);
elseif ((b1 * b2) <= 5e-294)
tmp = t_0;
elseif ((b1 * b2) <= 1e+172)
tmp = (a2 / (b1 * b2)) * a1;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(N[(a2 / b2), $MachinePrecision] * a1), $MachinePrecision] / b1), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -4e+105], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-260], N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-294], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 1e+172], N[(N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a1), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{a2}{b2} \cdot a1}{b1}\\
\mathbf{if}\;b1 \cdot b2 \leq -4 \cdot 10^{+105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-260}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-294}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b1 \cdot b2 \leq 10^{+172}:\\
\;\;\;\;\frac{a2}{b1 \cdot b2} \cdot a1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -3.9999999999999998e105 or -1.99999999999999992e-260 < (*.f64 b1 b2) < 5.0000000000000003e-294 or 1.0000000000000001e172 < (*.f64 b1 b2) Initial program 77.4%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
times-fracN/A
associate-*l/N/A
lower-/.f64N/A
associate-*r/N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6492.9
Applied rewrites92.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6492.5
Applied rewrites92.5%
if -3.9999999999999998e105 < (*.f64 b1 b2) < -1.99999999999999992e-260Initial program 94.7%
if 5.0000000000000003e-294 < (*.f64 b1 b2) < 1.0000000000000001e172Initial program 93.1%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6485.0
Applied rewrites85.0%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
*-commutativeN/A
frac-2negN/A
distribute-frac-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
remove-double-negN/A
lower-*.f6493.8
Applied rewrites93.8%
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (/ (* a1 a2) (* b1 b2))))
(if (<= t_0 -2e+296)
(* (/ (/ a1 b2) b1) a2)
(if (<= t_0 -2e-222)
t_0
(if (<= t_0 1e-259)
(* (/ a2 b1) (/ a1 b2))
(if (<= t_0 2e+233) t_0 (* (/ (/ a2 b2) b1) a1)))))))assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -2e+296) {
tmp = ((a1 / b2) / b1) * a2;
} else if (t_0 <= -2e-222) {
tmp = t_0;
} else if (t_0 <= 1e-259) {
tmp = (a2 / b1) * (a1 / b2);
} else if (t_0 <= 2e+233) {
tmp = t_0;
} else {
tmp = ((a2 / b2) / b1) * a1;
}
return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: t_0
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
if (t_0 <= (-2d+296)) then
tmp = ((a1 / b2) / b1) * a2
else if (t_0 <= (-2d-222)) then
tmp = t_0
else if (t_0 <= 1d-259) then
tmp = (a2 / b1) * (a1 / b2)
else if (t_0 <= 2d+233) then
tmp = t_0
else
tmp = ((a2 / b2) / b1) * a1
end if
code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -2e+296) {
tmp = ((a1 / b2) / b1) * a2;
} else if (t_0 <= -2e-222) {
tmp = t_0;
} else if (t_0 <= 1e-259) {
tmp = (a2 / b1) * (a1 / b2);
} else if (t_0 <= 2e+233) {
tmp = t_0;
} else {
tmp = ((a2 / b2) / b1) * a1;
}
return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) tmp = 0 if t_0 <= -2e+296: tmp = ((a1 / b2) / b1) * a2 elif t_0 <= -2e-222: tmp = t_0 elif t_0 <= 1e-259: tmp = (a2 / b1) * (a1 / b2) elif t_0 <= 2e+233: tmp = t_0 else: tmp = ((a2 / b2) / b1) * a1 return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if (t_0 <= -2e+296) tmp = Float64(Float64(Float64(a1 / b2) / b1) * a2); elseif (t_0 <= -2e-222) tmp = t_0; elseif (t_0 <= 1e-259) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); elseif (t_0 <= 2e+233) tmp = t_0; else tmp = Float64(Float64(Float64(a2 / b2) / b1) * a1); end return tmp end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_0 <= -2e+296)
tmp = ((a1 / b2) / b1) * a2;
elseif (t_0 <= -2e-222)
tmp = t_0;
elseif (t_0 <= 1e-259)
tmp = (a2 / b1) * (a1 / b2);
elseif (t_0 <= 2e+233)
tmp = t_0;
else
tmp = ((a2 / b2) / b1) * a1;
end
tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+296], N[(N[(N[(a1 / b2), $MachinePrecision] / b1), $MachinePrecision] * a2), $MachinePrecision], If[LessEqual[t$95$0, -2e-222], t$95$0, If[LessEqual[t$95$0, 1e-259], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+233], t$95$0, N[(N[(N[(a2 / b2), $MachinePrecision] / b1), $MachinePrecision] * a1), $MachinePrecision]]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+296}:\\
\;\;\;\;\frac{\frac{a1}{b2}}{b1} \cdot a2\\
\mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-222}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 10^{-259}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+233}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a2}{b2}}{b1} \cdot a1\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999996e296Initial program 82.4%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6495.3
Applied rewrites95.3%
if -1.99999999999999996e296 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000000001e-222 or 1.0000000000000001e-259 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999995e233Initial program 98.9%
if -2.0000000000000001e-222 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e-259Initial program 80.8%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6491.5
Applied rewrites91.5%
if 1.99999999999999995e233 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 70.0%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6491.1
Applied rewrites91.1%
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (/ (* a1 a2) (* b1 b2))) (t_1 (* (/ a2 b1) (/ a1 b2))))
(if (<= t_0 -2e+296)
(* (/ (/ a1 b2) b1) a2)
(if (<= t_0 -2e-222)
t_0
(if (<= t_0 1e-259) t_1 (if (<= t_0 1e+253) t_0 t_1))))))assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if (t_0 <= -2e+296) {
tmp = ((a1 / b2) / b1) * a2;
} else if (t_0 <= -2e-222) {
tmp = t_0;
} else if (t_0 <= 1e-259) {
tmp = t_1;
} else if (t_0 <= 1e+253) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
t_1 = (a2 / b1) * (a1 / b2)
if (t_0 <= (-2d+296)) then
tmp = ((a1 / b2) / b1) * a2
else if (t_0 <= (-2d-222)) then
tmp = t_0
else if (t_0 <= 1d-259) then
tmp = t_1
else if (t_0 <= 1d+253) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if (t_0 <= -2e+296) {
tmp = ((a1 / b2) / b1) * a2;
} else if (t_0 <= -2e-222) {
tmp = t_0;
} else if (t_0 <= 1e-259) {
tmp = t_1;
} else if (t_0 <= 1e+253) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) t_1 = (a2 / b1) * (a1 / b2) tmp = 0 if t_0 <= -2e+296: tmp = ((a1 / b2) / b1) * a2 elif t_0 <= -2e-222: tmp = t_0 elif t_0 <= 1e-259: tmp = t_1 elif t_0 <= 1e+253: tmp = t_0 else: tmp = t_1 return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) t_1 = Float64(Float64(a2 / b1) * Float64(a1 / b2)) tmp = 0.0 if (t_0 <= -2e+296) tmp = Float64(Float64(Float64(a1 / b2) / b1) * a2); elseif (t_0 <= -2e-222) tmp = t_0; elseif (t_0 <= 1e-259) tmp = t_1; elseif (t_0 <= 1e+253) tmp = t_0; else tmp = t_1; end return tmp end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
t_1 = (a2 / b1) * (a1 / b2);
tmp = 0.0;
if (t_0 <= -2e+296)
tmp = ((a1 / b2) / b1) * a2;
elseif (t_0 <= -2e-222)
tmp = t_0;
elseif (t_0 <= 1e-259)
tmp = t_1;
elseif (t_0 <= 1e+253)
tmp = t_0;
else
tmp = t_1;
end
tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+296], N[(N[(N[(a1 / b2), $MachinePrecision] / b1), $MachinePrecision] * a2), $MachinePrecision], If[LessEqual[t$95$0, -2e-222], t$95$0, If[LessEqual[t$95$0, 1e-259], t$95$1, If[LessEqual[t$95$0, 1e+253], t$95$0, t$95$1]]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+296}:\\
\;\;\;\;\frac{\frac{a1}{b2}}{b1} \cdot a2\\
\mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-222}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_0 \leq 10^{-259}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+253}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999996e296Initial program 82.4%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6495.3
Applied rewrites95.3%
if -1.99999999999999996e296 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000000001e-222 or 1.0000000000000001e-259 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999994e252Initial program 98.9%
if -2.0000000000000001e-222 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e-259 or 9.9999999999999994e252 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 76.6%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6492.3
Applied rewrites92.3%
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (* (/ a2 b1) (/ a1 b2))) (t_1 (/ (* a1 a2) (* b1 b2))))
(if (<= t_1 -2e-222)
t_1
(if (<= t_1 1e-259) t_0 (if (<= t_1 1e+253) t_1 t_0)))))assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a2 / b1) * (a1 / b2);
double t_1 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_1 <= -2e-222) {
tmp = t_1;
} else if (t_1 <= 1e-259) {
tmp = t_0;
} else if (t_1 <= 1e+253) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (a2 / b1) * (a1 / b2)
t_1 = (a1 * a2) / (b1 * b2)
if (t_1 <= (-2d-222)) then
tmp = t_1
else if (t_1 <= 1d-259) then
tmp = t_0
else if (t_1 <= 1d+253) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a2 / b1) * (a1 / b2);
double t_1 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_1 <= -2e-222) {
tmp = t_1;
} else if (t_1 <= 1e-259) {
tmp = t_0;
} else if (t_1 <= 1e+253) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): t_0 = (a2 / b1) * (a1 / b2) t_1 = (a1 * a2) / (b1 * b2) tmp = 0 if t_1 <= -2e-222: tmp = t_1 elif t_1 <= 1e-259: tmp = t_0 elif t_1 <= 1e+253: tmp = t_1 else: tmp = t_0 return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a2 / b1) * Float64(a1 / b2)) t_1 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if (t_1 <= -2e-222) tmp = t_1; elseif (t_1 <= 1e-259) tmp = t_0; elseif (t_1 <= 1e+253) tmp = t_1; else tmp = t_0; end return tmp end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a2 / b1) * (a1 / b2);
t_1 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_1 <= -2e-222)
tmp = t_1;
elseif (t_1 <= 1e-259)
tmp = t_0;
elseif (t_1 <= 1e+253)
tmp = t_1;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-222], t$95$1, If[LessEqual[t$95$1, 1e-259], t$95$0, If[LessEqual[t$95$1, 1e+253], t$95$1, t$95$0]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
t_1 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-222}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_1 \leq 10^{-259}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 10^{+253}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000000001e-222 or 1.0000000000000001e-259 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999994e252Initial program 94.7%
if -2.0000000000000001e-222 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e-259 or 9.9999999999999994e252 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 76.6%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6492.3
Applied rewrites92.3%
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. (FPCore (a1 a2 b1 b2) :precision binary64 (if (<= (/ (* a1 a2) (* b1 b2)) 2e+233) (/ (/ (* a2 a1) b1) b2) (/ (* (/ a2 b2) a1) b1)))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((a1 * a2) / (b1 * b2)) <= 2e+233) {
tmp = ((a2 * a1) / b1) / b2;
} else {
tmp = ((a2 / b2) * a1) / b1;
}
return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: tmp
if (((a1 * a2) / (b1 * b2)) <= 2d+233) then
tmp = ((a2 * a1) / b1) / b2
else
tmp = ((a2 / b2) * a1) / b1
end if
code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((a1 * a2) / (b1 * b2)) <= 2e+233) {
tmp = ((a2 * a1) / b1) / b2;
} else {
tmp = ((a2 / b2) * a1) / b1;
}
return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if ((a1 * a2) / (b1 * b2)) <= 2e+233: tmp = ((a2 * a1) / b1) / b2 else: tmp = ((a2 / b2) * a1) / b1 return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (Float64(Float64(a1 * a2) / Float64(b1 * b2)) <= 2e+233) tmp = Float64(Float64(Float64(a2 * a1) / b1) / b2); else tmp = Float64(Float64(Float64(a2 / b2) * a1) / b1); end return tmp end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
tmp = 0.0;
if (((a1 * a2) / (b1 * b2)) <= 2e+233)
tmp = ((a2 * a1) / b1) / b2;
else
tmp = ((a2 / b2) * a1) / b1;
end
tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := If[LessEqual[N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision], 2e+233], N[(N[(N[(a2 * a1), $MachinePrecision] / b1), $MachinePrecision] / b2), $MachinePrecision], N[(N[(N[(a2 / b2), $MachinePrecision] * a1), $MachinePrecision] / b1), $MachinePrecision]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 2 \cdot 10^{+233}:\\
\;\;\;\;\frac{\frac{a2 \cdot a1}{b1}}{b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a2}{b2} \cdot a1}{b1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999995e233Initial program 89.8%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lower-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6485.8
Applied rewrites85.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lower-/.f64N/A
remove-double-negN/A
*-commutativeN/A
lower-*.f6489.2
Applied rewrites89.2%
if 1.99999999999999995e233 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 70.0%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
times-fracN/A
associate-*l/N/A
lower-/.f64N/A
associate-*r/N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6491.0
Applied rewrites91.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6490.3
Applied rewrites90.3%
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. (FPCore (a1 a2 b1 b2) :precision binary64 (let* ((t_0 (/ (* a1 a2) (* b1 b2)))) (if (<= t_0 2e+213) t_0 (* (/ a1 (* b1 b2)) a2))))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= 2e+213) {
tmp = t_0;
} else {
tmp = (a1 / (b1 * b2)) * a2;
}
return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: t_0
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
if (t_0 <= 2d+213) then
tmp = t_0
else
tmp = (a1 / (b1 * b2)) * a2
end if
code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= 2e+213) {
tmp = t_0;
} else {
tmp = (a1 / (b1 * b2)) * a2;
}
return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) tmp = 0 if t_0 <= 2e+213: tmp = t_0 else: tmp = (a1 / (b1 * b2)) * a2 return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if (t_0 <= 2e+213) tmp = t_0; else tmp = Float64(Float64(a1 / Float64(b1 * b2)) * a2); end return tmp end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_0 <= 2e+213)
tmp = t_0;
else
tmp = (a1 / (b1 * b2)) * a2;
end
tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+213], t$95$0, N[(N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a2), $MachinePrecision]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+213}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1 \cdot b2} \cdot a2\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999997e213Initial program 89.7%
if 1.99999999999999997e213 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 71.1%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6489.5
Applied rewrites89.5%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
*-commutativeN/A
remove-double-negN/A
lower-/.f64N/A
remove-double-negN/A
lower-*.f6475.8
Applied rewrites75.8%
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. (FPCore (a1 a2 b1 b2) :precision binary64 (* (/ a2 (* b1 b2)) a1))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return (a2 / (b1 * b2)) * a1;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a2 / (b1 * b2)) * a1
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return (a2 / (b1 * b2)) * a1;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): return (a2 / (b1 * b2)) * a1
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) return Float64(Float64(a2 / Float64(b1 * b2)) * a1) end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = (a2 / (b1 * b2)) * a1;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := N[(N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a1), $MachinePrecision]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\frac{a2}{b1 \cdot b2} \cdot a1
\end{array}
Initial program 86.4%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6486.2
Applied rewrites86.2%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
*-commutativeN/A
frac-2negN/A
distribute-frac-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
remove-double-negN/A
lower-*.f6486.4
Applied rewrites86.4%
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. (FPCore (a1 a2 b1 b2) :precision binary64 (* (/ a1 (* b1 b2)) a2))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return (a1 / (b1 * b2)) * a2;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 / (b1 * b2)) * a2
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return (a1 / (b1 * b2)) * a2;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2]) [a1, a2, b1, b2] = sort([a1, a2, b1, b2]) def code(a1, a2, b1, b2): return (a1 / (b1 * b2)) * a2
a1, a2, b1, b2 = sort([a1, a2, b1, b2]) a1, a2, b1, b2 = sort([a1, a2, b1, b2]) function code(a1, a2, b1, b2) return Float64(Float64(a1 / Float64(b1 * b2)) * a2) end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = (a1 / (b1 * b2)) * a2;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := N[(N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a2), $MachinePrecision]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\frac{a1}{b1 \cdot b2} \cdot a2
\end{array}
Initial program 86.4%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6486.6
Applied rewrites86.6%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
*-commutativeN/A
remove-double-negN/A
lower-/.f64N/A
remove-double-negN/A
lower-*.f6486.3
Applied rewrites86.3%
herbie shell --seed 2025092
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
(/ (* a1 a2) (* b1 b2)))