
(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
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-outN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (fma (- y) x x) (if (<= x 8.8e-87) (fma 1.0 x y) (fma (- y) x y))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = fma(-y, x, x);
} else if (x <= 8.8e-87) {
tmp = fma(1.0, x, y);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = fma(Float64(-y), x, x); elseif (x <= 8.8e-87) tmp = fma(1.0, x, y); else tmp = fma(Float64(-y), x, y); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.0], N[((-y) * x + x), $MachinePrecision], If[LessEqual[x, 8.8e-87], N[(1.0 * x + y), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{-87}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites98.6%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f6498.6
Applied rewrites98.6%
if -1 < x < 8.79999999999999953e-87Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-outN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.4%
if 8.79999999999999953e-87 < x Initial program 100.0%
Taylor expanded in y around inf
flip--N/A
flip--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6452.3
Applied rewrites52.3%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- x (* x y)) (if (<= x 8.8e-87) (fma 1.0 x y) (fma (- y) x y))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x - (x * y);
} else if (x <= 8.8e-87) {
tmp = fma(1.0, x, y);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x - Float64(x * y)); elseif (x <= 8.8e-87) tmp = fma(1.0, x, y); else tmp = fma(Float64(-y), x, y); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8.8e-87], N[(1.0 * x + y), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{-87}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites98.6%
if -1 < x < 8.79999999999999953e-87Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-outN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.4%
if 8.79999999999999953e-87 < x Initial program 100.0%
Taylor expanded in y around inf
flip--N/A
flip--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6452.3
Applied rewrites52.3%
(FPCore (x y) :precision binary64 (if (<= y -600.0) (* (- x) y) (if (<= y 6.5e-35) (fma 1.0 x y) (fma (- y) x y))))
double code(double x, double y) {
double tmp;
if (y <= -600.0) {
tmp = -x * y;
} else if (y <= 6.5e-35) {
tmp = fma(1.0, x, y);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -600.0) tmp = Float64(Float64(-x) * y); elseif (y <= 6.5e-35) tmp = fma(1.0, x, y); else tmp = fma(Float64(-y), x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -600.0], N[((-x) * y), $MachinePrecision], If[LessEqual[y, 6.5e-35], N[(1.0 * x + y), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -600:\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-35}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if y < -600Initial program 100.0%
Taylor expanded in y around inf
flip--N/A
flip--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6499.4
Applied rewrites99.4%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6451.1
Applied rewrites51.1%
if -600 < y < 6.4999999999999999e-35Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-outN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.2%
if 6.4999999999999999e-35 < y Initial program 100.0%
Taylor expanded in y around inf
flip--N/A
flip--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6493.6
Applied rewrites93.6%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (+ x y) (* x y))) (t_1 (* (- x) y))) (if (<= t_0 (- INFINITY)) t_1 (if (<= t_0 5e+283) (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 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= 5e+283) {
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 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= 5e+283) 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, (-Infinity)], t$95$1, If[LessEqual[t$95$0, 5e+283], 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 -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+283}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 5.0000000000000004e283 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
flip--N/A
flip--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6493.7
Applied rewrites93.7%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6486.8
Applied rewrites86.8%
if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 5.0000000000000004e283Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
+-commutativeN/A
associate--l+N/A
*-lft-identityN/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-outN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites85.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (+ x y) (* x y))) (t_1 (* (- x) y)))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -5e-238) x (if (<= t_0 2e+305) 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 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -5e-238) {
tmp = x;
} else if (t_0 <= 2e+305) {
tmp = y;
} else {
tmp = t_1;
}
return tmp;
}
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 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= -5e-238) {
tmp = x;
} else if (t_0 <= 2e+305) {
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 <= -math.inf: tmp = t_1 elif t_0 <= -5e-238: tmp = x elif t_0 <= 2e+305: 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 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -5e-238) tmp = x; elseif (t_0 <= 2e+305) 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 <= -Inf) tmp = t_1; elseif (t_0 <= -5e-238) tmp = x; elseif (t_0 <= 2e+305) 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, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -5e-238], x, If[LessEqual[t$95$0, 2e+305], 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 -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -5 \cdot 10^{-238}:\\
\;\;\;\;x\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+305}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 1.9999999999999999e305 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
flip--N/A
flip--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6498.5
Applied rewrites98.5%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6497.1
Applied rewrites97.1%
if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < -5e-238Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites44.1%
if -5e-238 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1.9999999999999999e305Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites43.7%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -5e-238) x y))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -5e-238) {
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)) <= (-5d-238)) 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)) <= -5e-238) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -5e-238: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -5e-238) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x + y) - (x * y)) <= -5e-238) 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], -5e-238], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -5 \cdot 10^{-238}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -5e-238Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites39.0%
if -5e-238 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites38.5%
(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.5%
herbie shell --seed 2025101
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))