示例#1
0
        private Proof TryRule(Sequent sequent, InferenceRule rule)
        {
            RuleType?prevRule = currentRule;

            currentRule = rule.type;

            FormulaMapping mapping = null;

            if (!MapFormulas(rule.conclusion, sequent.conclusion, null, ref mapping))
            {
                throw new ArgumentException("The given rule should have been applicable to the conclusion");
            }

            Proof    proof = new Proof();
            RuleStep step  = new RuleStep(1, sequent.conclusion, rule.type);

            if (MatchPremises(rule, mapping, ref proof, ref step))
            {
                proof.AddRuleStep(step);
            }
            else
            {
                proof = null;
            }

            currentRule = prevRule;

            return(proof);
        }
示例#2
0
        public void Visit(OR or)
        {
            Sequent sequent = new Sequent(
                new ISymbol[0],
                or
                );

            Result = solver.Prove(sequent);
        }
示例#3
0
        public void Visit(NOT not)
        {
            Sequent sequent = new Sequent(
                new ISymbol[0],
                not
                );

            Result = solver.Prove(sequent);
        }
示例#4
0
        public void Visit(Implies implies)
        {
            Sequent sequent = new Sequent(
                new ISymbol[0],
                implies
                );

            Result = solver.Prove(sequent);
        }
示例#5
0
        public void Visit(Contradiction contradiction)
        {
            Sequent sequent = new Sequent(
                new ISymbol[0],
                contradiction
                );

            Result = solver.Prove(sequent);
        }
示例#6
0
        public void Visit(Atom atom)
        {
            Sequent sequent = new Sequent(
                new ISymbol[0],
                atom
                );

            Result = solver.Prove(sequent);
        }
示例#7
0
        public void Visit(AND and)
        {
            Sequent sequent = new Sequent(
                new ISymbol[0],
                and
                );

            Result = solver.Prove(sequent);
        }
示例#8
0
        public Proof Prove(Sequent sequent)
        {
            if (proofStack.Contains(sequent.conclusion) && !AllowBypassProofStack(sequent.conclusion))
            {
                // We're already trying to prove this conclusion; circular argument detected
                return(null);
            }

            if (currentRule == RuleType.OR_Elimination)
            {
                orEliminationPremises.Push(currentOEPremise);
            }

            Proof proof = new Proof
            {
                conclusion = sequent.conclusion
            };
            var premiseSteps = proof.AddPremises(sequent.premises);

            proofStack.Push(sequent.conclusion);
            truths.AddAll(premiseSteps);

            RuleType[] concludingRuleTypes = sequent.conclusion.GetConcludingRuleTypes();
            Proof      subproof            = null;

            foreach (RuleType ruleType in concludingRuleTypes)
            {
                if (rules.ContainsKey(ruleType))
                {
                    subproof = TryRule(sequent, rules[ruleType]);
                    if (subproof != null)
                    {
                        proof.AddStepsFromProof(subproof);
                        break;
                    }
                }
            }

            truths.RemoveAll(premiseSteps);
            proofStack.Pop();

            if (currentRule == RuleType.OR_Elimination)
            {
                orEliminationPremises.Pop();
            }

            if (subproof == null)
            {
                return(null);
            }

            return(proof);
        }
示例#9
0
        public void Visit(Hypothesis hypothesis)
        {
            Sequent sequent = new Sequent(
                new ISymbol[] { hypothesis.premise },
                hypothesis.conclusion
                );

            Proof subproof = solver.Prove(sequent);

            if (subproof != null)
            {
                Result = new Proof();
                Result.AddProofStep(subproof);
            }
        }
示例#10
0
        static bool DoProof(Solver solver, int problemNumber)
        {
            Sequent sequent = problems[problemNumber];
            Proof   proof   = solver.Prove(sequent);

            if (proof == null)
            {
                Console.WriteLine("The following sequent could not be proven:");
                Console.WriteLine(sequent.ToString());
                return(false);
            }
            else
            {
                proof.PrintToConsole();
                return(true);
            }
        }