예제 #1
0
        public static object Reify(object e, Dictionary <object, object> s)
        {
            if (Var.IsVar(e))
            {
                var tempVar = (Var)e;
                return(s.ContainsKey(tempVar) ? Reify(s[tempVar], s) : e);
            }

            var term = e as Term;

            if (term != null)
            {
                var gArgs = Reify(term.Args, s);
                if (gArgs.Equals(term.Args))
                {
                    return(e);
                }
                else
                {
                    return(new Term(term.Op, gArgs));
                }
            }
            dynamic a = e;

            return(ReifyImpl(a, s));
        }
예제 #2
0
        private static bool SatisfyGoalCondition(Equation eq)
        {
            var  lhs        = eq.Lhs;
            var  rhs        = eq.Rhs;
            bool rhsNumeral = LogicSharp.IsNumeric(rhs);

            return(Var.IsVar(lhs) && rhsNumeral);
        }
예제 #3
0
        public static Dictionary <object, object> ToDict(this EqGoal goal)
        {
            object variable;
            object value;

            if (Var.IsVar(goal.Lhs))
            {
                variable = goal.Lhs;
                value    = goal.Rhs;
            }
            else
            {
                variable = goal.Rhs;
                value    = goal.Lhs;
            }

            var pair       = new KeyValuePair <object, object>(variable, value);
            var substitute = new Dictionary <object, object>();

            substitute.Add(pair.Key, pair.Value);
            return(substitute);
        }
예제 #4
0
        public static bool Unify(object u, object v, Dictionary <object, object> s)
        {
            if (s == null)
            {
                s = new Dictionary <object, object>();
            }

            object tempU = LogicSharp.transitive_get(u, s);
            object tempV = LogicSharp.transitive_get(v, s);

            if (LogicSharp.equal_test(tempU, tempV))
            {
                return(true);
            }

            if (Var.IsVar(tempU) && Var.IsVar(tempV))
            {
                return(tempU.Equals(tempV));
            }

            if (Var.IsVar(tempU))
            {
                LogicSharp.Assoc(s, tempU, tempV);
                return(true);
            }

            if (Var.IsVar(tempV))
            {
                LogicSharp.Assoc(s, tempV, tempU);
                return(true);
            }

            dynamic a = tempU;
            dynamic b = tempV;

            return(UnifyImpl(a, b, s));
        }