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

ntheory.AskEvenHandler.Mul is order-dependent #9127

Open
toolforger opened this issue Mar 12, 2015 · 5 comments
Open

ntheory.AskEvenHandler.Mul is order-dependent #9127

toolforger opened this issue Mar 12, 2015 · 5 comments
Labels

Comments

@toolforger
Copy link
Contributor

ask(Q.even(x*y*(y + z)), Q.integer(x) & Q.integer(y) & Q.odd(z)) is supposed to give True (the ability to infer that y*(y+z) for odd z was introduced in e91f8f0 by @skirpichev).
However, some permutations of x, y, and (y + z) will fail because the code will not recognize that y and (y + z) combine in a relevant fashion if it sees x between the two.

Fixing this would require checking all combinations of two terms.
That's O(N^2) for N = number of terms.
So either N needs to be limited, or the list of term combinations to check would need to exclude those that cannot contribute to the answer.

@toolforger
Copy link
Contributor Author

I spoke too soon - preparing the test case revealed that all permutations work with the old ordering_of_classes sort order, and none with the new, class-name based one.
It's still related to terms being fed to the comparison loop in an unexpected order, but the order in which terms are fed to the comparison loop seems to happen after some internal sorting step.

More analysis is needed.

@skirpichev
Copy link
Contributor

However, some permutations of x, y, and (y + z) will fail

Did you know about sorting?

Fixing this would require checking all combinations of two terms.

Or not count this as a bug at all. If something work differently in non-canonical form, i.e. for unevaluated Mul like Mul(y, x, (y + z), evaluate=False) - not necessary it's a bug.

More analysis is needed.

How sorted results looks now? I think, if they look differently from x*y*(y + z) - this is a real bug.

@skirpichev
Copy link
Contributor

unsubscribed. mention me, if you want reply

@toolforger
Copy link
Contributor Author

Didn't have to do more detailed analysis, renaming x and y got me a None even in current master. (I didn't know that the terms would be sorted before the ask handler would see them. Once I found that out, I could trigger a changed sort order by renaming symbols.)
Added a PR for a new unit test to demonstrate the problem, see #9130 .
@skirpichev so you know.

@skirpichev
Copy link
Contributor

Didn't have to do more detailed analysis, renaming x and y got me a None even in current master.

I admit, this looks as a bug for me. And same "works" for old assumptions.

Fixing wouldn't require checking all terms - you should do care only about special ones, i.e. Add instances.

I didn't know that the terms would be sorted before the ask handler

I'm sure you know that Python uses eager evaluation rules. So, constructor for Mul must be called before Q.even. Mul have some canonicalization logic in it's constructor (i.e. Mul.flatten and so on) and that include sorting.

toolforger added a commit to toolforger/sympy that referenced this issue Mar 17, 2015
skirpichev pushed a commit to diofant/diofant that referenced this issue Jul 1, 2015
skirpichev pushed a commit to diofant/diofant that referenced this issue Jul 3, 2015
skirpichev pushed a commit to diofant/diofant that referenced this issue Jul 3, 2015
skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants