sympy match has difficulty with modulo
Following this StackOverflow question, and a fix provided by @smichr, I tried the following:
>>> from sympy import *
>>> k,m,n = symbols("k m n", integer=True)
>>> (3*k+4)%2 - k%2
0 # it works with the fix above. Thank you!
>>> p = Wild('p')
>>> q = Wild('q')
>>> e = (2*k+7)%5 + 7*k+7
>>> e
7*k + Mod(2*k + 2, 5) + 7
>>> e.match(p%5+p)
>>> e.match((p+5*q)%5+p)
>>> e.match(p%5+p+5*q)
q_: k + 1, p_: 2*k + 2
I expected the first or second e.match
to work for me (p:7*k+7
for first one and p:7*k+7,q:-k
for second one), but it didn't. Is this a bug? If yes, is there a fix/workaround?
python match sympy modulo
add a comment |
Following this StackOverflow question, and a fix provided by @smichr, I tried the following:
>>> from sympy import *
>>> k,m,n = symbols("k m n", integer=True)
>>> (3*k+4)%2 - k%2
0 # it works with the fix above. Thank you!
>>> p = Wild('p')
>>> q = Wild('q')
>>> e = (2*k+7)%5 + 7*k+7
>>> e
7*k + Mod(2*k + 2, 5) + 7
>>> e.match(p%5+p)
>>> e.match((p+5*q)%5+p)
>>> e.match(p%5+p+5*q)
q_: k + 1, p_: 2*k + 2
I expected the first or second e.match
to work for me (p:7*k+7
for first one and p:7*k+7,q:-k
for second one), but it didn't. Is this a bug? If yes, is there a fix/workaround?
python match sympy modulo
add a comment |
Following this StackOverflow question, and a fix provided by @smichr, I tried the following:
>>> from sympy import *
>>> k,m,n = symbols("k m n", integer=True)
>>> (3*k+4)%2 - k%2
0 # it works with the fix above. Thank you!
>>> p = Wild('p')
>>> q = Wild('q')
>>> e = (2*k+7)%5 + 7*k+7
>>> e
7*k + Mod(2*k + 2, 5) + 7
>>> e.match(p%5+p)
>>> e.match((p+5*q)%5+p)
>>> e.match(p%5+p+5*q)
q_: k + 1, p_: 2*k + 2
I expected the first or second e.match
to work for me (p:7*k+7
for first one and p:7*k+7,q:-k
for second one), but it didn't. Is this a bug? If yes, is there a fix/workaround?
python match sympy modulo
Following this StackOverflow question, and a fix provided by @smichr, I tried the following:
>>> from sympy import *
>>> k,m,n = symbols("k m n", integer=True)
>>> (3*k+4)%2 - k%2
0 # it works with the fix above. Thank you!
>>> p = Wild('p')
>>> q = Wild('q')
>>> e = (2*k+7)%5 + 7*k+7
>>> e
7*k + Mod(2*k + 2, 5) + 7
>>> e.match(p%5+p)
>>> e.match((p+5*q)%5+p)
>>> e.match(p%5+p+5*q)
q_: k + 1, p_: 2*k + 2
I expected the first or second e.match
to work for me (p:7*k+7
for first one and p:7*k+7,q:-k
for second one), but it didn't. Is this a bug? If yes, is there a fix/workaround?
python match sympy modulo
python match sympy modulo
edited Nov 14 '18 at 18:15
Salem Derisavi
asked Nov 14 '18 at 17:04
Salem DerisaviSalem Derisavi
978
978
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
(Copying the same thing I wrote on the SymPy issue)
match has very limited mathematical knowledge. It doesn't know that the 2*k
in the Mod
can be replaced with 7*k
.
I'm not sure if this would be easy to fix. match is already pretty complicated with the limited mathematical matching it does. A better design would likely be needed to solve problems like this. Actually this strikes me as the sort of problem that you would need an SMT solver to solve, but maybe there are simpler algorithms that could do it.
Sorry this doesn't give a direct answer on how to solve the problem.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305361%2fsympy-match-has-difficulty-with-modulo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
(Copying the same thing I wrote on the SymPy issue)
match has very limited mathematical knowledge. It doesn't know that the 2*k
in the Mod
can be replaced with 7*k
.
I'm not sure if this would be easy to fix. match is already pretty complicated with the limited mathematical matching it does. A better design would likely be needed to solve problems like this. Actually this strikes me as the sort of problem that you would need an SMT solver to solve, but maybe there are simpler algorithms that could do it.
Sorry this doesn't give a direct answer on how to solve the problem.
add a comment |
(Copying the same thing I wrote on the SymPy issue)
match has very limited mathematical knowledge. It doesn't know that the 2*k
in the Mod
can be replaced with 7*k
.
I'm not sure if this would be easy to fix. match is already pretty complicated with the limited mathematical matching it does. A better design would likely be needed to solve problems like this. Actually this strikes me as the sort of problem that you would need an SMT solver to solve, but maybe there are simpler algorithms that could do it.
Sorry this doesn't give a direct answer on how to solve the problem.
add a comment |
(Copying the same thing I wrote on the SymPy issue)
match has very limited mathematical knowledge. It doesn't know that the 2*k
in the Mod
can be replaced with 7*k
.
I'm not sure if this would be easy to fix. match is already pretty complicated with the limited mathematical matching it does. A better design would likely be needed to solve problems like this. Actually this strikes me as the sort of problem that you would need an SMT solver to solve, but maybe there are simpler algorithms that could do it.
Sorry this doesn't give a direct answer on how to solve the problem.
(Copying the same thing I wrote on the SymPy issue)
match has very limited mathematical knowledge. It doesn't know that the 2*k
in the Mod
can be replaced with 7*k
.
I'm not sure if this would be easy to fix. match is already pretty complicated with the limited mathematical matching it does. A better design would likely be needed to solve problems like this. Actually this strikes me as the sort of problem that you would need an SMT solver to solve, but maybe there are simpler algorithms that could do it.
Sorry this doesn't give a direct answer on how to solve the problem.
answered Nov 15 '18 at 22:10
asmeurerasmeurer
58.2k16113186
58.2k16113186
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305361%2fsympy-match-has-difficulty-with-modulo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown