
(FPCore (x) :precision binary64 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
public static double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
def code(x): return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
function code(x) return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) end
function tmp = code(x) tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x))); end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))
double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))
end function
public static double code(double x) {
return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)));
}
def code(x): return (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))
function code(x) return Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) end
function tmp = code(x) tmp = (6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x))); end
code[x_] := N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
(FPCore (x) :precision binary64 (* (/ (- 1.0 x) (fma (sqrt x) 4.0 (- x -1.0))) -6.0))
double code(double x) {
return ((1.0 - x) / fma(sqrt(x), 4.0, (x - -1.0))) * -6.0;
}
function code(x) return Float64(Float64(Float64(1.0 - x) / fma(sqrt(x), 4.0, Float64(x - -1.0))) * -6.0) end
code[x_] := N[(N[(N[(1.0 - x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * 4.0 + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -6.0), $MachinePrecision]
\frac{1 - x}{\mathsf{fma}\left(\sqrt{x}, 4, x - -1\right)} \cdot -6
Initial program 99.7%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
Applied rewrites99.9%
(FPCore (x) :precision binary64 (/ (fma x 6.0 -6.0) (fma (sqrt x) 4.0 (- x -1.0))))
double code(double x) {
return fma(x, 6.0, -6.0) / fma(sqrt(x), 4.0, (x - -1.0));
}
function code(x) return Float64(fma(x, 6.0, -6.0) / fma(sqrt(x), 4.0, Float64(x - -1.0))) end
code[x_] := N[(N[(x * 6.0 + -6.0), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * 4.0 + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\mathsf{fma}\left(x, 6, -6\right)}{\mathsf{fma}\left(\sqrt{x}, 4, x - -1\right)}
Initial program 99.7%
lift-*.f64N/A
lift--.f64N/A
distribute-rgt-out--N/A
metadata-evalN/A
sub-flip-reverseN/A
lower-fma.f64N/A
metadata-eval99.7%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flip-reverseN/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
add-flipN/A
sub-negate-revN/A
sub-negate-revN/A
add-flipN/A
lift-+.f64N/A
lower-fma.f6499.7%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
metadata-eval99.7%
Applied rewrites99.7%
(FPCore (x) :precision binary64 (if (<= x 42.0) (/ (fma 6.0 x -6.0) (fma 4.0 (sqrt x) 1.0)) (/ 6.0 (+ 1.0 (* 4.0 (sqrt (/ 1.0 x)))))))
double code(double x) {
double tmp;
if (x <= 42.0) {
tmp = fma(6.0, x, -6.0) / fma(4.0, sqrt(x), 1.0);
} else {
tmp = 6.0 / (1.0 + (4.0 * sqrt((1.0 / x))));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 42.0) tmp = Float64(fma(6.0, x, -6.0) / fma(4.0, sqrt(x), 1.0)); else tmp = Float64(6.0 / Float64(1.0 + Float64(4.0 * sqrt(Float64(1.0 / x))))); end return tmp end
code[x_] := If[LessEqual[x, 42.0], N[(N[(6.0 * x + -6.0), $MachinePrecision] / N[(4.0 * N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(1.0 + N[(4.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 42:\\
\;\;\;\;\frac{\mathsf{fma}\left(6, x, -6\right)}{\mathsf{fma}\left(4, \sqrt{x}, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{1 + 4 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
if x < 42Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites51.9%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
metadata-evalN/A
distribute-lft-inN/A
metadata-evalN/A
lower-fma.f6451.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6451.9%
Applied rewrites51.9%
if 42 < x Initial program 99.7%
Taylor expanded in x around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6450.3%
Applied rewrites50.3%
(FPCore (x) :precision binary64 (if (<= x 55.0) (/ -6.0 (fma 4.0 (sqrt x) (- x -1.0))) (/ 6.0 (+ 1.0 (* 4.0 (sqrt (/ 1.0 x)))))))
double code(double x) {
double tmp;
if (x <= 55.0) {
tmp = -6.0 / fma(4.0, sqrt(x), (x - -1.0));
} else {
tmp = 6.0 / (1.0 + (4.0 * sqrt((1.0 / x))));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 55.0) tmp = Float64(-6.0 / fma(4.0, sqrt(x), Float64(x - -1.0))); else tmp = Float64(6.0 / Float64(1.0 + Float64(4.0 * sqrt(Float64(1.0 / x))))); end return tmp end
code[x_] := If[LessEqual[x, 55.0], N[(-6.0 / N[(4.0 * N[Sqrt[x], $MachinePrecision] + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(1.0 + N[(4.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 55:\\
\;\;\;\;\frac{-6}{\mathsf{fma}\left(4, \sqrt{x}, x - -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{1 + 4 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
if x < 55Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites49.5%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
add-flipN/A
metadata-evalN/A
lift--.f6449.5%
Applied rewrites49.5%
if 55 < x Initial program 99.7%
Taylor expanded in x around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6450.3%
Applied rewrites50.3%
(FPCore (x) :precision binary64 (if (<= x 0.35) (/ -6.0 (fma 4.0 (sqrt x) (- x -1.0))) (/ 6.0 (fma -4.0 (sqrt (/ 1.0 x)) 1.0))))
double code(double x) {
double tmp;
if (x <= 0.35) {
tmp = -6.0 / fma(4.0, sqrt(x), (x - -1.0));
} else {
tmp = 6.0 / fma(-4.0, sqrt((1.0 / x)), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 0.35) tmp = Float64(-6.0 / fma(4.0, sqrt(x), Float64(x - -1.0))); else tmp = Float64(6.0 / fma(-4.0, sqrt(Float64(1.0 / x)), 1.0)); end return tmp end
code[x_] := If[LessEqual[x, 0.35], N[(-6.0 / N[(4.0 * N[Sqrt[x], $MachinePrecision] + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(-4.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 0.35:\\
\;\;\;\;\frac{-6}{\mathsf{fma}\left(4, \sqrt{x}, x - -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{\mathsf{fma}\left(-4, \sqrt{\frac{1}{x}}, 1\right)}\\
\end{array}
if x < 0.34999999999999998Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites49.5%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
add-flipN/A
metadata-evalN/A
lift--.f6449.5%
Applied rewrites49.5%
if 0.34999999999999998 < x Initial program 99.7%
Taylor expanded in x around -inf
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6451.6%
Applied rewrites51.6%
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lower-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-fma.f64N/A
metadata-eval51.6%
Applied rewrites51.6%
(FPCore (x) :precision binary64 (if (<= x 55.0) (/ -6.0 (fma 4.0 (sqrt x) (- x -1.0))) (/ 1.5 (sqrt (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 55.0) {
tmp = -6.0 / fma(4.0, sqrt(x), (x - -1.0));
} else {
tmp = 1.5 / sqrt((1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 55.0) tmp = Float64(-6.0 / fma(4.0, sqrt(x), Float64(x - -1.0))); else tmp = Float64(1.5 / sqrt(Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, 55.0], N[(-6.0 / N[(4.0 * N[Sqrt[x], $MachinePrecision] + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.5 / N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 55:\\
\;\;\;\;\frac{-6}{\mathsf{fma}\left(4, \sqrt{x}, x - -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1.5}{\sqrt{\frac{1}{x}}}\\
\end{array}
if x < 55Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites49.5%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
add-flipN/A
metadata-evalN/A
lift--.f6449.5%
Applied rewrites49.5%
if 55 < x Initial program 99.7%
Taylor expanded in x around -inf
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6451.6%
Applied rewrites51.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.0%
Applied rewrites4.0%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f644.5%
Applied rewrites4.5%
(FPCore (x) :precision binary64 (if (<= x 55.0) (/ 6.0 (fma -4.0 (sqrt x) -1.0)) (/ 1.5 (sqrt (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 55.0) {
tmp = 6.0 / fma(-4.0, sqrt(x), -1.0);
} else {
tmp = 1.5 / sqrt((1.0 / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 55.0) tmp = Float64(6.0 / fma(-4.0, sqrt(x), -1.0)); else tmp = Float64(1.5 / sqrt(Float64(1.0 / x))); end return tmp end
code[x_] := If[LessEqual[x, 55.0], N[(6.0 / N[(-4.0 * N[Sqrt[x], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.5 / N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 55:\\
\;\;\;\;\frac{6}{\mathsf{fma}\left(-4, \sqrt{x}, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1.5}{\sqrt{\frac{1}{x}}}\\
\end{array}
if x < 55Initial program 99.7%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6449.3%
Applied rewrites49.3%
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-neg-inN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval49.3%
Applied rewrites49.3%
if 55 < x Initial program 99.7%
Taylor expanded in x around -inf
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6451.6%
Applied rewrites51.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.0%
Applied rewrites4.0%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f644.5%
Applied rewrites4.5%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (/ 1.0 x)))) (if (<= x 55.0) (* -1.5 t_0) (/ 1.5 t_0))))
double code(double x) {
double t_0 = sqrt((1.0 / x));
double tmp;
if (x <= 55.0) {
tmp = -1.5 * t_0;
} else {
tmp = 1.5 / t_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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 / x))
if (x <= 55.0d0) then
tmp = (-1.5d0) * t_0
else
tmp = 1.5d0 / t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 / x));
double tmp;
if (x <= 55.0) {
tmp = -1.5 * t_0;
} else {
tmp = 1.5 / t_0;
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 / x)) tmp = 0 if x <= 55.0: tmp = -1.5 * t_0 else: tmp = 1.5 / t_0 return tmp
function code(x) t_0 = sqrt(Float64(1.0 / x)) tmp = 0.0 if (x <= 55.0) tmp = Float64(-1.5 * t_0); else tmp = Float64(1.5 / t_0); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 / x)); tmp = 0.0; if (x <= 55.0) tmp = -1.5 * t_0; else tmp = 1.5 / t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 55.0], N[(-1.5 * t$95$0), $MachinePrecision], N[(1.5 / t$95$0), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sqrt{\frac{1}{x}}\\
\mathbf{if}\;x \leq 55:\\
\;\;\;\;-1.5 \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1.5}{t\_0}\\
\end{array}
if x < 55Initial program 99.7%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6449.3%
Applied rewrites49.3%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f644.1%
Applied rewrites4.1%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
mult-flipN/A
lift-/.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f64N/A
lower-*.f644.1%
Applied rewrites4.1%
Taylor expanded in x around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f644.4%
Applied rewrites4.4%
if 55 < x Initial program 99.7%
Taylor expanded in x around -inf
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6451.6%
Applied rewrites51.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.0%
Applied rewrites4.0%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f644.5%
Applied rewrites4.5%
(FPCore (x) :precision binary64 (if (<= x 5600.0) (* -1.5 (sqrt (/ 1.0 x))) (/ 1.5 (sqrt x))))
double code(double x) {
double tmp;
if (x <= 5600.0) {
tmp = -1.5 * sqrt((1.0 / x));
} else {
tmp = 1.5 / sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5600.0d0) then
tmp = (-1.5d0) * sqrt((1.0d0 / x))
else
tmp = 1.5d0 / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5600.0) {
tmp = -1.5 * Math.sqrt((1.0 / x));
} else {
tmp = 1.5 / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5600.0: tmp = -1.5 * math.sqrt((1.0 / x)) else: tmp = 1.5 / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 5600.0) tmp = Float64(-1.5 * sqrt(Float64(1.0 / x))); else tmp = Float64(1.5 / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5600.0) tmp = -1.5 * sqrt((1.0 / x)); else tmp = 1.5 / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5600.0], N[(-1.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 5600:\\
\;\;\;\;-1.5 \cdot \sqrt{\frac{1}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1.5}{\sqrt{x}}\\
\end{array}
if x < 5600Initial program 99.7%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6449.3%
Applied rewrites49.3%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f644.1%
Applied rewrites4.1%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
mult-flipN/A
lift-/.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f64N/A
lower-*.f644.1%
Applied rewrites4.1%
Taylor expanded in x around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f644.4%
Applied rewrites4.4%
if 5600 < x Initial program 99.7%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6449.3%
Applied rewrites49.3%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f644.1%
Applied rewrites4.1%
lift-*.f64N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-undivN/A
metadata-evalN/A
pow1/2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f644.1%
Applied rewrites4.1%
(FPCore (x) :precision binary64 (if (<= (/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))) -1.0) (* (sqrt x) -1.5) (/ 1.5 (sqrt x))))
double code(double x) {
double tmp;
if (((6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)))) <= -1.0) {
tmp = sqrt(x) * -1.5;
} else {
tmp = 1.5 / sqrt(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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (((6.0d0 * (x - 1.0d0)) / ((x + 1.0d0) + (4.0d0 * sqrt(x)))) <= (-1.0d0)) then
tmp = sqrt(x) * (-1.5d0)
else
tmp = 1.5d0 / sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * Math.sqrt(x)))) <= -1.0) {
tmp = Math.sqrt(x) * -1.5;
} else {
tmp = 1.5 / Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if ((6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * math.sqrt(x)))) <= -1.0: tmp = math.sqrt(x) * -1.5 else: tmp = 1.5 / math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(6.0 * Float64(x - 1.0)) / Float64(Float64(x + 1.0) + Float64(4.0 * sqrt(x)))) <= -1.0) tmp = Float64(sqrt(x) * -1.5); else tmp = Float64(1.5 / sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((6.0 * (x - 1.0)) / ((x + 1.0) + (4.0 * sqrt(x)))) <= -1.0) tmp = sqrt(x) * -1.5; else tmp = 1.5 / sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(6.0 * N[(x - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], N[(N[Sqrt[x], $MachinePrecision] * -1.5), $MachinePrecision], N[(1.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}} \leq -1:\\
\;\;\;\;\sqrt{x} \cdot -1.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1.5}{\sqrt{x}}\\
\end{array}
if (/.f64 (*.f64 #s(literal 6 binary64) (-.f64 x #s(literal 1 binary64))) (+.f64 (+.f64 x #s(literal 1 binary64)) (*.f64 #s(literal 4 binary64) (sqrt.f64 x)))) < -1Initial program 99.7%
Taylor expanded in x around -inf
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6451.6%
Applied rewrites51.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.0%
Applied rewrites4.0%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-sqrt.f64N/A
pow1/2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f644.0%
lower-*.f64N/A
*-commutativeN/A
lower-*.f644.0%
Applied rewrites4.0%
if -1 < (/.f64 (*.f64 #s(literal 6 binary64) (-.f64 x #s(literal 1 binary64))) (+.f64 (+.f64 x #s(literal 1 binary64)) (*.f64 #s(literal 4 binary64) (sqrt.f64 x)))) Initial program 99.7%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6449.3%
Applied rewrites49.3%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f644.1%
Applied rewrites4.1%
lift-*.f64N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-undivN/A
metadata-evalN/A
pow1/2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f644.1%
Applied rewrites4.1%
(FPCore (x) :precision binary64 (* (sqrt x) -1.5))
double code(double x) {
return sqrt(x) * -1.5;
}
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 = sqrt(x) * (-1.5d0)
end function
public static double code(double x) {
return Math.sqrt(x) * -1.5;
}
def code(x): return math.sqrt(x) * -1.5
function code(x) return Float64(sqrt(x) * -1.5) end
function tmp = code(x) tmp = sqrt(x) * -1.5; end
code[x_] := N[(N[Sqrt[x], $MachinePrecision] * -1.5), $MachinePrecision]
\sqrt{x} \cdot -1.5
Initial program 99.7%
Taylor expanded in x around -inf
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6451.6%
Applied rewrites51.6%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.0%
Applied rewrites4.0%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-sqrt.f64N/A
pow1/2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
pow1/2N/A
lift-sqrt.f644.0%
lower-*.f64N/A
*-commutativeN/A
lower-*.f644.0%
Applied rewrites4.0%
herbie shell --seed 2025183
(FPCore (x)
:name "Data.Approximate.Numerics:blog from approximate-0.2.2.1"
:precision binary64
(/ (* 6.0 (- x 1.0)) (+ (+ x 1.0) (* 4.0 (sqrt x)))))