public static bool AcquireCongruences(KnownMeasurementsAggregator known, List <GroundedClause> clauses)
        {
            bool addedKnown = false;

            foreach (GeometryTutorLib.ConcreteAST.GroundedClause clause in clauses)
            {
                GeometryTutorLib.ConcreteAST.CongruentSegments cs = clause as GeometryTutorLib.ConcreteAST.CongruentSegments;
                if (cs != null && !cs.IsReflexive())
                {
                    double length1 = known.GetSegmentLength(cs.cs1);
                    double length2 = known.GetSegmentLength(cs.cs2);

                    if (length1 >= 0 && length2 < 0)
                    {
                        if (known.AddSegmentLength(cs.cs2, length1))
                        {
                            addedKnown = true;
                        }
                    }
                    if (length1 <= 0 && length2 > 0)
                    {
                        if (known.AddSegmentLength(cs.cs1, length2))
                        {
                            addedKnown = true;
                        }
                    }
                    // else: both known
                }

                GeometryTutorLib.ConcreteAST.CongruentAngles cas = clause as GeometryTutorLib.ConcreteAST.CongruentAngles;
                if (cas != null && !cas.IsReflexive())
                {
                    double measure1 = known.GetAngleMeasure(cas.ca1);
                    double measure2 = known.GetAngleMeasure(cas.ca2);

                    if (measure1 >= 0 && measure2 < 0)
                    {
                        if (known.AddAngleMeasureDegree(cas.ca2, measure1))
                        {
                            addedKnown = true;
                        }
                    }
                    if (measure1 <= 0 && measure2 > 0)
                    {
                        if (known.AddAngleMeasureDegree(cas.ca1, measure2))
                        {
                            addedKnown = true;
                        }
                    }
                    // else: both known
                }
            }

            return(addedKnown);
        }
        public static bool AcquireCongruences(KnownMeasurementsAggregator known, List<GroundedClause> clauses)
        {
            bool addedKnown = false;

            foreach (GeometryTutorLib.ConcreteAST.GroundedClause clause in clauses)
            {
                GeometryTutorLib.ConcreteAST.CongruentSegments cs = clause as GeometryTutorLib.ConcreteAST.CongruentSegments;
                if (cs != null && !cs.IsReflexive())
                {
                    double length1 = known.GetSegmentLength(cs.cs1);
                    double length2 = known.GetSegmentLength(cs.cs2);

                    if (length1 >= 0 && length2 < 0)
                    {
                        if (known.AddSegmentLength(cs.cs2, length1)) addedKnown = true;
                    }
                    if (length1 <= 0 && length2 > 0)
                    {
                        if (known.AddSegmentLength(cs.cs1, length2)) addedKnown = true;
                    }
                    // else: both known
                }

                GeometryTutorLib.ConcreteAST.CongruentAngles cas = clause as GeometryTutorLib.ConcreteAST.CongruentAngles;
                if (cas != null && !cas.IsReflexive())
                {
                    double measure1 = known.GetAngleMeasure(cas.ca1);
                    double measure2 = known.GetAngleMeasure(cas.ca2);

                    if (measure1 >= 0 && measure2 < 0)
                    {
                        if (known.AddAngleMeasureDegree(cas.ca2, measure1)) addedKnown = true;
                    }
                    if (measure1 <= 0 && measure2 > 0)
                    {
                        if (known.AddAngleMeasureDegree(cas.ca1, measure2)) addedKnown = true;
                    }
                    // else: both known
                }
            }

            return addedKnown;
        }
        //
        // (1) Make a copy
        // (2) Collect the equation terms.
        // (3) Are all but one known?
        // (4) Substitute
        // (5) Simplify
        // (6) Acquire the unknown and its value.
        // (7) Add to the list of knowns.
        //
        private static bool HandleArcEquation(KnownMeasurementsAggregator known, List<GroundedClause> clauses, ArcEquation theEq)
        {
            if (theEq.GetAtomicity() == Equation.BOTH_ATOMIC) return HandleSimpleArcEquation(known, theEq);

            // CTA: Verify this calls the correct Equation deep copy mechanism.
            // (1) Make a copy
            ArcEquation copy = (ArcEquation)theEq.DeepCopy();

            // (2) Collect the equation terms.
            List<GroundedClause> left = copy.lhs.CollectTerms();
            double[] leftVal = new double[left.Count];
            List<GroundedClause> right = copy.rhs.CollectTerms();
            double[] rightVal = new double[right.Count];

            // (3) Are all but one term known?
            int unknownCount = 0;
            for (int ell = 0; ell < left.Count; ell++)
            {
                if (left[ell] is NumericValue) leftVal[ell] = (left[ell] as NumericValue).DoubleValue;
                else
                {
                    if (left[ell] is Angle)
                    {
                        leftVal[ell] = known.GetAngleMeasure(left[ell] as Angle);
                        if (leftVal[ell] <= 0) unknownCount++;
                    }
                    else if (left[ell] is Arc)
                    {
                        leftVal[ell] = known.GetArcMeasure(left[ell] as Arc);
                        if (leftVal[ell] <= 0) unknownCount++;
                    }
                }
            }
            for (int r = 0; r < right.Count; r++)
            {
                if (right[r] is NumericValue) rightVal[r] = (right[r] as NumericValue).DoubleValue;
                else
                {
                    if (right[r] is Angle)
                    {
                        rightVal[r] = known.GetAngleMeasure(right[r] as Angle);
                        if (rightVal[r] <= 0) unknownCount++;
                    }
                    else if (right[r] is Arc)
                    {
                        rightVal[r] = known.GetArcMeasure(right[r] as Arc);
                        if (rightVal[r] <= 0) unknownCount++;
                    }
                }
            }

            // We can't solve for more or less than one unknown.
            if (unknownCount != 1) return false;

            //
            // (4) Substitute
            //
            for (int ell = 0; ell < left.Count; ell++)
            {
                if (leftVal[ell] > 0) copy.Substitute(left[ell], new NumericValue(leftVal[ell]));
            }
            for (int r = 0; r < right.Count; r++)
            {
                if (rightVal[r] > 0) copy.Substitute(right[r], new NumericValue(rightVal[r]));
            }

            //
            // (5) Simplify
            //
            ArcEquation simplified = (ArcEquation)GenericInstantiator.Simplification.Simplify(copy);

            return HandleSimpleArcEquation(known, simplified);
        }
        //
        // (1) Make a copy
        // (2) Collect the equation terms.
        // (3) Are all but one known?
        // (4) Substitute
        // (5) Simplify
        // (6) Acquire the unknown and its value.
        // (7) Add to the list of knowns.
        //
        private static bool HandleArcEquation(KnownMeasurementsAggregator known, List <GroundedClause> clauses, ArcEquation theEq)
        {
            if (theEq.GetAtomicity() == Equation.BOTH_ATOMIC)
            {
                return(HandleSimpleArcEquation(known, theEq));
            }

            // CTA: Verify this calls the correct Equation deep copy mechanism.
            // (1) Make a copy
            ArcEquation copy = (ArcEquation)theEq.DeepCopy();

            // (2) Collect the equation terms.
            List <GroundedClause> left = copy.lhs.CollectTerms();

            double[] leftVal            = new double[left.Count];
            List <GroundedClause> right = copy.rhs.CollectTerms();

            double[] rightVal = new double[right.Count];

            // (3) Are all but one term known?
            int unknownCount = 0;

            for (int ell = 0; ell < left.Count; ell++)
            {
                if (left[ell] is NumericValue)
                {
                    leftVal[ell] = (left[ell] as NumericValue).DoubleValue;
                }
                else
                {
                    if (left[ell] is Angle)
                    {
                        leftVal[ell] = known.GetAngleMeasure(left[ell] as Angle);
                        if (leftVal[ell] <= 0)
                        {
                            unknownCount++;
                        }
                    }
                    else if (left[ell] is Arc)
                    {
                        leftVal[ell] = known.GetArcMeasure(left[ell] as Arc);
                        if (leftVal[ell] <= 0)
                        {
                            unknownCount++;
                        }
                    }
                }
            }
            for (int r = 0; r < right.Count; r++)
            {
                if (right[r] is NumericValue)
                {
                    rightVal[r] = (right[r] as NumericValue).DoubleValue;
                }
                else
                {
                    if (right[r] is Angle)
                    {
                        rightVal[r] = known.GetAngleMeasure(right[r] as Angle);
                        if (rightVal[r] <= 0)
                        {
                            unknownCount++;
                        }
                    }
                    else if (right[r] is Arc)
                    {
                        rightVal[r] = known.GetArcMeasure(right[r] as Arc);
                        if (rightVal[r] <= 0)
                        {
                            unknownCount++;
                        }
                    }
                }
            }

            // We can't solve for more or less than one unknown.
            if (unknownCount != 1)
            {
                return(false);
            }

            //
            // (4) Substitute
            //
            for (int ell = 0; ell < left.Count; ell++)
            {
                if (leftVal[ell] > 0)
                {
                    copy.Substitute(left[ell], new NumericValue(leftVal[ell]));
                }
            }
            for (int r = 0; r < right.Count; r++)
            {
                if (rightVal[r] > 0)
                {
                    copy.Substitute(right[r], new NumericValue(rightVal[r]));
                }
            }

            //
            // (5) Simplify
            //
            ArcEquation simplified = (ArcEquation)GenericInstantiator.Simplification.Simplify(copy);

            return(HandleSimpleArcEquation(known, simplified));
        }