コード例 #1
0
        /// <summary>
        /// Implies when run, evaluates left hand side and right hand side then sets itself
        /// this is the a result, True, the argument is valid and false it is not valid.
        /// Unknown will have to be taken as invalid. If all steps in the argument are valid
        /// then we should have a good argument
        /// implies testing
        /// p --> q
        /// 1  1  1
        /// 1  0  0
        /// 0  1  1
        /// 0  1  0
        /// X  1  1
        /// X  0  X
        /// 1  X  X
        /// 0  X  1
        /// X  X  X
        /// </summary>
        /// <param name="element"></param>
        /// <param name="predicateState"></param>
        /// <returns></returns>
        public static PredicateList execute(ImplicationSyntacticExpression element, PredicateList predicateState)
        {
            bool?lhs = ExpressionExecutive.Evaluate(element.lhs, predicateState);
            bool?rhs = ExpressionExecutive.Evaluate(element.rhs, predicateState);

            element.Value = ImpliesTruthTable(lhs, rhs);
            return(predicateState);
        }
コード例 #2
0
        private static SyntacticElement parseStandardProposition(List <string> lineElements)
        {
            PropositionExpression proposition;
            int index = -1;

            index = IndexOfImplies(lineElements);
            if (index < 0)
            {
                index = IndexOfIfAndOnlyIf(lineElements);
                if (index < 0)
                {
                    throw new FormatException("no proposition element");
                }
                proposition = new IfAndOnlyIfSyntacticExpression();
            }
            else
            {
                proposition = new ImplicationSyntacticExpression();
            }

            // get lhs prop p and q imp z
            List <string>    lhsText = lineElements.Skip(1).Take(index - 1).ToList();
            SyntacticElement lhs     = ExpressionParser.Parse(lhsText);

            // check lhs
            if (lhs is ExpressionSyntacticElement)
            {
                proposition.lhs = (ExpressionSyntacticElement)lhs;
            }
            else
            {
                return(ProcessLhsError(lhs));
            }

            //           0  1  2  3  4  5  6  7     8 - X = 3
            // get rhs prop p and q imp z and k     index = 4
            //           0  1  2  3  4  5     6 - X = 3
            // get rhs prop p imp z and k     index = 2
            List <string>    rhsText = lineElements.Skip(index + 1).Take(lineElements.Count() - (index + 1)).ToList();
            SyntacticElement rhs     = ExpressionParser.Parse(rhsText);

            if (rhs is ExpressionSyntacticElement)
            {
                proposition.rhs = (ExpressionSyntacticElement)rhs;
            }
            else
            {
                return(ProcessRhsError(rhs));
            }
            return(proposition);
        }
コード例 #3
0
        public static bool?Evaluate(ImplicationSyntacticExpression exp, PredicateList state)
        {
            bool?lhs = ExpressionExecutive.Evaluate(exp.lhs, state);
            bool?rhs = ExpressionExecutive.Evaluate(exp.rhs, state);

            if (lhs == true && rhs == true)
            {
                return(true);
            }
            if (lhs == true && rhs == false)
            {
                return(false);
            }
            if (lhs == true && rhs == null)
            {
                return(null);
            }
            if (lhs == false && rhs == true)
            {
                return(true);
            }
            if (lhs == false && rhs == false)
            {
                return(true);
            }
            if (lhs == false && rhs == null)
            {
                return(true);
            }
            if (lhs == null && rhs == true)
            {
                return(null);
            }
            if (lhs == null && rhs == false)
            {
                return(null);
            }
            if (lhs == null && rhs == null)
            {
                return(null);
            }
            throw new NotImplementedException();
        }