Skip to content
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

assumptions that are wrong in master #8046

Closed
4 of 14 tasks
smichr opened this issue Sep 15, 2014 · 9 comments
Closed
4 of 14 tasks

assumptions that are wrong in master #8046

smichr opened this issue Sep 15, 2014 · 9 comments
Labels
assumptions Wrong Result The output produced by SymPy is mathematically incorrect.

Comments

@smichr
Copy link
Member

smichr commented Sep 15, 2014

  • 1
>>> a = Dummy
>>> (a(zero=1)*a(complex=1)).is_complex
True <--- should be None since complex could be unbounded -> NaN
>>> ask(Q.real(x*y),Q.real(x)&Q.real(y))
True
  • 1b enhancement
>>> (a(complex=0)*a(complex=0)).is_complex  <--should be False; ~complex --X--> re or im
>>> ask(Q.complex(x*y),~Q.complex(x)&~Q.complex(y))
>>>
  • 2
>>> (a(real=1)*a(real=1)).is_real
True <--- should be None since complex could be unbounded -> NaN
>>> ask(Q.complex(x*y),Q.zero(x)&Q.complex(y))
True
  • 3 (enhancement, not an error here)
>>> (a(unbounded=1, real=1)*a(imaginary=1)).is_real  # should be False 
>>> ask(Q.real(x*y),Q.real(x)&~Q.bounded(x)&Q.imaginary(y))
False
  • 4
>>> (1/Dummy(integer=1)).is_rational
True <--should be None since den could be zero
  • 4.1
>>> n=Dummy(integer=1,positive=1)
>>> (n/(n-1)).is_rational
True  <-- should be None since n could be 1
  • 5
>>> (Dummy(integer=1)/Dummy(integer=1)).is_rational
True <--should be None since den could be zero
>>> (I*sqrt(1-sqrt(2))).is_positive
>>> <-- should be False
  • 7 enhancement
>>> (a(zero=True)*a(imaginary=True)).is_positive
>>> <-- should be False
  • 8 enhancement
>>> c = Symbol('c', complex=True, real=False, imaginary=False)
>>> assert (I*c).is_real
>>>  <-- should be False
  • 9, 10, 11, 12, 13, 14, 15, 16
    r  = Dummy('r', infinite=True, real=True)
    p = Dummy('p', infinite=True, positive=True)
    n = Dummy('n', infinite=True, negative=True)
    i = Dummy('i', infinite=True, imaginary=True)
    z = Dummy('z', infinite=True, imaginary=False, real=False, complex=True)
    assert (p + r).is_complex is None
    assert (n + r).is_complex is None
    assert (z + r).is_complex is None
    assert (z + p).is_complex is None
    assert (z + n).is_complex is None
    assert (z + i).is_complex is None
    assert (p + r).is_real is None
    assert (n + r).is_real is None
    nn = Dummy(nonnegative=1, infinite=1)
    assert (p + nn).is_finite is False # gives None (enhancement)
    assert (p + nn).is_positive is True # gives None (enhancement) [#8162]
    assert (p + r).is_real is None # gives True (error, result is nan or oo)
    >>> nn=Dummy(nonnegative=1)
    >>> (1+nn).is_positive
    True
    >>> (I+nn*I).is_imaginary
    >>> <--should be True
  • 18
    >>> d = Dummy(real=True)
    >>> (1/d).is_real
    True <-- should be None since d could be zero
    >>> 1/S(0)
    zoo
    >>> _.is_real
    >>> 
  • 19 If 2 or more arguments can cancel then no conclusion on their properties should be made
example: the two args of q are each non-hermitian but they cancel. 
We should only conclude non-hermitian if only one arg is non-hermitian

>>> q=S('''-2**(2/3)*3**(1/3)*I + 12**(1/3)*I''')
>>> [i.is_hermitian for i in q.args]
[False, False]
>>> q.is_hermitian
False <-- should be None
>>> S.Zero.is_hermitian
True
>>> q.equals(0)
True

This is a helpful routine to compare what the object's evaluation are relative to the deduced values:

def compare(z):
    print('\t_eval\tis_')
    for k in sorted([w for w in dir(z) if 'eval_is' in w]):
        try:
            a = getattr(z, k)(), getattr(z, k.lstrip('_eval_'))
            args = a + (k.split('_')[-1], )
            if a[0] != a[1] and None not in a:
                print("%-->\ts\t%s\t%s" % args)
            elif a[0] != a[1]:
                print(">\t%s\t%s\t%s" % args)
            else:
                print("\t%s\t%s\t%s" % args)
        except:
            pass

>>> compare(sqrt(2))
        _eval   is_
        True    True    algebraic
        True    True    complex
>       None    False   composite
>       None    False   even
        True    True    finite
        False   False   imaginary
        False   False   integer
        False   False   negative
>       None    False   odd
        None    None    polar
        True    True    positive
>       None    False   prime
        False   False   rational
        True    True    real
        False   False   zero
@smichr
Copy link
Member Author

smichr commented Sep 28, 2014

As these are fixed, they can be checked off and the PR that fixed them can be indicated.

@pelegm
Copy link
Contributor

pelegm commented Jan 2, 2015

In 1 you wrote:

True <--- should be None since complex could be unbounded -> NaN

I am not sure I follow. Do you suggest that zoo.is_complex should be true? Considering the discussion about real versus extended_real, I'd say whatever is complex is bounded. Don't you agree?

@pelegm
Copy link
Contributor

pelegm commented Jan 2, 2015

The following is also an assumption which is wrong in master: #8649.

@pelegm
Copy link
Contributor

pelegm commented Jan 2, 2015

#8732 should, when merged, resolve bullets 4 and 5.

pelegm pushed a commit to pelegm/sympy that referenced this issue Jan 23, 2015
aka001 pushed a commit to aka001/sympy that referenced this issue Jan 31, 2015
@AnishShah
Copy link
Contributor

Hi @smichr, I'm trying to solve some issues from the above list.

7th one

>>> (a(zero=True)*a(imaginary=True)).is_positive
>>> <-- should be False

We don't know whether the imaginary number is finite or infinite, so shouldn't the correct answer be None?

In [16]: a = Symbol('a', imaginary=True, finite=True)

In [17]: b = Symbol('b', zero=True)

In [18]: (a*b).is_positive
Out[18]: False

In [19]: a = Symbol('a', imaginary=True, infinite=True)

In [20]: (a*b).is_positive

In [21]: 

@AnishShah
Copy link
Contributor

For 9-16 issues, what should be the output for

>>> r  = Dummy('r', real=True)
>>> p = Dummy('p', positive=True)
>>> (p+w).is_real

Should it be None? As we don't know whether it is finite or infinite?

@mvnnn
Copy link
Contributor

mvnnn commented Feb 17, 2016

In [4]:n=Dummy(integer=1,positive=1)
In [5]:(n/(n-2)).is_rational
Out[5]: True

that's right answer is True or None.

@asmeurer
Copy link
Member

I guess it should be None, since n can be 2 (and infinity is not rational).

@oscarbenjamin
Copy link
Contributor

I think all of the examples above are fixed already.

I guess that the definitions of some predicates have changed since the OP. For example complex implies finite now which changes what a number of the answers should be. Also there is now extended_real as separate from real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assumptions Wrong Result The output produced by SymPy is mathematically incorrect.
Projects
None yet
Development

No branches or pull requests

8 participants