default exclusions

14 views
Skip to first unread message

smichr

unread,
Dec 4, 2012, 10:34:50 PM12/4/12
to sy...@googlegroups.com
Does it make sense to allow match to automatically exclude from a Wild all other free symbols in a term?

>>> (3*x*y*exp(x)+4/y+3*x).match(a*x+b)
{a_: 3*y*exp(x), b_: 3*x + 4/y}
>>> (3*x*y*exp(x)+4/y+3*x).match(a*x+b,exclude=1)
{a_: 3, b_: 3*x*y*exp(x) + 4/y}

Aaron Meurer

unread,
Dec 4, 2012, 11:17:38 PM12/4/12
to sy...@googlegroups.com
Maybe as an optional option, but not by the default. Just because you
have a wild, doesn't mean that you want it to match against a number.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/NUqA8u6Q5YkJ.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

Chris Smith

unread,
Dec 5, 2012, 12:41:31 AM12/5/12
to sy...@googlegroups.com
It will match anything that isn't explicitly given in the term that it appears in. 'a' will only exclude 'x' in the following, hence matching '3*y'

>>> (4+3*x*y).match(a*x+b,exclude=1)
{a_: 3*y, b_: 4}

Aaron Meurer

unread,
Dec 5, 2012, 1:05:17 AM12/5/12
to sy...@googlegroups.com
Well, it also doesn't mean that you necessarily want to match a
"coefficient", though that's usually what it's used for. For example,
something like

(cos(x)*x).match(a*x) -> {a: cos(x)}

I suppose you'd say something like if the user wants that, he can use
exclude=[] to force zero exclusions. There are two issues with that.
The first is that we still have ambiguity if the user defines
exclusions (does wild automatically add exclusions in that case, or do
we assume that if some are explicitly given that the user knows what
he is doing?).

But even then, I'm willing to concede that we could come up with a
reasonable way to do it, and it might be useful. A more important
issues is that this would be a rather subtle API change. Granted, if
people aren't using exclude, their matches are probably
nondeterministic anyway, but it's hard to be sure. Furthermore, since
the use of Wild inside SymPy itself already use exclude almost all the
time, it would be very difficult to judge the extent of such a change
only by our own tests.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.

Chris Smith

unread,
Dec 5, 2012, 4:32:30 AM12/5/12
to sy...@googlegroups.com
On Wed, Dec 5, 2012 at 11:50 AM, Aaron Meurer <asme...@gmail.com> wrote:
Well, it also doesn't mean that you necessarily want to match a
"coefficient", though that's usually what it's used for.  For example,
something like

(cos(x)*x).match(a*x) -> {a: cos(x)}


It's just an optional setting so there is no compatibility change to worry about. If someone uses exclude=True in the call to match, all Wilds have their exclude parameter updated and restored after matching. Alternatively, I could make it where only vanilla wilds would get the updating. Perhaps that's better -- "do the default thing except on the things that I want to behave a certain way" .
Reply all
Reply to author
Forward
0 new messages