From 71ab7759d1a6976b1dca675a891f10b3cd4a5dce Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 10 Jan 2013 12:23:37 -0800 Subject: [PATCH] Add root method (syntax sugar for isolate_roots) Signed-off-by: Leonardo de Moura --- src/math/realclosure/realclosure.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/math/realclosure/realclosure.cpp b/src/math/realclosure/realclosure.cpp index 5dd229fbf..dc15c18bf 100644 --- a/src/math/realclosure/realclosure.cpp +++ b/src/math/realclosure/realclosure.cpp @@ -800,6 +800,11 @@ namespace realclosure { a.m_value = 0; } + void del(numeral_vector & v) { + for (unsigned i = 0; i < v.size(); i++) + del(v[i]); + } + /** \brief Return true if the given interval is smaller than 1/2^k */ @@ -2261,7 +2266,18 @@ namespace realclosure { p.push_back(0); p.push_back(one()); - // TODO: invoke isolate_roots + numeral_vector roots; + nz_isolate_roots(p.size(), p.c_ptr(), roots); + SASSERT(roots.size() == 1 || roots.size() == 2); + if (roots.size() == 1 || sign(roots[0].m_value) > 0) { + set(b, roots[0]); + } + else { + SASSERT(roots.size() == 2); + SASSERT(sign(roots[1].m_value) > 0); + set(b, roots[1]); + } + del(roots); } /**