
(FPCore (x y) :precision binary64 (+ (+ (* x y) x) y))
double code(double x, double y) {
return ((x * y) + x) + 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) + y
end function
public static double code(double x, double y) {
return ((x * y) + x) + y;
}
def code(x, y): return ((x * y) + x) + y
function code(x, y) return Float64(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\left(x \cdot y + x\right) + y
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x y) x) y))
double code(double x, double y) {
return ((x * y) + x) + 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) + y
end function
public static double code(double x, double y) {
return ((x * y) + x) + y;
}
def code(x, y): return ((x * y) + x) + y
function code(x, y) return Float64(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\left(x \cdot y + x\right) + y
(FPCore (x y) :precision binary64 (fma (- x -1.0) y x))
double code(double x, double y) {
return fma((x - -1.0), y, x);
}
function code(x, y) return fma(Float64(x - -1.0), y, x) end
code[x_, y_] := N[(N[(x - -1.0), $MachinePrecision] * y + x), $MachinePrecision]
\mathsf{fma}\left(x - -1, y, x\right)
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
distribute-rgt1-inN/A
lower-fma.f64N/A
add-flipN/A
lower--.f64N/A
metadata-eval100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= (+ (+ (* (fmin x y) (fmax x y)) (fmin x y)) (fmax x y)) -1e-258) (fma (fmax x y) (fmin x y) (fmin x y)) (fma (fmax x y) (fmin x y) (fmax x y))))
double code(double x, double y) {
double tmp;
if ((((fmin(x, y) * fmax(x, y)) + fmin(x, y)) + fmax(x, y)) <= -1e-258) {
tmp = fma(fmax(x, y), fmin(x, y), fmin(x, y));
} else {
tmp = fma(fmax(x, y), fmin(x, y), fmax(x, y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(fmin(x, y) * fmax(x, y)) + fmin(x, y)) + fmax(x, y)) <= -1e-258) tmp = fma(fmax(x, y), fmin(x, y), fmin(x, y)); else tmp = fma(fmax(x, y), fmin(x, y), fmax(x, y)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision] + N[Min[x, y], $MachinePrecision]), $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision], -1e-258], N[(N[Max[x, y], $MachinePrecision] * N[Min[x, y], $MachinePrecision] + N[Min[x, y], $MachinePrecision]), $MachinePrecision], N[(N[Max[x, y], $MachinePrecision] * N[Min[x, y], $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left(\mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right) + \mathsf{min}\left(x, y\right)\right) + \mathsf{max}\left(x, y\right) \leq -1 \cdot 10^{-258}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{max}\left(x, y\right), \mathsf{min}\left(x, y\right), \mathsf{min}\left(x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{max}\left(x, y\right), \mathsf{min}\left(x, y\right), \mathsf{max}\left(x, y\right)\right)\\
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -9.9999999999999995e-259Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6464.1%
Applied rewrites64.1%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6464.1%
Applied rewrites64.1%
if -9.9999999999999995e-259 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower-+.f6462.4%
Applied rewrites62.4%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
add-flip-revN/A
sub-flipN/A
mul-1-negN/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-inN/A
mul-1-negN/A
remove-double-negN/A
metadata-evalN/A
associate-*r*N/A
mul-1-negN/A
remove-double-negN/A
mul0-lftN/A
remove-double-negN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
mul0-lftN/A
remove-double-negN/A
mul-1-negN/A
associate-*r*N/A
metadata-evalN/A
Applied rewrites62.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (fmin x y) (fmax x y)))
(t_1 (+ (+ t_0 (fmin x y)) (fmax x y))))
(if (<= t_1 -1e-258)
(fma (fmax x y) (fmin x y) (fmin x y))
(if (<= t_1 2e+270) (fmax x y) t_0))))double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double t_1 = (t_0 + fmin(x, y)) + fmax(x, y);
double tmp;
if (t_1 <= -1e-258) {
tmp = fma(fmax(x, y), fmin(x, y), fmin(x, y));
} else if (t_1 <= 2e+270) {
tmp = fmax(x, y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(fmin(x, y) * fmax(x, y)) t_1 = Float64(Float64(t_0 + fmin(x, y)) + fmax(x, y)) tmp = 0.0 if (t_1 <= -1e-258) tmp = fma(fmax(x, y), fmin(x, y), fmin(x, y)); elseif (t_1 <= 2e+270) tmp = fmax(x, y); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 + N[Min[x, y], $MachinePrecision]), $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-258], N[(N[Max[x, y], $MachinePrecision] * N[Min[x, y], $MachinePrecision] + N[Min[x, y], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+270], N[Max[x, y], $MachinePrecision], t$95$0]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right)\\
t_1 := \left(t\_0 + \mathsf{min}\left(x, y\right)\right) + \mathsf{max}\left(x, y\right)\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-258}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{max}\left(x, y\right), \mathsf{min}\left(x, y\right), \mathsf{min}\left(x, y\right)\right)\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+270}:\\
\;\;\;\;\mathsf{max}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -9.9999999999999995e-259Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6464.1%
Applied rewrites64.1%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6464.1%
Applied rewrites64.1%
if -9.9999999999999995e-259 < (+.f64 (+.f64 (*.f64 x y) x) y) < 2.0000000000000001e270Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.3%
if 2.0000000000000001e270 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower-+.f6462.4%
Applied rewrites62.4%
Taylor expanded in x around inf
lower-*.f6427.5%
Applied rewrites27.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (fmin x y) (fmax x y)))
(t_1 (+ (+ t_0 (fmin x y)) (fmax x y))))
(if (<= t_1 -2e+300)
t_0
(if (<= t_1 -1e-258)
(* (fmin x y) 1.0)
(if (<= t_1 2e+270) (fmax x y) t_0)))))double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double t_1 = (t_0 + fmin(x, y)) + fmax(x, y);
double tmp;
if (t_1 <= -2e+300) {
tmp = t_0;
} else if (t_1 <= -1e-258) {
tmp = fmin(x, y) * 1.0;
} else if (t_1 <= 2e+270) {
tmp = fmax(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) :: t_1
real(8) :: tmp
t_0 = fmin(x, y) * fmax(x, y)
t_1 = (t_0 + fmin(x, y)) + fmax(x, y)
if (t_1 <= (-2d+300)) then
tmp = t_0
else if (t_1 <= (-1d-258)) then
tmp = fmin(x, y) * 1.0d0
else if (t_1 <= 2d+270) then
tmp = fmax(x, y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double t_1 = (t_0 + fmin(x, y)) + fmax(x, y);
double tmp;
if (t_1 <= -2e+300) {
tmp = t_0;
} else if (t_1 <= -1e-258) {
tmp = fmin(x, y) * 1.0;
} else if (t_1 <= 2e+270) {
tmp = fmax(x, y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = fmin(x, y) * fmax(x, y) t_1 = (t_0 + fmin(x, y)) + fmax(x, y) tmp = 0 if t_1 <= -2e+300: tmp = t_0 elif t_1 <= -1e-258: tmp = fmin(x, y) * 1.0 elif t_1 <= 2e+270: tmp = fmax(x, y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(fmin(x, y) * fmax(x, y)) t_1 = Float64(Float64(t_0 + fmin(x, y)) + fmax(x, y)) tmp = 0.0 if (t_1 <= -2e+300) tmp = t_0; elseif (t_1 <= -1e-258) tmp = Float64(fmin(x, y) * 1.0); elseif (t_1 <= 2e+270) tmp = fmax(x, y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = min(x, y) * max(x, y); t_1 = (t_0 + min(x, y)) + max(x, y); tmp = 0.0; if (t_1 <= -2e+300) tmp = t_0; elseif (t_1 <= -1e-258) tmp = min(x, y) * 1.0; elseif (t_1 <= 2e+270) tmp = max(x, y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 + N[Min[x, y], $MachinePrecision]), $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+300], t$95$0, If[LessEqual[t$95$1, -1e-258], N[(N[Min[x, y], $MachinePrecision] * 1.0), $MachinePrecision], If[LessEqual[t$95$1, 2e+270], N[Max[x, y], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right)\\
t_1 := \left(t\_0 + \mathsf{min}\left(x, y\right)\right) + \mathsf{max}\left(x, y\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+300}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq -1 \cdot 10^{-258}:\\
\;\;\;\;\mathsf{min}\left(x, y\right) \cdot 1\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+270}:\\
\;\;\;\;\mathsf{max}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -2.0000000000000001e300 or 2.0000000000000001e270 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower-+.f6462.4%
Applied rewrites62.4%
Taylor expanded in x around inf
lower-*.f6427.5%
Applied rewrites27.5%
if -2.0000000000000001e300 < (+.f64 (+.f64 (*.f64 x y) x) y) < -9.9999999999999995e-259Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6464.1%
Applied rewrites64.1%
Taylor expanded in y around 0
Applied rewrites38.9%
if -9.9999999999999995e-259 < (+.f64 (+.f64 (*.f64 x y) x) y) < 2.0000000000000001e270Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (fmin x y) (fmax x y))))
(if (<= (fmin x y) -2.6)
t_0
(if (<= (fmin x y) 26000000000.0) (fmax x y) t_0))))double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double tmp;
if (fmin(x, y) <= -2.6) {
tmp = t_0;
} else if (fmin(x, y) <= 26000000000.0) {
tmp = fmax(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 = fmin(x, y) * fmax(x, y)
if (fmin(x, y) <= (-2.6d0)) then
tmp = t_0
else if (fmin(x, y) <= 26000000000.0d0) then
tmp = fmax(x, y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = fmin(x, y) * fmax(x, y);
double tmp;
if (fmin(x, y) <= -2.6) {
tmp = t_0;
} else if (fmin(x, y) <= 26000000000.0) {
tmp = fmax(x, y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = fmin(x, y) * fmax(x, y) tmp = 0 if fmin(x, y) <= -2.6: tmp = t_0 elif fmin(x, y) <= 26000000000.0: tmp = fmax(x, y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(fmin(x, y) * fmax(x, y)) tmp = 0.0 if (fmin(x, y) <= -2.6) tmp = t_0; elseif (fmin(x, y) <= 26000000000.0) tmp = fmax(x, y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = min(x, y) * max(x, y); tmp = 0.0; if (min(x, y) <= -2.6) tmp = t_0; elseif (min(x, y) <= 26000000000.0) tmp = max(x, y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Min[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[x, y], $MachinePrecision], -2.6], t$95$0, If[LessEqual[N[Min[x, y], $MachinePrecision], 26000000000.0], N[Max[x, y], $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(x, y\right) \cdot \mathsf{max}\left(x, y\right)\\
\mathbf{if}\;\mathsf{min}\left(x, y\right) \leq -2.6:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\mathsf{min}\left(x, y\right) \leq 26000000000:\\
\;\;\;\;\mathsf{max}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -2.6000000000000001 or 2.6e10 < x Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower-+.f6462.4%
Applied rewrites62.4%
Taylor expanded in x around inf
lower-*.f6427.5%
Applied rewrites27.5%
if -2.6000000000000001 < x < 2.6e10Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.3%
(FPCore (x y) :precision binary64 (fmax x y))
double code(double x, double y) {
return fmax(x, 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 = fmax(x, y)
end function
public static double code(double x, double y) {
return fmax(x, y);
}
def code(x, y): return fmax(x, y)
function code(x, y) return fmax(x, y) end
function tmp = code(x, y) tmp = max(x, y); end
code[x_, y_] := N[Max[x, y], $MachinePrecision]
\mathsf{max}\left(x, y\right)
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.3%
herbie shell --seed 2025192
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))