예제 #1
0
        public static object Unify(this LineSymbol ls, object constraint)
        {
            var refObj = constraint as string;
            var eqGoal = constraint as EqGoal;

            if (refObj != null)
            {
                #region forward searching

                if (LineAcronym.EqualSlopeLabels(refObj))
                {
                    return(ls.InferSlope(refObj));
                }

                if (LineAcronym.EqualInterceptLabels(refObj))
                {
                    return(ls.InferIntercept(refObj));
                }

                if (LineAcronym.EqualGeneralFormLabels(refObj))
                {
                    return(ls.InferGeneralForm(refObj));
                }

                if (LineAcronym.EqualSlopeInterceptFormLabels(refObj))
                {
                    return(ls.InferSlopeInterceptForm());
                }

                if (LineAcronym.GraphLine.Equals(refObj))
                {
                    return(ls.InferGraph());
                }
                #endregion
            }

            if (eqGoal != null)
            {
                var    rhs = eqGoal.Rhs;
                double dNum;
                bool   isDouble = LogicSharp.IsDouble(rhs, out dNum);
                if (!isDouble)
                {
                    return(null);
                }

                var lhs = eqGoal.Lhs.ToString();

                if (LineAcronym.EqualSlopeLabels(lhs))
                {
                    var obj    = ls.InferSlope(dNum);
                    var lstObj = obj as List <object>;
                    Debug.Assert(lstObj != null);
                    var eqGoal1 = lstObj[0] as EqGoal;
                    if (eqGoal1 != null)
                    {
                        var newTraces = new List <Tuple <object, object> >();
                        newTraces.AddRange(eqGoal.Traces);
                        newTraces.AddRange(eqGoal1.Traces);
                        eqGoal1.Traces = newTraces;
                    }
                    return(obj);
                }
            }
            return(null);
        }