import proveit
from proveit import a, b, c, d, e, f, x, y, A, B, S, InstantiationFailure
from proveit.logic import Or, Equals, NotEquals, Set, InSet, NotInSet, Difference
from proveit.numbers import (one, two, three, four, five, six, seven, Add,
Integer, Natural, NaturalPos, Neg)
%begin demonstrations
InSet(x, Difference(A, B)).definition()
InSet(x, Difference(A, B)).prove(assumptions=[InSet(x, A), NotInSet(x, B)])
InSet(x, Difference(A, Set(y))).prove(assumptions=[InSet(x, A), NotEquals(x, y)])
InSet(x, A).prove(assumptions=[InSet(x, Difference(A, B))])
NotInSet(x, B).prove(assumptions=[InSet(x, Difference(A, B))])
NotEquals(x, y).prove(assumptions=[InSet(x, Difference(A, Set(y)))])
NotInSet(x, Difference(A, B)).definition()
NotInSet(x, Difference(A, B)).prove(assumptions=[Or(NotInSet(x, A), InSet(x, B))])
Or(NotInSet(x, A), InSet(x, B)).prove(assumptions=[NotInSet(x, Difference(A, B))])
The material below was developed to test various intersection-related methods. Some of this material could be integrated into the `_demonstrations_` page eventually and/or deleted as development continues.
Sets
For Testing¶# define some enumerated Sets for use in testing, containing numeric literals
set_123, set_12345, set_1234567 = (
Set(one, two , three),
Set(one, two , three, four, five),
Set(one, two , three, four, five, six, seven))
# define some enumerated Sets for use in testing, containing variables
set_abc, set_abcde = (
Set(a, b, c),
Set(a, b, c, d, e))
DifferenceMembership
class methods¶
The DifferenceMembership
class currently has the following class methods:
A few DifferenceMembership
objects for convenience:
# a DifferenceMembership object that is clearly True
diff_mem_01 = Difference(set_abcde, set_abc).membership_object(d)
diff_mem_01.expr
# a DifferenceMembership object that is clearly False
diff_mem_02 = Difference(set_12345, set_123).membership_object(two)
diff_mem_02.expr
# a DifferenceMembership object that is not clearly True or False
diff_mem_03 = Difference(set_12345, set_123).membership_object(c)
diff_mem_03.expr
DifferenceMembership.conclude()
¶diff_mem_01.expr
# using explicit assumptions about set membership and set non-membership
diff_mem_01.conclude(assumptions=[InSet(d, set_abcde), NotInSet(d, set_abc)])
# using less explicit assumptions about set membership/nonmembership
diff_mem_01.conclude(assumptions=[NotEquals(d, a), NotEquals(d, b), NotEquals(d, c)])
# Recall the False IntersectMembership object:
diff_mem_02.expr
# We should not be able to conclude() such a False IntersectMembership object:
try:
diff_mem_02.conclude()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
# Recall this IntersectMembership object of unknown verity (where 'c' is an unassigned variable):
diff_mem_03.expr
# We should not be able to conclude() such an DifferenceMembership object:
try:
diff_mem_03.conclude()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
# But if we supply some extra information about 'c', we can conclude:
diff_mem_03.conclude(assumptions=[Equals(c, four)],
simplify_with_known_evaluations=True)
# Consider a more general DifferenceMembership object
Difference(Set(a, b, c, d, e), Set(b, c, d)).membership_object(a).expr
# We should not be able to conclude() such an DifferenceMembership object,
# without knowing the value of a:
try:
Difference(Set(a, b, c, d, e), Set(b, c, d)).membership_object(a).conclude()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
# define a Difference with an unsimplified element (1+1)
diff_mem_04 = Difference(Set(one, two, three), Set(Add(one, one), three)).membership_object(c)
diff_mem_04.expr
diff_mem_04.conclude(assumptions=[Equals(c, one)],
simplify_with_known_evaluations=True)
# a DifferenceMembership object involving general sets
diff_mem_05 = Difference(Integer, Natural).membership_object(x)
diff_mem_05.expr
diff_mem_05.conclude(assumptions=[InSet(x, Integer), NotInSet(x, Natural)])
DifferenceMembership.conclude_as_folded()
¶Currently, DifferenceMembership.conclude() simply calls DifferenceMembership.conclude_as_folded(), so the examples that work for conclude() should all work for conclude_as_folded().
diff_mem_01.expr
# using explicit assumptions about set membership and set non-membership
diff_mem_01.conclude_as_folded(assumptions=[InSet(d, set_abcde), NotInSet(d, set_abc)])
# using less explicit assumptions about set membership/nonmembership
diff_mem_01.conclude_as_folded(assumptions=[NotEquals(d, a), NotEquals(d, b), NotEquals(d, c)])
# Recall the False IntersectMembership object:
diff_mem_02.expr
# We should not be able to conclude() such a False IntersectMembership object:
try:
diff_mem_02.conclude_as_folded()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
# Recall this IntersectMembership object of unknown verity (where 'c' is an unassigned variable):
diff_mem_03.expr
# We should not be able to conclude() such an IntersectMembership object:
try:
diff_mem_03.conclude_as_folded()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
# But if we supply some extra information about 'c', we can conclude:
diff_mem_03.conclude_as_folded(assumptions=[Equals(c, four)])
# define a Difference with an unsimplified element (1+1)
diff_mem_06 = Difference(Set(one, two, three), Set(two, Add(two, one))).membership_object(c)
diff_mem_06.expr
diff_mem_06.conclude_as_folded(assumptions=[Equals(c, one)],
simplify_with_known_evaluations=True)
# a DifferenceMembership object involving general sets
diff_mem_07 = Difference(Natural, NaturalPos).membership_object(x)
diff_mem_07.expr
diff_mem_07.conclude_as_folded(assumptions=[InSet(x, Natural), NotInSet(x, NaturalPos)])
DifferenceMembership.definition()
¶Deduce and return something of the form $[x \in (A - B)] = [(x \in A) \land (x \notin B)$.
diff_mem_01.expr
diff_mem_01.definition()
diff_mem_02.expr
diff_mem_02.definition()
diff_mem_03.expr
diff_mem_03.definition()
diff_mem_04.expr
diff_mem_04.definition()
DifferenceMembership.unfold()
¶From something proven or assumed of the form $[x \in (A - B)]$, derive and return $[(x \in A) \land (x \notin B)]$, or, for the special case of $x \in (S - {y})$, derive and return $[(x \in A) \land (x \notin y)]$ (if that theorem is usable).
diff_mem_01.expr
diff_mem_01.unfold(assumptions=[diff_mem_01.expr])
diff_mem_02.expr
# This should fail, since 2 has been subtracted out
try:
diff_mem_02.unfold()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
Difference(set_12345, Set(one, three)).membership_object(two).expr
# Notice here we don't need any explicit assumptions
Difference(set_12345, Set(one, three)).membership_object(two).unfold()
diff_mem_08 = Difference(set_12345, Set(one, Add(one, two))).membership_object(two)
diff_mem_08.expr
diff_mem_08.unfold()
DifferenceNonmembership
class methods¶
The DifferenceNonmembership
class includes the following class methods:
A few DifferenceNonmembership
objects for convenience:
# a DifferenceMembership object that is clearly True
diff_nonmem_01 = Difference(set_abcde, set_abc).nonmembership_object(b)
diff_nonmem_01.expr
# a DifferenceNonmembership object that is clearly False
diff_nonmem_02 = Difference(set_12345, set_123).nonmembership_object(four)
diff_nonmem_02.expr
# a DifferenceMembership object that is not clearly True or False
diff_nonmem_03 = Difference(set_12345, set_123).nonmembership_object(c)
diff_nonmem_03.expr
DifferenceNonmembership.conclude()
¶Prove something of the form $x \notin (A - B)$ via $(x \notin A) \lor (x \in B)$. The special case of $x \notin (S - \{y\})$ may be concluded via $(x \notin S) \lor (x = y)$ as long as that theorem is usable.
diff_nonmem_01.expr
# At first, this seems a bit odd … what if we have something like b=d?
# But in such a case, the subtraction of {a, b, c} would have removed the
# value for d as well, so it seems to be correct.
diff_nonmem_01.conclude()
# Notice that it doesn't matter what b actually is …
# The conclusion is independent of the assumption(s) about the value of b
diff_nonmem_01.conclude(assumptions=[Equals(b, d)])
diff_nonmem_02.expr
# We should not be able to conclude() the False non-membership:
try:
diff_nonmem_02.conclude()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
# Interestingly, we can assume an obviously False premise and conclude():
diff_nonmem_02.conclude(assumptions=[NotInSet(four, set_12345)])
diff_nonmem_03.expr
# We should not be able to conclude() the non-membership of unknown verity:
try:
diff_nonmem_03.conclude()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
# but given some information about the value of c, we can conclude():
diff_nonmem_03.conclude(assumptions=[Equals(c, two)])
DifferenceNonmembership.conclude_as_folded()
¶Because DifferenceNonmembership.conclude()
simply calls DifferenceNonmembership.conclude_as_folded()
, the work above for the conclude()
method also demonstrates the functionality of the conclude_as_folded()
method.
DifferenceNonmembership.definition()
¶Deduce and return something of the form $[x \notin (A - B)] = [(x \notin A) or (x \in B)]$.
diff_nonmem_01.expr
diff_nonmem_01.definition()
diff_nonmem_02.expr
# Notice the definition is returned even for False non-membership claims
diff_nonmem_02.definition()
diff_nonmem_03.expr
# Notice the definition is returned even non-membership claims of unknown verity
diff_nonmem_03.definition()
diff_nonmem_complicated = Difference(Set(one, Add(one, one), three, Add(two, two)), Set(Add(one, one), Add(two, one), four)).nonmembership_object(c)
diff_nonmem_complicated.expr
diff_nonmem_complicated.definition()
DifferenceNonmembership.unfold()
¶From something proven or assumed of the form $[x \notin (A - B)]$, derive and return $[(x \notin A) \lor (x \in B)]$, or, for the special case of $x \notin (S - {y})$, derive and return $[(x \notin A) \lor (x = y)]$ (if that theorem is usable).
diff_nonmem_01.expr
diff_nonmem_01.unfold()
diff_nonmem_02.expr
# This should fail, since 4 has not been subtracted out
try:
diff_nonmem_02.unfold()
assert False, "Expecting a ProofFailure (InstantiationFailure); should not get this far!"
except InstantiationFailure as the_error:
print("ProofFailure (InstantiationFailure): {}".format(the_error))
Difference(set_12345, Set(one, three)).nonmembership_object(three).expr
# Notice here we don't need any explicit assumptions
Difference(set_12345, Set(one, three)).nonmembership_object(three).unfold()
# Consider an interesting example involving literals and an addition element
Difference(set_12345, Set(one, Add(one, two))).nonmembership_object(three).expr
# We can unfold that with no extra assumptions (clearly the 2nd disjunct is True):
Difference(set_12345, Set(one, Add(one, two))).nonmembership_object(three).unfold()
%end demonstrations