
(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]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + 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(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]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + y
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (fma (- y -1.0) x y))
assert(x < y);
double code(double x, double y) {
return fma((y - -1.0), x, y);
}
x, y = sort([x, y]) function code(x, y) return fma(Float64(y - -1.0), x, y) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(y - -1.0), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(y - -1, x, y\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64100.0
Applied rewrites100.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) x) y))) (if (<= t_0 -1e+307) (* y x) (if (<= t_0 1e+291) (+ x y) (* y x)))))
assert(x < y);
double code(double x, double y) {
double t_0 = ((x * y) + x) + y;
double tmp;
if (t_0 <= -1e+307) {
tmp = y * x;
} else if (t_0 <= 1e+291) {
tmp = x + y;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = ((x * y) + x) + y
if (t_0 <= (-1d+307)) then
tmp = y * x
else if (t_0 <= 1d+291) then
tmp = x + y
else
tmp = y * x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = ((x * y) + x) + y;
double tmp;
if (t_0 <= -1e+307) {
tmp = y * x;
} else if (t_0 <= 1e+291) {
tmp = x + y;
} else {
tmp = y * x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = ((x * y) + x) + y tmp = 0 if t_0 <= -1e+307: tmp = y * x elif t_0 <= 1e+291: tmp = x + y else: tmp = y * x return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(Float64(Float64(x * y) + x) + y) tmp = 0.0 if (t_0 <= -1e+307) tmp = Float64(y * x); elseif (t_0 <= 1e+291) tmp = Float64(x + y); else tmp = Float64(y * x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = ((x * y) + x) + y;
tmp = 0.0;
if (t_0 <= -1e+307)
tmp = y * x;
elseif (t_0 <= 1e+291)
tmp = x + y;
else
tmp = y * x;
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[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+307], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 1e+291], N[(x + y), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot y + x\right) + y\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+307}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;t\_0 \leq 10^{+291}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -9.99999999999999986e306 or 9.9999999999999996e290 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6491.5
Applied rewrites91.5%
lift-fma.f64N/A
distribute-lft1-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lift--.f6491.5
Applied rewrites91.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6490.4
Applied rewrites90.4%
if -9.99999999999999986e306 < (+.f64 (+.f64 (*.f64 x y) x) y) < 9.9999999999999996e290Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites85.6%
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-202) (* (- y -1.0) x) (fma y x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((((x * y) + x) + y) <= -2e-202) {
tmp = (y - -1.0) * x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * y) + x) + y) <= -2e-202) tmp = Float64(Float64(y - -1.0) * x); else tmp = fma(y, 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[N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -2e-202], N[(N[(y - -1.0), $MachinePrecision] * x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-202}:\\
\;\;\;\;\left(y - -1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -2.0000000000000001e-202Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6498.7
Applied rewrites98.7%
lift-fma.f64N/A
distribute-lft1-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lift--.f6498.7
Applied rewrites98.7%
if -2.0000000000000001e-202 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6495.8
Applied rewrites95.8%
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-202) (fma y x x) (fma y x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((((x * y) + x) + y) <= -2e-202) {
tmp = fma(y, x, x);
} else {
tmp = fma(y, x, y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * y) + x) + y) <= -2e-202) tmp = fma(y, x, x); else tmp = fma(y, 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[N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -2e-202], N[(y * x + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-202}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -2.0000000000000001e-202Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6498.7
Applied rewrites98.7%
if -2.0000000000000001e-202 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6495.8
Applied rewrites95.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -1.0) (fma y x x) (if (<= x 4.2) (+ x y) (* y x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = fma(y, x, x);
} else if (x <= 4.2) {
tmp = x + y;
} else {
tmp = y * x;
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = fma(y, x, x); elseif (x <= 4.2) tmp = Float64(x + y); else tmp = Float64(y * x); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -1.0], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 4.2], N[(x + y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 4.2:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6499.4
Applied rewrites99.4%
if -1 < x < 4.20000000000000018Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites99.0%
if 4.20000000000000018 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6495.5
Applied rewrites95.5%
lift-fma.f64N/A
distribute-lft1-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lift--.f6495.5
Applied rewrites95.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6495.5
Applied rewrites95.5%
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-202) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((((x * y) + x) + y) <= -2e-202) {
tmp = x;
} else {
tmp = 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-202)) then
tmp = x
else
tmp = 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-202) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (((x * y) + x) + y) <= -2e-202: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * y) + x) + y) <= -2e-202) tmp = x; else tmp = 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-202)
tmp = x;
else
tmp = 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[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -2e-202], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-202}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -2.0000000000000001e-202Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites75.0%
if -2.0000000000000001e-202 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites71.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ x y))
assert(x < y);
double code(double x, double y) {
return x + 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 = x + y
end function
assert x < y;
public static double code(double x, double y) {
return x + y;
}
[x, y] = sort([x, y]) def code(x, y): return x + y
x, y = sort([x, y]) function code(x, y) return Float64(x + y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x + y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites75.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 x)
assert(x < y);
double code(double x, double y) {
return x;
}
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 = x
end function
assert x < y;
public static double code(double x, double y) {
return x;
}
[x, y] = sort([x, y]) def code(x, y): return x
x, y = sort([x, y]) function code(x, y) return x end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := x
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites39.5%
herbie shell --seed 2025092
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))