Skip to content

343-NotExists.conclude_via_forall() update #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/proveit/logic/booleans/booleans.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ def deduce_not_equal(self, other, **defaults_config):
return true_not_false
if other == TRUE:
raise ProofFailure(
self, defaults.assumptions,
"Cannot prove TRUE != TRUE since that statement is false")
raise ProofFailure(
self, defaults.assumptions,
"Inequality between TRUE and a non-boolean not defined")

def readily_in_bool(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,161 @@
"Exists((a, b), Equals(Add(a, b), five), domain=NaturalPos).conclude_via_example((two, three))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Testing `NotExists().conclude_via_forall()` for Multiple Cases"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from proveit import x, P, Function\n",
"from proveit.logic import Forall, Not, NotExists\n",
"from proveit.numbers import zero, greater_eq"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Deriving $\\not\\exists_{x}\\big(\\lnot P(x)\\big)$ via $\\forall_{x}\\big(P(x)\\big)$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Px = Function(P, x)\n",
"forall_x_Px_assumption = Forall(x, Px)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_not_Px_to_prove = NotExists(x, Not(Px))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_not_Px_to_prove.conclude_via_forall(assumptions = (forall_x_Px_assumption,))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Deriving $\\not\\exists_{x | Q(x)}\\big(\\lnot P(x)\\big)$ via $\\forall_{x | Q(x)}\\big(P(x)\\big)$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"forall_x_Px_with_condition_assumption = Forall(x, Px, conditions = [greater_eq(x, zero)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_not_Px_with_condition_to_prove = NotExists(x, Not(Px), conditions = [greater_eq(x, zero)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_not_Px_with_condition_to_prove.conclude_via_forall(assumptions = [forall_x_Px_with_condition_assumption])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Deriving $\\not\\exists_{x}\\big(P(x)\\big)$ via $\\forall_{x}\\big(\\lnot P(x)\\big)$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"forall_x_not_Px_assumption = Forall(x, Not(Px))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_Px_to_prove = NotExists(x, Px)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_Px_to_prove.conclude_via_forall(assumptions = [forall_x_not_Px_assumption])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Deriving $\\not\\exists_{x|Q(x)}\\big(P(x)\\big)$ via $\\forall_{x|Q(x)}\\big(\\lnot P(x)\\big)$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"forall_x_not_Px_with_condition_assumption = Forall(x, Not(Px), conditions = [greater_eq(x, zero)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_Px_with_condition_to_prove = NotExists(x, Px, conditions = [greater_eq(x, zero)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"noteexists_x_st_Px_with_condition_to_prove.conclude_via_forall(assumptions = [forall_x_not_Px_with_condition_assumption])"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Proof of <a class=\"ProveItLink\" href=\"../../../../../../../_theory_nbs_/theory.ipynb\">proveit</a>.<a class=\"ProveItLink\" href=\"../../../../../../_theory_nbs_/theory.ipynb\">logic</a>.<a class=\"ProveItLink\" href=\"../../../../../_theory_nbs_/theory.ipynb\">booleans</a>.<a class=\"ProveItLink\" href=\"../../../../_theory_nbs_/theory.ipynb\">quantification</a>.<a class=\"ProveItLink\" href=\"../../theory.ipynb\">existence</a>.<a class=\"ProveItLink\" href=\"../../theorems.ipynb#forall_implies_not_exists_not_no_conditions\">forall_implies_not_exists_not_no_conditions</a> theorem\n",
"========"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import proveit\n",
"theory = proveit.Theory() # the theorem's theory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%proving forall_implies_not_exists_not_no_conditions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Proof of <a class=\"ProveItLink\" href=\"../../../../../../../_theory_nbs_/theory.ipynb\">proveit</a>.<a class=\"ProveItLink\" href=\"../../../../../../_theory_nbs_/theory.ipynb\">logic</a>.<a class=\"ProveItLink\" href=\"../../../../../_theory_nbs_/theory.ipynb\">booleans</a>.<a class=\"ProveItLink\" href=\"../../../../_theory_nbs_/theory.ipynb\">quantification</a>.<a class=\"ProveItLink\" href=\"../../theory.ipynb\">existence</a>.<a class=\"ProveItLink\" href=\"../../theorems.ipynb#not_exists_via_forall_no_conditions\">not_exists_via_forall_no_conditions</a> theorem\n",
"========"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import proveit\n",
"theory = proveit.Theory() # the theorem's theory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%proving not_exists_via_forall_no_conditions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@
" domain=NaturalPos)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"not_exists_via_forall_no_conditions = Forall(\n",
" n, Forall(\n",
" (P, Q), Implies(general_forall__Py_not_T, \n",
" general_notexists_Px)\n",
" .with_wrap_after_operator()),\n",
" domain=NaturalPos)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -252,6 +266,29 @@
"**If all instances are true, then there exists no counter-example:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from proveit.logic.booleans.quantification import general_notexists_notPy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"forall_implies_not_exists_not_no_conditions = Forall(\n",
" n, Forall(\n",
" P, Implies(general_forall_Px, \n",
" general_notexists_notPy)\n",
" .with_wrap_after_operator()),\n",
" domain=NaturalPos)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,32 @@ def conclude_via_forall(self, **defaults_config):
or from forall_{x | Q(x)} (P(x) != TRUE)
respectively.
'''
exists_conditions = True
if len(self.conditions) == 0:
exists_conditions = False
from . import forall_implies_not_exists_not, not_exists_via_forall
from proveit.logic.equality.eq_ops import NotEquals
from bool_ops import Not
from bool_set import TRUE
from . import forall_implies_not_exists_not_no_conditions
from . import not_exists_via_forall_no_conditions
from proveit.logic import Not, NotEquals, TRUE
_x = _y = self.instance_params
_n = _x.num_elements()
_Q = Lambda(_x, self.conditions)
if isinstance(self.instance_expr, Not):
_P = Lambda(_x, self.instance_expr.operand)
return forall_implies_not_exists_not.instantiate(
{x: _x, y: _y, n: _n, P: _P, Q:_Q}).derive_consequent()
if exists_conditions:
return forall_implies_not_exists_not.instantiate(
{x: _x, y: _y, n: _n, P: _P, Q:_Q}).derive_consequent()
else:
return forall_implies_not_exists_not_no_conditions.instantiate(
{x: _x, y: _y, n: _n, P: _P}).derive_consequent()
else:
_P = Lambda(_x, self.instance_expr.operand)
return not_exists_via_forall.instantiate(
{x: _x, y: _y, n: _n, P: _P, Q:_Q}).derive_consequent()
_P = Lambda(_x, self.instance_expr)
if exists_conditions:
return not_exists_via_forall.instantiate(
{x: _x, y: _y, n: _n, P: _P, Q:_Q}).derive_consequent()
else:
return not_exists_via_forall_no_conditions.instantiate(
{x: _x, y: _y, n: _n, P: _P}).derive_consequent()

def readily_in_bool(self):
'''
Expand Down