コード例 #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
        private Proof TryProve(ISymbol requiredPremise, InferenceRule rule, FormulaMapping mapping, int premiseIndex, ref RuleStep step)
        {
            ISymbol lastOEPremise = currentOEPremise;

            if (rule.type == RuleType.OR_Elimination)
            {
                currentOEPremise = rule.premises[0].ApplyMapping(mapping);
            }

            SolverVisitor solverVisitor = new SolverVisitor(this);

            requiredPremise.Accept(solverVisitor);

            if (rule.type == RuleType.OR_Elimination)
            {
                currentOEPremise = lastOEPremise;
            }

            if (solverVisitor.Result != null)
            {
                Proof proof = solverVisitor.Result;
                step.AddReferredStep(proof.ProofSteps[^ 1]);
コード例 #3
0
        private bool MatchPremises(InferenceRule rule, FormulaMapping mapping, ref Proof proof, ref RuleStep step, int premiseIndex = 0)
        {
            if (premiseIndex >= rule.premises.Count)
            {
                return(true);
            }

            ISymbol premise = rule.premises[premiseIndex];

            List <MappingResult> nonRootMappings = new List <MappingResult>();

            for (int i = 0; i < truths.Count; i++)
            {
                IProofStep truth = truths[i];
                foreach (MappingResult mappingResult in FindFormulaMappings(premise, truth.Conclusion, mapping))
                {
                    if (mappingResult.isRoot)
                    {
                        step.AddReferredStep(truth);

                        if (MatchPremises(rule, mappingResult.mapping, ref proof, ref step, premiseIndex + 1))
                        {
                            break;
                        }

                        step.PopReferredStep();
                    }
                    else
                    {
                        // Do non-root options later for efficiency
                        nonRootMappings.Add(mappingResult);
                    }
                }

                if (step.referredSteps.Count >= rule.premises.Count)
                {
                    return(true);
                }
            }

            foreach (MappingResult mappingResult in nonRootMappings)
            {
                Proof newProof = TryProve(mappingResult.formula, rule, mappingResult.mapping, premiseIndex, ref step);
                if (newProof != null)
                {
                    proof.AddStepsFromProof(newProof);
                    return(true);
                }

                if (step.referredSteps.Count >= rule.premises.Count)
                {
                    return(true);
                }
            }

            if (mapping.Count >= rule.maxFormulaIndex)
            {
                RuleType lastUnreferredRuleBefore = lastUnreferredRule;

                if (rule.type == RuleType.Double_Negation_Elimination && lastUnreferredRule == RuleType.Double_Negation_Elimination)
                {
                    return(false);
                }

                lastUnreferredRule = rule.type;

                ISymbol mappedPremise = premise.ApplyMapping(mapping);
                Proof   newProof      = TryProve(mappedPremise, rule, mapping, premiseIndex, ref step);
                if (newProof != null)
                {
                    proof.AddStepsFromProof(newProof);
                    return(true);
                }

                lastUnreferredRule = lastUnreferredRuleBefore;
            }

            // Proof is impossible (invalid)
            return(false);
        }