Esempio n. 1
0
 public override Term ApplySubstitution(ref Substitution s)
 {
     for (int i = 0; i < Arity; i++)
     {
         Args[i] = Args[i].Replace(s.T1.ToString(), s.T2.ToString());
     }
     //Regex.Replace(Args[i], ( s.T1.ToString() + "\\b"), s.T2.ToString());
     return(this);
 }
Esempio n. 2
0
 public override Term ApplySubstitution(ref Substitution s)
 {
     Content = //Regex.Replace(Content, (s.T1.ToString() + "\\b"), s.T2.ToString());
               Content.Replace(s.T1.ToString(), s.T2.ToString());
     return(this);
 }
Esempio n. 3
0
 public virtual Term ApplySubstitution(ref Substitution s)
 {
     return(this);
 }
Esempio n. 4
0
        private static List <Substitution> UnifyArgs(ref Term e1, ref Term e2, ref List <Substitution> subs)
        {
            if (subs == null)
            {
                subs = new List <Substitution>();
            }

            if (e1.Empty() && e2.Empty())
            {
                return(subs);
            }

            if (e1.Func() && e2.Func())
            {
                if (((Function)e1).Arity != ((Function)e2).Arity)
                {
                    return(null);
                }
            }
            //if (e1.Constant() && e2.Constant()) return e1.ToString().Equals(e2.ToString()) ? subs : null;

            //if variable(E1) / if variable(E2)
            if (e1.Var())
            {
                if (e2.Var())
                {
                    if (((SimpleTerm)e1).Equals((SimpleTerm)e2))
                    {
                        return(subs);
                    }
                    else if (((SimpleTerm)e1).OccursIn(ref e2))
                    {
                        return(null);
                    }
                }
                //else {
                var s = new Substitution(ref e1, ref e2);
                //if (!subs.Contains(s)) {
                subs.Add(s);
                subs.TrimExcess();
                //}
                s = null;
                return(subs);
                //}
            }
            if (e2.Var())
            {
                if (e1.Var())
                {
                    if (((SimpleTerm)e2).Equals((SimpleTerm)e1))
                    {
                        return(subs);
                    }
                    else if (((SimpleTerm)e2).OccursIn(ref e1))
                    {
                        return(null);
                    }
                }
                //else {
                var s = new Substitution(ref e2, ref e1);
                //if (!subs.Contains(s)) {
                subs.Add(s);
                subs.TrimExcess();
                //}
                s = null;
                return(subs);
                //}
            }
            else
            {
                var HE1 = ((Function)e1).Head();
                var HE2 = ((Function)e2).Head();

                var SUBS1 = UnifyArgs(ref HE1, ref HE2, ref subs);
                HE1 = HE2 = null;

                if (SUBS1 == null)
                {
                    return(null);
                }

                var TE1 = ((Function)e1).Tail().ApplySubstitution(ref SUBS1, Performed);
                var TE2 = ((Function)e2).Tail().ApplySubstitution(ref SUBS1, Performed);
                SUBS1 = null;
                Performed++;

                var SUBS2 = UnifyArgs(ref TE1, ref TE2, ref subs);

                TE1 = TE2 = null;

                return(SUBS2 == null ? null : subs);
            }
        }