
(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}
Sampling outcomes in binary64 precision:
Herbie found 11 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 (fma (- y 1.0) x (fma -0.5 y 0.918938533204673)))
double code(double x, double y) {
return fma((y - 1.0), x, fma(-0.5, y, 0.918938533204673));
}
function code(x, y) return fma(Float64(y - 1.0), x, fma(-0.5, y, 0.918938533204673)) end
code[x_, y_] := N[(N[(y - 1.0), $MachinePrecision] * x + N[(-0.5 * y + 0.918938533204673), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - 1, x, \mathsf{fma}\left(-0.5, y, 0.918938533204673\right)\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites47.2%
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(if (<= x -5e+247)
(* x y)
(if (<= x -175.0)
(- 0.918938533204673 x)
(if (<= x 0.74) (fma -0.5 y 0.918938533204673) (* x y)))))
double code(double x, double y) {
double tmp;
if (x <= -5e+247) {
tmp = x * y;
} else if (x <= -175.0) {
tmp = 0.918938533204673 - x;
} else if (x <= 0.74) {
tmp = fma(-0.5, y, 0.918938533204673);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -5e+247) tmp = Float64(x * y); elseif (x <= -175.0) tmp = Float64(0.918938533204673 - x); elseif (x <= 0.74) tmp = fma(-0.5, y, 0.918938533204673); else tmp = Float64(x * y); end return tmp end
code[x_, y_] := If[LessEqual[x, -5e+247], N[(x * y), $MachinePrecision], If[LessEqual[x, -175.0], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[x, 0.74], N[(-0.5 * y + 0.918938533204673), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+247}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -175:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;x \leq 0.74:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, 0.918938533204673\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.00000000000000023e247 or 0.73999999999999999 < x Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
metadata-evalN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
Applied rewrites60.2%
Taylor expanded in x around inf
Applied rewrites59.4%
if -5.00000000000000023e247 < x < -175Initial program 100.0%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6462.8
Applied rewrites62.8%
if -175 < x < 0.73999999999999999Initial program 100.0%
Taylor expanded in x around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f6496.2
Applied rewrites96.2%
(FPCore (x y) :precision binary64 (if (or (<= y -2400000.0) (not (<= y 2.9))) (* (- x 0.5) y) (fma x y (- 0.918938533204673 x))))
double code(double x, double y) {
double tmp;
if ((y <= -2400000.0) || !(y <= 2.9)) {
tmp = (x - 0.5) * y;
} else {
tmp = fma(x, y, (0.918938533204673 - x));
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -2400000.0) || !(y <= 2.9)) tmp = Float64(Float64(x - 0.5) * y); else tmp = fma(x, y, Float64(0.918938533204673 - x)); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -2400000.0], N[Not[LessEqual[y, 2.9]], $MachinePrecision]], N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision], N[(x * y + N[(0.918938533204673 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2400000 \lor \neg \left(y \leq 2.9\right):\\
\;\;\;\;\left(x - 0.5\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, 0.918938533204673 - x\right)\\
\end{array}
\end{array}
if y < -2.4e6 or 2.89999999999999991 < y Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
metadata-evalN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
Applied rewrites98.8%
if -2.4e6 < y < 2.89999999999999991Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites98.2%
Final simplification98.5%
(FPCore (x y) :precision binary64 (if (<= y -2400000.0) (fma y x (* -0.5 y)) (if (<= y 2.9) (fma x y (- 0.918938533204673 x)) (* (- x 0.5) y))))
double code(double x, double y) {
double tmp;
if (y <= -2400000.0) {
tmp = fma(y, x, (-0.5 * y));
} else if (y <= 2.9) {
tmp = fma(x, y, (0.918938533204673 - x));
} else {
tmp = (x - 0.5) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2400000.0) tmp = fma(y, x, Float64(-0.5 * y)); elseif (y <= 2.9) tmp = fma(x, y, Float64(0.918938533204673 - x)); else tmp = Float64(Float64(x - 0.5) * y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2400000.0], N[(y * x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.9], N[(x * y + N[(0.918938533204673 - x), $MachinePrecision]), $MachinePrecision], N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2400000:\\
\;\;\;\;\mathsf{fma}\left(y, x, -0.5 \cdot y\right)\\
\mathbf{elif}\;y \leq 2.9:\\
\;\;\;\;\mathsf{fma}\left(x, y, 0.918938533204673 - x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - 0.5\right) \cdot y\\
\end{array}
\end{array}
if y < -2.4e6Initial program 100.0%
lift-+.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites21.0%
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites100.0%
Taylor expanded in y around inf
lower-*.f6499.4
Applied rewrites99.4%
if -2.4e6 < y < 2.89999999999999991Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites98.2%
if 2.89999999999999991 < y Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
metadata-evalN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
Applied rewrites98.2%
(FPCore (x y) :precision binary64 (if (or (<= y -1.5) (not (<= y 1.1))) (* (- x 0.5) y) (- 0.918938533204673 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.5) || !(y <= 1.1)) {
tmp = (x - 0.5) * y;
} else {
tmp = 0.918938533204673 - x;
}
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 <= (-1.5d0)) .or. (.not. (y <= 1.1d0))) then
tmp = (x - 0.5d0) * y
else
tmp = 0.918938533204673d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.5) || !(y <= 1.1)) {
tmp = (x - 0.5) * y;
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.5) or not (y <= 1.1): tmp = (x - 0.5) * y else: tmp = 0.918938533204673 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.5) || !(y <= 1.1)) tmp = Float64(Float64(x - 0.5) * y); else tmp = Float64(0.918938533204673 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.5) || ~((y <= 1.1))) tmp = (x - 0.5) * y; else tmp = 0.918938533204673 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.5], N[Not[LessEqual[y, 1.1]], $MachinePrecision]], N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \lor \neg \left(y \leq 1.1\right):\\
\;\;\;\;\left(x - 0.5\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\
\end{array}
\end{array}
if y < -1.5 or 1.1000000000000001 < y Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
metadata-evalN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
Applied rewrites98.4%
if -1.5 < y < 1.1000000000000001Initial program 100.0%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6497.0
Applied rewrites97.0%
Final simplification97.7%
(FPCore (x y) :precision binary64 (if (or (<= y -9500.0) (not (<= y 1.85))) (* -0.5 y) (- 0.918938533204673 x)))
double code(double x, double y) {
double tmp;
if ((y <= -9500.0) || !(y <= 1.85)) {
tmp = -0.5 * y;
} else {
tmp = 0.918938533204673 - x;
}
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 <= (-9500.0d0)) .or. (.not. (y <= 1.85d0))) then
tmp = (-0.5d0) * y
else
tmp = 0.918938533204673d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -9500.0) || !(y <= 1.85)) {
tmp = -0.5 * y;
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9500.0) or not (y <= 1.85): tmp = -0.5 * y else: tmp = 0.918938533204673 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -9500.0) || !(y <= 1.85)) tmp = Float64(-0.5 * y); else tmp = Float64(0.918938533204673 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -9500.0) || ~((y <= 1.85))) tmp = -0.5 * y; else tmp = 0.918938533204673 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9500.0], N[Not[LessEqual[y, 1.85]], $MachinePrecision]], N[(-0.5 * y), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9500 \lor \neg \left(y \leq 1.85\right):\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\
\end{array}
\end{array}
if y < -9500 or 1.8500000000000001 < y Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
metadata-evalN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
Applied rewrites98.8%
Taylor expanded in x around 0
Applied rewrites47.4%
if -9500 < y < 1.8500000000000001Initial program 100.0%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6496.3
Applied rewrites96.3%
Final simplification71.5%
(FPCore (x y) :precision binary64 (if (<= y -9500.0) (* -0.5 y) (if (<= y 1.05) (- 0.918938533204673 x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -9500.0) {
tmp = -0.5 * y;
} else if (y <= 1.05) {
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 <= (-9500.0d0)) then
tmp = (-0.5d0) * y
else if (y <= 1.05d0) 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 <= -9500.0) {
tmp = -0.5 * y;
} else if (y <= 1.05) {
tmp = 0.918938533204673 - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9500.0: tmp = -0.5 * y elif y <= 1.05: tmp = 0.918938533204673 - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -9500.0) tmp = Float64(-0.5 * y); elseif (y <= 1.05) 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 <= -9500.0) tmp = -0.5 * y; elseif (y <= 1.05) tmp = 0.918938533204673 - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9500.0], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 1.05], N[(0.918938533204673 - x), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9500:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;y \leq 1.05:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -9500Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
metadata-evalN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites51.1%
if -9500 < y < 1.05000000000000004Initial program 100.0%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6496.3
Applied rewrites96.3%
if 1.05000000000000004 < y Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-commutativeN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
mul-1-negN/A
metadata-evalN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-outN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
Applied rewrites98.2%
Taylor expanded in x around inf
Applied rewrites54.1%
(FPCore (x y) :precision binary64 (if (or (<= x -175.0) (not (<= x 3.1e-30))) (- x) 0.918938533204673))
double code(double x, double y) {
double tmp;
if ((x <= -175.0) || !(x <= 3.1e-30)) {
tmp = -x;
} else {
tmp = 0.918938533204673;
}
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 <= (-175.0d0)) .or. (.not. (x <= 3.1d-30))) then
tmp = -x
else
tmp = 0.918938533204673d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -175.0) || !(x <= 3.1e-30)) {
tmp = -x;
} else {
tmp = 0.918938533204673;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -175.0) or not (x <= 3.1e-30): tmp = -x else: tmp = 0.918938533204673 return tmp
function code(x, y) tmp = 0.0 if ((x <= -175.0) || !(x <= 3.1e-30)) tmp = Float64(-x); else tmp = 0.918938533204673; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -175.0) || ~((x <= 3.1e-30))) tmp = -x; else tmp = 0.918938533204673; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -175.0], N[Not[LessEqual[x, 3.1e-30]], $MachinePrecision]], (-x), 0.918938533204673]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -175 \lor \neg \left(x \leq 3.1 \cdot 10^{-30}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673\\
\end{array}
\end{array}
if x < -175 or 3.09999999999999991e-30 < x Initial program 100.0%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6447.2
Applied rewrites47.2%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6446.5
Applied rewrites46.5%
if -175 < x < 3.09999999999999991e-30Initial program 100.0%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6451.1
Applied rewrites51.1%
Taylor expanded in x around 0
Applied rewrites51.1%
Final simplification48.6%
(FPCore (x y) :precision binary64 (fma (- x 0.5) y (- 0.918938533204673 x)))
double code(double x, double y) {
return fma((x - 0.5), y, (0.918938533204673 - x));
}
function code(x, y) return fma(Float64(x - 0.5), y, Float64(0.918938533204673 - x)) end
code[x_, y_] := N[(N[(x - 0.5), $MachinePrecision] * y + N[(0.918938533204673 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - 0.5, y, 0.918938533204673 - x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
(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%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6449.1
Applied rewrites49.1%
(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 y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6449.1
Applied rewrites49.1%
Taylor expanded in x around 0
Applied rewrites25.8%
herbie shell --seed 2025026
(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))