
(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(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
Herbie found 8 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(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
(FPCore (x y) :precision binary64 (fma (- 1.0 y) x y))
double code(double x, double y) {
return fma((1.0 - y), x, y);
}
function code(x, y) return fma(Float64(1.0 - y), x, y) end
code[x_, y_] := N[(N[(1.0 - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1 - y, x, y\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (+ x y) (* x y))))
(if (<= t_0 -1000000000000.0)
(- x (* x y))
(if (<= t_0 2e-56) (fma 1.0 x y) (- y (* x y))))))
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double tmp;
if (t_0 <= -1000000000000.0) {
tmp = x - (x * y);
} else if (t_0 <= 2e-56) {
tmp = fma(1.0, x, y);
} else {
tmp = y - (x * y);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) tmp = 0.0 if (t_0 <= -1000000000000.0) tmp = Float64(x - Float64(x * y)); elseif (t_0 <= 2e-56) tmp = fma(1.0, x, y); else tmp = Float64(y - Float64(x * y)); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1000000000000.0], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-56], N[(1.0 * x + y), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
\mathbf{if}\;t\_0 \leq -1000000000000:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-56}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1e12Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites68.6%
if -1e12 < (-.f64 (+.f64 x y) (*.f64 x y)) < 2.0000000000000001e-56Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.9%
if 2.0000000000000001e-56 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites65.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (+ x y) (* x y))))
(if (<= t_0 -1000000000000.0)
(- x (* x y))
(if (<= t_0 2e-56) (fma 1.0 x y) (* (- 1.0 x) y)))))
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double tmp;
if (t_0 <= -1000000000000.0) {
tmp = x - (x * y);
} else if (t_0 <= 2e-56) {
tmp = fma(1.0, x, y);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) tmp = 0.0 if (t_0 <= -1000000000000.0) tmp = Float64(x - Float64(x * y)); elseif (t_0 <= 2e-56) tmp = fma(1.0, x, y); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1000000000000.0], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-56], N[(1.0 * x + y), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
\mathbf{if}\;t\_0 \leq -1000000000000:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-56}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1e12Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites68.6%
if -1e12 < (-.f64 (+.f64 x y) (*.f64 x y)) < 2.0000000000000001e-56Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.9%
if 2.0000000000000001e-56 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
distribute-rgt-inN/A
mul-1-negN/A
fp-cancel-sub-signN/A
*-lft-identityN/A
*-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f6465.8
Applied rewrites65.8%
(FPCore (x y) :precision binary64 (if (<= y -66.0) (* (- x) y) (if (<= y 1.95e-11) (fma 1.0 x y) (* (- 1.0 x) y))))
double code(double x, double y) {
double tmp;
if (y <= -66.0) {
tmp = -x * y;
} else if (y <= 1.95e-11) {
tmp = fma(1.0, x, y);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -66.0) tmp = Float64(Float64(-x) * y); elseif (y <= 1.95e-11) tmp = fma(1.0, x, y); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := If[LessEqual[y, -66.0], N[((-x) * y), $MachinePrecision], If[LessEqual[y, 1.95e-11], N[(1.0 * x + y), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -66:\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if y < -66Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
distribute-rgt-inN/A
mul-1-negN/A
fp-cancel-sub-signN/A
*-lft-identityN/A
*-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f6499.3
Applied rewrites99.3%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6451.3
Applied rewrites51.3%
if -66 < y < 1.95000000000000005e-11Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.2%
if 1.95000000000000005e-11 < y Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
distribute-rgt-inN/A
mul-1-negN/A
fp-cancel-sub-signN/A
*-lft-identityN/A
*-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f6497.3
Applied rewrites97.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (+ x y) (* x y))) (t_1 (* (- x) y))) (if (<= t_0 -1.5e+307) t_1 (if (<= t_0 2e+288) (fma 1.0 x y) t_1))))
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double t_1 = -x * y;
double tmp;
if (t_0 <= -1.5e+307) {
tmp = t_1;
} else if (t_0 <= 2e+288) {
tmp = fma(1.0, x, y);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) t_1 = Float64(Float64(-x) * y) tmp = 0.0 if (t_0 <= -1.5e+307) tmp = t_1; elseif (t_0 <= 2e+288) tmp = fma(1.0, x, y); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-x) * y), $MachinePrecision]}, If[LessEqual[t$95$0, -1.5e+307], t$95$1, If[LessEqual[t$95$0, 2e+288], N[(1.0 * x + y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
t_1 := \left(-x\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -1.5 \cdot 10^{+307}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+288}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.4999999999999999e307 or 2e288 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
distribute-rgt-inN/A
mul-1-negN/A
fp-cancel-sub-signN/A
*-lft-identityN/A
*-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f6494.3
Applied rewrites94.3%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6489.6
Applied rewrites89.6%
if -1.4999999999999999e307 < (-.f64 (+.f64 x y) (*.f64 x y)) < 2e288Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites85.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (+ x y) (* x y))) (t_1 (* (- x) y)))
(if (<= t_0 -1.5e+307)
t_1
(if (<= t_0 -2e-236) x (if (<= t_0 2e+288) y t_1)))))
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double t_1 = -x * y;
double tmp;
if (t_0 <= -1.5e+307) {
tmp = t_1;
} else if (t_0 <= -2e-236) {
tmp = x;
} else if (t_0 <= 2e+288) {
tmp = y;
} 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 * y)
t_1 = -x * y
if (t_0 <= (-1.5d+307)) then
tmp = t_1
else if (t_0 <= (-2d-236)) then
tmp = x
else if (t_0 <= 2d+288) then
tmp = y
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double t_1 = -x * y;
double tmp;
if (t_0 <= -1.5e+307) {
tmp = t_1;
} else if (t_0 <= -2e-236) {
tmp = x;
} else if (t_0 <= 2e+288) {
tmp = y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (x + y) - (x * y) t_1 = -x * y tmp = 0 if t_0 <= -1.5e+307: tmp = t_1 elif t_0 <= -2e-236: tmp = x elif t_0 <= 2e+288: tmp = y else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) t_1 = Float64(Float64(-x) * y) tmp = 0.0 if (t_0 <= -1.5e+307) tmp = t_1; elseif (t_0 <= -2e-236) tmp = x; elseif (t_0 <= 2e+288) tmp = y; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (x + y) - (x * y); t_1 = -x * y; tmp = 0.0; if (t_0 <= -1.5e+307) tmp = t_1; elseif (t_0 <= -2e-236) tmp = x; elseif (t_0 <= 2e+288) tmp = y; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-x) * y), $MachinePrecision]}, If[LessEqual[t$95$0, -1.5e+307], t$95$1, If[LessEqual[t$95$0, -2e-236], x, If[LessEqual[t$95$0, 2e+288], y, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
t_1 := \left(-x\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -1.5 \cdot 10^{+307}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-236}:\\
\;\;\;\;x\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+288}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.4999999999999999e307 or 2e288 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
negate-subN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
negate-subN/A
mul-1-negN/A
distribute-rgt-inN/A
mul-1-negN/A
fp-cancel-sub-signN/A
*-lft-identityN/A
*-commutativeN/A
associate--l+N/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
negate-subN/A
lower--.f6494.3
Applied rewrites94.3%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6489.6
Applied rewrites89.6%
if -1.4999999999999999e307 < (-.f64 (+.f64 x y) (*.f64 x y)) < -2.0000000000000001e-236Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites44.1%
if -2.0000000000000001e-236 < (-.f64 (+.f64 x y) (*.f64 x y)) < 2e288Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites43.5%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -2e-236) x y))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-236) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((x + y) - (x * y)) <= (-2d-236)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-236) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -2e-236: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -2e-236) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x + y) - (x * y)) <= -2e-236) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -2e-236], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{-236}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.0000000000000001e-236Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites38.7%
if -2.0000000000000001e-236 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites37.9%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return 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 = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites38.6%
herbie shell --seed 2025119
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))