Skip to content

Commit

Permalink
prover support for Universal/Existential Instantiation/Generalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipul-Cariappa committed Dec 25, 2023
1 parent 0a6ea98 commit 433f4fa
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 35 deletions.
100 changes: 100 additions & 0 deletions logic/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ def add(self, *statement: Statement) -> AssumptionT:
"""
return Assumption(self.assumptions.union({*statement}))

def get(self, statement: Statement) -> Statement:
"""
Returns the statement
Args:
statement (Statement): statement to find
Raises:
ValueError: if statement not found
Returns:
Statement: found statement
"""
for i in self.assumptions:
if i == statement:
return i
raise ValueError("Given statement not found un the assumptions")

Check warning on line 149 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L149

Added line #L149 was not covered by tests


class Proof:
"""Class to create, operate and verify on a proof"""
Expand Down Expand Up @@ -199,6 +217,73 @@ def _prove_decomposed_conclusion(self, to_prove: Statement) -> tuple[Proof, bool
my_proof = Proof()

match to_prove:
case CompositePredicateForAll():
universal_instantiation_statement = universal_instantiation(to_prove)
if universal_instantiation_statement in self.assumptions:
my_proof.add_step(
to_prove,
RulesOfInference.UniversalGeneralization,
self.assumptions.get(universal_instantiation_statement),
)
return my_proof, True

proof, truth = prove(
self.assumptions, universal_instantiation_statement
)
if truth:
my_proof.extend(proof)
my_proof.add_step(

Check warning on line 235 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L234-L235

Added lines #L234 - L235 were not covered by tests
to_prove,
RulesOfInference.UniversalGeneralization,
universal_instantiation_statement,
)
return my_proof, True

case CompositePredicateThereExists():
existential_instantiation_statement = existential_instantiation(
to_prove
)
if existential_instantiation_statement in self.assumptions:
my_proof.add_step(
to_prove,
RulesOfInference.ExistentialGeneralization,
self.assumptions.get(existential_instantiation_statement),
)
return my_proof, True

proof, truth = prove(
self.assumptions, existential_instantiation_statement
)
if truth:
my_proof.extend(proof)
my_proof.add_step(

Check warning on line 259 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L258-L259

Added lines #L258 - L259 were not covered by tests
to_prove,
RulesOfInference.ExistentialGeneralization,
existential_instantiation_statement,
)
return my_proof, True

Check warning on line 264 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L264

Added line #L264 was not covered by tests

universal_instantiation_statement = universal_instantiation(to_prove)
if universal_instantiation_statement in self.assumptions:
my_proof.add_step(
to_prove,
RulesOfInference.ExistentialGeneralization,
self.assumptions.get(universal_instantiation_statement),
)
return my_proof, True

proof, truth = prove(

Check warning on line 275 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L275

Added line #L275 was not covered by tests
self.assumptions, universal_instantiation_statement
)
if truth:
my_proof.extend(proof)
my_proof.add_step(

Check warning on line 280 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L278-L280

Added lines #L278 - L280 were not covered by tests
to_prove,
RulesOfInference.ExistentialGeneralization,
universal_instantiation_statement,
)
return my_proof, True

Check warning on line 285 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L285

Added line #L285 was not covered by tests

case CompositePropositionNOT(statement=statement):
# Applying NotOfNot i.e. ~(~x) <-> x
if isinstance(statement, CompositePropositionNOT):
Expand Down Expand Up @@ -379,6 +464,21 @@ def prove(self, to_prove: Statement) -> tuple[Proof, bool]:
my_proof.extend(proof)
return my_proof, True

Check warning on line 465 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L464-L465

Added lines #L464 - L465 were not covered by tests

existential_instantiation_statement = existential_instantiation(i)
if existential_instantiation_statement not in self.assumptions:
proof, truth = prove(

Check warning on line 469 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L467-L469

Added lines #L467 - L469 were not covered by tests
self.assumptions.add(existential_instantiation_statement),
to_prove,
)
if truth:
my_proof.add_step(

Check warning on line 474 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L473-L474

Added lines #L473 - L474 were not covered by tests
existential_instantiation_statement,
RulesOfInference.ExistentialInstantiation,
i,
)
my_proof.extend(proof)
return my_proof, True

Check warning on line 480 in logic/proof.py

View check run for this annotation

Codecov / codecov/patch

logic/proof.py#L479-L480

Added lines #L479 - L480 were not covered by tests

# TODO: Apply Demorgans Law

case CompositePredicateThereExists(_, predicate):
Expand Down
Loading

0 comments on commit 433f4fa

Please sign in to comment.