import proveit
from proveit import a, b, c, d, e, f, m, x, A, B, C, D, InstantiationFailure
from proveit.logic import Forall, And, Or, Equals, InSet, NotInSet, Set, Union
from proveit.core_expr_types import A_1_to_m
from proveit.logic.sets import x_in_any_A, x_notin_all_A
from proveit.numbers import (zero, one, two, three, four, five, six, seven,
Add, Integer, NaturalPos)
%begin demonstrations
Or(InSet(x, A), InSet(x, B), InSet(x,C)).prove(assumptions=[InSet(x,Union(A,B,C))])
InSet(x,Union(A,B,C)).prove(assumptions=[Or(InSet(x, A), InSet(x, B), InSet(x,C))])
NotInSet(x, Union(A,B,C,D)).definition()
NotInSet(x, Union(A,B,C)).prove(assumptions=[And(NotInSet(x,A), NotInSet(x,B),NotInSet(x,C))])
The material below was developed to test various unification-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_45, set_12345, set_1357, set_246 = (
Set(one, two , three),
Set(four, five),
Set(one, two, three, four, five),
Set(one, three, five, seven),
Set(two, four, six))
# define some enumerated Sets for use in testing, containing variables
set_abc, set_abcde, set_de = (
Set(a, b, c),
Set(a, b, c, d, e),
Set(d, e))
UnionMembership
class methods¶The UnionMembership
class has the following class methods:
A few UnionMembership
objects for convenience:
# a UnionMembership object that is clearly True
union_mem_01 = Union(set_abc, set_de).membership_object(d)
union_mem_01.expr
# a UnionMembership object that is clearly False
union_mem_02 = Union(set_123, set_45).membership_object(six)
union_mem_02.expr
# a UnionMembership object that is not clearly True or False
union_mem_03 = Union(set_123, set_abc).membership_object(d)
union_mem_03.expr
# a UnionMembership object that is not clearly True or False
union_mem_04 = Union(set_abc, Set(two, Add(one, three), five)).membership_object(d)
union_mem_04.expr
UnionMembership.definition()
¶From self $= [x \in (A \cup B \cup \ldots)]$, deduce and return something of the form $[x \in (A \cup B \cup \ldots)] = [(x \in A) \lor (x \in B) \lor \ldots$.
union_mem_01.expr
union_mem_01.definition()
union_mem_02.expr
# notice the definition is returned even for False membership claims
union_mem_02.definition()
union_mem_03.expr
# notice the definition is returned even for membership claims
# with unknown verity
union_mem_03.definition()
union_mem_04.expr
# notice the definition is returned even for membership claims
# with unknown verity
union_mem_04.definition()
UnionMembership.unfold()
¶From a self proven or assumed of the form $[x \in (A \cup B \cup \ldots)]$, derive and return $[(x \in A) \lor (x \in B) \lor \ldots]$.
union_mem_01.expr
union_mem_01.unfold(assumptions=[union_mem_01.expr])
union_mem_02.expr
# This should fail, since 6 is not in the union
try:
union_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))
Union(set_123, set_45).membership_object(two).expr
# Notice here we don't need any explicit assumptions
Union(set_123, set_45).membership_object(two).unfold()
# Consider a union of sets with some reducible elements:
Union(Set(two, Add(two, three)), Set(one, Add(one, two))).membership_object(three).expr
# We are still ok unfolding the membership, without any extra assumptions
Union(Set(two, Add(two, three)), Set(one, Add(one, two))).membership_object(three).unfold()
UnionMembership.conclude()
¶Called on self $= [x \in (A \cup B \;\cup\; ...)]$, and knowing or assuming $[[x \in A] \lor [x \in B] \;\lor\; ...]$, derive and return self.
union_mem_01.expr
# conclude() requires no extra assumptions for this one
union_mem_01.conclude()
# Recall the False UnionMembership object:
union_mem_02.expr
# We should not be able to conclude() such a False IntersectMembership object:
try:
union_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):
union_mem_03.expr
# We should not be able to conclude() such an DifferenceMembership object:
try:
union_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:
union_mem_03.conclude(assumptions=[Equals(d, a)])
# Consider a more general UnionMembership object
Union(Set(b, e), Set(b, c, d)).membership_object(a).expr
# We should not be able to conclude() such a UnionMembership object,
# without knowing the value of a:
try:
Union(Set(b, 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 Union with some unsimplified elements:
Union(Set(one, Add(one, one), Add(two, one)), Set(Add(one, one), three)).membership_object(c).expr
Union(Set(one, Add(one, one), Add(two, one)), Set(Add(one, one), three)).membership_object(c).conclude(
assumptions=[Equals(c, two)])
# a UnionMembership object involving general sets
Union(Integer, NaturalPos).membership_object(x).expr
# a conclude() on that general set UnionMembership
Union(Integer, NaturalPos).membership_object(x).conclude(
assumptions=[Equals(x, zero)])
UnionNonmembership
class methods¶The UnionNonmembership
class has the following class methods:
A few UnionNonmembership
objects for convenience:
# a UnionMembership object that is clearly True
union_nonmem_01 = Union(set_123, set_45).nonmembership_object(six)
union_nonmem_01.expr
# a UnionNonmembership object that is clearly False
union_nonmem_02 = Union(set_abc, set_de).nonmembership_object(d)
union_nonmem_02.expr
# a UnionNonmembership object that is not clearly True or False
union_nonmem_03 = Union(set_123, set_abc).nonmembership_object(d)
union_nonmem_03.expr
# a UnionMembership object that is not clearly True or False
union_nonmem_04 = Union(set_abc, Set(two, Add(one, three), Add(two, three))).nonmembership_object(d)
union_nonmem_04.expr
UnionNonmembership.definition()
¶From self $= [x \notin (A \cup B \cup \ldots)]$, deduce and return something of the form $[x \notin (A \cup B \cup \ldots)] = [(x \notin A) \land (x \notin B) \land \ldots]$.
union_nonmem_01.expr
union_nonmem_01.definition()
union_nonmem_02.expr
# notice the definition is returned even for False membership claims
union_nonmem_02.definition()
union_nonmem_03.expr
# notice the definition is returned even for membership claims
# with unknown verity
union_nonmem_03.definition()
union_nonmem_04.expr
# notice the definition is returned even for membership claims
# with unknown verity
union_nonmem_04.definition()
UnionNonmembership.conclude()
¶Called on self $= [x \notin (A \cup B \;\cup\; ...)]$, and knowing or assuming $[[x \notin A] \land [x \notin B] \;\land\; ...]$, derive and return self.
union_nonmem_01.expr
# conclude() requires no extra assumptions for this one
union_nonmem_01.conclude()
# Recall the False UnionNonmembership object:
union_nonmem_02.expr
# We should not be able to conclude() such a False UnionNonmembership object:
try:
union_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))
# Recall this UnionNonmembership object of unknown verity (where 'd' is an unassigned variable):
union_nonmem_03.expr
# We should not be able to conclude() such a UnionNonmembership object:
try:
union_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 if we supply some extra information about 'd', we can conclude:
union_nonmem_03.conclude(assumptions=[Equals(d, four), NotInSet(d, Set(a, b, c))],
simplify_with_known_evaluations=True)
# Consider a more general UnionNonmembership object
Union(Set(b, e), Set(b, c, d)).nonmembership_object(a).expr
# We should not be able to conclude() such a UnionNonmembership object,
# without knowing the value of a:
try:
Union(Set(b, e), Set(b, c, d)).nonmembership_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 Union with some unsimplified elements:
Union(Set(one, Add(one, one), Add(two, one)), Set(Add(one, one), three)).membership_object(c).expr
Union(Set(one, Add(one, one), Add(two, one)), Set(Add(one, one), three)).nonmembership_object(c).conclude(
assumptions=[Equals(c, zero)],
simplify_with_known_evaluations=True)
# a UnionNonmembership object involving general sets
Union(Integer, NaturalPos).nonmembership_object(x).expr
# a conclude() on that general set UnionNonmembership
Union(Integer, NaturalPos).nonmembership_object(x).conclude(
assumptions=[NotInSet(x, Integer)])
%end demonstrations