
(FPCore (x y) :precision binary64 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
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 - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y): return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y) return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673) end
function tmp = code(x, y) tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673; end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
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 - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y): return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y) return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673) end
function tmp = code(x, y) tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673; end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
(FPCore (x y) :precision binary64 (- 0.918938533204673 (fma y (- 0.5 x) x)))
double code(double x, double y) {
return 0.918938533204673 - fma(y, (0.5 - x), x);
}
function code(x, y) return Float64(0.918938533204673 - fma(y, Float64(0.5 - x), x)) end
code[x_, y_] := N[(0.918938533204673 - N[(y * N[(0.5 - x), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 - \mathsf{fma}\left(y, 0.5 - x, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
associate--r+N/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
add-flip-revN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (- x 0.5))))
(if (<= y -3e+21)
t_0
(if (<= y 620000000.0) (- 0.918938533204673 (fma y 0.5 x)) t_0))))
double code(double x, double y) {
double t_0 = y * (x - 0.5);
double tmp;
if (y <= -3e+21) {
tmp = t_0;
} else if (y <= 620000000.0) {
tmp = 0.918938533204673 - fma(y, 0.5, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(y * Float64(x - 0.5)) tmp = 0.0 if (y <= -3e+21) tmp = t_0; elseif (y <= 620000000.0) tmp = Float64(0.918938533204673 - fma(y, 0.5, x)); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3e+21], t$95$0, If[LessEqual[y, 620000000.0], N[(0.918938533204673 - N[(y * 0.5 + x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - 0.5\right)\\
\mathbf{if}\;y \leq -3 \cdot 10^{+21}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 620000000:\\
\;\;\;\;0.918938533204673 - \mathsf{fma}\left(y, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3e21 or 6.2e8 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6451.0
Applied rewrites51.0%
if -3e21 < y < 6.2e8Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
associate--r+N/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
add-flip-revN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites74.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (- x 0.5)))) (if (<= y -1.2) t_0 (if (<= y 1.7) (- 0.918938533204673 x) t_0))))
double code(double x, double y) {
double t_0 = y * (x - 0.5);
double tmp;
if (y <= -1.2) {
tmp = t_0;
} else if (y <= 1.7) {
tmp = 0.918938533204673 - x;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * (x - 0.5d0)
if (y <= (-1.2d0)) then
tmp = t_0
else if (y <= 1.7d0) then
tmp = 0.918938533204673d0 - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (x - 0.5);
double tmp;
if (y <= -1.2) {
tmp = t_0;
} else if (y <= 1.7) {
tmp = 0.918938533204673 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * (x - 0.5) tmp = 0 if y <= -1.2: tmp = t_0 elif y <= 1.7: tmp = 0.918938533204673 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(x - 0.5)) tmp = 0.0 if (y <= -1.2) tmp = t_0; elseif (y <= 1.7) tmp = Float64(0.918938533204673 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * (x - 0.5); tmp = 0.0; if (y <= -1.2) tmp = t_0; elseif (y <= 1.7) tmp = 0.918938533204673 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.2], t$95$0, If[LessEqual[y, 1.7], N[(0.918938533204673 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - 0.5\right)\\
\mathbf{if}\;y \leq -1.2:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.7:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.19999999999999996 or 1.69999999999999996 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6451.0
Applied rewrites51.0%
if -1.19999999999999996 < y < 1.69999999999999996Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
associate--r+N/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
add-flip-revN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in y around 0
lower--.f6450.4
Applied rewrites50.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (- y 1.0)))) (if (<= x -0.65) t_0 (if (<= x 0.65) (fma y -0.5 0.918938533204673) t_0))))
double code(double x, double y) {
double t_0 = x * (y - 1.0);
double tmp;
if (x <= -0.65) {
tmp = t_0;
} else if (x <= 0.65) {
tmp = fma(y, -0.5, 0.918938533204673);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(x * Float64(y - 1.0)) tmp = 0.0 if (x <= -0.65) tmp = t_0; elseif (x <= 0.65) tmp = fma(y, -0.5, 0.918938533204673); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.65], t$95$0, If[LessEqual[x, 0.65], N[(y * -0.5 + 0.918938533204673), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - 1\right)\\
\mathbf{if}\;x \leq -0.65:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.65:\\
\;\;\;\;\mathsf{fma}\left(y, -0.5, 0.918938533204673\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.650000000000000022 or 0.650000000000000022 < x Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6451.0
Applied rewrites51.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f6450.8
Applied rewrites50.8%
if -0.650000000000000022 < x < 0.650000000000000022Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f6450.5
Applied rewrites50.5%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
metadata-eval50.5
Applied rewrites50.5%
(FPCore (x y)
:precision binary64
(if (<= y -3e+21)
(* x y)
(if (<= y 2.6e-40)
(- 0.918938533204673 x)
(if (<= y 1.1e+121) (fma y -0.5 0.918938533204673) (* x y)))))
double code(double x, double y) {
double tmp;
if (y <= -3e+21) {
tmp = x * y;
} else if (y <= 2.6e-40) {
tmp = 0.918938533204673 - x;
} else if (y <= 1.1e+121) {
tmp = fma(y, -0.5, 0.918938533204673);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -3e+21) tmp = Float64(x * y); elseif (y <= 2.6e-40) tmp = Float64(0.918938533204673 - x); elseif (y <= 1.1e+121) tmp = fma(y, -0.5, 0.918938533204673); else tmp = Float64(x * y); end return tmp end
code[x_, y_] := If[LessEqual[y, -3e+21], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.6e-40], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[y, 1.1e+121], N[(y * -0.5 + 0.918938533204673), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+21}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-40}:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+121}:\\
\;\;\;\;\mathsf{fma}\left(y, -0.5, 0.918938533204673\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3e21 or 1.10000000000000001e121 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6451.0
Applied rewrites51.0%
Taylor expanded in x around inf
lower-*.f6426.6
Applied rewrites26.6%
if -3e21 < y < 2.6000000000000001e-40Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
associate--r+N/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
add-flip-revN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in y around 0
lower--.f6450.4
Applied rewrites50.4%
if 2.6000000000000001e-40 < y < 1.10000000000000001e121Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f6450.5
Applied rewrites50.5%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
metadata-eval50.5
Applied rewrites50.5%
(FPCore (x y)
:precision binary64
(if (<= y -3e+21)
(* x y)
(if (<= y 1.85)
(- 0.918938533204673 x)
(if (<= y 1.1e+121) (* y -0.5) (* x y)))))
double code(double x, double y) {
double tmp;
if (y <= -3e+21) {
tmp = x * y;
} else if (y <= 1.85) {
tmp = 0.918938533204673 - x;
} else if (y <= 1.1e+121) {
tmp = y * -0.5;
} else {
tmp = x * 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 (y <= (-3d+21)) then
tmp = x * y
else if (y <= 1.85d0) then
tmp = 0.918938533204673d0 - x
else if (y <= 1.1d+121) then
tmp = y * (-0.5d0)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3e+21) {
tmp = x * y;
} else if (y <= 1.85) {
tmp = 0.918938533204673 - x;
} else if (y <= 1.1e+121) {
tmp = y * -0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3e+21: tmp = x * y elif y <= 1.85: tmp = 0.918938533204673 - x elif y <= 1.1e+121: tmp = y * -0.5 else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -3e+21) tmp = Float64(x * y); elseif (y <= 1.85) tmp = Float64(0.918938533204673 - x); elseif (y <= 1.1e+121) tmp = Float64(y * -0.5); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3e+21) tmp = x * y; elseif (y <= 1.85) tmp = 0.918938533204673 - x; elseif (y <= 1.1e+121) tmp = y * -0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3e+21], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.85], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[y, 1.1e+121], N[(y * -0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+21}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.85:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+121}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3e21 or 1.10000000000000001e121 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6451.0
Applied rewrites51.0%
Taylor expanded in x around inf
lower-*.f6426.6
Applied rewrites26.6%
if -3e21 < y < 1.8500000000000001Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
associate--r+N/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
add-flip-revN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in y around 0
lower--.f6450.4
Applied rewrites50.4%
if 1.8500000000000001 < y < 1.10000000000000001e121Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6451.0
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites26.5%
(FPCore (x y) :precision binary64 (if (<= y -3e+21) (* x y) (if (<= y 1.0) (- 0.918938533204673 x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -3e+21) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = 0.918938533204673 - x;
} else {
tmp = x * 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 (y <= (-3d+21)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = 0.918938533204673d0 - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3e+21) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = 0.918938533204673 - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3e+21: tmp = x * y elif y <= 1.0: tmp = 0.918938533204673 - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -3e+21) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(0.918938533204673 - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3e+21) tmp = x * y; elseif (y <= 1.0) tmp = 0.918938533204673 - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3e+21], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], N[(0.918938533204673 - x), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+21}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3e21 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
lower--.f6451.0
Applied rewrites51.0%
Taylor expanded in x around inf
lower-*.f6426.6
Applied rewrites26.6%
if -3e21 < y < 1Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
associate--r+N/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
add-flip-revN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in y around 0
lower--.f6450.4
Applied rewrites50.4%
(FPCore (x y) :precision binary64 (- 0.918938533204673 x))
double code(double x, double y) {
return 0.918938533204673 - 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 = 0.918938533204673d0 - x
end function
public static double code(double x, double y) {
return 0.918938533204673 - x;
}
def code(x, y): return 0.918938533204673 - x
function code(x, y) return Float64(0.918938533204673 - x) end
function tmp = code(x, y) tmp = 0.918938533204673 - x; end
code[x_, y_] := N[(0.918938533204673 - x), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 - x
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
sub-flip-reverseN/A
lower--.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
associate--r+N/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
add-flip-revN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in y around 0
lower--.f6450.4
Applied rewrites50.4%
(FPCore (x y) :precision binary64 0.918938533204673)
double code(double x, double y) {
return 0.918938533204673;
}
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 = 0.918938533204673d0
end function
public static double code(double x, double y) {
return 0.918938533204673;
}
def code(x, y): return 0.918938533204673
function code(x, y) return 0.918938533204673 end
function tmp = code(x, y) tmp = 0.918938533204673; end
code[x_, y_] := 0.918938533204673
\begin{array}{l}
\\
0.918938533204673
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f6450.5
Applied rewrites50.5%
Taylor expanded in y around 0
Applied rewrites25.9%
herbie shell --seed 2025154
(FPCore (x y)
:name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A"
:precision binary64
(+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))