
(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 11 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 (* (- (/ x y) -1.0) (/ x (- x -1.0))))
double code(double x, double y) {
return ((x / y) - -1.0) * (x / (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 / y) - (-1.0d0)) * (x / (x - (-1.0d0)))
end function
public static double code(double x, double y) {
return ((x / y) - -1.0) * (x / (x - -1.0));
}
def code(x, y): return ((x / y) - -1.0) * (x / (x - -1.0))
function code(x, y) return Float64(Float64(Float64(x / y) - -1.0) * Float64(x / Float64(x - -1.0))) end
function tmp = code(x, y) tmp = ((x / y) - -1.0) * (x / (x - -1.0)); end
code[x_, y_] := N[(N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision] * N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{y} - -1\right) \cdot \frac{x}{x - -1}
\end{array}
Initial program 89.7%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f6499.9
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (- (/ x y) -1.0)) (- x -1.0))))
(if (<= t_0 -40.0)
(* (/ x (fma y x y)) x)
(if (<= t_0 0.02)
(fma (- (/ x y) x) x x)
(if (<= t_0 2.0) (/ x (- x -1.0)) (* (/ 1.0 y) x))))))
double code(double x, double y) {
double t_0 = (x * ((x / y) - -1.0)) / (x - -1.0);
double tmp;
if (t_0 <= -40.0) {
tmp = (x / fma(y, x, y)) * x;
} else if (t_0 <= 0.02) {
tmp = fma(((x / y) - x), x, x);
} else if (t_0 <= 2.0) {
tmp = x / (x - -1.0);
} else {
tmp = (1.0 / y) * x;
}
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 <= -40.0) tmp = Float64(Float64(x / fma(y, x, y)) * x); elseif (t_0 <= 0.02) tmp = fma(Float64(Float64(x / y) - x), x, x); elseif (t_0 <= 2.0) tmp = Float64(x / Float64(x - -1.0)); else tmp = Float64(Float64(1.0 / y) * x); 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, -40.0], N[(N[(x / N[(y * x + y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 0.02], N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] * x + x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / y), $MachinePrecision] * x), $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 -40:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(y, x, y\right)} \cdot x\\
\mathbf{elif}\;t\_0 \leq 0.02:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y} - x, x, x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{x - -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y} \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -40Initial program 71.9%
Taylor expanded in y around 0
unpow2N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6492.1
Applied rewrites92.1%
if -40 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.0200000000000000004Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
Applied rewrites99.0%
if 0.0200000000000000004 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6497.4
Applied rewrites97.4%
if 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 71.1%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f64100.0
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6470.5
Applied rewrites70.5%
Applied rewrites89.8%
Taylor expanded in x around inf
Applied rewrites90.5%
Final simplification96.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (- (/ x y) -1.0)) (- x -1.0))) (t_1 (* (/ 1.0 y) x)))
(if (<= t_0 -40.0)
t_1
(if (<= t_0 0.02)
(fma (- (/ x y) x) x x)
(if (<= t_0 2.0) (/ x (- x -1.0)) t_1)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) - -1.0)) / (x - -1.0);
double t_1 = (1.0 / y) * x;
double tmp;
if (t_0 <= -40.0) {
tmp = t_1;
} else if (t_0 <= 0.02) {
tmp = fma(((x / y) - x), x, x);
} else if (t_0 <= 2.0) {
tmp = x / (x - -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(1.0 / y) * x) tmp = 0.0 if (t_0 <= -40.0) tmp = t_1; elseif (t_0 <= 0.02) tmp = fma(Float64(Float64(x / y) - x), x, x); elseif (t_0 <= 2.0) tmp = Float64(x / Float64(x - -1.0)); else tmp = t_1; 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]}, Block[{t$95$1 = N[(N[(1.0 / y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -40.0], t$95$1, If[LessEqual[t$95$0, 0.02], N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] * x + x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], 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{1}{y} \cdot x\\
\mathbf{if}\;t\_0 \leq -40:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.02:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y} - x, x, x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{x - -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))) < -40 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 71.6%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f6499.9
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6472.0
Applied rewrites72.0%
Applied rewrites92.2%
Taylor expanded in x around inf
Applied rewrites89.4%
if -40 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.0200000000000000004Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
Applied rewrites99.0%
if 0.0200000000000000004 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6497.4
Applied rewrites97.4%
Final simplification95.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (- (/ x y) -1.0)) (- x -1.0))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 2e+208)))
(* (/ 1.0 y) x)
(/ (fma (/ x y) x 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 <= -((double) INFINITY)) || !(t_0 <= 2e+208)) {
tmp = (1.0 / y) * x;
} else {
tmp = fma((x / y), x, 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 <= Float64(-Inf)) || !(t_0 <= 2e+208)) tmp = Float64(Float64(1.0 / y) * x); else tmp = Float64(fma(Float64(x / y), x, 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[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 2e+208]], $MachinePrecision]], N[(N[(1.0 / y), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / 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 -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{+208}\right):\\
\;\;\;\;\frac{1}{y} \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x - -1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -inf.0 or 2e208 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 51.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f64100.0
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6463.4
Applied rewrites63.4%
Applied rewrites92.5%
Taylor expanded in x around inf
Applied rewrites99.7%
if -inf.0 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2e208Initial program 99.8%
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6499.8
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval99.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (- (/ x y) -1.0)) (- x -1.0))))
(if (or (<= t_0 -40.0) (not (<= t_0 2.0)))
(* (/ 1.0 y) x)
(/ 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 <= -40.0) || !(t_0 <= 2.0)) {
tmp = (1.0 / y) * x;
} 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 <= (-40.0d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = (1.0d0 / y) * x
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 <= -40.0) || !(t_0 <= 2.0)) {
tmp = (1.0 / y) * x;
} 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 <= -40.0) or not (t_0 <= 2.0): tmp = (1.0 / y) * x 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 <= -40.0) || !(t_0 <= 2.0)) tmp = Float64(Float64(1.0 / y) * x); 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 <= -40.0) || ~((t_0 <= 2.0))) tmp = (1.0 / y) * x; 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, -40.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(N[(1.0 / y), $MachinePrecision] * x), $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 -40 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\frac{1}{y} \cdot x\\
\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))) < -40 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 71.6%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f6499.9
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6472.0
Applied rewrites72.0%
Applied rewrites92.2%
Taylor expanded in x around inf
Applied rewrites89.4%
if -40 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6488.3
Applied rewrites88.3%
Final simplification88.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (- (/ x y) -1.0)) (- x -1.0))))
(if (<= t_0 0.9999999)
(* (/ (+ y x) (fma y x y)) x)
(if (<= t_0 2.0) (/ x (- x -1.0)) (* (/ 1.0 y) x)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) - -1.0)) / (x - -1.0);
double tmp;
if (t_0 <= 0.9999999) {
tmp = ((y + x) / fma(y, x, y)) * x;
} else if (t_0 <= 2.0) {
tmp = x / (x - -1.0);
} else {
tmp = (1.0 / y) * x;
}
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 <= 0.9999999) tmp = Float64(Float64(Float64(y + x) / fma(y, x, y)) * x); elseif (t_0 <= 2.0) tmp = Float64(x / Float64(x - -1.0)); else tmp = Float64(Float64(1.0 / y) * x); 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, 0.9999999], N[(N[(N[(y + x), $MachinePrecision] / N[(y * x + y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / y), $MachinePrecision] * x), $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 0.9999999:\\
\;\;\;\;\frac{y + x}{\mathsf{fma}\left(y, x, y\right)} \cdot x\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{x - -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y} \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.999999900000000053Initial program 91.7%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f6499.9
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6477.9
Applied rewrites77.9%
Applied rewrites98.1%
if 0.999999900000000053 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6498.5
Applied rewrites98.5%
if 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 71.1%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f64100.0
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6470.5
Applied rewrites70.5%
Applied rewrites89.8%
Taylor expanded in x around inf
Applied rewrites90.5%
Final simplification97.0%
(FPCore (x y) :precision binary64 (if (<= (/ (* x (- (/ x y) -1.0)) (- x -1.0)) -40.0) (* (- 1.0 x) x) (/ x (- x -1.0))))
double code(double x, double y) {
double tmp;
if (((x * ((x / y) - -1.0)) / (x - -1.0)) <= -40.0) {
tmp = (1.0 - x) * x;
} 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 * ((x / y) - (-1.0d0))) / (x - (-1.0d0))) <= (-40.0d0)) then
tmp = (1.0d0 - x) * x
else
tmp = x / (x - (-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)) <= -40.0) {
tmp = (1.0 - x) * x;
} else {
tmp = x / (x - -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * ((x / y) - -1.0)) / (x - -1.0)) <= -40.0: tmp = (1.0 - x) * x else: tmp = x / (x - -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)) <= -40.0) tmp = Float64(Float64(1.0 - x) * x); else tmp = Float64(x / Float64(x - -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * ((x / y) - -1.0)) / (x - -1.0)) <= -40.0) tmp = (1.0 - x) * x; else tmp = x / (x - -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], -40.0], N[(N[(1.0 - x), $MachinePrecision] * x), $MachinePrecision], N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\frac{x}{y} - -1\right)}{x - -1} \leq -40:\\
\;\;\;\;\left(1 - x\right) \cdot x\\
\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))) < -40Initial program 71.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6422.0
Applied rewrites22.0%
Taylor expanded in y around inf
Applied rewrites27.1%
if -40 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 94.4%
Taylor expanded in y around inf
lower-/.f64N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6472.3
Applied rewrites72.3%
Final simplification62.9%
(FPCore (x y) :precision binary64 (if (<= (/ (* x (- (/ x y) -1.0)) (- x -1.0)) 0.4) (* (- 1.0 x) x) (- 1.0 (/ 1.0 x))))
double code(double x, double y) {
double tmp;
if (((x * ((x / y) - -1.0)) / (x - -1.0)) <= 0.4) {
tmp = (1.0 - x) * x;
} else {
tmp = 1.0 - (1.0 / 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 (((x * ((x / y) - (-1.0d0))) / (x - (-1.0d0))) <= 0.4d0) then
tmp = (1.0d0 - x) * x
else
tmp = 1.0d0 - (1.0d0 / x)
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.4) {
tmp = (1.0 - x) * x;
} else {
tmp = 1.0 - (1.0 / x);
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * ((x / y) - -1.0)) / (x - -1.0)) <= 0.4: tmp = (1.0 - x) * x else: tmp = 1.0 - (1.0 / x) return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x * Float64(Float64(x / y) - -1.0)) / Float64(x - -1.0)) <= 0.4) tmp = Float64(Float64(1.0 - x) * x); else tmp = Float64(1.0 - Float64(1.0 / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * ((x / y) - -1.0)) / (x - -1.0)) <= 0.4) tmp = (1.0 - x) * x; else tmp = 1.0 - (1.0 / x); 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.4], N[(N[(1.0 - x), $MachinePrecision] * x), $MachinePrecision], N[(1.0 - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\frac{x}{y} - -1\right)}{x - -1} \leq 0.4:\\
\;\;\;\;\left(1 - x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{1}{x}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.40000000000000002Initial program 91.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
Taylor expanded in y around inf
Applied rewrites67.3%
if 0.40000000000000002 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 85.4%
Taylor expanded in y around inf
lower-/.f64N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6450.4
Applied rewrites50.4%
Taylor expanded in x around inf
Applied rewrites49.2%
Final simplification61.8%
(FPCore (x y) :precision binary64 (if (<= (/ (* x (- (/ x y) -1.0)) (- x -1.0)) -40.0) (* (- 1.0 x) x) (* (fma (- x 1.0) x 1.0) x)))
double code(double x, double y) {
double tmp;
if (((x * ((x / y) - -1.0)) / (x - -1.0)) <= -40.0) {
tmp = (1.0 - x) * x;
} else {
tmp = fma((x - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(x * Float64(Float64(x / y) - -1.0)) / Float64(x - -1.0)) <= -40.0) tmp = Float64(Float64(1.0 - x) * x); else tmp = Float64(fma(Float64(x - 1.0), x, 1.0) * x); end return 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], -40.0], N[(N[(1.0 - x), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(x - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\frac{x}{y} - -1\right)}{x - -1} \leq -40:\\
\;\;\;\;\left(1 - x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -40Initial program 71.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6422.0
Applied rewrites22.0%
Taylor expanded in y around inf
Applied rewrites27.1%
if -40 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 94.4%
Taylor expanded in y around inf
lower-/.f64N/A
rgt-mult-inverseN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
rgt-mult-inverseN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6472.3
Applied rewrites72.3%
Taylor expanded in x around inf
Applied rewrites19.7%
Taylor expanded in x around 0
Applied rewrites55.6%
Final simplification49.7%
(FPCore (x y) :precision binary64 (* (- 1.0 x) x))
double code(double x, double y) {
return (1.0 - x) * 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 = (1.0d0 - x) * x
end function
public static double code(double x, double y) {
return (1.0 - x) * x;
}
def code(x, y): return (1.0 - x) * x
function code(x, y) return Float64(Float64(1.0 - x) * x) end
function tmp = code(x, y) tmp = (1.0 - x) * x; end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot x
\end{array}
Initial program 89.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6456.1
Applied rewrites56.1%
Taylor expanded in y around inf
Applied rewrites47.3%
(FPCore (x y) :precision binary64 (* 1.0 x))
double code(double x, double y) {
return 1.0 * 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 = 1.0d0 * x
end function
public static double code(double x, double y) {
return 1.0 * x;
}
def code(x, y): return 1.0 * x
function code(x, y) return Float64(1.0 * x) end
function tmp = code(x, y) tmp = 1.0 * x; end
code[x_, y_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 89.7%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f6499.9
lift-+.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in y around 0
div-add-revN/A
associate-/l/N/A
*-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6474.4
Applied rewrites74.4%
Applied rewrites91.8%
Taylor expanded in x around 0
Applied rewrites42.8%
Final simplification42.8%
(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 2025017
(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)))