
(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 7 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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (fma (- 1.0 y) x y))
assert(x < y);
double code(double x, double y) {
return fma((1.0 - y), x, y);
}
x, y = sort([x, y]) function code(x, y) return fma(Float64(1.0 - y), x, y) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(1.0 - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(1 - y, x, y\right)
\end{array}
Initial program 100.0%
Applied rewrites100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -430000000000.0) (* (- x) y) (if (<= y 5.5e-5) (fma 1.0 x y) (* (- 1.0 x) y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -430000000000.0) {
tmp = -x * y;
} else if (y <= 5.5e-5) {
tmp = fma(1.0, x, y);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -430000000000.0) tmp = Float64(Float64(-x) * y); elseif (y <= 5.5e-5) tmp = fma(1.0, x, y); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, -430000000000.0], N[((-x) * y), $MachinePrecision], If[LessEqual[y, 5.5e-5], N[(1.0 * x + y), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -430000000000:\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if y < -4.3e11Initial program 100.0%
Taylor expanded in y around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.4
Applied rewrites62.4%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6426.5
Applied rewrites26.5%
if -4.3e11 < y < 5.5000000000000002e-5Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites75.0%
if 5.5000000000000002e-5 < y Initial program 100.0%
Taylor expanded in y around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.4
Applied rewrites62.4%
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6462.4
Applied rewrites62.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -2e-295) (* (- 1.0 y) x) (- y (* y x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-295) {
tmp = (1.0 - y) * x;
} else {
tmp = y - (y * x);
}
return tmp;
}
NOTE: x and y 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(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-295)) then
tmp = (1.0d0 - y) * x
else
tmp = y - (y * x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-295) {
tmp = (1.0 - y) * x;
} else {
tmp = y - (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -2e-295: tmp = (1.0 - y) * x else: tmp = y - (y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -2e-295) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(y - Float64(y * x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (((x + y) - (x * y)) <= -2e-295)
tmp = (1.0 - y) * x;
else
tmp = y - (y * x);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -2e-295], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{-295}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.00000000000000012e-295Initial program 100.0%
Taylor expanded in x around inf
flip--N/A
sqr-neg-revN/A
mul-1-negN/A
mul-1-negN/A
sqr-neg-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
flip--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-rgt-inN/A
mul-1-negN/A
fp-cancel-sub-signN/A
Applied rewrites63.0%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lift--.f6463.0
Applied rewrites63.0%
if -2.00000000000000012e-295 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.4
Applied rewrites62.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -2e-295) (* (- 1.0 y) x) (* (- 1.0 x) y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-295) {
tmp = (1.0 - y) * x;
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
NOTE: x and y 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(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-295)) then
tmp = (1.0d0 - y) * x
else
tmp = (1.0d0 - x) * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-295) {
tmp = (1.0 - y) * x;
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -2e-295: tmp = (1.0 - y) * x else: tmp = (1.0 - x) * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -2e-295) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (((x + y) - (x * y)) <= -2e-295)
tmp = (1.0 - y) * x;
else
tmp = (1.0 - x) * y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -2e-295], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{-295}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.00000000000000012e-295Initial program 100.0%
Taylor expanded in x around inf
flip--N/A
sqr-neg-revN/A
mul-1-negN/A
mul-1-negN/A
sqr-neg-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
flip--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-rgt-inN/A
mul-1-negN/A
fp-cancel-sub-signN/A
Applied rewrites63.0%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lift--.f6463.0
Applied rewrites63.0%
if -2.00000000000000012e-295 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.4
Applied rewrites62.4%
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6462.4
Applied rewrites62.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (let* ((t_0 (- (+ x y) (* x y))) (t_1 (* (- x) y))) (if (<= t_0 -5e+303) t_1 (if (<= t_0 1e+299) (fma 1.0 x y) t_1))))
assert(x < y);
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double t_1 = -x * y;
double tmp;
if (t_0 <= -5e+303) {
tmp = t_1;
} else if (t_0 <= 1e+299) {
tmp = fma(1.0, x, y);
} else {
tmp = t_1;
}
return tmp;
}
x, y = sort([x, y]) 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 <= -5e+303) tmp = t_1; elseif (t_0 <= 1e+299) tmp = fma(1.0, x, y); else tmp = t_1; end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function.
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, -5e+303], t$95$1, If[LessEqual[t$95$0, 1e+299], N[(1.0 * x + y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
t_1 := \left(-x\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+303}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+299}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -4.9999999999999997e303 or 1.0000000000000001e299 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.4
Applied rewrites62.4%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6426.5
Applied rewrites26.5%
if -4.9999999999999997e303 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1.0000000000000001e299Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites75.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (let* ((t_0 (* (- x) y))) (if (<= x -1.0) t_0 (if (<= x 1.0) y t_0))))
assert(x < y);
double code(double x, double y) {
double t_0 = -x * y;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x and y 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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = -x * y
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = -x * y;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = -x * y tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 1.0: tmp = y else: tmp = t_0 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(Float64(-x) * y) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = y; else tmp = t_0; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = -x * y;
tmp = 0.0;
if (x <= -1.0)
tmp = t_0;
elseif (x <= 1.0)
tmp = y;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := Block[{t$95$0 = N[((-x) * y), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], y, t$95$0]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(-x\right) \cdot y\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in y around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.4
Applied rewrites62.4%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6426.5
Applied rewrites26.5%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites38.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 y)
assert(x < y);
double code(double x, double y) {
return y;
}
NOTE: x and y 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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
assert x < y;
public static double code(double x, double y) {
return y;
}
[x, y] = sort([x, y]) def code(x, y): return y
x, y = sort([x, y]) function code(x, y) return y end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := y
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites38.6%
herbie shell --seed 2025138
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))