
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - 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) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - 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) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - 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) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
Initial program 100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) (- 1.0 y))) (t_1 (/ x (- 1.0 y))))
(if (<= t_0 -2e+15)
t_1
(if (<= t_0 2e-13)
(fma -1.0 y x)
(if (<= t_0 2.0) (/ (- y) (- 1.0 y)) t_1)))))
double code(double x, double y) {
double t_0 = (x - y) / (1.0 - y);
double t_1 = x / (1.0 - y);
double tmp;
if (t_0 <= -2e+15) {
tmp = t_1;
} else if (t_0 <= 2e-13) {
tmp = fma(-1.0, y, x);
} else if (t_0 <= 2.0) {
tmp = -y / (1.0 - y);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(1.0 - y)) t_1 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (t_0 <= -2e+15) tmp = t_1; elseif (t_0 <= 2e-13) tmp = fma(-1.0, y, x); elseif (t_0 <= 2.0) tmp = Float64(Float64(-y) / Float64(1.0 - y)); else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+15], t$95$1, If[LessEqual[t$95$0, 2e-13], N[(-1.0 * y + x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[((-y) / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{1 - y}\\
t_1 := \frac{x}{1 - y}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+15}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(-1, y, x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{-y}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < -2e15 or 2 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites99.5%
if -2e15 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 2.0000000000000001e-13Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower--.f6499.3
Applied rewrites99.3%
Taylor expanded in x around 0
Applied rewrites99.3%
if 2.0000000000000001e-13 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 2Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) (- 1.0 y))) (t_1 (/ x (- 1.0 y))))
(if (<= t_0 -2e+15)
t_1
(if (<= t_0 0.01) (fma -1.0 y x) (if (<= t_0 2.0) 1.0 t_1)))))
double code(double x, double y) {
double t_0 = (x - y) / (1.0 - y);
double t_1 = x / (1.0 - y);
double tmp;
if (t_0 <= -2e+15) {
tmp = t_1;
} else if (t_0 <= 0.01) {
tmp = fma(-1.0, y, x);
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(1.0 - y)) t_1 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (t_0 <= -2e+15) tmp = t_1; elseif (t_0 <= 0.01) tmp = fma(-1.0, y, x); elseif (t_0 <= 2.0) tmp = 1.0; else tmp = t_1; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+15], t$95$1, If[LessEqual[t$95$0, 0.01], N[(-1.0 * y + x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], 1.0, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{1 - y}\\
t_1 := \frac{x}{1 - y}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+15}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.01:\\
\;\;\;\;\mathsf{fma}\left(-1, y, x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < -2e15 or 2 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites99.5%
if -2e15 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 0.0100000000000000002Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower--.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites98.1%
if 0.0100000000000000002 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 2Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites99.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) (- 1.0 y))))
(if (<= t_0 -5e-109)
x
(if (<= t_0 0.01) (- y) (if (<= t_0 10000000.0) 1.0 x)))))
double code(double x, double y) {
double t_0 = (x - y) / (1.0 - y);
double tmp;
if (t_0 <= -5e-109) {
tmp = x;
} else if (t_0 <= 0.01) {
tmp = -y;
} else if (t_0 <= 10000000.0) {
tmp = 1.0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = (x - y) / (1.0d0 - y)
if (t_0 <= (-5d-109)) then
tmp = x
else if (t_0 <= 0.01d0) then
tmp = -y
else if (t_0 <= 10000000.0d0) then
tmp = 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / (1.0 - y);
double tmp;
if (t_0 <= -5e-109) {
tmp = x;
} else if (t_0 <= 0.01) {
tmp = -y;
} else if (t_0 <= 10000000.0) {
tmp = 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / (1.0 - y) tmp = 0 if t_0 <= -5e-109: tmp = x elif t_0 <= 0.01: tmp = -y elif t_0 <= 10000000.0: tmp = 1.0 else: tmp = x return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(1.0 - y)) tmp = 0.0 if (t_0 <= -5e-109) tmp = x; elseif (t_0 <= 0.01) tmp = Float64(-y); elseif (t_0 <= 10000000.0) tmp = 1.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / (1.0 - y); tmp = 0.0; if (t_0 <= -5e-109) tmp = x; elseif (t_0 <= 0.01) tmp = -y; elseif (t_0 <= 10000000.0) tmp = 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-109], x, If[LessEqual[t$95$0, 0.01], (-y), If[LessEqual[t$95$0, 10000000.0], 1.0, x]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{1 - y}\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-109}:\\
\;\;\;\;x\\
\mathbf{elif}\;t\_0 \leq 0.01:\\
\;\;\;\;-y\\
\mathbf{elif}\;t\_0 \leq 10000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < -5.0000000000000002e-109 or 1e7 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites59.7%
if -5.0000000000000002e-109 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 0.0100000000000000002Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower--.f6497.8
Applied rewrites97.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6462.2
Applied rewrites62.2%
if 0.0100000000000000002 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 1e7Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites98.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (- x y) (- 1.0 y)))) (if (<= t_0 2e-37) x (if (<= t_0 10000000.0) 1.0 x))))
double code(double x, double y) {
double t_0 = (x - y) / (1.0 - y);
double tmp;
if (t_0 <= 2e-37) {
tmp = x;
} else if (t_0 <= 10000000.0) {
tmp = 1.0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = (x - y) / (1.0d0 - y)
if (t_0 <= 2d-37) then
tmp = x
else if (t_0 <= 10000000.0d0) then
tmp = 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / (1.0 - y);
double tmp;
if (t_0 <= 2e-37) {
tmp = x;
} else if (t_0 <= 10000000.0) {
tmp = 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / (1.0 - y) tmp = 0 if t_0 <= 2e-37: tmp = x elif t_0 <= 10000000.0: tmp = 1.0 else: tmp = x return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / Float64(1.0 - y)) tmp = 0.0 if (t_0 <= 2e-37) tmp = x; elseif (t_0 <= 10000000.0) tmp = 1.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / (1.0 - y); tmp = 0.0; if (t_0 <= 2e-37) tmp = x; elseif (t_0 <= 10000000.0) tmp = 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-37], x, If[LessEqual[t$95$0, 10000000.0], 1.0, x]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{1 - y}\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{-37}:\\
\;\;\;\;x\\
\mathbf{elif}\;t\_0 \leq 10000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 2.00000000000000013e-37 or 1e7 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites54.6%
if 2.00000000000000013e-37 < (/.f64 (-.f64 x y) (-.f64 #s(literal 1 binary64) y)) < 1e7Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites93.5%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1.0) (fma (- x 1.0) y x) (if (<= y 7e+85) (/ x (- y)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = fma((x - 1.0), y, x);
} else if (y <= 7e+85) {
tmp = x / -y;
} else {
tmp = 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1.0) tmp = fma(Float64(x - 1.0), y, x); elseif (y <= 7e+85) tmp = Float64(x / Float64(-y)); else tmp = 1.0; end return tmp end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.0], N[(N[(x - 1.0), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[y, 7e+85], N[(x / (-y)), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(x - 1, y, x\right)\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+85}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 7.0000000000000001e85 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites76.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower--.f6498.7
Applied rewrites98.7%
if 1 < y < 7.0000000000000001e85Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites64.4%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6456.6
Applied rewrites56.6%
(FPCore (x y) :precision binary64 (if (or (<= y -0.82) (not (<= y 1.0))) (/ (- x y) (- y)) (fma (- x 1.0) y x)))
double code(double x, double y) {
double tmp;
if ((y <= -0.82) || !(y <= 1.0)) {
tmp = (x - y) / -y;
} else {
tmp = fma((x - 1.0), y, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -0.82) || !(y <= 1.0)) tmp = Float64(Float64(x - y) / Float64(-y)); else tmp = fma(Float64(x - 1.0), y, x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -0.82], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / (-y)), $MachinePrecision], N[(N[(x - 1.0), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.82 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{x - y}{-y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 1, y, x\right)\\
\end{array}
\end{array}
if y < -0.819999999999999951 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6497.6
Applied rewrites97.6%
if -0.819999999999999951 < y < 1Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower--.f6498.7
Applied rewrites98.7%
Final simplification98.2%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1.0) (fma (- x 1.0) y x) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = fma((x - 1.0), y, x);
} else {
tmp = 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1.0) tmp = fma(Float64(x - 1.0), y, x); else tmp = 1.0; end return tmp end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.0], N[(N[(x - 1.0), $MachinePrecision] * y + x), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(x - 1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites69.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower--.f6498.7
Applied rewrites98.7%
(FPCore (x y) :precision binary64 (if (<= y -33000000000000.0) 1.0 (if (<= y 1.0) (fma -1.0 y x) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -33000000000000.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = fma(-1.0, y, x);
} else {
tmp = 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -33000000000000.0) tmp = 1.0; elseif (y <= 1.0) tmp = fma(-1.0, y, x); else tmp = 1.0; end return tmp end
code[x_, y_] := If[LessEqual[y, -33000000000000.0], 1.0, If[LessEqual[y, 1.0], N[(-1.0 * y + x), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -33000000000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(-1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.3e13 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites70.9%
if -3.3e13 < y < 1Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-lft-neg-inN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower--.f6497.2
Applied rewrites97.2%
Taylor expanded in x around 0
Applied rewrites96.7%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
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 = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites37.8%
herbie shell --seed 2025054
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))