I noticed that some screwy things happen with symbols depending on how
you define them. For example

In [2]: x = Symbol('x', commutative = False)

In [3]: x.is_commutative; x._assumptions
Out[3]: False
Out[3]: {'comparable': False}

That's fine. But what happens if we add real = True/False:

In [5]: y = Symbol('y', commutative = False, real = True)

In [6]: y.is_commutative; y._assumptions
Out[6]: False
Out[6]: {'commutative': True,  'comparable': False, 'complex': True,
'imaginary': False, 'real': True}

In [7]: y?
Type:           Symbol
Base Class:     <class 'sympy.core.symbol.Symbol'>
String Form:    y
Namespace:      Interactive
File:           c:\python25\lib\site-packages\sympy\core\symbol.py
Docstring:
    Assumptions::
   real = True
   commutative = True

You can override the default assumptions in the constructor::
   >>> A,B = symbols('AB', commutative = False)
   >>> bool(A*B != B*A)
   True
   >>> bool(A*B*2 == 2*A*B) == True # multiplication by scalars is
commutative
   True
Call def:       y(self, *args)

Does this mean that the commutative = False is overwritten? I'm not
really sure what this means. But, you might run into trouble if you
use the subs() method. I got this error until I removed the real=True
part from all my symbols.

Traceback (most recent call last):
  File "C:\Documents and Settings\wflynn\My Documents\Python\One-
magnon Cross-section Calculation\linear_case.py", line 411, in
<module>
    cross_sect = generate_cross_section(N_atoms,ops,atom)
  File "C:\Documents and Settings\wflynn\My Documents\Python\One-
magnon Cross-section Calculation\linear_case.py", line 376, in
generate_cross_section
    arg[i][j] = sub_in(arg[i][j],exp(I*t*A+I*t*B+I*C+I*D),sp.DiracDelta
(A+B+C+D))
  File "C:\Documents and Settings\wflynn\My Documents\Python\One-
magnon Cross-section Calculation\sub_in.py", line 18, in sub_in
    new = _walk_it(expression, pattern, replacement, check)
  File "C:\Documents and Settings\wflynn\My Documents\Python\One-
magnon Cross-section Calculation\sub_in.py", line 82, in _walk_it
    new.insert(new.index(sub),_walk_it(sub, pattern, replacement,
check))
  File "C:\Documents and Settings\wflynn\My Documents\Python\One-
magnon Cross-section Calculation\sub_in.py", line 79, in _walk_it
    new.insert(new.index(sub),replacement.subs(v))
  File "C:\Python25\lib\site-packages\sympy\core\basic.py", line 966,
in subs
    return self._subs_list(sequence)
  File "C:\Python25\lib\site-packages\sympy\core\basic.py", line 1007,
in _subs_list
    result = result.subs(old, new)
  File "C:\Python25\lib\site-packages\sympy\core\basic.py", line 971,
in subs
    return self._subs_old_new(old, new)
  File "C:\Python25\lib\site-packages\sympy\core\cache.py", line 85,
in wrapper
    func_cache_it_cache[k] = r = func(*args, **kw_args)
  File "C:\Python25\lib\site-packages\sympy\core\basic.py", line 980,
in _subs_old_new
    return self._eval_subs(old, new)
  File "C:\Python25\lib\site-packages\sympy\core\function.py", line
204, in _eval_subs
    return Basic._seq_subs(self, old, new)
  File "C:\Python25\lib\site-packages\sympy\core\basic.py", line 1064,
in _seq_subs
    return self.__class__(*[s.subs(old, new) for s in args])
  File "C:\Python25\lib\site-packages\sympy\core\multidimensional.py",
line 127, in wrapper
    return f(*args, **kwargs)
  File "C:\Python25\lib\site-packages\sympy\core\cache.py", line 85,
in wrapper
    func_cache_it_cache[k] = r = func(*args, **kw_args)
  File "C:\Python25\lib\site-packages\sympy\core\function.py", line
141, in __new__
    evaluated = cls.eval(*args)
  File "C:\Python25\lib\site-packages\sympy\functions\special
\delta_functions.py", line 58, in eval
    if arg.is_positive or arg.is_negative:
  File "C:\Python25\lib\site-packages\sympy\core\assumptions.py", line
367, in getit
    return self._what_known_about(name)
  File "C:\Python25\lib\site-packages\sympy\core\assumptions.py", line
256, in _what_known_about
    a = getattr(self,'_eval_is_'+k)()
  File "C:\Python25\lib\site-packages\sympy\core\add.py", line 252, in
_eval_is_positive
    if c.is_positive and r.is_positive:
  File "C:\Python25\lib\site-packages\sympy\core\assumptions.py", line
367, in getit
    return self._what_known_about(name)
  File "C:\Python25\lib\site-packages\sympy\core\assumptions.py", line
279, in _what_known_about
    a = getattr(self,'is_'+pk)
  File "C:\Python25\lib\site-packages\sympy\core\assumptions.py", line
367, in getit
    return self._what_known_about(name)
  File "C:\Python25\lib\site-packages\sympy\core\assumptions.py", line
282, in _what_known_about
    self._learn_new_facts( ((pk,a),) )
  File "C:\Python25\lib\site-packages\sympy\core\assumptions.py", line
341, in _learn_new_facts
    self._assume_rules.deduce_all_facts(facts, base)
  File "C:\Python25\lib\site-packages\sympy\core\facts.py", line 884,
in deduce_all_facts
    assert new_facts[k] == v, ('inconsitency between
facts',new_facts,k,v)
AssertionError: ('inconsitency between facts', {'real': True,
'imaginary': False, 'complex': True, 'commutative': True},
'commutative', False)

This was conducted on the most recent version of sympy (I downloaded
it about an hour ago). It's not a big bug but it's something that
definitely gave me a headache for a couple of hours today.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to