Ejemplo n.º 1
0
 public static bool?Evaluate(ExpressionSyntacticElement exp, PredicateList state)
 {
     if (exp.GetType() == typeof(NotExpression))
     {
         return(ExpressionExecutive.Evaluate((NotExpression)exp, state));
     }
     if (exp.GetType() == typeof(AndExpression))
     {
         return(ExpressionExecutive.Evaluate((AndExpression)exp, state));
     }
     if (exp.GetType() == typeof(OrExpression))
     {
         return(ExpressionExecutive.Evaluate((OrExpression)exp, state));
     }
     if (exp.GetType() == typeof(XorExpression))
     {
         return(ExpressionExecutive.Evaluate((XorExpression)exp, state));
     }
     if (exp.GetType() == typeof(PredicateExpression))
     {
         return(ExpressionExecutive.Evaluate((PredicateExpression)exp, state));
     }
     if (exp.GetType() == typeof(ImplicationSyntacticExpression))
     {
         return(ExpressionExecutive.Evaluate((ImplicationSyntacticExpression)exp, state));
     }
     if (exp.GetType() == typeof(IfAndOnlyIfSyntacticExpression))
     {
         return(ExpressionExecutive.Evaluate((IfAndOnlyIfSyntacticExpression)exp, state));
     }
     throw new UnknownExpressionException();
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 private static PropositionExpression RunProposition(PropositionExpression pse, LogicArgument program)
 {
     if (pse is ImplicationSyntacticExpression)
     {
         ExpressionExecutive.execute((ImplicationSyntacticExpression)pse, program.predicateList);
     }
     else if (pse is IfAndOnlyIfSyntacticExpression)
     {
         ExpressionExecutive.execute((IfAndOnlyIfSyntacticExpression)pse, program.predicateList);
     }
     else
     {
         throw new NotImplementedException("this bit cannot be reached and records a design error");
     }
     return(pse);
 }
Ejemplo n.º 4
0
 private static PredicateSetterSyntacticElement RunPredicateSetter(PredicateSetterSyntacticElement pse, LogicArgument program)
 {
     if (pse is PropositionSyntacticElement)
     {
         program.predicateList = ExpressionExecutive.execute((PropositionSyntacticElement)pse, program.predicateList);
     }
     else if (pse is PropositionNegationSyntacticElement)
     {
         program.predicateList = ExpressionExecutive.execute((PropositionNegationSyntacticElement)pse, program.predicateList);
     }
     else
     {   // case cannot currently exist
         throw new NotImplementedException();
     }
     return(pse);
 }
Ejemplo n.º 5
0
        //what does this do?
        // if the conclusion is known, it works out what the conclusion should be and
        // returns the actual conclusion and the given one.
        // p->q conclusion is q predicate is p after execution p is known or not depending on value of p
        // if both are set then? is the truth table checked? do interested in state before and after
        // so how does an implies statement work?
        //  p --> q   ==== !p or q
        //  0  1  0
        //  0  1  1
        //  1  0  0
        //  1  1  1
        /// <summary>
        /// Execute with a full trace of what happened
        /// </summary>
        /// <param name="program"></param>
        public static List <string> Execute(LogicArgument program, out ProgramReturnCode errorCode)
        {
            // we want a value for the whole program and
            // we want a value for each line in the program
            // from the start to the end

            // executing must suggest a value for a predicate,
            // if this value cannot be set
            //    1 can be set to 1
            //    0 can be set to 0
            //    ? can be set to anything  1, 0 or ?

            // The execution must be such that it runs through setting predicates

            // run predicates -- if fails produce result
            // run not expressions -- if fails produce result
            // run propositions in order
            // produce result
            List <string> programOutput = new List <string>();

            // if no errors
            errorCode = Validate(program, ref programOutput);
            if (errorCode == ProgramReturnCode.No_errors)
            {
                errorCode = RunPredicateSetters(program, ref programOutput);
                if (errorCode == ProgramReturnCode.No_errors)
                {
                    // run propositions
                    errorCode = RunPropositions(program, ref programOutput);
                    if (errorCode == ProgramReturnCode.No_errors)
                    {
                        // run therefore statement
                        ExpressionExecutive.execute(program.thereforeSyntacticElement, program.predicateList);
                        program.Conclusion = program.thereforeSyntacticElement.Value;
                        if (program.Conclusion == true)
                        {
                            programOutput.Add("Your arguments conclusion was true.");
                        }
                        else
                        {
                            programOutput.Add("Your arguments conclusion was false.");
                        }
                    }
                }
            }
            return(programOutput);
        }
Ejemplo n.º 6
0
        public static bool?Evaluate(NotExpression exp, PredicateList state)
        {
            bool?val = ExpressionExecutive.Evaluate(exp.expression, state);

            if (val == true)
            {
                return(false);
            }
            if (val == false)
            {
                return(true);
            }
            if (val == null)
            {
                return(null);
            }
            throw new NotImplementedException();
        }
Ejemplo n.º 7
0
        public static bool?Evaluate(IfAndOnlyIfSyntacticExpression 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(false);
            }
            if (lhs == false && rhs == false)
            {
                return(true);
            }
            if (lhs == false && rhs == null)
            {
                return(null);
            }
            if (lhs == null && rhs == true)
            {
                return(null);
            }
            if (lhs == null && rhs == false)
            {
                return(null);
            }
            if (lhs == null && rhs == null)
            {
                return(null);
            }
            throw new NotImplementedException();
        }
Ejemplo n.º 8
0
 /// <summary>
 /// each of the following expressions all rely on expressions either unary or binary
 /// these are defined in the evaluate function, these can only really be worked out when all predicate suppositions
 /// are made. For propositions like p and not p must be run
 /// </summary>
 /// <param name="element"></param>
 /// <param name="predicateState"></param>
 /// <returns></returns>
 public static PredicateList execute(ThereforeSyntacticElement element, PredicateList predicateState)
 {
     // for of a therefore are
     element.Value = ExpressionExecutive.Evaluate(element.expression, predicateState);
     return(predicateState);
 }