
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 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 = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 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 = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= x -5.1e+91) (not (<= x 110000000.0))) (- 1.0 (/ (- 1.0 x) y)) (/ (fma (/ x y) x x) (- x -1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -5.1e+91) || !(x <= 110000000.0)) {
tmp = 1.0 - ((1.0 - x) / y);
} else {
tmp = fma((x / y), x, x) / (x - -1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -5.1e+91) || !(x <= 110000000.0)) tmp = Float64(1.0 - Float64(Float64(1.0 - x) / y)); else tmp = Float64(fma(Float64(x / y), x, x) / Float64(x - -1.0)); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -5.1e+91], N[Not[LessEqual[x, 110000000.0]], $MachinePrecision]], N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.1 \cdot 10^{+91} \lor \neg \left(x \leq 110000000\right):\\
\;\;\;\;1 - \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x - -1}\\
\end{array}
\end{array}
if x < -5.10000000000000013e91 or 1.1e8 < x Initial program 72.5%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6477.8
Applied rewrites77.8%
Taylor expanded in y around inf
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -5.10000000000000013e91 < x < 1.1e8Initial program 99.9%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lift-/.f6499.9
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x x) (fma y x y)))
(t_1 (/ (* x (+ (/ x y) 1.0)) (- x -1.0)))
(t_2 (/ (- x 1.0) y)))
(if (<= t_1 -1e+154)
t_2
(if (<= t_1 -20000000000000.0)
t_0
(if (<= t_1 1e+20) (/ x (- x -1.0)) (if (<= t_1 4e+172) t_0 t_2))))))
double code(double x, double y) {
double t_0 = (x * x) / fma(y, x, y);
double t_1 = (x * ((x / y) + 1.0)) / (x - -1.0);
double t_2 = (x - 1.0) / y;
double tmp;
if (t_1 <= -1e+154) {
tmp = t_2;
} else if (t_1 <= -20000000000000.0) {
tmp = t_0;
} else if (t_1 <= 1e+20) {
tmp = x / (x - -1.0);
} else if (t_1 <= 4e+172) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * x) / fma(y, x, y)) t_1 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x - -1.0)) t_2 = Float64(Float64(x - 1.0) / y) tmp = 0.0 if (t_1 <= -1e+154) tmp = t_2; elseif (t_1 <= -20000000000000.0) tmp = t_0; elseif (t_1 <= 1e+20) tmp = Float64(x / Float64(x - -1.0)); elseif (t_1 <= 4e+172) tmp = t_0; else tmp = t_2; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] / N[(y * x + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+154], t$95$2, If[LessEqual[t$95$1, -20000000000000.0], t$95$0, If[LessEqual[t$95$1, 1e+20], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e+172], t$95$0, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot x}{\mathsf{fma}\left(y, x, y\right)}\\
t_1 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x - -1}\\
t_2 := \frac{x - 1}{y}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+154}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq -20000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 10^{+20}:\\
\;\;\;\;\frac{x}{x - -1}\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+172}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1.00000000000000004e154 or 4.0000000000000003e172 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 65.1%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6488.7
Applied rewrites88.7%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
sub-divN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -1.00000000000000004e154 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2e13 or 1e20 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 4.0000000000000003e172Initial program 99.6%
Taylor expanded in y around 0
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6483.9
Applied rewrites83.9%
if -2e13 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 1e20Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites85.2%
Final simplification89.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (- x -1.0))))
(if (<= t_0 -1e+154)
(/ (- x 1.0) y)
(if (or (<= t_0 -20000000000000.0) (not (<= t_0 1e+20)))
(* x (/ x (fma y x y)))
(/ x (- x -1.0))))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x - -1.0);
double tmp;
if (t_0 <= -1e+154) {
tmp = (x - 1.0) / y;
} else if ((t_0 <= -20000000000000.0) || !(t_0 <= 1e+20)) {
tmp = x * (x / fma(y, x, y));
} else {
tmp = x / (x - -1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x - -1.0)) tmp = 0.0 if (t_0 <= -1e+154) tmp = Float64(Float64(x - 1.0) / y); elseif ((t_0 <= -20000000000000.0) || !(t_0 <= 1e+20)) tmp = Float64(x * Float64(x / fma(y, x, y))); else tmp = Float64(x / Float64(x - -1.0)); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+154], N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision], If[Or[LessEqual[t$95$0, -20000000000000.0], N[Not[LessEqual[t$95$0, 1e+20]], $MachinePrecision]], N[(x * N[(x / N[(y * x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x - -1}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\frac{x - 1}{y}\\
\mathbf{elif}\;t\_0 \leq -20000000000000 \lor \neg \left(t\_0 \leq 10^{+20}\right):\\
\;\;\;\;x \cdot \frac{x}{\mathsf{fma}\left(y, x, y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x - -1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1.00000000000000004e154Initial program 59.5%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6487.0
Applied rewrites87.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
sub-divN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
if -1.00000000000000004e154 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2e13 or 1e20 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 88.0%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
*-rgt-identityN/A
associate-*r/N/A
rgt-mult-inverseN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*l*N/A
unpow2N/A
frac-addN/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6466.7
Applied rewrites66.7%
Taylor expanded in y around 0
pow2N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
*-commutativeN/A
+-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lift-fma.f6490.8
Applied rewrites90.8%
if -2e13 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 1e20Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites85.2%
Final simplification89.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (- x -1.0))) (t_1 (/ (- x 1.0) y)))
(if (<= t_0 -20000000000000.0)
t_1
(if (<= t_0 0.001) x (if (<= t_0 2.0) 1.0 t_1)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x - -1.0);
double t_1 = (x - 1.0) / y;
double tmp;
if (t_0 <= -20000000000000.0) {
tmp = t_1;
} else if (t_0 <= 0.001) {
tmp = x;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = (x * ((x / y) + 1.0d0)) / (x - (-1.0d0))
t_1 = (x - 1.0d0) / y
if (t_0 <= (-20000000000000.0d0)) then
tmp = t_1
else if (t_0 <= 0.001d0) then
tmp = x
else if (t_0 <= 2.0d0) then
tmp = 1.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x - -1.0);
double t_1 = (x - 1.0) / y;
double tmp;
if (t_0 <= -20000000000000.0) {
tmp = t_1;
} else if (t_0 <= 0.001) {
tmp = x;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x - -1.0) t_1 = (x - 1.0) / y tmp = 0 if t_0 <= -20000000000000.0: tmp = t_1 elif t_0 <= 0.001: tmp = x elif t_0 <= 2.0: tmp = 1.0 else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x - -1.0)) t_1 = Float64(Float64(x - 1.0) / y) tmp = 0.0 if (t_0 <= -20000000000000.0) tmp = t_1; elseif (t_0 <= 0.001) tmp = x; elseif (t_0 <= 2.0) tmp = 1.0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (x * ((x / y) + 1.0)) / (x - -1.0); t_1 = (x - 1.0) / y; tmp = 0.0; if (t_0 <= -20000000000000.0) tmp = t_1; elseif (t_0 <= 0.001) tmp = x; elseif (t_0 <= 2.0) tmp = 1.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, -20000000000000.0], t$95$1, If[LessEqual[t$95$0, 0.001], x, If[LessEqual[t$95$0, 2.0], 1.0, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x - -1}\\
t_1 := \frac{x - 1}{y}\\
\mathbf{if}\;t\_0 \leq -20000000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.001:\\
\;\;\;\;x\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2e13 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 77.7%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower--.f6485.7
Applied rewrites85.7%
Taylor expanded in x around 0
sub-divN/A
lower-/.f64N/A
lower--.f6485.7
Applied rewrites85.7%
if -2e13 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 1e-3Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites81.1%
if 1e-3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 100.0%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6447.2
Applied rewrites47.2%
Taylor expanded in y around inf
Applied rewrites98.9%
Final simplification84.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (- x -1.0))))
(if (<= t_0 -20000000000000.0)
(/ x y)
(if (<= t_0 0.001) x (if (<= t_0 2.0) 1.0 (/ x y))))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x - -1.0);
double tmp;
if (t_0 <= -20000000000000.0) {
tmp = x / y;
} else if (t_0 <= 0.001) {
tmp = x;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} 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) :: t_0
real(8) :: tmp
t_0 = (x * ((x / y) + 1.0d0)) / (x - (-1.0d0))
if (t_0 <= (-20000000000000.0d0)) then
tmp = x / y
else if (t_0 <= 0.001d0) then
tmp = x
else if (t_0 <= 2.0d0) then
tmp = 1.0d0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x - -1.0);
double tmp;
if (t_0 <= -20000000000000.0) {
tmp = x / y;
} else if (t_0 <= 0.001) {
tmp = x;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x - -1.0) tmp = 0 if t_0 <= -20000000000000.0: tmp = x / y elif t_0 <= 0.001: tmp = x elif t_0 <= 2.0: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x - -1.0)) tmp = 0.0 if (t_0 <= -20000000000000.0) tmp = Float64(x / y); elseif (t_0 <= 0.001) tmp = x; elseif (t_0 <= 2.0) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) t_0 = (x * ((x / y) + 1.0)) / (x - -1.0); tmp = 0.0; if (t_0 <= -20000000000000.0) tmp = x / y; elseif (t_0 <= 0.001) tmp = x; elseif (t_0 <= 2.0) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -20000000000000.0], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 0.001], x, If[LessEqual[t$95$0, 2.0], 1.0, N[(x / y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x - -1}\\
\mathbf{if}\;t\_0 \leq -20000000000000:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 0.001:\\
\;\;\;\;x\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2e13 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 77.7%
Taylor expanded in x around inf
lift-/.f6485.0
Applied rewrites85.0%
if -2e13 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 1e-3Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites81.1%
if 1e-3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 100.0%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6447.2
Applied rewrites47.2%
Taylor expanded in y around inf
Applied rewrites98.9%
Final simplification84.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (- x -1.0))))
(if (or (<= t_0 -20000000000000.0) (not (<= t_0 2.0)))
(/ (- x 1.0) y)
(/ x (- x -1.0)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x - -1.0);
double tmp;
if ((t_0 <= -20000000000000.0) || !(t_0 <= 2.0)) {
tmp = (x - 1.0) / y;
} else {
tmp = x / (x - -1.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 = (x * ((x / y) + 1.0d0)) / (x - (-1.0d0))
if ((t_0 <= (-20000000000000.0d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = (x - 1.0d0) / y
else
tmp = x / (x - (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x - -1.0);
double tmp;
if ((t_0 <= -20000000000000.0) || !(t_0 <= 2.0)) {
tmp = (x - 1.0) / y;
} else {
tmp = x / (x - -1.0);
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x - -1.0) tmp = 0 if (t_0 <= -20000000000000.0) or not (t_0 <= 2.0): tmp = (x - 1.0) / y else: tmp = x / (x - -1.0) return tmp
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x - -1.0)) tmp = 0.0 if ((t_0 <= -20000000000000.0) || !(t_0 <= 2.0)) tmp = Float64(Float64(x - 1.0) / y); else tmp = Float64(x / Float64(x - -1.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x * ((x / y) + 1.0)) / (x - -1.0); tmp = 0.0; if ((t_0 <= -20000000000000.0) || ~((t_0 <= 2.0))) tmp = (x - 1.0) / y; else tmp = x / (x - -1.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -20000000000000.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x - -1}\\
\mathbf{if}\;t\_0 \leq -20000000000000 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\frac{x - 1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x - -1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2e13 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 77.7%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower--.f6485.7
Applied rewrites85.7%
Taylor expanded in x around 0
sub-divN/A
lower-/.f64N/A
lower--.f6485.7
Applied rewrites85.7%
if -2e13 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites85.8%
Final simplification85.8%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.25))) (- 1.0 (/ (- 1.0 x) y)) (/ (fma (/ x y) x x) 1.0)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.25)) {
tmp = 1.0 - ((1.0 - x) / y);
} else {
tmp = fma((x / y), x, x) / 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.25)) tmp = Float64(1.0 - Float64(Float64(1.0 - x) / y)); else tmp = Float64(fma(Float64(x / y), x, x) / 1.0); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.25]], $MachinePrecision]], N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1.25\right):\\
\;\;\;\;1 - \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{1}\\
\end{array}
\end{array}
if x < -1 or 1.25 < x Initial program 78.5%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6480.2
Applied rewrites80.2%
Taylor expanded in y around inf
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6499.9
Applied rewrites99.9%
if -1 < x < 1.25Initial program 99.8%
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lift-/.f6499.9
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites96.8%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= (/ (* x (+ (/ x y) 1.0)) (- x -1.0)) 0.001) x 1.0))
double code(double x, double y) {
double tmp;
if (((x * ((x / y) + 1.0)) / (x - -1.0)) <= 0.001) {
tmp = x;
} else {
tmp = 1.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) :: tmp
if (((x * ((x / y) + 1.0d0)) / (x - (-1.0d0))) <= 0.001d0) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x * ((x / y) + 1.0)) / (x - -1.0)) <= 0.001) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * ((x / y) + 1.0)) / (x - -1.0)) <= 0.001: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x - -1.0)) <= 0.001) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * ((x / y) + 1.0)) / (x - -1.0)) <= 0.001) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], 0.001], x, 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x - -1} \leq 0.001:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 1e-3Initial program 89.4%
Taylor expanded in x around 0
Applied rewrites50.4%
if 1e-3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 88.0%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6468.2
Applied rewrites68.2%
Taylor expanded in y around inf
Applied rewrites31.3%
Final simplification44.6%
(FPCore (x y) :precision binary64 (if (or (<= x -31000.0) (not (<= x 1.15))) (- 1.0 (/ (- 1.0 x) y)) (/ x (- x -1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -31000.0) || !(x <= 1.15)) {
tmp = 1.0 - ((1.0 - x) / y);
} else {
tmp = x / (x - -1.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) :: tmp
if ((x <= (-31000.0d0)) .or. (.not. (x <= 1.15d0))) then
tmp = 1.0d0 - ((1.0d0 - x) / y)
else
tmp = x / (x - (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -31000.0) || !(x <= 1.15)) {
tmp = 1.0 - ((1.0 - x) / y);
} else {
tmp = x / (x - -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -31000.0) or not (x <= 1.15): tmp = 1.0 - ((1.0 - x) / y) else: tmp = x / (x - -1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -31000.0) || !(x <= 1.15)) tmp = Float64(1.0 - Float64(Float64(1.0 - x) / y)); else tmp = Float64(x / Float64(x - -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -31000.0) || ~((x <= 1.15))) tmp = 1.0 - ((1.0 - x) / y); else tmp = x / (x - -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -31000.0], N[Not[LessEqual[x, 1.15]], $MachinePrecision]], N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -31000 \lor \neg \left(x \leq 1.15\right):\\
\;\;\;\;1 - \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x - -1}\\
\end{array}
\end{array}
if x < -31000 or 1.1499999999999999 < x Initial program 78.6%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
frac-addN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-lft-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6479.7
Applied rewrites79.7%
Taylor expanded in y around inf
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
lower--.f6499.3
Applied rewrites99.3%
if -31000 < x < 1.1499999999999999Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites72.3%
Final simplification86.1%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return 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 = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 89.0%
Taylor expanded in x around 0
Applied rewrites36.0%
(FPCore (x y) :precision binary64 (* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0))))
double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 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 = (x / 1.0d0) * (((x / y) + 1.0d0) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
def code(x, y): return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0))
function code(x, y) return Float64(Float64(x / 1.0) * Float64(Float64(Float64(x / y) + 1.0) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = (x / 1.0) * (((x / y) + 1.0) / (x + 1.0)); end
code[x_, y_] := N[(N[(x / 1.0), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}
herbie shell --seed 2025051
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(! :herbie-platform default (* (/ x 1) (/ (+ (/ x y) 1) (+ x 1))))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))