Beispiel #1
0
        internal object change_variable(string this_one, function to_this)
        {
            ArrayList old_args = new ArrayList(_arguments);
            ArrayList new_args = new ArrayList();

            while (old_args.Count > 0)
            {
                if (old_args[0] is function)
                {
                    function fun = new function((function)old_args[0]);
                    old_args[0] = fun.change_variable(this_one, to_this);
                }

                else if ((string)old_args[0] == this_one)
                {
                    new_args.Add(to_this);
                }
                else
                {
                    new_args.Add(old_args[0]);
                }

                old_args.RemoveAt(0);
            }

            function f = new function(name, new_args);

            return(f);
        }
Beispiel #2
0
        public formula change_variable(string this_one, function to_this)
        {
            formula new_expression = new formula();

            if (!this.is_Predicate)
            {
                if (top_operation is dis)
                {
                    new_expression = first_operand.change_variable(this_one, to_this) | second_operand.change_variable(this_one, to_this);
                }
                else if (top_operation is kon)
                {
                    new_expression = first_operand.change_variable(this_one, to_this) & second_operand.change_variable(this_one, to_this);
                }
                else if (top_operation is quantifier)
                {
                    new_expression = this;
                    new_expression = new_expression.first_operand.change_variable(this_one, to_this);
                    new_expression.logical_exp.Insert(0, top_operation);
                    return(new_expression);
                }

                //скорее всего здесь предикатное выражение, посему:
                if (first_operand.is_Predicate)
                {
                    Predicate Pred = new Predicate((Predicate)first_operand.logical_exp[0]);
                    for (int i = 0; i < Pred.arguments.Count; i++)
                    {
                        if ((string)Pred.arguments[i] == this_one)
                        {
                            Pred.arguments[i] = to_this;
                        }
                        if (Pred.arguments[i] is function)
                        {
                            function f = new function((function)Pred.arguments[i]);
                            Pred.arguments[i] = f.change_variable(this_one, to_this);
                        }
                    }
                    //new_expression.logical_exp.Add(Pred);
                }
                if (second_operand.is_Predicate)
                {
                    Predicate Pred = new Predicate((Predicate)second_operand.logical_exp[0]);
                    for (int i = 0; i < Pred.arguments.Count; i++)
                    {
                        if (Pred.arguments[i] is function)
                        {
                            function f = new function((function)Pred.arguments[i]);
                            Pred.arguments[i] = f.change_variable(this_one, to_this);
                        }
                        else if ((string)Pred.arguments[i] == this_one)
                        {
                            Pred.arguments[i] = to_this;
                        }
                    }
                    //new_expression.logical_exp.Add(Pred);
                }
            }
            else
            {
                Predicate Pred = new Predicate((Predicate)this.logical_exp[0]);
                for (int i = 0; i < Pred.arguments.Count; i++)
                {
                    if (Pred.arguments[i] is function)
                    {
                        function f = new function((function)Pred.arguments[i]);
                        Pred.arguments[i] = f.change_variable(this_one, to_this);
                    }
                    else if ((string)Pred.arguments[i] == this_one)
                    {
                        Pred.arguments[i] = to_this;
                    }
                }
                new_expression.logical_exp.Add(Pred);
            }

            return(new_expression);
        }