(FPCore (x) :precision binary64 (- (sqrt (+ x 39.0)) (sqrt x)))
double code(double x) { return sqrt((x + 39.0)) - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((x + 39.0d0)) - sqrt(x) end function
public static double code(double x) { return Math.sqrt((x + 39.0)) - Math.sqrt(x); }
def code(x): return math.sqrt((x + 39.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 39.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 39.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 39.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{x + 39} - \sqrt{x} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (- (sqrt (+ x 39.0)) (sqrt x)))
double code(double x) { return sqrt((x + 39.0)) - sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = sqrt((x + 39.0d0)) - sqrt(x) end function
public static double code(double x) { return Math.sqrt((x + 39.0)) - Math.sqrt(x); }
def code(x): return math.sqrt((x + 39.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 39.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 39.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 39.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \sqrt{x + 39} - \sqrt{x} \end{array}
(FPCore (x) :precision binary64 (/ 39.0 (+ (sqrt x) (sqrt (+ 39.0 x)))))
double code(double x) { return 39.0 / (sqrt(x) + sqrt((39.0 + x))); }
real(8) function code(x) real(8), intent (in) :: x code = 39.0d0 / (sqrt(x) + sqrt((39.0d0 + x))) end function
public static double code(double x) { return 39.0 / (Math.sqrt(x) + Math.sqrt((39.0 + x))); }
def code(x): return 39.0 / (math.sqrt(x) + math.sqrt((39.0 + x)))
function code(x) return Float64(39.0 / Float64(sqrt(x) + sqrt(Float64(39.0 + x)))) end
function tmp = code(x) tmp = 39.0 / (sqrt(x) + sqrt((39.0 + x))); end
code[x_] := N[(39.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(39.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{39}{\sqrt{x} + \sqrt{39 + x}} \end{array}
Initial program 53.7%
lift--.f64
N/A
flip--
N/A
lower-/.f64
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
lower--.f64
N/A
lift-+.f64
N/A
+-commutative
N/A
lower-+.f64
N/A
+-commutative
N/A
lower-+.f64
54.5
lift-+.f64
N/A
+-commutative
N/A
lower-+.f64
54.5
Applied rewrites54.5%
Taylor expanded in x around 0
Applied rewrites99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ x 39.0)) (sqrt x)))) (if (<= t_0 0.0001) (/ 19.5 (sqrt x)) t_0)))
double code(double x) { double t_0 = sqrt((x + 39.0)) - sqrt(x); double tmp; if (t_0 <= 0.0001) { tmp = 19.5 / sqrt(x); } else { tmp = t_0; } return tmp; }
real(8) function code(x) real(8), intent (in) :: x real(8) :: t_0 real(8) :: tmp t_0 = sqrt((x + 39.0d0)) - sqrt(x) if (t_0 <= 0.0001d0) then tmp = 19.5d0 / sqrt(x) else tmp = t_0 end if code = tmp end function
public static double code(double x) { double t_0 = Math.sqrt((x + 39.0)) - Math.sqrt(x); double tmp; if (t_0 <= 0.0001) { tmp = 19.5 / Math.sqrt(x); } else { tmp = t_0; } return tmp; }
def code(x): t_0 = math.sqrt((x + 39.0)) - math.sqrt(x) tmp = 0 if t_0 <= 0.0001: tmp = 19.5 / math.sqrt(x) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(sqrt(Float64(x + 39.0)) - sqrt(x)) tmp = 0.0 if (t_0 <= 0.0001) tmp = Float64(19.5 / sqrt(x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = sqrt((x + 39.0)) - sqrt(x); tmp = 0.0; if (t_0 <= 0.0001) tmp = 19.5 / sqrt(x); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(x + 39.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0001], N[(19.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 39} - \sqrt{x}\\ \mathbf{if}\;t\_0 \leq 0.0001:\\ \;\;\;\;\frac{19.5}{\sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 39 binary64))) (sqrt.f64 x)) < 1.00000000000000005e-4
Initial program 4.8%
Taylor expanded in x around inf
*-commutative
N/A
lower-*.f64
N/A
lower-sqrt.f64
N/A
lower-/.f64
99.0
Applied rewrites99.0%
Applied rewrites99.1%
if 1.00000000000000005e-4 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 39 binary64))) (sqrt.f64 x))
Initial program 99.7%
(FPCore (x) :precision binary64 (if (<= (- (sqrt (+ x 39.0)) (sqrt x)) 0.001) (/ 19.5 (sqrt x)) (- (sqrt 39.0) (sqrt x))))
double code(double x) { double tmp; if ((sqrt((x + 39.0)) - sqrt(x)) <= 0.001) { tmp = 19.5 / sqrt(x); } else { tmp = sqrt(39.0) - sqrt(x); } return tmp; }
real(8) function code(x) real(8), intent (in) :: x real(8) :: tmp if ((sqrt((x + 39.0d0)) - sqrt(x)) <= 0.001d0) then tmp = 19.5d0 / sqrt(x) else tmp = sqrt(39.0d0) - sqrt(x) end if code = tmp end function
public static double code(double x) { double tmp; if ((Math.sqrt((x + 39.0)) - Math.sqrt(x)) <= 0.001) { tmp = 19.5 / Math.sqrt(x); } else { tmp = Math.sqrt(39.0) - Math.sqrt(x); } return tmp; }
def code(x): tmp = 0 if (math.sqrt((x + 39.0)) - math.sqrt(x)) <= 0.001: tmp = 19.5 / math.sqrt(x) else: tmp = math.sqrt(39.0) - math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(sqrt(Float64(x + 39.0)) - sqrt(x)) <= 0.001) tmp = Float64(19.5 / sqrt(x)); else tmp = Float64(sqrt(39.0) - sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((sqrt((x + 39.0)) - sqrt(x)) <= 0.001) tmp = 19.5 / sqrt(x); else tmp = sqrt(39.0) - sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Sqrt[N[(x + 39.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.001], N[(19.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[39.0], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sqrt{x + 39} - \sqrt{x} \leq 0.001:\\ \;\;\;\;\frac{19.5}{\sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{39} - \sqrt{x}\\ \end{array} \end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 39 binary64))) (sqrt.f64 x)) < 1e-3
Initial program 5.2%
Taylor expanded in x around inf
*-commutative
N/A
lower-*.f64
N/A
lower-sqrt.f64
N/A
lower-/.f64
98.6
Applied rewrites98.6%
Applied rewrites98.8%
if 1e-3 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 39 binary64))) (sqrt.f64 x))
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.3%
(FPCore (x) :precision binary64 (/ 19.5 (sqrt x)))
double code(double x) { return 19.5 / sqrt(x); }
real(8) function code(x) real(8), intent (in) :: x code = 19.5d0 / sqrt(x) end function
public static double code(double x) { return 19.5 / Math.sqrt(x); }
def code(x): return 19.5 / math.sqrt(x)
function code(x) return Float64(19.5 / sqrt(x)) end
function tmp = code(x) tmp = 19.5 / sqrt(x); end
code[x_] := N[(19.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \frac{19.5}{\sqrt{x}} \end{array}
Initial program 53.7%
Taylor expanded in x around inf
*-commutative
N/A
lower-*.f64
N/A
lower-sqrt.f64
N/A
lower-/.f64
51.7
Applied rewrites51.7%
Applied rewrites51.8%
(FPCore (x) :precision binary64 (/ 39.0 0.0))
double code(double x) { return 39.0 / 0.0; }
real(8) function code(x) real(8), intent (in) :: x code = 39.0d0 / 0.0d0 end function
public static double code(double x) { return 39.0 / 0.0; }
def code(x): return 39.0 / 0.0
function code(x) return Float64(39.0 / 0.0) end
function tmp = code(x) tmp = 39.0 / 0.0; end
code[x_] := N[(39.0 / 0.0), $MachinePrecision]
\begin{array}{l} \\ \frac{39}{0} \end{array}
Initial program 53.7%
Applied rewrites53.5%
Taylor expanded in x around -inf
associate-*r/
N/A
unpow2
N/A
rem-square-sqrt
N/A
metadata-eval
N/A
metadata-eval
N/A
distribute-lft1-in
N/A
metadata-eval
N/A
mul0-lft
N/A
mul0-rgt
N/A
lower-/.f64
2.9
Applied rewrites2.9%
herbie shell --seed 1
(FPCore (x)
:name "sqrt(x + 39) - sqrt(x)"
:precision binary64
:pre (and (<= -1.79e+308 x) (<= x 1.79e+308))
(- (sqrt (+ x 39.0)) (sqrt x)))