public void MapAll(FormulaMapping formulaMapping) { foreach (var pair in formulaMapping.mapping) { mapping[pair.Key] = pair.Value; } }
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); }
public FormulaMapping(FormulaMapping other) { if (other == null) { mapping = new Dictionary <int, ISymbol>(); } else { mapping = new Dictionary <int, ISymbol>(other.mapping); } }
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]);
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); }
public override ISymbol ApplyMapping(FormulaMapping mapping) { return(new AND(left.ApplyMapping(mapping), right.ApplyMapping(mapping))); }
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); }
public ISymbol ApplyMapping(FormulaMapping mapping) { return(new Atom(variableIndex)); }
public abstract ISymbol ApplyMapping(FormulaMapping mapping);
public ISymbol ApplyMapping(FormulaMapping mapping) { return(mapping.GetMapping(this)); }
public ISymbol ApplyMapping(FormulaMapping mapping) { return(new Contradiction()); }
public ISymbol ApplyMapping(FormulaMapping mapping) { return(new Hypothesis(premise.ApplyMapping(mapping), conclusion.ApplyMapping(mapping))); }
public MappingResult(ISymbol formula, FormulaMapping mapping, bool isRoot) { this.formula = formula; this.mapping = mapping; this.isRoot = isRoot; }
public override ISymbol ApplyMapping(FormulaMapping mapping) { return(new NOT(operand.ApplyMapping(mapping))); }