(FPCore (x) :precision binary64 (- (sqrt (+ x 2.0)) (sqrt (- x 2.0))))
double code(double x) { return sqrt((x + 2.0)) - sqrt((x - 2.0)); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((x + 2.0d0)) - sqrt((x - 2.0d0)) end function
public static double code(double x) { return Math.sqrt((x + 2.0)) - Math.sqrt((x - 2.0)); }
def code(x): return math.sqrt((x + 2.0)) - math.sqrt((x - 2.0))
function code(x) return Float64(sqrt(Float64(x + 2.0)) - sqrt(Float64(x - 2.0))) end
function tmp = code(x) tmp = sqrt((x + 2.0)) - sqrt((x - 2.0)); end
code[x_] := N[(N[Sqrt[N[(x + 2.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[N[(x - 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{x + 2} - \sqrt{x - 2} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (sqrt (+ x 2.0)) (sqrt (- x 2.0))))
double code(double x) { return sqrt((x + 2.0)) - sqrt((x - 2.0)); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((x + 2.0d0)) - sqrt((x - 2.0d0)) end function
public static double code(double x) { return Math.sqrt((x + 2.0)) - Math.sqrt((x - 2.0)); }
def code(x): return math.sqrt((x + 2.0)) - math.sqrt((x - 2.0))
function code(x) return Float64(sqrt(Float64(x + 2.0)) - sqrt(Float64(x - 2.0))) end
function tmp = code(x) tmp = sqrt((x + 2.0)) - sqrt((x - 2.0)); end
code[x_] := N[(N[Sqrt[N[(x + 2.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[N[(x - 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{x + 2} - \sqrt{x - 2} \end{array}
(FPCore (x) :precision binary64 (/ (- -4.0) (+ (sqrt (- x 2.0)) (sqrt (- x -2.0)))))
double code(double x) { return -(-4.0) / (sqrt((x - 2.0)) + sqrt((x - -2.0))); }
real(8) function code(x) real(8), intent (in) :: x code = -(-4.0d0) / (sqrt((x - 2.0d0)) + sqrt((x - (-2.0d0)))) end function
public static double code(double x) { return -(-4.0) / (Math.sqrt((x - 2.0)) + Math.sqrt((x - -2.0))); }
def code(x): return -(-4.0) / (math.sqrt((x - 2.0)) + math.sqrt((x - -2.0)))
function code(x) return Float64(Float64(-(-4.0)) / Float64(sqrt(Float64(x - 2.0)) + sqrt(Float64(x - -2.0)))) end
function tmp = code(x) tmp = -(-4.0) / (sqrt((x - 2.0)) + sqrt((x - -2.0))); end
code[x_] := N[((--4.0) / N[(N[Sqrt[N[(x - 2.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[N[(x - -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{--4}{\sqrt{x - 2} + \sqrt{x - -2}} \end{array}
Initial program 98.8%
lift--.f64
N/A
sub-neg
N/A
+-commutative
N/A
flip-+
N/A
lower-/.f64
N/A
Applied rewrites99.3%
Taylor expanded in x around 0
Applied rewrites99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (- (sqrt (+ x 2.0)) (sqrt (- x 2.0))))
double code(double x) { return sqrt((x + 2.0)) - sqrt((x - 2.0)); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((x + 2.0d0)) - sqrt((x - 2.0d0)) end function
public static double code(double x) { return Math.sqrt((x + 2.0)) - Math.sqrt((x - 2.0)); }
def code(x): return math.sqrt((x + 2.0)) - math.sqrt((x - 2.0))
function code(x) return Float64(sqrt(Float64(x + 2.0)) - sqrt(Float64(x - 2.0))) end
function tmp = code(x) tmp = sqrt((x + 2.0)) - sqrt((x - 2.0)); end
code[x_] := N[(N[Sqrt[N[(x + 2.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[N[(x - 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{x + 2} - \sqrt{x - 2} \end{array}
Initial program 98.8%
(FPCore (x) :precision binary64 (/ (* (sqrt x) 2.0) x))
double code(double x) { return (sqrt(x) * 2.0) / x; }
real(8) function code(x) real(8), intent (in) :: x code = (sqrt(x) * 2.0d0) / x end function
public static double code(double x) { return (Math.sqrt(x) * 2.0) / x; }
def code(x): return (math.sqrt(x) * 2.0) / x
function code(x) return Float64(Float64(sqrt(x) * 2.0) / x) end
function tmp = code(x) tmp = (sqrt(x) * 2.0) / x; end
code[x_] := N[(N[(N[Sqrt[x], $MachinePrecision] * 2.0), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l} \\ \frac{\sqrt{x} \cdot 2}{x} \end{array}
Initial program 98.8%
Taylor expanded in x around inf
div-sub
N/A
rem-square-sqrt
N/A
unpow2
N/A
*-commutative
N/A
div-sub
N/A
lower-/.f64
N/A
*-lft-identity
N/A
*-commutative
N/A
unpow2
N/A
rem-square-sqrt
N/A
distribute-rgt-out--
N/A
metadata-eval
N/A
lower-*.f64
N/A
lower-sqrt.f64
25.8
Applied rewrites25.8%
(FPCore (x) :precision binary64 0.0)
double code(double x) { return 0.0; }
real(8) function code(x) real(8), intent (in) :: x code = 0.0d0 end function
public static double code(double x) { return 0.0; }
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l} \\ 0 \end{array}
Initial program 98.8%
lift--.f64
N/A
flip--
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
lift-sqrt.f64
N/A
lift-sqrt.f64
N/A
rem-square-sqrt
N/A
div-sub
N/A
lower--.f64
N/A
Applied rewrites99.0%
Taylor expanded in x around -inf
distribute-rgt-out
N/A
metadata-eval
N/A
mul0-rgt
N/A
metadata-eval
3.1
Applied rewrites3.1%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(x+2)-sqrt(x-2)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 10.0))
(- (sqrt (+ x 2.0)) (sqrt (- x 2.0))))