Fixed UPolynomial<T>::sign_at_negative_infinity() + Simulator::add() ar
authorDmitriy Morozov <morozov@cs.duke.edu>
Tue, 26 Feb 2008 16:15:12 -0500
branchar
changeset 71 a6c5cb5a17cc
parent 70 c37b0b2e5bb2
child 72 35500d7f9fca
Fixed UPolynomial<T>::sign_at_negative_infinity() + Simulator::add() Bug in the former and resulting logic problems in the latter.
include/geometry/polynomial.hpp
include/geometry/simulator.hpp
--- a/include/geometry/polynomial.hpp	Tue Feb 26 08:02:56 2008 -0500
+++ b/include/geometry/polynomial.hpp	Tue Feb 26 16:15:12 2008 -0500
@@ -46,8 +46,8 @@
 	const Polynomial& den = rf.denominator();
 	unsigned int ndegree = num.get_degree();
 	unsigned int ddegree = den.get_degree();
-	return (((ndegree + 1) % 2 == 0) ^ (num[ndegree] > 0)) ^
-		   (((ddegree + 1) % 2 == 0) ^ (den[ddegree] > 0));
+	return !((((ndegree + 1) % 2 == 0) ^ (num[ndegree] > 0)) ^
+		     (((ddegree + 1) % 2 == 0) ^ (den[ddegree] > 0)));
 }
 
 SynapsTraits<QQ>::RootType
--- a/include/geometry/simulator.hpp	Tue Feb 26 08:02:56 2008 -0500
+++ b/include/geometry/simulator.hpp	Tue Feb 26 16:15:12 2008 -0500
@@ -30,17 +30,29 @@
 	Event* ee = new Event_(e);
 	rLog(rlSimulator, "Solving: %s", tostring(f).c_str());
 	FunctionKernel::solve(f, ee->root_stack());
+    rLog(rlSimulator, "Got solution with root stack size: %i", ee->root_stack().size());
+
 	bool sign = FunctionKernel::sign_at_negative_infinity(f);
+    rLog(rlSimulator, "Sign at -infinity: %i", sign);
 	while (!ee->root_stack().empty() && ee->root_stack().top() < current_time())
 	{
 		ee->root_stack().pop();
 		sign = !sign;
 	}
-	if (sign) ee->root_stack().pop();			// TODO: double-check the logic
+    if (!sign)
+    {
+        AssertMsg(ee->root_stack().top() == current_time(), 
+                  "If sign is negative, we must be in the degenerate case");
+        ee->root_stack().pop();
+    }
+
 	if (ee->root_stack().empty())
         rLog(rlSimulator, "Pushing event with empty root stack");
     else
+    {
+        rLog(rlSimulator, "Root stack size: %i", ee->root_stack().size());
         rLog(rlSimulator, "Pushing: %s", tostring(ee->root_stack().top()).c_str());
+    }
 	return queue_.push(ee);
 }