Esempio n. 1
0
        // Truth Table
        public List <List <string> > GetTruthTable()
        {
            try
            {
                if (PropositionNode == null)
                {
                    return(null);
                }

                List <List <string> > allRows = new List <List <string> >();

                List <string> header = PropositionNode.GetVariables().OrderBy(c => c).Select(c => c.ToString()).ToList();

                header.Add(PropositionNode.ToString());
                allRows.Add(header);

                int noPrepositions = header.Count - 1;
                int rows           = (int)Math.Pow(2, noPrepositions);

                for (int i = 0; i < rows; i++)
                {
                    List <string> row = new List <string>();
                    string        x   = Convert.ToString(i, 2);
                    if (x.Count() < noPrepositions)
                    {
                        while (x.Count() != noPrepositions)
                        {
                            x = x.Insert(0, "0");
                        }
                    }

                    char[] array = x.ToCharArray();

                    for (int j = 0; j < noPrepositions; j++)
                    {
                        char character = header[j].First();
                        bool boolValue = array[j] == '1';
                        PropositionNode.SetValue(character, boolValue);
                        row.Add(array[j].ToString());
                    }

                    if (PropositionNode.CheckTruthSign() == false)
                    {
                        row.Add("0");
                    }
                    else
                    {
                        row.Add("1");
                    }

                    allRows.Add(row);
                }

                return(allRows);
            } catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 2
0
 //NANDIFY
 public string GetNandifyService()
 {
     try
     {
         return(PropositionNode.GetNandify());
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 3
0
        public void TautologyCheckInListOfTableuxNode()
        {
            PropositionNode propNode = new PropositionNode('R'.ToString());

            NotNode notNode = new NotNode();

            notNode.left = Functions.DeepCopyTree(propNode);

            PropositionNode p2 = new PropositionNode('Q'.ToString());

            List <Node> list = new List <Node> {
                propNode, notNode, p2
            };

            Assert.True(TableuxNode.IsTautology(list));
        }
Esempio n. 4
0
        /// <summary>
        /// A method that is called to actually build a tree from a given input. Is called from ProcessStringInput()
        /// </summary>
        /// <param name="input">input string</param>
        /// <param name="root">Node used in recursion for creating a binary tree</param>
        /// <exception cref="Exception"></exception>
        private void BuildTree(string input, Node root)
        {
            if (input == string.Empty)
            {
                return;
            }

            char first_character = input[0];

            if (first_character == '~')
            {
                NotNode node = new NotNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '>')
            {
                ImplicationNode node = new ImplicationNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '=')
            {
                BiImplicationNode node = new BiImplicationNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '&')
            {
                ConjunctionNode node = new ConjunctionNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '|')
            {
                DisjunctionNode node = new DisjunctionNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == '%')
            {
                NandNode node = new NandNode(input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (Char.IsUpper(first_character) && input[1] == '(')
            {
                /* predicate case */
                /* P(x), Q(x) */

                int closingBracketIndex = GetIndexOfClosingBracket(input, 1);

                var vars = QuantifierInputHandler.StringStartEndIndex(input, 2, closingBracketIndex - 1).Split(',');

                PredicateNode predicate = new PredicateNode(first_character);

                List <PropositionNode> propositions = new List <PropositionNode>();

                foreach (var variable in vars)
                {
                    propositions.Add(new PropositionNode(variable));
                }

                predicate.Formulas = propositions;

                root.Insert(predicate);
                predicate.parent = root;

                input = input.Substring(closingBracketIndex + 1);

                BuildTree(input, predicate);
            }
            else if (first_character == '@' || first_character == '!')
            {
                string quantifierInput = QuantifierInputHandler.ParseOutInputForQuantifiers(input);
                QuantifierInputHandler quantifierInputHandler = new QuantifierInputHandler(quantifierInput);
                var node = quantifierInputHandler.Create();

                node.parent = root;

                root.Insert(node);

                var newInput = input.Substring(IndexTillWhichStringAreSame(quantifierInput, input) + 1);

                BuildTree(newInput, node);
            }
            else if (first_character == ',')
            {
                if (root.parent == null)
                {
                    throw new Exception("Error in your input");
                }

                root  = root.parent;
                input = input.Substring(1);
                BuildTree(input, root);
            }
            else if (Char.IsLetter(first_character))
            {
                PropositionNode node = new PropositionNode(first_character.ToString(), input, root);
                root.Insert(node);
                BuildTree(node.Value, node);
            }
            else if (first_character == ')')
            {
                int numberOflevels = CalculateNumberOfLevelsToGoUp(input);

                for (int i = 0; i < numberOflevels; i++)
                {
                    if (root.parent != null)
                    {
                        root = root.parent;
                    }
                    else
                    {
                        throw new Exception("Error in string input. Source: class Processor, method BuildTree, else if (')')");
                    }
                }

                input = input.Substring(numberOflevels);
                BuildTree(input, root);
            }
            else if (first_character == '(')
            {
                input = input.Substring(1);
                BuildTree(input, root);
            }
        }
Esempio n. 5
0
 public List <char> GetVariables()
 {
     return(PropositionNode.GetVariables());
 }