
(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 10 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 4.0 (sqrt x) x) -1.0)) -6.0))
double code(double x) {
return ((1.0 - x) / (fma(4.0, sqrt(x), x) - -1.0)) * -6.0;
}
function code(x) return Float64(Float64(Float64(1.0 - x) / Float64(fma(4.0, sqrt(x), x) - -1.0)) * -6.0) end
code[x_] := N[(N[(N[(1.0 - x), $MachinePrecision] / N[(N[(4.0 * N[Sqrt[x], $MachinePrecision] + x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] * -6.0), $MachinePrecision]
\frac{1 - x}{\mathsf{fma}\left(4, \sqrt{x}, x\right) - -1} \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%
lift-fma.f64N/A
lift--.f64N/A
associate-+r-N/A
lower--.f64N/A
*-commutativeN/A
lift-*.f64N/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
remove-double-negN/A
lower-fma.f6499.9%
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 1.0) (* 6.0 (/ (- x 1.0) (fma (sqrt x) 4.0 1.0))) (/ 6.0 (/ (+ x (* 4.0 (sqrt x))) x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 6.0 * ((x - 1.0) / fma(sqrt(x), 4.0, 1.0));
} else {
tmp = 6.0 / ((x + (4.0 * sqrt(x))) / x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(6.0 * Float64(Float64(x - 1.0) / fma(sqrt(x), 4.0, 1.0))); else tmp = Float64(6.0 / Float64(Float64(x + Float64(4.0 * sqrt(x))) / x)); end return tmp end
code[x_] := If[LessEqual[x, 1.0], N[(6.0 * N[(N[(x - 1.0), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * 4.0 + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(N[(x + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;6 \cdot \frac{x - 1}{\mathsf{fma}\left(\sqrt{x}, 4, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{\frac{x + 4 \cdot \sqrt{x}}{x}}\\
\end{array}
if x < 1Initial 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%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6453.0%
Applied rewrites53.0%
lift-/.f64N/A
lift-fma.f64N/A
metadata-evalN/A
distribute-rgt-inN/A
metadata-evalN/A
sub-flipN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6453.0%
lift-+.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
sub-negate-revN/A
metadata-evalN/A
Applied rewrites53.0%
if 1 < 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-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6448.9%
Applied rewrites48.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) (/ (fma x 6.0 -6.0) (fma (sqrt x) 4.0 1.0)) (/ 6.0 (/ (+ x (* 4.0 (sqrt x))) x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = fma(x, 6.0, -6.0) / fma(sqrt(x), 4.0, 1.0);
} else {
tmp = 6.0 / ((x + (4.0 * sqrt(x))) / x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(fma(x, 6.0, -6.0) / fma(sqrt(x), 4.0, 1.0)); else tmp = Float64(6.0 / Float64(Float64(x + Float64(4.0 * sqrt(x))) / x)); end return tmp end
code[x_] := If[LessEqual[x, 1.0], N[(N[(x * 6.0 + -6.0), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * 4.0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(N[(x + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, 6, -6\right)}{\mathsf{fma}\left(\sqrt{x}, 4, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{\frac{x + 4 \cdot \sqrt{x}}{x}}\\
\end{array}
if x < 1Initial 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%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6453.0%
Applied rewrites53.0%
lift-+.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
sub-negate-revN/A
metadata-evalN/A
add-flipN/A
lift-fma.f64N/A
lift-fma.f64N/A
distribute-neg-inN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6453.0%
Applied rewrites53.0%
if 1 < 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-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6448.9%
Applied rewrites48.9%
(FPCore (x) :precision binary64 (if (<= x 1.92) (/ -6.0 (fma (sqrt x) 4.0 (- x -1.0))) (/ 6.0 (/ (+ x (* 4.0 (sqrt x))) x))))
double code(double x) {
double tmp;
if (x <= 1.92) {
tmp = -6.0 / fma(sqrt(x), 4.0, (x - -1.0));
} else {
tmp = 6.0 / ((x + (4.0 * sqrt(x))) / x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.92) tmp = Float64(-6.0 / fma(sqrt(x), 4.0, Float64(x - -1.0))); else tmp = Float64(6.0 / Float64(Float64(x + Float64(4.0 * sqrt(x))) / x)); end return tmp end
code[x_] := If[LessEqual[x, 1.92], N[(-6.0 / N[(N[Sqrt[x], $MachinePrecision] * 4.0 + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(N[(x + N[(4.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 1.92:\\
\;\;\;\;\frac{-6}{\mathsf{fma}\left(\sqrt{x}, 4, x - -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{\frac{x + 4 \cdot \sqrt{x}}{x}}\\
\end{array}
if x < 1.9199999999999999Initial 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%
Taylor expanded in x around 0
Applied rewrites50.6%
if 1.9199999999999999 < 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-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6448.9%
Applied rewrites48.9%
(FPCore (x) :precision binary64 (if (<= x 1.92) (/ -6.0 (fma (sqrt x) 4.0 (- x -1.0))) (/ 6.0 (fma (sqrt (/ 1.0 x)) 4.0 1.0))))
double code(double x) {
double tmp;
if (x <= 1.92) {
tmp = -6.0 / fma(sqrt(x), 4.0, (x - -1.0));
} else {
tmp = 6.0 / fma(sqrt((1.0 / x)), 4.0, 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.92) tmp = Float64(-6.0 / fma(sqrt(x), 4.0, Float64(x - -1.0))); else tmp = Float64(6.0 / fma(sqrt(Float64(1.0 / x)), 4.0, 1.0)); end return tmp end
code[x_] := If[LessEqual[x, 1.92], N[(-6.0 / N[(N[Sqrt[x], $MachinePrecision] * 4.0 + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(6.0 / N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 4.0 + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 1.92:\\
\;\;\;\;\frac{-6}{\mathsf{fma}\left(\sqrt{x}, 4, x - -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{6}{\mathsf{fma}\left(\sqrt{\frac{1}{x}}, 4, 1\right)}\\
\end{array}
if x < 1.9199999999999999Initial 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%
Taylor expanded in x around 0
Applied rewrites50.6%
if 1.9199999999999999 < 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-/.f6448.9%
Applied rewrites48.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6448.9%
Applied rewrites48.9%
(FPCore (x) :precision binary64 (if (<= x 1.92) (/ -6.0 (fma (sqrt x) 4.0 (- x -1.0))) (* (sqrt x) 1.5)))
double code(double x) {
double tmp;
if (x <= 1.92) {
tmp = -6.0 / fma(sqrt(x), 4.0, (x - -1.0));
} else {
tmp = sqrt(x) * 1.5;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.92) tmp = Float64(-6.0 / fma(sqrt(x), 4.0, Float64(x - -1.0))); else tmp = Float64(sqrt(x) * 1.5); end return tmp end
code[x_] := If[LessEqual[x, 1.92], N[(-6.0 / N[(N[Sqrt[x], $MachinePrecision] * 4.0 + N[(x - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * 1.5), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 1.92:\\
\;\;\;\;\frac{-6}{\mathsf{fma}\left(\sqrt{x}, 4, x - -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot 1.5\\
\end{array}
if x < 1.9199999999999999Initial 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%
Taylor expanded in x around 0
Applied rewrites50.6%
if 1.9199999999999999 < 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-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.4%
Applied rewrites4.4%
lift-*.f64N/A
*-commutativeN/A
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.f64N/A
lower-*.f644.4%
Applied rewrites4.4%
(FPCore (x) :precision binary64 (if (<= x 1.92) (/ 6.0 (fma -4.0 (sqrt x) -1.0)) (* (sqrt x) 1.5)))
double code(double x) {
double tmp;
if (x <= 1.92) {
tmp = 6.0 / fma(-4.0, sqrt(x), -1.0);
} else {
tmp = sqrt(x) * 1.5;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.92) tmp = Float64(6.0 / fma(-4.0, sqrt(x), -1.0)); else tmp = Float64(sqrt(x) * 1.5); end return tmp end
code[x_] := If[LessEqual[x, 1.92], N[(6.0 / N[(-4.0 * N[Sqrt[x], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * 1.5), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 1.92:\\
\;\;\;\;\frac{6}{\mathsf{fma}\left(-4, \sqrt{x}, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot 1.5\\
\end{array}
if x < 1.9199999999999999Initial program 99.7%
Taylor expanded in x around 0
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f6450.4%
Applied rewrites50.4%
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-eval50.4%
Applied rewrites50.4%
if 1.9199999999999999 < 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-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.4%
Applied rewrites4.4%
lift-*.f64N/A
*-commutativeN/A
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.f64N/A
lower-*.f644.4%
Applied rewrites4.4%
(FPCore (x) :precision binary64 (if (<= x 3.5) (/ -1.5 (sqrt (/ 1.0 x))) (* (sqrt x) 1.5)))
double code(double x) {
double tmp;
if (x <= 3.5) {
tmp = -1.5 / sqrt((1.0 / x));
} else {
tmp = sqrt(x) * 1.5;
}
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 <= 3.5d0) then
tmp = (-1.5d0) / sqrt((1.0d0 / x))
else
tmp = sqrt(x) * 1.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 3.5) {
tmp = -1.5 / Math.sqrt((1.0 / x));
} else {
tmp = Math.sqrt(x) * 1.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 3.5: tmp = -1.5 / math.sqrt((1.0 / x)) else: tmp = math.sqrt(x) * 1.5 return tmp
function code(x) tmp = 0.0 if (x <= 3.5) tmp = Float64(-1.5 / sqrt(Float64(1.0 / x))); else tmp = Float64(sqrt(x) * 1.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 3.5) tmp = -1.5 / sqrt((1.0 / x)); else tmp = sqrt(x) * 1.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 3.5], N[(-1.5 / N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * 1.5), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 3.5:\\
\;\;\;\;\frac{-1.5}{\sqrt{\frac{1}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot 1.5\\
\end{array}
if x < 3.5Initial program 99.7%
Taylor expanded in x around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.4%
Applied rewrites4.4%
Taylor expanded in x around -inf
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f644.2%
Applied rewrites4.2%
if 3.5 < 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-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.4%
Applied rewrites4.4%
lift-*.f64N/A
*-commutativeN/A
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.f64N/A
lower-*.f644.4%
Applied rewrites4.4%
(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-/.f6448.9%
Applied rewrites48.9%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f644.4%
Applied rewrites4.4%
lift-*.f64N/A
*-commutativeN/A
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.f64N/A
lower-*.f644.4%
Applied rewrites4.4%
herbie shell --seed 2025188
(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)))))