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 Hypothesis(premise.ApplyMapping(mapping), conclusion.ApplyMapping(mapping))); }