public void AddEquation(ILogicElement x1, ILogicElement x2)
        {
            LogicElement t1 = x1.ToLogicElement();
            LogicElement t2 = x2.ToLogicElement();

            if (t1 is Function <WorldSymbol> f1 && t2 is Function <WorldSymbol> f2)
            {
                AddFunctionEquation(f1, f2);
            }
            else if (t1 is Function <Terminal> f3 && t2 is Function <Terminal> f4)
            {
                AddFunctionEquation(f3, f4);
            }

            //Rule 3 [x = x -> Cancel Equation]
            if (t1.Name == t2.Name)
            {
                return;
            }

            //Rule 4 [t = x -> x = t]
            if (t1.GetType() == typeof(Variable) && t2.GetType() != typeof(Variable))
            {
                equations.Add(new Equation <ILogicElement>(x2, x1));
            }
            else
            {
                equations.Add(new Equation <ILogicElement>(x1, x2));
            }
        }
示例#2
0
        public void Substitute(ILogicElement item, ILogicElement logicElement)
        {
            var newParams = new List <T>(Parameters);

            foreach (var param in Parameters)
            {
                LogicElement originalParam = null;

                if (param is ILogicElement originalParamBox)
                {
                    originalParam = originalParamBox.ToLogicElement();
                }

                else if (param is LogicElement originalPar)
                {
                    originalParam = originalPar;
                }

                if (originalParam.Name == item.ToLogicElement().Name)
                {
                    newParams[Parameters.IndexOf(param)] = (T)logicElement;
                }

                Parameters = newParams;
            }
        }