Пример #1
0
 private void btnParse_Click(object sender, EventArgs e)
 {
     try
     {
         if (sender is MenuItem)
         {
             string prop = ((ContextMenu)((MenuItem)sender).Parent).SourceControl.Text;
             tbInput.Text = prop;
             n            = parser.ParseExpression(prop);
         }
         else
         {
             n = parser.ParseExpression(tbInput.Text);
         }
         if (n != null)
         {
             lbInfo.Items.Clear();
             tbPrefix.Text = n.ToPrefixString();
             tbInfix.Text  = n.ToString();
             GenerateVariableString();
             if (IsProposition())
             {
                 ShowTruthTable();
             }
             ShowST();
         }
     }
     catch (Exception ex)
     {
         DirectMessage.ShowError(ex.Message);
     }
 }
Пример #2
0
        private bool ApplyGammaRules()
        {
            string         rule  = "Gamma rule";
            HashSet <Node> nodes = new HashSet <Node>();

            foreach (Node n in propositions)
            {
                if (n is UniversalQuantifier)
                {
                    UniversalQuantifier quantifier = (UniversalQuantifier)n;
                    //add predicates for existing variables
                    foreach (char var in ActiveVariables)
                    {
                        try
                        {
                            UniversalQuantifier newQuantifier = (UniversalQuantifier)quantifier.Copy().ReplaceObjectVariableNewNode(quantifier.Variable, var);
                            if (quantifier != null)
                            {
                                nodes.Add(newQuantifier.Proposition);
                            }
                        }
                        catch (Exception ex) { DirectMessage.ShowError(ex.Message); }
                    }
                }
                else if (n is NegationSign && ((NegationSign)n).ReturnChildNode() is ExistentialQuantifier)
                {
                    ExistentialQuantifier quantifier = (ExistentialQuantifier)((NegationSign)n).ReturnChildNode();
                    //add predicates for existing variables
                    foreach (char var in ActiveVariables)
                    {
                        try
                        {
                            ExistentialQuantifier newQuantifier = (ExistentialQuantifier)quantifier.Copy().ReplaceObjectVariableNewNode(quantifier.Variable, var);
                            if (quantifier != null)
                            {
                                nodes.Add(new NegationSign(newQuantifier.Proposition));
                            }
                        }
                        catch (Exception ex) { DirectMessage.ShowError(ex.Message); }
                    }
                }
                else
                {
                    continue;
                }
            }
            if (nodes.Count > 0 && !nodes.IsSubsetOf(propositions))
            {
                nodes.UnionWith(propositions);
                leftNode = new STElement(nodes, ActiveVariables, rule);
                SimplifyChild(leftNode);
                return(true);
            }
            return(false);
        }
Пример #3
0
        private bool ApplyDeltaRules()
        {
            string rule = "Delta rule";

            foreach (Node n in propositions)
            {
                if (n is ExistentialQuantifier)
                {
                    HashSet <Node> props = new HashSet <Node>(propositions);
                    props.Remove(n);
                    //change variable
                    List <char> newVariables = AddNewVariable();
                    try
                    {
                        ExistentialQuantifier quantifier = (ExistentialQuantifier)n.Copy();
                        quantifier.ReplaceObjectVariable(quantifier.Variable, newVariables[newVariables.Count - 1]);
                        HashSet <Node> nodes = new HashSet <Node> {
                            quantifier.Proposition
                        };
                        props.UnionWith(nodes);
                        leftNode = new STElement(props, newVariables, rule);
                        SimplifyChild(leftNode);
                        return(true);
                    }
                    catch (Exception ex) { DirectMessage.ShowError(ex.Message); }
                }
                else if (n is NegationSign && ((NegationSign)n).ReturnChildNode() is UniversalQuantifier)
                {
                    HashSet <Node> props = new HashSet <Node>(propositions);
                    props.Remove(n);
                    //change variable
                    List <char> newVariables = AddNewVariable();
                    try
                    {
                        UniversalQuantifier quantifier = (UniversalQuantifier)((NegationSign)n).ReturnChildNode().Copy();
                        quantifier.ReplaceObjectVariable(quantifier.Variable, newVariables[newVariables.Count - 1]);
                        HashSet <Node> nodes = new HashSet <Node> {
                            new NegationSign(quantifier.Proposition)
                        };
                        props.UnionWith(nodes);
                        leftNode = new STElement(props, newVariables, rule);
                        SimplifyChild(leftNode);
                        return(true);
                    }
                    catch (Exception ex) { DirectMessage.ShowError(ex.Message); }
                }
                else
                {
                    continue;
                }
            }
            return(false);
        }