
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
(FPCore (x) :precision binary64 (if (<= (- (/ x (- x -1.0)) (/ (- x -1.0) (- x 1.0))) 0.0) (/ (+ (/ (fma (/ (- (pow x -1.0) -3.0) x) -1.0 -1.0) x) -3.0) x) (/ (fma 3.0 x 1.0) (- 1.0 (* x x)))))
double code(double x) {
double tmp;
if (((x / (x - -1.0)) - ((x - -1.0) / (x - 1.0))) <= 0.0) {
tmp = ((fma(((pow(x, -1.0) - -3.0) / x), -1.0, -1.0) / x) + -3.0) / x;
} else {
tmp = fma(3.0, x, 1.0) / (1.0 - (x * x));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x - -1.0)) - Float64(Float64(x - -1.0) / Float64(x - 1.0))) <= 0.0) tmp = Float64(Float64(Float64(fma(Float64(Float64((x ^ -1.0) - -3.0) / x), -1.0, -1.0) / x) + -3.0) / x); else tmp = Float64(fma(3.0, x, 1.0) / Float64(1.0 - Float64(x * x))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x - -1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(N[(N[(N[(N[Power[x, -1.0], $MachinePrecision] - -3.0), $MachinePrecision] / x), $MachinePrecision] * -1.0 + -1.0), $MachinePrecision] / x), $MachinePrecision] + -3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(3.0 * x + 1.0), $MachinePrecision] / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x - -1} - \frac{x - -1}{x - 1} \leq 0:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\frac{{x}^{-1} - -3}{x}, -1, -1\right)}{x} + -3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(3, x, 1\right)}{1 - x \cdot x}\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0Initial program 8.6%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-neg-fracN/A
lower-/.f64N/A
Applied rewrites99.3%
if 0.0 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 98.9%
Applied rewrites98.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= (- (/ x (- x -1.0)) (/ (- x -1.0) (- x 1.0))) 0.0) (/ (- (/ (- (/ -3.0 x) 1.0) x) 3.0) x) (/ (fma 3.0 x 1.0) (- 1.0 (* x x)))))
double code(double x) {
double tmp;
if (((x / (x - -1.0)) - ((x - -1.0) / (x - 1.0))) <= 0.0) {
tmp = ((((-3.0 / x) - 1.0) / x) - 3.0) / x;
} else {
tmp = fma(3.0, x, 1.0) / (1.0 - (x * x));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x - -1.0)) - Float64(Float64(x - -1.0) / Float64(x - 1.0))) <= 0.0) tmp = Float64(Float64(Float64(Float64(Float64(-3.0 / x) - 1.0) / x) - 3.0) / x); else tmp = Float64(fma(3.0, x, 1.0) / Float64(1.0 - Float64(x * x))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x - -1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(N[(N[(-3.0 / x), $MachinePrecision] - 1.0), $MachinePrecision] / x), $MachinePrecision] - 3.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(3.0 * x + 1.0), $MachinePrecision] / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x - -1} - \frac{x - -1}{x - 1} \leq 0:\\
\;\;\;\;\frac{\frac{\frac{-3}{x} - 1}{x} - 3}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(3, x, 1\right)}{1 - x \cdot x}\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0Initial program 8.6%
Taylor expanded in x around inf
lower-/.f64N/A
lower--.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
lower-+.f64N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6499.2
Applied rewrites99.2%
if 0.0 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 98.9%
Applied rewrites98.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= (- (/ x (- x -1.0)) (/ (- x -1.0) (- x 1.0))) 0.0) (/ (+ -3.0 (/ -1.0 x)) x) (/ (fma 3.0 x 1.0) (- 1.0 (* x x)))))
double code(double x) {
double tmp;
if (((x / (x - -1.0)) - ((x - -1.0) / (x - 1.0))) <= 0.0) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = fma(3.0, x, 1.0) / (1.0 - (x * x));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x - -1.0)) - Float64(Float64(x - -1.0) / Float64(x - 1.0))) <= 0.0) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = Float64(fma(3.0, x, 1.0) / Float64(1.0 - Float64(x * x))); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x - -1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(3.0 * x + 1.0), $MachinePrecision] / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x - -1} - \frac{x - -1}{x - 1} \leq 0:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(3, x, 1\right)}{1 - x \cdot x}\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0Initial program 8.6%
Applied rewrites4.3%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6443.3
Applied rewrites43.3%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
pow2N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6443.3
Applied rewrites43.3%
Taylor expanded in x around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
distribute-lft-inN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
mul-1-negN/A
frac-2negN/A
lower-+.f64N/A
lower-/.f6499.0
Applied rewrites99.0%
if 0.0 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 98.9%
Applied rewrites98.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= (- (/ x (- x -1.0)) (/ (- x -1.0) (- x 1.0))) 0.02) (/ (+ -3.0 (/ -1.0 x)) x) (fma (- x -3.0) x 1.0)))
double code(double x) {
double tmp;
if (((x / (x - -1.0)) - ((x - -1.0) / (x - 1.0))) <= 0.02) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = fma((x - -3.0), x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x - -1.0)) - Float64(Float64(x - -1.0) / Float64(x - 1.0))) <= 0.02) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = fma(Float64(x - -3.0), x, 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x - -1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.02], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(x - -3.0), $MachinePrecision] * x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x - -1} - \frac{x - -1}{x - 1} \leq 0.02:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - -3, x, 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0200000000000000004Initial program 10.3%
Applied rewrites6.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6445.0
Applied rewrites45.0%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
pow2N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6445.0
Applied rewrites45.0%
Taylor expanded in x around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
distribute-lft-inN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
mul-1-negN/A
frac-2negN/A
lower-+.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
if 0.0200000000000000004 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.2
Applied rewrites99.2%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= (- (/ x (- x -1.0)) (/ (- x -1.0) (- x 1.0))) 0.02) (/ -3.0 x) (fma (- x -3.0) x 1.0)))
double code(double x) {
double tmp;
if (((x / (x - -1.0)) - ((x - -1.0) / (x - 1.0))) <= 0.02) {
tmp = -3.0 / x;
} else {
tmp = fma((x - -3.0), x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x - -1.0)) - Float64(Float64(x - -1.0) / Float64(x - 1.0))) <= 0.02) tmp = Float64(-3.0 / x); else tmp = fma(Float64(x - -3.0), x, 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x - -1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.02], N[(-3.0 / x), $MachinePrecision], N[(N[(x - -3.0), $MachinePrecision] * x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x - -1} - \frac{x - -1}{x - 1} \leq 0.02:\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - -3, x, 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0200000000000000004Initial program 10.3%
Taylor expanded in x around inf
lower-/.f6497.1
Applied rewrites97.1%
if 0.0200000000000000004 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.2
Applied rewrites99.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (if (<= (- (/ x (- x -1.0)) (/ (- x -1.0) (- x 1.0))) 0.0) (- 1.0 1.0) (fma (- x -3.0) x 1.0)))
double code(double x) {
double tmp;
if (((x / (x - -1.0)) - ((x - -1.0) / (x - 1.0))) <= 0.0) {
tmp = 1.0 - 1.0;
} else {
tmp = fma((x - -3.0), x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x - -1.0)) - Float64(Float64(x - -1.0) / Float64(x - 1.0))) <= 0.0) tmp = Float64(1.0 - 1.0); else tmp = fma(Float64(x - -3.0), x, 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x - -1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(1.0 - 1.0), $MachinePrecision], N[(N[(x - -3.0), $MachinePrecision] * x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x - -1} - \frac{x - -1}{x - 1} \leq 0:\\
\;\;\;\;1 - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - -3, x, 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0Initial program 8.6%
Taylor expanded in x around inf
Applied rewrites6.7%
Taylor expanded in x around inf
Applied rewrites5.9%
if 0.0 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 98.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6496.5
Applied rewrites96.5%
Final simplification52.2%
(FPCore (x) :precision binary64 (if (<= (- (/ x (- x -1.0)) (/ (- x -1.0) (- x 1.0))) 0.02) (- 1.0 1.0) (fma 3.0 x 1.0)))
double code(double x) {
double tmp;
if (((x / (x - -1.0)) - ((x - -1.0) / (x - 1.0))) <= 0.02) {
tmp = 1.0 - 1.0;
} else {
tmp = fma(3.0, x, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x - -1.0)) - Float64(Float64(x - -1.0) / Float64(x - 1.0))) <= 0.02) tmp = Float64(1.0 - 1.0); else tmp = fma(3.0, x, 1.0); end return tmp end
code[x_] := If[LessEqual[N[(N[(x / N[(x - -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x - -1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.02], N[(1.0 - 1.0), $MachinePrecision], N[(3.0 * x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x - -1} - \frac{x - -1}{x - 1} \leq 0.02:\\
\;\;\;\;1 - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, 1\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) < 0.0200000000000000004Initial program 10.3%
Taylor expanded in x around inf
Applied rewrites7.1%
Taylor expanded in x around inf
Applied rewrites5.8%
if 0.0200000000000000004 < (-.f64 (/.f64 x (+.f64 x #s(literal 1 binary64))) (/.f64 (+.f64 x #s(literal 1 binary64)) (-.f64 x #s(literal 1 binary64)))) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6499.0
Applied rewrites99.0%
Final simplification52.0%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 54.8%
Taylor expanded in x around 0
Applied rewrites50.2%
herbie shell --seed 2025085
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))