コード例 #1
0
        public TableauxHolder(string Proposition)
        {
            Connective proposition = PropositionReader.ReadPropositionString(Proposition);

            infixString = proposition.GetInfix();

            ConnectiveNot notPorposition = new ConnectiveNot();

            notPorposition.setLeftConnective(proposition);

            TableauxSetElement tse = new TableauxSetElement(notPorposition);

            this.startTableaux = new TableauxSet(new List <TableauxSetElement>()
            {
                tse
            });
            isNormalProposition = notPorposition.IsNormalProposition();
            if (!notPorposition.AreLocalArgumentsMatching(new List <char>(), new List <char>()))
            {
                throw new Exception("Local Arguments are mismatching or there are quantifiers with the same Local Argument");
            }
            calculateFreeArguments(notPorposition);
            Console.WriteLine("Succesfully parsed proposition: " + Proposition);
            Console.WriteLine("Creating tableaux nodes...   (In-Progress Feedback: " + TableauxSet.provideFeedback + ")");
            this.startTableaux.CreateNextSets(new List <char>(), availableArguments, true); //Can be (!isNormalProposition) OR (true)
            this.startTableaux.CalculateIsTautology();
            Console.WriteLine("Succesfully created all teableaux nodes");
        }
コード例 #2
0
        public override bool IsTheSameAs(Connective con)
        {
            if (con is ConnectiveFunction)
            {
                ConnectiveFunction c = (ConnectiveFunction)con;

                if (c.FunctionChar == this.functionChar)
                {
                    if (c.LocalArguments.Count == this.localArguments.Count)
                    {
                        bool differenceFound = false;
                        for (int i = 0; i < this.localArguments.Count; i++)
                        {
                            if (c.LocalArguments[i] != this.localArguments[i])
                            {
                                differenceFound = true;
                                break;
                            }
                        }
                        return(!differenceFound);
                    }
                }
            }
            return(false);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: BasJoosten98/Logic-app
        private bool createAllConHoldersAndTruthtables(string proposition)
        {
            try
            {
                //CREATING PROPOSITION
                Connective con = PropositionReader.ReadPropositionString(proposition);

                if (con.IsNormalProposition())
                {
                    conHolder = new ConnectiveHolder(con);
                    table     = new Truthtable(conHolder);
                    printDisjunctive();

                    conHolderDisjunctive = new ConnectiveHolder(tbDisjunctiveParse.Text);
                    tableDisjunctive     = new Truthtable(conHolderDisjunctive);

                    conHolderDisjunctiveSimple = new ConnectiveHolder(tbDisjunctiveSimpleParse.Text);
                    tableDisjunctiveSimple     = new Truthtable(conHolderDisjunctiveSimple);

                    conHolderNand = conHolder.GetNandHolder();
                    tableNand     = new Truthtable(conHolderNand);

                    conHolderNandSimple = conHolderDisjunctiveSimple.GetNandHolder();
                    tableNandSimple     = new Truthtable(conHolderNandSimple);

                    tbInfix.Text      = conHolder.GetInfixString();
                    tbNand.Text       = conHolderNand.GetParseString();
                    tbNandSimple.Text = conHolderNandSimple.GetParseString();
                    showTableauxTree  = false;

                    //DRAWING AND PRINTING TABLE INFORMATION
                    printVisualTruthtables(table);
                    printTablesInformation();
                }
                else
                {
                    if (!con.AreLocalArgumentsMatching(new List <char>(), new List <char>()))
                    {
                        throw new Exception("Local Arguments are mismatching or there are quantifiers with the same Local Argument");
                    }
                    conHolder        = new ConnectiveHolder(con);
                    tbInfix.Text     = conHolder.GetInfixString();
                    showTableauxTree = false;
                }
                Console.WriteLine("Succesfully parsed proposition: " + proposition);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Parsing failed: please make sure that you wrote a proposition");
                Console.WriteLine("Failed to parse proposition: " + proposition);
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Parsing failed: " + ex.Message);
                Console.WriteLine("Failed to parse proposition: " + proposition);
                return(false);
            }
            return(true);
        }
コード例 #4
0
        //GET NAND CONNECTIVE HOLDER
        public ConnectiveHolder GetNandHolder()
        {
            Connective       startCon = startConnective.GetNandProposition();
            ConnectiveHolder temp     = new ConnectiveHolder(startCon);

            return(temp);
        }
コード例 #5
0
        //READING PROPOSITIONS AND GENERATING CONNECTIVE TREE
        public static Connective ReadPropositionString(string proposition)
        {
            PropositionList = proposition.ToList <char>();
            Connective result = null;

            result = readPropositionStringRec();
            return(result);
        }
コード例 #6
0
 public ConnectiveHolder(Connective con)
 {
     if (con != null)
     {
         startConnective = con;
     }
     else
     {
         throw new NullReferenceException();
     }
 }
コード例 #7
0
 public override void setRightConnective(Connective con)
 {
     if (con != null)
     {
         con2 = con;
     }
     else
     {
         throw new NullReferenceException();
     }
 }
コード例 #8
0
 //CALCULATE USED/AVAILABLE ARGUMENTS
 private void calculateFreeArguments(Connective startCon)
 {
     usedArguments      = startCon.GetAllLocalArguments();
     availableArguments = new List <char>();
     foreach (char c in SmallArguments)
     {
         if (!usedArguments.Contains(c))
         {
             availableArguments.Add(c);
         }
     }
 }
コード例 #9
0
        //CREATING CONNECTIVE/TABLEAUX TREE PICTURE
        public static string CreateStructurePicture(Connective startCon)
        {
            if (startCon == null)
            {
                throw new NullReferenceException();
            }
            //Console.WriteLine("PropositionReader: creating structure picture");
            List <Connective> allConnectives = startCon.GetAllConnectives();

            FileStream   fs;
            StreamWriter sw;
            string       fileName = "abc.dot";

            try
            {
                fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                sw = new StreamWriter(fs);
                sw.WriteLine("graph calculus {");
                sw.WriteLine("node [ fontname = \"Arial\" ]");

                for (int i = 0; i < allConnectives.Count; i++)
                {
                    sw.WriteLine("node" + (allConnectives[i].ID) + " [ label = \"" + allConnectives[i].GetLocalString() + "\" ]");
                    //if (allNodes[i].Parent != null)
                    //{
                    //    sw.WriteLine("node" + (allNodes[i].Parent.ID) + " -- node" + (allNodes[i].ID));
                    //}
                    //if (allConnectives[i].Con1 != null)
                    //{
                    //    sw.WriteLine("node" + (allConnectives[i].ID) + " -- node" + (allConnectives[i].Con1.ID));
                    //}
                    //if (allConnectives[i].Con2 != null)
                    //{
                    //    sw.WriteLine("node" + (allConnectives[i].ID) + " -- node" + (allConnectives[i].Con2.ID));
                    //}
                    if (allConnectives[i] is ConnectiveOne)
                    {
                        sw.WriteLine("node" + (allConnectives[i].ID) + " -- node" + ((ConnectiveOne)allConnectives[i]).Con1.ID);
                    }
                    if (allConnectives[i] is ConnectiveTwo)
                    {
                        sw.WriteLine("node" + (allConnectives[i].ID) + " -- node" + ((ConnectiveTwo)allConnectives[i]).Con2.ID);
                    }
                }
                sw.WriteLine("}");
                sw.Close();
            }
            catch (IOException)
            {
                throw new Exception("Structure picture failed");
            }
            return(CreateDotPNG(fileName));
        }
コード例 #10
0
        public override bool IsTheSameAs(Connective con)
        {
            if (con is ConnectiveArgument)
            {
                ConnectiveArgument c = (ConnectiveArgument)con;

                if (c.Argument == this.argument)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #11
0
        public override bool IsTheSameAs(Connective con)
        {
            if (con is QuantifierExists)
            {
                QuantifierExists c = (QuantifierExists)con;

                if (con1.IsTheSameAs(c.Con1))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #12
0
        public override bool IsTheSameAs(Connective con)
        {
            if (con is ConnectiveImplication)
            {
                ConnectiveTwo c = (ConnectiveTwo)con;

                if (con1.IsTheSameAs(c.Con1) && con2.IsTheSameAs(c.Con2))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #13
0
 public ConnectiveHolder(string proposition)
 {
     if (proposition != null)
     {
         Connective con = PropositionReader.ReadPropositionString(proposition);
         if (con != null)
         {
             startConnective = con;
         }
         else
         {
             throw new NullReferenceException();
         }
     }
     else
     {
         throw new NullReferenceException();
     }
 }
コード例 #14
0
        //CREATING A NEW VARIABLE NEEDED
        public List <Connective> ApplyDeltaTableauxRules(List <char> usedArguments, List <char> availableArguments)
        {
            List <Connective> results = new List <Connective>();

            if (element.IsNormalProposition())
            {
                return(results);
            }

            if (element is QuantifierExists)
            {
                QuantifierExists qe     = (QuantifierExists)element;
                QuantifierExists qeCopy = (QuantifierExists)element.Copy();

                char qeArgument = qe.Argument;
                if (availableArguments.Count > 0)
                {
                    if (qeCopy.ChangeLocalArgument(qeArgument, availableArguments[0]))
                    {
                        usedArguments.Add(availableArguments[0]);
                        availableArguments.RemoveAt(0);

                        Connective newElement = qeCopy.Con1;
                        results.Add(newElement);
                    }
                }
                else
                {
                    throw new Exception("Not enough available arguments");
                }
            }
            else if (element is ConnectiveNot)
            {
                ConnectiveNot cn = (ConnectiveNot)element;

                if (cn.Con1 is QuantifierForAll)
                {
                    QuantifierForAll qfa     = (QuantifierForAll)cn.Con1;
                    QuantifierForAll qfaCopy = (QuantifierForAll)cn.Con1.Copy();

                    char qfaArgument = qfa.Argument;
                    if (availableArguments.Count > 0)
                    {
                        if (qfaCopy.ChangeLocalArgument(qfaArgument, availableArguments[0]))
                        {
                            usedArguments.Add(availableArguments[0]);
                            availableArguments.RemoveAt(0);

                            ConnectiveNot newNot = new ConnectiveNot();
                            newNot.setLeftConnective(qfaCopy.Con1);
                            Connective newElement = newNot;
                            results.Add(newElement.Copy());
                        }
                    }
                    else
                    {
                        throw new Exception("Not enough available arguments");
                    }
                }
            }
            return(results);
        }
コード例 #15
0
 public abstract void setRightConnective(Connective con);
コード例 #16
0
ファイル: Connective.cs プロジェクト: BasJoosten98/Logic-app
 public abstract bool IsTheSameAs(Connective con);
コード例 #17
0
 public TableauxSetElement(Connective con)
 {
     this.element = con;
 }
コード例 #18
0
        private static Connective readPropositionStringRec()
        {
            Connective Head  = null;
            int        index = 0;


            while (PropositionList.Count != 0)
            {
                switch (PropositionList[0])
                {
                case ',':
                    //ERROR CHECKING
                    if (index == 0)
                    {
                        throw new Exception("',' has not been placed between '(' and ')'");
                    }
                    if (Head != null)
                    {
                        if (Head is ConnectiveNot || Head is ConnectiveArgument)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' does not need more than 2 parameters");
                        }
                        if (Head is ConnectiveOne)
                        {
                            if (((ConnectiveOne)Head).Con1 == null)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                            }
                        }
                        if (Head is ConnectiveFunction)
                        {
                            if (((ConnectiveFunction)Head).LocalArguments.Count != index)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a parameter");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("',' does not belong to any connective");
                    }

                    //SET INDEX
                    index++;
                    PropositionList.RemoveAt(0);
                    break;

                case '(':
                    //ERROR CHECKING
                    if (Head == null)
                    {
                        throw new Exception("'(' does not belong to any connective");
                    }
                    if (Head is ConnectiveArgument)
                    {
                        throw new Exception("'" + Head.GetLocalString() + "' cannot have any parameters");
                    }

                    //SET INDEX
                    index = 1;
                    PropositionList.RemoveAt(0);
                    break;

                case ')':
                    //ERROR CHECKING
                    if (index == 1)
                    {
                        if (Head is ConnectiveArgument)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' cannot have any parameters");
                        }
                        if (Head is ConnectiveOne)
                        {
                            if (((ConnectiveOne)Head).Con1 == null)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                            }
                        }
                        if (Head is ConnectiveFunction)
                        {
                            if (((ConnectiveFunction)Head).LocalArguments.Count == 0)
                            {
                                throw new Exception("Function '" + Head.GetLocalString() + "' is missing parameters");
                            }
                        }
                    }
                    else if (index == 2)
                    {
                        if (Head is ConnectiveNot || Head is ConnectiveArgument)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' cannot have 2 paramters, only 1");
                        }
                        if (Head is ConnectiveTwo)
                        {
                            if (((ConnectiveTwo)Head).Con2 == null)
                            {
                                throw new Exception("'" + Head.GetLocalString() + "' is missing a right connective");
                            }
                        }
                    }

                    PropositionList.RemoveAt(0);
                    return(Head);

                default:
                    if (ConnectiveTypes.Contains(PropositionList[0]))     //type found
                    {
                        Connective con;
                        switch (index)
                        {
                        case 0:
                            if (Head == null)
                            {
                                con  = getConnectiveByType(PropositionList[0]);
                                Head = con;
                                if (Head is ConnectiveQuantifier)
                                {
                                    if (PropositionList.Count >= 3)
                                    {
                                        ConnectiveQuantifier cq = (ConnectiveQuantifier)Head;
                                        if (SmallArguments.Contains(PropositionList[1]))
                                        {
                                            cq.SetArgument(PropositionList[1]);
                                            PropositionList.RemoveAt(0);         //removes @/!
                                            PropositionList.RemoveAt(0);         //removes local argument
                                        }
                                        else
                                        {
                                            throw new Exception("Invalid local variable '" + PropositionList[1] + "' for quantifier: " + PropositionList[0]);
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("Unfinished quantifier: " + PropositionList[0]);
                                    }
                                }
                                PropositionList.RemoveAt(0);         //removes type or .
                            }
                            else
                            {
                                throw new Exception("'" + PropositionList[0] + "' cannot be placed after another connective");
                            }
                            break;

                        case 1:
                            if (Head != null)
                            {
                                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                                {
                                    con = readPropositionStringRec();
                                    ((ConnectiveOne)Head).setLeftConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' does not need any connectives as parameters");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 1, Head = null)");
                            }
                            break;

                        case 2:
                            if (Head != null)
                            {
                                if (Head is ConnectiveTwo)
                                {
                                    con = readPropositionStringRec();
                                    ((ConnectiveTwo)Head).setRightConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' cannot have a second parameter");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 2, Head = null)");
                            }
                            break;

                        default:
                            throw new Exception("Internal index problem occured (index > 2 & head != function)");
                        }
                    }
                    else if (Arguments.Contains(PropositionList[0]))     //argument found
                    {
                        Connective con;
                        con = new ConnectiveArgument(PropositionList[0]);
                        if (PropositionList.Count > 1)
                        {
                            if (PropositionList[1] == '(')
                            {
                                con = new ConnectiveFunction();
                                ((ConnectiveFunction)con).SetFunctionChar(PropositionList[0]);
                            }
                        }

                        switch (index)
                        {
                        case 0:
                            if (Head == null)
                            {
                                PropositionList.RemoveAt(0);
                                Head = con;
                            }
                            else
                            {
                                throw new Exception("'" + PropositionList[0] + "' cannot be placed after another connective");
                            }
                            break;

                        case 1:
                            if (Head != null)
                            {
                                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                                {
                                    if (con is ConnectiveFunction)
                                    {
                                        con = readPropositionStringRec();
                                    }
                                    else
                                    {
                                        PropositionList.RemoveAt(0);
                                    }
                                    ((ConnectiveOne)Head).setLeftConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' cannot have Argument as parameter");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 1, Head = null)");
                            }
                            break;

                        case 2:
                            if (Head != null)
                            {
                                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                                {
                                    if (con is ConnectiveFunction)
                                    {
                                        con = readPropositionStringRec();
                                    }
                                    else
                                    {
                                        PropositionList.RemoveAt(0);
                                    }
                                    ((ConnectiveTwo)Head).setRightConnective(con);
                                }
                                else
                                {
                                    throw new Exception("'" + Head.GetLocalString() + "' cannot have Argument as parameter");
                                }
                            }
                            else
                            {
                                throw new Exception("Internal index problem occured (index = 2, Head = null)");
                            }
                            break;

                        default:
                            throw new Exception("Internal index problem occured (index > 2 & Head != Function)");
                        }
                    }
                    else if (SmallArguments.Contains(PropositionList[0]))
                    {
                        if (Head != null)
                        {
                            if (Head is ConnectiveFunction)
                            {
                                ConnectiveFunction cf = (ConnectiveFunction)Head;
                                cf.AddArgument(PropositionList[0]);
                                PropositionList.RemoveAt(0);
                            }
                            else
                            {
                                throw new Exception("Local Argument found outside Function/Quantifier: " + PropositionList[0]);
                            }
                        }
                        else
                        {
                            throw new Exception("Local Argument found outside Function/Quantifier: " + PropositionList[0]);
                        }
                    }
                    else if (PropositionList[0] != ' ')    //UNKNOWN (no space)
                    {
                        throw new Exception("Unknown character found, char: '" + PropositionList[0] + "'. Please remove it!");
                    }
                    else     //SPACE
                    {
                        PropositionList.RemoveAt(0);
                    }
                    break;
                }
            }
            //Final check for main connective
            if (Head != null)
            {
                if (!(Head is ConnectiveArgument || Head is ConnectiveFunction))
                {
                    if (Head is ConnectiveNot || Head is ConnectiveQuantifier)
                    {
                        if (((ConnectiveOne)Head).Con1 == null)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                        }
                    }
                    else
                    {
                        if (((ConnectiveTwo)Head).Con1 == null)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' is missing a left connective");
                        }
                        if (((ConnectiveTwo)Head).Con2 == null)
                        {
                            throw new Exception("'" + Head.GetLocalString() + "' is missing a right connective");
                        }
                    }
                }
            }
            return(Head);
        }
コード例 #19
0
 public abstract void setLeftConnective(Connective con);