Пример #1
0
 public void MapAll(FormulaMapping formulaMapping)
 {
     foreach (var pair in formulaMapping.mapping)
     {
         mapping[pair.Key] = pair.Value;
     }
 }
Пример #2
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);
        }
Пример #3
0
 public FormulaMapping(FormulaMapping other)
 {
     if (other == null)
     {
         mapping = new Dictionary <int, ISymbol>();
     }
     else
     {
         mapping = new Dictionary <int, ISymbol>(other.mapping);
     }
 }
Пример #4
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]);
Пример #5
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            FormulaMapping other = (FormulaMapping)obj;

            if (Count != other.Count)
            {
                return(false);
            }

            foreach (var pair in mapping)
            {
                if (!other.mapping[pair.Key].Equals(pair.Value))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #6
0
 public override ISymbol ApplyMapping(FormulaMapping mapping)
 {
     return(new AND(left.ApplyMapping(mapping), right.ApplyMapping(mapping)));
 }
Пример #7
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);
        }
Пример #8
0
 public ISymbol ApplyMapping(FormulaMapping mapping)
 {
     return(new Atom(variableIndex));
 }
Пример #9
0
 public abstract ISymbol ApplyMapping(FormulaMapping mapping);
Пример #10
0
 public ISymbol ApplyMapping(FormulaMapping mapping)
 {
     return(mapping.GetMapping(this));
 }
Пример #11
0
 public ISymbol ApplyMapping(FormulaMapping mapping)
 {
     return(new Contradiction());
 }
Пример #12
0
 public ISymbol ApplyMapping(FormulaMapping mapping)
 {
     return(new Hypothesis(premise.ApplyMapping(mapping), conclusion.ApplyMapping(mapping)));
 }
Пример #13
0
 public MappingResult(ISymbol formula, FormulaMapping mapping, bool isRoot)
 {
     this.formula = formula;
     this.mapping = mapping;
     this.isRoot  = isRoot;
 }
Пример #14
0
 public override ISymbol ApplyMapping(FormulaMapping mapping)
 {
     return(new NOT(operand.ApplyMapping(mapping)));
 }