Пример #1
0
        public function rename_variable(string this_one, string to_that)
        {
            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.rename_variable(this_one, to_that);
                }

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

                old_args.RemoveAt(0);
            }

            function f = new function(name, new_args);

            return(f);
        }
Пример #2
0
        public formula make_SSF()
        {
            if (this.is_PNF)
            {
                formula ssf = new formula();
                if (this.top_operation is quantifier)
                {
                    int       all_quantors       = 0;
                    int       existance_quantors = -1;
                    ArrayList all_variables      = new ArrayList();
                    ArrayList quantifiers        = new ArrayList();
                    while (this.is_quantum_expression && top_operation is quantifier)
                    {
                        quantifier K = new quantifier((quantifier)this.top_operation);
                        if (K.is_universality)
                        {
                            all_quantors++;
                            quantifiers.Add(K);
                            this.logical_exp.RemoveAt(0);
                            all_variables.Add(K.variable);
                        }
                        else // if (K.is_existance)
                        {
                            existance_quantors++;
                            if (all_quantors == 0)
                            {
                                this.logical_exp.RemoveAt(0);
                                this.rename_variable(K.variable, "const");
                            }
                            else
                            {
                                this.logical_exp.RemoveAt(0);
                                function scolem = new function("s" + existance_quantors, all_variables);
                                ssf = this.change_variable(K.variable, scolem);
                            }
                        }
                    }
                    ssf.logical_exp.InsertRange(0, quantifiers);
                }
                else
                {
                    return(ssf);
                }

                return(ssf);
            }
            else
            {
                MessageBox.Show("Для сколемизации формула должна быть в ПНФ!", "Ошибка");
                return(this);
            }
        }
        public static ArrayList predicate_arguments(ref string str, bool del = false)
        {
            ArrayList args = new ArrayList();

            if (str[0] == ')') //найдена закрывающая скобка => дальше пойдёт функция
            {
                function f = get_function(ref str, true);
                args.Add(f);
                if (str[0] == ',') //запятая между аргументами
                {
                    str = str.Substring(1);
                }
                if (str != "" && str[0] != '(' && str[0] != ',')
                {
                    args.InsertRange(0, predicate_arguments(ref str, true));
                }
            }
            else //нету никакой лишней скобки
            {
                char[] invalid_symbols = { ',', '(' };
                string argument        = str.Substring(0, str.IndexOfAny(invalid_symbols)); //имена аргументов (это может быть константа или переменная) разделены запятыми
                string argument_name   = Name(ref argument, true);                          //выделим имя аргумента, если оно записано правильно
                args.Add(argument_name);                                                    //добавим элемент с таким именем

                if (del)
                {
                    str = str.Substring(str.IndexOfAny(invalid_symbols)); //если надо - удалим только что полученный аргумент из строки
                }
                if (str[0] == ',')                                        //запятая между аргументами
                {
                    str = str.Substring(1);
                }
                if (str != "" && str[0] != '(' && str[0] != ',')
                {
                    args.InsertRange(0, predicate_arguments(ref str, true));
                }
            }

            return(args);
        }
        public static function get_function(ref string str, bool del = false)
        {
            function fun = new function();

            fun.arguments = function_arguments(ref str, true);
            str           = str.Substring(1);
            char[] invalid_symbols = { ',', '(' };
            string probably_name   = str.Substring(0, str.IndexOfAny(invalid_symbols)); //после открывающей скобки идет имя функции, от других аргументов его отделяет запятая

            fun.name = Name(ref probably_name, true);                                   //выделим его, если оно записано правильно

            if (del)
            {
                str = str.Substring(str.IndexOfAny(invalid_symbols)); //если надо, удалаем и имя
                if (str[0] == ',')
                {
                    str = str.Substring(1);
                }
            }

            return(fun);
        }
Пример #5
0
        public formula rename_variable(string that_one, string to_this_one)
        {
            formula new_expression = new formula();

            if (!this.is_Predicate)
            {
                if (top_operation is dis)
                {
                    new_expression = first_operand.rename_variable(that_one, to_this_one) | second_operand.rename_variable(that_one, to_this_one);
                }
                else if (top_operation is kon)
                {
                    new_expression = first_operand.rename_variable(that_one, to_this_one) & second_operand.rename_variable(that_one, to_this_one);
                }
                else if (top_operation is quantifier)
                {
                    new_expression = this;
                    new_expression = new_expression.first_operand.rename_variable(that_one, to_this_one);
                    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] == that_one)
                        {
                            Pred.arguments[i] = to_this_one;
                        }
                        if (Pred.arguments[i] is function)
                        {
                            function f = new function((function)Pred.arguments[i]);
                            Pred.arguments[i] = f.rename_variable(that_one, to_this_one);
                        }
                    }
                    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.rename_variable(that_one, to_this_one);
                        }
                        else if ((string)Pred.arguments[i] == that_one)
                        {
                            Pred.arguments[i] = to_this_one;
                        }
                    }
                    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.rename_variable(that_one, to_this_one);
                    }
                    else if ((string)Pred.arguments[i] == that_one)
                    {
                        Pred.arguments[i] = to_this_one;
                    }
                }
                new_expression.logical_exp.Add(Pred);
            }

            return(new_expression);
        }
Пример #6
0
 public function(function copy)
 {
     _name      = copy.name;
     _arguments = new ArrayList(copy.arguments);
 }