(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) (sqrt x)))
double code(double x) { return sqrt((1.0 + x)) - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((1.0d0 + x)) - sqrt(x) end function
public static double code(double x) { return Math.sqrt((1.0 + x)) - Math.sqrt(x); }
def code(x): return math.sqrt((1.0 + x)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((1.0 + x)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{1 + x} - \sqrt{x} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) (sqrt x)))
double code(double x) { return sqrt((1.0 + x)) - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((1.0d0 + x)) - sqrt(x) end function
public static double code(double x) { return Math.sqrt((1.0 + x)) - Math.sqrt(x); }
def code(x): return math.sqrt((1.0 + x)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((1.0 + x)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{1 + x} - \sqrt{x} \end{array}
(FPCore (x) :precision binary64 (- (sqrt (+ 1.0 x)) (sqrt x)))
double code(double x) { return sqrt((1.0 + x)) - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((1.0d0 + x)) - sqrt(x) end function
public static double code(double x) { return Math.sqrt((1.0 + x)) - Math.sqrt(x); }
def code(x): return math.sqrt((1.0 + x)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((1.0 + x)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{1 + x} - \sqrt{x} \end{array}
Initial program 100.0%
(FPCore (x) :precision binary64 (fma (fma -0.125 x 0.5) x (- 1.0 (sqrt x))))
double code(double x) { return fma(fma(-0.125, x, 0.5), x, (1.0 - sqrt(x))); }
function code(x) return fma(fma(-0.125, x, 0.5), x, Float64(1.0 - sqrt(x))) end
code[x_] := N[(N[(-0.125 * x + 0.5), $MachinePrecision] * x + N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.5\right), x, 1 - \sqrt{x}\right) \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
associate--l+
N/A
*-commutative
N/A
lower-fma.f64
N/A
+-commutative
N/A
lower-fma.f64
N/A
lower--.f64
N/A
lower-sqrt.f64
98.7
Applied rewrites98.7%
(FPCore (x) :precision binary64 (- 1.0 (- (sqrt x) (* 0.5 x))))
double code(double x) { return 1.0 - (sqrt(x) - (0.5 * x)); }
real(8) function code(x) real(8), intent (in) :: x code = 1.0d0 - (sqrt(x) - (0.5d0 * x)) end function
public static double code(double x) { return 1.0 - (Math.sqrt(x) - (0.5 * x)); }
def code(x): return 1.0 - (math.sqrt(x) - (0.5 * x))
function code(x) return Float64(1.0 - Float64(sqrt(x) - Float64(0.5 * x))) end
function tmp = code(x) tmp = 1.0 - (sqrt(x) - (0.5 * x)); end
code[x_] := N[(1.0 - N[(N[Sqrt[x], $MachinePrecision] - N[(0.5 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ 1 - \left(\sqrt{x} - 0.5 \cdot x\right) \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
associate--l+
N/A
lower-fma.f64
N/A
lower--.f64
N/A
lower-sqrt.f64
98.4
Applied rewrites98.4%
Applied rewrites98.4%
(FPCore (x) :precision binary64 (fma 0.5 x (- 1.0 (sqrt x))))
double code(double x) { return fma(0.5, x, (1.0 - sqrt(x))); }
function code(x) return fma(0.5, x, Float64(1.0 - sqrt(x))) end
code[x_] := N[(0.5 * x + N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(0.5, x, 1 - \sqrt{x}\right) \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
associate--l+
N/A
lower-fma.f64
N/A
lower--.f64
N/A
lower-sqrt.f64
98.4
Applied rewrites98.4%
(FPCore (x) :precision binary64 (- 1.0 (sqrt x)))
double code(double x) { return 1.0 - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = 1.0d0 - sqrt(x) end function
public static double code(double x) { return 1.0 - Math.sqrt(x); }
def code(x): return 1.0 - math.sqrt(x)
function code(x) return Float64(1.0 - sqrt(x)) end
function tmp = code(x) tmp = 1.0 - sqrt(x); end
code[x_] := N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ 1 - \sqrt{x} \end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites97.4%
(FPCore (x) :precision binary64 (* (* x x) -0.125))
double code(double x) { return (x * x) * -0.125; }
real(8) function code(x) real(8), intent (in) :: x code = (x * x) * (-0.125d0) end function
public static double code(double x) { return (x * x) * -0.125; }
def code(x): return (x * x) * -0.125
function code(x) return Float64(Float64(x * x) * -0.125) end
function tmp = code(x) tmp = (x * x) * -0.125; end
code[x_] := N[(N[(x * x), $MachinePrecision] * -0.125), $MachinePrecision]
\begin{array}{l} \\ \left(x \cdot x\right) \cdot -0.125 \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
associate--l+
N/A
*-commutative
N/A
lower-fma.f64
N/A
+-commutative
N/A
lower-fma.f64
N/A
lower--.f64
N/A
lower-sqrt.f64
98.7
Applied rewrites98.7%
Taylor expanded in x around inf
Applied rewrites2.7%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(1+x) - sqrt(x)"
:precision binary64
:pre (and (<= -1.79e+308 x) (<= x 1.0))
(- (sqrt (+ 1.0 x)) (sqrt x)))