Created
October 1, 2014 17:11
-
-
Save smichr/c771ddd47e8c85c89bd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These are all of our assumptions in master: | |
['algebraic', 'antihermitian', 'commutative', 'complex', 'composite', | |
'even', 'finite', 'hermitian', 'imaginary', 'infinite', 'integer', | |
'irrational', 'negative', 'noninteger', 'nonnegative', 'nonpositive', | |
'nonzero', 'odd', 'positive', 'prime', 'rational', 'real', | |
'transcendental', 'zero'] | |
Beta_rules gives the ways to prove different items. For example, we | |
know a number is odd if even is False and integer is True | |
``` | |
>>> from sympy.utilities.misc import filldedent as fd | |
>>> from sympy.core.assumptions import _assume_rules as A | |
>>> A.beta_rules[0] | |
(set([('even', False), ('integer', True)]), ('odd', True)) | |
\_____________set_______________________/ \__tuple__/ | |
``` | |
These are all the items that appear in the set-part of beta_rules: | |
``` | |
['algebraic', 'complex', 'even', 'integer', 'negative', 'nonnegative', | |
'nonpositive', 'nonzero', 'odd', 'positive', 'prime', 'rational', | |
'real', 'zero'] | |
``` | |
It seems like these are the only routines that should be defined other than | |
ones to handle definitions which are not handled in the assumptions. | |
Now, what things can be proved with a beta rule: | |
``` | |
['composite', 'even', 'irrational', 'negative', 'noninteger', | |
'nonnegative', 'nonpositive', 'odd', 'positive', 'real', | |
'transcendental', 'zero'] | |
``` | |
So given all the facts, less the ones we define, less the ones that are defined | |
by those we define, leaves the additional ones that require definition (by setting | |
the attribute as in numbers.py where we set transcendental=True or by writing | |
an `_eval_is_foo` routine: | |
set(['commutative', 'antihermitian', 'hermitian', 'infinite', | |
'imaginary', 'finite']) | |
Let's see what facts are not defined for Add, Mul, and Pow | |
``` | |
>>> for g in (Add, Mul, Pow): | |
... print g | |
... for i in sorted(a): | |
... if not hasattr(g, '_eval_is_'+i): print '\t',i | |
... | |
<class 'sympy.core.add.Add'> | |
composite | |
even | |
infinite | |
noninteger | |
nonnegative | |
nonpositive | |
nonzero | |
prime | |
transcendental | |
zero | |
<class 'sympy.core.mul.Mul'> | |
composite | |
infinite | |
noninteger | |
nonnegative | |
nonpositive | |
nonzero | |
prime | |
transcendental | |
<class 'sympy.core.power.Pow'> | |
antihermitian | |
commutative | |
composite | |
hermitian | |
infinite | |
irrational | |
noninteger | |
nonnegative | |
nonpositive | |
nonzero | |
prime | |
transcendental | |
zero | |
``` | |
When a fact is requested like foo.is_odd, the assumption engine traverses all | |
the prerequisites of that fact, in arbitrary order, watching to see if the | |
fact ever becomes known in the process. For example, here are the prerequisites | |
for `odd`: | |
``` | |
>>> print fd(A.prereq['odd']) | |
set(['even', 'real', 'commutative', 'nonzero', 'noninteger', | |
'hermitian', 'algebraic', 'zero', 'complex', 'rational', 'integer', | |
'imaginary', 'transcendental', 'irrational']) | |
``` | |
But compare that to the rule that will prove that something is odd: | |
``` | |
>>> for i,j in A.beta_rules: | |
... if j[0] == 'odd': print i, j | |
... | |
set([('even', False), ('integer', True)]) ('odd', True) | |
``` | |
Let's see what it takes to prove either even or integer: | |
``` | |
>>> for i,j in A.beta_rules: | |
... if j[0] == 'even': print i, j | |
... | |
set([('integer', True), ('odd', False)]) ('even', True) | |
``` | |
(ah, just the opposite of odd) | |
``` | |
>>> for i,j in A.beta_rules: | |
... if j[0] == 'integer': print i, j | |
... | |
>>> | |
``` | |
Hmmm. No way to prove it. It just is defined to be such. | |
Question: why are all the other prerequisites called when | |
(it would seem to me) that we should only call `integer` and | |
`even` to know if the object is odd. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something to always remember when dealing with assumptions is that there are always two sides to every assumption, the case when it is True and the case when it is False. The correct knowledge about any of the facts in
prereq['odd']
can be used to deduce thatodd
is False. For example if nonzero is False then odd must be False since odd implies nonzero (in general, remember thata -> b
is logically equivalent to!b -> !a
).