public void Visit(Atom atom) { Sequent sequent = new Sequent( new ISymbol[0], atom ); Result = solver.Prove(sequent); }
public void Visit(Contradiction contradiction) { Sequent sequent = new Sequent( new ISymbol[0], contradiction ); Result = solver.Prove(sequent); }
public void Visit(AND and) { Sequent sequent = new Sequent( new ISymbol[0], and ); Result = solver.Prove(sequent); }
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); }
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); } }
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); } }
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]);
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); }